-
Notifications
You must be signed in to change notification settings - Fork 16
/
EzComponents.cs
3120 lines (2741 loc) · 116 KB
/
EzComponents.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
// Copyright © Microsoft Corporation. All Rights Reserved.
// This code released under the terms of the
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)
using Microsoft.DataTransformationServices.Controls;
using Microsoft.SqlServer.Dts.Pipeline;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using Microsoft.SqlServer.VSTAHosting;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using System.Runtime.Serialization;
using System.Linq;
namespace Microsoft.SqlServer.SSIS.EzAPI
{
[Serializable]
public class PropertyException : Exception
{
public PropertyException() : base() { }
public PropertyException(string message) : base(message) { }
protected PropertyException(SerializationInfo info, StreamingContext context) : base(info, context) { }
public PropertyException(string message, Exception innerException) : base(message, innerException) { }
}
[Serializable]
public class ComponentException : Exception
{
public ComponentException() : base() { }
public ComponentException(string message) : base(message) { }
protected ComponentException(SerializationInfo info, StreamingContext context) : base(info, context) { }
public ComponentException(string message, Exception innerException) : base(message, innerException) { }
}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class CompIDAttribute : Attribute
{
private string m_id;
public CompIDAttribute(string id)
{
m_id = id;
}
public string ID { get { return m_id; } }
}
public enum IndexerType
{
Input = 1,
Output = 2,
Both = 3
}
/// <summary>
/// This is class for accessing of output aliases of input columns (For example - see sort transform)
/// </summary>
public class OutputAliasIndexer
{
EzComponent m_obj;
string m_propname;
public OutputAliasIndexer(EzComponent obj, string propname) { m_obj = obj; m_propname = propname; }
public string this[string inputColName]
{
get
{
IDTSInputColumn100 col = m_obj.InputCol(inputColName);
foreach (IDTSOutputColumn100 c in m_obj.Meta.OutputCollection[0].OutputColumnCollection)
{
if (!m_obj.OutputColumnPropertyExists(c.Name, m_propname))
continue;
int id = (int)m_obj.OutputCol(c.Name).CustomPropertyCollection[m_propname].Value;
if (col.LineageID == id)
return c.Name;
}
return null;
}
set
{
IDTSInputColumn100 col = m_obj.InputCol(inputColName);
string outColName = this[inputColName];
if (string.IsNullOrEmpty(outColName))
outColName = inputColName;
m_obj.OutputCol(outColName).Name = value;
m_obj.ReinitializeMetaData();
}
}
}
/// <summary>
/// Class to implement access to columns custom properties as arrays.
/// It indexes only columns which are in the first input or output.
/// </summary>
/// <typeparam name="T">type of the property</typeparam>
public class ColumnCustomPropertyIndexer<T>
{
EzComponent m_obj;
string m_propname; // column property name
bool m_insout; // insert new output column if column with indexed name does not exist
IndexerType m_indtype;
public ColumnCustomPropertyIndexer(EzComponent obj, string propname, IndexerType indtype) : this(obj, propname, indtype, false) { }
/// <summary>
/// Class constructor
/// </summary>
/// <param name="obj">Component which columns properties are to be index</param>
/// <param name="propname">Custom property name</param>
/// <param name="indtype">Which columns are to be searched (input, output or both)</param>
/// <param name="insOutput">Indicates if new output column is to be created when indexed column does not exist.
/// Setting to true also causes to set usage type of input column to READWRITE.</param>
public ColumnCustomPropertyIndexer(EzComponent obj, string propname, IndexerType indtype, bool insOutput)
{
m_obj = obj;
m_propname = propname;
m_indtype = indtype;
m_insout = insOutput;
}
public T this[string colName]
{
get { return this[colName, 0]; }
set { this[colName, 0] = value; }
}
public T this[string colName, int inOrOutIndex]
{
get { return this[colName, inOrOutIndex, inOrOutIndex]; }
set { this[colName, inOrOutIndex, inOrOutIndex] = value; }
}
public T this[string colName, int inputIndex, int outputIndex]
{
get
{
if ((m_indtype & IndexerType.Input) != 0 && m_obj.InputColumnExists(inputIndex, colName))
return (T)m_obj.Meta.InputCollection[inputIndex].InputColumnCollection[colName].CustomPropertyCollection[m_propname].Value;
if ((m_indtype & IndexerType.Input) != 0 && m_obj.OutputColumnExists(outputIndex, colName))
return (T)m_obj.Meta.OutputCollection[outputIndex].OutputColumnCollection[colName].CustomPropertyCollection[m_propname].Value;
throw new PropertyException(string.Format("Cannot get property {0}. The specified column {1} is not found.", m_propname, colName));
}
set
{
if ((m_indtype & IndexerType.Input) != 0 && m_obj.VirtualInputColumnExists(inputIndex, colName))
{
m_obj.LinkInputToOutput(inputIndex, colName);
if (m_insout)
m_obj.SetUsageType(inputIndex, colName, DTSUsageType.UT_READWRITE, false);
m_obj.SetInputColumnProperty(inputIndex, colName, m_propname, value, m_insout);
return;
}
if ((m_indtype & IndexerType.Output) != 0)
{
if (!m_obj.OutputColumnExists(outputIndex, colName) && m_insout)
m_obj.InsertOutputColumn(outputIndex, colName, -1, false);
if (m_obj.OutputColumnExists(outputIndex, colName))
{
m_obj.SetOutputColumnProperty(outputIndex, colName, m_propname, value);
return;
}
}
throw new PropertyException(string.Format("Cannot set property {0}. The specified column {1} is not found.", m_propname, colName));
}
}
}
public class EzComponent
{
protected EzDataFlow m_parent;
protected IDTSComponentMetaData100 m_meta;
protected IDTSDesigntimeComponent100 m_comp;
public string GetCompID()
{
object[] compids = GetType().GetCustomAttributes(typeof(CompIDAttribute), true);
if (compids.Length == 0)
return null;
return (compids[0] as CompIDAttribute).ID;
}
public IDTSComponentMetaData100 Meta { get { return m_meta; } }
public IDTSDesigntimeComponent100 Comp { get { return m_comp; } }
public EzDataFlow Parent { get { return m_parent; } }
public string Name { get { return m_meta.Name; } set { m_meta.Name = value; } }
public string Description
{
get { return EzExecutable.GetEzDescription(Meta.Description); }
set { Meta.Description = string.Format("<EzName>{0}</EzName>{1}", EzName, value); }
}
public EzComponent(EzDataFlow dataFlow)
{
m_parent = dataFlow;
if (m_parent == null)
throw new ComponentException("Cannot create component without Dataflow. Component parent cannot be null.");
CreateComponent();
Parent.m_components.Add(this);
}
public EzComponent(EzDataFlow parent, IDTSComponentMetaData100 meta) { Assign(parent, meta); Parent.m_components.Add(this); }
public virtual EzComponent Assign(EzDataFlow parent, IDTSComponentMetaData100 meta)
{
if (meta == null)
throw new ArgumentNullException("meta");
if (!meta.ComponentClassID.ToUpper(CultureInfo.InvariantCulture).Contains(GetCompID().ToUpper(CultureInfo.InvariantCulture)))
throw new IncorrectAssignException(string.Format("Cannot assign non-{0} component to {0 object.", GetType().Name));
m_meta = meta;
m_comp = m_meta.Instantiate();
m_parent = parent;
return this;
}
/// <summary>
/// Returns the member name of the current component, if it exists in the parent package
/// </summary>
public string EzName
{
get
{
EzExecutable p = Parent;
while (p != null)
{
FieldInfo[] m = p.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy);
foreach (FieldInfo mi in m)
{
object cur = mi.GetValue(p);
EzComponent curComp = cur as EzComponent;
if (curComp == null)
continue;
if (curComp.ID == ID && Parent.ID == curComp.Parent.ID)
return mi.Name;
}
p = p.Parent;
}
return null;
}
}
protected void CreateComponent()
{
m_meta = m_parent.DataFlow.ComponentMetaDataCollection.New();
m_meta.ComponentClassID = GetCompID();
m_comp = m_meta.Instantiate();
m_comp.ProvideComponentProperties();
m_meta.Name = GetType().Name + m_meta.ID;
}
public void AttachTo(EzComponent c)
{
AttachTo(c, 0, 0);
}
public virtual void AttachTo(EzComponent c, int outInd, int inInd)
{
if (c == null)
throw new ArgumentNullException("c");
Detach(inInd, false);
IDTSOutput100 upstreamOutput = c.Meta.OutputCollection[outInd];
IDTSPath100 path = m_parent.DataFlow.PathCollection.New();
path.AttachPathAndPropagateNotifications(upstreamOutput, m_meta.InputCollection[inInd]);
c.ReinitializeMetaData();
}
public virtual void Detach()
{
Detach(0);
}
public virtual void Detach(int inID)
{
Detach(inID, true);
}
public virtual void Detach(int inID, bool reinitMeta)
{
foreach (IDTSPath100 p in m_parent.DataFlow.PathCollection)
{
if (p.EndPoint.ID == Meta.InputCollection[inID].ID)
{
m_parent.DataFlow.PathCollection.RemoveObjectByID(p.ID);
if (reinitMeta)
ReinitializeMetaData();
return;
}
}
}
public void SetComponentProperty(string propName, object propValue)
{
m_comp.SetComponentProperty(propName, propValue);
}
public bool CustomPropertyExists(string name)
{
return CustomPropertyExists(Meta.CustomPropertyCollection, name);
}
public bool CustomPropertyExists(IDTSCustomPropertyCollection100 props, string name)
{
foreach (IDTSCustomProperty100 p in props)
if (string.Compare(p.Name, name, StringComparison.OrdinalIgnoreCase) == 0)
return true;
return false;
}
public bool InputColumnPropertyExists(string colName, string propName)
{
return InputColumnPropertyExists(0, colName, propName);
}
public bool InputColumnPropertyExists(int inputIndex, string colName, string propName)
{
if (!VirtualInputColumnExists(inputIndex, colName))
return false;
foreach (IDTSCustomProperty100 p in InputCol(inputIndex, colName).CustomPropertyCollection)
if (string.Compare(p.Name, propName, StringComparison.OrdinalIgnoreCase) == 0)
return true;
return false;
}
public bool OutputColumnPropertyExists(string colName, string propName)
{
return OutputColumnPropertyExists(0, colName, propName);
}
public bool OutputColumnPropertyExists(int outputIndex, string colName, string propName)
{
if (!OutputColumnExists(outputIndex, colName))
return false;
foreach (IDTSCustomProperty100 p in OutputCol(outputIndex, colName).CustomPropertyCollection)
if (string.Compare(p.Name, propName, StringComparison.OrdinalIgnoreCase) == 0)
return true;
return false;
}
public string Compare(EzComponent v)
{
if (v == null)
throw new ArgumentNullException("v");
PropertyInfo[] pi = typeof(IDTSComponentMetaData100).GetProperties();
foreach (PropertyInfo p in pi)
{
string res = CompareProperty(p, Meta, v.Meta);
if (!string.IsNullOrEmpty(res))
return res;
}
return string.Empty;
}
private string CompareProperty(PropertyInfo p, object origObj, object newObj)
{
return CompareProperty(p, origObj, newObj, null);
}
private string CompareProperty(PropertyInfo p, object origObj, object newObj, object[] index)
{
if (IsSkipProperty(p.Name))
return string.Empty;
object origVal = p.GetValue(origObj, index);
object newVal = p.GetValue(newObj, index);
if (p.PropertyType.IsPrimitive || p.PropertyType.IsValueType ||
"System.String" == p.PropertyType.FullName || "System.Decimal" == p.PropertyType.FullName ||
"System.DateTime" == p.PropertyType.FullName || "System.Object" == p.PropertyType.FullName)
{
if (!origVal.Equals(newVal))
return string.Format("{0} property values are different: {1} <> {2}", p.Name, origVal, newVal);
else
return string.Empty;
}
else
return RecursiveCompare(p, origVal, newVal);
}
private string RecursiveCompare(PropertyInfo parent, object origObj, object newObj)
{
PropertyInfo[] pi = parent.PropertyType.GetProperties();
foreach (PropertyInfo p in pi)
{
string res;
System.Reflection.ParameterInfo[] param = p.GetIndexParameters();
if (param.Length <= 0)
{
res = CompareProperty(p, origObj, newObj);
if (!string.IsNullOrEmpty(res))
return string.Format("{0}.{1}", parent.Name, res);
continue;
}
object[] index = new object[1];
PropertyInfo countprop = parent.PropertyType.GetProperty("Count");
res = CompareProperty(countprop, origObj, newObj);
if (!string.IsNullOrEmpty(res))
return string.Format("{0}.{1}", parent.Name, res);
int count = (int)countprop.GetValue(origObj, null);
for (int i = 0; i < count; i++)
{
index[0] = i;
res = CompareProperty(p, origObj, newObj, index);
if (!string.IsNullOrEmpty(res))
return string.Format("{0}[{1}].{2}", parent.Name, i, res);
}
}
return string.Empty;
}
private static bool IsSkipProperty(string propertyName)
{
switch (propertyName)
{
case "Buffer":
case "IsAttached":
case "ConnectionManager":
case "IdentificationString":
case "Component":
return true;
case "ID": //To support merge and diff we are stripping out these pipeline IDs on save and replacing them with more robust references and then regenerating IDs on load.
return true;
case "LineageID":
return true;
case "ExternalMetadataColumnID":
return true;
case "SynchronousInputID":
return true;
case "Value":
return true;
}
return false;
}
public void AddCustomProperty(string name, object value)
{
IDTSCustomProperty100 p = null;
if (!CustomPropertyExists(name))
{
p = m_meta.CustomPropertyCollection.New();
p.Name = name;
}
else
p = m_meta.CustomPropertyCollection[name];
p.Value = value;
}
public string DescribeRedirectedErrorCode(int code)
{
return Comp.DescribeRedirectedErrorCode(code);
}
public IDTSInputColumn100 InputCol(int inputIndex, string colName)
{
if (!InputColumnExists(inputIndex, colName) && VirtualInputColumnExists(0, colName))
LinkInputToOutput(inputIndex, colName);
return Meta.InputCollection[inputIndex].InputColumnCollection[colName];
}
public IDTSInputColumn100 InputCol(string colName)
{
return InputCol(0, colName);
}
public IDTSVirtualInputColumn100 VirtualInputCol(string colName)
{
return VirtualInputCol(0, colName);
}
public IDTSVirtualInputColumn100 VirtualInputCol(int inputIndex, string colName)
{
return Meta.InputCollection[inputIndex].GetVirtualInput().VirtualInputColumnCollection[colName];
}
public IDTSExternalMetadataColumn100 ExternalCol(int inputIndex, string colName)
{
return Meta.InputCollection[inputIndex].ExternalMetadataColumnCollection[colName];
}
public IDTSExternalMetadataColumn100 ExternalCol(string colName)
{
return ExternalCol(0, colName);
}
public IDTSOutputColumn100 OutputCol(int outputIndex, string colName)
{
return Meta.OutputCollection[outputIndex].OutputColumnCollection[colName];
}
public IDTSOutputColumn100 OutputCol(string colName)
{
return OutputCol(0, colName);
}
public void SetInputProperty(string propName, string propValue)
{
SetInputProperty(0, propName, propValue);
}
public void SetInputProperty(int inputIndex, string propName, string propValue)
{
Comp.SetInputProperty(Meta.InputCollection[inputIndex].ID, propName, propValue);
}
public void SetInputColumnProperty(int inputIndex, string columnName, string propertyName, object propertyValue)
{
SetInputColumnProperty(inputIndex, columnName, propertyName, propertyValue, true);
}
public void SetInputColumnProperty(int inputIndex, string columnName, string propertyName, object propertyValue,
bool reinitMeta)
{
IDTSInput100 input = m_meta.InputCollection[inputIndex];
IDTSInputColumn100 inputColumn = input.InputColumnCollection[columnName];
m_comp.SetInputColumnProperty(input.ID, inputColumn.ID, propertyName, propertyValue);
if (reinitMeta)
ReinitializeMetaData();
}
public void SetInputColumnProperty(string columnName, string propertyName, object propertyValue)
{
SetInputColumnProperty(0,columnName,propertyName,propertyValue);
}
public void SetOutputProperty(string propName, object propValue)
{
SetOutputProperty(0, propName, propValue);
}
public void SetOutputProperty(int outputIndex, string propName, object propValue)
{
Comp.SetOutputProperty(Meta.OutputCollection[outputIndex].ID, propName, propValue);
}
//Paul Rizza - https://blogs.msdn.microsoft.com/paulrizza/2014/07/14/ssis-2012-ezapi-basic-intro/
public void SetOutputSorted(int outputIndex, bool IsSorted)
{
m_meta.OutputCollection[outputIndex].IsSorted = IsSorted;
}
public void SetOutputColumnErrorRowDisposition(string columnName, DTSRowDisposition propertyValue)
{
IDTSOutput100 output = m_meta.OutputCollection[0];
IDTSOutputColumn100 outputColumn = output.OutputColumnCollection[columnName];
outputColumn.ErrorRowDisposition = propertyValue;
}
public void SetOutputColumnTruncationRowDisposition(string columnName, DTSRowDisposition propertyValue)
{
IDTSOutput100 output = m_meta.OutputCollection[0];
IDTSOutputColumn100 outputColumn = output.OutputColumnCollection[columnName];
outputColumn.TruncationRowDisposition = propertyValue;
}
public void SetOutputColumnProperty(int outputIndex, string columnName, string propertyName, object propertyValue, bool initMeta)
{
if (!OutputColumnExists(outputIndex, columnName))
InsertOutputColumn(outputIndex, columnName, -1, false);
IDTSOutput100 output = m_meta.OutputCollection[outputIndex];
IDTSOutputColumn100 outputColumn = output.OutputColumnCollection[columnName];
m_comp.SetOutputColumnProperty(output.ID, outputColumn.ID, propertyName, propertyValue);
if (initMeta)
ReinitializeMetaData();
}
public void SetOutputColumnProperty(int outputIndex, string columnName, string propertyName, object propertyValue)
{
SetOutputColumnProperty(outputIndex, columnName, propertyName, propertyValue, true);
}
public void SetOutputColumnProperty(string columnName, string propertyName, object propertyValue)
{
SetOutputColumnProperty(0, columnName, propertyName, propertyValue);
}
public void SetColumnProperty(string colName, string propName, object value)
{
if (InputColumnExists(colName))
SetInputColumnProperty(colName, propName, value);
else
SetOutputColumnProperty(colName, propName, value);
}
/// <summary>
/// Inserts input to the component at the specified position
/// </summary>
/// <param name="indexAt"></param>
public void InsertInput(int indexAt)
{
if (indexAt < 0)
indexAt = 0;
if (indexAt > InputCount)
indexAt = InputCount;
DTSInsertPlacement ip = DTSInsertPlacement.IP_BEFORE;
if (indexAt == InputCount)
{
indexAt--;
ip = DTSInsertPlacement.IP_AFTER;
}
Comp.InsertInput(ip, Meta.InputCollection[indexAt].ID);
}
public void InsertInput()
{
InsertInput(InputCount);
}
public void InsertOutput(int indexAt)
{
if (indexAt < 0)
indexAt = 0;
if (indexAt > OutputCount)
indexAt = OutputCount;
DTSInsertPlacement ip = DTSInsertPlacement.IP_BEFORE;
if (indexAt == OutputCount)
{
indexAt--;
ip = DTSInsertPlacement.IP_AFTER;
}
Comp.InsertOutput(ip, Meta.OutputCollection[indexAt].ID);
}
public void InsertOutput()
{
InsertOutput(OutputCount);
}
public void DeleteInput(int inputIndex)
{
Comp.DeleteInput(Meta.InputCollection[inputIndex].ID);
}
public void DeleteOutput(int outputIndex)
{
Comp.DeleteOutput(Meta.OutputCollection[outputIndex].ID);
}
public int InputCount { get { return Meta.InputCollection.Count; } }
public int OutputCount { get { return Meta.OutputCollection.Count; } }
public void InsertOutputColumn(string columnName)
{
InsertOutputColumn(0, columnName);
}
public void InsertOutputColumn(int outputIndex, string columnName)
{
InsertOutputColumn(outputIndex, columnName, -1);
}
public void InsertOutputColumn(int outputIndex, string columnName, int colIndex)
{
InsertOutputColumn(outputIndex, columnName, colIndex, true);
}
public void InsertOutputColumn(int outputIndex, string columnName, int colIndex, bool initMeta)
{
int outputID = Meta.OutputCollection[outputIndex].ID;
IDTSOutputColumnCollection100 outCols = Meta.OutputCollection[outputIndex].OutputColumnCollection;
if (colIndex < 0)
colIndex = outCols.Count;
m_comp.InsertOutputColumnAt(outputID, colIndex, columnName, "OUTPUT COLUMN " + columnName);
if (initMeta)
ReinitializeMetaData();
}
public void SetUsageType(int inputIndex, string columnName, DTSUsageType usageType)
{
SetUsageType(inputIndex, columnName, usageType, true);
}
public void SetUsageType(int inputIndex, string columnName, DTSUsageType usageType, bool initMeta)
{
if (VirtualInputCol(inputIndex, columnName).UsageType == usageType)
return;
IDTSInput100 input = m_meta.InputCollection[inputIndex];
// If we need to change usage tipe of the column from UT_READONLY to UT_READWRITE or vice versa and keep
// values of all the custom properties, we need to cache them because pipeline engine will rub them away
bool cacheValues = VirtualInputCol(inputIndex, columnName).UsageType != DTSUsageType.UT_IGNORED && usageType != DTSUsageType.UT_IGNORED;
Dictionary<string, object> props = new Dictionary<string, object>();
if (cacheValues)
foreach (IDTSCustomProperty100 p in input.InputColumnCollection[columnName].CustomPropertyCollection)
props[p.Name] = p.Value;
IDTSVirtualInput100 virtualInput = input.GetVirtualInput();
IDTSVirtualInputColumn100 virtualInputColumn = virtualInput.VirtualInputColumnCollection[columnName];
m_comp.SetUsageType(input.ID, virtualInput, virtualInputColumn.LineageID, usageType);
if (cacheValues)
foreach (string key in props.Keys)
{
if (CustomPropertyExists(input.InputColumnCollection[columnName].CustomPropertyCollection, key))
input.InputColumnCollection[columnName].CustomPropertyCollection[key].Value = props[key];
}
if (initMeta)
ReinitializeMetaData();
}
public void SetUsageType(string columnName, DTSUsageType usageType)
{
SetUsageType(0, columnName, usageType);
}
public void SetOutputColumnDataTypeProperties(int outputIndex, string columnName, DataType dataType,
int length, int precision, int scale, int codePage)
{
SetOutputColumnDataTypeProperties(outputIndex, columnName, dataType, length, precision, scale, codePage, true);
}
public void SetOutputColumnDataTypeProperties(int outputIndex, string columnName, DataType dataType,
int length, int precision, int scale, int codePage, bool initMeta)
{
IDTSOutput100 output = m_meta.OutputCollection[outputIndex];
IDTSOutputColumn100 outputColumn = output.OutputColumnCollection[columnName];
m_comp.SetOutputColumnDataTypeProperties(output.ID, outputColumn.ID, dataType, length, precision, scale, codePage);
if (initMeta)
ReinitializeMetaData();
}
public void SetOutputColumnDataTypeProperties(string columnName, DataType dataType, int length, int precision,
int scale, int codePage)
{
SetOutputColumnDataTypeProperties(0, columnName, dataType, length, precision, scale, codePage);
}
public void DeleteOutputColumn(string columnName)
{
DeleteOutputColumn(0, columnName);
}
public void DeleteOutputColumn(int outputIndex, string columnName)
{
IDTSOutput100 output = m_meta.OutputCollection[outputIndex];
IDTSOutputColumn100 outputColumn = output.OutputColumnCollection[columnName];
m_comp.DeleteOutputColumn(output.ID, outputColumn.ID);
ReinitializeMetaData();
}
public void DeleteInputColumn(string columnName)
{
DeleteInputColumn(0, columnName);
}
public void DeleteInputColumn(int inputIndex, string columnName)
{
DeleteInputColumn(inputIndex, columnName, true);
}
public void DeleteInputColumn(int inputIndex, string columnName, bool reinitMeta)
{
IDTSInput100 input = m_meta.InputCollection[inputIndex];
IDTSInputColumn100 inputColumn = input.InputColumnCollection[columnName];
input.InputColumnCollection.RemoveObjectByID(inputColumn.ID);
if (reinitMeta)
ReinitializeMetaData();
}
public void AcquireConnections() { AcquireConnections(null); }
public void AcquireConnections(object pTransaction) { m_comp.AcquireConnections(pTransaction); }
public void ReleaseConnections() { m_comp.ReleaseConnections(); }
public void ReinitializeMetaData()
{
Parent.ReinitializeMetaData(this);
}
public void LinkAllInputsToOutputs()
{
for (int i = 0; i < m_meta.InputCollection.Count; i++)
{
IDTSInput100 input = m_meta.InputCollection[i];
IDTSVirtualInput100 virtualInput = input.GetVirtualInput();
foreach (IDTSVirtualInputColumn100 virtualInputColumn in virtualInput.VirtualInputColumnCollection)
if (!InputColumnExists(i, virtualInputColumn.Name))
m_comp.SetUsageType(input.ID, virtualInput, virtualInputColumn.LineageID, DTSUsageType.UT_READONLY);
}
}
public void LinkInputToOutput(string colName)
{
LinkInputToOutput(0, colName);
}
public void LinkInputToOutput(int inputIndex, string colName)
{
if (InputColumnExists(inputIndex, colName))
return; // return as this column is already linked
IDTSInput100 input = m_meta.InputCollection[inputIndex];
IDTSVirtualInput100 virtualInput = input.GetVirtualInput();
IDTSVirtualInputColumn100 virtualInputColumn = virtualInput.VirtualInputColumnCollection[colName];
m_comp.SetUsageType(input.ID, virtualInput, virtualInputColumn.LineageID, DTSUsageType.UT_READONLY);
}
public virtual void ReinitializeMetaDataNoCast()
{
m_comp.ReinitializeMetaData();
}
public bool ValidateExternalMetadata
{
get { return m_meta.ValidateExternalMetadata; }
set { m_meta.ValidateExternalMetadata = value; }
}
public bool UsesDispositions { get { return m_meta.UsesDispositions; } set { m_meta.UsesDispositions = value; } }
public int ID { get { return m_meta.ID; } set { m_meta.ID = value; } }
public string IdentificationString { get { return m_meta.IdentificationString; } }
public int LocaleID { get { return m_meta.LocaleID; } set { m_meta.LocaleID = value; } }
public bool VirtualInputColumnExists(int inputInd, string colName)
{
IDTSVirtualInputColumnCollection100 cols = m_meta.InputCollection[inputInd].GetVirtualInput().VirtualInputColumnCollection;
for (int i = 0; i < cols.Count; i++)
if (string.Compare(cols[i].Name, colName, StringComparison.OrdinalIgnoreCase) == 0)
return true;
return false;
}
public bool VirtualInputColumnExists(string colName)
{
return VirtualInputColumnExists(0, colName);
}
public bool InputColumnExists(int inputInd, string colName)
{
IDTSInputColumnCollection100 cols = m_meta.InputCollection[inputInd].InputColumnCollection;
for (int i = 0; i < cols.Count; i++)
if (string.Compare(cols[i].Name, colName, StringComparison.OrdinalIgnoreCase) == 0)
return true;
return false;
}
public bool InputColumnExists(string colName)
{
return Meta.InputCollection.Count != 0 && InputColumnExists(0, colName);
}
public bool OutputColumnExists(string colName)
{
return OutputColumnExists(0, colName);
}
public bool OutputColumnExists(int outputInd, string colName)
{
IDTSOutputColumnCollection100 cols = m_meta.OutputCollection[outputInd].OutputColumnCollection;
for (int i = 0; i < cols.Count; i++)
if (string.Compare(cols[i].Name, colName, StringComparison.OrdinalIgnoreCase) == 0)
return true;
return false;
}
public bool ExternalColumnExists(int inputInd, string colName)
{
IDTSExternalMetadataColumnCollection100 cols = m_meta.InputCollection[inputInd].ExternalMetadataColumnCollection;
for (int i = 0; i < cols.Count; i++)
if (string.Compare(cols[i].Name, colName, StringComparison.OrdinalIgnoreCase) == 0)
return true;
return false;
}
public bool ExternalColumnExists(string colName)
{
return ExternalColumnExists(0, colName);
}
public void MapColumn(string inputColName, string externalColName)
{
LinkInputToOutput(inputColName);
m_comp.MapInputColumn(m_meta.InputCollection[0].ID, InputCol(inputColName).ID, ExternalCol(externalColName).ID);
}
public void UnmapColumn(string inputColName)
{
InputCol(inputColName).MappedColumnID = 0;
m_comp.MapInputColumn(m_meta.InputCollection[0].ID, InputCol(inputColName).ID, 0);
}
public void UnmapAllInputColumns()
{
foreach(IDTSInputColumn100 inputcol in m_meta.InputCollection[0].InputColumnCollection)
{
UnmapColumn(inputcol.Name);
}
}
public void MapOutputColumn(string outputColName, string externalColName)
{
MapOutputColumn(outputColName, externalColName, true);
}
public void MapOutputColumn(string outputColName, string externalColName, bool bMatch)
{
IDTSExternalMetadataColumn100 c = Meta.OutputCollection[0].ExternalMetadataColumnCollection[externalColName];
if (!OutputColumnExists(outputColName))
InsertOutputColumn(0, outputColName, -1, false);
m_comp.MapOutputColumn(m_meta.OutputCollection[0].ID, OutputCol(outputColName).ID, c.ID, bMatch);
}
public void UnmapOutputColumn(string outputColName)
{
UnmapOutputColumn(outputColName, true);
}
public void UnmapOutputColumn(string outputColName, bool reinitMeta)
{
m_comp.MapOutputColumn(m_meta.OutputCollection[0].ID, OutputCol(outputColName).ID, 0, true);
if (reinitMeta)
ReinitializeMetaData();
}
public object CallDesignTimeMethod(string methodName, object[] methodParams, bool commit)
{
IDTSComponentView100 view = Meta.GetComponentView();
MethodInfo method = typeof(IDTSDesigntimeComponent100).GetMethod(methodName);
object returnVal = method.Invoke(Comp, methodParams);
if (commit)
view.Commit();
else
view.Cancel();
return returnVal;
}
}
public enum AccessMode
{
AM_OPENROWSET = 0,
AM_OPENROWSET_VARIABLE = 1,
AM_SQLCOMMAND = 2,
AM_SQLCOMMAND_VARIABLE = 3, // for oledb source only
AM_OPENROWSET_FASTLOAD = 3, // for oledb destination only
AM_OPENROWSET_FASTLOAD_VARIABLE = 4 // for oledb destination only
}
public class EzAdapter : EzComponent
{
protected EzAdapter(EzDataFlow dataFlow) : base(dataFlow) { }
protected EzAdapter(EzDataFlow parent, IDTSComponentMetaData100 meta) : base(parent, meta) { }
protected virtual void VerifyConnection() { }
protected EzConnectionManager m_connection;
public EzConnectionManager Connection
{
get
{
if (m_connection == null)
{
IDTSRuntimeConnection100 rtCnn = m_meta.RuntimeConnectionCollection[0];
if (rtCnn != null)
m_connection = new EzCacheCM(Parent.Package, Parent.Package.Connections[rtCnn.ConnectionManagerID]);
}
return m_connection;
}
set
{
IDTSRuntimeConnection100 rtCnn = m_meta.RuntimeConnectionCollection[0];
rtCnn.ConnectionManagerID = ((ConnectionManager)value).ID;
rtCnn.ConnectionManager = DtsConvert.GetExtendedInterface((ConnectionManager)value);
m_connection = value;
VerifyConnection();
}
}
public override void ReinitializeMetaDataNoCast()
{
if (m_meta.RuntimeConnectionCollection[0].ConnectionManager == null
|| string.IsNullOrEmpty(m_meta.RuntimeConnectionCollection[0].ConnectionManager.ConnectionString)
|| string.Compare(m_meta.RuntimeConnectionCollection[0].ConnectionManager.ConnectionString, "Provider=Microsoft.Jet.OLEDB.4.0;", true) == 0 )
return;
AcquireConnections();
try
{
base.ReinitializeMetaDataNoCast();
}
catch
{
return;
}
finally
{
ReleaseConnections();
}
if (m_meta.InputCollection.Count == 0)
return;
IDTSInput100 input = m_meta.InputCollection[0];
IDTSVirtualInput100 virtualInput = input.GetVirtualInput();
IDTSExternalMetadataColumnCollection100 extMetadataColumns = input.ExternalMetadataColumnCollection;
List<string> cols = new List<string>();
foreach (IDTSVirtualInputColumn100 virtualInputColumn in virtualInput.VirtualInputColumnCollection)
{