-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainForm.cs
1402 lines (1069 loc) · 54.3 KB
/
MainForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.BizTalk.ExplorerOM;
using System.Data.SqlClient;
using Microsoft.Win32;
using System.IO;
using System.Xml.Linq;
namespace Microsys.EAI.BizTalkUtilities
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
Welcome welcome = new Welcome();
welcome.ShowDialog();
tableLayoutPanel.SetColumnSpan(statusStrip, 3);
try
{
string fileName = Path.Combine(Path.GetTempPath(), "Servers.bin");
if (File.Exists(fileName))
{
using (StreamReader stream = new StreamReader(fileName))
{
while (stream.Peek() >= 0)
{
string line = stream.ReadLine();
txtSource.Items.Add(line);
txtTarget.Items.Add(line);
}
if (txtSource.Items.Count > 0)
{
txtSource.SelectedIndex = 0;
txtTarget.SelectedIndex = 0;
}
stream.Close();
}
}
if (txtSource.Items.Count == 0)
{
using (RegistryKey bizTalkAdminKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\BizTalk Server\3.0\Administration"))
{
if (bizTalkAdminKey != null)
{
string server = (string)bizTalkAdminKey.GetValue("MgmtDBServer", ".");
string database = (string)bizTalkAdminKey.GetValue("MgmtDBName", "BizTalkMgmtDb");
txtSource.Text = string.Format("Data Source={0};Initial Catalog={1};Integrated Security=SSPI;", server, database);
txtTarget.Text = txtSource.Text;
}
}
}
}
catch
{
txtSource.Text = "Data Source=localhost;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;";
}
}
private void Collect(ref TreeView biztalkTree, string connectionString)
{
BtsCatalogExplorer catalog = new BtsCatalogExplorer();
catalog.ConnectionString = connectionString;
BizTalkObject biztalkObject;
TreeNode node;
int i = 0;
biztalkTree.Nodes.Clear();
sourceReport.Visible = false;
targetReport.Visible = false;
attributeReport.Visible = false;
System.Windows.Forms.Application.DoEvents();
#region Application
// Applications Folder
biztalkObject = new BizTalkObject(BizTalkObjectType.Folder, false);
node = new TreeNode();
node.Text = "Applications";
node.Tag = biztalkObject;
node.ImageIndex = 0;
node.SelectedImageIndex = 0;
biztalkTree.Nodes.Add(node);
foreach (Microsoft.BizTalk.ExplorerOM.Application application in catalog.Applications)
{
if (application.Name != "BizTalk.System")
{
#region Application
// Application
biztalkObject = new BizTalkObject(BizTalkObjectType.Application, false);
node = new TreeNode();
node.Text = application.Name;
node.Tag = biztalkObject;
node.ImageIndex = 1;
node.SelectedImageIndex = 1;
biztalkTree.Nodes[0].Nodes.Add(node);
#endregion
#region Receive Port & Receive Location
// Receive Ports Folder
biztalkObject = new BizTalkObject(BizTalkObjectType.Folder, false);
node = new TreeNode();
node.Text = "Receive Ports";
node.Tag = biztalkObject;
node.ImageIndex = 0;
node.SelectedImageIndex = 0;
biztalkTree.Nodes[0].Nodes[i].Nodes.Add(node);
// Receive Ports
int j = 0;
foreach (ReceivePort receivePort in application.ReceivePorts)
{
IList<string> inboundTransforms = new List<string>();
IList<string> outboundTransforms = new List<string>();
if (receivePort.InboundTransforms != null)
{
foreach (Transform map in receivePort.InboundTransforms)
{
inboundTransforms.Add(map.FullName);
}
}
if (receivePort.OutboundTransforms != null)
{
foreach (Transform map in receivePort.OutboundTransforms)
{
outboundTransforms.Add(map.FullName);
}
}
biztalkObject = new BizTalkObject(BizTalkObjectType.ReceivePort, true, receivePort, inboundTransforms, outboundTransforms);
node = new TreeNode();
node.Text = receivePort.Name;
node.Tag = biztalkObject;
node.ImageIndex = 0;
node.SelectedImageIndex = 0;
biztalkTree.Nodes[0].Nodes[i].Nodes[0].Nodes.Add(node);
// Receive Locations
foreach (ReceiveLocation receiveLocation in receivePort.ReceiveLocations)
{
biztalkObject = new BizTalkObject(BizTalkObjectType.ReceiveLocation, true, receiveLocation);
node = new TreeNode();
node.Text = receiveLocation.Name;
node.Tag = biztalkObject;
node.ImageIndex = 3;
node.SelectedImageIndex = 3;
biztalkTree.Nodes[0].Nodes[i].Nodes[0].Nodes[j].Nodes.Add(node);
}
j++;
}
#endregion
#region Send Port Group
// Send Port Groups Folder
biztalkObject = new BizTalkObject(BizTalkObjectType.Folder, false);
node = new TreeNode();
node.Text = "Send Port Groups";
node.Tag = biztalkObject;
node.ImageIndex = 0;
node.SelectedImageIndex = 0;
biztalkTree.Nodes[0].Nodes[i].Nodes.Add(node);
// Send Port Groups
foreach (SendPortGroup sendPortGroup in application.SendPortGroups)
{
biztalkObject = new BizTalkObject(BizTalkObjectType.SendPortGroup, true, sendPortGroup);
node = new TreeNode();
node.Text = sendPortGroup.Name;
node.Tag = biztalkObject;
node.ImageIndex = 2;
node.SelectedImageIndex = 2;
biztalkTree.Nodes[0].Nodes[i].Nodes[1].Nodes.Add(node);
}
#endregion
#region Send Port
// Send Ports Folder
biztalkObject = new BizTalkObject(BizTalkObjectType.Folder, false);
node = new TreeNode();
node.Text = "Send Ports";
node.Tag = biztalkObject;
node.ImageIndex = 0;
node.SelectedImageIndex = 0;
biztalkTree.Nodes[0].Nodes[i].Nodes.Add(node);
// Send Ports
foreach (SendPort sendPort in application.SendPorts)
{
IList<string> inboundTransforms = new List<string>();
IList<string> outboundTransforms = new List<string>();
if (sendPort.InboundTransforms != null)
{
foreach (Transform map in sendPort.InboundTransforms)
{
inboundTransforms.Add(map.FullName);
}
}
if (sendPort.OutboundTransforms != null)
{
foreach (Transform map in sendPort.OutboundTransforms)
{
outboundTransforms.Add(map.FullName);
}
}
biztalkObject = new BizTalkObject(BizTalkObjectType.SendPort, true, sendPort, inboundTransforms, outboundTransforms);
node = new TreeNode();
node.Text = sendPort.Name;
node.Tag = biztalkObject;
node.ImageIndex = 2;
node.SelectedImageIndex = 2;
biztalkTree.Nodes[0].Nodes[i].Nodes[2].Nodes.Add(node);
}
#endregion
#region Orchestration
// Orchestrations Folder
biztalkObject = new BizTalkObject(BizTalkObjectType.Folder, false);
node = new TreeNode();
node.Text = "Orchestrations";
node.Tag = biztalkObject;
node.ImageIndex = 0;
node.SelectedImageIndex = 0;
biztalkTree.Nodes[0].Nodes[i].Nodes.Add(node);
// Orchestrations
foreach (BtsOrchestration orchestration in application.Orchestrations)
{
IList<string> ports = new List<string>();
if (orchestration.Ports != null)
{
foreach (OrchestrationPort port in orchestration.Ports)
{
if (port.ReceivePort != null)
{
ports.Add(string.Concat(port.Name, "|", port.ReceivePort.Name));
}
else if (port.SendPort != null)
{
ports.Add(string.Concat(port.Name, "|", port.SendPort.Name));
}
else if (port.SendPortGroup != null)
{
ports.Add(string.Concat(port.Name, "|", port.SendPortGroup.Name));
}
else
{
ports.Add(string.Concat(port.Name, "|unbound"));
}
}
}
biztalkObject = new BizTalkObject(BizTalkObjectType.Orchestration, false, orchestration, ports);
node = new TreeNode();
node.Text = orchestration.FullName;
node.Tag = biztalkObject;
node.ImageIndex = 6;
node.SelectedImageIndex = 6;
biztalkTree.Nodes[0].Nodes[i].Nodes[3].Nodes.Add(node);
}
#endregion
i++;
}
}
#endregion
#region Host
// Host Folder
biztalkObject = new BizTalkObject(BizTalkObjectType.Folder, false);
node = new TreeNode();
node.Text = "Hosts";
node.Tag = biztalkObject;
node.ImageIndex = 0;
node.SelectedImageIndex = 0;
biztalkTree.Nodes.Add(node);
// Host
foreach (Microsoft.BizTalk.ExplorerOM.Host host in catalog.Hosts)
{
biztalkObject = new BizTalkObject(BizTalkObjectType.Host, false);
node = new TreeNode();
node.Text = host.Name;
node.Tag = biztalkObject;
node.ImageIndex = 5;
node.SelectedImageIndex = 5;
biztalkTree.Nodes[1].Nodes.Add(node);
}
#endregion
}
private void lnkCollect_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
try
{
Collect(ref biztalkSource, txtSource.Text);
Collect(ref biztalkTarget, txtTarget.Text);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
private void biztalkSourceActions_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
try
{
biztalkSourceActions.Close();
}
catch { }
System.Windows.Forms.Application.DoEvents();
try
{
if (biztalkSource.Nodes.Count > 0)
{
if (biztalkSource.SelectedNode != null)
{
switch (e.ClickedItem.Name)
{
case "alignToolStripMenuItem":
Align(biztalkSource.SelectedNode);
break;
case "findToolStripMenuItem":
if (Find(biztalkSource.SelectedNode, biztalkTarget.Nodes) == null)
{
MessageBox.Show("Object not found.");
}
break;
case "compareToolStripMenuItem":
SelectCompareParameters selectParameterForm = new SelectCompareParameters();
selectParameterForm.ShowDialog();
Compare();
break;
case "viewDetailsToolStripMenuItem":
if (biztalkSource.SelectedNode.Tag != null)
{
BizTalkObject sourceObject;
BizTalkObject targetObject;
if (Find(biztalkSource.SelectedNode, biztalkTarget.Nodes) != null)
{
sourceObject = (BizTalkObject)biztalkSource.SelectedNode.Tag;
targetObject = (BizTalkObject)biztalkTarget.SelectedNode.Tag;
}
else
{
sourceObject = (BizTalkObject)biztalkSource.SelectedNode.Tag;
targetObject = null;
}
Details details = new Details(sourceObject, targetObject);
details.ShowDialog();
}
break;
case "copyItemNameSourceActions":
Clipboard.SetText(biztalkSource.SelectedNode.FullPath);
break;
case "viewOnlyDifferencesToolStripMenuItem":
biztalkSource.CollapseAll();
biztalkTarget.CollapseAll();
ViewOnlyDifferences(biztalkSource.Nodes);
ViewOnlyDifferences(biztalkTarget.Nodes);
break;
}
}
else
{
MessageBox.Show("Select a node.");
}
}
else
{
MessageBox.Show("Collect BizTalk information.");
}
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
private void ViewOnlyDifferences(TreeNodeCollection treeNodes)
{
foreach (TreeNode node in treeNodes)
{
if (node.BackColor == Color.OrangeRed || node.BackColor == Color.Orange)
{
node.EnsureVisible();
}
ViewOnlyDifferences(node.Nodes);
}
}
private BizTalkObject Find(TreeNode sourceSelectedNode, TreeNodeCollection targetNodes)
{
BizTalkObject returnValue = null;
foreach (TreeNode node in targetNodes)
{
if (returnValue != null)
break;
if (sourceSelectedNode.FullPath == node.FullPath)
{
node.EnsureVisible();
biztalkTarget.SelectedNode = node;
biztalkTarget.Select();
returnValue = (BizTalkObject)node.Tag;
}
else
{
returnValue = Find(sourceSelectedNode, node.Nodes);
}
}
return returnValue;
}
public void Align(TreeNode sourceSelectedNode)
{
BizTalkObject biztalkObject = (BizTalkObject)sourceSelectedNode.Tag;
if (biztalkObject.IsExportable == false)
{
MessageBox.Show("You have to select a Port, a Receive Location or a Port Group");
return;
}
if (MessageBox.Show(string.Format("Are you sure you want create object '{0}' on target system ?", biztalkSource.SelectedNode.Text), "Confirm", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
{
return;
}
if (Find(sourceSelectedNode, biztalkTarget.Nodes) != null)
{
MessageBox.Show("Target object already exist");
return;
}
switch (biztalkObject.ObjectType)
{
case BizTalkObjectType.SendPort:
CreateSendPort(biztalkObject);
break;
case BizTalkObjectType.SendPortGroup:
CreateSendPortGroup(biztalkObject);
break;
case BizTalkObjectType.ReceivePort:
CreateReceivePort(biztalkObject);
break;
case BizTalkObjectType.ReceiveLocation:
if (Find(sourceSelectedNode.Parent, biztalkTarget.Nodes) == null)
{
MessageBox.Show("You can creare a receive location only if target receive port already exist.");
return;
}
CreateReceiveLocationName(biztalkObject);
break;
}
Collect(ref biztalkTarget, txtTarget.Text);
Find(sourceSelectedNode, biztalkTarget.Nodes);
}
private void CreateReceiveLocationName(BizTalkObject sourceBizTalkObject)
{
BtsCatalogExplorer targetCatalog = new BtsCatalogExplorer();
try
{
// connect to the target BizTalk configuration database
targetCatalog.ConnectionString = txtTarget.Text;
ReceiveLocation sourceRlc = (ReceiveLocation)sourceBizTalkObject.NativeObject;
ReceiveLocation targetRlc = targetCatalog.Applications[sourceRlc.ReceivePort.Application.Name].ReceivePorts[sourceRlc.ReceivePort.Name].AddNewReceiveLocation();
targetRlc.Name = sourceRlc.Name;
targetRlc.Address = sourceRlc.Address;
targetRlc.CustomData = sourceRlc.CustomData;
targetRlc.Description = sourceRlc.Description;
targetRlc.EncryptionCert = sourceRlc.EncryptionCert;
targetRlc.EndDate = sourceRlc.EndDate;
targetRlc.EndDateEnabled = sourceRlc.EndDateEnabled;
targetRlc.FragmentMessages = sourceRlc.FragmentMessages;
targetRlc.FromTime = sourceRlc.FromTime;
targetRlc.PublicAddress = sourceRlc.PublicAddress;
foreach (ReceiveHandler rh in targetCatalog.ReceiveHandlers)
{
if (rh.Name == sourceRlc.ReceiveHandler.Name && rh.TransportType.Name == sourceRlc.TransportType.Name)
{
targetRlc.ReceiveHandler = rh;
break;
}
}
targetRlc.ReceivePipeline = targetCatalog.Pipelines[sourceRlc.ReceivePipeline.FullName];
targetRlc.ReceivePipelineData = sourceRlc.ReceivePipelineData;
if (sourceRlc.ReceivePort.IsTwoWay)
{
targetRlc.SendPipeline = targetCatalog.Pipelines[sourceRlc.SendPipeline.FullName];
targetRlc.SendPipelineData = sourceRlc.SendPipelineData;
}
targetRlc.ServiceWindowEnabled = sourceRlc.ServiceWindowEnabled;
targetRlc.StartDate = sourceRlc.StartDate;
targetRlc.StartDateEnabled = sourceRlc.StartDateEnabled;
targetRlc.ToTime = sourceRlc.ToTime;
targetRlc.TransportType = targetCatalog.ProtocolTypes[sourceRlc.TransportType.Name];
targetRlc.TransportTypeData = sourceRlc.TransportTypeData;
// persist changes to BizTalk configuration database
targetCatalog.SaveChanges();
}
catch (Exception exc)
{
targetCatalog.DiscardChanges();
MessageBox.Show(string.Concat(exc.Message, ". Check if all assemblies are deployed on destination system."));
}
}
private void CreateSendPortGroup(BizTalkObject sourceBizTalkObject)
{
BtsCatalogExplorer targetCatalog = new BtsCatalogExplorer();
try
{
// connect to the target BizTalk configuration database
targetCatalog.ConnectionString = txtTarget.Text;
SendPortGroup sourceSendPortGroup = (SendPortGroup)sourceBizTalkObject.NativeObject;
SendPortGroup targetSendPortGroup = targetCatalog.Applications[sourceSendPortGroup.Application.Name].AddNewSendPortGroup();
targetSendPortGroup.Name = sourceSendPortGroup.Name;
targetSendPortGroup.CustomData = sourceSendPortGroup.CustomData;
targetSendPortGroup.Description = sourceSendPortGroup.Description;
targetSendPortGroup.Filter = sourceSendPortGroup.Filter;
foreach (SendPort sourceSendPort in sourceSendPortGroup.SendPorts)
{
targetSendPortGroup.SendPorts.Add(targetCatalog.SendPorts[sourceSendPort.Name]);
}
// persist changes to BizTalk configuration database
targetCatalog.SaveChanges();
}
catch (Exception exc)
{
targetCatalog.DiscardChanges();
MessageBox.Show(exc.Message);
}
}
private void CreateReceivePort(BizTalkObject sourceBizTalkObject)
{
BtsCatalogExplorer targetCatalog = new BtsCatalogExplorer();
try
{
// connect to the target BizTalk configuration database
targetCatalog.ConnectionString = txtTarget.Text;
ReceivePort sourceReceivePort = (ReceivePort)sourceBizTalkObject.NativeObject;
ReceivePort targetReceivePort = targetCatalog.Applications[sourceReceivePort.Application.Name].AddNewReceivePort(sourceReceivePort.IsTwoWay);
targetReceivePort.Name = sourceReceivePort.Name;
targetReceivePort.Authentication = sourceReceivePort.Authentication;
targetReceivePort.CustomData = sourceReceivePort.CustomData;
targetReceivePort.Description = sourceReceivePort.Description;
targetReceivePort.RouteFailedMessage = sourceReceivePort.RouteFailedMessage;
targetReceivePort.Tracking = sourceReceivePort.Tracking;
foreach (ReceiveLocation sourceReceiveLocation in sourceReceivePort.ReceiveLocations)
{
ReceiveLocation targetReceiveLocation = targetReceivePort.AddNewReceiveLocation();
targetReceiveLocation.Name = sourceReceiveLocation.Name;
targetReceiveLocation.Address = sourceReceiveLocation.Address;
targetReceiveLocation.CustomData = sourceReceiveLocation.CustomData;
targetReceiveLocation.Description = sourceReceiveLocation.Description;
targetReceiveLocation.EncryptionCert = sourceReceiveLocation.EncryptionCert;
targetReceiveLocation.EndDate = sourceReceiveLocation.EndDate;
targetReceiveLocation.EndDateEnabled = sourceReceiveLocation.EndDateEnabled;
targetReceiveLocation.FragmentMessages = sourceReceiveLocation.FragmentMessages;
targetReceiveLocation.FromTime = sourceReceiveLocation.FromTime;
targetReceiveLocation.PublicAddress = sourceReceiveLocation.PublicAddress;
foreach (ReceiveHandler rh in targetCatalog.ReceiveHandlers)
{
if (rh.Name == sourceReceiveLocation.ReceiveHandler.Name && rh.TransportType.Name == sourceReceiveLocation.TransportType.Name)
{
targetReceiveLocation.ReceiveHandler = rh;
break;
}
}
targetReceiveLocation.ReceivePipeline = targetCatalog.Pipelines[sourceReceiveLocation.ReceivePipeline.FullName];
targetReceiveLocation.ReceivePipelineData = sourceReceiveLocation.ReceivePipelineData;
if (sourceReceivePort.IsTwoWay)
{
targetReceiveLocation.SendPipeline = targetCatalog.Pipelines[sourceReceiveLocation.SendPipeline.FullName];
targetReceiveLocation.SendPipelineData = sourceReceiveLocation.SendPipelineData;
}
targetReceiveLocation.ServiceWindowEnabled = sourceReceiveLocation.ServiceWindowEnabled;
targetReceiveLocation.StartDate = sourceReceiveLocation.StartDate;
targetReceiveLocation.StartDateEnabled = sourceReceiveLocation.StartDateEnabled;
targetReceiveLocation.ToTime = sourceReceiveLocation.ToTime;
targetReceiveLocation.TransportType = targetCatalog.ProtocolTypes[sourceReceiveLocation.TransportType.Name];
targetReceiveLocation.TransportTypeData = sourceReceiveLocation.TransportTypeData;
if (sourceReceiveLocation.IsPrimary)
{
targetReceivePort.PrimaryReceiveLocation = targetReceiveLocation;
}
}
foreach (Transform map in sourceReceivePort.InboundTransforms)
{
targetReceivePort.InboundTransforms.Add(targetCatalog.Transforms[map.FullName]);
}
if (sourceReceivePort.IsTwoWay)
{
foreach (Transform map in sourceReceivePort.OutboundTransforms)
{
targetReceivePort.OutboundTransforms.Add(targetCatalog.Transforms[map.FullName]);
}
}
// persist changes to BizTalk configuration database
targetCatalog.SaveChanges();
}
catch (Exception exc)
{
targetCatalog.DiscardChanges();
MessageBox.Show(string.Concat(exc.Message, ". Check if all assemblies are deployed on destination system."));
}
}
private void CreateSendPort(BizTalkObject sourceBizTalkObject)
{
BtsCatalogExplorer targetCatalog = new BtsCatalogExplorer();
try
{
// connect to the target BizTalk configuration database
targetCatalog.ConnectionString = txtTarget.Text;
SendPort sourceSendPort = (SendPort)sourceBizTalkObject.NativeObject;
SendPort targetSendPort = targetCatalog.Applications[sourceSendPort.Application.Name].AddNewSendPort(sourceSendPort.IsDynamic, sourceSendPort.IsTwoWay);
targetSendPort.Name = sourceSendPort.Name;
targetSendPort.CustomData = sourceSendPort.CustomData;
targetSendPort.Description = sourceSendPort.Description;
targetSendPort.EncryptionCert = sourceSendPort.EncryptionCert;
targetSendPort.Filter = sourceSendPort.Filter;
if (!sourceSendPort.IsDynamic)
{
if (sourceSendPort.InboundTransforms != null)
{
foreach (Transform map in sourceSendPort.InboundTransforms)
{
targetSendPort.InboundTransforms.Add(targetCatalog.Transforms[map.FullName]);
}
}
if (sourceSendPort.OutboundTransforms != null)
{
foreach (Transform map in sourceSendPort.OutboundTransforms)
{
targetSendPort.OutboundTransforms.Add(targetCatalog.Transforms[map.FullName]);
}
}
targetSendPort.PrimaryTransport.TransportType = targetCatalog.ProtocolTypes[sourceSendPort.PrimaryTransport.TransportType.Name];
targetSendPort.PrimaryTransport.TransportTypeData = sourceSendPort.PrimaryTransport.TransportTypeData;
targetSendPort.PrimaryTransport.Address = sourceSendPort.PrimaryTransport.Address;
targetSendPort.PrimaryTransport.TransportTypeData = sourceSendPort.PrimaryTransport.TransportTypeData;
targetSendPort.PrimaryTransport.DeliveryNotification = sourceSendPort.PrimaryTransport.DeliveryNotification;
targetSendPort.PrimaryTransport.FromTime = sourceSendPort.PrimaryTransport.FromTime;
targetSendPort.PrimaryTransport.OrderedDelivery = sourceSendPort.PrimaryTransport.OrderedDelivery;
targetSendPort.PrimaryTransport.RetryCount = sourceSendPort.PrimaryTransport.RetryCount;
targetSendPort.PrimaryTransport.RetryInterval = sourceSendPort.PrimaryTransport.RetryInterval;
foreach (SendHandler sh in targetCatalog.SendHandlers)
{
if (sh.Name == sourceSendPort.PrimaryTransport.SendHandler.Name && sh.TransportType.Name == sourceSendPort.PrimaryTransport.TransportType.Name)
{
targetSendPort.PrimaryTransport.SendHandler = sh;
break;
}
}
targetSendPort.PrimaryTransport.ServiceWindowEnabled = sourceSendPort.PrimaryTransport.ServiceWindowEnabled;
targetSendPort.PrimaryTransport.ToTime = sourceSendPort.PrimaryTransport.ToTime;
if (!string.IsNullOrEmpty(sourceSendPort.SecondaryTransport.Address))
{
targetSendPort.SecondaryTransport.TransportType = targetCatalog.ProtocolTypes[sourceSendPort.SecondaryTransport.TransportType.Name];
targetSendPort.SecondaryTransport.TransportTypeData = sourceSendPort.SecondaryTransport.TransportTypeData;
targetSendPort.SecondaryTransport.Address = sourceSendPort.SecondaryTransport.Address;
targetSendPort.SecondaryTransport.TransportTypeData = sourceSendPort.SecondaryTransport.TransportTypeData;
targetSendPort.SecondaryTransport.DeliveryNotification = sourceSendPort.SecondaryTransport.DeliveryNotification;
targetSendPort.SecondaryTransport.FromTime = sourceSendPort.SecondaryTransport.FromTime;
targetSendPort.SecondaryTransport.OrderedDelivery = sourceSendPort.SecondaryTransport.OrderedDelivery;
targetSendPort.SecondaryTransport.RetryCount = sourceSendPort.SecondaryTransport.RetryCount;
targetSendPort.SecondaryTransport.RetryInterval = sourceSendPort.SecondaryTransport.RetryInterval;
foreach (SendHandler sh in targetCatalog.SendHandlers)
{
if (sh.Name == sourceSendPort.SecondaryTransport.SendHandler.Name && sh.TransportType.Name == sourceSendPort.SecondaryTransport.TransportType.Name)
{
targetSendPort.SecondaryTransport.SendHandler = sh;
break;
}
}
targetSendPort.SecondaryTransport.ServiceWindowEnabled = sourceSendPort.SecondaryTransport.ServiceWindowEnabled;
targetSendPort.SecondaryTransport.ToTime = sourceSendPort.SecondaryTransport.ToTime;
}
}
targetSendPort.Priority = sourceSendPort.Priority;
if (sourceSendPort.IsTwoWay)
{
targetSendPort.ReceivePipeline = targetCatalog.Pipelines[sourceSendPort.ReceivePipeline.FullName];
targetSendPort.ReceivePipelineData = sourceSendPort.ReceivePipelineData;
}
targetSendPort.RouteFailedMessage = sourceSendPort.RouteFailedMessage;
targetSendPort.SendPipeline = targetCatalog.Pipelines[sourceSendPort.SendPipeline.FullName];
targetSendPort.SendPipelineData = sourceSendPort.SendPipelineData;
targetSendPort.StopSendingOnFailure = sourceSendPort.StopSendingOnFailure;
targetSendPort.Tracking = sourceSendPort.Tracking;
// persist changes to BizTalk configuration database
targetCatalog.SaveChanges();
}
catch (Exception exc)
{
targetCatalog.DiscardChanges();
MessageBox.Show(string.Concat(exc.Message, ". Check if all assemblies are deployed on destination system."));
}
}
private void Compare()
{
int sourceDiffCount = 0;
int targetDiffCount = 0;
int propertiesDiffCount = 0;
foreach (TreeNode node in biztalkSource.Nodes)
{
CompareRecursive(node, biztalkTarget.Nodes, ref sourceDiffCount, true, ref propertiesDiffCount);
}
foreach (TreeNode node in biztalkTarget.Nodes)
{
CompareRecursive(node, biztalkSource.Nodes, ref targetDiffCount, false, ref propertiesDiffCount);
}
biztalkSource.Nodes[0].EnsureVisible();
biztalkSource.SelectedNode = biztalkSource.Nodes[0];
biztalkTarget.Nodes[0].EnsureVisible();
biztalkTarget.SelectedNode = biztalkTarget.Nodes[0];
sourceReport.Text = string.Format("{0} source items not found in the target", sourceDiffCount);
targetReport.Text = string.Format("{0} target items not found in the source", targetDiffCount);
attributeReport.Text = string.Format("{0} different property values", propertiesDiffCount);
sourceReport.BackColor = (sourceDiffCount == 0 ? Color.LightGreen : Color.OrangeRed);
sourceReport.Visible = true;
targetReport.BackColor = (targetDiffCount == 0 ? Color.LightGreen : Color.OrangeRed);
targetReport.Visible = true;
attributeReport.BackColor = (propertiesDiffCount == 0 ? Color.LightGreen : Color.Orange);
attributeReport.Visible = true;
string message = "Found {0} items on the source system that do not exist in the target.\r\nFound {1} items on the target system that do not exist in the source.\r\nFound {2} property values.";
System.Windows.Forms.Application.DoEvents();
MessageBox.Show(string.Format(message, sourceDiffCount, targetDiffCount, propertiesDiffCount));
}
private void CompareRecursive(TreeNode node, TreeNodeCollection target, ref int diffCount, bool checkPropertiesDiff, ref int propertiesDiffCount)
{
BizTalkObject targetObject = Find(node, target);
if (targetObject == null)
{
node.BackColor = Color.OrangeRed;
diffCount++;
}
else
{
if (checkPropertiesDiff)
{
BizTalkObject sourceObject = (BizTalkObject)node.Tag;
node.BackColor = Color.White;
switch (sourceObject.ObjectType)
{
case BizTalkObjectType.SendPort:
SendPort sourceSpt = (SendPort)sourceObject.NativeObject;
SendPort targetSpt = (SendPort)targetObject.NativeObject;
if (CompareParameters.SendPortCheckAddress)
{
if (sourceSpt.PrimaryTransport != null)
{
if (targetSpt.PrimaryTransport == null || sourceSpt.PrimaryTransport.Address != targetSpt.PrimaryTransport.Address)
{
SetDifferenceProperties(ref node, ref propertiesDiffCount);
}
}
}
if (CompareParameters.SendPortCheckAddressFileMask)
{
if (sourceSpt.PrimaryTransport != null && sourceSpt.PrimaryTransport.TransportType.Name == "FILE")
{
if (targetSpt.PrimaryTransport == null || Path.GetFileName(sourceSpt.PrimaryTransport.Address) != Path.GetFileName(targetSpt.PrimaryTransport.Address))
{
SetDifferenceProperties(ref node, ref propertiesDiffCount);
}
}
}
if (CompareParameters.SendPortCheckHost)
{
if (sourceSpt.PrimaryTransport != null)
{
if (targetSpt.PrimaryTransport == null || sourceSpt.PrimaryTransport.SendHandler.Name != targetSpt.PrimaryTransport.SendHandler.Name)
{
SetDifferenceProperties(ref node, ref propertiesDiffCount);
}
}