IgorShare Weblog

Practical Engineering

Archive for the ‘Workflows’ Category

Now I have ALL of the Microsoft developer certifications – long journey is over!!!

Posted by igormoochnick on 09/09/2009

Now I own the full deck of the Microsoft certifications and I can sit back and relax (beer is in order ;-) . Unfortunately, in the startup world that I operate most of the time, it’s not very recognizable achievement, but it’s nice to put these logos on my presentation slide decks and, especially now, I have a very powerful bragging rights – I have ALL of the Microsoft developers certifications !!!

It was a lengthy path and, I should add, a very confusing one. It wasn’t very obvious what certification is a prerequisite to which one and, I must add, I’ve made a couple of mistakes on the road until I’ve discovered a developer’s certification map by Jorgen Thelin that put everything in order and cleared all the confusions.

ms-cert-path-mcpd_4[1]

Posted in .NET, ADO.Net, ASP.NET, C#, Community, Thoughts, WCF, WPF, Workflows | 6 Comments »

Error Handling in Workflows

Posted by igormoochnick on 02/09/2009

Note a great article by Matt Milner in the latest (Feb’09) MSDN about different ways of Error Handling in Workflows.

Posted in .NET, Workflows | Leave a Comment »

TechValley CodeCamp, thank you!

Posted by igormoochnick on 04/21/2008

This Saturday I was talking about Workflows at TechValley CodeCamp. The organizers (Andrew Badera and Griffith Townsend) did a terrific job making this happen. It’s their first CodeCamp in TechValley and I’d like to wish them more success in the future and that they’ll finally fix the CodeCamp registration site.  [ BTW: The food was way better than at Waltham CodeCamp :lol: ]

Useful links:

Presentation slides – CodeCamp_Workflows.ppsx

Presentation code – CodeCamp_Workflows.zip

Posted in C#, Presentations, Thoughts, Tutorials, Workflows | Leave a Comment »

70-504 – Congratulations to … me again ?!!!

Posted by igormoochnick on 04/19/2008

MCTS_WF

Just got a confirmation that I’ve passed the 70-504 TS: Workflow Foundation.

And, you can guess, I’m heading to a bar for some beers :-) – this becomes a habit and, at this rate, I can become an alcoholic too :lol:

Posted in C#, Presentations, Thoughts, Tutorials, Visual Studio, Workflows | 2 Comments »

Albany, NY – see you there

Posted by igormoochnick on 04/16/2008

So, finally all my plans have crystallized and I’ll be talking in Albany, NY this weekend about the Workflows.

In this talk I’ll cover the ways you can extend your applications and projects with Workflow Foundation SDK. Use cases where the WF will give you more power and flexibility to solve you project’s problems.

I’ll be covering how you can extend the WF via creation of your own custom activities, designers and designer hosts.

 

For more information check the CodeCamp’s site: http://techvalleycodecamp.com/

See you there.

Posted in Presentations, Tutorials, Workflows | Leave a Comment »

CodeCamp (Waltham, MA) was a great success

Posted by igormoochnick on 04/06/2008

The last 2 days we had CodeCamp #9 in Waltham. It was a great success – 555 registered  participants (I swear it was 5 more than allowed 550). A lot of great presentations and presenters. I want personally thank the organizers and the participants.

I’ve given 4 presentations – 2 intro sessions and 2 in-depth session. Audience was great, engaging, friendly and asked a lot of good questions.

You’re welcome to download the presentations and the source code. Feel free to ask questions over the e-mail.

  1. PowerShell – extending your projects with PowerShell “To Infinity … and Beyond” (samples source code)
  2. Workflows are … not only for Business (samples source code)

I hope to see all of you next CodeCamp or during User Group meetings.

Posted in Pash, PowerShell, Presentations, Software, Thoughts, Tutorials, Workflows | 1 Comment »

Miguel Castro and Mark Dunn on the Marriage of WF and WCF

Posted by igormoochnick on 02/21/2008

