|
1 |
| -# BizTalk Mapper: How to create a custom If-Then-Else Functoid |
| 1 | +# Moving Event Source To Different Event Log (Administration) |
2 | 2 |
|
3 | 3 | # Introduction
|
4 |
| -Sometimes I ask myself: Why is so hard to make a simple If-Then-Else Functoid, or even so painful to do an If-Then-Else operation, using BizTalk mapper? |
| 4 | +Many time in BizTalk developers like to write informations that will help them tracking and debuging there orchestrations like: |
| 5 | +* Message received |
| 6 | +* Message successfully Transformed |
| 7 | +* Message sent to external system |
5 | 8 |
|
6 |
| -I don't mean to say that it is complicated, quite the opposite, is quite easy to make If…Then…Else statements using the Mapper. You can use **If...Then...Else** statements, to be completely correct, you can use something related to an **If...Then...Else** statements, to execute blocks of statements depending on the **Boolean** value of a condition by, normally, using: |
7 |
| -* One **Logical Functoid** (Logical Existence, Logical String, Logical Numeric, Equal, Greater Than, Less Than and so on) to determine: |
8 |
| - * whether the Record, Field Element, or Field Attribute node that is linked to it exists or have a valid value in a particular input instance message |
9 |
| - * or if a condition match. |
10 |
| -* One **Logical NOT Functoid** to negate the Logical Functoid |
11 |
| - * And two **Value Mapping Functoids** to returns the value that we want to linked based on the result of the condition |
| 9 | +And for that they normally use the following code: |
| 10 | + |
| 11 | + System.Diagnostics.EventLog.WriteEntry("AnnoyingTord3", |
| 12 | + "Just an update Tord! Message successfully Transformed"); |
| 13 | + |
12 | 14 |
|
13 |
| -However, if you want to create a custom If-Then-Else Functoid, you will find that, out-of-the-box, it is impossible to create a custom functoid based on a Logical Functoid and the reason why this is true is that, all Logical Functoids available out-of-the-box with BizTalk only accept the following outputs connection types: |
14 |
| -* ConnectionType.Element |
15 |
| -* ConnectionType.FunctoidAssert |
16 |
| -* ConnectionType.FunctoidNilValue |
17 |
| -* ConnectionType.FunctoidKeyMatch |
18 |
| -* ConnectionType.FunctoidTableLooping |
19 |
| -* ConnectionType.FunctoidValueMapping |
20 |
| -* ConnectionType.FunctoidScripter |
21 |
| -* ConnectionType.FunctoidLogical |
22 |
| -* ConnectionType.FunctoidString is not allowed in all the existing Logical Functoids. And that is the reason why you will find impossible to create a custom functoid based on a Logical functoid (don’t know the reason why Microsoft decide to implement this limitation) |
| 15 | +The problem using this code is that by default in the Application Log. Application event log is used to application installed in your server/machine like BizTalk Server to log the exceptions or problems and you should keep it clean. in other to proper monitor and find problems with your environment. |
| 16 | + |
| 17 | +And also this are unnecessary information that is being logged in the Application Log in that don't provide any additional information to BizTalk Administrators. |
23 | 18 |
|
24 | 19 | # Building the Sample
|
25 |
| -What I want to archive is create a custom functoid that accepts 3 inputs: |
26 |
| -* A Boolean - the result of a previous Logical Functoid (Logical Existence, Logical String, Logical Numeric, Equal, Greater Than, Less Than and so on) |
27 |
| -* And two inputs |
| 20 | +In this sample you will find a simple orchestration that will receive any XML message and will log some traditional tracking information that developers normally do in their orchestrations… I call this trying to annoying Tord Glad Nordahl (my friend and one of the best BizTalk Administrator that I know) and that is always complaining about developer doing this. |
| 21 | + |
| 22 | + |
28 | 23 |
|
29 |
| -Were the custom Functoid will return a value from one of two input parameters based on a condition. |
30 |
| -* If the condition (first input) is True, then the value of the second input parameter is returned; |
31 |
| -* Otherwise the Third input is returned. |
| 24 | +## What is that the Admin does normally? |
| 25 | +They ask the developer to change is code, that already is deployed in all the environments, to not write in the application log |
32 | 26 |
|
33 |
| - |
| 27 | +However change is hard - Getting others to change can be impossible or a big challenge |
34 | 28 |
|
35 |
| -# Functoid Code |
| 29 | +## What is that the Admin should do? |
| 30 | +Let the developer by happy by writing in the Event Viewer... |
| 31 | + |
| 32 | +But take back the control of your environment by easily creating or using PowerShell script |
36 | 33 |
|
37 | 34 |
|
38 |
| - namespace BizTalk.CustomAdvanced.Functoids |
39 |
| - { |
40 |
| - [Serializable] |
41 |
| - public class IfThenElse : BaseFunctoid |
42 |
| - { |
43 |
| - public IfThenElse() |
44 |
| - : base() |
45 |
| - { |
46 |
| - //ID for this functoid |
47 |
| - this.ID = 10900; |
48 |
| - |
49 |
| - // resource assembly must be ProjectName.ResourceName if building with VS.Net |
50 |
| - SetupResourceAssembly("BizTalk.Logical.Functoids.LogicalResources", Assembly.GetExecutingAssembly()); |
51 |
| - |
52 |
| - //Setup the Name, ToolTip, Help Description, and the Bitmap for this functoid |
53 |
| - SetName("IDS_IFELSEFUNCTOID_NAME"); |
54 |
| - SetTooltip("IDS_IFELSEFUNCTOID_TOOLTIP"); |
55 |
| - SetDescription("IDS_IFELSEFUNCTOID_DESCRIPTION"); |
56 |
| - SetBitmap("IDS_IFELSEFUNCTOID_BITMAP"); |
57 |
| - |
58 |
| - //category for this functoid. This functoid goes under the String Functoid Tab in the |
59 |
| - this.Category = FunctoidCategory.String; |
60 |
| - |
61 |
| - // Set the limits for the number of input parameters. This example: 1 parameter |
62 |
| - this.SetMinParams(3); |
63 |
| - this.SetMaxParams(3); |
64 |
| - |
65 |
| - // Add one line of code as set out below for each input param. For multiple input params, each line would be identical. |
66 |
| - this.AddInputConnectionType(ConnectionType.AllExceptRecord); //first input |
67 |
| - this.AddInputConnectionType(ConnectionType.AllExceptRecord); //Second input |
68 |
| - this.AddInputConnectionType(ConnectionType.AllExceptRecord); //Third input |
69 |
| - |
70 |
| - // The functoid output can go to any node type. |
71 |
| - this.OutputConnectionType = ConnectionType.AllExceptRecord; |
72 |
| - |
73 |
| - SetScriptBuffer(ScriptType.CSharp, this.GetCSharpBuffer()); |
74 |
| - HasSideEffects = false; |
75 |
| - } |
76 |
| - |
77 |
| - private string GetCSharpBuffer() |
78 |
| - { |
79 |
| - StringBuilder builder = new StringBuilder(); |
80 |
| - builder.Append("public string IfThenElseOperation(string condition, string trueValue, string falseValue)\n"); |
81 |
| - builder.Append("{\n"); |
82 |
| - builder.Append("\tif (System.Convert.ToBoolean(condition))\n"); |
83 |
| - builder.Append("\t\treturn trueValue;\n"); |
84 |
| - builder.Append("\treturn falseValue;\n"); |
85 |
| - builder.Append("}\n"); |
86 |
| - return builder.ToString(); |
87 |
| - } |
88 |
| - } |
| 35 | + foreach ($LogSource in $LogSources) { |
| 36 | + Remove-EventLog -Source $LogSource |
| 37 | + } |
| 38 | + |
| 39 | + $logFileExists = Get-EventLog -list | Where-Object {$_.logdisplayname -eq $LogName} |
| 40 | + if (! $logFileExists) { |
| 41 | + $LogSources | %{ |
| 42 | + New-EventLog -LogName $LogName -Source $_ |
| 43 | + } |
| 44 | + |
| 45 | + # Compose Key: |
| 46 | + $LogPath = 'HKLM:\SYSTEM\CurrentControlSet\services\eventlog\'+$LogName; |
| 47 | + if(Test-Path $LogPath) |
| 48 | + { |
| 49 | + $acl = Get-Acl $LogPath |
| 50 | + $GpOrUsers | %{ |
| 51 | + $ace = New-Object System.Security.AccessControl.RegistryAccessRule $_,'WriteKey, ReadKey','allow' |
| 52 | + $acl.AddAccessRule($ace) |
| 53 | + #Set-Acl $LogPath $acl |
| 54 | + } |
| 55 | + }else{Write-Error "Cannot acesss log $LogName"} |
| 56 | + } |
| 57 | + else { |
| 58 | + $LogSources | %{ |
| 59 | + New-EventLog -LogName $LogName -Source $_ |
| 60 | + } |
89 | 61 | }
|
90 |
| - |
| 62 | + |
| 63 | + |
| 64 | +You can find the entired PowerShell script here: [BizTalk DevOps: Moving an Event Source To a Different/Custom Windows Event Log](https://gallery.technet.microsoft.com/scriptcenter/BizTalk-DevOps-Moving-an-e4c23236) |
91 | 65 |
|
92 |
| -# How did I solve (or I overcame) this challenger? Read more about it |
| 66 | +# Read more about it |
93 | 67 | You can read more about this topic here: [Why is so hard to make a simple If-Then-Else Functoid? … well, not anymore!
|
94 | 68 | ](https://blog.sandro-pereira.com/2016/02/10/why-is-so-hard-to-make-a-simple-if-then-else-functoid-well-not-anymore/)
|
95 | 69 |
|
|
0 commit comments