tag:blogger.com,1999:blog-88566103644788617322024-03-19T02:39:12.580-07:00Speak TechnologyRohit Shrivastavahttp://www.blogger.com/profile/03860125443731856847noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-8856610364478861732.post-11791237747416735892011-09-09T14:39:00.000-07:002012-10-16T16:32:59.100-07:00Create Parallel Task in State Machine Workflow in SharePoint2010<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">I faced a problem while creating parallel tasks in state machine workflow. My requirement is same as OUT of Box SharePoint approval workflow which allows multiple users to approve the document and when everyone approves the document, document moves to next state which is approved.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"> </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">All the articles pointed me that this is possible in sequential workflow. </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"> </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Here is the thread which explains the problem, I would no be investing much time to explain the problem </span><a href="http://groups.google.com/group/microsoft.public.sharepoint.portalserver.development/browse_thread/thread/e0beac08110f6135"><span style="font-family: Arial, Helvetica, sans-serif;">http://groups.google.com/group/microsoft.public.sharepoint.portalserver.development/browse_thread/thread/e0beac08110f6135</span></a><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">I downloaded the code sample available at Microsoft site which is basic state machine workflow. Following is the link. </span><a href="http://code.msdn.microsoft.com/SharePoint-2010-Creating-39ac75ea"><span style="font-family: Arial, Helvetica, sans-serif;">http://code.msdn.microsoft.com/SharePoint-2010-Creating-39ac75ea</span></a></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Modifications to the code are as follows:</span></div>
<ul style="text-align: left;"><span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<li><span style="font-family: Arial, Helvetica, sans-serif;">Add a new state at level 2.</span></li>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<li><span style="font-family: Arial, Helvetica, sans-serif;">In the state initialization, create two tasks with different Correlation token, task ids and task properties.</span></li>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<li><span style="font-family: Arial, Helvetica, sans-serif;">Now add two event driven activity. </span></li>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<li><span style="font-family: Arial, Helvetica, sans-serif;">Keep flags for each parallel task </span></li>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<li><span style="font-family: Arial, Helvetica, sans-serif;">Added OnTaskChanged event driven activity, On Invoked event updated the associated flag to true.</span></li>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<li><span style="font-family: Arial, Helvetica, sans-serif;">Put an IF block and check if all the flags are true, then set state workflow to next state.</span></li>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span></ul>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNEsIROwCYQUN1eSRXnLlbvRzAvtqfI0sz-BWocgvLSftVxn-U0RuDuAB84eOWjMKK6RE49l_fliGjCrBskFa9wF77QvaITeKGO4yUYRl6Eot2CQSWx_E_zHprmrm7u3TKtK0sjAvGKFVt/s1600/ParallelTask.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Arial, Helvetica, sans-serif;"><img border="0" height="270" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNEsIROwCYQUN1eSRXnLlbvRzAvtqfI0sz-BWocgvLSftVxn-U0RuDuAB84eOWjMKK6RE49l_fliGjCrBskFa9wF77QvaITeKGO4yUYRl6Eot2CQSWx_E_zHprmrm7u3TKtK0sjAvGKFVt/s320/ParallelTask.png" width="320" /></span></a></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">I found this easy to implement, though manual code is involved which should be done via a parallel activity. </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Code can be downloaded from </span><a href="https://docs.google.com/viewer?a=v&pid=explorer&chrome=true&srcid=0B72iXH9cCIeKYjFkNmNkOTYtMTU0Ni00YWE2LWI0MjMtMGFiM2Y4MWYyZjQ5&hl=en_US"><span style="font-family: Arial, Helvetica, sans-serif;">here</span></a><span style="font-family: Arial, Helvetica, sans-serif;">.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"></span></div>
</div>
<a href="http://www.codeproject.com/script/Articles/BlogArticleList.aspx?amid=5284466" rel="tag">CodeProject</a>Rohit Shrivastavahttp://www.blogger.com/profile/03860125443731856847noreply@blogger.comtag:blogger.com,1999:blog-8856610364478861732.post-48618960210504117392009-06-29T06:37:00.000-07:002009-07-01T06:48:12.513-07:00N Tier Architecture<div align="justify"><span style="font-family:verdana;color:#000000;"><strong>Some Myths</strong></span></div><p align="justify"><span style="font-family:verdana;font-size:85%;">People normally think if they have created UI (ASP.Net application project), BL (.Net Class Library Project), & DAL data access layer (.Net Class Library Project) and referencing these projects in their web project, they are following 3 tier architecture. I think creating a n tier application is more than this.</span></p><p align="justify"><span style="font-family:verdana;"><strong>What is tier?</strong></span></p><p align="justify"><span style="font-family:verdana;font-size:85%;">According to me tier means a stand-alone process which has some code to process. In the above scenario where ASP.Net Web Application is referencing BL and DAL, all the code is running in w3wp (server OS)/ aspnet_wp process which is known as worker process. So in real terms all this is single tier. </span></p><p align="justify"><span style="font-family:verdana;font-size:85%;">Then question arises that, is it 1 tier application? If you are not dealing with databases or any other thing which has its own process then <strong>yes </strong>it is 1-tier architecture. Database makes it 2-tier architecture. As all the databases are run under some process. sqlservr is the process for SQL databases.</span></p><p align="justify"><span style="font-family:verdana;font-size:85%;">Some people also say that a web application will always run under a browser and why don't treat that as a tier and say this as 3 tier architecture?</span></p><p align="justify"><span style="font-family:verdana;font-size:85%;">I would say a tier should contain some meat in it. Meat means, some code which processes some part of the request handling, it should minimize the effort of request processing. Now what all can be processed at browser? To process anything on browser one has to write java script or any other client script.</span></p><p align="justify"><span style="font-family:verdana;font-size:85%;">Browser can do validation, however every one should be agree that all the validation which we do on client should be done on server also. So browser do not minimize any processing here. </span></p><p align="justify"><span style="font-family:verdana;font-size:85%;">Browser can also enhance the UI which is instant action. That's a good help in enhancing the UI, now logically it is a part of UI layer which is been run on browser instead of server just to improve the user experience it is not helping in request processing.</span></p><p align="justify"><span style="font-family:verdana;"><strong>What makes 3 tier architecture</strong></span></p><p align="justify"><span style="font-family:Verdana;font-size:85%;">One has to introduce one more process somewhere. We can host the Business Logic as a WCF service / Remoting. WCF service should be hosted in an application pool other than the web application pool. This is just to make sure that both the application will be run in different worker process.</span></p><p align="justify"><span style="font-family:Verdana;font-size:85%;">In this way we would have 3 different processes 1. Web Application Process, 2. BL WCF process, and 3 would be the database process.</span></p><p align="justify"><span style="font-family:Verdana;"><strong>Why to make 3-tier</strong></span></p><p align="justify"><span style="font-family:Verdana;font-size:85%;">Going back to the starting why did you want your application to be 3-tier. Answer to this question contains many big words like Performance Optimization, Scalability, Robustness, Code Re-Usability, and many more.</span></p><p align="justify"><span style="font-family:Verdana;font-size:85%;">Compare this with following question:</span></p><p align="justify"><span style="font-family:Verdana;font-size:85%;">2 person to do your job vs 3 person to do your job, you will get all your answers. 3 men can do the task more rapidly, correct? <strong>Yes if task can be broken into sub tasks.</strong> Same applies here if you can divide your task in sub tasks then 3 tier architecture will be beneficial.</span></p><p align="justify"><span style="font-family:Verdana;font-size:85%;"><strong>Some people take the following approach in writing the code: </strong></span></p><p align="justify"><span style="font-family:Verdana;font-size:85%;">Lets take an example when one is creating a inventory application, now they write a method in DAL <span style="color:#3333ff;">PlaceOrder </span>(which takes many arguments like Customer, collection of products, PersonBillingPlan etc), this method will call a SP sp_PlaceOrder and all the logic will be written in that SP. This DAL method will simply be called in BL and will return success / failure. Now even if we create WCF service and force it to run in different process, we won't achieve what we intended to while following 3-tier architecture. This is because we do not have any meat (code to execute in BL), hence all the load is on the database. Database has to perform all the operation of validating data and applying business rules. Now in a team of 2 people if one is over burdened then will my team give the right productivity as expected? I guess no... what do you say please let me know in the comments section<span style="font-size:100%;">.</span></span></p><p align="justify"><span style="font-family:verdana;font-size:85%;"><strong>One more interesting question arises here while following true 3-tier architecture</strong></span></p><p align="justify"><span style="font-family:verdana;font-size:85%;">People say, if we have to write business logic in .Net code then we have to fetch some extra data from Sql to .Net and write code on them, where in SP approach everything was coded in SQL and no data was travelling from SQL to .Net and finally a flag was sent from the DB which signifies success or failure. Now to counter attack this question I would say following things:</span></p><p align="justify"><span style="font-family:verdana;font-size:85%;">1. Data is anyway fetched from database, select query will be hit in both the cases only thing is data will be travelled from sql to .Net. I guess this would not harm that much but depends.</span></p><br /><p align="justify"><span style="font-family:verdana;font-size:85%;">2. Data caching: data caching is way to minimize the above damage. One can easily write code to use data caching at DAL and save the effort of fetching common/static data. If data will be cached then it would really enhance the performance of the application by leaps and bounds.</span></p><p><span style="font-family:verdana;font-size:85%;">I hope this would help you writing 3-tier application.</span></p><p></p><p align="justify"><span style="font-family:verdana;font-size:85%;"></span></p><div align="justify"><span style="font-family:verdana;font-size:85%;"></span></div><br /><div style="DISPLAY: none" align="justify"><br /><a href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=5284466" rel="tag">codeproject </a></div>Rohit Shrivastavahttp://www.blogger.com/profile/03860125443731856847noreply@blogger.comtag:blogger.com,1999:blog-8856610364478861732.post-42591151638388002532009-03-24T01:46:00.000-07:002009-06-29T05:15:37.163-07:00Client Storage in SilverLight<div align="justify"><br /><strong>Client Storage for Silverlight</strong><br />Silverlight provides two classes, one is <strong>IsolatedStorage</strong> and another is <strong>DataContractSerializer</strong>.</div><div align="justify"><br />Silverlight provides <strong>IsolatedStorage</strong> class to store data at client machine. With isolated storage, data is always isolated by user and by assembly. Credentials such as the origin or the strong name of the assembly determine assembly identity. Data can also be isolated by application domain, using similar credentials.</div><div align="justify"><br />DataContractSerializer class, which is used to serialize and deserialize instances of a type into an XML stream or document. For example, you can create a type named Person with properties that contain essential data, such as a name and address. You can then create and manipulate an instance of the Person class and write all of its property values in an XML document for later retrieval, or in an XML stream for immediate transport. Most important, the DataContractSerializer is used to serialize and deserialize data sent in Silverlight version 2 messages. Apply the DataContractAttribute attribute to classes, and the DataMemberAttribute attribute to class members to specify properties and fields that are serialized. </div><div align="justify"><br /><strong>Problem Statement</strong></div><strong><div align="justify"><br /></strong>To make use of IsolatedStorage developer has to create file stream and save the data. Ideally in real world all data will be kept in memory as an object of some type. Now to store this object in IsolatedStorage one has to first deserialize it and store it in files and define file names for them. Later this data will be read from the files and will be kept in memory again in the form of an object.</div><div align="justify"><br />To simplify the above task I have combined the funcationality IsolatedStorage and DataContractSerializer and created ClientStorage class which helps user to store any object directly in the IsolatedStorage i.e. making object persistent an interesting feature of OOPs. Persistence is a feature of OOPs then to achieve this one must follow the oops approach rather than writing same code again and again for different objects this piece of code can be clubbed together and I have named it as ClientStorage.</div><div align="justify"><br /><strong>What ClientStorage does:</strong><br />The approach is simple and following the habit of using Session and ViewState. When we use Session to store any object in asp.net, developer does not bother where this information will be kept. She keep her objects in session when she wanted them to be available through out the life time of user's session. Same applies to IsolatedStorage, when developer wants to store something per user/application wide data on client machine that would be available cross browser to the application independent of session like persistent for always until user deletes them manually. Then why to complex things, why not something like ClientStorage[keyname] = object; and its all done.</div><div align="justify"><br />ClientStorage is a singleton class that is basically a indexed collection which helps in fetching the objects on the basis of key. It automatically serializes the object and also stores the type of the object, so that it can be deserialize later. Gives Index based object fetching mechanism which makes life easier. </div><div align="justify"><br />Next, it can be improved/enhanced further to provide versioning support for the objects stored in ClientStorage so that it helps in identifying the stale objects in the ClientStorage and allows to re-fetch/re-creation of that object.</div><div align="justify"><br />I know this can be improved further, any suggestion or feedback is highly appreciable.</div><div align="justify"></div><div align="justify"></div><div align="justify">Source Code of Client Storage can be found <a href="http://www.codeproject.com/KB/silverlight/SilverLightClientStorage.aspx">here</a></div><div align="justify"><br />Thanks </div><div align="justify">Rohit</div>Rohit Shrivastavahttp://www.blogger.com/profile/03860125443731856847noreply@blogger.com