Posted in Tutorials, Workflows | 1 Comment »

PowerShell Rules Engine: How-To Technical Details

Posted by igormoochnick on 02/15/2008

In my recent article, Marrying Workflows into PowerShell (Part 1 of 2), PowerShell Rules Engine, I’ve shown an example of how to use a Rule Set editor, shipped with Workflows Foundation, in your own application and how to evaluate rules against managed objects. Actually, PowerShell was used as a specific example of how to use this technology.

I haven’t invented anything new and this information is readily available from different public sources, but, I think, it’ll be better if I’ll explain how it works for the readers of this blog.

There are 3 simple steps to get this technology to work for you:

  1. Create and edit rule sets via the Rule Set Dialog and serialize the rules into an XML
  2. Load (deserialize) the Rule Set from an XML file
  3. Evaluate/apply the rules against your own objects

The step #1 is implemented in the ShowDialog function:

   1: public static RuleSet ShowRulesDialog(Type targetType, RuleSet ruleSetIn, string rulesFileName)
   2: {
   3:     RuleSet ruleSet = ruleSetIn ?? new RuleSet();
   4:     RuleSetDialog ruleSetDialog = new RuleSetDialog(targetType, null, ruleSet);
   5:     DialogResult dr = ruleSetDialog.ShowDialog();
   6:     if (dr == DialogResult.OK)
   7:     {
   8:         ruleSet = ruleSetDialog.RuleSet;
   9:         if (ruleSet == null)
  10:             return null;
  11:  
  12:         XmlTextWriter writer = new XmlTextWriter(rulesFileName, Encoding.Unicode);
  13:  
  14:         WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
  15:         serializer.Serialize(writer, ruleSet);
  16:  
  17:         writer.Flush();
  18:         writer.Close();
  19:     }
  20:  
  21:     return ruleSet;
  22: }

 

Note line #3 – if you’ll provide a valid instance of a Rule Set – the editor will allow you to edit it, if you don’t have a Rule Set, provide a new instance in the editor will fill it in with your new rules. In the line #15 the newly edited Rule Set is written (serialized) to an XML file with WorkflowMarkupSerializer.

The step #2 is implemented in the LoadRules function:

   1: public static RuleSet LoadRules(string rulesFileName)
   2: {
   3:     if (File.Exists(rulesFileName))
   4:     {
   5:         FileStream fs = new FileStream(rulesFileName, FileMode.Open);
   6:         StreamReader sr = new StreamReader(fs);
   7:         string serializedRuleSet = sr.ReadToEnd();
   8:         WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
   9:         StringReader stringReader = new StringReader(serializedRuleSet);
  10:         XmlTextReader reader = new XmlTextReader(stringReader);
  11:         var ruleSet = serializer.Deserialize(reader) as RuleSet;
  12:         fs.Close();
  13:  
  14:         return ruleSet;
  15:     }
  16:     return null;
  17: }

 

Note that this function is doing a reverse Rule Set deserialization with the WorkflowMarkupSerializer and returning a Rule Set instance (if everything wen right).

The last, and the most important step #3, is executed in the Run-Rules CmdLet. It evaluates the rules against each and every PSObject in the command pipeline.

   1: // Validate the rules
   2: RuleValidation validation = new RuleValidation(typeof(PSCurrentItem), null);
   3: ruleSet.Validate(validation);
   4: if (validation.Errors.Count != 0)
   5: {
   6:     foreach (ValidationError error in validation.Errors)
   7:         WriteWarning(string.Format("Validation Error: {0}", error.ErrorText));
   8: }
   9: if (validation.Errors.Count != 0)
  10:     return;
  11:  
  12: ...
  13:  
  14: var psObject = new PSCurrentItem() { CurrentItem = this.CurrentItem, Runtime = this };
  15:  
  16: // Execute the rules against the object
  17: RuleExecution execution = new RuleExecution(validation, psObject);
  18: ruleSet.Execute(execution);
  19:  
  20: if (! psObject.StopProcessing)
  21:     WriteObject(CurrentItem);

