Esempio n. 1
0
        private void AppendProcessNode(ProcessDetailTN node, ProcessDetail pd, int depth)
        {
            depth--;
            if (depth < 0)
            {
                return;
            }

            var childNode = new ProcessDetailTN();

            childNode.Text              = pd.Name;
            childNode.Id                = pd.Id;
            childNode.Category          = pd.Category;
            childNode.Type              = pd.Type;
            childNode.PrimaryEntityName = pd.PrimaryEntityName;

            node.Nodes.Add(childNode);
            childNode.IsVisited = IsComponentVisited(childNode, childNode.Id);

            if (!childNode.IsVisited)
            {
                foreach (var cpd in pd.ChildProcess)
                {
                    AppendProcessNode(childNode, cpd, depth);
                }
            }
        }
        public ProcessDetail GetPluginTypeById(EntityDetail entityDetail, Guid id)
        {
            var pa = entityDetail.PluginAssemblies.Where(x => x.Id == id).FirstOrDefault();

            if (pa == null)
            {
                var pt = Service.Retrieve("plugintype", id, new ColumnSet(new string[] { "name", }));
                pa      = new ProcessDetail();
                pa.Id   = id;
                pa.Name = pt.GetAttributeValueSafe <string>("name");
                pa.Type = ProcessDetail.eTypes.CustomCode;
                entityDetail.PluginAssemblies.Add(pa);
            }
            return(pa);
        }
        public ProcessDetail GetComponentByType(EntityDetail entityDetail, List <ProcessDetail> pdList, int type, Guid id)
        {
            ProcessDetail pd = null;

            switch (type)
            {
            case 29:
                pd = pdList.Where(x => x.Id == id).FirstOrDefault();
                break;

            case 90:
                pd      = GetPluginTypeById(entityDetail, id);
                pd.Type = ProcessDetail.eTypes.CustomCode;
                break;
            }
            return(pd);
        }
        public ProcessDetail CloneMe()
        {
            var newNode = new ProcessDetail()
            {
                Name              = this.Name,
                Id                = this.Id,
                Category          = this.Category,
                Type              = this.Type,
                PrimaryEntityName = this.PrimaryEntityName,
                IsVisited         = this.IsVisited
            };

            foreach (var childNode in this.Nodes)
            {
                if (childNode.Type != eTypes.CustomCode)
                {
                    var newChildNode = childNode.CloneMe();
                    newNode.Nodes.Add(newChildNode);
                }
            }

            return(newNode);
        }
        public List <ProcessDetail> GetPluginsByEntity(EntityDetail entityDetail)
        {
            if (entityDetail == null)
            {
                return(null);
            }
            List <ProcessDetail> processInfo = new List <ProcessDetail>();

            try
            {
                var layoutXml = @"<grid name='plugintype'>
	                        <row>
		                        <cell name='name' width='300' />
		                        <cell name='assemblyname' width='150' />
		                        <cell name='step.rank' width='100' />
		                        <cell name='step.stage' width='100' />
		                        <cell name='step.description' width='200' />
		                        <cell name='step.impersonatinguserid' width='125' />
		                        <cell name='step.sdkmessageid' width='125' />
		                        <cell name='filter.primaryobjecttypecode' width='125' />
                            </row></grid>";

                var fetchXml = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true' no-lock='true' >
                      <entity name='plugintype' >
                        <attribute name='plugintypeid' />
                        <attribute name='assemblyname' />
                        <attribute name='name' />
                        <filter>
                          <condition attribute='componentstate' operator='eq' value='0' />
                        </filter>
                        <link-entity name='sdkmessageprocessingstep' from='plugintypeid' to='plugintypeid' link-type='inner' alias='step' >
                          <attribute name='rank' />
                          <attribute name='stage' />
                          <attribute name='description' />
                          <attribute name='impersonatinguserid' />
                          <attribute name='sdkmessageid' />
                          <filter>
                            <condition attribute='ishidden' operator='eq' value='0' />
                            <condition attribute='iscustomizable' operator='eq' value='1' />
                            <condition attribute='invocationsource' operator='eq' value='0' />
                          </filter>
                          <link-entity name='sdkmessagefilter' from='sdkmessagefilterid' to='sdkmessagefilterid' link-type='outer' alias='filter' >
                            <attribute name='primaryobjecttypecode' />
                            <filter type='and' >
                              <condition attribute='primaryobjecttypecode' operator='in' >
                                <value>0</value>
                                <value>{entityDetail.Metadata.ObjectTypeCode}</value>
                              </condition>
                              <condition attribute='isvisible' operator='eq' value='1' />
                              <condition attribute='componentstate' operator='eq' value='0' />
                            </filter>
                          </link-entity>
                        </link-entity>
                        <link-entity name='pluginassembly' from='pluginassemblyid' to='pluginassemblyid' link-type='inner' alias='assembly' >
                          <filter>
                            <condition attribute='componentstate' operator='eq' value='0' />
                            <condition attribute='iscustomizable' operator='eq' value='1' />
                            <condition attribute='ishidden' operator='eq' value='0' />
                            <condition attribute='ismanaged' operator='eq' value='0' />
                          </filter>
                        </link-entity>
                      </entity>
                    </fetch>";

                var resultXml     = ExecuteFetchXML(fetchXml);
                var isMoreRecords = false;
                var rowList       = Helper.ProcessXML(entityDetail.Metadata, layoutXml, resultXml, out isMoreRecords);
                rowList.ForEach(r =>
                {
                    var rLength                = r.Length;
                    var workflow               = new ProcessDetail();
                    workflow.Category          = ProcessDetail.eCategories.Plugins;
                    workflow.Type              = ProcessDetail.eTypes.CustomCode;
                    workflow.Id                = new Guid(r[rLength - 3].ToStringNullSafe());
                    workflow.Name              = GetName(r, rLength);
                    workflow.PrimaryEntityName = entityDetail.Metadata.LogicalName;

                    processInfo.Add(workflow);
                });
            }
            catch { }
            return(processInfo);
        }
        public List <ProcessDetail> GetWorkflowsByEntity(EntityDetail entityDetail)
        {
            if (entityDetail == null)
            {
                return(null);
            }

            List <ProcessDetail> processInfo = new List <ProcessDetail>();
            QueryExpression      query       = new QueryExpression("workflow");

            query.ColumnSet.AddColumns(new string[] { "mode", "primaryentity", "name", "scope", "statecode", "type",
                                                      "uniquename", "solutionid", "category" });
            query.Criteria.AddCondition("statecode", ConditionOperator.Equal, 1);
            query.Criteria.AddCondition("type", ConditionOperator.Equal, 1);
            query.Criteria.AddCondition("primaryentity", ConditionOperator.Equal, entityDetail.Metadata.LogicalName);

            var wfList = Service.RetrieveMultiple(query);

            foreach (var wf in wfList.Entities)
            {
                var workflow = new ProcessDetail();
                var category = wf.GetAttributeValueSafe <OptionSetValue>("category").Value;
                workflow.Category          = (ProcessDetail.eCategories)category;
                workflow.Type              = ProcessDetail.eTypes.Workflow;
                workflow.Id                = wf.Id;
                workflow.Name              = wf.GetAttributeValueSafe <string>("name");
                workflow.PrimaryEntityName = wf.GetAttributeValueSafe <string>("primaryentity");


                processInfo.Add(workflow);
            }

            processInfo.ForEach(p => {
                var rcList = RetrieveRequiredComponents(p.Id);

                rcList.ForEach(r =>
                {
                    int componentType = r.GetAttributeValueSafe <OptionSetValue>("requiredcomponenttype").Value;
                });

                foreach (var rc in rcList)
                {
                    var cType = rc.GetAttributeValue <OptionSetValue>("requiredcomponenttype").Value;
                    var rcId  = rc.GetAttributeValue <Guid>("requiredcomponentobjectid");

                    if (cType == (int)ProcessDetail.eTypes.Workflow || cType == (int)ProcessDetail.eTypes.CustomCode)
                    {
                        var w = GetComponentByType(entityDetail, processInfo, cType, rcId);
                        if (w != null)
                        {
                            p.ChildProcess.Add(w);
                        }
                    }
                }
            });

            // get plugins info
            var ppInfo = GetPluginsByEntity(entityDetail);

            if (ppInfo != null && ppInfo.Count > 0)
            {
                processInfo.AddRange(ppInfo);
            }

            return(processInfo);
        }