private string CreateCsvLine(CrmEntityStore record, List <string> header)
        {
            if (record != null)
            {
                string[] items = new string[header.Count];
                items[0] = record.Id.ToString();
                foreach (var item in record.Attributes)
                {
                    int position = header.IndexOf(item.AttributeName);

                    if (position >= 0)
                    {
                        object attrValue = EntityConverterHelper.GetAttributeValueForCsv(item);
                        if (item.AttributeType == "System.String")
                        {
                            string atVal = attrValue?.ToString().Replace("\"", "\"\"");
                            items[position] = $"\"{atVal}\"";
                        }
                        else
                        {
                            items[position] = attrValue?.ToString();
                        }
                    }
                }

                return(string.Join(delimiter, items));
            }

            return(null);
        }
Exemple #2
0
        public void ConvertEntities()
        {
            var entityName = "account";
            var guidList   = new List <Guid>();
            var entitylist = new List <CrmEntityStore>();

            for (int i = 0; i < 5; i++)
            {
                var id = Guid.NewGuid();
                guidList.Add(id);
                entitylist.Add(new CrmEntityStore(new Entity(entityName, id)));
            }

            var actual = EntityConverterHelper.ConvertEntities(entitylist);

            actual.Count.Should().Be(entitylist.Count);

            for (int i = 0; i < 5; i++)
            {
                var           id   = guidList[i];
                EntityWrapper item = null;
                FluentActions.Invoking(() => item = actual.First(a => a.Id.ToString() == id.ToString()))
                .Should()
                .NotThrow();

                item.LogicalName.Should().Be(entityName);
            }
        }
Exemple #3
0
        public void GetAttributeValueFromCsvOptionSetValue()
        {
            string itemType   = "optionsetvalue";
            string lookUpType = string.Empty;
            object input      = 5;

            var actual = (OptionSetValue)EntityConverterHelper.GetAttributeValueFromCsv(itemType, lookUpType, input);

            actual.Value.Should().Be(5);
        }
Exemple #4
0
        public void GetAttributeValueFromCsvString()
        {
            string itemType   = "string";
            string lookUpType = string.Empty;
            object input      = "Joe";

            var actual = EntityConverterHelper.GetAttributeValueFromCsv(itemType, lookUpType, input);

            actual.ToString().Should().Be("Joe");
        }
Exemple #5
0
        public void GetAttributeValueFromCsv()
        {
            string itemType   = "integer";
            string lookUpType = string.Empty;
            object input      = 5;

            var actual = (int)EntityConverterHelper.GetAttributeValueFromCsv(itemType, lookUpType, input);

            actual.Should().Be(5);
        }
Exemple #6
0
        public void GetAttributeValueFromCsvNullInput()
        {
            string itemType   = string.Empty;
            string lookUpType = string.Empty;
            object input      = null;

            var actual = EntityConverterHelper.GetAttributeValueFromCsv(itemType, lookUpType, input);

            actual.Should().BeNull();
        }
Exemple #7
0
        public void GetAttributeValueForCsvEntityReference()
        {
            var input = new EntityReference("contact", Guid.NewGuid());
            CrmAttributeStore attribute = new CrmAttributeStore(new KeyValuePair <string, object>("firstname", input))
            {
                AttributeType = "Microsoft.Xrm.Sdk.EntityReference"
            };

            var actual = EntityConverterHelper.GetAttributeValueForCsv(attribute);

            actual.ToString().Should().Be(input.Id.ToString());
        }
Exemple #8
0
        public void GetAttributeValueForCsvOptionSetValue()
        {
            var input = new OptionSetValue(12);
            CrmAttributeStore attribute = new CrmAttributeStore(new KeyValuePair <string, object>("firstname", input))
            {
                AttributeType = "Microsoft.Xrm.Sdk.OptionSetValue"
            };

            var actual = EntityConverterHelper.GetAttributeValueForCsv(attribute);

            actual.ToString().Should().Be(input.Value.ToString(CultureInfo.InvariantCulture));
        }
Exemple #9
0
        public void GetAttributeValueForCsvMoney()
        {
            var input     = new Money(new decimal(12.00));
            var attribute = new CrmAttributeStore(new KeyValuePair <string, object>("firstname", input))
            {
                AttributeType = "Microsoft.Xrm.Sdk.Money"
            };

            var actual = EntityConverterHelper.GetAttributeValueForCsv(attribute);

            actual.Should().Be(input.Value);
        }
