_
_
_
_
_
Public Class ScriptMain
Inherits UserComponent
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Overrides Sub Input_ProcessInputRow(ByVal Row As InputBuffer)
Try
If Not m_service2011 Is Nothing Then
' CRM 2011
Dim req As New CRM2011.OrganizationRequest
req.RequestName = m_requestName
req("RelationshipName") = Me.RelationshipName
' Setup relationship parameters.
Dim moniker1 As New CRM2011.EntityReference
moniker1.LogicalName = CStr(Row.Buffer(m_fenIndex))
moniker1.Id = New Guid(Row.Buffer(m_feiIndex).ToString())
req("Moniker1") = moniker1
Dim moniker2 As New CRM2011.EntityReference
moniker2.LogicalName = CStr(Row.Buffer(m_senIndex))
moniker2.Id = New Guid(Row.Buffer(m_seiIndex).ToString())
req("Moniker2") = moniker2
' Execute action.
Call m_service2011.Execute(req)
Else
' CRM 4.0
' Setup relationship parameters.
Dim moniker1 As New CRM4.Moniker
moniker1.Name = CStr(Row.Buffer(m_fenIndex))
moniker1.Id = New Guid(Row.Buffer(m_feiIndex).ToString())
Dim moniker2 As New CRM4.Moniker
moniker2.Name = CStr(Row.Buffer(m_senIndex))
moniker2.Id = New Guid(Row.Buffer(m_seiIndex).ToString())
' Execute action.
Select Case Me.Action
Case ActionTypes.Associate
Dim assocReq As New CRM4.AssociateEntitiesRequest
assocReq.Moniker1 = moniker1
assocReq.Moniker2 = moniker2
assocReq.RelationshipName = Me.RelationshipName
Call m_service4.Execute(assocReq)
Case ActionTypes.Disassociate
Dim disassocReq As New CRM4.DisassociateEntitiesRequest
disassocReq.Moniker1 = moniker1
disassocReq.Moniker2 = moniker2
disassocReq.RelationshipName = Me.RelationshipName
Call m_service4.Execute(disassocReq)
Case Else
Throw New ApplicationException("Unhandled action type.")
End Select
End If
Catch ex As SoapException
Call FireError_(ex.Detail.InnerXml)
Catch ex As Exception
Call FireError_(ex.Message)
End Try
End Sub ' Input_ProcessInputRow
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Overrides Sub PreExecute()
Call MyBase.PreExecute()
' Setup CRM service.
m_connection = CType( _
Me.Connections.CrmConnection.AcquireConnection(Nothing), _
ICrmConnection)
Call m_connection.Connect()
Dim service As Object = m_connection.GetService(0) ' 0 - CRM Service
m_service2011 = TryCast(service, CRM2011.OrganizationServiceClient)
If m_service2011 Is Nothing Then
m_service4 = TryCast(service, CRM4.CrmService)
If m_service4 Is Nothing Then
Throw New Exception("Unhandled service object.")
End If
End If
' Setup request for CRM 2011.
Select Case Me.Action
Case ActionTypes.Associate
m_requestName = "AssociateEntities"
Case ActionTypes.Disassociate
m_requestName = "DisassociateEntities"
Case Else
Throw New ApplicationException("Unhandled action type.")
End Select
Dim input As IDTSInput100 = MyBase.ComponentMetaData.InputCollection(0)
Dim inputCol As IDTSInputColumn100
' Get input column indexes.
inputCol = GetInputColumn_("FirstEntityName")
m_fenIndex = Me.HostComponent.BufferManager.FindColumnByLineageID( _
input.Buffer, _
inputCol.LineageID)
inputCol = GetInputColumn_("FirstEntityId")
m_feiIndex = Me.HostComponent.BufferManager.FindColumnByLineageID( _
input.Buffer, _
inputCol.LineageID)
inputCol = GetInputColumn_("SecondEntityName")
m_senIndex = Me.HostComponent.BufferManager.FindColumnByLineageID( _
input.Buffer, _
inputCol.LineageID)
inputCol = GetInputColumn_("SecondEntityId")
m_seiIndex = Me.HostComponent.BufferManager.FindColumnByLineageID( _
input.Buffer, _
inputCol.LineageID)
End Sub ' PreExecute
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Overrides Sub PostExecute()
Call MyBase.PostExecute()
Call m_connection.Close()
End Sub ' PostExecute
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function Validate(ByRef errMessage As String) As Boolean
Dim result As Boolean
Try
If String.IsNullOrEmpty(Me.CrmConnection) Then
Throw New ApplicationException("Select Dynamics CRM connection.")
End If
If String.IsNullOrEmpty(Me.RelationshipName) Then
Throw New ApplicationException("Specify relationship name.")
End If
Dim input As IDTSInput100 = Me.ComponentMetaData.InputCollection(0)
If input.IsAttached AndAlso _
(input.InputColumnCollection.Count = 0 OrElse _
input.InputColumnCollection.Count < 4) Then
Throw New Exception("Map input columns.")
End If
' Store connection information in the runtime connection collection, too.
' Cannot directly use RuntimeConnectionCollection in the property get/set
' because of issues with multi-threading.
Me.ComponentMetaData.RuntimeConnectionCollection("CrmConnection").ConnectionManagerID = Me.CrmConnection
result = True
Catch ex As Exception
result = False
errMessage = ex.Message
End Try
Validate = result
End Function 'Validate
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Overrides Sub ReinitializeMetaData()
Call MyBase.ReinitializeMetaData()
If MyBase.ComponentMetaData.InputCollection.Count = 0 Then
' At least one input must exist.
Throw New Exception("No inputs.")
End If
Dim input As IDTSInput100 = MyBase.ComponentMetaData.InputCollection(0)
' Cleanup.
input.ExternalMetadataColumnCollection.IsUsed = True
Call input.InputColumnCollection.RemoveAll()
Call input.ExternalMetadataColumnCollection.RemoveAll()
Dim column As IDTSExternalMetadataColumn100
' Setup first entity.
column = input.ExternalMetadataColumnCollection.[New]()
column.Name = "FirstEntityName"
column.DataType = DataType.DT_WSTR
column.Length = 100
column = input.ExternalMetadataColumnCollection.[New]()
column.Name = "FirstEntityId"
column.DataType = DataType.DT_GUID
' Setup second entity.
column = input.ExternalMetadataColumnCollection.[New]()
column.Name = "SecondEntityName"
column.DataType = DataType.DT_WSTR
column.Length = 100
column = input.ExternalMetadataColumnCollection.[New]()
column.Name = "SecondEntityId"
column.DataType = DataType.DT_GUID
End Sub ' ReinitializeMetaData
#Region "Properties"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
_
_
_
Public Property CrmConnection() As String
Get
CrmConnection = m_crmConnection
End Get
Set(ByVal value As String)
m_crmConnection = value
End Set
End Property ' CrmConnection
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
_
_
Public Property Action() As ActionTypes
Get
Action = m_action
End Get
Set(ByVal value As ActionTypes)
m_action = value
End Set
End Property ' Action
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
_
_
Public Property RelationshipName() As String
Get
RelationshipName = m_relationshipName
End Get
Set(ByVal value As String)
m_relationshipName = value
End Set
End Property ' RelationshipName
#End Region ' Properties
#Region "Internals"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private ReadOnly Property CrmConnectionType() As String()
Get
CrmConnectionType = New String() {"DYNAMICS-CRM"}
End Get
End Property ' CrmConnectionType
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub FireError_(ByVal message As String)
Dim cancel As Boolean = False
Call MyBase.ComponentMetaData.FireError( _
0, _
"Dynamics CRM Relationships", _
message, _
String.Empty, _
0, _
cancel)
End Sub ' FireError_
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function GetInputColumn_(ByVal externalName As String) As IDTSInputColumn100
Dim result As IDTSInputColumn100
Dim input As IDTSInput100 = MyBase.ComponentMetaData.InputCollection(0)
Dim extColumn As IDTSExternalMetadataColumn100 = input.ExternalMetadataColumnCollection(externalName)
' Find input column for specified external column.
For Each inputCol As IDTSInputColumn100 In input.InputColumnCollection
If inputCol.ExternalMetadataColumnID = extColumn.ID Then
' Found input column.
result = inputCol
Exit For
End If
Next
If result Is Nothing Then
Throw New Exception("Input column not found.")
End If
GetInputColumn_ = result
End Function ' GetInputColumn_
#End Region ' Internals
#Region "Attributes"
Enum ActionTypes
Associate
Disassociate
End Enum ' ActionTypes
Private m_crmConnection As String
Private m_action As ActionTypes
Private m_relationshipName As String
Private m_connection As ICrmConnection
Private m_service2011 As CRM2011.OrganizationServiceClient
Private m_service4 As CRM4.CrmService
Private m_requestName As String
Private m_fenIndex As Integer
Private m_feiIndex As Integer
Private m_senIndex As Integer
Private m_seiIndex As Integer
#End Region ' Attributes
End Class ' ScriptMain
]]>{30D016F9-3734-4E33-A861-5E7D899E18F3};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}DebugAnyCPU8.0.307032.0{0C9E8046-52E7-4D2F-9113-343CB5758CE9}LibraryMy ProjectScriptComponent_fb9fe4dbdd154fe1b06903054a22dc92ScriptComponent_fb9fe4dbdd154fe1b06903054a22dc92v4.0512BinaryOnOntruefullfalse.\bin\Debug\falsetruetrueprompt4falsetrue.\bin\Release\falsefalsetrueprompt4FalseC:\Program Files (x86)\Microsoft SQL Server\120\SDK\Assemblies\CozyRoc.SSISPlus.2014.dllFalseFalseFalseFalseFalseFalseSSIS_SC120]]> _
Public Class InputBuffer
Inherits ScriptBufferPlus
Public Sub New(ByVal Component As ScriptComponent, ByVal ObjectID As Integer, ByVal IsInput As Boolean, ByVal Buffer As PipelineBuffer, ByVal OutputMap As OutputNameMap)
MyBase.New(Component, ObjectID, IsInput, Buffer, OutputMap)
End Sub
Public Overrides ReadOnly Property StaticInputColumns() As String()
Get
Return New String() {}
End Get
End Property
Public Overrides ReadOnly Property StaticOutputColumns() As String()
Get
Return New String() {}
End Get
End Property
Public Overloads Function NextRow() As Boolean
NextRow = MyBase.NextRow()
End Function
Public Overloads Function EndOfRowset() As Boolean
EndOfRowset = MyBase.EndOfRowset
End Function
End Class
]]> _
Public Class UserComponent
Inherits ScriptComponentPlus
Public Connections As New Connections(Me)
Public Variables As New Variables(Me)
Public Overrides Sub ProcessInput(ByVal InputID As Integer, ByVal InputName As String, ByVal Buffer As PipelineBuffer, ByVal OutputMap As OutputNameMap)
If InputID = MyBase.ComponentMetaData.InputCollection("Input").ID Then
Input_ProcessInput(New InputBuffer(Me, InputID, True, Buffer, OutputMap))
End If
End Sub
Public Overridable Sub Input_ProcessInput(ByVal Buffer As InputBuffer)
While Buffer.NextRow()
Input_ProcessInputRow(Buffer)
End While
End Sub
Public Overridable Sub Input_ProcessInputRow(ByVal Row As InputBuffer)
End Sub
End Class
Public Class Connections
Dim ParentComponent As ScriptComponent
_
Public Sub New(ByVal Component As ScriptComponent)
ParentComponent = Component
End Sub
Public ReadOnly Property CrmConnection() As IDTSConnectionManager100
Get
Return ParentComponent.ComponentMetaData.RuntimeConnectionCollection("CrmConnection").ConnectionManager
End Get
End Property
End Class
Public Class Variables
Dim ParentComponent As ScriptComponent
_
Public Sub New(ByVal Component As ScriptComponent)
ParentComponent = Component
End Sub
End Class
]]>msBuildScriptComponent_fb9fe4dbdd154fe1b06903054a22dc92ScriptComponent_fb9fe4dbdd154fe1b06903054a22dc92{847A3FAF-382D-40A4-82C6-A332349A05EC}]]>CozyRoc.SqlServer.SSIS.ScriptComponentHostPlus, CozyRoc.SSISPlus.2014, Version=1.0.0.0, Culture=neutral, PublicKeyToken=16cf490bb80c34eaScriptComponent_fb9fe4dbdd154fe1b06903054a22dc92VisualBasic