示例#1
0
 private void AddAssembly(PluginAssemblyComponent comp)
 {
     PluginAssemblyComponents.Components.Add(comp);
 }
示例#2
0
        public void LoadFromComponents(List <CrmComponent> components, IOrganizationService service)
        {
            var mainForm = (MainForm)Application.OpenForms[0];

            mainForm.ProgressStart("Loading Components...", 1, 2 * components.Count);

            foreach (var component in components)
            {
                if (component.ComponentType == ComponentType.Entity)
                {
                    RetrieveEntityRequest request = new RetrieveEntityRequest
                    {
                        EntityFilters = EntityFilters.All,
                        MetadataId    = component.ObjectId
                    };

                    RetrieveEntityResponse response = (RetrieveEntityResponse)service.Execute(request);
                    AddEntity(new EntityComponent(component, response.EntityMetadata));
                }
                else if (component.ComponentType == ComponentType.PluginAssembly)
                {
                    var e = service.Retrieve("pluginassembly", component.ObjectId, new ColumnSet(true));

                    var name = e.GetAttributeValue <string>("name");

                    var paComp = new PluginAssemblyComponent(component, e);

                    var qe = new QueryByAttribute("plugintype");
                    qe.ColumnSet = new ColumnSet(true);
                    qe.AddAttributeValue("pluginassemblyid", e.Id);

                    var pts = service.RetrieveMultiple(qe).Entities;

                    var ns = $"{name}.";
                    foreach (var pt in pts)
                    {
                        var typeName = pt.GetAttributeValue <string>("typename")?.Replace(ns, "");

                        paComp.PluginTypeComponents.Add(new PluginTypeComponent(component, pt));
                    }

                    AddAssembly(paComp);
                }
                else if (component.ComponentType == ComponentType.SDKMessageProcessingStep)
                {
                    var e    = service.Retrieve("sdkmessageprocessingstep", component.ObjectId, new ColumnSet(true));
                    var name = e.GetAttributeValue <string>("name");
                }
                else if (component.ComponentType == ComponentType.Workflow)
                {
                    var e    = service.Retrieve("workflow", component.ObjectId, new ColumnSet("asyncautodelete", "uniquename", "subprocess", "description", "inputparameters", "name", "businessprocesstype", "category"));
                    var name = e.GetAttributeValue <string>("name");
                    WorkflowComponents.Components.Add(new WorkflowComponent(component, e));
                }
                else if (component.ComponentType == ComponentType.WebResource)
                {
                    var e    = service.Retrieve("webresource", component.ObjectId, new ColumnSet(true));
                    var name = e.GetAttributeValue <string>("name");
                    WebResourceComponents.Components.Add(new WebResourceComponent(component, e));
                }
                else if (component.ComponentType == ComponentType.Role)
                {
                    var e    = service.Retrieve("role", component.ObjectId, new ColumnSet(true));
                    var name = e.GetAttributeValue <string>("name");
                    SecurityRoleComponents.Components.Add(new SecurityRoleComponent(component, e));
                }
                else if (component.ComponentType == ComponentType.RoutingRule)
                {
                    var e = service.Retrieve("routingrule", component.ObjectId, new ColumnSet(true));
                    RoutingRuleComponents.Components.Add(new RoutingRuleComponent(component, e));
                }
                else if (component.ComponentType == ComponentType.EmailTemplate)
                {
                    var e = service.Retrieve("template", component.ObjectId, new ColumnSet("title", "description", "iscustomizable", "componentstate", "modifiedby", "createdby", "ismanaged", "modifiedon"));
                    EmailTemplateComponents.Components.Add(new EmailTemplateComponent(component, e));
                }
                else if (component.ComponentType == ComponentType.MailMergeTemplate)
                {
                    var e = service.Retrieve("mailmergetemplate", component.ObjectId, new ColumnSet("name", "description", "iscustomizable", "componentstate", "modifiedby", "createdby", "ismanaged", "modifiedon"));
                    MailMergeTemplateComponents.Components.Add(new MailMergeTemplateComponent(component, e));
                }
                else if (component.ComponentType == ComponentType.KBArticleTemplate)
                {
                    var e = service.Retrieve("kbarticletemplate", component.ObjectId, new ColumnSet("title", "description", "iscustomizable", "componentstate", "modifiedby", "createdby", "ismanaged", "modifiedon"));
                    KbArticleTemplateComponents.Components.Add(new KbArticleTemplateComponent(component, e));
                }
                else if (component.ComponentType == ComponentType.ContractTemplate)
                {
                    var e = service.Retrieve("contracttemplate", component.ObjectId, new ColumnSet("name", "description", "iscustomizable", "componentstate", "modifiedby", "createdby", "ismanaged", "modifiedon"));
                    ContractTemplateComponents.Components.Add(new ContractTemplateComponent(component, e));
                }
                else if (component.ComponentType == ComponentType.OptionSet)
                {
                    var optionSetMetabase = Organization.OptionSets.Where(x => x.MetadataId == component.ObjectId).FirstOrDefault <OptionSetMetadataBase>();

                    if (optionSetMetabase != null)
                    {
                        OptionSetComponents.Components.Add(new OptionSetComponent(component, optionSetMetabase));
                    }
                }

                mainForm.ProgressPerformStep();
            }

            foreach (var component in components)
            {
                if (component.ComponentType == ComponentType.Attribute)
                {
                    var rootComponent = components.Where(x => x.Id == component.RootSolutionComponentId).FirstOrDefault <CrmComponent>();
                    AddAttribute(component, rootComponent);
                }
                else if (component.ComponentType == ComponentType.EntityRelationship)
                {
                    var rootComponent = components.Where(x => x.Id == component.RootSolutionComponentId).FirstOrDefault <CrmComponent>();
                    AddManyToOneRelationship(component, rootComponent);
                    AddManyToManyRelationship(component, rootComponent);
                }

                mainForm.ProgressPerformStep();
            }
        }