tag:blogger.com,1999:blog-49718041375227555502024-02-21T02:04:28.017-08:00ASP.net , C#, SqlserverPost contains my learning in asp.net, c# and sqlserver 2005.Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.comBlogger22125tag:blogger.com,1999:blog-4971804137522755550.post-3028715546339975492010-05-07T00:19:00.000-07:002010-05-07T01:29:43.105-07:00LINQ lambda Samples (Partitioning operator) : 'SkipWhile' example'SkipWhile' is similar to takewhile except that skipwhile will take the values from list until the condition is met.<br /><br /><em><span style="color:#000099;">public void SkipWhileSimple()<br /> {<br /> int[] num = { 34, 56, 72, 74, 223, 442, 4, 61, 40 };<br /><br /> Console.WriteLine("\n\nPrint num ");<br /> foreach (int j in num)<br /> Console.Write("{0} ", j);<br /><br /> Console.WriteLine("\n\nPrint num(unordered) with SkipWhile until value is not > 150 ");<br /> IEnumerable<int> i1 = num.SkipWhile(a => a < 150);<br /> foreach (int j in i1)<br /> Console.Write("{0} ", j);<br /><br /> Console.WriteLine("\n\nPrint num (ordered) with SkipWhile until value is not > 150 ");<br /> IEnumerable<int> i2 = num.OrderBy(a => a).SkipWhile(a => a < 150);<br /> foreach (int j in i2)<br /> Console.Write("{0} ", j); <br /> }<br /></em></span><br /><br /><b>OUTPUT :</b><br /><em><span style="color:green;">Print num<br />34 56 72 74 223 442 4 61 40<br /><br />Print num(unordered) with SkipWhile until value is not > 150<br />223 442 4 61 40<br /><br />Print num (ordered) with SkipWhile until value is not > 150<br />223 442<br /></span></em>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.comtag:blogger.com,1999:blog-4971804137522755550.post-87000446764601660282010-05-06T01:38:00.000-07:002010-05-06T01:44:44.181-07:00LINQ Samples (Partitioning operator) : 'TakeWhile'<b>Example Simple</b>:'TakeWhile' will list all the items in a collection until it reaches the condition given .Following example show its usage.<br /><em><span style="color:#000099;"><br />public void TakeWhileSimple()<br /> {<br /> int[] num = { 34, 56, 72, 74, 223, 442, 4, 61, 40 };<br /><br /> Console.WriteLine("Print num ");<br /> foreach (int j in num)<br /> Console.Write("{0} ", j);<br /><br /> Console.WriteLine("\n\nPrint num(unordered) with TakeWhile until value is not < 150 ");<br /> IEnumerable<int> i1 = num.TakeWhile(a => a < 150);<br /> foreach (int j in i1)<br /> Console.Write("{0} ", j);<br /><br /> Console.WriteLine("\n\nPrint num (ordered) with TakeWhile until value is not < 150 ");<br /> IEnumerable<int> i2 = num.OrderBy(a=>a).TakeWhile(a => a < 150);<br /> foreach (int j in i2)<br /> Console.Write("{0} ", j); <br /> }<br /></em></span><br /><br /><b>OUTPUT :</b><br /><em><span style="color:green;"><br />Print num<br />34 56 72 74 223 442 4 61 40<br /><br />Print num(unordered) with TakeWhile until value is not < 150<br />34 56 72 74<br /><br />Print num (ordered) with TakeWhile until value is not < 150<br />4 34 40 56 61 72 74<br /></span></em><br /><br /><b>Example Nested</b>: In this example we are first order the list and then uses 'TakeWhile' .The output generated is equivalent to using 'Where' clause. However note that the purpose of 'TakeWhile' is complete different.<br /><em><span style="color:#000099;"><br />public void TakeWhileMore()<br /> {<br /> List<Product> prodA = new List<Product> { <br /> new Product { productID=1, productName="Prod1", productPrice=100.50, stockQuantity= 10 }, <br /> new Product { productID=2, productName="Prod2", productPrice=129.50, stockQuantity= 15 }, <br /> new Product { productID=3, productName="Prod3", productPrice=51.00, stockQuantity= 120 }, <br /> new Product { productID=4, productName="Prod4", productPrice=79.50, stockQuantity= 30 }, <br /> new Product { productID=3, productName="Prod5", productPrice=30.00, stockQuantity= 120 }, <br /> new Product { productID=4, productName="Prod6", productPrice=19.50, stockQuantity= 30 }, <br /><br /> };<br /><br /> Console.WriteLine("\nTake While price < 99\n");<br /><br /> // prints nothing since 'prodA' start with price = '100.50'<br /> var v = prodA.TakeWhile(a => a.productPrice < 99);<br /><br /> // This will print the 4 rows where the price is less than 99.<br /> // Ordered + TakeWhile = Where<br /> <br /> var u = prodA.OrderBy(a=>a.productPrice).TakeWhile(a => a.productPrice < 99); <br /><br /> foreach (var v1 in u)<br /> {<br /> Console.WriteLine("ProdId:{0}, ProdName:{1}, Price:{2}, Qty:{3}",<br /> v1.productID, v1.productName, v1.productPrice, v1.stockQuantity );<br /> }<br /> <br /> }<br /></em></span><br /><br /><b>OUTPUT :</b><br /><em><span style="color:green;"><br />Take While price < 99<br /><br />ProdId:4, ProdName:Prod6, Price:19.5, Qty:30<br />ProdId:3, ProdName:Prod5, Price:30, Qty:120<br />ProdId:3, ProdName:Prod3, Price:51, Qty:120<br />ProdId:4, ProdName:Prod4, Price:79.5, Qty:30<br /></span></em>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.comtag:blogger.com,1999:blog-4971804137522755550.post-87976911986204537542010-05-06T01:13:00.000-07:002010-05-07T01:30:50.014-07:00LINQ lambda Samples (Partitioning operator) : 'Skip' simple and Nested<b>Example Simple: </b>Skip is the opposite of 'Take', where it skips the values in a collection until numeric value specified. Following simple example shows the usage if 'skip' which skips first'5' values.<br /><em><span style="color:#000099;"><br />public void SkipSimple()<br /> {<br /> int[] num = { 34, 56, 72, 74, 223, 442, 4, 61, 40 };<br /><br /> Console.WriteLine("Print num ");<br /> foreach (int j in num)<br /> Console.Write("{0} ", j);<br /><br /> Console.WriteLine("\n\nPrint num with Skip(5) ");<br /> IEnumerable<int> i = num.Skip(5);<br /><br /> foreach (int j in i)<br /> {<br /> Console.Write("{0} ", j);<br /> }<br /> }<br /></em></span><br /><b>OUTPUT :</b><em><span style="color:green;"><br />Print num<br />34 56 72 74 223 442 4 61 40<br /><br />Print num with Skip(5)<br />442 4 61 40<br /></span></em><br /><b>Example Nested : </b> Consider the following example which first filters the collection and then apply 'Skip' to it.<br /><em><span style="color:#000099;"><br />public void SkipNested()<br /> {<br /> int[] num = { 34, 36, 56, 72, 45, 74, 223, 442, 4, 61, 40 };<br /><br /> Console.WriteLine("Print num");<br /> foreach (int j in num)<br /> Console.Write("{0} ", j);<br /><br /> Console.WriteLine("\n\nPrint num where value > 25");<br /> IEnumerable<int> i1 = num.Where(a => a > 25);<br /> foreach (int j in i1)<br /> Console.Write("{0} ", j);<br /><br /> Console.WriteLine("\n\nPrint num where value > 25 and skip 5");<br /> IEnumerable<int> i2 = num.Where(a => a > 25).Skip(5);<br /> foreach (int j in i2)<br /> Console.Write("{0} ", j);<br /> }<br /></em></span><br /><b>OUTPUT :</b><em><span style="color:green;"><br />Print num<br />34 36 56 72 45 74 223 442 4 61 40<br /><br />Print num where value > 25<br />34 36 56 72 45 74 223 442 61 40<br /><br />Print num where value > 25 and skip 5<br />74 223 442 61 40<br /></span></em>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.com0tag:blogger.com,1999:blog-4971804137522755550.post-10354403981044964482010-05-03T04:44:00.000-07:002010-05-03T04:52:34.460-07:00LINQ Samples (Partitioning operator) : 'Take' simple and Nested<b>Example simple</b> : Example takes the first 5 values from the collection using the 'Take' operator<br /><br /><em><span style="color:#000099;"><br />public void TakeSimple()<br /> {<br /> int[] num = { 34,56,72,74,223,442,4, 61 , 40 };<br /><br /> Console.WriteLine("Print num ");<br /> foreach (int j in num)<br /> Console.Write("{0} ",j);<br /><br /> Console.WriteLine("\n\nPrint num with take(5) ");<br /> IEnumerable<int> i = num.Take(5);<br /><br /> foreach (int j in i)<br /> {<br /> Console.Write("{0} ",j);<br /> }<br /> }<br /></em></span><br /><br /><b>OUTPUT :</b><br /><em><span style="color:green;"><br />Print num<br />34 56 72 74 223 442 4 61 40<br /><br />Print num with take(5)<br />34 56 72 74 223<br /></span></em><br /><br /><br /><b>Example Nested</b> : Following example first check a condition using restriction operator 'where', then applies 'Take' to the result <br /><br /><em><span style="color:#000099;"><br />public void TakeNested()<br /> {<br /> int[] num = { 34, 36 , 56, 72, 45 , 74, 223, 442, 4, 61, 40 };<br /><br /> Console.WriteLine("Print num");<br /> foreach (int j in num)<br /> Console.Write("{0} ", j);<br /> <br /> Console.WriteLine("\n\nPrint num where value > 25");<br /> IEnumerable<int> i1 = num.Where(a => a > 25); <br /> foreach (int j in i1)<br /> Console.Write("{0} ", j);<br /> <br /> Console.WriteLine("\n\nPrint num where value > 25 and take only 5");<br /> IEnumerable<int> i2 = num.Where(a => a > 25).Take(5); <br /> foreach (int j in i2)<br /> Console.Write("{0} ", j); <br /> }<br /></em></span><br /><br /><b>OUTPUT :</b><br /><em><span style="color:green;"><br />Print num<br />34 36 56 72 45 74 223 442 4 61 40<br /><br />Print num where value > 25<br />34 36 56 72 45 74 223 442 61 40<br /><br />Print num where value > 25 and take only 5<br />34 36 56 72 45<br /><br /></span></em>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.comtag:blogger.com,1999:blog-4971804137522755550.post-59773941718481069232010-05-03T02:14:00.000-07:002010-05-03T02:21:42.869-07:00LINQ Samples (Projection Operators) : Select Compound 2Following example uses LINQ lambda on a 2 set of objects. Eventhough join is used here the condition is set to 'true', simply to join the collection.<br /><br />Also note the 'query' equivalent of the lambda code as commented out section .(Eventhough the query expression is easier to write, this examples are all in lambda expression of people who are interested in lambdas)<br /><br /><em><span style="color:#000099;"><br /> private void SelectManyCompound()<br /> {<br /> List<Product> prodA = new List<Product> { <br /> new Product { productID=1, productName="Prod1", productPrice=100.50, stockQuantity= 10 }, <br /> new Product { productID=2, productName="Prod2", productPrice=89.50, stockQuantity= 15 }, <br /> new Product { productID=3, productName="Prod3", productPrice=10.00, stockQuantity= 120 }, <br /> new Product { productID=4, productName="Prod4", productPrice=19.50, stockQuantity= 30 }, <br /><br /> };<br /><br /> List<Order> orderA = new List<Order> {<br /><br /> new Order { CustomerName="Ben", OrderNo=1, TotalAmt= 1000},<br /> new Order { CustomerName="Alice", OrderNo=2, TotalAmt= 900},<br /> new Order { CustomerName="Sam", OrderNo=3, TotalAmt= 700},<br /> };<br /> <br /> var v = prodA.Join(orderA, a => true, b => true,<br /> (a, b) =><br /> new<br /> {<br /> Prod = a,<br /> order = b<br /> })<br /> .Where( (c) => c.Prod.productPrice > 75 ); <br /> <br /> <b>/* Equivalent code using Query <br /> var v = from a in prodA<br /> from b in orderA<br /> where a.productPrice > 75<br /> select new { Prod = a, order = b }; <br /> */</b><br /> foreach (var v1 in v)<br /> {<br /> Console.WriteLine("ProdId:{0}, ProdName:{1}, Price:{2}, Qty:{3}, CustNm:{4}, OrdNo:{5},Total:{6}",<br /> v1.Prod.productID,v1.Prod.productName,v1.Prod.productPrice,v1.Prod.stockQuantity,<br /> v1.order.CustomerName,v1.order.OrderNo,v1.order.TotalAmt <br /> );<br /> }<br /> }<br /></em></span><br /><br /><b>OUTPUT</b><br /><em><span style="color:green;"><br />ProdId:1, ProdName:Prod1, Price:100.5, Qty:10, CustNm:Ben, OrdNo:1,Total:1000<br />ProdId:1, ProdName:Prod1, Price:100.5, Qty:10, CustNm:Alice, OrdNo:2,Total:900<br />ProdId:1, ProdName:Prod1, Price:100.5, Qty:10, CustNm:Sam, OrdNo:3,Total:700<br />ProdId:2, ProdName:Prod2, Price:89.5, Qty:15, CustNm:Ben, OrdNo:1,Total:1000<br />ProdId:2, ProdName:Prod2, Price:89.5, Qty:15, CustNm:Alice, OrdNo:2,Total:900<br />ProdId:2, ProdName:Prod2, Price:89.5, Qty:15, CustNm:Sam, OrdNo:3,Total:700<br /><br /></span></em>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.com0tag:blogger.com,1999:blog-4971804137522755550.post-16407813679748774542010-05-03T02:08:00.000-07:002010-05-03T02:14:41.178-07:00LINQ Samples (Projection Operators) : Select CompoundFollowing example is using select on 2 set of collections.The example is equivalent to the query <br /><b><br />var v = from a in numA<br /> from b in numB<br /> where a < b<br /> select new { a = a,b = b};<br /></b><br /><em><span style="color:#000099;"><br />private void SelectMany()<br /> {<br /> List<int> numA = new List<int> { 12, 25, 5, 6, 7, 28, 9 };<br /> List<int> numB = new List<int> { 11, 22, 15, 16, 27 };<br /><br /> var v = numA.Join(numB, a => true, b => true,<br /> (a, b) => new { a= a, b=b }).Where(c=>c.a < c.b ); <br /><br /> foreach (var v1 in v)<br /> {<br /> Console.WriteLine("{0}",v1 );<br /> }<br /> }<br /></em></span><br /><br />OUTPUT<br /><em><span style="color:green;"><br />{ a = 12, b = 22 }<br />{ a = 12, b = 15 }<br />{ a = 12, b = 16 }<br />{ a = 12, b = 27 }<br />{ a = 25, b = 27 }<br />{ a = 5, b = 11 }<br />{ a = 5, b = 22 }<br />{ a = 5, b = 15 }<br />{ a = 5, b = 16 }<br />{ a = 5, b = 27 }<br />{ a = 6, b = 11 }<br />{ a = 6, b = 22 }<br />{ a = 6, b = 15 }<br />{ a = 6, b = 16 }<br />{ a = 6, b = 27 }<br />{ a = 7, b = 11 }<br />{ a = 7, b = 22 }<br />{ a = 7, b = 15 }<br />{ a = 7, b = 16 }<br />{ a = 7, b = 27 }<br /><br /></span></em>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.com0tag:blogger.com,1999:blog-4971804137522755550.post-66669224042025371242010-05-02T23:49:00.000-07:002010-05-03T01:19:59.626-07:00LINQ Samples (Projection Operators) : Select FilteredIn following example we see how to filter the using the 'where' clause. Example will produce the list of students that have roll numbers less than 10. Roll number is in int variable 'rollnum' and student's name are in string variable 'Studname'.<br /><br />See how first we need to fetch the element and the corresponding positions such that we can fetch the proper name from studname'<br /><br /><br /><em><span style="color:#000099;"><br />private void SelectFiltered()<br /> {<br /> int[] Rollnum = { 6, 8, 2, 4, 12, 11, 7, 1, };<br /> string[] StudName = { "Betty", "Helen", "Alice", "Ben", "Zen", "Jim", "Davan", "Alan" };<br /><br /> var roll = Rollnum <br /> // get the Element,index<br /> .Select( (a,b) => new<br /> {<br /> rollnum = a ,<br /> index = b<br /> })<br /> // get the Rollnum which are < 10<br /> .Where((a) => a.rollnum < 10) <br /> // get the studname corresponding to the Rollnum index<br /> .Select((a)=> new <br /> {<br /> stud = StudName[a.index] <br /> })<br /> //Order based on name<br /> .OrderBy(c=>c.stud);<br /><br /> Console.WriteLine("Student with Roll num < 10");<br /> foreach (var s in roll)<br /> {<br /> Console.WriteLine("{0}", s.stud);<br /> } <br /> }<br /></em></span><br /><br /><b>OUTPUT</b><br /><em><span style="color:green;"><br />Student with Roll num < 10<br />Alan<br />Alice<br />Ben<br />Betty<br />Davan<br />Helen<br /><br /></span></em>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.com0tag:blogger.com,1999:blog-4971804137522755550.post-14398561607973704842010-05-01T03:59:00.000-07:002010-05-01T04:36:33.599-07:00LINQ Samples (Restriction operator) : Select simple 1A simple where clause used to find all elements that are greater than value 'x'<br /><em><span style="color:#000099;"><br />private void LINQWhereOne()<br /> { <br /> //Find Array where elements are less than x;<br /> int x = 25;<br /><br /> int[] numeric = new int[] { 12, 18, 35, 50, 24, 25, 10, 15, 18 };<br /> var lessThanX = numeric.Where(a => a < x);<br /><br /> Console.WriteLine("Array where elements are less than {0}",x);<br /> foreach(int i in lessThanX )<br /> {<br /> Console.WriteLine("{0}",i);<br /> } <br /> }<br /></span></em><br />OUTPUT :<br /><em><span style="color:green;"><br />Array where elements are less than 25<br />12<br />18<br />24<br />10<br />15<br />18<br /></span></em><br /><br /><b><font color=#cd5c5c>LINQ Samples (Restriction Operators) : Select simple 2</font></b><br />Going forward with 'Where' another simple example that works with Object<br /><em><span style="color:#000099;"><br />private void LINQWhereTwo()<br /> {<br /> //Find product where stock is 0<br /> var noStock = prod.Where(a => a.Stock <= 0);<br /><br /> Console.WriteLine("Product where stock is 0");<br /> foreach (Product pd in noStock)<br /> {<br /> Console.WriteLine("ProductId : {0} ,ProductName : {1} , ProductPrice : {2} , Stock : {3}",<br /> pd.ProductId, pd.ProductName, pd.ProductPrice, pd.Stock );<br /> } <br /> }<br /></span></em><br />OUTPUT :<br /><em><span style="color:green;"><br />Product where stock is 0<br />ProductId : 5 ,ProductName : Noodles , ProductPrice : 25.4 , Stock : 0<br />ProductId : 6 ,ProductName : Washing Powder , ProductPrice : 25.4 , Stock : 0<br /></span></em>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.com0tag:blogger.com,1999:blog-4971804137522755550.post-41866519277473323602010-04-26T03:40:00.000-07:002010-04-26T04:32:32.863-07:00LINQ Samples (Projection Operators) : Select IndexedIn this example we explore the index for a given enumeration. In the statement <b><br />var str = strTech.Select( (a, b) => new { condition = a.Length > b , strTech = a });</b><br /><br /><b>a</b> is the object strTech , <b>b</b> in the index or position of enumeration, <b>new {} </b> is the anonymous type.<br /><br /><em><span style="color:#000099;"><br />private void SelectIndexed()<br /> {<br /> int[] num = { 1,2,3,4,5,6,7,8,9};<br /> string[] strTech = new string[] { "C#", "asp.net", "vb.net", "j#", "f#", "Cobol.net", "LINQ", "WCF", "WPF", "Silverlight" };<br /><br /> var str = strTech.Select( (a, b) => new { condition = a.Length > b , strTech = a });<br /><br /> foreach (var s in str)<br /> {<br /> Console.WriteLine("{0}\t{1}", s.strTech, s.condition);<br /> }<br /> }<br /></em></span><br /><br /><b>OUTPUT</b><br /><em><span style="color:green;"><br />C# True<br />asp.net True<br />vb.net True<br />j# False<br />f# False<br />Cobol.net True<br />LINQ False<br />WCF False<br />WPF False<br />Silverlight True<br /><br /></span></em>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.comtag:blogger.com,1999:blog-4971804137522755550.post-88457622721081109662010-04-26T03:31:00.000-07:002010-04-26T03:37:04.597-07:00LINQ Samples (Projection Operators) : Select AnonymousFollowing example is used with Anonymous type for a select operation.It provides an transformed output as a Anonymous type<br /><br /><em><span style="color:#000099;"><br />private void SelectAnonymousTypeOne()<br /> {<br /> string[] strTech = new string[] { "C#", "asp.net", "vb.net", "j#", "f#", "Cobol.net", "LINQ", "WCF", "WPF", "Silverlight" };<br /> <br /> var str = strTech.Select(a => <br /> new { str = a.ToString(),<br /> length = a.Length ,<br /> specialChar = a.EndsWith("#") <br /> });<br /><br /> foreach(var v in str)<br /> {<br /> Console.WriteLine("{0}\n Length:{1} Ends With #{2}",v.str,v.length , v.specialChar );<br /> <br /> } <br /> } <br /></em></span><br /><b>OUTPUT</b><br /><em><span style="color:green;"><br />C#<br /> Length:2 Ends with char '#': True<br />asp.net<br /> Length:7 Ends with char '#': False<br />vb.net<br /> Length:6 Ends with char '#': False<br />j#<br /> Length:2 Ends with char '#': True<br />f#<br /> Length:2 Ends with char '#': True<br />Cobol.net<br /> Length:9 Ends with char '#': False<br />LINQ<br /> Length:4 Ends with char '#': False<br />WCF<br /> Length:3 Ends with char '#': False<br />WPF<br /> Length:3 Ends with char '#': False<br />Silverlight<br /> Length:11 Ends with char '#': False<br /></em></span>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.comtag:blogger.com,1999:blog-4971804137522755550.post-90887717046678290952010-04-26T03:22:00.000-07:002010-04-26T03:31:19.273-07:00LINQ Samples (Projection Operators) : Select TransformationFollowing example will obtain the odd string from there index position based on the value from a different array. If this is to be acheived by for loop; two for loops are required.<br /><br /><em><span style="color:#000099;"><br /> private void SimpleSelectTransformation()<br /> {<br /> int[] num = { 1, 3, 5, 7, 9};<br /><br /> string[] strTechn = new string[] { "C#", "asp.net", "vb.net", "j#", "f#", "Cobol.net", "LINQ", "WCF", "WPF", "Silverlight" };<br /> var trans1 = num.Select(a => strTechn[a]);<br /><br /> foreach (string s in trans1)<br /> {<br /> Console.WriteLine(s);<br /> } <br /> }<br /></em></span><br /><br /><b>OUTPUT:</b><br /><em><span style="color:green;"><br />asp.net<br />j#<br />Cobol.net<br />WCF<br />Silverlight<br /></span></em>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.comtag:blogger.com,1999:blog-4971804137522755550.post-27677193593970886512010-04-26T01:43:00.000-07:002010-04-26T01:50:37.033-07:00LINQ Samples (Projection Operators) : Example 2Following example is used to obtain all product name from a list of 'Product'.<br /><br />In the statement <b>var v = prod.Select(a => a.productName);</b> a is nothing but a placeholder or act as a parameter that represent object 'prod'.<br /><br /><em><span style="color:#000099;"><br />private void SimpleSelectTwo()<br /> {<br /><br /> List<Product> prod = new List<Product><br /> { <br /> new Product() { productID=1, productName="Cooking Oil", productPrice=21.5, stockQuantity=10 },<br /> new Product() { productID=2, productName="Washing Powder", productPrice=38, stockQuantity=10 },<br /> new Product() { productID=3, productName="Tea bags", productPrice=110, stockQuantity=100 },<br /> new Product() { productID=4, productName="Garbase bags", productPrice=21.5, stockQuantity=12 },<br /> new Product() { productID=5, productName="Health drink", productPrice=85, stockQuantity=18 },<br /> new Product() { productID=6, productName="Cool drinks", productPrice=45, stockQuantity=15 }<br /> };<br /> Console.WriteLine("\nBefore LINQ :");<br /> foreach (Product pr in prod)<br /> {<br /> Console.WriteLine("ProdId: {0}, ProdName: {1}, ProdPrice: {2}, Stock: {3} ", pr.productID, pr.productName,pr.productPrice, pr.stockQuantity );<br /> }<br /><br /> var v = prod.Select(a => a.productName);<br /><br /> Console.WriteLine("\nAfter LINQ : only Product is selected");<br /> foreach(string pr in v )<br /> {<br /> Console.WriteLine("Product Name : {0}", pr); <br /> }<br /><br /> }<br /></em></span><br /><b>OUTPUT</b><br /><span style="color:green;"><br />Before LINQ :<br />ProdId: 1, ProdName: Cooking Oil, ProdPrice: 21.5, Stock: 10<br />ProdId: 2, ProdName: Washing Powder, ProdPrice: 38, Stock: 10<br />ProdId: 3, ProdName: Tea bags, ProdPrice: 110, Stock: 100<br />ProdId: 4, ProdName: Garbase bags, ProdPrice: 21.5, Stock: 12<br />ProdId: 5, ProdName: Health drink, ProdPrice: 85, Stock: 18<br />ProdId: 6, ProdName: Cool drinks, ProdPrice: 45, Stock: 15<br /><br />After LINQ : only Product name is selected<br />Product Name : Cooking Oil<br />Product Name : Washing Powder<br />Product Name : Tea bags<br />Product Name : Garbase bags<br />Product Name : Health drink<br />Product Name : Cool drinks<br /></span>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.comtag:blogger.com,1999:blog-4971804137522755550.post-46823892296881599722010-04-25T23:35:00.000-07:002010-05-07T01:32:25.653-07:00LINQ Sample using lambda ExpressionsThe <b>LINQ Samples</b> are modification for the existing examples at 'http://msdn.microsoft.com/en-us/vcsharp/aa336758.aspx'.<br /><br />The example here serve two purpose one is all are using lambda expression instead of the query used such that whoever is from a lambda expression background can understand those examples and secondly its more details for beginners.<br /><br /><b>Restriction Operators</b><br /><a href=''>Simple where 1</a><br /><a href=''>Simple where 2</a><br /><a href=''>Simple where 3</a><br /><a href=''>Simple where drill down</a><br /><a href=''>Simple where using indexed</a><br /><br /><b>Projection Operators</b><br /><a href='http://anilrajan.blogspot.com/2010/04/linq-samples-2.html'>Simple select example 1 </a><br /><a href='http://anilrajan.blogspot.com/2010/04/linq-samples-projection-operators.html'>Simple select example 2 </a><br /><a href='http://anilrajan.blogspot.com/2010/04/linq-samples-projection-operators_26.html'>Select transformation</a><br /><a href='http://anilrajan.blogspot.com/2010/04/linq-samples-projection-operators_7709.html'>Select anonymous type example1</a><br /><a href='http://anilrajan.blogspot.com/2010/04/linq-samples-projection-operators_762.html'>Select indexed</a><br /><a href='http://anilrajan.blogspot.com/2010/05/linq-samples-projection-operators.html'>Select filtered</a><br /><a href='http://anilrajan.blogspot.com/2010/05/linq-samples-projection-operators_03.html'>Select Compound 1 (combine two unrelated list)</a><br /><a href='http://anilrajan.blogspot.com/2010/05/linq-samples-projection-operators_6252.html'>Select Compound 2 (combine two unrelated list)</a><br /><br /><b>Partitioning Operators</b><br /><a href='http://anilrajan.blogspot.com/2010/05/linq-samples-partitioning-operator-take.html'>Take simple and nested</a><br /><a href='http://anilrajan.blogspot.com/2010/05/linq-samples-partitioning-operator-skip.html'>Skip simple and nested</a><br /><a href='http://anilrajan.blogspot.com/2010/05/linq-samples-partitioning-operator.html'>TakeWhile simple </a><br /><a href='http://anilrajan.blogspot.com/2010/05/linq-lambda-samples-partitioning.html'>SkipWhile simple </a><br /><a href=''>Take and Skip combined </a>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.com0tag:blogger.com,1999:blog-4971804137522755550.post-59609984146865667772010-04-25T23:13:00.000-07:002010-04-25T23:44:14.516-07:00LINQ Samples (Projection Operators) : Example 1<b>Example 1</b> : Provide a simple select which will allow to do a select on the list of string with a simple modification<br /><span style="color:#000099;"><br />private void SimpleSelectOne()<br /> { <br /> Console.WriteLine("Simple Select operations \n");<br /> string[] strTechnology = new string[] { "C#","asp.net","vb.net","j#","f#","Cobol.net","LINQ","WCF","WPF","Silverlight" };<br /><br /> Console.WriteLine("\nBefore LINQ :");<br /> foreach (string s in strTechnology)<br /> {<br /> Console.WriteLine("{0}", s);<br /> }<br /><br /> Console.WriteLine("\nAfter LINQ transform : ");<br /> var strList = strTechnology.Select( a => "MS " + a );<br /> foreach (string s in strList)<br /> {<br /> Console.WriteLine("{0}",s);<br /> }<br /> }<br /></span><br /><br /><b>OUTPUT :</b><br /><span style="color:green;"><br />BEFORE LINQ :<br />C#<br />asp.net<br />vb.net<br />j#<br />f#<br />Cobol.net<br />LINQ<br />WCF<br />WPF<br />Silverlight<br /><br />AFTER LINQ transform :<br />MS C#<br />MS asp.net<br />MS vb.net<br />MS j#<br />MS f#<br />MS Cobol.net<br />MS LINQ<br />MS WCF<br />MS WPF<br />MS Silverlight<br /></span><br /><br />You can see that the statement <strong>var strList = strTechnology.Select( a => "MS " + a );</strong> has added a string "MS" to existing string. Let it be reminded that the original string remains the same.Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.comtag:blogger.com,1999:blog-4971804137522755550.post-7683346261514620372010-04-22T01:30:00.000-07:002010-04-22T01:33:19.098-07:00Logging the progress of SSIS dataflow taskProgress of SSIS cannot be done using 'RowCount' Variable as value of a rowcount variable is set only after the execution of 'Data flow task'<br /><br />We can acheive this however by using a script Component.<br /><br />Read through the steps here ..Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.comtag:blogger.com,1999:blog-4971804137522755550.post-32048348580580010732010-01-05T04:02:00.000-08:002010-01-06T19:59:02.630-08:00SSIS QuickBytes<font color=#cd5c5c><b>How to create a dynamic subject or message for the Send Mail task in SSIS 2k5</b></font><br /><a href=http://support.microsoft.com/kb/906547>http://support.microsoft.com/kb/906547</a><br /><br /><font color=#cd5c5c><b>How to add an incremental counter in a SSIS 2k5 package by using a Script component in a Data Flow task</b></font><br /><a href=http://support.microsoft.com/kb/908460/en-us >http://support.microsoft.com/kb/908460/en-us</a><br /><br /><font color=#cd5c5c><b>Sending an HTML Mail Message with the Script Task</b></font><br /><a href=>http://msdn.microsoft.com/en-gb/library/ms403365.aspx</a><strong></strong>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.comtag:blogger.com,1999:blog-4971804137522755550.post-45112384037882835802009-12-21T21:30:00.000-08:002010-01-05T03:26:07.088-08:00SSIS Error logsSSIS Error logs and workarounds<br /><br /><font color=#cd5c5c><b>1.Error for 'Excel Destination'</b></font><br /><strong>Description </strong>: [Excel Destination [5606]] Error: The "input "Excel Destination Input" (5617)" failed because error code 0xC020907B occurred, and the error row disposition on "input "Excel Destination Input" (5617)" specifies failure on error. An error occurred on the specified object of the specified component. <br /><strong>Reason </strong>: I was getting this error when my excel file's max row count of 65536 is reached and SSIS package try to write to it. <br /><strong>Workaround </strong>: My rowcount of the result was definately not that huge, only thing was it was always appending on to the excel. Few workaround<br />1. use excel 2007 , it has 1 million rows.<br />2. Create a 2 execute sql task before the 'dataflow task, such that <strong>'execute sql task1' </strong>drops the excel table and <strong>'execute sql task2'</strong> will create the table again.<br /><br /><font color=#cd5c5c><b>2.Error when executing SSIS</b></font><br /><br /><strong>Description </strong>: Product level is insufficient for component <br /><strong>Scenario </strong>: Trying to execute a SSIS package from SSMS and its fails on "rowcount","Raw file source", "Audit"<br /><strong>Reason</strong> : SSIS is not installed on the machine where you are trying to access the package however you have SSMS<br /><strong>Workaround</strong> : <br />1. Write a scheduler/job that runs the SSIS and run it .<br />2. Login to the server where SSIS is installed and try accessing the package from there.<br />3. Install SSIS in you PC.<br /><br /><font color=#cd5c5c><b>3.Error with 'Flat file source' + variable use</b></font><br /><br /><strong>Description </strong>: The filename is a device or contains invalid characters.<br /><strong>Reason </strong>: In my case the execution on local machine was working and on deployment i was getting this failure result.<br /><strong>Workaround </strong>: I found the issue was the flat file location was both a input and output location and it was failing when both happens synchonously.<br /><br /><font color=#cd5c5c><b>4a.Error with 'Send mail Task'</b></font><br /><strong>Description </strong>: Error occur when trying to send mail<br />[Send Mail Task] Error: An error occurred with the following error message: "Mailbox unavailable. The server response was: 5.7.1 Unable to relay<br /><strong>Reason </strong>: SMTP server expect Window's authentication. <br /><strong>Workaround </strong>: To do this, Enable (check) integrated authentication for the SMTP server. See below<br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQbbvO3bFhfF3zL-JSHBTaXwtUIpAovCfaIHE53JJTWFyWTMWxU6pf6H5cFP_Aa1buY_EQCNrus3NKkQwclUmjVWp-ai1MPPM1Yv9IK7Po8SiA1zGIMzmvK91PZ18NCS8R5MS9Ko3Sfd01/s1600-h/Send+mail+failure.JPG"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 329px; height: 400px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQbbvO3bFhfF3zL-JSHBTaXwtUIpAovCfaIHE53JJTWFyWTMWxU6pf6H5cFP_Aa1buY_EQCNrus3NKkQwclUmjVWp-ai1MPPM1Yv9IK7Po8SiA1zGIMzmvK91PZ18NCS8R5MS9Ko3Sfd01/s400/Send+mail+failure.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5423188739185404690" /></a><br /><br /><br><br /><br><br /><br><br /><br><br /><br><br /><br><br /><br><br /><br><br /><br><br /><br /><font color=#cd5c5c><b>4b.Error with 'Send mail Task'+ variable use</b></font><br /><br /><strong>Description </strong>:<br />[Send Mail Task] Error: " specified string is not in the form required for an e-mail address.".<br /><strong>Scenario </strong>: When you want to configure a Send mail's Toline as a user defined variable. using Property window or using Send mail task editor.<br /><strong>WorkAround </strong>: <br />step 1 : Double click 'send mail task'.Goto expression and then select 'Toline' and then click '...' and then select the user variable. (@user::updateEmail)<br />step 2 : Goto mail and then assign @user::updateEmail for Toline.<br /><br />Execute the task. You will find that the value of variable is replaced in place of @user::updateEmail.<br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgT453cPsyFVDYOe7-6yfB58dZckxtIFmrFUDaz6GGX8L980GZy02JChHgYNnWwWjGifUvfydxCsCA2KPFJoH-7jEFpH_i7RbqmxM6moYdkvuFToQjMhW4fF-PfNcvCcD0Cm47Oj12Oc2TV/s1600-h/Send+mail+failure+-+Toline.JPG"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 400px; height: 239px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgT453cPsyFVDYOe7-6yfB58dZckxtIFmrFUDaz6GGX8L980GZy02JChHgYNnWwWjGifUvfydxCsCA2KPFJoH-7jEFpH_i7RbqmxM6moYdkvuFToQjMhW4fF-PfNcvCcD0Cm47Oj12Oc2TV/s400/Send+mail+failure+-+Toline.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5423214829012331746" /></a>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.comtag:blogger.com,1999:blog-4971804137522755550.post-17594745741453271262009-10-15T02:07:00.000-07:002010-01-06T19:59:28.807-08:00Sql Server Quick reference : How to<br><br /><b><font color=#cd5c5c>How to get the version of Sqlserver ?</font></b><br /><b>Step 1 :</b><br />Open query analyser and execute the following<br />Select serverproperty('productversion'), serverproperty('productlevel'), serverproperty('edition')<br /><br /><b>Step 2 :</b><br />If Output is <b> 10.0.1600.22</b> for first field then its sqlserver 2008<br />If Output is <b> 9.00.3257.00</b> for first field then its sqlserver 2005<br /><br />For further details : http://support.microsoft.com/kb/321185<br /><br><br /><hr><br /><b><font color=#cd5c5c>Common Solution for T-sql problems</font></b><br /><a href='http://code.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=SelectTopNbyGroup&referringTitle=Home' >'http://code.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=SelectTopNbyGroup&referringTitle=Home</a><br /><br /><font color=#cd5c5c><b>Recursive Queries Using Common Table Expressions<br /></b></font><br /><a href=http://msdn.microsoft.com/en-us/library/ms186243.aspx>http://msdn.microsoft.com/en-us/library/ms186243.aspx</a>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.comtag:blogger.com,1999:blog-4971804137522755550.post-47508362081018728402009-10-07T02:51:00.001-07:002009-10-07T02:51:36.328-07:00.net Quick referenceAnil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.comtag:blogger.com,1999:blog-4971804137522755550.post-86919253812404228332009-10-07T02:49:00.001-07:002009-10-07T02:50:38.880-07:00Common Colors reference chartAnil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.comtag:blogger.com,1999:blog-4971804137522755550.post-59050702913418554142009-09-15T05:15:00.000-07:002009-09-16T02:03:12.842-07:00C# 3.0 Implicitly typed local variable<div align="left"><table style="font-family: trebuchet ms; font-size: 13px; height: 100px;"><tbody><tr><td>In c# 3.0 we got a new keyword var which enable you to declare implicit local variables. </td></tr><tr><td>(i) Let’s look into the statement I made, its ‘local’ variable, that means cannot be used as class variables (instance variable) and is declared only in methods, not even as method parameter.</td></tr><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiO7c1cCqwgIU_In26YGEsjfMxpQk3GsB_pE05yM_R4xgUU46iCTWCcU1G5pdUWiMY8FCvYyDzvbCRjaHUCrUHDnwhe0gDOsSJvI0uF2Zexkwk5jf1LwURUeEbDjf5Lif0vwvxEMgKQ9XvM/s1600-h/Figure1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" mq="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiO7c1cCqwgIU_In26YGEsjfMxpQk3GsB_pE05yM_R4xgUU46iCTWCcU1G5pdUWiMY8FCvYyDzvbCRjaHUCrUHDnwhe0gDOsSJvI0uF2Zexkwk5jf1LwURUeEbDjf5Lif0vwvxEMgKQ9XvM/s320/Figure1.JPG" /></a></td></tr><tr><td>Figure1</td></tr><tr><td>Execution of Code1 breaks at: </td></tr><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0geT5mIAQmWav91e0NwhOt3mlLIzL0fgM-BD1LEKVV4O3s1x6p2uNUL0BzrSgG7XCkklG_vNJ5wvjhFadk9QV5Ll9K1kTnM9alIS-DEJHGDqdmh9cHvQaslFTQqmEeJnoygYz-gD3u8pT/s1600-h/Figure2.JPG"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 400px; height: 76px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0geT5mIAQmWav91e0NwhOt3mlLIzL0fgM-BD1LEKVV4O3s1x6p2uNUL0BzrSgG7XCkklG_vNJ5wvjhFadk9QV5Ll9K1kTnM9alIS-DEJHGDqdmh9cHvQaslFTQqmEeJnoygYz-gD3u8pT/s400/Figure2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5381672212262786930" /></a></td></tr><tr><td>Figure2</td></tr><tr><td>(ii)Next thing about ‘Implicit variable’ is, it should be initialized, why? It’s very obvious how the compiler will know to what type it should declare the variable as. If you correct the above two errors we will get our next error at line 19.</td></tr><tr><td></td></tr><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXBtIiclT4Up9wo-soAONhobyeh0OGpmZTC-Wp6oh4bV4vbeVJ_1ty-KP1EDzK1WeAYthlMsEGQfvBHka9wL0O5qMyhUgBvME3E2EOuVb7NXQSGvLLhV7a6MdYUqLPjFHhyphenhyphen29VbuARvS-0/s1600-h/Figure3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" mq="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXBtIiclT4Up9wo-soAONhobyeh0OGpmZTC-Wp6oh4bV4vbeVJ_1ty-KP1EDzK1WeAYthlMsEGQfvBHka9wL0O5qMyhUgBvME3E2EOuVb7NXQSGvLLhV7a6MdYUqLPjFHhyphenhyphen29VbuARvS-0/s320/Figure3.JPG" /></a><td></td></tr><tr><td>Figure3</td></tr><tr><td></td></tr><tr><td>(iii) Implicit variable cannot be null, rather cannot be null when you declare them.</td></tr><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIMd-SVzakxaMLkCzZHj1xll6m-KdRXPkZ6B7NCmG_gDr95QMEUj1HpBOxuKWxgpM6euWXEXBXP9SOJ4AW63h0bS4NamtfDwkxlLLzxY5-DsUosv7nMfDGn-4E2Ri_-UBxDbYXh1n1M0Vm/s1600-h/Figure4.JPG"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 400px; height: 166px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIMd-SVzakxaMLkCzZHj1xll6m-KdRXPkZ6B7NCmG_gDr95QMEUj1HpBOxuKWxgpM6euWXEXBXP9SOJ4AW63h0bS4NamtfDwkxlLLzxY5-DsUosv7nMfDGn-4E2Ri_-UBxDbYXh1n1M0Vm/s400/Figure4.JPG" border="0" alt=""id="Img1" /></a></td></tr><tr><td>Figure4</td></tr><tr><td>OUTPUT:</td></tr><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhw1kQJp-CtoqsgjHBc65D3m2RA29rEJD9uN6-MjT4Cns-V4vRi2IZe-KT2pfx_r7bR0hfu7OPnK3fHtFm1kiEOx3FZrdK2vAlw0nYqP4nF7rF2s_R2Gdd8T3neMFI_hIt65a5FXUcSTf_R/s1600-h/Other1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" mq="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhw1kQJp-CtoqsgjHBc65D3m2RA29rEJD9uN6-MjT4Cns-V4vRi2IZe-KT2pfx_r7bR0hfu7OPnK3fHtFm1kiEOx3FZrdK2vAlw0nYqP4nF7rF2s_R2Gdd8T3neMFI_hIt65a5FXUcSTf_R/s320/Other1.JPG" /></a></td></tr><tr><td></td></tr><br /><tr><td>You can see strE.getType() returns ‘System.String[]’</td></tr><tr><td><br /></td></tr><tr><td>(iv) When you declare an implicit variable with multiple types you will get a compile time error.</td></tr><br /><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdcrTZ9itUKUfR4g2R3vIhxax011iuYwK7DJRjvUevh2hHeKISWt-EZxFzDk0Q80BEP2151XOccD6uBEebpns2A1NrRbHAO8zsMAMPXhpvdphL5vkRHzpFs8NM0oFsgaydY7-ZoNKs4g7X/s1600-h/Figure5.JPG"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 400px; height: 70px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdcrTZ9itUKUfR4g2R3vIhxax011iuYwK7DJRjvUevh2hHeKISWt-EZxFzDk0Q80BEP2151XOccD6uBEebpns2A1NrRbHAO8zsMAMPXhpvdphL5vkRHzpFs8NM0oFsgaydY7-ZoNKs4g7X/s400/Figure5.JPG" border="0" alt=""id="Img2" /></a></td></tr><tr><td>Figure5</td></tr><br /><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiba7QU7dAYKJc4UC_FynEVeOTg66bylk51Wf5HOVv8V37khoughvpZsq1epNh6Mxfjf6izCHLIaQJZmqgHWCbdrOQtwRvRS0AwtdLbQLaKdtfTP6sCRiUnePhwq42aAyOl62eHfOfNckgE/s1600-h/Figure6.JPG"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 400px; height: 114px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiba7QU7dAYKJc4UC_FynEVeOTg66bylk51Wf5HOVv8V37khoughvpZsq1epNh6Mxfjf6izCHLIaQJZmqgHWCbdrOQtwRvRS0AwtdLbQLaKdtfTP6sCRiUnePhwq42aAyOl62eHfOfNckgE/s400/Figure6.JPG" border="0" alt=""id="Img3" /></a></td></tr><tr><td>Figure6</td></tr><tr><td></td></tr><tr><td></td></tr></tbody></table><table style="font-family: trebuchet ms; font-size: 13px;" ><tr><td><strong><h5>LINQ and Implicit variable</h5></strong></td></tr><tr><td>Declaring implicit variable using ‘Var’ keyword should be restricted is one of the recommendations in the c# specification. The reason could be that many of the new features of c# 3.0 have direct relation with LINQ and these new feature suits LINQ rather than normal programming. Let’s explore the implicit variable and LINQ relation.</td></tr><br /><tr><td><br /></td></tr><tr><td>A very good example and a simple one is given at http://msdn.microsoft.com/en-us/library/bb384061.aspx. It explains using a simple string. For you convenience I will put the example here (figure 7), now if you replace 2 instances of var with string[] and string respectively, since string look like a more likely type for ‘var’ here, you will be tempted to think replacing var with string makes things easier then, why ‘var’. However, doing so will result in following error.</td></tr><tr><td><em><span style="color:red;">ERROR :Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<AnonymousType#1>' to 'string[]'<br /></span></em></td></tr><tr><td><em><span style="color:#000099;"><br /><strong>class</strong> ImplicitlyTypedLocals2<br />{<br /> static void Main()<br /> {<br /> string[] words = { "aPPLE", "BlUeBeRrY", "cHeRry" };<br /><br /> // If a query produces a sequence of anonymous types, <br /> // then use var in the foreach statement to access the properties.<br /> var upperLowerWords =<br /> from w in words<br /> select new { Upper = w.ToUpper(), Lower = w.ToLower() };<br /><br /> // Execute the query<br /> foreach (var ul in upperLowerWords)<br /> {<br /> Console.WriteLine("Uppercase: {0}, Lowercase: {1}", ul.Upper, ul.Lower);<br /> }<br /> }<br />}<br /></span></em><em><span style="color:green;"><br />/* Outputs:<br /> Uppercase: APPLE, Lowercase: apple<br /> Uppercase: BLUEBERRY, Lowercase: blueberry<br /> Uppercase: CHERRY, Lowercase: cherry <br /> */<br /></span></em>/td></tr><tr><td>Figure 7</td></tr><tr><td>I know using string or build-in type is easy to relate, so let’s take a new example to understand the same scenario. Look at the code in figure8.Here instead of string we declare a class called SomeReturnClass and created a list< SomeReturnClass > with three values, to enable enumeration. Here use of ‘var’ cannot be replaced by SomeReturnClass for two reasons, SomeReturnClass does not have any constructor that take two int as parameters, the statement select new { x = w.updateValueI(), y = w.updateValueJ() }; therefore does not related to SomeReturnClass, therefore it’s more accurate to declare the output as ‘var’ and let compiler decide the type(Can call it anonymous type). Coming to the second use of ‘var’ at foreach (var v in objReturnClassX) , its very clear than objReturnClassX hold a type that better to be interpreted by compiler(anonymous type). Neither we have explicit convertion between ‘var’ and SomeReturnClass.</td></tr><tr><td><em><span style="color:#000099;"><strong>namespace CSharpFeatures </strong><br /><strong>{</strong><br /><br /> <strong>class ImplicitVariableLINQ </strong><br /> { <br /> public static void GetImplicitVarLINQ()<br /> {<br /> List<SomeReturnClass> objReturnClassA = new List<SomeReturnClass><br /> {<br /> new SomeReturnClass { i=0, j=2 },<br /> new SomeReturnClass { i=2, j=2 },<br /> new SomeReturnClass { i=2, j=0}<br /> };<br /> var objReturnClassX =<br /> from w in objReturnClassA<br /> select new { x = w.updateValueI(), y = w.updateValueJ() };<br /><br /> foreach (var v in objReturnClassX) {<br /> Console.WriteLine("i:{0}, j:{1} ", v.x, v.y);<br /> }<br /> }<br /> static void Main(string[] args)<br /> {<br /> ImplicitVariableLINQ.GetImplicitVarLINQ();<br /> Console.ReadLine();<br /> }<br /> }<br /><br /> <strong>class SomeReturnClass </strong> <br /> <strong>{</strong><br /> public int i, j;<br /> public SomeReturnClass() { }<br /><br /> public int updateValueI() {<br /> if (i <= 0) i = 100;<br /> else i = i + j;<br /> return i;<br /> }<br /> public int updateValueJ() {<br /> if (j <= 0) j = 200;<br /> else j = j + i;<br /> return j;<br /> }<br /> <strong>}</strong><br /> <strong>}</strong><br /><br /></span></em></td></tr><tr><td>Figure 8</td></tr><tr><td>OUTPUT</td></tr><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUZmQRFBmHLBBdJpWt5I1L4DAU7-Hys63Zl6PWv5_gjcO9dGE9JcO5P86jyJ6tCBHD3skhkQVpywIr2DcKTyjG-TJAWyyGhe3EQChiHlCTM9LkqsDbQm1tz8QeuNseDTY_WKgGWBGwO_KZ/s1600-h/Other2.JPG"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 400px; height: 91px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUZmQRFBmHLBBdJpWt5I1L4DAU7-Hys63Zl6PWv5_gjcO9dGE9JcO5P86jyJ6tCBHD3skhkQVpywIr2DcKTyjG-TJAWyyGhe3EQChiHlCTM9LkqsDbQm1tz8QeuNseDTY_WKgGWBGwO_KZ/s400/Other2.JPG" border="0" alt=""id="Img4" /></a></td></tr><br /></table></div>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.comtag:blogger.com,1999:blog-4971804137522755550.post-89962922593203091332009-09-08T19:13:00.000-07:002009-09-15T06:32:04.559-07:00Workflow foundation (WF): Creating a Simple sequential workflow with ASP.NET.<div align="left"><table style="FONT-SIZE: 13px; FONT-FAMILY: trebuchet ms" height="100"><tbody><tr><td><strong>Pre-requisite:</strong>This workflow example was created using following configuration</td></tr><tr><td>Visual studio 2008</td></tr><tr><td>.net Framework 3.5</td></tr><tr><td></td></tr><tr><td>Article assumes that the user understands the difference between sequential workflow and State machine workflow. For an overview please refer</td></tr><tr><td>Sequential Workflow:<a href="http://msdn.microsoft.com/en-us/library/ms735937.aspx">http://msdn.microsoft.com/en-us/library/ms735937.aspx</a></td></tr><tr><td>State Machine Workflow:<a href="http://msdn.microsoft.com/en-us/library/ms735945.aspx">http://msdn.microsoft.com/en-us/library/ms735945.aspx</a></td></tr><br /><tr><td><strong>Getting started</strong></td></tr><tr><td>Whoever are old .net developer using Visual studio, can relate a WF development similar to the way you develop a webservice ie. You create a webservice and expect a application(usually a asp.net application) to host it,similarly WF service is created and expect a host application to call that service. However Webservice and WF are completely different and are nowhere interchangeable.I will divide this article into 3 parts,</td></tr><tr><td>1. Creating a WF, we will look into sequential Console application</td></tr><tr><td>2. Create a Host application (an asp.net application).</td></tr><tr><td>3. How Host and WF will communicate with each other.</td></tr><tr><td><strong>Creating a Sequential Workflow</strong></td></tr><tr><td>Steps</td></tr><tr><td>1. Open visual studio File > New project.</td></tr><tr><td>2. Select c# ->Workflow-> Sequential Workflow Console application.</td></tr><tr><td>3. Give appropriate project name (I gave it as CallAnalysis.WF)</td></tr><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUMvpaIdrLuUGz8JIA67m62ALCRUzD6Q6aIetAPZrxEQYNHiMLDF3teVO665NsvjQj0RY95AU5WbxI4iDvg8fIWR4gwKX8YEpQsuGsd6VS9RyRdrazLaKd_r1MOSuNbUV5uh9pMADagDW3/s1600-h/Figure1.JPG"><img id="Img1" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 239px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUMvpaIdrLuUGz8JIA67m62ALCRUzD6Q6aIetAPZrxEQYNHiMLDF3teVO665NsvjQj0RY95AU5WbxI4iDvg8fIWR4gwKX8YEpQsuGsd6VS9RyRdrazLaKd_r1MOSuNbUV5uh9pMADagDW3/s400/Figure1.JPG" border="0" /></a></td></tr><tr><td>Figure1</td></tr><tr><td>4. The project will create Workflow1.cs, Workflow1.designer.cs, and Program.cs. Selecting the design mode for Workflow1.cs will show you an empty sequential workflow.(figure1)</td></tr><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLJyTHE0SsmcF3k7J7K6SmnV9aJJe869vsUMmvV_aoaJ-8x6xe6mzCW24e_1a3jOP4D9y-WQwomuNoO1RimN2QH_udWUK7y80fGAsdLMP1JLo6qL3dU0mKNcH9BzarmRTNy5Sib5Hv3aj6/s1600-h/Figure2.JPG"><img id="Img2" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 342px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLJyTHE0SsmcF3k7J7K6SmnV9aJJe869vsUMmvV_aoaJ-8x6xe6mzCW24e_1a3jOP4D9y-WQwomuNoO1RimN2QH_udWUK7y80fGAsdLMP1JLo6qL3dU0mKNcH9BzarmRTNy5Sib5Hv3aj6/s400/Figure2.JPG" border="0" /></a></td></tr><tr><td><strong>Business scenario</strong></td></tr><tr><td>Now before we continue lets create our business scenario or objective or functionality that the WF will do. Let’s say you are working as a support analyst for an application where you get calls from application users. Calls can be divided as Incidents and Service request. Further incident can be divided into critical, high and medium and Service request is divided into severity1, severity2 and severity3.</td></tr><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAI3i-ZswkvQPIqdQTmcS0Ei66YZT87SHugADLU7ect9ol-OXHADeihuSYtCPyUyBoqJZvQArT7R_g6ZtC6W_yf0SlGVGMsYpZlaj6bqFNDxbHPYxhx7zY2ZfsIhtSTHgcFF9-JHARyjHZ/s1600-h/Figure3.JPG"><img id="BLOGGER_PHOTO_ID_5379292784173681122" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 348px; CURSOR: hand; HEIGHT: 237px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAI3i-ZswkvQPIqdQTmcS0Ei66YZT87SHugADLU7ect9ol-OXHADeihuSYtCPyUyBoqJZvQArT7R_g6ZtC6W_yf0SlGVGMsYpZlaj6bqFNDxbHPYxhx7zY2ZfsIhtSTHgcFF9-JHARyjHZ/s400/Figure3.JPG" border="0" /></a></td></tr><tr><td>Figure 3<br /></td></tr><tr><td>Now let’s maps the scenario to our workflow application. To make things simple we will use the <strong><em>if-else activity</em></strong> and <strong><em>code activity</em></strong> only.</td></tr><tr><td>1. Open Tool box and drag the if-else between <img style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 24px; CURSOR: hand; HEIGHT: 24px" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUYfs7UDAdRLwyZqdSMloLIdq4_l2xRWM7frYBSwl5Fjevp5v6gTJntn0iYHZKEdeGdfiOssnMgsPMzjWkiFlm6HLARV4RUhmCh3Q3VQks2819c0XKOlL3SqjsfZRfeEinTBHLvM06Mb3P/s400/Other1.JPG" border="0" /> <img style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 24px; CURSOR: hand; HEIGHT: 24px" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw_8fGVvxU02v0nmnmNvN-rqfrTHMqq3DYVRq8m3F5I9giTTsLmJZXKquIJRXvQJbp_C2n2yLNqNv1bFH0n5XaseOwQ29EDkD0_xJTbXyO-WtZJCIbCbcv5fNt0Gfhml_j4k85kmUUuiI8/s400/Other2.JPG" border="0" /> symbols as shown below.</td></tr><tr><td><br /><br /><table><tbody><br /><tr><td><br /><img style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 358px; CURSOR: hand; HEIGHT: 232px" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr5f2XUBEA7xMTX8bPwx7_aN8kGXa78WemRCRkVNIcgzx-jX55AFYjkPW_cAgb3PSdPQ6pRutUXX6vuciz4rWSb242738wRBUPaR_rcrEJvNm41Cm2mVijlxcCX8zr-D-t4m1wqws7OazG/s400/Figure4a.JPG" border="0" /></td></tr><br /><tr><td>To</td></tr><br /><tr><td><img style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 374px" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4YmD1FgN0CR8Y4WEuNgOqLZfYdVaMCyCFJJqkoC5i0lpHS24QS5uo_0Zk8Tu1oiVjC3e35s4tQ0qLUfVKZqekqS0JOBqoouxvCvlBEbS6c5nU30CznOmUvVnotMrj-b9HJ_bLEQwHkaky/s400/Figure4b.JPG" border="0" /><br /></td><br /></tr><br /></tbody><br /></table><br /><br /></td></tr><tr><td>Figure 4<br /><br /></td></tr><tr><td>2. Give appropriate names to the <em>ifelseActivity1</em>, <em>ifelseBranchActivity1</em> and <em>ifelseBranchActivity2</em>. In the drop activity for <em>ifelseBranchActivity1</em> add an <em><strong>if-else activity</strong></em>. Name the controls as shown below.</td></tr></tbody></table><table style="FONT-SIZE: 13px; FONT-FAMILY: trebuchet ms"><br /><tbody><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjq9h-R-r_FRnYqFOUunWvjp8KUTfce7QMtr4ORKL8WT0sgwpi0RskqwlihG55BDKZpjd5LkVvabR_woRooSe46TlH6qEp-bDw3ecgGMpDEilreOA4-n-xUGAY7WO59Ikrnx3e0ktwFKiZt/s1600-h/Figure5.JPG"><img id="Img6" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 336px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjq9h-R-r_FRnYqFOUunWvjp8KUTfce7QMtr4ORKL8WT0sgwpi0RskqwlihG55BDKZpjd5LkVvabR_woRooSe46TlH6qEp-bDw3ecgGMpDEilreOA4-n-xUGAY7WO59Ikrnx3e0ktwFKiZt/s400/Figure5.JPG" border="0" /></a></td></tr><tr><td>Figure 5 <br/></td></tr><tr><td>3. To explain figure5, workflow start at <em>ifElseCallMain</em> which we will configure later to check for the condition of call. If the call is an incident the control will go to <em>IfIncident</em> else to <em>IfServiceRequest</em>. If call is an incident, then control will go to the if-elsebranch <em>IfElseIncident</em>. Now for <em>IfelseIncident,</em> we need to configure to check for the condition whether it’s critical, high or medium. By default an <strong><em>if-else activity</em></strong> adds two conditions. If we need to add more conditions we need to add something called <strong><em>if-else-branch activity</em></strong>.</td></tr><tr><td>4. To add if-else-branch activity, right click anywhere with-in the boundary of <em>ifelseIncident</em> and click Add Branch.</td></tr><br /><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpMe395AtrhT2EK762CVPlexeqacfvRsfE6atDFudAZlWeEszXVs-GmNqi_1QuSjJ-HCtUUYGrU0B-AbkHLnMc5NJ9r3lItHvcUU-tCVZfgXDudoP32vEqUpxISN8jAemP0t7u3VIvzEn5/s1600-h/Figure6.JPG"><img id="Img4" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 302px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpMe395AtrhT2EK762CVPlexeqacfvRsfE6atDFudAZlWeEszXVs-GmNqi_1QuSjJ-HCtUUYGrU0B-AbkHLnMc5NJ9r3lItHvcUU-tCVZfgXDudoP32vEqUpxISN8jAemP0t7u3VIvzEn5/s400/Figure6.JPG" border="0" /></a></td></tr><tr><td>Figure 6</td></tr><tr><td>5. Name the new branch as ‘ifMedium’.This will add a new branch called <em>IfMedium</em> for<em> ifelseIncident</em></td></tr><tr><td></td></tr><tr><td><strong>Adding condition: Code condition and Declarative rule condition</strong></td></tr><tr><td>Now if you see the designer you will find <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4dMuf53jh60AHJ1Vyok4JfYPDNmaE0oXXprwKrchB1Ymo9tlzAzBga_SAaiUY9SIHX44R9d6NSKnCgCMNgLEJSrBp-h76lMnw9XXCAnnq2yFJlgzJyEOa4tQGQhtz0FMNjye06LO-xkOs/s1600-h/Other3.JPG"></a>exclamation in red, that says when clicked </td></tr><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj24A3LYW2ev5gm_oZxU-bEAzSWcFnB_xFZWEFgtinoPIFclbcybFhozQX2iqtvpqnrGUf6QnMOJSwXgPRcqUs2FV3V_lPECs4URTSW3tXVJLrp521n4u17XKculla9kf8euSo8JIRoLDwC/s1600-h/Other4.JPG"><img id="Img6" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 215px; CURSOR: hand; HEIGHT: 54px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj24A3LYW2ev5gm_oZxU-bEAzSWcFnB_xFZWEFgtinoPIFclbcybFhozQX2iqtvpqnrGUf6QnMOJSwXgPRcqUs2FV3V_lPECs4URTSW3tXVJLrp521n4u17XKculla9kf8euSo8JIRoLDwC/s400/Other4.JPG" border="0" /></a></td></tr><tr><td></td></tr><br /><tr><td>Now select ‘IfCritical’ and on the property window select ‘condition’, you will see 3 options <em>None</em>, <em>Code condition</em> and <em>Declarative rule condition</em>.None is the default and we are required to select either of the other two.</td></tr><tr><td><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 266px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiswSDk-SocPNmY3C53eGCFHmymlE3rIaferW5BMXGWKYScL3fmkPJHAFc4XOtQr2ilxkcuL_2F3_bOuJxDonpBPyU9TMkAdii9ZjwIZKzVfniQNYfOjJnJYsPidXwLi5uNW66_p6ctZa7U/s400/Figure7.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5379371749089880082" /></td></tr><tr><td>Figure 7<br/><br/></td></tr><tr><td><strong>Code Condition</strong>: When you want your condition to be evaluated based on your custom code. Drawback is the change in condition requires re-compilation.</td></tr><tr><td><strong>Declarative Rule Condition</strong>: When an expression is evaluated to obtain the Boolean value for the condition. Here a .rules xml file is created that evaluate the condition.</td></tr><tr><td>We will explore both of these options. For Incident scenario we will write Code condition and for service request scenario we will use Declarative Rule condition.</td></tr></tbody></table><table style="FONT-SIZE: 13px; FONT-FAMILY: trebuchet ms" height="100"><tbody><tr><td><strong>CODE CONDITION IMPLEMENTATION</strong>:</td></tr><tr><td>1. Make the following changes for IfCritical, i.e. give the condition property to ‘code condition’.</td></tr><tr><td></td></tr><tr><td>Figure 8<br/></td></tr><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZqReCmyNqoSaP6H6Yqa0oVZE3kKoT2c2CU75F1HCxJCxuzJWNjfkgcqrwGjTqiHl83hBrksuFxfgjvPPz6p2p874aa1q_QX3BJrq5dldBLBIQBt0E2nPp40IuD3gitOtnqnPsRXVsLt1g/s1600-h/Figure8.JPG"><img id="Img8" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 267px; CURSOR: hand; HEIGHT: 198px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZqReCmyNqoSaP6H6Yqa0oVZE3kKoT2c2CU75F1HCxJCxuzJWNjfkgcqrwGjTqiHl83hBrksuFxfgjvPPz6p2p874aa1q_QX3BJrq5dldBLBIQBt0E2nPp40IuD3gitOtnqnPsRXVsLt1g/s400/Figure8.JPG" border="0" /></a></td></tr><tr><td>2. This will give an additional property called condition. If you open the view-code for workflow1.cs, the name ‘CheckIncidentCritical’, will be the event names that visual studio automatically generates for you.</td></tr><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhM7ishQwNUo-_UvsjCekm7gH5zlqkWf1KAGV8QbHNGXtjnIW8xhkvXVRZbyw92pu-OvQwAh4Ck0SpIMC6Tv4C7nHqiPsJeMe68ufVAIKH-tX8T50JxQyQIfYhDTvcYoigkJHg_kN8gv3Bl/s1600-h/Figure9.JPG"><img id="Img9" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 253px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhM7ishQwNUo-_UvsjCekm7gH5zlqkWf1KAGV8QbHNGXtjnIW8xhkvXVRZbyw92pu-OvQwAh4Ck0SpIMC6Tv4C7nHqiPsJeMe68ufVAIKH-tX8T50JxQyQIfYhDTvcYoigkJHg_kN8gv3Bl/s400/Figure9.JPG" border="0" /></a></td></tr><tr><td>Figure 9<br/><br /></td></tr><tr><td>3. Make the changes for IfHigh and IfMedium, similar to IfCritical and name the events CheckIncidentHigh and CheckIncidentMedium respectively.</td></tr><tr><td>4. For IfIncident too select condition as ‘code condition’ and name the condition property as ‘CheckIncident’. Now do following changes to code</td></tr><tr><td><br /><em><span style="color:#000099;">public sealed partial class Workflow1: SequentialWorkflowActivity<br />{<br />public Workflow1(){<br />InitializeComponent();<br />}<br />private void CheckIncidentCritical(object sender, ConditionalEventArgs e){<br />Console.WriteLine("Incident-Critical Reached");<br />}<br />private void CheckIncidentHigh(object sender, ConditionalEventArgs e){<br />Console.WriteLine("Incident-High Reached");<br />e.Result = true;<br />}<br />private void CheckIncidentMedium(object sender, ConditionalEventArgs e) {<br />Console.WriteLine("Incident-Medium Reached");<br />}<br />private void CheckIncident(object sender, ConditionalEventArgs e){<br />Console.WriteLine("Incident Main Reached");<br />e.Result = true;<br />}<br />}<br /></span></em><br /><br /></td></tr><tr><td>5. Let’s have our first compilation. Right click the project and select build. Solution should compile without any error.<br /></td></tr><tr><td>6. Now we are ready for our first run. Open the file ‘Program.cs’, it is the file that is currently helping us to be the Host application. Put a break-point on line ‘instance.start()’ as shown below.<br /></td></tr><tr><td><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitqNvyHKz-eXZ2aId_6lHAhw5yIKPqkE5SfMVSNP-gEC0al6z8hcKZU4cYtIJSsNmxTY6OT047Qqbbo9-klAcQn8czcJGhtSLeZ0aRaT3m1QsrhAOvmQHcTagH9qKrCRo-aX2nmDhruXW7/s1600-h/Figure10.JPG"><img id="Img10" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 203px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitqNvyHKz-eXZ2aId_6lHAhw5yIKPqkE5SfMVSNP-gEC0al6z8hcKZU4cYtIJSsNmxTY6OT047Qqbbo9-klAcQn8czcJGhtSLeZ0aRaT3m1QsrhAOvmQHcTagH9qKrCRo-aX2nmDhruXW7/s400/Figure10.JPG" border="0" /></a></td></tr><tr><td>Figure 10<br /><br /></td></tr><br /><tr><td>7. Right click the solution and select “debug->start a new instance”. Press F10 until reach next line. Check the console window. Output looks like this<br /></td></tr><tr><td><br />OUTPUT:</td></tr><tr><td><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidJayM4ClCDQfntuKWgsQ77OJ5GjiJzYp6UJLbrtD9dATBgXaJzpcLZafHXv_0G_S20gZnvndqbfoU04LCt2U8D_rWUo8otXaAgAhyphenhyphenq1t0dHML7VTx2npD6FQDtA5qr48lMA8zxZyMAnmh/s1600-h/Figure11.JPG"><img id="Img11" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 95px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidJayM4ClCDQfntuKWgsQ77OJ5GjiJzYp6UJLbrtD9dATBgXaJzpcLZafHXv_0G_S20gZnvndqbfoU04LCt2U8D_rWUo8otXaAgAhyphenhyphenq1t0dHML7VTx2npD6FQDtA5qr48lMA8zxZyMAnmh/s400/Figure11.JPG" border="0" /></a></td></tr><tr><td><br />Figure 11<br /></td></tr><tr><td><strong>Explanation:</strong></td></tr><tr><td>1. Ifincident will evaluate to true because of e.result=true in following line of code<br /></td></tr><br /><tr><td><br /><em><span style="color:#000099;">private void CheckIncident(object sender, ConditionalEventArgs e){<br />Console.WriteLine("Incident Main Reached");<br />e.Result = true;<br />}</span></em><br /></td></tr><tr><td>2. Control goes to ‘ifcritical’ where e.result is not set and bool’s default value ‘false’ is taken. Print statement executed.<br /></td></tr><tr><td>3. Control goes to ‘Ifhigh’, here e.result is set to true. Print statement executed.</td></tr><tr><td>4. Since no more statements follow it. Execution is stopped.<br /></td></tr><tr><td>I know here you must be thinking, there seems no big difference since false and true both resulted in printing. So let’s get into little more coding with reading values from input window and seeing the difference. For that do the following changes to design.</td></tr><tr><td>1. Add a code activity (refer figure4 to add a control from toolbox to workflow) for each of the ifcritical, ifhigh and ifMedium activity and associate the code with it such that following changes happen in Design(figure12) and Code(figure13) respectively.<br /></td></tr><tr><td><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmr9dqYx86Z1mhA0djtxzW-5kWog6WbgvfjUcjS6gy7cJMitDrfbokjGG_vTBMcfxCBMegsW1nKmu1fXyYRH41Lkvk0aLQV_KzFn0u5Ajxx1j-moOGBhH8v6JNe12JOA8Qct1ULLp3DXWn/s1600-h/Figure12.JPG"><img id="Img12" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 276px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmr9dqYx86Z1mhA0djtxzW-5kWog6WbgvfjUcjS6gy7cJMitDrfbokjGG_vTBMcfxCBMegsW1nKmu1fXyYRH41Lkvk0aLQV_KzFn0u5Ajxx1j-moOGBhH8v6JNe12JOA8Qct1ULLp3DXWn/s400/Figure12.JPG" border="0" /></a></td></tr><tr><td>Figure 12<br /></td></tr><br /><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhm93wicfX57_WhyphenhyphenJDarIulZNu2qA_Z61SQHJ06rE-AY4jdE9u7P_7G0AcnQxvJUUrlqnNHTH0KdjSg0S-mULfkupctZByxfZdBON6jFE0TriLArGuZmIbg7GO-jB7oRBHFLZM6bDdTenfl/s1600-h/Figure13.JPG"><img id="Img13" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 384px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhm93wicfX57_WhyphenhyphenJDarIulZNu2qA_Z61SQHJ06rE-AY4jdE9u7P_7G0AcnQxvJUUrlqnNHTH0KdjSg0S-mULfkupctZByxfZdBON6jFE0TriLArGuZmIbg7GO-jB7oRBHFLZM6bDdTenfl/s400/Figure13.JPG" border="0" /></a></td></tr><tr><td>Figure 13</td></tr><tr><td></td></tr></tbody></table><table style="FONT-SIZE: 13px; FONT-FAMILY: trebuchet ms" height="100"><tbody><tr><td>2. Two properties IntSeverity and IntCalltype are defined. GetSLACriticalI, GetSLAHighI and GetSLAMediumI are the excuteCode Property for the code-Activities codeCritical, codeHigh and codeMedium respectively.</td></tr><tr><td><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH9s4LhqDoqdB8Y-Xt55nZcqKXBkWse2mBp142d54H6BXtTyjSIJNz4vcCrPQLXBhZrjBICPT2gkGj1WgtibnnOypHSSUcLmB_P-2Q52xBwM1Mr0omECE70oZ7Fhq-WaxHpDNIXdyAMMya/s1600-h/Other5.JPG"><img id="Img16" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 236px; CURSOR: hand; HEIGHT: 181px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH9s4LhqDoqdB8Y-Xt55nZcqKXBkWse2mBp142d54H6BXtTyjSIJNz4vcCrPQLXBhZrjBICPT2gkGj1WgtibnnOypHSSUcLmB_P-2Q52xBwM1Mr0omECE70oZ7Fhq-WaxHpDNIXdyAMMya/s400/Other5.JPG" border="0" /></a><br /></td></tr><tr><td>3. Now let’s have a re-look of the if-else code condition methods. The value of the properties are used to set the e.result.</td></tr><tr><td><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXDItN3Siizf94Vp9R4HZzFc5J1mvH_pxxn0XE_DE1eORU_Mt9pmS6-UE939TgBz8gszkEsOwSL9_9Vw0UbPQEPozmDGjMi5HkA0fGvZ_WwqGWR_NoyjowYrD2tYoxNJywp_6GGjq0ggeS/s1600-h/Figure14.JPG"><img id="Img14" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 244px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXDItN3Siizf94Vp9R4HZzFc5J1mvH_pxxn0XE_DE1eORU_Mt9pmS6-UE939TgBz8gszkEsOwSL9_9Vw0UbPQEPozmDGjMi5HkA0fGvZ_WwqGWR_NoyjowYrD2tYoxNJywp_6GGjq0ggeS/s400/Figure14.JPG" border="0" /></a></td></tr><tr><td>Figure 14<br /><br /></td></tr><tr><td>4. Now do the following changes to the program.cs. Compile the code.</td></tr><tr><td><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdSPyW-psBCsOE_S-Xqng8m1hs0O3mQThDbjy_gGf2b8DJgFUmA-wLX8xLEjQdz1wNDJJD2qaL0Pinnpoy12r8DDJQO-hjDMn-UbG87mahVNBAA6BDOsWwyxjYTnyir3J4RX89ydBJnKTp/s1600-h/Figure15.JPG"><img id="Img15" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 293px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdSPyW-psBCsOE_S-Xqng8m1hs0O3mQThDbjy_gGf2b8DJgFUmA-wLX8xLEjQdz1wNDJJD2qaL0Pinnpoy12r8DDJQO-hjDMn-UbG87mahVNBAA6BDOsWwyxjYTnyir3J4RX89ydBJnKTp/s400/Figure15.JPG" border="0" /></a></td></tr><tr><td>Figure15<br /><br /></td></tr><tr><td>The changes that we did here is read the value of calltype and severity from console and create a dictionary object with following definition. Generic type Dictionary<> is the type the createWorkflow parameter expects.</td></tr><tr><td><br /><em><span style="color:#000099;">Dictionary<string,object> callAnalysisParam = new Dictionary<string,object> ();<br />callAnalysisParam.Add("IntCallType", callType);<br />callAnalysisParam.Add("IntSeverity", CallSeverity);<br />}</span></em><br /></td></tr><tr><td>Another thing to be very careful is the “IntCallType” and “IntSeverity” name should be same name as the Properties that we defined in the Workflow1.cs class</td></tr><tr><td>5. Right click the solution and select “debug->start a new instance”. Press F10 until reach next line. Check the console window. Output looks like this</td></tr><tr><td>OUTPUT</td></tr><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQb0Rjt6XI-rdZN3mIr5sgjdaCp_9ovCM6iyTrCQ9k_PLar3ZGwYGDmCoLNqI0qO1lKcYfvzO7q61hap0spZTaQcHttNJCLbhP1wg1SG0jztxy8gHIPVi-RjjtxyhQWLlFZZLKUrouPO3R/s1600-h/Other6a.JPG"><img id="Img17" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 105px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQb0Rjt6XI-rdZN3mIr5sgjdaCp_9ovCM6iyTrCQ9k_PLar3ZGwYGDmCoLNqI0qO1lKcYfvzO7q61hap0spZTaQcHttNJCLbhP1wg1SG0jztxy8gHIPVi-RjjtxyhQWLlFZZLKUrouPO3R/s400/Other6a.JPG" border="0" /></a></td></tr><tr><td></td></tr><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjISSvFsSXD4SU9eYbuhZkYbef3nylhCa3LU1gE56-lEiwiwpaZnz4LyLz9HdhzjBe7O26UnZ_uOfdbZNwfcm4AIC-fHP2dlQ7jQBkOV6A0Xpqx1gK0FihUXQHDiOv-ZGnkGt6NpGgKMctu/s1600-h/Other6b.JPG"><img id="Img18" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 106px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjISSvFsSXD4SU9eYbuhZkYbef3nylhCa3LU1gE56-lEiwiwpaZnz4LyLz9HdhzjBe7O26UnZ_uOfdbZNwfcm4AIC-fHP2dlQ7jQBkOV6A0Xpqx1gK0FihUXQHDiOv-ZGnkGt6NpGgKMctu/s400/Other6b.JPG" border="0" /></a></td></tr><tr><td>To be continued ...</td></tr><tr><td></td></tr></tbody></table></div>Anil Rajanhttp://www.blogger.com/profile/09447768292071541074noreply@blogger.com1