Пример #1
0
        public static bool Compare(Image image1, XrmImageContainer image2, string attributes)
        {
            if (image2 == null)
            {
                return(false);
            }

            if (image1.Name != image2.Name)
            {
                return(false);
            }

            if ((int)image1.ImageType != image2.Type)
            {
                return(false);
            }

            var a1 = attributes;
            var a2 = image2.Attributes;

            if (string.IsNullOrWhiteSpace(a1))
            {
                a1 = null;
            }
            if (string.IsNullOrWhiteSpace(a2))
            {
                a2 = null;
            }

            if (a1 != null && a2 == null)
            {
                return(false);
            }
            if (a1 == null && a2 != null)
            {
                return(false);
            }

            if (a1 != null && a2 != null)
            {
                var fa1 = a1.Split(',').OrderBy(x => x).ToArray();
                var fa2 = a2.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);
        }
Пример #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
            });
        }