<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>.NET Developer in Toronto</title>
	<atom:link href="http://alexandershapovalov.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://alexandershapovalov.com</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Sat, 21 Jan 2012 01:38:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Strongly type properties with NHibernate</title>
		<link>http://alexandershapovalov.com/strongly-type-properties-with-nhibernate-88/</link>
		<comments>http://alexandershapovalov.com/strongly-type-properties-with-nhibernate-88/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 22:19:11 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alexandershapovalov.com/?p=88</guid>
		<description><![CDATA[I like NHIbernate and use it in all my projects. Now I am working on Atomic CMS &#8211; its a content management system project. I am working on sorting, but I don&#8217;t like to use strings for names of properties. I tried to find solution how to use strongly typed properties with NHibernate, but did [...]]]></description>
			<content:encoded><![CDATA[<p>
	I like NHIbernate and use it in all my projects. Now I am working on <a href="http://atomiccms.com/">Atomic CMS</a> &ndash; its a <a href="http://atomiccms.com/">content management system</a> project. I am working on sorting, but I don&rsquo;t like to use strings for names of properties. I tried to find solution how to use strongly typed properties with NHibernate, but did not. So I created my own solution.</p>
<p>
	Instead of the code like this</p>
<pre class="brush: csharp; gutter: false; toolbar: false;">
session.CreateCriteria(typeof(IEntry)).AddOrder(Order.Desc(&quot;Alias&quot;))</pre>
<p>
	I prefer to have something like this</p>
<pre class="brush: csharp; gutter: false; toolbar: false;">
session.CreateCriteria(typeof(IEntry)).AddOrder(Order.Desc(x=&gt;x.Alias))</pre>
<p>
	But unfortunately it&rsquo;s not possible with NHibernate. So I created simple solution which is fine for me and my project. I created class to return name of the method or property. The code using this class looks like this</p>
<pre class="brush: csharp; gutter: false; toolbar: false;">
session.CreateCriteria(typeof(IEntry)).AddOrder(Order.Desc(Strong&lt;IEntry&gt;.Name(x=&gt;x.Alias)))</pre>
<p>
	And the code for Strong class is.</p>
<pre class="brush: csharp; gutter: false; toolbar: false;">
namespace AtomicCms.Common.Utils
{
    using System;
    using System.Linq.Expressions;

    public static class Strong&lt;T&gt;
    {
        public static string Name(Expression&lt;Func&lt;T, object&gt;&gt; action)
        {
            if (null == action || null == action.Body)
            {
                throw new NullReferenceException(&quot;action or action.body is null&quot;);
            }

            UnaryExpression unary = action.Body as UnaryExpression;
            if (null != unary &amp;&amp; null != unary.Operand as MemberExpression)
            {
                return PropertyName(unary.Operand);
            }

            MemberExpression memberCall = action.Body as MemberExpression;
            if (memberCall != null)
            {
                return PropertyName(action.Body);
            }

            MethodCallExpression methodCall = action.Body as MethodCallExpression;
            if (null != methodCall)
            {
                return MethodName(action.Body);
            }

            throw new Exception(&quot;Not supported action &quot; + action);
        }

        private static string PropertyName(Expression operand)
        {
            MemberExpression member = operand as MemberExpression;
            if (member != null) return member.Member.Name;

            throw new NullReferenceException(&quot;Unxexpected null reference&quot;);
        }

        private static string MethodName(Expression operand)
        {
            MethodCallExpression member = operand as MethodCallExpression;
            if (member != null) return member.Method.Name;

            throw new NullReferenceException(&quot;Unxexpected null reference&quot;);
        }
    }
}</pre>
<p>
	&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://alexandershapovalov.com/strongly-type-properties-with-nhibernate-88/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to call WCF services from JavaScript jQuery and ASP.NET AJAX</title>
		<link>http://alexandershapovalov.com/how-to-call-wcf-services-from-javascript-jquery-and-asp-net-ajax-85/</link>
		<comments>http://alexandershapovalov.com/how-to-call-wcf-services-from-javascript-jquery-and-asp-net-ajax-85/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 22:18:51 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alexandershapovalov.com/?p=85</guid>
		<description><![CDATA[First we have to create a webapplication and add to it Ajax enabled WCF service. Change default DoWork method to accept parameter [OperationContract] public string DoWork(string userName) { // Add your operation implementation here return &#34;Hello &#34; + userName; } First add on the page input text control and two buttons. &#60;input type=&#34;text&#34; name=&#34;txtName&#34; id=&#34;txtName&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>
	First we have to create a webapplication and add to it Ajax enabled WCF service.</p>
<p>
	Change default DoWork method to accept parameter</p>
<pre class="brush: csharp; gutter: false;">
        [OperationContract]
        public string DoWork(string userName)
        {
            // Add your operation implementation here
            return &quot;Hello &quot; + userName;
        }</pre>
<p>
	First add on the page input text control and two buttons.</p>
<pre class="brush: xml; gutter: false;">
        &lt;input type=&quot;text&quot; name=&quot;txtName&quot; id=&quot;txtName&quot; /&gt;
        &lt;input type=&quot;button&quot; value=&quot;jQuery call&quot; onclick=&quot;cityClickJQuery();&quot; /&gt;
        &lt;input type=&quot;button&quot; value=&quot;ASP.NET AJAX Call&quot; onclick=&quot;cityClick();&quot; /&gt;</pre>
<p>
	First we will call this method with jQuery. So reference jQuery library and add this javascript function for calling WCF service</p>
<pre class="brush: js; gutter: false;">
        function cityClickJQuery()
        {
            $.ajax({
                type: &quot;POST&quot;,
                url: &quot;http://localhost:65424/CityService.svc/DoWork&quot;,
                data: &#39;{&quot;userName&quot;:&quot;&#39;+$get(&quot;txtName&quot;).value+&#39;&quot;}&#39;,
                processData:false,
                contentType: &quot;application/json; charset=utf-8&quot;,
                dataType: &quot;json&quot;,
                success: function(data)
                {
                    alert(data.d);
                }
            });
        }</pre>
<p>
	It&rsquo;s very easy, you have to pass url with method, parameter (value from textbox) specify data type and callback function.</p>
<p>
	Now you can run webapplication, put some text in input box and press button &ldquo;jQuery call&rdquo;</p>
<p>
	<a href="http://alexandershapovalov.com/blog/wp-content/uploads/2009/12/image.png"><img alt="image" border="0" height="193" src="http://alexandershapovalov.com/blog/wp-content/uploads/2009/12/image_thumb.png" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="image" width="432" /></a></p>
<p>
	&nbsp;</p>
<p>
	Calling WCF service with Microsoft Ajax is much more easy. You do not to provide most of the properties like jQuery call.</p>
<pre class="brush: js; gutter: false;">
        function cityClick()
        {
            CityService.DoWork($get(&quot;txtName&quot;).value, onSuccess);
        }

        function onSuccess(data)
        {
            if (data)
                alert(data);
        }</pre>
<p>
	After pressing button, you will have the same result.</p>
<p>
	<a href="http://alexandershapovalov.com/blog/wp-content/uploads/2009/12/image.png"><img alt="image" border="0" height="193" src="http://alexandershapovalov.com/blog/wp-content/uploads/2009/12/image_thumb.png" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="image" width="432" /></a></p>
<p>
	&nbsp;</p>
<p>
	&nbsp;</p>
<p>
	All source code can bi found below. I did not change web.config, so you can use default data generated by VisualStudio.</p>
<p>
	ASPX page:</p>
<pre class="brush: xml; collapse: true;">
&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;Default.aspx.cs&quot;
    Inherits=&quot;WebApplication1._Default&quot; %&gt;

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head runat=&quot;server&quot;&gt;
    &lt;title&gt;&lt;/title&gt;

    &lt;script src=&quot;jquery-1.3.2.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;jquery-1.3.2-vsdoc.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;

    &lt;script type=&quot;text/javascript&quot;&gt;
        function cityClickJQuery()
        {
            $.ajax({
                type: &quot;POST&quot;,
                url: &quot;http://localhost:65424/CityService.svc/DoWork&quot;,
                data: &#39;{&quot;userName&quot;:&quot;&#39;+$get(&quot;txtName&quot;).value+&#39;&quot;}&#39;,
                processData:false,
                contentType: &quot;application/json; charset=utf-8&quot;,
                dataType: &quot;json&quot;,
                success: function(data)
                {
                    alert(data.d);
                }
            });
        }
        function cityClick()
        {
            CityService.DoWork($get(&quot;txtName&quot;).value, onSuccess);
        }

        function onSuccess(data)
        {
            if (data)
                alert(data);
        }
    &lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
    &lt;div&gt;
        &lt;asp:ScriptManager runat=&quot;server&quot;&gt;
            &lt;Services&gt;
                &lt;asp:ServiceReference Path=&quot;~/CityService.svc&quot; /&gt;
            &lt;/Services&gt;
        &lt;/asp:ScriptManager&gt;

        &lt;div style=&quot;background-color:#eee;&quot;&gt;

        &lt;input type=&quot;text&quot; name=&quot;txtName&quot; id=&quot;txtName&quot; /&gt;
        &lt;input type=&quot;button&quot; value=&quot;jQuery call&quot; onclick=&quot;cityClickJQuery();&quot; /&gt;
        &lt;input type=&quot;button&quot; value=&quot;ASP.NET AJAX Call&quot; onclick=&quot;cityClick();&quot; /&gt;
        &lt;/div&gt;

    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>
	&nbsp;</p>
<p>
	C# code:</p>
<pre class="brush: csharp; collapse: true;">
namespace WebApplication1
{
    using System.ServiceModel;
    using System.ServiceModel.Activation;

    [ServiceContract(Namespace = &quot;&quot;)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class CityService
    {
        // Add [WebGet] attribute to use HTTP GET
        [OperationContract]
        public string DoWork(string userName)
        {
            // Add your operation implementation here
            return &quot;Hello &quot; + userName;
        }

        // Add more operations here and mark them with [OperationContract]
    }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://alexandershapovalov.com/how-to-call-wcf-services-from-javascript-jquery-and-asp-net-ajax-85/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrate to new version Nhibernate 2.1.0 with Oracle database</title>
		<link>http://alexandershapovalov.com/migrate-to-new-version-nhibernate-2-1-0-with-oracle-database-83/</link>
		<comments>http://alexandershapovalov.com/migrate-to-new-version-nhibernate-2-1-0-with-oracle-database-83/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 22:18:31 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alexandershapovalov.com/?p=83</guid>
		<description><![CDATA[A couple of days ago new version of Nhibernate was released. You can download new version here.&#160; And if you migrate to this version and using Oracle database, You will get this exception Could not load type NHibernate.Dialect.OracleDialect. Possible cause: no assembly name specified The reason is, you need specify not OracleDialect, but Oracle8iDialect, Oracle9iDialect, [...]]]></description>
			<content:encoded><![CDATA[<p>
	A couple of days ago new version of Nhibernate was released. <a href="http://sourceforge.net/projects/nhibernate/files/NHibernate/NHibernate-2.1.0.GA-bin.zip/download">You can download new version here</a>.&nbsp;</p>
<p>
	And if you migrate to this version and using Oracle database,<br />
	You will get this exception</p>
<blockquote>
<p>
		Could not load type NHibernate.Dialect.OracleDialect. Possible cause: no assembly name specified</p>
</blockquote>
<p>
	The reason is, you need specify not OracleDialect, but Oracle8iDialect, Oracle9iDialect, Oracle10gDialect, or OracleLiteDialect instead.<br />
	For example for oracle 10.x version you have to change dialect line in your hibernate.cfg.xml to this line</p>
<pre class="brush: xml; gutter: false; toolbar: false;">
&lt;property name=&quot;dialect&quot;&gt;NHibernate.Dialect.Oracle10gDialect&lt;/property&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://alexandershapovalov.com/migrate-to-new-version-nhibernate-2-1-0-with-oracle-database-83/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to read data from app.config?</title>
		<link>http://alexandershapovalov.com/how-to-read-data-from-app-config-82/</link>
		<comments>http://alexandershapovalov.com/how-to-read-data-from-app-config-82/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 22:18:16 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alexandershapovalov.com/?p=82</guid>
		<description><![CDATA[It&#39;s simple, Just use ConfigurationManager class &#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34; ?&#62; &#60;configuration&#62; &#60;appSettings&#62; &#60;add key=&#34;ApplicationPath&#34; value=&#34;C:\MyProjects\TestProject\&#34;/&#62; &#60;/appSettings&#62; &#60;/configuration&#62; And to read data use this code public static string AppPath() { return ConfigurationManager.AppSettings[&#34;ApplicationPath&#34;]; } Do not forget add reference to the System.Configuration]]></description>
			<content:encoded><![CDATA[<p>
	It&#39;s simple, Just use ConfigurationManager class</p>
<pre class="csharpcode">
<span class="kwrd">&lt;?</span><span class="html">xml</span> <span class="attr">version</span><span class="kwrd">=&quot;1.0&quot;</span> <span class="attr">encoding</span><span class="kwrd">=&quot;utf-8&quot;</span> ?<span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">configuration</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">appSettings</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">key</span><span class="kwrd">=&quot;ApplicationPath&quot;</span> <span class="attr">value</span><span class="kwrd">=&quot;C:\MyProjects\TestProject\&quot;</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">appSettings</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">configuration</span><span class="kwrd">&gt;</span></pre>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->
<p>
	And to read data use this code</p>
<pre class="csharpcode">
<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">string</span> AppPath()
{
<span class="kwrd">return</span> ConfigurationManager.AppSettings[<span class="str">&quot;ApplicationPath&quot;</span>];
}</pre>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->
<p>
	Do not forget add reference to the System.Configuration</p>
]]></content:encoded>
			<wfw:commentRss>http://alexandershapovalov.com/how-to-read-data-from-app-config-82/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eval vs Bind for ASP.NET</title>
		<link>http://alexandershapovalov.com/eval-vs-bind-for-asp-net-81/</link>
		<comments>http://alexandershapovalov.com/eval-vs-bind-for-asp-net-81/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 22:17:59 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alexandershapovalov.com/?p=81</guid>
		<description><![CDATA[When you start working with ASP.NET sometimes it&#8217;s difficult to understand what is the difference between Eval and Bind for data binding controls in ASP.NET. If you just need to display data on the screen from DataSource it&#8217;s enough to use Eval. It&#8217;s something like read-only method from DataSource. But if you need to edit [...]]]></description>
			<content:encoded><![CDATA[<p>
	When you start working with ASP.NET sometimes it&rsquo;s difficult to understand what is the difference between Eval and Bind for data binding controls in ASP.NET.</p>
<p>
	If you just need to display data on the screen from DataSource it&rsquo;s enough to use Eval. It&rsquo;s something like read-only method from DataSource.</p>
<p>
	But if you need to edit data inside of Grid you have to use Bind method. Because it provides two way binding you can read data from DataSource and you can write data back.</p>
<p>
	Usually you have to use this methods if you need to quickly develop some WebPages and display and edit data from one table or simple view.</p>
<p>
	If you try to edit some row in Data Grid and want to make some changes in code behind class in OnUdpdating event, data with Eval method will not be available instead of Bind method.</p>
<pre class="brush: xml; gutter: false; toolbar: false; smart-tabs: false;">
&lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot; CssClass=&quot;dataGrid&quot;
   DataSourceID=&quot;SqlDataSource1&quot; AllowPaging=&quot;True&quot; AutoGenerateColumns=&quot;false&quot;
  OnRowDeleting=&quot;grid_onRowDeleting&quot; OnRowUpdating=&quot;GridView1_OnRowUpdating&quot;
    AutoGenerateEditButton=&quot;true&quot; AutoGenerateDeleteButton=&quot;true&quot;
  PageSize=&quot;20&quot; GridLines=&quot;None&quot; Width=&quot;99%&quot;&gt;
   &lt;AlternatingRowStyle CssClass=&quot;odd&quot; /&gt;
   &lt;Columns&gt;

       &lt;asp:TemplateField HeaderText=&quot;App Id&quot;&gt;
           &lt;ItemTemplate&gt;
               &lt;asp:Label ID=&quot;lbl&quot; runat=&quot;server&quot; Text=&#39;&lt;%#Bind(&quot;APP_ID&quot;) %&gt;&#39;&gt;&lt;/asp:Label&gt;
           &lt;/ItemTemplate&gt;
       &lt;/asp:TemplateField&gt;

      &lt;asp:TemplateField HeaderText=&quot;App name&quot;&gt;
           &lt;ItemTemplate&gt;
               &lt;%#Eval(&quot;APPLICATION_NAME&quot;)%&gt;
           &lt;/ItemTemplate&gt;
       &lt;/asp:TemplateField&gt;
   &lt;/Columns&gt;
&lt;/asp:GridView&gt;</pre>
<pre class="brush: csharp; gutter: false; toolbar: false; smart-tabs: false;">
protected void GridView1_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
{
   // if APP_ID in the grid bind with Eval method, it will be exception below
   // But if you use Bind instead of Eval it will be ok.
   rowToUpdate = e.NewValues[&quot;APP_ID&quot;];
}
</pre>
<div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e1cd7091-3e3a-4c72-a422-58c19682f08e" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
	Technorati Tags: <a href="http://technorati.com/tags/asp.NET" rel="tag">asp.NET</a>,<a href="http://technorati.com/tags/standard+controls" rel="tag">standard controls</a></div>
]]></content:encoded>
			<wfw:commentRss>http://alexandershapovalov.com/eval-vs-bind-for-asp-net-81/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use curly brackets inside of String.Format</title>
		<link>http://alexandershapovalov.com/how-to-use-curly-brackets-inside-of-string-format-79/</link>
		<comments>http://alexandershapovalov.com/how-to-use-curly-brackets-inside-of-string-format-79/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 22:17:38 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alexandershapovalov.com/?p=79</guid>
		<description><![CDATA[String.Format provides inserting variables inside of the string, indicated with curly brackets and index, for example String s = string.Format&#34;Hello {0}&#34;, name) But if you need to use curly brackets inside of string format you will get exception, because compiler does not know if you trying to insert curly bracket or replacing string. So you [...]]]></description>
			<content:encoded><![CDATA[<p>
	String.Format provides inserting variables inside of the string, indicated with curly brackets and index, for example</p>
<pre class="brush: csharp; gutter: false; toolbar: false; smart-tabs: false;">
String s = string.Format&quot;Hello {0}&quot;, name)</pre>
<p>
	But if you need to use curly brackets inside of string format you will get exception, because compiler does not know if you trying to insert curly bracket or replacing string. So you can get exception</p>
<pre class="brush: csharp; gutter: false; toolbar: false; smart-tabs: false;">
String s = string.Format(&quot;{name} = {0}&quot;, name); // exception</pre>
<p>
	But there is a simple solution to avoid exception, you need to use double curly brackets.</p>
<pre class="brush: csharp; gutter: false; toolbar: false; smart-tabs: false;">
String s = string.Format(&quot;{{name}} = {0}&quot;, name); // ok</pre>
]]></content:encoded>
			<wfw:commentRss>http://alexandershapovalov.com/how-to-use-curly-brackets-inside-of-string-format-79/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET Health Monitor with ASP.NET 3.5</title>
		<link>http://alexandershapovalov.com/asp-net-health-monitor-with-asp-net-3-5-77/</link>
		<comments>http://alexandershapovalov.com/asp-net-health-monitor-with-asp-net-3-5-77/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 22:17:15 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alexandershapovalov.com/?p=77</guid>
		<description><![CDATA[Health monitor is a system to monitor health of the application. It&#8217;s easy to add to your website and easy to use. You can subscribe to some events occurred in the application, for example, &#8220;Error&#8221; and log it, or sent per email. To add it you have to modify your web.config file, just add this [...]]]></description>
			<content:encoded><![CDATA[<p>
	<strong>Health monitor</strong> is a system to monitor health of the application. It&rsquo;s easy to add to your website and easy to use.</p>
<p>
	You can subscribe to some events occurred in the application, for example, &ldquo;Error&rdquo; and log it, or sent per email.</p>
<p>
	To add it you have to modify your web.config file, just add this lines of code in <strong>system.web</strong> section</p>
<pre class="csharpcode">
<span class="kwrd">&lt;</span><span class="html">healthMonitoring</span> <span class="attr">enabled</span><span class="kwrd">=&quot;true&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">eventMappings</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">clear</span><span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">add</span>
                    <span class="attr">name</span><span class="kwrd">=&quot;All Errors&quot;</span>
                    <span class="attr">type</span><span class="kwrd">=&quot;System.Web.Management.WebBaseErrorEvent,
                    System.Web, Version=2.0.0.0, Culture=neutral,
                    PublicKeyToken=b03f5f7f11d50a3a&quot;</span>
                    <span class="attr">startEventCode</span><span class="kwrd">=&quot;0&quot;</span>
                    <span class="attr">endEventCode</span><span class="kwrd">=&quot;2147483647&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">eventMappings</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">providers</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">clear</span><span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">add</span>
                    <span class="attr">name</span><span class="kwrd">=&quot;mailWebEventProvider&quot;</span>
                    <span class="attr">type</span><span class="kwrd">=&quot;System.Web.Management.SimpleMailWebEventProvider&quot;</span>
                    <span class="attr">from</span><span class="kwrd">=&quot;name@test.com&quot;</span>
                    <span class="attr">to</span><span class="kwrd">=&quot;name@test.com&quot;</span>
                    <span class="attr">buffer</span><span class="kwrd">=&quot;false&quot;</span>
                    <span class="attr">subjectPrefix</span><span class="kwrd">=&quot;An error occurred: &quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">providers</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">rules</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">clear</span><span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">add</span>
                    <span class="attr">name</span><span class="kwrd">=&quot;Testing mail event provider&quot;</span>
                    <span class="attr">eventName</span><span class="kwrd">=&quot;All Errors&quot;</span>
                    <span class="attr">provider</span><span class="kwrd">=&quot;mailWebEventProvider&quot;</span>
                    <span class="attr">profile</span><span class="kwrd">=&quot;Default&quot;</span>
                    <span class="attr">minInstances</span><span class="kwrd">=&quot;1&quot;</span>
                    <span class="attr">maxLimit</span><span class="kwrd">=&quot;Infinite&quot;</span>
                    <span class="attr">minInterval</span><span class="kwrd">=&quot;00:01:00&quot;</span>
                    <span class="attr">custom</span><span class="kwrd">=&quot;&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">rules</span><span class="kwrd">&gt;</span>

        <span class="kwrd">&lt;/</span><span class="html">healthMonitoring</span><span class="kwrd">&gt;</span></pre>
<p><style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }	</style>
<p>	And add in your <strong>system.net</strong> section this code</p>
<pre class="csharpcode">
<span class="kwrd">&lt;</span><span class="html">mailSettings</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">smtp</span>
                <span class="attr">deliveryMethod</span><span class="kwrd">=&quot;Network&quot;</span>
                <span class="attr">from</span><span class="kwrd">=&quot;name@test.com&quot;</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">network</span>
                    <span class="attr">host</span><span class="kwrd">=&quot;mailhost&quot;</span>
                    <span class="attr">port</span><span class="kwrd">=&quot;25&quot;</span>
                    <span class="attr">defaultCredentials</span><span class="kwrd">=&quot;true&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">smtp</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">mailSettings</span><span class="kwrd">&gt;</span></pre>
<p><style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }	</style>
<p>	The explanation what this code does is very simple, firstly, in <strong>eventMapping</strong> section you subscribes to some event occurred in the application. There are a great deal of event which you can subscribe, you can find info about they in MSDN documentation.</p>
<p>
	Than in <strong>providers </strong>section you need to define provider, it can be email, database or some other provider. In my example I am using email provider, so all messages will be sent per email.</p>
<p>
	And than in <strong>rules</strong> section you have to bind events to providers.</p>
<p>
	Because I am using email provider, I have to define <strong>mailSettings</strong> settings in <strong>system.net </strong>section.</p>
<p>
	And it&rsquo;s all. Now after error messages you will get the text like this:</p>
<blockquote>
<p>
		** Application Information **<br />
		&#8212;&#8212;&#8212;&#8212;&#8212;<br />
		Application domain: 8487b6cb-4-128819412246400827 Trust level: Full Application Virtual Path: /WebSite Application Path: C:\ProjectLocker\Trunk\LightCMS\WebSite\<br />
		Machine name: xxx</p>
<p>
		** Events **<br />
		&#8212;&#8212;&#8212;&#8212;&#8212;<br />
		Event code: 3005<br />
		Event message: An unhandled exception has occurred.<br />
		Event time: 3/19/2009 4:00:29 PM<br />
		Event time (UTC): 3/19/2009 1:00:29 PM<br />
		Event ID: f6146a7781d34b9698cc5741b2aa75bd Event sequence: 15 Event occurrence: 1 Event detail code: 0</p>
<p>
		Process information:<br />
		&nbsp;&nbsp;&nbsp; Process ID: 2420<br />
		&nbsp;&nbsp;&nbsp; Process name: WebDev.WebServer.EXE<br />
		&nbsp;&nbsp;&nbsp; Account name: xxx\xxx</p>
<p>
		Exception information:<br />
		&nbsp;&nbsp;&nbsp; Exception type: System.DivideByZeroException<br />
		&nbsp;&nbsp;&nbsp; Exception message: Attempted to divide by zero.</p>
<p>
		Request information:<br />
		&nbsp;&nbsp;&nbsp; Request URL: <a href="http://localhost:7323/WebSite/CssVariables.aspx">http://localhost:7323/WebSite/CssVariables.aspx</a><br />
		&nbsp;&nbsp;&nbsp; Request path: /WebSite/CssVariables.aspx<br />
		&nbsp;&nbsp;&nbsp; User host address: 127.0.0.1<br />
		&nbsp;&nbsp;&nbsp; User:<br />
		&nbsp;&nbsp;&nbsp; Is authenticated: False<br />
		&nbsp;&nbsp;&nbsp; Authentication Type:<br />
		&nbsp;&nbsp;&nbsp; Thread account name: xxx\xxx</p>
<p>
		Thread information:<br />
		&nbsp;&nbsp;&nbsp; Thread ID: 4<br />
		&nbsp;&nbsp;&nbsp; Thread account name: xxx\xxx<br />
		&nbsp;&nbsp;&nbsp; Is impersonating: False<br />
		&nbsp;&nbsp;&nbsp; Stack trace:&nbsp;&nbsp;&nbsp; at CssVariables.Button1_Click(Object sender, EventArgs e) in c:\ProjectLocker\Trunk\LightCMS\WebSite\CssVariables.aspx.cs:line 18<br />
		&nbsp;&nbsp; at System.Web.UI.WebControls.Button.OnClick(EventArgs e)<br />
		&nbsp;&nbsp; at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)<br />
		&nbsp;&nbsp; at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)<br />
		&nbsp;&nbsp; at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)<br />
		&nbsp;&nbsp; at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)<br />
		&nbsp;&nbsp; at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://alexandershapovalov.com/asp-net-health-monitor-with-asp-net-3-5-77/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calling Oracle stored procedures from SQLDataSource</title>
		<link>http://alexandershapovalov.com/calling-oracle-stored-procedures-from-sqldatasource-75/</link>
		<comments>http://alexandershapovalov.com/calling-oracle-stored-procedures-from-sqldatasource-75/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 22:14:45 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alexandershapovalov.com/?p=75</guid>
		<description><![CDATA[For some simple pages in my application I prefer to use declarative manner of programming. To display some data on the page you can use this lines of code. &#60;asp:SqlDataSource ID=&#34;SqlDataSource1&#34; runat=&#34;server&#34; ProviderName=&#34;System.Data.OracleClient&#34; SelectCommand=&#34;pac_dwh.Revew_item_info.GetAppPermissionInfoExt&#34; SelectCommandType=&#34;StoredProcedure&#34;&#62; &#60;SelectParameters&#62; &#60;asp:QueryStringParameter Name=&#34;p_line_id&#34; QueryStringField=&#34;lineId&#34; /&#62; &#60;asp:Parameter Name=&#34;p_res&#34; Direction=&#34;Output&#34; /&#62; &#60;/SelectParameters&#62; &#60;/asp:SqlDataSource&#62; &#60;asp:FormView ID=&#34;FormViewContent&#34; runat=&#34;server&#34; DataSourceID=&#34;SqlDataSource1&#34; &#62; &#60;ItemTemplate&#62; &#60;%# Eval(&#34;profile&#34;) %&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>
	For some simple pages in my application I prefer to use declarative manner of programming. To display some data on the page you can use this lines of code.</p>
<pre class="brush: xml; gutter: false; toolbar: false; smart-tabs: false;">
&lt;asp:SqlDataSource ID=&quot;SqlDataSource1&quot; runat=&quot;server&quot;
ProviderName=&quot;System.Data.OracleClient&quot;
    SelectCommand=&quot;pac_dwh.Revew_item_info.GetAppPermissionInfoExt&quot;
    SelectCommandType=&quot;StoredProcedure&quot;&gt;
    &lt;SelectParameters&gt;
        &lt;asp:QueryStringParameter Name=&quot;p_line_id&quot;
                  QueryStringField=&quot;lineId&quot; /&gt;
        &lt;asp:Parameter Name=&quot;p_res&quot; Direction=&quot;Output&quot; /&gt;
    &lt;/SelectParameters&gt;
&lt;/asp:SqlDataSource&gt;
&lt;asp:FormView ID=&quot;FormViewContent&quot; runat=&quot;server&quot;
          DataSourceID=&quot;SqlDataSource1&quot; &gt;
        &lt;ItemTemplate&gt;
            &lt;%# Eval(&quot;profile&quot;) %&gt;
            &lt;%# Eval(&quot;application_description&quot;) %&gt;
        &lt;/ItemTemplate&gt;
&lt;/asp:FormView&gt;</pre>
<p>
	But if you are using Oracle database you will get the error</p>
<p>
	<strong>System.Exception: Parameter &#39;p_res&#39;: No size set for variable length data type: String.</strong></p>
<p>
	It&rsquo;s because you can&rsquo;t define type of parameter in DataSource, because it&rsquo;s a Cursor, and Direction has no this type of data.</p>
<p>
	The solution is very simple, you just need to set datatype for the output parameter in OnSelecting event, like this:</p>
<pre class="brush: xml; gutter: false; toolbar: false; smart-tabs: false;">
&lt;asp:SqlDataSource ID=&quot;SqlDataSource1&quot; runat=&quot;server&quot;
ProviderName=&quot;System.Data.OracleClient&quot;
SelectCommand=&quot;pac_dwh.Revew_item_info.GetAppPermissionInfoExt&quot;
SelectCommandType=&quot;StoredProcedure&quot;
OnSelecting=&quot;FixOracleRefCursorProblem_SqlDataSource1_Selecting&quot;&gt;
    &lt;SelectParameters&gt;
        &lt;asp:QueryStringParameter Name=&quot;p_line_id&quot;
                  QueryStringField=&quot;lineId&quot; /&gt;
        &lt;asp:Parameter Name=&quot;p_res&quot; Direction=&quot;Output&quot; /&gt;
    &lt;/SelectParameters&gt;
&lt;/asp:SqlDataSource&gt;</pre>
<p>
	and in cs file:</p>
<pre class="brush: csharp; gutter: false; toolbar: false; smart-tabs: false;">
protected void FixOracleRefCursorProblem_SqlDataSource1_Selecting(object sender,
   SqlDataSourceSelectingEventArgs e)
{
    ((System.Data.OracleClient.OracleParameter)
    e.Command.Parameters[1]).OracleType = OracleType.Cursor;
}</pre>
<p>
	And now it works <img src='http://alexandershapovalov.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://alexandershapovalov.com/calling-oracle-stored-procedures-from-sqldatasource-75/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET Charting Control</title>
		<link>http://alexandershapovalov.com/asp-net-charting-control-73/</link>
		<comments>http://alexandershapovalov.com/asp-net-charting-control-73/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 22:14:26 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alexandershapovalov.com/?p=73</guid>
		<description><![CDATA[Not a long time ago Microsoft charting controls was announced. It&#39;s a great controls. I used Syncfusion to make graphics, but it was too expensive. But now anybody can create graphics for free. Download Microsoft Chart Controls Download VS 2008 Tool Support for the Chart Controls Download Microsoft Chart Controls Samples Download Microsoft Chart Controls [...]]]></description>
			<content:encoded><![CDATA[<p>
	Not a long time ago Microsoft charting controls was announced. It&#39;s a great controls. I used Syncfusion to make graphics, but it was too expensive. But now anybody can create graphics for free.</p>
<ul>
<li>
		<a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=130f7986-bf49-4fe5-9ca8-910ae6ea442c&amp;DisplayLang=en">Download Microsoft Chart Controls</a></li>
<li>
		<a href="http://www.microsoft.com/downloads/details.aspx?familyid=1D69CE13-E1E5-4315-825C-F14D33A303E9&amp;displaylang=en">Download VS 2008 Tool Support for the Chart Controls</a></li>
<li>
		<a href="http://code.msdn.microsoft.com/mschart/Release/ProjectReleases.aspx?ReleaseId=1591">Download Microsoft Chart Controls Samples</a></li>
<li>
		<a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=EE8F6F35-B087-4324-9DBA-6DD5E844FD9F&amp;displaylang=en">Download Microsoft Chart Controls Documentation</a></li>
</ul>
<p>
	After installation this files there are new item in Data page in Visual studio toolbox.</p>
<p>
	<a href="http://alexandershapovalov.com/uploads/2008/12/image.png"><img alt="image" border="0" height="172" src="http://alexandershapovalov.com/uploads/2008/12/image-thumb.png" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" width="221" /></a>&nbsp;<br />
	You need drag and drop it on the web page.</p>
<p>
	<a href="http://alexandershapovalov.com/uploads/2008/12/image1.png"><img alt="image" border="0" height="244" src="http://alexandershapovalov.com/uploads/2008/12/image-thumb1.png" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" width="203" /></a></p>
<pre class="csharpcode">
<span class="kwrd">&lt;</span><span class="html">asp:Chart</span> <span class="attr">ID</span><span class="kwrd">=&quot;Chart1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">series</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:Series</span> <span class="attr">Name</span><span class="kwrd">=&quot;NumberOfEmployees&quot;</span> <span class="attr">XValueMember</span><span class="kwrd">=&quot;Year&quot;</span> <span class="attr">YValueMembers</span><span class="kwrd">=&quot;NumberOfPeople&quot;</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">asp:Series</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">series</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">chartareas</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:ChartArea</span> <span class="attr">Name</span><span class="kwrd">=&quot;ChartArea1&quot;</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">AxisX</span> <span class="attr">LineColor</span> = <span class="kwrd">&quot;Blue&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">AxisX</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">AxisY</span> <span class="attr">LineColor</span> = <span class="kwrd">&quot;Purple&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">AxisY</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">asp:ChartArea</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">chartareas</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">asp:Chart</span><span class="kwrd">&gt;</span></pre>
<p><style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }	</style>
</p>
<p>
	As a DataSource it was used DataTable. Just add this code to Page_Load</p>
<pre class="csharpcode">
                var table = <span class="kwrd">new</span> DataTable();
                table.Columns.Add(<span class="str">&quot;Year&quot;</span>, <span class="kwrd">typeof</span>(<span class="kwrd">int</span>));
                table.Columns.Add(<span class="str">&quot;NumberOfPeople&quot;</span>, <span class="kwrd">typeof</span>(<span class="kwrd">long</span>));
                table.Columns.Add(<span class="str">&quot;Lbl&quot;</span>);
                var row = table.NewRow();
                row[<span class="str">&quot;Year&quot;</span>] = 2000;
                row[<span class="str">&quot;NumberOfPeople&quot;</span>] = 15;
                table.Rows.Add(row);
                row = table.NewRow();
                row[<span class="str">&quot;Year&quot;</span>] = 2001;
                row[<span class="str">&quot;NumberOfPeople&quot;</span>] = 35;
                table.Rows.Add(row);
               .......
                row = table.NewRow();
                row[<span class="str">&quot;Year&quot;</span>] = 2008;
                row[<span class="str">&quot;NumberOfPeople&quot;</span>] = 1390;
                table.Rows.Add(row);
                <strong><font color="#ff0000">Chart1.DataSource = table;
                Chart1.DataBind();</font></strong> </pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>
	After run the page you get this graphic.</p>
<p>
	<a href="http://alexandershapovalov.com/uploads/2008/12/image2.png"><img alt="image" border="0" height="244" src="http://alexandershapovalov.com/uploads/2008/12/image-thumb2.png" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" width="226" /></a></p>
<p>
	To change the style you can add this code to the page load method</p>
<pre class="csharpcode">
Chart1.Series[<span class="str">&quot;NumberOfEmployees&quot;</span>][<span class="str">&quot;DrawingStyle&quot;</span>] = cbCilinder.Checked ? <span class="str">&quot;Cylinder&quot;</span> : <span class="str">&quot;Default&quot;</span>; </pre>
<p>
	And appearance for the graphic will be much more better.</p>
<p>
	<a href="http://alexandershapovalov.com/uploads/2008/12/image3.png"><img alt="image" border="0" height="241" src="http://alexandershapovalov.com/uploads/2008/12/image-thumb3.png" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" width="244" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://alexandershapovalov.com/asp-net-charting-control-73/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dependency injection design pattern</title>
		<link>http://alexandershapovalov.com/dependency-injection-design-pattern-71/</link>
		<comments>http://alexandershapovalov.com/dependency-injection-design-pattern-71/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 22:14:04 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alexandershapovalov.com/?p=71</guid>
		<description><![CDATA[Normally when designing some parts of the application, one classes is always depends on the other classes. For example, business logic classes (BL) are depend on data access classes (DAL). This dependence can be in very different ways, for example, BL can call static methods of DAL, or create instance of DAL every time it [...]]]></description>
			<content:encoded><![CDATA[<p>
	Normally when designing some parts of the application, one classes is always depends on the other classes. For example, business logic classes (BL) are depend on data access classes (DAL). This dependence can be in very different ways, for example, BL can call static methods of DAL, or create instance of DAL every time it needs it&hellip; But in this case it&rsquo;s can be difficulties to test business logic with Unit tests because it&rsquo;s difficult or even impossible to create mocks to the database. To solve this problem you can use Dependency injection pattern. Here is example of how I am using it. Firstly create our classes for DAL:</p>
<pre class="csharpcode">
<span class="kwrd">public</span> <span class="kwrd">class</span> ProductDAL
    {
        <span class="kwrd">public</span> <span class="kwrd">virtual</span> List&lt;Product&gt; GetProducts()
        {
            <span class="rem">// connect to DB and get products</span>
            <span class="kwrd">return</span> <span class="kwrd">new</span> List&lt;Product&gt;();
        }
    }</pre>
<p>
	And for BL:</p>
<pre class="csharpcode">
<span class="kwrd">public</span> <span class="kwrd">class</span> ProductBL
    {
        <span class="kwrd">private</span> <span class="kwrd">readonly</span> ProductDAL dal;

        <strong><span class="kwrd">public</span> ProductBL(ProductDAL dal)</strong>
        {
            <span class="kwrd">this</span>.dal = dal;
        }

        <span class="kwrd">public</span> List&lt;Product&gt; GetProducts()
        {
            <span class="rem">// Get products, make some manipulation with the products,</span>
            <span class="rem">// e.g. sorting, filtering...</span>
            <span class="kwrd">return</span> dal.GetProducts();
        }
    }</pre>
<p>
<!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>
	For parameter in constructor in BL I passed instance of DAL, it&rsquo;s Constructor injection. And it&rsquo;s very easy to test this calls with Rhino mocks.</p>
<pre class="csharpcode">
[TestFixture]
    <span class="kwrd">public</span> <span class="kwrd">class</span> ProductBLTests
    {
        [Test]
        <span class="kwrd">public</span> <span class="kwrd">void</span> GetProductsTest()
        {
            MockRepository mocks = <span class="kwrd">new</span> MockRepository();
            ProductDAL dal = (ProductDAL)mocks.StrictMock(<span class="kwrd">typeof</span>(ProductDAL));
            <span class="kwrd">using</span> (mocks.Record())
            {
                List&lt;Product&gt; expectedProducts = <span class="kwrd">new</span> List&lt;Product&gt;();
                Product p = <span class="kwrd">new</span> Product();
                p.Name = <span class="str">&quot;Dell Pc&quot;</span>;
                p.Id = 333;
                expectedProducts.Add(p);

                Expect.Call(dal.GetProducts()).Return(expectedProducts);
            }

            <span class="kwrd">using</span> (mocks.Playback())
            {
                ProductBL bl = <span class="kwrd">new</span> ProductBL(dal);
                List&lt;Product&gt; products = bl.GetProducts();
                Assert.AreEqual(1, products.Count);
            }

        }
    }</pre>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->
<p>
	Some developers can say than Dependency Injection is a not good pattern for database layer and there are some another patterns for this purpose, but I like this solution, and successfully using it. <!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
]]></content:encoded>
			<wfw:commentRss>http://alexandershapovalov.com/dependency-injection-design-pattern-71/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