First the rule set is validated against the target type (lines #2-3), the same type used while creating the rule set in the first time (line #4 in ShowRulesDialog). Then the rules are applied to the managed object (lines #17-18). The rules can modify the object which can change the flow of the logic. In line #20 the code checks if the StopProcesing flag was set or cleared which forces the object to be written back to the command pipe or omitted.

Hope this post was educational and showed how easy it is to use the Rule Set editor in your applications.

Posted in C#, PowerShell, Tutorials, Workflows | 1 Comment »

WF are not only for business (part 3): Marrying Workflows into PowerShell (Part 1 of 2), PowerShell Rules Engine

Posted by igormoochnick on 02/15/2008

[ Update: PowerShell Rules Engine: How-To Technical Details ] 

Workflow Foundation gives us another “gem in a rough” – Rules Evaluation Engine. It is like a product within a product. [It is "rough" in a sense as in "buried within".]

As you know that in a lot of cases a simple if-else-then rule is either “too dumb” or it takes a lot of code (a set of rules) to express your requirement. In this case the Workflow Rules Engine comes handy. Among other great features, it allows you to define rules priorities, status and chaining policy. This can easily control the order in which these rules are evaluated (and even reevaluated). These rules can be executed against any managed object. The Rules Editor, that you’re getting with the Workflow Foundation, does the type reflection behind the scenes and provides you with a reach editing interface, which includes intellisense as well as syntax evaluation.

To make my case easier to explain, let’s take an extremely simple and exaggerated example: “let’s delete all the files that are more than 10 bytes”.

This is how the RuleSet will look like:

image

This is what will happen:

  • The first rule “IsFile” checks if the “current” item is a directory. If it is – the evaluation will “halt” for the current item and the system will move to the next item. If it’s a file the, rules will continue to evaluate.
  • The second rule “IsBig” will execute the “Then” script only if the file size (“Length”) is more than 10 bytes.

There are a lot of interesting things you can do with the rules, but first you have to understand how they work.

Note the order of the rules execution (crash guide for dummies, since it’s a huge topic and I can’t put everything in one post):

  1. Only the active rules will be executed
  2. The rules with the higher priority will be executed earlier (0 is is lowest priority)
  3. The rules within the same priority will be executed in the ALPHABETICAL order
  4. If you have the FullChaining turned on – the rules will be reevaluated until either nothing to reevaluate or “Halt” command was called
  5. for more info see great article by Scott Allen “Windows Workflow: Rules and Conditions” and, of cause, MSDN.

If you want to start playing with this technology go ahead and download my code. You’ll find there 3 CmdLets. Here is a short intro:

  1. New-Rules file-name    - will open a new Rule Set Editor and will allow you to create your own rule-set.
  2. Edit-Rules file-name     – will allow you to edit already existing Rule-Set
  3. Run-Rules file-name item-pipe    – will execute the rules against each and every item in the pipeline

This is how you can execute the Rule Set against a PowerShell command pipe:

dir c:\logs | Run-Rules rules.xml | % { "copy $_ c:\temp" }

All the items, after the rules were applied, will continue traveling the command pipe. If you’d like to stop an item to go through add an action:

this.StopProcessing = true

The code is operational as it is, so, what are you waiting for? Go ahead and unleash your imagination!

But first, don’t forget to take the code from the usual place imageon my web site.

Note: the code is provided only as a sample and a good starting point for your projects. If you’ll decide to make any changes and to share them with the community – send the code to me and I’ll upload it.

For more info:

MSDN article: Introduction to the Windows Workflow Foundation Rules Engine

Talk by Michael Stiefel: Using the WF Rules Engine Outside of a Workflow (and the attached presentation with a code sample)

Posted in C#, PowerShell, Tutorials, Workflows | 2 Comments »

Windows Workflow Foundation Tutorial Series

Posted by igormoochnick on 02/14/2008

Posted in Thoughts, Tutorials, Workflows | Leave a Comment »