public void Test_CaseImport() { CrmConnection crmConnection = (CrmConnection)connection.GetConnection(); IOrganizationService service = new OrganizationService(crmConnection); string accountName1 = Guid.NewGuid().ToString(); Entity account = new Entity("account"); account.Attributes.Add("name", accountName1); Guid account1 = service.Create(account); IntegrationTool.Module.WriteToDynamicsCrm.WriteToDynamicsCrmConfiguration writeToCrmConfig = new IntegrationTool.Module.WriteToDynamicsCrm.WriteToDynamicsCrmConfiguration(); writeToCrmConfig.EntityName = "incident"; writeToCrmConfig.PrimaryKeyAttributes.Add("ticketnumber"); writeToCrmConfig.ImportMode = Module.WriteToDynamicsCrm.SDK.Enums.ImportMode.All; writeToCrmConfig.MultipleFoundMode = Module.WriteToDynamicsCrm.SDK.Enums.MultipleFoundMode.All; writeToCrmConfig.Mapping.Add(new IntegrationTool.DataMappingControl.DataMapping() { Source = "CaseID", Target = "ticketnumber" }); writeToCrmConfig.Mapping.Add(new IntegrationTool.DataMappingControl.DataMapping() { Source = "CaseTitle", Target = "title" }); writeToCrmConfig.RelationMapping.Add(new Module.WriteToDynamicsCrm.SDK.RelationMapping() { EntityName = "account", LogicalName = "customerid", Mapping = new List <DataMappingControl.DataMapping>() { new DataMappingControl.DataMapping() { Source = "CompanyName", Target = "name" } } }); writeToCrmConfig.ConfigurationId = Guid.NewGuid(); writeToCrmConfig.SelectedConnectionConfigurationId = Test_Helpers.CRMCONNECTIONID; IDatastore dataObject = DataStoreFactory.GetDatastore(); dataObject.AddColumn(new ColumnMetadata("CaseID")); dataObject.AddColumn(new ColumnMetadata("CaseTitle")); dataObject.AddColumn(new ColumnMetadata("CompanyName")); dataObject.AddData(new object[] { "CA-100", "101 Title", accountName1 }); dataObject.AddData(new object[] { "CA-101", "Anöther Title", null }); dataObject.AddData(new object[] { "CA-102", "A'Title\"chen", accountName1 }); IModule module = Activator.CreateInstance(typeof(WriteToDynamicsCrm)) as IModule; module.SetConfiguration(writeToCrmConfig); ((IDataTarget)module).WriteData(connection, new DummyDatabaseInterface(), dataObject, Test_Helpers.ReportProgressMethod); service.Delete("account", account1); }
public void Test_RelateProductsWithCampaigns() { var defaultUnits = Test_Helpers.GetDefaultUnitGroup(organizationService); Entity campaign = new Entity("campaign"); campaign.Attributes.Add("name", "test prd_cmpgn 1"); Guid campaignId = organizationService.Create(campaign); Entity product = new Entity("product"); product.Attributes.Add("name", "test prd_cmpgn 1"); product.Attributes.Add("productnumber", "prd_cmpgn 1"); product.Attributes.Add("defaultuomscheduleid", new EntityReference("uomschedule", defaultUnits.DefaultUnitGroupId)); product.Attributes.Add("defaultuomid", new EntityReference("uom", defaultUnits.PrimaryUnitId)); product.Attributes.Add("quantitydecimal", 2); Guid productId = organizationService.Create(product); Microsoft.Crm.Sdk.Messages.PublishProductHierarchyRequest publishProduct = new Microsoft.Crm.Sdk.Messages.PublishProductHierarchyRequest(); publishProduct.Target = new EntityReference("product", productId); organizationService.Execute(publishProduct); WriteToDynamicsCrmN2NConfiguration writeToDynamicsCrmN2NConfig = new WriteToDynamicsCrmN2NConfiguration(); writeToDynamicsCrmN2NConfig.MultipleFoundMode = N2NMultipleFoundMode.None; writeToDynamicsCrmN2NConfig.Entity1Name = "campaign"; writeToDynamicsCrmN2NConfig.Entity1Mapping = new List <DataMapping>() { new DataMapping("CampaigName", "name") }; writeToDynamicsCrmN2NConfig.Entity2Name = "product;campaignproduct_association"; writeToDynamicsCrmN2NConfig.Entity2Mapping = new List <DataMapping>() { new DataMapping("ProductNumber", "productnumber") }; writeToDynamicsCrmN2NConfig.ConfigurationId = Guid.NewGuid(); writeToDynamicsCrmN2NConfig.SelectedConnectionConfigurationId = Test_Helpers.CRMCONNECTIONID; IDatastore dataObject = DataStoreFactory.GetDatastore(); dataObject.AddColumn(new ColumnMetadata("CampaigName")); dataObject.AddColumn(new ColumnMetadata("ProductNumber")); dataObject.AddData(new object[] { "test prd_cmpgn 1", "prd_cmpgn 1" }); IModule module = Activator.CreateInstance(typeof(WriteToDynamicsCrmN2N)) as IModule; module.SetConfiguration(writeToDynamicsCrmN2NConfig); ((IDataTarget)module).WriteData(connection, new DummyDatabaseInterface(), dataObject, Test_Helpers.ReportProgressMethod); organizationService.Delete("campaign", campaignId); organizationService.Delete("product", productId); }
private IDatastore GetCompanyDatastore() { IDatastore store = DataStoreFactory.GetDatastore(); store.AddColumn(new ColumnMetadata("CompanyId")); store.AddColumn(new ColumnMetadata("CompanyName")); store.AddColumn(new ColumnMetadata("ContactPerson")); store.AddData(new object [] { 1, "comp 1", 2 }); store.AddData(new object[] { 2, "comp 2", 3 }); return(store); }
public IDatastore GetDatastoreB() { IDatastore store = DataStoreFactory.GetDatastore(); store.AddColumn(new ColumnMetadata("TableBColA")); store.AddColumn(new ColumnMetadata("TableBColB")); store.AddColumn(new ColumnMetadata("TableBFull")); store.AddData(new object[] { "A", "B", "A_B" }); store.AddData(new object[] { "A", null, "A_Null" }); store.AddData(new object[] { "A", "B", "A_B_2" }); return(store); }
private IDatastore GetContactsDatastore() { IDatastore dataObject = DataStoreFactory.GetDatastore(); dataObject.AddColumn(new ColumnMetadata("FirstName")); dataObject.AddColumn(new ColumnMetadata("LastName")); dataObject.AddColumn(new ColumnMetadata("City")); dataObject.AddColumn(new ColumnMetadata("ID")); dataObject.AddData(new object[] { "Peter", "Widmer", "Wettingen", 1001 }); dataObject.AddData(new object[] { "Joachim", "Suter", "Dättwil", 1002 }); return(dataObject); }
private void ExtractTableHeaders(IDatastore datastore, KeyValuePair <string, object> fieldValue) { if (datastore.Metadata.ContainsColumn(fieldValue.Key) == false) { if (fieldValue.Value as FieldUserValue != null || fieldValue.Value as FieldLookupValue != null) { datastore.AddColumn(new ColumnMetadata(fieldValue.Key + "_LookupId")); datastore.AddColumn(new ColumnMetadata(fieldValue.Key + "_LookupValue")); } else { datastore.AddColumn(new ColumnMetadata(fieldValue.Key)); } } }
private IDatastore GetPersonDatastore() { IDatastore store = DataStoreFactory.GetDatastore(); store.AddColumn(new ColumnMetadata("PersonId")); store.AddColumn(new ColumnMetadata("Firstname")); store.AddColumn(new ColumnMetadata("Lastname")); store.AddData(new object[] { 1, "Simon", "Miller" }); store.AddData(new object[] { 2, "Frank", "Houston" }); store.AddData(new object[] { 3, "Jill", "Smith" }); store.AddData(new object[] { 4, "Gregory", "Thomson" }); return(store); }
public void Test_AccountDeletion() { var organizationService = connection.GetConnection() as IOrganizationService; // Create dummy account, which shall be deleted string accountName1 = Guid.NewGuid().ToString(); Entity account = new Entity("account"); account.Attributes.Add("name", accountName1); Guid account1 = organizationService.Create(account); DeleteInDynamicsCrmConfiguration deleteInCrmConfig = new DeleteInDynamicsCrmConfiguration(); deleteInCrmConfig.EntityName = "account"; deleteInCrmConfig.MultipleFoundMode = DeleteInCrmMultipleFoundMode.DeleteAll; deleteInCrmConfig.DeleteMapping.Add(new DataMapping() { Source = "CompanyName", Target = "name" }); IDatastore dataObject = DataStoreFactory.GetDatastore(); dataObject.AddColumn(new ColumnMetadata("CompanyName")); dataObject.AddData(new object[] { accountName1 }); IModule module = Activator.CreateInstance(typeof(DeleteInDynamicsCrm)) as IModule; module.SetConfiguration(deleteInCrmConfig); ((IDataTarget)module).WriteData(connection, new DummyDatabaseInterface(), dataObject, ReportProgressMethod); }
public void LoadData(IConnection connection, IDatastore datastore, ReportProgressMethod reportProgress) { ExcelConnectionObject excelConnection = (ExcelConnectionObject)connection.GetConnection(); ExcelWorksheet worksheet = excelConnection.Worksheet; for (int rowNumber = 1; rowNumber <= worksheet.Dimension.End.Row; rowNumber++) { // If first row, the build MetaData if (rowNumber == 1) { for (int columnNumber = 1; columnNumber <= worksheet.Dimension.End.Column; columnNumber++) { string columnName = worksheet.GetValue(rowNumber, columnNumber).ToString(); datastore.AddColumn(new ColumnMetadata(columnName)); } continue; } // All other rows go to the data object [] rowData = new object [worksheet.Dimension.End.Column]; for (int columnNumber = 1; columnNumber <= worksheet.Dimension.End.Column; columnNumber++) { rowData[columnNumber - 1] = worksheet.GetValue(rowNumber, columnNumber); } datastore.AddData(rowData); if (StatusHelper.MustShowProgress(rowNumber - 1, worksheet.Dimension.End.Row) == true) { reportProgress(new SimpleProgressReport("Loaded " + rowNumber + " of " + worksheet.Dimension.End.Row + " records")); } } }
private void InitializeResultDatastore(IDatastore resultDatastore) { foreach (var outputColumn in this.Configuration.OutputColumns) { string columnName = String.IsNullOrEmpty(outputColumn.ColumnAlias) ? outputColumn.Column.ColumnName : outputColumn.ColumnAlias; resultDatastore.AddColumn(new ColumnMetadata(columnName)); } }
public void Test_RelateContactsWithInvoice() { Entity contact = Test_Helpers.CreateDummyContact(); Guid contactId = organizationService.Create(contact); Entity invoice = Test_Helpers.CreateDummyInvoice(); Guid invoiceId = organizationService.Create(invoice); WriteToDynamicsCrmN2NConfiguration writeToDynamicsCrmN2NConfig = new WriteToDynamicsCrmN2NConfiguration(); writeToDynamicsCrmN2NConfig.MultipleFoundMode = N2NMultipleFoundMode.None; writeToDynamicsCrmN2NConfig.Entity1Name = "contact"; writeToDynamicsCrmN2NConfig.Entity1Mapping = new List <DataMapping>() { new DataMapping("FirstName", "firstname") }; writeToDynamicsCrmN2NConfig.Entity2Name = "invoice;contactinvoices_association"; writeToDynamicsCrmN2NConfig.Entity2Mapping = new List <DataMapping>() { new DataMapping("InvoiceNo", "invoicenumber") }; writeToDynamicsCrmN2NConfig.ConfigurationId = Guid.NewGuid(); writeToDynamicsCrmN2NConfig.SelectedConnectionConfigurationId = Test_Helpers.CRMCONNECTIONID; IDatastore dataObject = DataStoreFactory.GetDatastore(); dataObject.AddColumn(new ColumnMetadata("FirstName")); dataObject.AddColumn(new ColumnMetadata("InvoiceNo")); dataObject.AddData(new object[] { contact["firstname"], invoice["invoicenumber"] }); IModule module = Activator.CreateInstance(typeof(WriteToDynamicsCrmN2N)) as IModule; module.SetConfiguration(writeToDynamicsCrmN2NConfig); ((IDataTarget)module).WriteData(connection, new DummyDatabaseInterface(), dataObject, Test_Helpers.ReportProgressMethod); organizationService.Delete("contact", contactId); organizationService.Delete("invoice", invoiceId); }
private IDatastore GetContactDataStore(string accountName1) { IDatastore dataObject = DataStoreFactory.GetDatastore(); dataObject.AddColumn(new ColumnMetadata("FirstName")); dataObject.AddColumn(new ColumnMetadata("LastName")); dataObject.AddColumn(new ColumnMetadata("City")); dataObject.AddColumn(new ColumnMetadata("ID")); dataObject.AddColumn(new ColumnMetadata("CompanyName")); dataObject.AddColumn(new ColumnMetadata("Status")); dataObject.AddColumn(new ColumnMetadata("Birthdate")); dataObject.AddColumn(new ColumnMetadata("OwnerFirstname")); dataObject.AddColumn(new ColumnMetadata("OwnerLastname")); dataObject.AddData(new object[] { "Peter", "Widmer", "Wettingen", 1001, accountName1, "Active", new DateTime(1980, 06, 23), "James", "Test" }); dataObject.AddData(new object[] { "Joachim 2", "Suter", "Dättwil", 1002, accountName1, "Inactive", new DateTime(2004, 12, 03), "John", "test" }); dataObject.AddData(new object[] { "James", "Brown", "London", 1003, null, "Active", null, null, null }); // Doublekey to test it works too dataObject.AddData(new object[] { "Peter", "Widmer", "Wettingen", 1001, accountName1, "Active", new DateTime(1980, 06, 23), "James", "Test" }); dataObject.AddData(new object[] { "Empty", "City", "", 1004, null, "Active", null, null, null }); return(dataObject); }
public void LoadData(IConnection connection, IDatastore datastore, ReportProgressMethod reportProgress) { var databaseConnection = connection.GetConnection() as SQLiteConnection; if (databaseConnection.State != System.Data.ConnectionState.Open) { databaseConnection.Open(); } var databaseCommand = new SQLiteCommand(Configuration.SqlValue, databaseConnection); var databaseReader = databaseCommand.ExecuteReader(); int counter = 0; while (databaseReader.Read()) { // Read the metadata from the source if (datastore.Count == 0) { for (int i = 0; i < databaseReader.FieldCount; i++) { datastore.AddColumn(new ColumnMetadata(databaseReader.GetName(i))); } } // Add data to the datastore object[] data = new object[databaseReader.FieldCount]; for (int dataIndex = 0; dataIndex < databaseReader.FieldCount; dataIndex++) { data[dataIndex] = databaseReader.GetValue(dataIndex); } datastore.AddData(data); if (StatusHelper.MustShowProgress(counter, -1) == true) { reportProgress(new SimpleProgressReport("Loaded " + (counter + 1) + " records")); } counter++; } databaseConnection.Dispose(); }
public void LoadData(IConnection connection, IDatastore datastore, ReportProgressMethod reportProgress) { using (SqlConnection sqlConnection = connection.GetConnection() as SqlConnection) { sqlConnection.Open(); using (SqlCommand sqlCommand = new SqlCommand(Configuration.SqlValue, sqlConnection)) { using (SqlDataReader reader = sqlCommand.ExecuteReader()) { int counter = 0; while (reader.Read()) { // Read the metadata from the source if (datastore.Count == 0) { for (int i = 0; i < reader.FieldCount; i++) { datastore.AddColumn(new ColumnMetadata(reader.GetName(i))); } } // Add data to the datastore object[] data = new object[reader.FieldCount]; for (int dataIndex = 0; dataIndex < reader.FieldCount; dataIndex++) { data[dataIndex] = reader.GetValue(dataIndex); } datastore.AddData(data); if (StatusHelper.MustShowProgress(counter, -1) == true) { reportProgress(new SimpleProgressReport("Loaded " + (counter + 1) + " records")); } counter++; } } } } }
public static void AddDatarowToDatastore(IDatastore datastore, TransformationLog transformationLog, int sourceRowIndex, XElement row) { datastore.AddData(new object[datastore.Metadata.Columns.Count]); // Copy values from sourcerow to new row for (int i = 0; i < datastore[sourceRowIndex].Length; i++) { datastore[datastore.Count - 1][i] = datastore[sourceRowIndex][i]; } // Add new columns if necessary and fill the values foreach (var column in row.Elements()) { if (datastore.Metadata.Columns.ContainsKey(column.Name.LocalName) == false) { transformationLog.NewColumns.Add(column.Name.LocalName); datastore.AddColumn(new ColumnMetadata(column.Name.LocalName)); } datastore.SetValue(datastore.Count - 1, datastore.Metadata[column.Name.LocalName].ColumnIndex, column.Value); } }
private void FetchXmlEntityCollectionRetrieved(EntityCollection retrievedEntityCollection) { foreach (Entity entity in retrievedEntityCollection.Entities) { foreach (var attribute in entity.Attributes) { if (datastore.Metadata.ContainsColumn(attribute.Key) == false) { datastore.AddColumn(new ColumnMetadata(attribute.Key)); } } object[] data = new object[datastore.Metadata.Columns.Count]; foreach (var attribute in entity.Attributes) { if (attribute.Value as AliasedValue != null) { data[datastore.Metadata[attribute.Key].ColumnIndex] = ((AliasedValue)attribute.Value).Value; } else if (attribute.Value as EntityReference != null) { data[datastore.Metadata[attribute.Key].ColumnIndex] = ((EntityReference)attribute.Value).Id; } else if (attribute.Value as OptionSetValue != null) { data[datastore.Metadata[attribute.Key].ColumnIndex] = ((OptionSetValue)attribute.Value).Value; } else if (attribute.Value as Money != null) { data[datastore.Metadata[attribute.Key].ColumnIndex] = ((Money)attribute.Value).Value; } else { data[datastore.Metadata[attribute.Key].ColumnIndex] = attribute.Value; } } datastore.AddData(data); } }
public void TransformData(IConnection connection, IDatabaseInterface databaseInterface, IDatastore dataObject, ReportProgressMethod reportProgress) { foreach (var transformation in this.Configuration.ColumnConcatenations) { reportProgress(new SimpleProgressReport("Start column-cocatenation")); dataObject.AddColumn(new ColumnMetadata(transformation.OutputColumn)); int leftColumnIndex = dataObject.Metadata.Columns.Values.Where(t => t.ColumnName == transformation.LeftColumn).First().ColumnIndex; int rightColumnIndex = dataObject.Metadata.Columns.Values.Where(t => t.ColumnName == transformation.RightColumn).First().ColumnIndex; string separator = transformation.ColumnSeparation.Replace("\\n", "\n"); for (int i = 0; i < dataObject.Count; i++) { string leftValue = (dataObject[i][leftColumnIndex] == null || dataObject[i][leftColumnIndex] == DBNull.Value) ? "" : dataObject[i][leftColumnIndex].ToString(); string rightValue = (dataObject[i][rightColumnIndex] == null || dataObject[i][rightColumnIndex] == DBNull.Value) ? "" : dataObject[i][rightColumnIndex].ToString(); string concatenatedValue = leftValue + separator + rightValue; dataObject.SetValue(i, dataObject.Metadata.Columns[transformation.OutputColumn].ColumnIndex, concatenatedValue); } reportProgress(new SimpleProgressReport("Finished column concatenation")); } }
public void Test_ContactImport() { CrmConnection crmConnection = (CrmConnection)connection.GetConnection(); IOrganizationService service = new OrganizationService(crmConnection); string accountName1 = Guid.NewGuid().ToString(); Entity account = new Entity("account"); account.Attributes.Add("name", accountName1); Guid account1 = service.Create(account); IntegrationTool.Module.WriteToDynamicsCrm.WriteToDynamicsCrmConfiguration writeToCrmConfig = new IntegrationTool.Module.WriteToDynamicsCrm.WriteToDynamicsCrmConfiguration(); writeToCrmConfig.EntityName = "contact"; writeToCrmConfig.PrimaryKeyAttributes.Add("new_id"); writeToCrmConfig.ImportMode = Module.WriteToDynamicsCrm.SDK.Enums.ImportMode.All; writeToCrmConfig.MultipleFoundMode = Module.WriteToDynamicsCrm.SDK.Enums.MultipleFoundMode.All; writeToCrmConfig.Mapping.Add(new IntegrationTool.DataMappingControl.DataMapping() { Source = "ID", Target = "new_id" }); writeToCrmConfig.Mapping.Add(new IntegrationTool.DataMappingControl.DataMapping() { Source = "FirstName", Target = "firstname" }); writeToCrmConfig.Mapping.Add(new IntegrationTool.DataMappingControl.DataMapping() { Source = "LastName", Target = "lastname" }); writeToCrmConfig.Mapping.Add(new IntegrationTool.DataMappingControl.DataMapping() { Source = "Status", Target = "statuscode" }); writeToCrmConfig.Mapping.Add(new IntegrationTool.DataMappingControl.DataMapping() { Source = "Birthdate", Target = "birthdate" }); writeToCrmConfig.RelationMapping.Add(new Module.WriteToDynamicsCrm.SDK.RelationMapping() { EntityName = "account", LogicalName = "parentcustomerid", Mapping = new List <DataMappingControl.DataMapping>() { new DataMappingControl.DataMapping() { Source = "CompanyName", Target = "name" } } }); writeToCrmConfig.ConfigurationId = Guid.NewGuid(); writeToCrmConfig.SelectedConnectionConfigurationId = Test_Helpers.CRMCONNECTIONID; writeToCrmConfig.PicklistMapping.Add(new Module.WriteToDynamicsCrm.SDK.PicklistMapping() { LogicalName = "statuscode", MappingType = Module.WriteToDynamicsCrm.SDK.Enums.PicklistMappingType.Manual, Mapping = new List <DataMappingControl.DataMapping>() { new DataMappingControl.DataMapping() { Source = "Active", Target = "1" }, new DataMappingControl.DataMapping() { Source = "Inactive", Target = "2" } } }); IDatastore dataObject = DataStoreFactory.GetDatastore(); dataObject.AddColumn(new ColumnMetadata("FirstName")); dataObject.AddColumn(new ColumnMetadata("LastName")); dataObject.AddColumn(new ColumnMetadata("City")); dataObject.AddColumn(new ColumnMetadata("ID")); dataObject.AddColumn(new ColumnMetadata("CompanyName")); dataObject.AddColumn(new ColumnMetadata("Status")); dataObject.AddColumn(new ColumnMetadata("Birthdate")); dataObject.AddData(new object[] { "Peter", "Widmer", "Wettingen", 1001, accountName1, "Active", new DateTime(1980, 06, 23) }); dataObject.AddData(new object[] { "Joachim 2", "Suter", "Dättwil", 1002, accountName1, "Inactive", new DateTime(2004, 12, 03) }); dataObject.AddData(new object[] { "James", "Brown", "London", 1003, null, "Active", null }); // Doublekey to test it works too dataObject.AddData(new object[] { "Peter", "Widmer", "Wettingen", 1001, accountName1, "Active", new DateTime(1980, 06, 23) }); IModule module = Activator.CreateInstance(typeof(WriteToDynamicsCrm)) as IModule; module.SetConfiguration(writeToCrmConfig); ((IDataTarget)module).WriteData(connection, new DummyDatabaseInterface(), dataObject, Test_Helpers.ReportProgressMethod); service.Delete("account", account1); }