Beispiel #1
0
        public void Test_ContactImport()
        {
            var accountName1 = Guid.NewGuid().ToString();
            var account      = new Entity("account");

            account.Attributes.Add("name", accountName1);
            Guid account1 = organizationService.Create(account);


            // FIRST RUN
            var writeToCrmConfig = GetContactImportConfiguration();

            IDatastore contactDatastore = GetContactDataStore(accountName1);
            IModule    module           = Activator.CreateInstance(typeof(WriteToDynamicsCrm)) as IModule;

            module.SetConfiguration(writeToCrmConfig);

            ((IDataTarget)module).WriteData(connection, new DummyDatabaseInterface(), contactDatastore, Test_Helpers.ReportProgressMethod);

            var contactsId1001 = Crm2013Wrapper.RetrieveMultiple(organizationService, "contact", new ColumnSet(true), new ConditionExpression("new_id", ConditionOperator.Equal, "1001"));

            Assert.AreEqual(1, contactsId1001.Count);
            var contact1001 = contactsId1001.First();

            Assert.AreEqual("James Test", ((EntityReference)contact1001["ownerid"]).Name);

            // SECOND RUN
            writeToCrmConfig.ImportMode   = ImportMode.AllChangedValuesOnly;
            writeToCrmConfig.SetOwnerMode = ImportMode.AllChangedValuesOnly;
            contactDatastore.SetValue(0, 2, "Baden");
            contactDatastore.SetValue(0, 7, "John");
            contactDatastore.SetValue(0, 8, "test");
            contactDatastore.SetValue(3, 7, "John");
            contactDatastore.SetValue(3, 8, "test");
            contactDatastore.AddData(new object[] { "Thomas", "Meyer", "New York", 1004, accountName1, "Active", new DateTime(1973, 04, 24), "James", "Test" });

            ((IDataTarget)module).WriteData(connection, new DummyDatabaseInterface(), contactDatastore, Test_Helpers.ReportProgressMethod);

            var contactsId1004 = Crm2013Wrapper.RetrieveMultiple(organizationService, "contact", new ColumnSet(true), new ConditionExpression("new_id", ConditionOperator.Equal, "1004"));

            Assert.AreEqual(1, contactsId1004.Count);

            contactsId1001 = Crm2013Wrapper.RetrieveMultiple(organizationService, "contact", new ColumnSet(true), new ConditionExpression("new_id", ConditionOperator.Equal, "1001"));
            Assert.AreEqual(1, contactsId1001.Count);
            contact1001 = contactsId1001.First();
            Assert.AreEqual("John test", ((EntityReference)contact1001["ownerid"]).Name);

            organizationService.Delete("account", account1);
        }
Beispiel #2
0
        public void TransformData(IConnection connection, IDatabaseInterface databaseInterface, IDatastore dataObject, ReportProgressMethod reportProgress)
        {
            Dictionary <StringTransformationType, Type> stringTransformationMapping = Helpers.LoadAllTransformationTypes();

            foreach (var transformation in this.Configuration.Transformations)
            {
                reportProgress(new SimpleProgressReport("Start stringtranformation of type " + transformation.TransformationType + " on column " + transformation.ColumnName));

                if (dataObject.Metadata.Columns.Values.Where(t => t.ColumnName == transformation.ColumnName).Count() == 0)
                {
                    throw new Exception("Column " + transformation.ColumnName + " was not found in the sourcedata");
                }

                int columnIndex = dataObject.Metadata.Columns[transformation.ColumnName].ColumnIndex;
                ITransformationExecutor transformer = Activator.CreateInstance(stringTransformationMapping[transformation.TransformationType]) as ITransformationExecutor;

                for (int i = 0; i < dataObject.Count; i++)
                {
                    string transformedValue = transformer.ExecuteTransformation(dataObject[i][columnIndex].ToString(), transformation);
                    dataObject.SetValue(i, columnIndex, transformedValue);
                }

                reportProgress(new SimpleProgressReport("Finished stringtranformation of type " + transformation.TransformationType + " on column " + transformation.ColumnName));
            }
        }
Beispiel #3
0
        public static TransformationLog TransformToDatastore(IDatastore datastore, string xslTransformation, string columnToTransform, bool isRunFromPreview)
        {
            TransformationLog transformationLog = new TransformationLog();

            if (datastore.Count <= 0)
            {
                return(transformationLog);
            }

            int columnIndex = datastore.Metadata.Columns[columnToTransform].ColumnIndex;
            int rowCount    = datastore.Count; // Rowcount increases while adding data, therefore it must be fixed here!

            // Transform xml to table?
            string transformedXml = TransformXml(datastore[0][columnIndex].ToString(), xslTransformation);

            if (Regex.IsMatch(transformedXml, @"<\?xml.*\?>.*\n<it_table>"))
            {
                for (int sourceRowIndex = 0; sourceRowIndex < rowCount; sourceRowIndex++)
                {
                    transformedXml = TransformXml(datastore[sourceRowIndex][columnIndex].ToString(), xslTransformation);
                    XDocument xDocument = XDocument.Parse(transformedXml, LoadOptions.PreserveWhitespace);

                    foreach (var row in xDocument.Root.Elements("it_row"))
                    {
                        AddDatarowToDatastore(datastore, transformationLog, sourceRowIndex, row);
                    }
                }

                // Remove transformed rows
                if (isRunFromPreview == false)
                {
                    for (int rowIndex = rowCount - 1; rowIndex >= 0; rowIndex--)
                    {
                        datastore.RemoveDataAt(rowIndex);
                    }
                    datastore.RemoveColumn(datastore.Metadata.Columns.Where(t => t.Value.ColumnIndex == columnIndex).First().Value.ColumnName);
                }
                else
                {
                    for (int rowIndex = rowCount - 1; rowIndex >= 0; rowIndex--)
                    {
                        transformationLog.RowNumbersToHide.Add(rowIndex);
                    }
                }
            }
            else
            {
                for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
                {
                    datastore.SetValue(rowIndex, columnIndex, TransformXml(datastore[rowIndex][columnIndex].ToString(), xslTransformation));
                }
            }

            return(transformationLog);
        }
Beispiel #4
0
        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);
            }
        }
        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"));
            }
        }