예제 #1
0
        private void GeneratePluginSdkMessageImage(RetrievePluginTypes retrievePluginTypes, Guid pluginstepId, ref XmlNode images, ref XmlDocument xmlDoc, IOrganizationService service)
        {
            EntityCollection imageColl = retrievePluginTypes.GetSdkProcessingStepImage(pluginstepId, service);

            foreach (Entity sdkstepImage in imageColl.Entities)
            {
                XmlNode image = xmlDoc.CreateElement("Image");
                images.AppendChild(image);

                XmlAttribute attributes = xmlDoc.CreateAttribute("Attributes");
                attributes.Value = sdkstepImage.Attributes.Contains("attributes") ? sdkstepImage["attributes"].ToString() : "All";
                image.Attributes.Append(attributes);

                XmlAttribute entityAlias = xmlDoc.CreateAttribute("EntityAlias");
                entityAlias.Value = sdkstepImage["entityalias"].ToString();
                image.Attributes.Append(entityAlias);

                XmlAttribute name = xmlDoc.CreateAttribute("Name");
                name.Value = sdkstepImage["name"].ToString();
                image.Attributes.Append(name);

                XmlAttribute id = xmlDoc.CreateAttribute("Id");
                id.Value = sdkstepImage.Id.ToString();
                image.Attributes.Append(id);

                XmlAttribute messagePropertyName = xmlDoc.CreateAttribute("MessagePropertyName");
                messagePropertyName.Value = sdkstepImage["messagepropertyname"].ToString();
                image.Attributes.Append(messagePropertyName);

                XmlAttribute imageType = xmlDoc.CreateAttribute("ImageType");
                imageType.Value = ((OptionSetValue)sdkstepImage["imagetype"]).Value.ToString();
                image.Attributes.Append(imageType);
            }
        }
예제 #2
0
        public void UnRegisterPluginTypes(Guid pluginAssemblyId, IOrganizationService service)
        {
            RetrievePluginTypes retrievePluginTypes = new RetrievePluginTypes();
            EntityCollection    pluginTypesColl     = retrievePluginTypes.GetPluginTypes(pluginAssemblyId, service);

            foreach (Entity pluginTypeEntity in pluginTypesColl.Entities)
            {
                EntityCollection pluginStepsColl = retrievePluginTypes.GetSdkProcessingStep(pluginTypeEntity.Id, service);
                foreach (Entity pluginStep in pluginStepsColl.Entities)
                {
                    EntityCollection stepImageColl = retrievePluginTypes.GetSdkProcessingStepImage(pluginStep.Id, service);
                    foreach (Entity stepImage in stepImageColl.Entities)
                    {
                        service.Delete(stepImage.LogicalName, stepImage.Id);
                    }
                    service.Delete(pluginStep.LogicalName, pluginStep.Id);
                }
                service.Delete(pluginTypeEntity.LogicalName, pluginTypeEntity.Id);
            }
        }
