Blog D'Joy

This [we]blog will be used to share thoughts (mostly technical), examples, tutorials, etc. for Microsoft Tech (mostly System Center).

OIS - Link Properties, Published Data with Newline Characters, and Regular Expressions

OIS - Link Properties, Published Data with Newline Characters, and Regular Expressions

  • Comments 4
  • Likes

Hello readers/viewers! No video today, but I will be covering a fairly interesting topic. I realize that this may be an edge case, but I thought it would good to have something on the blog to reference for related topics.

SCENARIO:

  1. You have Published Data output which may contain newline characters (\n).
    • NOTES:
      • In this case, the Published Data is not separated into multiple output data items.
      • You may experience this if you have flattened the Published Data with the Separate with line breaks option, or if you are referencing output from some objects where this data format is common (e.g. “Query WMI” object).
  2. You want to filter this Published Data by the existence of the newline character (\n).
  3. You use the available Link Properties for string filtering, taking advantage of the matches pattern option.
  4. You notice that filtering the Published Data by matches pattern \n does not work as you expect.
    • NOTE: There is a workaround” as well as a “working with /n character published data” section below.

EXAMPLE SCENARIO CONFIGURATION:
If we take something like the “Query WMI” object, which produces output with the new line character, and attempt to filter the “WMI Query Result as a string” by “Matches Pattern” \n in the link, it does not work:

image

image

image

EXAMPLE SCENARIO RESULTS:
During execution, this link filter configuration results in no data progressing past the link, even though the results look like this (where matching pattern would normally contain the \n):

image

POSSIBLE CAUSE:
I do not know the root cause for this behavior, but it may be that the Regular Expression implementation for Link Properties in OIS does not support “multiline mode” (search on this page for “multiline”).

MATCHES PATTERN DOES WORK:
I do know that “Match Pattern” in Link Properties Filtering does work, as I use it frequently to filter out “null” values from Published Data fields:

Usage for field “Is Null”:
image

Usage for field “Is Not Null”:
image

ALTERNATE REGEX TOOL RESULTS:
Now, if we take a portion of that same output and put it in an online .NET RegEx tester, you can see that the highlighted areas are where the \n character exists in the output sample (first 5 lines of the output from the Query WMI object).

image

NOTE: Lines copied from “Query WMI” object:

Caption=System Idle Process
Caption=System
Caption=smss.exe
Caption=csrss.exe
Caption=csrss.exe

WORKAROUND:
This does not mean that you are left with no ability filter based on the \n character; you simply have to use a workaround. The good news is, the workaround is pretty simple.

For those of you who do not yet know, there are a couple CodePlex releases which allow you to work with RegEx as a workaround:

If you would like to use Foundation Objects for the workaround, see the following steps:

Workaround Steps:

  1. Remove the link filter from the “Query WMI” object to the “Send Platform Event” object
  2. Insert a “Run .Net Script” object between those two objects (you will be doing the match in this object using PowerShell)
    image
  3. In the “Run .Net Script” object:
    • Choose the PowerShell Language Type
    • Use the following script (where the first variable takes in all the data from the output of the “Query WMI” object):
      image
    • Configure the Published Data tab like this:
      image
  4. Now add link filtering to the link after the “Run .Net Script” object:
    image

NOTE: PowerShell from the Details tab in this example (where $hasnewline will return “True” or “False”):

$inputdata = "{PUBLISHED DATA HERE}"
$hasnewline = $inputdata -match "\n"
$hasnewline

WORKING WITH \n CHARACTER IN PUBLISHED DATA:
Now that you can filter based on the \n character, you may want to know how to work with it.

Examples:
The following C# usage with the “Run .Net Script” object examples (OIS_EXPORT attached) parse the following output (from an example query WMI object):

clip_image002

  • Option 1: Just Parsing the “blob” of text into an array (where each new line is a new array element) – If you want to parse the “Name=” portion of the string in each array item, it will have to be parsed later in another object:

    string res = @"PUBLISHED DATA HERE";
    string[] results = res.Split(new string[] {"\n", "\r\n"}, StringSplitOptions.RemoveEmptyEntries);
    foreach (string r in results)
    {
       lstResults.Add(r);
    }


    This results in multiple line output that still needs to be parsed (based on the desire to remove “Name=” from each array item):
    clip_image001
  • Option 2: Parse the “blob” of text into an array, then parse for specific data and output only what you want (no other objects required):

    string res = @"PUBLISHED DATA HERE";
    string[] results = res.Split(new string[] {"\n", "\r\n"}, StringSplitOptions.RemoveEmptyEntries);
    foreach (string r in results)
    {
    string[] parsedResults = r.Split('=');
       lstResults.Add(parsedResults[1]);
    }


    This results in multiple line output that has already been parsed:
    clip_image001[5]

NOTE: For a more detailed video example of C# usage with the “Run .Net Script” object, please refer to the following post: http://blogs.technet.com/b/charlesjoy/archive/2010/07/14/8-minute-demo-net-scripting-object-c.aspx

enJOY!

Attachment: Run_dotNet_Script_cSharp_Parse_Data_Examples.zip
Comments
  • You can also use objects from the Integration Pack for Data Manipulation (opalis.codeplex.com/.../46827) to work with strings that include characters such as new lines (\n) - no scripting required! :)

  • Thanks for the reminder Jeff. I have updated the post (workaround section). :)

  • Charles,

    I have two questions, the first is that I see there is an SSH object, is there any kind of SFTP object or any way for Opalis to pull a file?

    The second is that I was wondering what the differences were with the Legacy objects from the newer objects with the same names?

    Thanks

  • 1. There is currently no Integration Pack for FTP, its release currently *targeted* with the SC Orchestrator 2012 release later this year. This does not mean you cannot use the OIS extensibility objects to integrate to software with SFTP capabilities.

    2. Legacy objects are to be used exclusively with the Legacy Workflow Engine. They exist strictly for backwards compatibility for customers running workflows in Legacy mode. All new workflows are created and configured for Pipeline Mode and no Legacy Objects should be used. These objects are already obsolete and I would bet they would not be a part of the SC Orchestrator 2012 release. Alternate functionality is available for each of these Legacy Objects (by either an existing OIS object or extensibility object potential).

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment