Exemple #1
0
        public static bool Compare(PluginStep step1, XrmStepContainer step2, string filteringAttributes, string unsecureconfig, string secureconfig)
        {
            if (step2 == null)
            {
                return(false);
            }

            var name1 = step2.Entity;
            var name2 = step1.EntityName;

            if (string.IsNullOrWhiteSpace(name1))
            {
                name1 = string.Empty;
            }
            if (string.IsNullOrWhiteSpace(name2))
            {
                name2 = string.Empty;
            }

            if (name1 == "none")
            {
                name1 = string.Empty;
            }
            if (name2 == "none")
            {
                name2 = string.Empty;
            }

            if (name1 != name2)
            {
                return(false);
            }
            if (step2.Message != step1.MessageName)
            {
                return(false);
            }
            if (step2.Rank != step1.Rank)
            {
                return(false);
            }
            if (step2.Mode != (int)step1.StepMode)
            {
                return(false);
            }
            if (step2.Stage != (int)step1.Stage)
            {
                return(false);
            }

            var unsecureconfig2 = string.IsNullOrWhiteSpace(step2.UnsecureConfig) ? null : step2.UnsecureConfig;
            var unsecureconfig1 = string.IsNullOrWhiteSpace(unsecureconfig) ? null : unsecureconfig;

            if (unsecureconfig2 != unsecureconfig1)
            {
                return(false);
            }

            var secureconfig2 = string.IsNullOrWhiteSpace(step2.SecureConfig) ? null : step2.SecureConfig;
            var secureconfig1 = string.IsNullOrWhiteSpace(secureconfig) ? null : secureconfig;

            if (secureconfig2 != secureconfig1)
            {
                return(false);
            }

            if (filteringAttributes != null && step2.FilteringAttributes == null)
            {
                return(false);
            }
            if (filteringAttributes == null && step2.FilteringAttributes != null)
            {
                return(false);
            }

            if (filteringAttributes != null && step2.FilteringAttributes != null)
            {
                var fa1 = filteringAttributes.Split(',').OrderBy(x => x).ToArray();
                var fa2 = step2.FilteringAttributes.Split(',').OrderBy(x => x).ToArray();

                if (fa1.Length != fa2.Length)
                {
                    return(false);
                }

                for (int i = 0; i < fa1.Length; i++)
                {
                    if (fa1[i] != fa2[i])
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemple #2
0
        public static XrmInstanceConfiguration GetPluginTypesHiearki(EntityReference assemblyRef, IOrganizationService service)
        {
            var assemblyId = assemblyRef.Id;

            var context    = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service);
            var plugintype = (from pt in context.CreateQuery("plugintype")
                              where (Guid)pt["pluginassemblyid"] == assemblyId
                              select pt).ToList();


            var steps1 = (from spt in context.CreateQuery("sdkmessageprocessingstep")
                          join pt in context.CreateQuery("plugintype") on(Guid) spt["plugintypeid"] equals(Guid) pt["plugintypeid"]
                          where (Guid)pt["pluginassemblyid"] == assemblyId && (EntityReference)spt["sdkmessagefilterid"] == null
                          select new { Step = spt, EntityName = string.Empty }).ToList();

            var steps2 = (from spt in context.CreateQuery("sdkmessageprocessingstep")
                          join m in context.CreateQuery("sdkmessagefilter") on(Guid) spt["sdkmessagefilterid"] equals(Guid) m["sdkmessagefilterid"]
                          join pt in context.CreateQuery("plugintype") on(Guid) spt["plugintypeid"] equals(Guid) pt["plugintypeid"]
                          where (Guid)pt["pluginassemblyid"] == assemblyId
                          select new { Step = spt, EntityName = m.GetAttributeValue <string>("primaryobjecttypecode") }).ToList();

            var steps = steps1.Union(steps2).ToList();



            var images = (from img in context.CreateQuery("sdkmessageprocessingstepimage")
                          join spt in context.CreateQuery("sdkmessageprocessingstep") on(Guid) img["sdkmessageprocessingstepid"] equals(Guid) spt["sdkmessageprocessingstepid"]
                          join pt in context.CreateQuery("plugintype") on(Guid) spt["plugintypeid"] equals(Guid) pt["plugintypeid"]
                          where (Guid)pt["pluginassemblyid"] == assemblyId
                          select img).ToList();

            var secureConfigs = (from spt in context.CreateQuery("sdkmessageprocessingstep")
                                 join pt in context.CreateQuery("plugintype") on(Guid) spt["plugintypeid"] equals(Guid) pt["plugintypeid"]
                                 join sc in context.CreateQuery("sdkmessageprocessingstepsecureconfig") on(Guid) spt["sdkmessageprocessingstepsecureconfigid"] equals(Guid) sc["sdkmessageprocessingstepsecureconfigid"]
                                 where (Guid)pt["pluginassemblyid"] == assemblyId
                                 select new
            {
                Step = new {
                    Id = (Guid)spt["sdkmessageprocessingstepid"],
                    SecureConfig = (string)sc["secureconfig"],
                    SecureConfigId = (Guid)sc["sdkmessageprocessingstepsecureconfigid"]
                }
            }).ToList();


            var ptdic = new Collection <XrmPluginTypeContainer>();

            foreach (var pt in plugintype)
            {
                var pluginTypeContainer = new XrmPluginTypeContainer {
                    Name = pt.GetAttributeValue <string>("typename"), Id = pt.Id, Steps = new Collection <XrmStepContainer>()
                };

                var pluginsteps = steps.Where(x => x.Step.GetAttributeValue <EntityReference>("plugintypeid").Id == pt.Id).ToList();
                foreach (var step in pluginsteps)
                {
                    var secureConfig = secureConfigs.Where(x => x.Step.Id == step.Step.Id).FirstOrDefault();

                    var stepContainer = new XrmStepContainer {
                        Name = step.Step.GetAttributeValue <string>("name"),
                        Id   = step.Step.Id, Images = new Collection <XrmImageContainer>(),
                        XrmPluginTypeName   = pt.GetAttributeValue <string>("name"),
                        Entity              = step.EntityName,
                        Message             = step.Step.GetAttributeValue <EntityReference>("sdkmessageid").Name,
                        FilteringAttributes = step.Step.GetAttributeValue <string>("filteringattributes"),
                        Rank           = step.Step.GetAttributeValue <int?>("rank").Value,
                        Mode           = step.Step.GetAttributeValue <OptionSetValue>("mode").Value,
                        Stage          = step.Step.GetAttributeValue <OptionSetValue>("stage").Value,
                        UnsecureConfig = step.Step.GetAttributeValue <string>("configuration"),
                        SecureConfig   = secureConfig != null ? secureConfig.Step.SecureConfig : null,
                        SecureConfigId = secureConfig != null ? (Guid?)secureConfig.Step.SecureConfigId : null
                    };


                    var stepimages = images.Where(x => x.GetAttributeValue <EntityReference>("sdkmessageprocessingstepid").Id == step.Step.Id).ToList();
                    foreach (var image in stepimages)
                    {
                        var imageContainer = new XrmImageContainer {
                            Id                   = image.Id,
                            Name                 = image.GetAttributeValue <string>("name"),
                            Type                 = image.GetAttributeValue <OptionSetValue>("imagetype").Value,
                            Attributes           = image.GetAttributeValue <string>("attributes"),
                            XrmPluginTypeName    = pt.GetAttributeValue <string>("name"),
                            XrmStepContainerName = step.Step.GetAttributeValue <string>("name"),
                        };
                        stepContainer.Images.Add(imageContainer);
                    }
                    pluginTypeContainer.Steps.Add(stepContainer);
                }
                ptdic.Add(pluginTypeContainer);
            }

            return(new XrmInstanceConfiguration {
                PluginTypes = ptdic, AssemblyRef = assemblyRef
            });
        }