예제 #3
0
        private void GeneratePluginSdkMessageProcessingStep(RetrievePluginTypes retrievePluginTypes, Guid pluginTypeId, ref XmlNode steps, ref XmlDocument xmlDoc, IOrganizationService service)
        {
            EntityCollection stepsColl = retrievePluginTypes.GetSdkProcessingStep(pluginTypeId, service);

            foreach (Entity sdkstep in stepsColl.Entities)
            {
                try
                {
                    XmlNode step = xmlDoc.CreateElement("Step");
                    steps.AppendChild(step);
                    XmlAttribute stepname = xmlDoc.CreateAttribute("Name");
                    stepname.Value = sdkstep["name"].ToString();
                    step.Attributes.Append(stepname);
                    XmlAttribute stepDescription = xmlDoc.CreateAttribute("Description");
                    if (sdkstep.Attributes.Contains("description") && sdkstep["description"] != null)
                    {
                        stepDescription.Value = sdkstep["description"].ToString();
                    }
                    else
                    {
                        stepDescription.Value = sdkstep["name"].ToString();
                    }
                    step.Attributes.Append(stepDescription);
                    XmlAttribute stepId = xmlDoc.CreateAttribute("Id");
                    stepId.Value = sdkstep.Id.ToString();
                    step.Attributes.Append(stepId);
                    if (sdkstep.Attributes.Contains("filteringattributes"))
                    {
                        XmlAttribute filteringAttributes = xmlDoc.CreateAttribute("FilteringAttributes");
                        filteringAttributes.Value = sdkstep["filteringattributes"].ToString();
                        step.Attributes.Append(filteringAttributes);
                    }
                    XmlAttribute sdkstepMode = xmlDoc.CreateAttribute("Mode");
                    sdkstepMode.Value = sdkstep["mode"].ToString();
                    step.Attributes.Append(sdkstepMode);
                    EntityReference sdkmessageRef    = (EntityReference)sdkstep["sdkmessageid"];
                    Entity          sdkmessageEntity = service.Retrieve(sdkmessageRef.LogicalName, sdkmessageRef.Id, new ColumnSet("name"));
                    XmlAttribute    sdkmessage       = xmlDoc.CreateAttribute("MessageName");
                    sdkmessage.Value = sdkmessageEntity["name"].ToString();
                    step.Attributes.Append(sdkmessage);
                    XmlAttribute mode = xmlDoc.CreateAttribute("Mode");
                    mode.Value = ((OptionSetValue)sdkstep["mode"]).Value.ToString();
                    step.Attributes.Append(mode);
                    XmlAttribute rank = xmlDoc.CreateAttribute("Rank");
                    rank.Value = sdkstep["rank"].ToString();
                    step.Attributes.Append(rank);
                    XmlAttribute stage = xmlDoc.CreateAttribute("Stage");
                    stage.Value = ((OptionSetValue)sdkstep["stage"]).Value.ToString();
                    step.Attributes.Append(stage);
                    XmlAttribute supporteddeployment = xmlDoc.CreateAttribute("SupportedDeployment");
                    supporteddeployment.Value = ((OptionSetValue)sdkstep["supporteddeployment"]).Value.ToString();
                    step.Attributes.Append(supporteddeployment);
                    //sdkmessage filter
                    XmlAttribute primaryentity = xmlDoc.CreateAttribute("PrimaryEntityName");
                    if (sdkstep.Attributes.Contains("sdkmessagefilterid") && sdkstep["sdkmessagefilterid"] != null)
                    {
                        EntityReference sdkmessageFilterRef    = (EntityReference)sdkstep["sdkmessagefilterid"];
                        Entity          sdkmessageFilterEntity = service.Retrieve(sdkmessageFilterRef.LogicalName, sdkmessageFilterRef.Id, new ColumnSet("primaryobjecttypecode", "sdkmessageid"));
                        primaryentity.Value = sdkmessageFilterEntity["primaryobjecttypecode"].ToString();
                    }
                    else
                    {
                        primaryentity.Value = "none";
                    }
                    step.Attributes.Append(primaryentity);

                    //Images
                    XmlNode Images = xmlDoc.CreateElement("Images");
                    step.AppendChild(Images);
                    GeneratePluginSdkMessageImage(retrievePluginTypes, sdkstep.Id, ref Images, ref xmlDoc, service);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
예제 #4
0
        public void GeneratePluginOrWorkflowTypes(bool isWorkflowActivity, List <Entity> pluginTypesColl, ref XmlNode solution, ref XmlDocument xmlDoc, IOrganizationService service)
        {
            RetrievePluginTypes retrievePluginTypes = new RetrievePluginTypes();
            XmlNode             pluginTypes;

            if (!isWorkflowActivity)
            {
                pluginTypes = xmlDoc.CreateElement("PluginTypes");
                solution.AppendChild(pluginTypes);
            }
            else
            {
                pluginTypes = xmlDoc.CreateElement("WorkflowTypes");
                solution.AppendChild(pluginTypes);
            }
            foreach (Entity pluginType in pluginTypesColl)
            {
                XmlNode pluginTypeNode = null;
                if (!isWorkflowActivity)
                {
                    pluginTypeNode = xmlDoc.CreateElement("Plugin");
                }
                else
                {
                    pluginTypeNode = xmlDoc.CreateElement("WorkflowType");
                    XmlAttribute workflowactivitygroupname = xmlDoc.CreateAttribute("WorkflowActivityGroupName");
                    workflowactivitygroupname.Value = pluginType["workflowactivitygroupname"].ToString();
                    pluginTypeNode.Attributes.Append(workflowactivitygroupname);
                }

                pluginTypes.AppendChild(pluginTypeNode);

                if (pluginType.Attributes.Contains("description"))
                {
                    XmlAttribute description = xmlDoc.CreateAttribute("Description");
                    description.Value = pluginType["description"].ToString();
                    pluginTypeNode.Attributes.Append(description);
                }

                XmlAttribute friendlyname = xmlDoc.CreateAttribute("friendlyname");
                friendlyname.Value = pluginType["friendlyname"].ToString();
                pluginTypeNode.Attributes.Append(friendlyname);
                XmlAttribute name = xmlDoc.CreateAttribute("Name");
                name.Value = pluginType["name"].ToString();
                pluginTypeNode.Attributes.Append(name);
                XmlAttribute plugintypeId = xmlDoc.CreateAttribute("Id");
                plugintypeId.Value = pluginType.Id.ToString();
                pluginTypeNode.Attributes.Append(plugintypeId);
                XmlAttribute typeName = xmlDoc.CreateAttribute("TypeName");
                typeName.Value = pluginType["typename"].ToString();
                pluginTypeNode.Attributes.Append(typeName);

                if (!isWorkflowActivity)
                {
                    //Steps
                    XmlNode steps = xmlDoc.CreateElement("Steps");
                    pluginTypeNode.AppendChild(steps);
                    GeneratePluginSdkMessageProcessingStep(retrievePluginTypes, pluginType.Id, ref steps, ref xmlDoc, service);
                }
            }
        }
예제 #5
0
        public void RegisterPluginsFromXml(string registrationXmlPath, string pluginsDllFilePath, IOrganizationService service)
        {
            RetrievePluginTypes retrievePluginTypes = new RetrievePluginTypes();
            string      strPluginDllName            = Path.GetFileName(pluginsDllFilePath);
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(registrationXmlPath);
            XmlNodeList xnList = xmlDoc.DocumentElement.SelectNodes("/Register/Solutions/Solution[@Assembly='" + strPluginDllName + "']");

            foreach (XmlElement node in xnList)
            {
                var id = node.GetAttribute("Id");
                UnRegisterPlugins unregisterPlugins = new UnRegisterPlugins();
                Console.WriteLine("Unregistering the plugin assembly: " + strPluginDllName);
                unregisterPlugins.UnRegisterPluginTypes(new Guid(id), service);
                var    sourceType     = Convert.ToInt32(node.GetAttribute("SourceType").ToString());
                var    isolationMode  = Convert.ToInt32(node.GetAttribute("IsolationMode").ToString());
                Entity pluginAssembly = new Entity("pluginassembly", new Guid(id));
                pluginAssembly["isolationmode"] = new OptionSetValue(isolationMode);
                pluginAssembly["sourcetype"]    = new OptionSetValue(sourceType);
                pluginAssembly["content"]       = Convert.ToBase64String(File.ReadAllBytes(pluginsDllFilePath));
                UpsertRequest upsertpluginAssemblyRequest = new UpsertRequest();
                upsertpluginAssemblyRequest.Target = pluginAssembly;
                UpsertResponse upsertPluginAssemblyResponse = (UpsertResponse)service.Execute(upsertpluginAssemblyRequest);
                node.Attributes["Id"].Value = upsertPluginAssemblyResponse.Target.Id.ToString();
                pluginAssembly.Id           = upsertPluginAssemblyResponse.Target.Id;
                XmlNodeList workflowTypeList = node.SelectNodes("WorkflowTypes/WorkflowType");
                foreach (XmlElement workflowType in workflowTypeList)
                {
                    Guid workflowTypeId = RegisterWorkflowTypes(new EntityReference(pluginAssembly.LogicalName, upsertPluginAssemblyResponse.Target.Id), workflowType, service);
                    workflowType.Attributes["Id"].Value = workflowTypeId.ToString();
                }

                XmlNodeList pluginTypeList = node.SelectNodes("PluginTypes/Plugin");
                foreach (XmlElement pluginType in pluginTypeList)
                {
                    Console.WriteLine("Registering the plugin type: " + pluginType.GetAttribute("TypeName"));
                    Entity pluginTypeEntity = new Entity("plugintype", new Guid(pluginType.GetAttribute("Id")));
                    pluginTypeEntity["typename"]         = pluginType.GetAttribute("TypeName");
                    pluginTypeEntity["friendlyname"]     = pluginType.GetAttribute("friendlyname");
                    pluginTypeEntity["name"]             = pluginType.GetAttribute("Name");
                    pluginTypeEntity["pluginassemblyid"] = new EntityReference(pluginAssembly.LogicalName, pluginAssembly.Id);
                    UpsertRequest upsertPluginTypeRequest = new UpsertRequest();
                    upsertPluginTypeRequest.Target = pluginTypeEntity;
                    UpsertResponse upsertPluginTypeResponse = (UpsertResponse)service.Execute(upsertPluginTypeRequest);
                    if (upsertPluginTypeResponse.RecordCreated)
                    {
                        pluginType.Attributes["Id"].Value = upsertPluginTypeResponse.Target.Id.ToString();
                    }

                    XmlNodeList sdksteps = pluginType.SelectNodes("Steps/Step");
                    foreach (XmlElement sdkmessageStepNode in sdksteps)
                    {
                        Console.WriteLine("Registering the sdk step: " + sdkmessageStepNode.GetAttribute("Name"));
                        Entity sdkmessageProcessingStep = new Entity("sdkmessageprocessingstep", new Guid(sdkmessageStepNode.GetAttribute("Id")));
                        sdkmessageProcessingStep["name"]        = sdkmessageStepNode.GetAttribute("Name");
                        sdkmessageProcessingStep["description"] = sdkmessageStepNode.GetAttribute("Description");
                        Guid messageId = retrievePluginTypes.GetSdkMessageId(sdkmessageStepNode.GetAttribute("MessageName"), service);
                        sdkmessageProcessingStep["sdkmessageid"]        = new EntityReference("sdkmessage", messageId);
                        sdkmessageProcessingStep["plugintypeid"]        = new EntityReference("plugintype", upsertPluginTypeResponse.Target.Id);
                        sdkmessageProcessingStep["mode"]                = new OptionSetValue(Convert.ToInt32(sdkmessageStepNode.GetAttribute("Mode")));  //0=sync,1=async
                        sdkmessageProcessingStep["rank"]                = Convert.ToInt32(sdkmessageStepNode.GetAttribute("Rank"));
                        sdkmessageProcessingStep["stage"]               = new OptionSetValue(Convert.ToInt32(sdkmessageStepNode.GetAttribute("Stage"))); //10-preValidation, 20-preOperation, 40-PostOperation
                        sdkmessageProcessingStep["supporteddeployment"] = new OptionSetValue(Convert.ToInt32(sdkmessageStepNode.GetAttribute("SupportedDeployment")));
                        Guid messageFitlerId = retrievePluginTypes.GetSdkMessageFilterId(sdkmessageStepNode.GetAttribute("PrimaryEntityName"), messageId, service);
                        sdkmessageProcessingStep["sdkmessagefilterid"] = new EntityReference("sdkmessagefilter", messageFitlerId);
                        UpsertRequest upsertPluginStepsRequest = new UpsertRequest();
                        upsertPluginStepsRequest.Target = sdkmessageProcessingStep;
                        UpsertResponse upsertPluginStepResponse = (UpsertResponse)service.Execute(upsertPluginStepsRequest);
                        if (upsertPluginStepResponse.RecordCreated)
                        {
                            sdkmessageStepNode.Attributes["Id"].Value = upsertPluginStepResponse.Target.Id.ToString();
                        }

                        string      messageName   = sdkmessageStepNode.GetAttribute("MessageName");
                        XmlNodeList sdkstepImages = sdkmessageStepNode.SelectNodes("Images/Image");
                        foreach (XmlElement sdkstepImageNode in sdkstepImages)
                        {
                            Guid createdImageId = CreateSdkImage(upsertPluginStepResponse.Target.Id, sdkstepImageNode, messageName, service);
                            if (createdImageId != Guid.Empty)
                            {
                                sdkstepImageNode.Attributes["Id"].Value = createdImageId.ToString();
                            }
                        }
                    }
                }
            }

            xmlDoc.Save(registrationXmlPath);
        }