Exemple #10
0
        public void GetAttributeValueForCsvByte()
        {
            byte[] input     = new byte[5];
            var    attribute = new CrmAttributeStore(new KeyValuePair <string, object>("firstname", input))
            {
                AttributeType = "System.Byte[]"
            };

            FluentActions.Invoking(() => EntityConverterHelper.GetAttributeValueForCsv(attribute))
            .Should()
            .Throw <ConfigurationException>();
        }
Exemple #11
0
        public void GetAttributeValueForCsvAliasedValue()
        {
            var input     = new AliasedValue("contact", "contactid", Guid.NewGuid().ToString());
            var attribute = new CrmAttributeStore(new KeyValuePair <string, object>("firstname", input))
            {
                AttributeType = "Microsoft.Xrm.Sdk.AliasedValue"
            };

            var actual = EntityConverterHelper.GetAttributeValueForCsv(attribute);

            actual.Should().Be(input.Value);
        }
Exemple #12
0
        public void GetAttributeValueFromCsvEntityreference()
        {
            var    id         = Guid.NewGuid();
            var    entityName = "account";
            string itemType   = "entityreference";
            string lookUpType = entityName;
            object input      = id;

            var actual = (EntityReference)EntityConverterHelper.GetAttributeValueFromCsv(itemType, lookUpType, input);

            actual.Id.ToString().Should().Be(id.ToString());
            actual.LogicalName.Should().Be(entityName);
        }
Exemple #13
0
        public void GetAttributeValueForCsvEntityCollection()
        {
            var list = new List <Entity>
            {
                new Entity("account", Guid.NewGuid())
            };
            EntityCollection input = new EntityCollection(list);
            var attribute          = new CrmAttributeStore(new KeyValuePair <string, object>("firstname", input))
            {
                AttributeType = "Microsoft.Xrm.Sdk.EntityCollection"
            };

            FluentActions.Invoking(() => EntityConverterHelper.GetAttributeValueForCsv(attribute))
            .Should()
            .Throw <ConfigurationException>();
        }
Exemple #14
0
        public void GetAttributeValueForCsvOptionSetValueCollection()
        {
            var list = new List <OptionSetValue>
            {
                new OptionSetValue(12),
                new OptionSetValue(3)
            };
            var input     = new OptionSetValueCollection(list);
            var attribute = new CrmAttributeStore(new KeyValuePair <string, object>("firstname", input))
            {
                AttributeType = "Microsoft.Xrm.Sdk.OptionSetValueCollection"
            };

            var actual = EntityConverterHelper.GetAttributeValueForCsv(attribute);

            actual.Should().Be("12|3");
        }
Exemple #15
0
        public void ConvertAttributes()
        {
            var attributes = new List <CrmAttributeStore>
            {
                new CrmAttributeStore(new KeyValuePair <string, object>("firstname", "Joe")),
                new CrmAttributeStore(new KeyValuePair <string, object>("lastname", "Blogs"))
            };

            var actual = EntityConverterHelper.ConvertAttributes(attributes);

            FluentActions.Invoking(() => actual.Single(a => a.Key == "firstname" && a.Value.ToString() == "Joe"))
            .Should()
            .NotThrow();
            FluentActions.Invoking(() => actual.Single(a => a.Key == "lastname" && a.Value.ToString() == "Blogs"))
            .Should()
            .NotThrow();
            actual.Count.Should().Be(attributes.Count);
        }
Exemple #16
0
        public void GetAttributeValueFromCsvOptionSetValueCollection()
        {
            string itemType   = "optionsetvaluecollection";
            string lookUpType = string.Empty;
            object input      = "3|13|5";

            var actual = (OptionSetValueCollection)EntityConverterHelper.GetAttributeValueFromCsv(itemType, lookUpType, input);

            actual.Count.Should().Be(3);
            FluentActions.Invoking(() => actual.Single(a => a.Value == 13))
            .Should()
            .NotThrow();
            FluentActions.Invoking(() => actual.Single(a => a.Value == 3))
            .Should()
            .NotThrow();
            FluentActions.Invoking(() => actual.Single(a => a.Value == 5))
            .Should()
            .NotThrow();
        }
