tag:blogger.com,1999:blog-18016840180532448462024-03-05T21:20:07.444-08:00ferocia animiRredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.comBlogger58125tag:blogger.com,1999:blog-1801684018053244846.post-20459933138178102782020-08-04T11:42:00.006-07:002021-03-03T05:04:51.169-08:00What do you need to be prepared for AI-900 Azure AI Fundamentals?<div><a href="https://images.youracclaim.com/size/680x680/images/4136ced8-75d5-4afb-8677-40b6236e2672/azure-ai-fundamentals-600x600.png" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span></span><img alt="Microsoft Certified: Azure AI Fundamentals" border="0" data-original-height="600" data-original-width="600" height="158" src="https://images.youracclaim.com/size/680x680/images/4136ced8-75d5-4afb-8677-40b6236e2672/azure-ai-fundamentals-600x600.png" title="Azure Bot Services, Azure Machine Learning, Cognitive Services" width="158" /></a><i><b>Disclaimer:</b> I am not an AI engineer, and I have passed beta AI-900 just for fun. I want to share the minimum level of knowledge that is required to pass this exam. The beta exam has 53 questions. My score was 800. </i><br /></div><div><br /></div><div>It will be a small post because AI-900 is a pretty simple fundamentals exam. I know that you could download the required <a href="https://docs.microsoft.com/en-us/learn/certifications/exams/ai-900?source=learn" target="_blank">exam skills outline</a>, but I want to share the minimum set of skills:</div><span><a name='more'></a></span><div><br /></div><div><ol style="text-align: left;"><li>Basic knowledge in Machine Learning (You have to know the difference between regression, k-mean and classification so on)</li><li>Guiding principles for responsible AI (fairness, reliability and safety, privacy and security, inclusiveness, transparency, and accountability).<br /></li><li>You should understand AI Azure Services (witch one responsible for what, without practical experience).</li></ol><div>I have used for learning next resources:</div><div style="text-align: left;"><ol style="text-align: left;"><li>ML - <a href="https://www.coursera.org/learn/machine-learning">https://www.coursera.org/learn/machine-learning</a></li><li>The topics are covered in Online Learning paths <a href="https://docs.microsoft.com/en-us/learn/certifications/exams/ai-900?source=learn&tab=tab-learning-paths" target="_blank">on the exam page</a>.</li></ol>This is it.</div></div>RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com0tag:blogger.com,1999:blog-1801684018053244846.post-34480272141467542292018-06-18T13:00:00.000-07:002018-10-01T00:28:12.194-07:00FaaS on AWS for .NET developers<br />
<div style="text-align: justify;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-QhuaXrUfPs7MQU6HINvYa0zfFkZzQqi29riKE5Jnp6GRqk_-pIUf-VLGjfHfRTIrTpXp9rw3o9OXs0jF54B258xO6J-kuO-d_Pa7ouVm1y6tRYPZVBywLGsAoy79Pj4L7nS2uvlQQoc/s1600/35071148_1766688890091592_4746947702653190144_o.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="668" data-original-width="1000" height="213" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-QhuaXrUfPs7MQU6HINvYa0zfFkZzQqi29riKE5Jnp6GRqk_-pIUf-VLGjfHfRTIrTpXp9rw3o9OXs0jF54B258xO6J-kuO-d_Pa7ouVm1y6tRYPZVBywLGsAoy79Pj4L7nS2uvlQQoc/s320/35071148_1766688890091592_4746947702653190144_o.jpg" width="320" /></a></div>
Last weekend, I joined to IT Talk event series promoted one of the Lviv's company. This event was dedicated to cloud solutions for C# developers.</div>
<br />
<div style="text-align: justify;">
I have prepared the presentation about FaaS on AWS for .NET developers. There are I presented how to develop&deploy a serverless solution on Amazon. And I did a demo with C# in Visual Studio 2017.</div>
<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="485" marginheight="0" marginwidth="0" scrolling="no" src="//www.slideshare.net/slideshow/embed_code/key/gRzL5NZL8fXEwB" style="border-width: 1px; border: 1px solid #ccc; margin-bottom: 5px; max-width: 100%;" width="595"> </iframe> <br />
<div style="margin-bottom: 5px;">
<b> <a href="https://www.slideshare.net/RredCat/faas-on-aws-for-net-developers" target="_blank" title="FaaS on AWS for .NET developers">FaaS on AWS for .NET developers</a> </b> from <b><a href="https://www.slideshare.net/RredCat" target="_blank">Taras Romanyk</a></b><br />
<br />
<div style="text-align: justify;">
Slides contain brief information about the theme. So anybody feels free to contact me if he/she has any questions or needs additional explanations.</div>
<br />
<div style="text-align: justify;">
You could find more photos - <a href="https://www.facebook.com/media/set/?set=oa.2115124912098188&type=3" target="_blank">there</a>.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
And read info about my presentation and extra info+slided of another presentation <a href="https://dataart.com.ua/news/u-lvovi-net-rozrobniki-zustrilis-na-it-talk/" target="_blank">there</a>.</div>
<br /></div>
RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com0tag:blogger.com,1999:blog-1801684018053244846.post-263152182850435592017-12-06T13:48:00.000-08:002019-07-22T09:23:49.582-07:00Secure ASP.NET Core Web API using API Key Authentication<div style="text-align: right;">
</div>
<div style="text-align: justify;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiePsXmFtHGMjMHerxU55jybcxk_qIhKbNjfMJnU9gqd-xBYNImcrYR4UhRggBr42mzaxsDnGmLdofvfz0HXo0BbdJt1_02MjP8w3aGnU5Pn48TUQGBsyvVzHijQiJjlbe0cRA7hUXuyDo/s1600/cyber-security-1915628_640.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="640" data-original-width="640" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiePsXmFtHGMjMHerxU55jybcxk_qIhKbNjfMJnU9gqd-xBYNImcrYR4UhRggBr42mzaxsDnGmLdofvfz0HXo0BbdJt1_02MjP8w3aGnU5Pn48TUQGBsyvVzHijQiJjlbe0cRA7hUXuyDo/s200/cyber-security-1915628_640.png" width="200" /></a></div>
I am implementing the simple web service that grants access via usual login and api login with some token. I have googled a bit for good solution but found it for asp.net mvc 5 application only (original article - <a href="http://bit.ly/1wBdnqd">Secure ASP.NET Web API using API Key Authentication – HMAC Authentication</a>).</div>
<br />
So it is something that helps me to do the same stuff for asp.net core that I am using for my web services.<br />
<br />
First of all, I went <span class="short_text" id="result_box" lang="en"><span class="">through great workshop related to </span></span><span class="short_text" id="result_box" lang="en"><span class=""><span class="col-11 text-gray-dark mr-2">the various new pieces in ASP.NET Core Authorization - <a href="https://github.com/blowdart/AspNetAuthorizationWorkshop">AspNetAuthorizationWorkshop.</a></span></span></span> Also, check out the great article about <a href="https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters">Filters</a>.<br />
<br />
<a name='more'></a>But both these materials are focused on Authorization, it is nice to know but for our purpose, we have to use Authentication.<br />
<br />
I implemented custom AuthenticationHandler and override there HandleAuthenticateAsync. I returned AuthenticateResult.Success when request met requirment and AuthenticateResult.Fail in otherwise.<br />
<br />
<script src="https://gist.github.com/RredCat/3c3a30fbe79765b30911a2785b8910b6.js"></script> When handler was implemented I needed to configure service to use it. I wrote next code in Startup.ConfigureServices method:<br />
<br />
<script src="https://gist.github.com/RredCat/169f273dadd9c8ba87baaa56fd29c09d.js"></script><br />
And marked controller/action that I needed to protect:<br />
<br />
<script src="https://gist.github.com/RredCat/5e3e9f7432b083a71c6a021c913b948c.js"></script><br />
Vu'a la, it works now.<br />
<br />
<b>PS: </b>I used AddMvcCore() rather AddMvc() for better performance. Also, I added AddJsonFormatters for exploring JSON in respoce and AddAuthorization to use security.<br />
<br />
You could find source <a href="https://github.com/RredCat/WebApiHMACAuthentication" target="_blank">there on GitHub.</a><br />
<br />
<b>EDIT: </b><br />
My implementation had the bug; it related to the way how to <i>request.body</i> works. If the <i>request.body </i>was read already before during request pipeline, then it is empty when you try to read it the second time. <i>AuthenticationHandler </i>reads <i>request.body</i> for computing hash, so model binder can't process correct binding from <i>request.body</i> to post or put parameters. But this bug is easy to fix I have to enable rewind for body stream (Allow rewind<i> request.EnableRewind(); </i>and rewind request.Body.Position = 0;).<br />
<br />
I have already updated sources code on GitHub.RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com5tag:blogger.com,1999:blog-1801684018053244846.post-90747081994607824752017-07-24T05:02:00.002-07:002017-07-24T05:02:24.744-07:00Dynamic Configuration Settings in ASP.NET Core<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3Hvt9-Hgt6XLO3MTaWhlEkvqNFhhgsmotADOs2DbE9I49pa7nljvZ8a-VL33LY905GfIIksxKK-qg4_UwNLPI_7REGw7E3B5YTnJzMo9drbvnP77w6ZACyRaGztdWY72Obx8QT9FhK7I/s1600/B32.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="400" data-original-width="300" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3Hvt9-Hgt6XLO3MTaWhlEkvqNFhhgsmotADOs2DbE9I49pa7nljvZ8a-VL33LY905GfIIksxKK-qg4_UwNLPI_7REGw7E3B5YTnJzMo9drbvnP77w6ZACyRaGztdWY72Obx8QT9FhK7I/s200/B32.jpg" width="150" /></a><br />
<div style="text-align: justify;">
I read the great article about the configuration of ASP.NET Core web application - <a href="https://weblog.west-wind.com/posts/2016/may/23/strongly-typed-configuration-settings-in-aspnet-core" target="_blank">Strongly Typed Configuration Settings in ASP.NET Core</a>. As for me, it is better than access via dictionary's keys but it is always boring to create another POCO classes. I prefer to use a dynamic object. And it is easy to replace POCO class with dynamic.<br />
<br />
<a name='more'></a></div>
First of all, I replaced <i>ConfigureServices </i>method<i> </i>with the next code:<br />
<i><br /></i> <i>public void ConfigureServices(IServiceCollection services)</i><br />
<i>{</i><br />
<i>services.AddMvc();</i><br />
<i>services.AddOptions(); //be careful. don't miss options injection</i><br />
<i>services.Configure< ExpandoObject >(Configuration.GetSection("MySettings"));</i><br />
<i>}</i><br />
<i><br /></i> And inject settings in the controller:<br />
<i><br /></i> <i>private dynamic MySettings { get; set; }</i><br />
<i><br />public HomeController(IOptions< ExpandoObject > settings)</i><br />
<i>{</i><br />
<i> MySettings = settings.Value;</i><br />
<i>}</i><br />
<br />
Now, you could use it like usual instance.<br />
<br />
<i>public IActionResult Index()</i><br />
<i>{</i><br />
<i> ViewBag.ApplicationName = MySettings.ApplicationName;</i><br />
<i> return View();</i><br />
<i>}</i><br />
<br />
This way has a number of disadvantages:<br />
<ul>
<li>The risk of a typo - do you know how to detect if a property exists on an ExpandoObject? <i>ExpandoObject</i> is inherited from <i>Dictionary<string object=""></string></i>. <a href="https://stackoverflow.com/a/2839629/182344" target="_blank">So check doesn't look graceful</a>.</li>
<li>Complex properties. As I mentioned, <i>ExpandoObject</i> is inherited from <i>Dictionary<string object=""> </string></i>so we can't parse complex settings. We could create POCO class that has as a property another POCO class and fit our complex settings without any problem. But in the instance of ExpandoObject, we can't fit object to dynamic object what is represented in the settings.</li>
</ul>
<div>
Also, you could get more information about asp.net core configuration in <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration" target="_blank">Configuration in ASP.NET Core</a> article.</div>
RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com0tag:blogger.com,1999:blog-1801684018053244846.post-469601442618688922016-08-22T10:16:00.001-07:002016-08-24T01:30:35.940-07:00TFS 2015: deploy website to IIS without installing extra add-ons to TFSRecently,
I started to keep my sources under <a href="https://www.visualstudio.com/en-us/docs/whats-new" target="_blank">TFS 2015</a>. After moving our work items I have
time to pay attention to new build. Everything looks pretty simple until I
tried to deploy my website to local IIS. I have found pretty simple article
how to do it - <a href="https://www.visualstudio.com/en-us/docs/release/examples/other-servers/net-to-vm" target="_blank">Deploy ASP.NET apps to domain-joined machines using WinRM</a>. But
this way was closed for me because I didn't have permission to install add-on
from the market on TFS Server. So I came back to the old and proven method with
MS Build. My parameters for MS Build look like :
<br />
<i><br /></i>
<i>/p:DeployOnBuild=True /p:DeployTarget=MsDeployPublish /p:MSDeployPublishMethod=RemoteAgent /p:CreatePackageOnPublish=True /p:DeployIisAppPath="Sites/Stage" /p:MsDeployServiceUrl=10.XXX.XXX.XXX /p:username=DOMAIN\MyUserName /p:password=MyPassword</i><br />
<br />
<div lang="en-US" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
But I didn't want to store my password in
build's configuration. So I looked into <a href="https://www.visualstudio.com/en-us/docs/build/define/variables#" target="_blank">TFS variables</a> for this. After small investigation I modified a bit MS Build string: </div>
<div lang="en-US" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div lang="en-US" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<i>/p:DeployOnBuild=True /p:DeployTarget=MsDeployPublish /p:MSDeployPublishMethod=RemoteAgent /p:CreatePackageOnPublish=True /p:DeployIisAppPath="$(SiteName)" /p:MsDeployServiceUrl=10.XXX.XXX.XXX /p:username=DOMAIN\$(User) /p:password=$(Password)</i> </div>
<div lang="en-US" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div lang="en-US" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
And added <i>SiteName, </i><i>User</i> and <i>Password </i>variables: </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV5Q8YGizm_1QEhZALCAhOtXRkjt0sJ-z1KMmgJWDFOgSEf_30BhdEQbyKWpB_E0lIJjNJxljsJO1tdIrfhmFshy1fqyzM4HCCz7MksD9y2fItNE5nf5mf9zEBgs0Qiz1sVypJeTQEg9o/s1600/Untitled.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="356" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV5Q8YGizm_1QEhZALCAhOtXRkjt0sJ-z1KMmgJWDFOgSEf_30BhdEQbyKWpB_E0lIJjNJxljsJO1tdIrfhmFshy1fqyzM4HCCz7MksD9y2fItNE5nf5mf9zEBgs0Qiz1sVypJeTQEg9o/s640/Untitled.png" width="640" /></a></div>
<div lang="en-US" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div lang="en-US" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Pay attention, that I set checkboxes at "Allow at Queue Time" section - it shows parameter in the dialog window during queue and set secret for <i>Password</i> variable. But you can't clear this field and turn off secret - in this case a developer who starts a build has to enter own credential.</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg45bBq9atfa1qhIe88Z91y9BVFprrLEh39EtBqqh8iy5q0MLPS0GLXWeJNzKnYWFdApgfryVLFlIIJJbTYq342JjcjTLhmoUcRbjR2VIHtYh5F5KBEIAmd6_FCQZsWXFbZEgTwvhHGcOA/s1600/Untitled1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg45bBq9atfa1qhIe88Z91y9BVFprrLEh39EtBqqh8iy5q0MLPS0GLXWeJNzKnYWFdApgfryVLFlIIJJbTYq342JjcjTLhmoUcRbjR2VIHtYh5F5KBEIAmd6_FCQZsWXFbZEgTwvhHGcOA/s320/Untitled1.png" width="318" /></a></div>
<div lang="en-US" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div lang="en-US" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
So in such simple way, I added the possibility to deploy website without adding new add-ons to TFS.</div>
<div lang="en-US" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com0tag:blogger.com,1999:blog-1801684018053244846.post-56526550407705130242013-07-06T04:01:00.001-07:002013-07-10T11:34:43.324-07:00Migration to ASP.NET MVC 4: Deployment.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQsl9w2GQ-DCYAqTGQpz7zE5E_A2lbmgVWCFAJX9VgtGb5z1uel" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQsl9w2GQ-DCYAqTGQpz7zE5E_A2lbmgVWCFAJX9VgtGb5z1uel" /></a></div>
<br />
<div style="text-align: justify;">
<span class="gmw_"><span class="gmw_">We are developing ASP.NET MVC application. We are using a latest version of the frameworks. So I need to update a software after each framework's upgrade. It easy to do on the developer's machine: you can use <a href="http://www.asp.net/mvc/mvc4" target="_blank">web or standalone installer</a> or </span><a href="http://nuget.org/packages/aspnetmvc" target="_blank"><span class="gm_ gm_e8abc1c7-892f-adcb-c7a9-579dfca6ebe0 gm-spell">nuget</span></a></span> package.</div>
<div style="text-align: justify;">
Usual I used to run installer on the server for the previous version of ASP.NET MVC. But I noticed that installer for ASP.NET MVC 4 contains SQL Express Server and Visual Studio Express 2012 for Web. They are definitely not tools for the server's PC. I carried on with googling and found out that ASP.NET MVC 4 doesn't need any extra library in GAC. It requests .NET Framework (4 or 4.5) on the server and it all.<br />
<a name='more'></a>I deployed my latest (created as ASP.NET MVC 4) project on the server and it run without any concerns. But when I deployed 'migrated' project, it was crashed. I checked log file and found that latest (ASP.NET MVC 4) libraries weren't included.</div>
<div style="text-align: justify;">
<span class="gmw_">To fixed it I needed to go in Visual Studio by the next path: <b><span class="gmw_"><span class="gmw_">Solution Explorer/</span></span><span class="gmw_"><span class="gm_ gm_dc5de031-a29b-f9ef-0f9b-a6dca7c94690 gm-spell">MyProject</span></span><span class="gmw_"><span class="gmw_">/References </span></span></b>and </span>change 'Copy Local' value to 'true' in the properties of the number included references. </div>
<div style="text-align: justify;">
List of references that I added and/or changed 'Copy Local' property in my project:</div>
<ul>
<li><span class="gmw_"><span class="gmw_">System.Web.<span class="gm_ gm_618e6932-3f4a-1e62-c779-043579085a3b gm-spell">Mvc</span></span></span></li>
<span class="gmw_"> </span>
<li>System.Web.Helpers</li>
<li>System.Web.WebPages</li>
<li>System.Web.WebPages.Deployment</li>
<li>System.Web.WebPages.Razor</li>
<li>System.Web.Razor </li>
</ul>
<div style="text-align: justify;">
Some of this references weren't included in my project, some of them were under <b>'Reference Manager'/Assemblies/Framework</b> some were under <b>'Reference Manager'/Assemblies/Extensions </b>- be aware.</div>
RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com1tag:blogger.com,1999:blog-1801684018053244846.post-85454710339904362412013-05-14T13:02:00.000-07:002013-05-15T01:24:38.108-07:00Developing ASP.NET MVC 4 Web Applications - passed.<div style="text-align: justify;">
<a href="http://www.lybecker.com/blog/wp-content/uploads/ASPNet_MVC.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="191" src="http://www.lybecker.com/blog/wp-content/uploads/ASPNet_MVC.png" width="200" /></a>I have successfully passed Exam 70-486: <a href="http://www.microsoft.com/learning/en/us/course.aspx?id=20486a#fbid=fuxjlDdRKLf" target="_blank">Developing ASP.NET MVC 4 Web Applications</a>.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
I used next sources for preparations:</div>
<ul>
<li style="text-align: justify;"><a href="http://www.microsoftvirtualacademy.com/training-courses/learn-html5-with-javascript-css3-jumpstart-training" target="_blank">Developing in HTML5 with JavaScript and CSS3 Jump Start</a>. </li>
<li style="text-align: justify;">I went throw HTML5&CSS4 features when preparing <a href="http://www.slideshare.net/RredCat/html5-introl" target="_blank">the next short presentation</a>. It was really helpful for me. I want to share one of the source that I used for my presentation - <a href="http://slides.html5rocks.com/#landing-slide" target="_blank">html5rocks</a>. It is very useful slides that describes and shows HTML5/CSS4 features.</li>
<li style="text-align: justify;"><a href="http://www.pluralsight.com/training/Courses/TableOfContents/aspdotnet-mvc-advanced-topics" target="_blank">ASP.NET MVC Advanced Topics</a>: there are a lot of useful courses. I took one of them, but honestly I am not sure that it was the best for preparation.</li>
<li style="text-align: justify;">And finally my experience.</li>
</ul>
From the other hand I filled problem with questions related to Azure and CSS. At least first one is topic for develop.RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com0tag:blogger.com,1999:blog-1801684018053244846.post-63835750349488737382013-03-24T06:45:00.000-07:002013-03-24T06:45:19.947-07:0010gen: M101P MongoDB for Developers - has been completed<div style="text-align: justify;">
I have successfully completed, with distinction, M101P, MongoDB for Developers (Python). My score puts me in the top 6% of all students who registered for the course.</div>
<div style="text-align: justify;">
My final grade:
<span class="grade-value">95%</span>. </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://s3.amazonaws.com/edu-cert.10gen.com/downloads/8e7299fde1b54345ad8c7755ed459499/Certificate.pdf" target="_blank"><img border="0" height="222" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqkpX64quN4bfdLdDUG5vXxSeYzqcU6jItMjNpw05jywRlJXnwzR1Ydt4ZwQ7bqjT6hFxVXQMCUOkIT9owuQPOdTyLo0SkEvsC_sCDq_LjshAA1iF53X8s_s4RsuxRjg7ZGrToEa01ul4/s320/Untitled.png" width="320" /></a></div>
<div style="text-align: justify;">
<br /></div>
RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com0tag:blogger.com,1999:blog-1801684018053244846.post-11127549824755821552012-07-16T10:21:00.000-07:002012-07-16T22:31:41.294-07:00How to force to update JavaScript and CSS files after deploying new version of ASP.NET MVC application.<div style="text-align: justify;">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://captico.com/wp-content/uploads/2010/12/CSS-Tricks-Error-Page.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="126" src="http://captico.com/wp-content/uploads/2010/12/CSS-Tricks-Error-Page.png" width="200" /></a></div>
Usually after each deployment my ASP.NET MVC (Razor view) site I have a little mess with cached JavaScript and CSS files. Sometimes user's browsers show unappropriated view or some client functionality doesn't work.<br />
Yeah, it is very easy to fix - just clear browser cache or reload JavaScript and CSS files (press CTRL+F5). But I want user to avoid this annoying action moreover not all users are so familiar with PC to know this trick.</div>
<div style="text-align: justify;">
My friend <a href="http://www.linkedin.com/pub/mykhaylo-artymyshyn/24/183/633" target="_blank">Mykhailo</a> found nice solution for this. If I add parameter to JavaScript's url and will change parameter's value after each deployment. Browser will recognize it as other script and will update file.<br />
So now I should add something like "?v=xxxx" to all links of CSS and JavaScript files in my project and keep in mind it for future links. Looks not really smart solution doesn't it?<br />
First of all I want to say that I set JavaScript and CSS files in "Razor" style. For instance:<br />
<br />
<a name='more'></a><br />
<pre style="background: white; color: black; font-family: Consolas; font-size: 19;"><span style="color: blue;"><</span><span style="color: maroon;">link</span> <span style="color: teal;">href</span><span style="color: blue;">=</span><span style="color: blue;">"</span><span style="background: none repeat scroll 0% 0% yellow;">@</span><span style="color: blue;">Url</span><span style="color: blue;">.</span><span style="color: blue;">Content</span><span style="color: blue;">(</span><span style="color: #a31515;">"~/Content/Site.css"</span><span style="color: blue;">)"</span> <span style="color: teal;">rel</span><span style="color: blue;">=</span><span style="color: blue;">"...</span>
</pre>
<br />
In this case I just need to find way override <code>"Content"</code> method. Ok I've done it:<br />
<br />
<pre style="background: white; color: black; font-family: Consolas; font-size: 19;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">UrlHelperEx</span> : <span style="color: #2b91af;">UrlHelper</span>
{
<span style="color: blue;"> #region</span> Constants
<span style="color: blue;">private</span> <span style="color: blue;">const</span> <span style="color: blue;">string</span> c_VERSION_FORMAT = <span style="color: #a31515;">"{0}?v={1}"</span>;
<span style="color: blue;"> #endregion</span>
<span style="color: blue;"> #region</span> Initialization
<span style="color: blue;">public</span> UrlHelperEx(<span style="color: #2b91af;">RequestContext</span> requestContext)
: <span style="color: blue;">base</span>(requestContext)
{
}
<span style="color: blue;"> #endregion</span>
<span style="color: blue;"> #region</span> Public methods
<span style="color: blue;">public</span> <span style="color: blue;">new</span> <span style="color: blue;">string</span> Content(<span style="color: blue;">string</span> contentPath)
{
<span style="color: blue;">var</span> content = <span style="color: blue;">base</span>.Content(contentPath);
<span style="color: #2b91af;">Version</span> version = <span style="color: #2b91af;">WebHelper</span>.GetVersion();
<span style="color: blue;">return</span> <span style="color: blue;">string</span>.Format(c_VERSION_FORMAT, content
, version.Build.ToString(
<span style="color: #2b91af;">CultureInfo</span>.InvariantCulture));
}
<span style="color: blue;"> #endregion</span>
}</pre>
<br />
Please, pay attention - I've used <code>"new"</code> key world for <code>"Content"</code> method.<br />
Razor's view bases on <code>"</code><code><code></code>WebViewPage" </code>and <code></code><code><code>"</code><code><code></code>WebViewPage<t><t><T>" </t></t></code></code>classes. So I extended to use new <code>"UrlHelper</code><code>"</code> class them.<br />
<pre style="background: white; color: black; font-family: Consolas; font-size: 19;"><span style="color: blue;">public</span> <span style="color: blue;">abstract</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">WebViewPageEx</span> : <span style="color: #2b91af;">WebViewPage</span>
{
<span style="color: blue;"> #region</span> Properties
<span style="color: blue;">public</span> <span style="color: blue;">new</span> <span style="color: #2b91af;">UrlHelperEx</span> Url
{
<span style="color: blue;">get</span>;
<span style="color: blue;">set</span>;
}
<span style="color: blue;"> #endregion</span>
<span style="color: blue;"> #region</span> Public methods
<span style="color: blue;">public</span> <span style="color: blue;">override</span> <span style="color: blue;">void</span> InitHelpers()
{
<span style="color: blue;">base</span>.InitHelpers();
Url = <span style="color: blue;">new</span> <span style="color: #2b91af;">UrlHelperEx</span>(ViewContext.RequestContext);
}
<span style="color: blue;"> #endregion</span>
}
<span style="color: blue;">public</span> <span style="color: blue;">abstract</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">WebViewPageEx</span><tmodel><t><T> : <span style="color: #2b91af;">WebViewPage</span><tmodel>
{
<span style="color: blue;"> #region</span> Properties
<span style="color: blue;">public</span> <span style="color: blue;">new</span> <span style="color: #2b91af;">UrlHelperEx</span> Url
{
<span style="color: blue;">get</span>;
<span style="color: blue;">set</span>;
}
<span style="color: blue;"> #endregion</span>
<span style="color: blue;"> #region</span> Public methods
<span style="color: blue;">public</span> <span style="color: blue;">override</span> <span style="color: blue;">void</span> InitHelpers()
{
<span style="color: blue;">base</span>.InitHelpers();
Url = <span style="color: blue;">new</span> <span style="color: #2b91af;">UrlHelperEx</span>(ViewContext.RequestContext);
}
<span style="color: blue;"> #endregion</span>
}</tmodel></t></tmodel></pre>
Pay attention - I've used <code>"new"</code> key again. So I've replaced method and properties from base classes and I don't need to do any changes in my views.<br />
Now I need to replace base classes for views in my project. How to do it I've found in the this great article - "<a href="http://haacked.com/archive/2011/02/21/changing-base-type-of-a-razor-view.aspx" target="_blank">Changing Base Type Of A Razor View</a>". So I replaced next line in Web.config <b>that is located in Views folder.</b><br />
<pre class="csharpcode"><code>
</code></pre>
<pre class="csharpcode"><code> <span class="kwrd"><</span><span class="html">pages</span> <b><span class="attr">pageBaseType</span><span class="kwrd">="System.Web.Mvc.WebViewPage"</span></b><span class="kwrd">></span></code></pre>
<pre class="csharpcode"><code><span class="kwrd"> </span></code></pre>
with
<br />
<pre class="csharpcode"><code> <span class="kwrd"><</span><span class="html">pages</span> <b><span class="attr">pageBaseType</span><span class="kwrd">="MyNamespace.WebViewPageEx"</span></b><span class="kwrd">></span></code></pre>
<pre class="csharpcode"><code><span class="kwrd"> </span></code></pre>
And version of current build is added to each CSS and JavaScript's url in my project now.<br />
It was "pros" and now a few words about "cons". I have a lot of "default" CSS and JavaScript files. For instance of jQuery, third part components and so on. I don't change this files from build to build but they are updated after build. It is possible to implement some extra logic in <code>"Content"</code> method for skipping such files or use old school way adding url. for instance:<br />
<code>
<link <br="" href="../../Scripts/jquery/jquery-ui-1.8.5.custom/css/custom-theme/jquery-ui-1.8.5.custom.css"></link></code><br />
<br />
<code>
<link href="../../css/custom-theme/jquery-ui-1.8.5.custom.css" rel="...<br />
</code><br />
But in my opinion it is whims and current implementation is enough.<br />
<br />
<b>PS:</b> I'm pretty sure that it is possible to do something like for any view engines in ASP.NET MVC.</div>
RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com4tag:blogger.com,1999:blog-1801684018053244846.post-41067446954569175802012-06-13T08:19:00.000-07:002012-06-13T08:19:15.430-07:00Route of executing in Controller of ASP.NET MVC<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.naturaltherapy4u.com/communities/9/004/008/652/319/images/4541428397.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="200" src="http://www.naturaltherapy4u.com/communities/9/004/008/652/319/images/4541428397.jpg" width="160" /></a></div>
<div style="text-align: justify;">
Base classes of controller is ASP.NET MVC have number of methods for initialization before your code runs in an action. Lets review them.</div>
<div style="text-align: justify;">
<br /></div>
<ul style="text-align: justify;">
<li>First of all about constructor. You can't do a lot in it because most of properties aren't initialized yet and you will get NullReferenceException if try to use them.</li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.controllerbase.execute.aspx" target="_blank">Execute</a> is inherited from IController interface and manages all other initialization methods. Usually you have to avoid override it.</li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.controllerbase.initialize.aspx" target="_blank">Initialize</a> sets <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.controllerbase.controllercontext.aspx" target="_blank">ControllerContext</a>. You should to override it if you need to set culture so on.</li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.executecore.aspx" target="_blank">ExecuteCore</a> is called to process request and responsible for loading TempData.</li>
<li>If I want to predefine some information (grab data from Session and so on) You should use <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.onactionexecuting.aspx" target="_blank">OnActionExecuting</a>. This methods is called just before executing your action method.</li>
<li>And finally you should use <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.onactionexecuted.aspx" target="_blank">OnActionExecuted</a> for any finalization after executing your code. </li>
</ul>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
PS: During preparing for this post I've used <a href="http://wiki.sharpdevelop.net/ILSpy.ashx" target="_blank">ILSpy</a>. It is excellent free substitute for <a href="http://www.reflector.net/" target="_blank">.NET Reflector</a> (it is payment tool now).<a href="http://wiki.sharpdevelop.net/ILSpy.ashx" target="_blank"></a></div>RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com1tag:blogger.com,1999:blog-1801684018053244846.post-42511374088152930472011-12-27T16:38:00.000-08:002011-12-27T16:44:05.683-08:00Introduction to Artificial Intelligence<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh128PL7bnYy08x5-NdnB4QxAsZ0kcfHOjnh7YV_ISOMWEdezDncyvV7Ou2CzZK-9sz-k-JmAqo6Sx5oGvdBvdu_5wahisjmao2vPMKL0WPFus657AlyAFP_9wxk87fdK1ZoZdVxW9Ge-2D/s1600/head.png" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh128PL7bnYy08x5-NdnB4QxAsZ0kcfHOjnh7YV_ISOMWEdezDncyvV7Ou2CzZK-9sz-k-JmAqo6Sx5oGvdBvdu_5wahisjmao2vPMKL0WPFus657AlyAFP_9wxk87fdK1ZoZdVxW9Ge-2D/s1600/head.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Introduction to AI</td></tr>
</tbody></table>
<div style="text-align: justify;">
Some time ago I have joined to <a href="http://www.ai-class.com/" target="_blank">Introduction to Artificial Intelligence</a> it is online course that is based on Stanford CS221, Introduction to Artificial Intelligence.</div>
<div style="text-align: justify;">
This class introduced students to the basics of Artificial Intelligence, which included machine learning, probabilistic reasoning, robotics, and natural language processing.</div>
<div style="text-align: justify;">
My reason to join this class was simple I wanted to know more. I took 82% it isn't so bad for not native speaker.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiL5nQcBBe812OwczTumMIle2Bov3QSI25RYdTjXBSGScRM5w2PhoUXEerJZmmZWfcqdTYe5uQ_RRHgmqMVvYmx4AvEuPNQgs_FSxKg_2o2R6Jrdklrn8HypZ9rJHLF6TsRwaUrS9EdNIc/s640/ai.png" target="_blank"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE3uOjQ3y7ekLvIR9jX8IcPjdC8LPuIp6KQFPcvhUMhkBFsGpoTjp7gZOyZbW4nNMXsJKyTiv_9rTIyArfoVcUNO0vAS9i3y5KjvyF-jboLNoTy_dn7PtxRA_uVMNkUAFPMea4Hd6yae_V/s200/ai.png" width="183" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div style="text-align: justify;">
If you want to get more <span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">
</span> you can join a lot of next online <span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">courses
</span>- <a href="http://www.class-central.com/">http://www.class-central.com/</a></div>RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com0tag:blogger.com,1999:blog-1801684018053244846.post-38562659397800680202011-08-16T06:49:00.000-07:002011-08-16T14:24:47.555-07:00Trouble with resources in WP7<div style="text-align: justify;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1_AVjO4wTPVQ4xN1jjnoOvOwrioQXsmK5oBz5ZjYznUCgv4pSM2VCrelTx5nA53WJVdOalferWWQVVYH1K8EpZLqek_PCgPR8O5L1qWgfWE_cQNcC4lG_JL7ADL69vBidNYJtmTe3EUY/s1600/The_world_flag_2006.png"><img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 200px; height: 125px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1_AVjO4wTPVQ4xN1jjnoOvOwrioQXsmK5oBz5ZjYznUCgv4pSM2VCrelTx5nA53WJVdOalferWWQVVYH1K8EpZLqek_PCgPR8O5L1qWgfWE_cQNcC4lG_JL7ADL69vBidNYJtmTe3EUY/s200/The_world_flag_2006.png" alt="" id="BLOGGER_PHOTO_ID_5640338046283718610" border="0" /></a>I started a few projects on WP7. It was done just for fun and for improving my skills (Fun was profitable - <a href="http://ghostsofideas.blogspot.com/2011/07/wp7-kinect.html">I won in Ukrainian WP7 competition</a>). So I had completed my projects and tried to localize it.
<br /></div>I met some issues:
<br /><ol><li style="text-align: justify;">If you have experience in developing for web silverlight - first isn't new for you. When I edit/add/remove a item in resources's file I need to open resources designer's file and change <span class="st">access modifiers of parameterless </span>constructor from "internal" to "public".
<br />It is know issue and know fix - <a href="http://www.dotnetcurry.com/ShowArticle.aspx?ID=643">proof</a>.
<br /></li><li style="text-align: justify;">Second was new for me. It is strange issue because it appeared only in one of my projects. I created resources file and added key in Resources section of app.xaml (for binding to resources in my xaml files). My project started to crash after this.
<br />I had spent some time and found source of the issue. I noticed that Resource class (auto generated) is internal. I checked <span>"Custom tool" field in properties of resource file. It was filled "ResXFileCodeGenerator" value. In my other projects this field contained "</span>PublicResXFileCodeGenerator<span>" value. I didn't found detailed description of "ResXFileCodeGenerator" but looks like that it is obsolete tool. I no idea how to it was set in my project.</span></li></ol>One more note: it is for WP7 without "Mango" update. I hope I will not meet such issues after this update.
<br />RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com0tag:blogger.com,1999:blog-1801684018053244846.post-22282164936785420512011-02-07T06:05:00.000-08:002011-02-07T09:07:11.901-08:00Trimmed TextBlock for Windows Phone 7.<div style="text-align: justify;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://steliq.com/c/lm/0/01/12356266_windows-phone-7-wp7-review.jpg"><img style="float: right; margin: 10pt 0pt 10px 10px; cursor: pointer; width: 135px; height: 110px;" src="http://steliq.com/c/lm/0/01/12356266_windows-phone-7-wp7-review.jpg" alt="" border="0" /></a>Unfortunately WP7 is based on Silverlight 3. So we can't use some nice features of Silverlight 4 i.e. <span style="color: rgb(51, 102, 255); font-style: italic;">dynamic</span> key word or TextBlock's trimming. But I've solved issue with trimming for Silverlight 3. Solution is <a href="http://rredcat.blogspot.com/2010/03/trimmed-textblock-for-silverlight.html">here</a>. Let me explain which code I use in WP7 project:<br /></div><ul><li style="text-align: justify;"><span style="font-weight: bold;">Generic.xaml</span>: File contains style and template for custom control. This file is located in Themes folder. WP7 tools doesn't contains Resources.xaml file template. So I created xml file and name it as "Generic.xaml".<br /></li><li style="text-align: justify;"><span style="font-weight: bold;">TrimmedTextBlock.cs</span>: It is implementation of custom control. I just copied this file. One more note: I decrement c_POINTS_COUNT to "1" because screen resolution of desktop and mobile versions are different.</li></ul>Easy coding.RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com2tag:blogger.com,1999:blog-1801684018053244846.post-14613322041134689212010-12-15T11:29:00.000-08:002011-09-30T07:39:14.341-07:00"using" directive in aspx's pages.<div style="text-align: justify;">
It is funny but I don't know about this. I used full name of type (namespace+type name) in aspx pages. It is unnecessary. ASP.NET has directive for this.<br />
<%@ Import namespace="value" %><br />
Sometime we omit in haste important things.<br />
<br />
UPD: And more easy for Razor view engine:<br />
@using MyNamespace<code><span class="typ"></span><span class="pln">
</span></code></div>
RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com0tag:blogger.com,1999:blog-1801684018053244846.post-92023372247122267492010-11-15T13:48:00.000-08:002010-11-15T14:04:29.949-08:00ASP.NET MVC aplication inside in an iframe (fix issue with empty session).<div style="text-align: justify;">I developed application using ASP.NET MVC framework. It worked well but when I put my app inside of iframe I founded that in some case in Internet Explorer application missed session.<br />I started to investigate for the source of the issue.<br />I founded that application worked well if I decrease security level in the IE. But this fix weren’t suitable for me (I can`t request something in the customers). So I carried on with investigation.<br />Well description what happen I founded on the follow <a href="http://support.microsoft.com/kb/323752/ja">page</a> (unfortunately, I didn’t found English version of this page, so I used google translate for figure out this article).<br />So for fix this I should add “PSP” header to response. How can I do it for the ASP.NET MVC application? In classic ASP.NET it is easy to do in code behind or in aspx file. I overrode ExecuteResult method in all classes inherited from ActionResult that used in my application. ViewResult for example:<br /></div><code>public class CustomViewResult : ViewResult<br /> {<br /> public override void ExecuteResult(ControllerContext context)<br /> {<br /> context.HttpContext.Response.AddHeader("P3P", "CP=\"CAO PSA OUR\"");<br /> base.ExecuteResult(context);<br /> }<br /> }</code><br /><div style="text-align: justify;">After it I used my customized classes in base controller of all controllers in application (It was very nice idea to implement one base controller for all other controllers, wasn't it?). For example:<br /></div><code>public class BaseController : Controller<br /> {<br /> protected override ViewResult View(string viewName, string masterName, object model)<br /> {<br /> if (model != null)<br /> {<br /> base.ViewData.Model = model;<br /> }<br /><br /> return new CustomViewResult<br /> {<br /> ViewName = viewName,<br /> MasterName = masterName,<br /> ViewData = base.ViewData,<br /> TempData = base.TempData<br /> };<br /> }<br /> }</code><br /><div style="text-align: justify;">For figure out which methods I need to override I used cool tools - <a href="http://www.red-gate.com/products/reflector/">.NET Reflector.</a></div>RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com0tag:blogger.com,1999:blog-1801684018053244846.post-46958883875534515442010-09-16T12:19:00.000-07:002010-09-16T14:17:40.715-07:00Unit Tests for ASP.NET MVC application that uses resources in code behind.<a style="" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicayFzIEi1umlfuGaQmeqA2aBcepOQVWngqz4I-nZEMX-ka6kq75_RBIwaBCuJG8R1Y0GxLQHY40esJvNk8A4wu9o0lHkiCWgqebVPoEYO3gQDbYWCjrfBRIDIQgmBjgGkGJuPutneR00/s1600/test.jpg"><img style="float: right; margin: 0pt 0pt 10px 10px; cursor: pointer; width: 200px; height: 200px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicayFzIEi1umlfuGaQmeqA2aBcepOQVWngqz4I-nZEMX-ka6kq75_RBIwaBCuJG8R1Y0GxLQHY40esJvNk8A4wu9o0lHkiCWgqebVPoEYO3gQDbYWCjrfBRIDIQgmBjgGkGJuPutneR00/s200/test.jpg" alt="" id="BLOGGER_PHOTO_ID_5517595673647608386" border="0" /></a>Download source files - <a href="http://code.google.com/p/snoopmyversion/downloads/detail?name=ResourcesUnitTests.zip&can=2&q="><span style="font-style: italic;">here</span></a>.<br /><br /><div style="text-align: justify;">Some time ago I start to play with ASP.NET MVC. It is very well pattern and Microsoft made nice choose that implemented it for ASP.NET in my opinion.<br /></div><div style="text-align: justify;">I started a project that uses ASP.NET MVC. This project requests multilingual support. I use resources for this. It works well when I use resource's properties in the View's layer but when I call resource's properties from code behind. It's something likes to next:<br /></div><pre name="code" class="csharp">public ActionResult Index()<br />{<br />ViewData["Message"] = CommonResource.WELCOME;<br />return View();<br />}<br /></pre><div style="text-align: justify;">It works but I pay attention that this code breaks my Unit Tests. My Unit Tests looks like:<br /></div><pre name="code" class="csharp">[TestMethod]<br />public void Index_Test()<br />{<br />//// Arrange<br />var controller = new HomeController();<br /><br />// Act<br />var result = controller.Index();<br /><br />// Assert<br />Assert.IsInstanceOfType(result, typeof(ViewResult));<br />}</pre><div style="text-align: justify;">It happens because I run my code in other project and my ResourceManager is not filled (it equals to null). How can I fix it? A first idea that came to mind is "extract interface".. but it is very annoying because resource's class is auto-generate and I should update this code after each updating of resources.. I made some research and found additional way for extracting resources - HttpContext contains <a href="http://msdn.microsoft.com/en-us/library/system.web.httpcontext.getglobalresourceobject.aspx">GetGlobalResourceObject</a> method! It is well way because I can set mock for HttpContext and for any its methods or properties.<br /><br /></div><div style="text-align: justify; font-style: italic;"><span><span style="font-weight: bold;">Note:</span> </span>GetGlobalResourceObject returns object but I use only strings for localization. So I create linq method for HttpContext that returns string if it presents:<br /></div><pre style="font-style: italic;" name="code" class="csharp">public static string GetGlobalResource(<br /> this HttpContextBase httpContext<br /> , string classKey, string resourceKey)<br />{<br />var result = httpContext.GetGlobalResourceObject<br /> (classKey, resourceKey);<br />return null != result<br /> ? result.ToString() : string.Empty;<br />}<br /></pre><span style="font-style: italic;">Pay attention, MissingManifestResourceException is possible in this code if you pass incorrect key/keys! </span><br /><br />So I change pieces of code in Controller's classes in the next manner:<br /><pre name="code" class="csharp">public ActionResult Index()<br />{<br />ViewData[CommonStrings.MESSAGE] = HttpContext<br /> .GetGlobalResource(CommonStrings<br /> .COMMON_RESOURCE, CommonStrings.WELCOME);<br />return View();<br />}</pre>After it I should change my Unit Test's methods in next manner:<br /><pre name="code" class="csharp">[TestMethod]<br />public void Index_Test()<br />{<br />//// Arrange<br />var httpContextMock = MockRepository<br /> .GenerateMock<HttpContextBase>();<br />httpContextMock.Stub<br /> (x => x.GetGlobalResource(<br /> CommonStrings.COMMON_RESOURCE, CommonStrings.WELCOME))<br /> .Return(CommonStrings.WELCOME);<br /><br />var controller = new HomeController();<br />var context = new ControllerContext<br /> (httpContextMock, new RouteData(), controller);<br />controller.ControllerContext = context;<br /><br />// Act<br />var result = controller.Index();<br /><br />// Assert<br />Assert.IsInstanceOfType(result, typeof(ViewResult));<br />ViewDataDictionary viewData = ((ViewResult)result).ViewData;<br />Assert.AreEqual(CommonStrings.WELCOME<br /> , viewData[CommonStrings.MESSAGE]);<br />}</pre><div style="text-align: justify;">Moreover, you can see that I added additional checking related to localization.<br /></div>RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com1tag:blogger.com,1999:blog-1801684018053244846.post-61327307654326125812010-03-24T08:01:00.001-07:002010-05-04T00:05:07.770-07:00Trimmed TextBlock for Silverlight.<a style="" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj572Fs72QR6W-sv0ANU72N6nQpv0aSWynkorZGArbaElH-aldQILYvuwlLGWfLyziI_BMDTtwhDrgDQjuiqACUSdh3H3V6nwixqhO68gQrnA4_m7RCwRTEj_Jv6YggtHPimEyKaAiSsLk/s1600/Untitled.png"><img style="margin: 10pt 0pt 10px 10px; float: right; cursor: pointer; width: 278px; height: 102px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj572Fs72QR6W-sv0ANU72N6nQpv0aSWynkorZGArbaElH-aldQILYvuwlLGWfLyziI_BMDTtwhDrgDQjuiqACUSdh3H3V6nwixqhO68gQrnA4_m7RCwRTEj_Jv6YggtHPimEyKaAiSsLk/s320/Untitled.png" alt="" id="BLOGGER_PHOTO_ID_5452292440484503554" border="0" /></a>Download source files - <a href="http://snoopmyversion.googlecode.com/files/TrimmingTextAplication_new.zip"><span style="font-style: italic;">here</span></a><br /><br /><div style="text-align: justify;">Not always Silverlight TextBlock that contains long text has enough space for shows all this text. TextBlock clips text in this case - this behaviour isn't best way for this. Because I wait that TextBlock not only trims but also adds "..." to clipped text. WPF has brilliant property that helps to resolve this trouble - TextTrimming. I implemented this possibility for Silverlight and now want to present it for you. Furthermore I implemented ToolTip that shows trimmed text (only if text is trimmed!)<br /></div>Enjoy!<br /><br /><div style="text-align: justify;">UPD: I have just updated performance and behaviour when width defined zero.</div>RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com1tag:blogger.com,1999:blog-1801684018053244846.post-43710510057850730152010-02-24T03:07:00.000-08:002010-03-03T01:19:25.561-08:00Trips&Ticks: Easy way to navigate from XAML to class's definition.<div style="text-align: justify;"><a style="" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhgfw3YlzfmaPZM0VE914SiFQPmxdhBhvb20d_ahsSqiudaPNEuW9BJQEDTB4qolOE4_Lm_7AXrOxH27RyNRS0KaSLQIj9154X3t21gw44Rfz6ZowVTbHyHvGxbBV7TvdEQWRPmogpoFM/s1600-h/xamllogo.jpg"><img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 97px; height: 121px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhgfw3YlzfmaPZM0VE914SiFQPmxdhBhvb20d_ahsSqiudaPNEuW9BJQEDTB4qolOE4_Lm_7AXrOxH27RyNRS0KaSLQIj9154X3t21gw44Rfz6ZowVTbHyHvGxbBV7TvdEQWRPmogpoFM/s320/xamllogo.jpg" alt="" id="BLOGGER_PHOTO_ID_5444170054379605874" border="0" /></a>Working with XAML code in VS2008 I have just found that I can easy jump to class's or property definition. If I press CTRL and click left mouse button on certain class or property in XAML I will be immediately switched to Object Browser (if it is class or property of .NET or external dll) or to class's or property definition in my code (if it is class or property from my sources).<br /><div style="text-align: justify;"><a href="http://realnero.blogspot.com/">Eugene Dolinskyy</a> just pay my attention that "clear" VS2008 doesn't have this possibility. This feature is presented by <a href="http://www.jetbrains.com/resharper/">ReSharper</a>.<br /></div></div>RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com0tag:blogger.com,1999:blog-1801684018053244846.post-69429372902558024442010-01-25T13:33:00.000-08:002010-01-25T23:47:50.891-08:00Zoom event for FlowDocumentPageViewer (corrected)<a style="" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPbEXTp-EnQvbXmFlxl5Ousxt2hLHxnMDDNU5LxBRiMxkcSfOFZzGdFUHuaAxFEx8TvA9zKcDKr_9yxrD8p-f0ffmfuScOInbm4pOkcQymq2UzYwsfbUKDI_00QJ2speIxvOVxgSM1vvc/s1600/help_key.jpg"><img style="margin: 10pt 0pt 10px 10px; float: right; cursor: pointer; width: 165px; height: 137px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPbEXTp-EnQvbXmFlxl5Ousxt2hLHxnMDDNU5LxBRiMxkcSfOFZzGdFUHuaAxFEx8TvA9zKcDKr_9yxrD8p-f0ffmfuScOInbm4pOkcQymq2UzYwsfbUKDI_00QJ2speIxvOVxgSM1vvc/s320/help_key.jpg" alt="" id="BLOGGER_PHOTO_ID_5405961531917985170" border="0" /></a><span style="font-style: italic;">Download source files - <a href="http://snoopmyversion.googlecode.com/files/SearchVisualTree_new.zip">here</a><br /><br /></span><div style="text-align: justify;">When I wrote my article <span style="font-style: italic;"><a href="http://rredcat.blogspot.com/2009/11/zoom-and-page-chahged-events-for.html">Zoom and page chaged events for FlowDocumentPageViewer</a></span> I make mistake, you can read about it - <a href="http://wittersworld.com/post/2010/01/13/Zoom-and-PageChanged-Events-for-FlowDocumentPageViewer.aspx">there</a>. However Martin offer solution for this problem. But I don't like this solution, overriding of <a href="http://msdn.microsoft.com/en-us/library/system.windows.dependencyobject.onpropertychanged.aspx">OnPropertyChanged</a> isn't best solution because this method is risen in many cases so any logic there is serious performance issue.<br /></div><div style="text-align: justify;">So how can we fix it in other way? We can find object of <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.slider.aspx">Slider</a> in Visual Tree of <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.flowdocumentpageviewer.aspx">FlowDocumentPageViewer</a> and subscribe to <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.rangebase.valuechanged.aspx">ValueChanged</a> event and call OnZoomChanged(); there.<br /></div><div style="text-align: justify;">Bingo! It fixes my trouble.</div>RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com0tag:blogger.com,1999:blog-1801684018053244846.post-28105952285516123212010-01-24T00:46:00.001-08:002010-01-24T01:02:56.816-08:00Trips&Ticks: How to implement GroupName for RadioButton in WPF DataGrid's column?<a style="" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifwEzR-CG8feEsW_jgTSOL1X4smEM7WYcErANYqSTUzdcYQoBucqJXa7pF-AQsm7ZwsEPst2MYXc_FNur8Abb1YNi532c605qaTUGae2gNEp7QjwbrZwZKFtw-q_OaaTlK1giFhfzkoz4/s1600-h/column2.jpg"><img style="margin: 10pt 0pt 10px 10px; float: right; cursor: pointer; width: 181px; height: 254px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifwEzR-CG8feEsW_jgTSOL1X4smEM7WYcErANYqSTUzdcYQoBucqJXa7pF-AQsm7ZwsEPst2MYXc_FNur8Abb1YNi532c605qaTUGae2gNEp7QjwbrZwZKFtw-q_OaaTlK1giFhfzkoz4/s320/column2.jpg" alt="" id="BLOGGER_PHOTO_ID_5430228816203812034" border="0" /></a><span style="font-style: italic;">Download source files - <a href="http://snoopmyversion.googlecode.com/files/DataGridIntro.zip">here</a></span><br /><br /><div style="text-align: justify;">It is very easy. We should use DataGridTemplateColumn for this. My acquaintance requested to me show it. I added source code where implemented this.<br /><br /></div><span style="font-weight: bold;">Some notes:</span><br /><ul style="text-align: justify;"><li>You should turn off AutoGenerateColumns feature. In other case control will have duplicate values. </li><li>I recommend to turn off CanUserAddRows. In other case user can pick undefined row. <br /></li></ul><div style="text-align: justify;">Enjoy Yulian ;).<br /></div>RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com1tag:blogger.com,1999:blog-1801684018053244846.post-42166603259529061982010-01-15T01:11:00.000-08:002010-01-21T07:52:05.669-08:00Web access to Team Foundation Server.<div style="text-align: justify;"><a style="" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEojMRirBLy7pnx10SvGAe3YpSQ0hNZZtqnxNi-Nx8QvunLBfKeTB_b0msmj0dua1eN8u8lFg0zRjYutPgP9JqS1cdojNFdffUOqahqOOevlb94fbw9zeDgHkoFpgES3Hkcb0cMEmVXxw/s1600-h/TeamPlain.png"><img style="margin: 10pt 0pt 10px 10px; float: right; cursor: pointer; width: 225px; height: 53px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEojMRirBLy7pnx10SvGAe3YpSQ0hNZZtqnxNi-Nx8QvunLBfKeTB_b0msmj0dua1eN8u8lFg0zRjYutPgP9JqS1cdojNFdffUOqahqOOevlb94fbw9zeDgHkoFpgES3Hkcb0cMEmVXxw/s320/TeamPlain.png" alt="" id="BLOGGER_PHOTO_ID_5429211519671788002" border="0" /></a>I have been starting to work with Team Foundation Server as source control and bag tracking system for 2 month. In this time we migrated from one TFS to another. So sometime we needed access to both these servers (one as bug track, another as source control). I said to my manager about web access tool for TFS he heard it already that this tool is very cool but expensive.<br /></div><div style="text-align: justify;">It isn't truth. This tool is useful but full freeware! Because <a href="http://blogs.msdn.com/bharry/archive/2007/03/26/microsoft-acquires-teamplain.aspx">Microsoft Acquired TeamPlain</a> 3 year ago :). When I tried to find it - I was a bit disappointed I couldn't found this tool - all links were broken. Little find out shows that TeamPlain is renamed to Team System Web Access. I founded article that describes <a href="http://msdn.microsoft.com/en-us/library/bb822178.aspx">How to: Install Team System Web Access</a> (this page also contains broken link to installation of Team System Web Access :) ) and after all I found <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=3ECD00BA-972B-4120-A8D5-3D38311893DE&displaylang=en">download page</a>.<br />That isn't fresh news, but it is very upset that this useful tool is so hard for found.<br /></div>RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com0tag:blogger.com,1999:blog-1801684018053244846.post-51810925205548324522009-11-24T06:51:00.000-08:002009-11-24T11:05:39.644-08:00Useful code snippets for WPF developer.<div style="text-align: justify;"><span style="font-style: italic;">Download snippets </span><span style="font-style: italic;">- <a href="http://snoopmyversion.googlecode.com/files/NetFX30.zip">here</a></span><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcyOHP0F3BHpbg2o9EpsuwE4WgS9RkHg3r1mtqAFYca0IfNenTsO8ia7DbFeGlGMpDQzFSElCMeW-dpNqh3SX1X66ARNjBm6E_x7O9UVxWECPgXclhzyJPgRHsZurBZOf0oxnvr0x9mwI/s1600/Untitled.png"><img style="margin: 10pt 0pt 10px 10px; float: right; cursor: pointer; width: 320px; height: 192px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcyOHP0F3BHpbg2o9EpsuwE4WgS9RkHg3r1mtqAFYca0IfNenTsO8ia7DbFeGlGMpDQzFSElCMeW-dpNqh3SX1X66ARNjBm6E_x7O9UVxWECPgXclhzyJPgRHsZurBZOf0oxnvr0x9mwI/s320/Untitled.png" alt="" id="BLOGGER_PHOTO_ID_5407688290208843682" border="0" /></a>I want to share very useful in my opinion code snippets for WPF developers. Most of they were created my friend - <a href="http://immortalratblog.blogspot.com/">Dmitrij Zakharov.</a> Moreover I want to add a short description to each snippets.<br /><span style="font-style: italic; color: rgb(102, 0, 0); font-weight: bold;"><br />Note:</span><span style="font-style: italic;"> The Code Snippet Inserter inserts a code snippet at the cursor location, or inserts a surround-with code snippet around the currently selected code.</span><br /></div><br /><div style="text-align: justify;">Don't you know how to use code snippets? You should read next article - <a href="http://msdn.microsoft.com/en-us/library/z4c5cc9b.aspx">How to: Use Code Snippets (C#)</a>. You should copy the code snippets files to <span style="font-style: italic;" class="parameter">Installation directory</span>\Microsoft Visual Studio 9.0\VC#\Snippets\1033\NetFX30 in your PC for start to use.<br /></div><br />Let me start:<br /><ul style="text-align: justify;"><li><span style="font-weight: bold;">addowner</span> - Adds owner to the dependency property that already exists.</li><li><span style="font-weight: bold;">defstyle</span> - Code snippet for overriding DefaultStyleKey.</li><li><span style="font-weight: bold;">propa</span> - Code snippet for an attached property using DependencyProperty as the backing store. It is the common code snippet that is delivered with installation of VS2008 </li><li><span style="font-weight: bold;">propdp</span> - Code snippet for a property using DependencyProperty as the backing store. It is the common code snippet that is delivered with installation of VS2008<br /></li><li><span style="font-weight: bold;">propdpec</span> - Code snippet for a property with value caching and events support using DependencyProperty as the backing store.</li><li><span style="font-weight: bold;">propdpr</span> - Code snippet for a property using DependencyPropertyKey as the backing store.</li><li><span style="font-weight: bold;">routedcmd</span> - Implements routed command executor.</li><li><span style="font-weight: bold;">routedevent</span> - Declares and implements routed event.</li></ul><div style="text-align: justify;"><span style="font-weight: bold;">PS: </span>Do you want to know more? - read about <a href="http://msdn.microsoft.com/en-us/library/z41h7fat.aspx">Default Code Snippets</a>.<br /></div>RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com0tag:blogger.com,1999:blog-1801684018053244846.post-37519447602197377192009-11-19T15:17:00.000-08:002010-01-25T14:10:01.776-08:00Zoom and page changed events for FlowDocumentPageViewer<a style="" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPbEXTp-EnQvbXmFlxl5Ousxt2hLHxnMDDNU5LxBRiMxkcSfOFZzGdFUHuaAxFEx8TvA9zKcDKr_9yxrD8p-f0ffmfuScOInbm4pOkcQymq2UzYwsfbUKDI_00QJ2speIxvOVxgSM1vvc/s1600/help_key.jpg"><img style="margin: 10pt 0pt 10px 10px; float: right; cursor: pointer; width: 165px; height: 137px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPbEXTp-EnQvbXmFlxl5Ousxt2hLHxnMDDNU5LxBRiMxkcSfOFZzGdFUHuaAxFEx8TvA9zKcDKr_9yxrD8p-f0ffmfuScOInbm4pOkcQymq2UzYwsfbUKDI_00QJ2speIxvOVxgSM1vvc/s320/help_key.jpg" alt="" id="BLOGGER_PHOTO_ID_5405961531917985170" border="0" /></a><span style="font-style: italic;">Download source files - </span><a style="font-style: italic;" href="http://snoopmyversion.googlecode.com/files/SearchVisualTree.zip">here</a><br /><br />My old known Bala send to me this <a href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/4a127007-c673-45ea-9b25-81d87fcea5d9">link</a>.<br /><div style="text-align: left;"><div style="text-align: justify;">Kent Boogaart has written an article that describes approach searching and highlighting text in FlowDocumentPageViewer - <a href="http://kentb.blogspot.com/2009/06/search-and-highlight-text-in-arbitrary.html">Search and Highlight Text in an Arbitrary Visual Tree</a>. Unfortunate, two serious issues present there. I copy theirs description from msdn forum:<br /></div><ol><li style="text-align: justify;">When I change the pages of the FlowDocumentPageViewer, my Rectangular highlighted area remains the same and it is not sinking with the Text.</li><li style="text-align: justify;">When I zoom in or zoom out of the FlowDocumentPageViewer, the text gets zoomed but the Highlight rectangle remains in the same position. </li></ol><div style="text-align: justify;">Seems.. solution should be easy - just add DoSeach() method in PageChanged and ZoomChanged event handler methods of <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.flowdocumentpageviewer.aspx">FlowDocumentPageViewer</a> but it doesn't have events for notice these actions. So I decided just to implement these events :). <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.flowdocumentpageviewer.aspx">FlowDocumentPageViewer</a> doesn't have protected and virtual methods like OnZoomChanged or OnPageChanged. It was bad. But I found four protected and virtual methods that could help me they are OnNextPageCommand(), OnPreviousPageCommand(), OnIncreaseZoomCommand() and OnDecreaseZoomCommand(). When I added call to rise my events in theirs override methods I found that this approach wasn't work. It happened because command logic works through concurrency approach. I called the rise methods through <a href="http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.begininvoke.aspx">BeginInvoke</a> for delay the calls rise methods - and problem was solved.<br /></div><div style="text-align: justify;">You can download sources with fix above.<br /></div><br /><div style="text-align: left;">PS: I didn't have time for full investigate sources.. but one question. Why did Kent use SearchRectangle class? In my opinion common <a href="http://msdn.microsoft.com/en-us/library/system.windows.rect.aspx">Rect</a> is enough.<br /></div></div>RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com2tag:blogger.com,1999:blog-1801684018053244846.post-6333124775980748462009-11-16T07:10:00.000-08:002009-11-18T15:00:07.455-08:00How to implement TextBox with PlaceHolder in WPF<div style="text-align: justify;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFQIcWfFqu8AG4RgyGEDmEbaZBNzPieOt0TV1Ov9D7CfrnVDxvvsmn6Sv9xUp659OcWy6oFRcMTQ5L9DiLG22DrE9R7CPL9Zvpn38g90nBd2rvJYo2cUM0aygPLdm1F1xuUSfe8U-RgHs/s1600/logo.png"><img style="margin: 10pt 0pt 10px 10px; float: right; cursor: pointer; width: 278px; height: 117px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFQIcWfFqu8AG4RgyGEDmEbaZBNzPieOt0TV1Ov9D7CfrnVDxvvsmn6Sv9xUp659OcWy6oFRcMTQ5L9DiLG22DrE9R7CPL9Zvpn38g90nBd2rvJYo2cUM0aygPLdm1F1xuUSfe8U-RgHs/s320/logo.png" alt="" id="BLOGGER_PHOTO_ID_5404723663428938002" border="0"></a><span style="font-style: italic;">Download source files - </span><a style="font-style: italic;" href="http://snoopmyversion.googlecode.com/files/TextBoxWithPlaceHolder_src.zip">here</a><br /><br />Using PlaceHolder is very useful thing for UI in any type application. I want to show a short way how can you implement it in WPF.<br /><div style="text-align: justify;">You can custom <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.aspx">TextBox</a> and add place-holder text on <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.mouseenter.aspx">MouseEnter</a> and remove on <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.mouseleave.aspx">MouseLeave</a> events. In this case place-holder's text looks like original text.. You can experiment with <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.control.foreground.aspx">Foreground</a> property, but truth me - you will not be satisfy.<br /></div>Let my suggest other way. You can use <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.adornerlayer.aspx">AdornerLayer</a> for host the place-holder text. In this case you should create class that is inherit from <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.adorner.aspx">Adorner</a> and this class should show your place-holder text on <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.adornerlayer.aspx">AdornerLayer</a>. I've create little sample that demonstrate this.<br /><br />Unfortunate, <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.adornerlayer.aspx">AdornerLayer</a> doesn't presented over any <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.popup.aspx">Popup</a> controls. So this solution isn't worked if you put our customized TextBox control in any <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.popup.aspx">Popup</a> and as item in <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.menu.aspx">Menu</a> or <a href="http://msdn.microsoft.com/en-us/library/ms753382%28VS.85%29.aspx">ComboBox</a> controls.<br /></div>RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com0tag:blogger.com,1999:blog-1801684018053244846.post-36353194110278516712009-10-16T12:15:00.000-07:002009-11-16T23:44:27.135-08:00Performance degrades in your Silverlight App!? What can you do?<img style="margin: 20pt 0pt 10px 10px; float: right; cursor: pointer; width: 150px; height: 150px;" src="http://www.sparklingclient.com/wp-content/uploads/2009/03/silverlight_logo1-150x150.jpg" alt="" border="0" /><br />Some time ago I had written Silverlight app and I confronted with difficulties of difference between WPF and Silverlight :). When I had vanquished mismatches I found that performance of my app was serous degraded. I have done a little investigate of ways that can help to correct this issues.<br /><ol><li>MaxFrameRate</li><li>EnableGPUAcceleration & BitmapCash</li><li>CompositionTarget.Rendering</li></ol><a style="font-weight: bold; color: rgb(51, 51, 255);" href="http://msdn.microsoft.com/en-us/library/cc838147%28VS.95%29.aspx"><span>MaxFrameRate</span></a> - presents the maximum number of frames that Silverlight can render per second. The default value is 60 second. I've set 30 in my app - looks pretty. This property likes <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.animation.timeline.desiredframerate.aspx">DesiredFrameRate</a> in WPF. Target is clear - reduce frame rate. It is useful when more animations are started in Silverlight app.<br />You can set it from Silverlight code:<br /><br /><code>App.Current.Host.Settings.MaxFrameRate=30;</code><br /><br />or as parameter of object on HTML page:<br /><br /><code> <param name="framerate" value="30"> </code><br /><br />Pay attention there is a mismatch naming in Silverilght code and HTML. Why is it? You can read <a href="http://msdn.microsoft.com/en-us/library/cc838147%28VS.95%29.aspx">there</a>.<br /><br /><a style="color: rgb(51, 51, 255);" href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.cachemode%28VS.95%29.aspx"><span style="color: rgb(51, 51, 255); font-weight: bold;">EnableGPUAcceleration & BitmapCash</span></a> - allows to cache visual object when it is possible. You should switch on EnableGPUAcceleration that Cache has any effect. This approach is useful when your app <span>has opacity or transform operations applied to it</span>.<br />You can set it from Silverlight code:<br /><br /><code>You can't change it from Silverlight because it should be set before app's initialization.</code><br /><br />or as parameter of object on HTML page:<br /><br /><code><param name="EnableGPUAcceleration" value="true" /> </code><br /><br />and set CacheMode. In current moment <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.bitmapcache%28VS.95%29.aspx">BitmapCache</a> is supported only.<br />You can set it in C# code:<br /><br /><code>LayoutRoot.CacheMode = new BitmapCache();</code><br /><br />or in XAML:<br /><br /><code><Grid x:Name="LayoutRoot" CacheMode="BitmapCache"></code><br /><br />Some objects don't look well (high-resolution images for example) you can increase <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.bitmapcache.renderatscale%28VS.95%29.aspx">RenderAtScale</a> property of <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.bitmapcache%28VS.95%29.aspx">BitmapCache</a> class for avoid this mess. Default value of this property is 1, when I set 4 (like MSDN's samples) quality restores but performance degrades again. A value between 2-3 is god for my app.<br />You can set it in C# code:<br /><br /><code>LayoutRoot.CacheMode = new BitmapCache<br />{<br />RenderAtScale = 2.5,<br />};</code><br /><br />or in XAML:<br /><br /><code><Grid x:Name="LayoutRoot"><br /><Grid.CacheMode><br /><BitmapCache RenderAtScale="2.5" /><br /></Grid.CacheMode><br /></Grid></code><br /><br /><a style="color: rgb(51, 51, 255);" href="http://msdn.microsoft.com/en-us/library/system.windows.media.compositiontarget.rendering.aspx"><span style="font-weight: bold;">CompositionTarget.Rendering</span></a> - this event rises before the objects in the composition tree are rendered. How does it can help? In common case - doesn't. But if you zoom your object in app (or in same other manner move out of bounds some item) - it is very useful. Look in my case:<br />First - subscribe event handler's method in constructor of your main window:<br /><br /><code>CompositionTarget.Rendering += new EventHandler( OnCompositionTargetRendering );</code><br /><br />Second - handler method:<br /><code><br />private void OnCompositionTargetRendering( object sender, EventArgs e )<br />{<br />//--- Start 1 -- //<br />foreach ( GalleryItem item in xGalleryCanvas.Children )<br />{<br /> if ( Visibility.Collapsed == item.Visibility )<br /> {<br /> item.Visibility = Visibility.Visible;<br /> }<br />}<br />//--- End 1 -- //<br />//--- Start 2 -- //<br />if ( _isZoomed && 0 < rect =" new" visibleitems =" VisualTreeHelper.FindElementsInHostCoordinates(" f =""> f.GetType() == typeof( GalleryItem ) );<br /><br /> foreach ( GalleryItem item in xGalleryCanvas.Children )<br /> {<br /> if ( !visibleItems.Contains( item ) )<br /> {<br /> item.Visibility = Visibility.Collapsed;<br /> }<br /> }<br />//--- End 2 -- //<br />}</code><br />Some explanation: You should ascertain that all items are visible (block 1).<br /><u style="font-style: italic;">Note:</u> Dependency property works not so good as in WPF. So you should change Visibility only of collapsed items. In other case you serious reduce the performance.<br />Use mix of <a href="http://msdn.microsoft.com/en-us/library/cc838303%28VS.95%29.aspx">FindElementsInHostCoordinates()</a> of <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.visualtreehelper_members%28VS.95%29.aspx">VisualTreeHelper</a> and LINQ for create collection all visible items in current moment and collapse all other items (block 2).<br /><br />Promise these three approaches can help as these help me.<br /><br />PS: Recently I've found useful tips of Silverlight performance. You can read it there - <a href="http://msdn.microsoft.com/en-gb/library/cc189071%28VS.95%29.aspx">Performance Tips.</a>RredCathttp://www.blogger.com/profile/06888794692783746379noreply@blogger.com0