{"id":1823,"date":"2005-07-11T13:34:22","date_gmt":"2005-07-11T12:34:22","guid":{"rendered":"https:\/\/yvespeneveyre8e29bf869d.wordpress.com\/2005\/07\/11\/comment-dtecter-larrt-dune-orchestration-how-to-detect-when-an-orchestration-stops\/"},"modified":"2005-07-11T13:34:22","modified_gmt":"2005-07-11T12:34:22","slug":"comment-dtecter-larrt-dune-orchestration-how-to-detect-when-an-orchestration-stops","status":"publish","type":"post","link":"https:\/\/www.peneveyre.com\/en\/2005\/07\/11\/comment-dtecter-larrt-dune-orchestration-how-to-detect-when-an-orchestration-stops\/","title":{"rendered":"Comment d??tecter l&#8217;arr??t d&#8217;une orchestration &#8211; How to detect when an orchestration stops"},"content":{"rendered":"<p><P class=\"MsoNormal\"><SPAN lang=\"FR-CH\"><FONT color=\"#000000\">A voir, BizTalk rencontre passablement de probl??mes pour g??rer les fichiers dont le volume est important. Pourtant, malgr?? les efforts entrepris pour r?? architecturer l&#8217;application, il est parfois impossible de s&#8217;affranchir de ses OutOfMemoryException. Dans le cas du projet actuel, le probl??me ne se passe que lorsque BizTalk doit traiter plus d&#8217;un fichier en m??me temps. J&#8217;ai donc d??cid??, provisoirement, de ne soumettre ?? BizTalk qu&#8217;un seul fichier ?? la fois, et attendre qu&#8217;il en ait termin?? le traitement avant d&#8217;en soumettre le suivant. Or, il me semble qu&#8217;il n&#8217;est pas possible d&#8217;??tre averti lorsqu&#8217;une orchestration se termine, dans le framework .NET.<\/FONT><\/SPAN><\/P><br \/>\n<P class=\"MsoNormal\"><SPAN lang=\"FR-CH\"><FONT color=\"#000000\">La m??thode que j&#8217;ai trouv??e passe par WMI. Ainsi, pour conna??tre quand une orchestration se termine&nbsp;:<\/FONT><\/SPAN><\/P><SPAN lang=\"FR-CH\"><FONT face=\"Times New Roman\" color=\"#000000\"><br \/>\n<P><SPAN><FONT size=\"2\"><SPAN>private<\/SPAN> <SPAN>void<\/SPAN> MountBTSOrchestrationMonitoring()<BR>{<BR><SPAN>&nbsp;&nbsp;&nbsp;\/\/ Only one watch to mount, because we can only monitor orchestration deletion<\/SPAN><BR>&nbsp;&nbsp;&nbsp;WqlEventQuery q <SPAN>=<\/SPAN> <SPAN>new<\/SPAN> WqlEventQuery(__InstanceDeletionEvent,<BR><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new<\/SPAN> TimeSpan(0,0,0,10),<BR><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;TargetInstance isa \\&#8221;MSBTS_ServiceInstance\\&#8221;&#8221;<\/SPAN>);<BR>&nbsp;&nbsp;&nbsp;m_btsWatcher <SPAN>=<\/SPAN> <SPAN>new<\/SPAN> ManagementEventWatcher(<SPAN>new<\/SPAN> ManagementScope(root\/MicrosoftBizTalkServe),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q);<BR>&nbsp;&nbsp;&nbsp;m_btsWatcher.EventArrived += <SPAN>new<\/SPAN> EventArrivedEventHandler(bts_OrchestrationDeleted);<BR>&nbsp;&nbsp;&nbsp;m_btsWatcher.Start();<BR>}<BR><BR><BR><SPAN>private<\/SPAN> <SPAN>void<\/SPAN> bts_OrchestrationDeleted(<SPAN>object<\/SPAN> sender, EventArrivedEventArgs e)<BR>{<BR><SPAN>&nbsp;&nbsp;&nbsp;\/\/ Do something<\/SPAN><BR>}<BR><\/FONT><\/SPAN><\/P><br \/>\n<P class=\"MsoNormal\"><\/FONT><\/SPAN><SPAN lang=\"FR-CH\"><FONT color=\"#000000\">Ainsi, lorsqu&#8217;une orchestration se terminera, l&#8217;??v??nement bts_OrchestrationDeleted sera appel??. Le seul petit probl??me, c&#8217;est qu&#8217;il n&#8217;est pas possible de conna??tre quelle orchestration s&#8217;est termin??e. Il faut alors interroger BizTalk, via WMI, ?? nouveau, pour savoir si une instance de l&#8217;orchestration observ??e est encore active&nbsp;:<\/FONT><\/SPAN><\/P><SPAN lang=\"FR-CH\"><FONT face=\"Times New Roman\" color=\"#000000\"><br \/>\n<P><SPAN><FONT size=\"2\"><SPAN>private<\/SPAN> <SPAN>int<\/SPAN> OrchestrationInstanceCount(<SPAN>string<\/SPAN> strOrchestrationName)<BR>{<BR>&nbsp;&nbsp;&nbsp;System.Text.StringBuilder sb <SPAN>=<\/SPAN> <SPAN>new<\/SPAN> System.Text.StringBuilder(<SPAN>&#8220;SELECT * FROM MSBTS_ServiceInstance WHERE ServiceName=\\&#8221;&#8221;<\/SPAN>);<BR>&nbsp;&nbsp;&nbsp;sb.Append(strOrchestrationName);<BR>&nbsp;&nbsp;&nbsp;sb.Append(<SPAN>&#8220;\\&#8221;&#8221;<\/SPAN>);<BR>&nbsp;&nbsp;&nbsp;WqlObjectQuery w <SPAN>=<\/SPAN> <SPAN>new<\/SPAN> WqlObjectQuery(sb.ToString());<BR>&nbsp;&nbsp;&nbsp;ManagementObjectSearcher objSearcher <SPAN>=<\/SPAN> <SPAN>new<\/SPAN> ManagementObjectSearcher(<SPAN>new<\/SPAN> ManagementScope(kstrWMIBTSNamespace),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;w);<BR><SPAN>&nbsp;&nbsp;&nbsp;return<\/SPAN> objSearcher.Get().Count;<BR>}<BR><\/FONT><\/SPAN><\/P><br \/>\n<P class=\"MsoNormal\"><\/FONT><\/SPAN><SPAN lang=\"FR-CH\"><FONT color=\"#000000\">Si la m??thode retourne 0, aucune orchestration avec le nom donn?? en param??tre n&#8217;est active.<\/FONT><\/SPAN><\/P><br \/>\n<P class=\"MsoNormal\"><SPAN lang=\"FR-CH\"><FONT color=\"#000000\">Attention toute fois&nbsp;! BizTalk met un certain temps avant de mettre en route une orchestration, faisant que m??me si un fichier est d??pos?? dans un r??pertoire d&#8217;accueil de BizTalk, la m??thode risque de renvoyer la valeur 0, car l&#8217;orchestration n&#8217;aura pas encore d??marr??. Il serait alors judicieux de voir si des fichiers sont encore pr??sent dans le r??pertoire d&#8217;accueil avant d&#8217;en poster de nouveaux.<\/FONT><\/SPAN><\/P><br \/>\n<P class=\"MsoNormal\"><SPAN lang=\"FR-CH\"><FONT color=\"#000000\">&nbsp;<\/FONT><\/SPAN><\/P><br \/>\n<P class=\"MsoNormal\"><SPAN lang=\"FR-CH\"><FONT color=\"#000000\">&nbsp;<\/FONT><\/SPAN><\/P><br \/>\n<P class=\"MsoNormal\"><SPAN lang=\"FR-CH\"><FONT color=\"#000000\"><\/FONT><\/SPAN><\/P><br \/>\n<P class=\"MsoNormal\"><SPAN lang=\"FR-CH\"><FONT color=\"#000000\"><\/FONT><\/SPAN><\/P><br \/>\n<P class=\"MsoNormal\"><SPAN lang=\"FR-CH\"><FONT color=\"#000000\"><\/FONT><\/SPAN><\/P><br \/>\n<P class=\"MsoNormal\"><FONT color=\"#000000\"><EM>According to a lot of blogs, BizTalk has some issues with large files. However, despite of the efforts for rearchitecturing the application, it is sometimes not possible to avoid the OutOfMemoryException.<\/EM><\/FONT><\/P><br \/>\n<P class=\"MsoNormal\"><FONT color=\"#000000\"><EM>In the case of the actual project, that happens only when BizTalk has to process more than one file at a time. So, I temporary decided to pass to BizTalk only one file at a time and to wait the orchestration stops before copying the next file to the receive location. But, it seems that it is not possible to be warned when an orchestration stops with .NET.<\/EM><\/FONT><\/P><br \/>\n<P class=\"MsoNormal\"><FONT color=\"#000000\"><EM>The way I found is using WMI. To know when an orchestration stops, I install an event handler :<\/EM><\/FONT><\/P><br \/>\n<P class=\"MsoNormal\"><FONT color=\"#000000\">&nbsp;<\/FONT><\/P><FONT face=\"Arial\" color=\"#000000\"><br \/>\n<P><SPAN><FONT size=\"2\"><SPAN>private<\/SPAN> <SPAN>void<\/SPAN> MountBTSOrchestrationMonitoring()<BR>{<BR><SPAN>&nbsp;&nbsp;&nbsp;\/\/ Only one watch to mount, because we can only monitor orchestration deletion<\/SPAN><BR>&nbsp;&nbsp;&nbsp;WqlEventQuery q <SPAN>=<\/SPAN> <SPAN>new<\/SPAN> WqlEventQuery(__InstanceDeletionEvent,<BR><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new<\/SPAN> TimeSpan(0,0,0,10),<BR><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;TargetInstance isa \\&#8221;MSBTS_ServiceInstance\\&#8221;&#8221;<\/SPAN>);<BR>&nbsp;&nbsp;&nbsp;m_btsWatcher <SPAN>=<\/SPAN> <SPAN>new<\/SPAN> ManagementEventWatcher(<SPAN>new<\/SPAN> ManagementScope(root\/MicrosoftBizTalkServe),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q);<BR>&nbsp;&nbsp;&nbsp;m_btsWatcher.EventArrived += <SPAN>new<\/SPAN> EventArrivedEventHandler(bts_OrchestrationDeleted);<BR>&nbsp;&nbsp;&nbsp;m_btsWatcher.Start();<BR>}<BR><BR><BR><SPAN>private<\/SPAN> <SPAN>void<\/SPAN> bts_OrchestrationDeleted(<SPAN>object<\/SPAN> sender, EventArrivedEventArgs e)<BR>{<BR><SPAN>&nbsp;&nbsp;&nbsp;\/\/ Do something<\/SPAN><BR>}<BR><\/FONT><\/SPAN><\/P><br \/>\n<P class=\"MsoNormal\"><\/FONT><FONT color=\"#000000\"><EM>When an orchestration will stop, the bts_OrchestrationDeleted event will be called. There is only one little issue. It is impossible to know which orchestration stopped. We have to get the answer from BizTalk itself, through WMI again, and getting the number of active instance with a given name :<\/EM><\/FONT><\/P><br \/>\n<P class=\"MsoNormal\"><FONT color=\"#000000\"><\/FONT>&nbsp;<\/P><br \/>\n<P><SPAN><SPAN>private<\/SPAN> <SPAN>int<\/SPAN> OrchestrationInstanceCount(<SPAN>string<\/SPAN> strOrchestrationName)<BR>{<BR>&nbsp;&nbsp;&nbsp;System.Text.StringBuilder sb <SPAN>=<\/SPAN> <SPAN>new<\/SPAN> System.Text.StringBuilder(<SPAN>&#8220;SELECT * FROM MSBTS_ServiceInstance WHERE ServiceName=\\&#8221;&#8221;<\/SPAN>);<BR>&nbsp;&nbsp;&nbsp;sb.Append(strOrchestrationName);<BR>&nbsp;&nbsp;&nbsp;sb.Append(<SPAN>&#8220;\\&#8221;&#8221;<\/SPAN>);<BR>&nbsp;&nbsp;&nbsp;WqlObjectQuery w <SPAN>=<\/SPAN> <SPAN>new<\/SPAN> WqlObjectQuery(sb.ToString());<BR>&nbsp;&nbsp;&nbsp;ManagementObjectSearcher objSearcher <SPAN>=<\/SPAN> <SPAN>new<\/SPAN> ManagementObjectSearcher(<SPAN>new<\/SPAN> ManagementScope(kstrWMIBTSNamespace),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;w);<BR><SPAN>&nbsp;&nbsp;&nbsp;return<\/SPAN> objSearcher.Get().Count;<BR>}<BR><\/SPAN><\/P><br \/>\n<P class=\"MsoNormal\"><FONT color=\"#000000\"><EM>If the method returns 0, no orchestration with the given name is still running.<\/EM><\/FONT><\/P><br \/>\n<P class=\"MsoNormal\"><FONT color=\"#000000\"><EM>But, warning ! BizTalk needs a bit of time before starting an orchestration and event a file is dropped in a BizTalk receive location, the method will certainly return 0, because the orchestration is not yet started. It would be a good idea to test is there are files in the receive location before dropping new files.<\/EM><\/FONT><\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Il n&#8217;est pas possible d&#8217;??tre notifi?? quand une orchestration BizTalk se termine. Ce post montre un moyen d&#8217;y arriver tout de m??me, mais en utilisant WMI. It is not possible to be notified when a BizTalk orchestration ends. This post shows how we can do that, using WMI.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-1823","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.peneveyre.com\/en\/wp-json\/wp\/v2\/posts\/1823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.peneveyre.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.peneveyre.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.peneveyre.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.peneveyre.com\/en\/wp-json\/wp\/v2\/comments?post=1823"}],"version-history":[{"count":0,"href":"https:\/\/www.peneveyre.com\/en\/wp-json\/wp\/v2\/posts\/1823\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.peneveyre.com\/en\/wp-json\/wp\/v2\/media?parent=1823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.peneveyre.com\/en\/wp-json\/wp\/v2\/categories?post=1823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.peneveyre.com\/en\/wp-json\/wp\/v2\/tags?post=1823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}