Exemple #17
0
        public static void Config()
        {
            var builder = new ContainerBuilder();

            // Get your HttpConfiguration.
            var config = GlobalConfiguration.Configuration;

            // Register your Web API controllers.
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            // OPTIONAL: Register the Autofac filter provider.
            builder.RegisterWebApiFilterProvider(config);

            // Configure the DatabaseFactory to read its configuration from the .config file
            DatabaseProviderFactory factory = new DatabaseProviderFactory();
            Database database = factory.Create("DataBase");

            builder.Register <Database>(c => database).InstancePerLifetimeScope();

            // Configure for Repositories on Data Access Layer(DAL)
            builder.RegisterType <Repository>().As <IRepository>().InstancePerApiRequest();
            builder.RegisterType <PatientRepository>().As <IPatientRepository>().InstancePerApiRequest();
            builder.RegisterType <StudyRepository>().As <IStudyRepository>().InstancePerApiRequest();

            // Configure for Business Services on Business Logic Layer(BLL)
            builder.RegisterType <EntityService>().As <IEntityService>().InstancePerApiRequest();
            builder.RegisterType <PatientService>().As <IPatientService>().InstancePerApiRequest();
            builder.RegisterType <StudyService>().As <IStudyService>().InstancePerApiRequest();
            builder.RegisterType <ChecksumService>().As <IChecksumService>().InstancePerApiRequest();

            EntityConverterHelper entityConverterHelper = new EntityConverterHelper();

            builder.Register <EntityConverterHelper>(c => entityConverterHelper).InstancePerLifetimeScope();

            // Set the dependency resolver to be Autofac.
            var container = builder.Build();

            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
Exemple #18
0
        public List <EntityWrapper> ReadBatchDataFromStore()
        {
            currentBatchNo++;

            logger.LogVerbose($"DataFileStoreReader ReadBatchDataFromStore started, batchNo:{currentBatchNo}");

            try
            {
                var dataStore = ReadCrmExportedDataStore(currentBatchNo);

                if (dataStore != null)
                {
                    return(EntityConverterHelper.ConvertEntities(dataStore.ExportedEntities));
                }

                return(new List <EntityWrapper>());
            }
            finally
            {
                logger.LogVerbose($"DataFileStoreReader ReadBatchDataFromStore finsihed, batchNo:{currentBatchNo}");
            }
        }
Exemple #19
0
        public void GetAttributeTypeForCsvGuid()
        {
            var actual = EntityConverterHelper.GetAttributeTypeForCsv("guid");

            Assert.AreEqual(typeof(Guid), actual);
        }
Exemple #20
0
        public void GetAttributeTypeForCsvEntityreference()
        {
            var actual = EntityConverterHelper.GetAttributeTypeForCsv("entityreference");

            Assert.AreEqual(typeof(Guid), actual);
        }
Exemple #21
0
        public void GetAttributeTypeForCsvDouble()
        {
            var actual = EntityConverterHelper.GetAttributeTypeForCsv("double");

            Assert.AreEqual(typeof(double), actual);
        }
Exemple #22
0
        public void GetAttributeTypeForCsvOptionSetValue()
        {
            var actual = EntityConverterHelper.GetAttributeTypeForCsv("optionsetvalue");

            Assert.AreEqual(typeof(int), actual);
        }
Exemple #23
0
        public void GetAttributeTypeForCsvOptionSetValueCollection()
        {
            var actual = EntityConverterHelper.GetAttributeTypeForCsv("optionsetvaluecollection");

            Assert.AreEqual(typeof(string), actual);
        }
Exemple #24
0
        public void GetAttributeTypeForCsvBool()
        {
            var actual = EntityConverterHelper.GetAttributeTypeForCsv("bool");

            Assert.AreEqual(typeof(bool), actual);
        }
Exemple #25
0
 public void GetAttributeTypeForCsvUnSupported()
 {
     FluentActions.Invoking(() => EntityConverterHelper.GetAttributeTypeForCsv("float"))
     .Should()
     .Throw <ConfigurationException>();
 }
Exemple #26
0
        public void GetAttributeTypeForCsvString()
        {
            var actual = EntityConverterHelper.GetAttributeTypeForCsv("string");

            Assert.AreEqual(typeof(string), actual);
        }
Exemple #27
0
        public void GetAttributeTypeForCsvInteger()
        {
            var actual = EntityConverterHelper.GetAttributeTypeForCsv("integer");

            Assert.AreEqual(typeof(int), actual);
        }
 public StudyController(IStudyService StudyService, IChecksumService checksumService, EntityConverterHelper entityConverterHelper)
 {
     _StudyService          = StudyService;
     _checksumService       = checksumService;
     _entityConverterHelper = entityConverterHelper;
 }
Exemple #29
0
        public void GetAttributeTypeForCsvDecimal()
        {
            var actual = EntityConverterHelper.GetAttributeTypeForCsv("decimal");

            Assert.AreEqual(typeof(decimal), actual);
        }
 public PatientController(IPatientService patientService, IChecksumService checksumService, EntityConverterHelper entityConverterHelper)
 {
     _patientService        = patientService;
     _checksumService       = checksumService;
     _entityConverterHelper = entityConverterHelper;
 }