Ejemplo n.º 1
0
        public void Export(string entityLogicalName)
        {
            Log.Debug($"Exporting data {entityLogicalName}");

            var strategy = entityStrategyFactory.Create(entityLogicalName);

            var data = crmService.GetEntities(strategy.QueryExpressionForEntitiesList);

            var jsonContent = data.Select(new EntityAndJsonConverter(strategy).ToJson).ToList();

            fileService.WriteData(entityLogicalName, jsonContent);
            Log.Debug($"Finished data {entityLogicalName}");
        }
Ejemplo n.º 2
0
        public void Import(CrmCommandsQueue requestsQueue, string entityLogicalName)
        {
            Log.Debug($"Importing {entityLogicalName}");

            var strategy  = entityStrategyFactory.Create(entityLogicalName);
            var converter = new EntityAndJsonConverter(strategy);

            var dataFileContent = fileService.ReadData(entityLogicalName);

            var jsonEntities   = dataFileContent.Select(converter.ToEntity).ToList();
            var crmEntities    = crmService.GetEntities(strategy.QueryExpressionForEntitiesList);
            var equalityColumn = strategy.EqualityColumn;

            foreach (var dataEntity in jsonEntities)
            {
                var currentDataEntity = crmEntities.FirstOrDefault(x => Equals(x[equalityColumn], dataEntity[equalityColumn]));

                var diff = new Dictionary <string, object>();

                foreach (var key in dataEntity.Attributes.Keys)
                {
                    var    dataAttribute    = dataEntity[key];
                    object currentAttribute = null;

                    if (currentDataEntity?.Contains(key) == true)
                    {
                        currentAttribute = currentDataEntity[key];
                    }

                    if (!Equals(currentAttribute, dataAttribute))
                    {
                        diff[key] = dataAttribute;
                    }
                }

                if (diff.Any())
                {
                    strategy.OnUpsertEntityRecord(requestsQueue, currentDataEntity, dataEntity, diff);
                }
            }

            var excessRows = crmEntities.Where(x => !jsonEntities.Any(y => Equals(x[equalityColumn], y[equalityColumn]))).ToList();

            foreach (var excessRow in excessRows)
            {
                strategy.OnDeleteEntityRecord(requestsQueue, excessRow);
            }
            Log.Debug($"Finished importing {entityLogicalName}");
        }
        public DisabledWorkflowsScope(ICrmService crmService, IEnumerable <string> entityLogicalnames)
        {
            this.crmService = crmService;

            var entityLogicalnamesArray = entityLogicalnames.ToArray();

            if (entityLogicalnamesArray.Any())
            {
                workflows.AddRange(crmService.GetEntities(new QueryExpression("sdkmessageprocessingstep")
                {
                    LinkEntities =
                    {
                        new LinkEntity("sdkmessageprocessingstep",                   "sdkmessagefilter",       "sdkmessagefilterid", "sdkmessagefilterid", JoinOperator.Inner)
                        {
                            Columns      = new ColumnSet("secondaryobjecttypecode",  "primaryobjecttypecode"),
                            LinkCriteria = new FilterExpression(LogicalOperator.And)
                            {
                                Conditions =
                                {
                                    new ConditionExpression("primaryobjecttypecode", ConditionOperator.In,
                                                            entityLogicalnamesArray)
                                }
                            }
                        }
                    },
                    ColumnSet = new ColumnSet("name", "statuscode", "statecode"),
                    Criteria  = new FilterExpression(LogicalOperator.And)
                    {
                        Conditions =
                        {
                            new ConditionExpression("statuscode", ConditionOperator.Equal, 1), // active only
                            new ConditionExpression("ishidden",   ConditionOperator.Equal, false)
                        }
                    }
                }));

                workflows.AddRange(crmService.GetEntities(new QueryExpression("workflow")
                {
                    ColumnSet = new ColumnSet("primaryentity", "type", "statecode", "statuscode", "name", "triggeronupdateattributelist", "triggeroncreate", "triggerondelete"),
                    Criteria  = new FilterExpression(LogicalOperator.And)
                    {
                        Conditions =
                        {
                            new ConditionExpression("primaryentity", ConditionOperator.In,    entityLogicalnamesArray),
                            new ConditionExpression("statuscode",    ConditionOperator.Equal,                       1), // active only
                            new ConditionExpression("type",          ConditionOperator.Equal,                       1), // activation only (no old snapshots)
                        },
                        Filters =
                        {
                            new FilterExpression(LogicalOperator.Or)
                            {
                                Conditions =
                                {
                                    new ConditionExpression("triggeronupdateattributelist", ConditionOperator.NotNull),
                                    new ConditionExpression("triggeroncreate",              ConditionOperator.Equal,   true),
                                    new ConditionExpression("triggerondelete",              ConditionOperator.Equal,   true)
                                }
                            }
                        }
                    }
                }));
            }
            Disable();
        }