public ProcessDiagram(EntityDetail eDetail, ProcessDetailTN rProcess, string url)
 {
     InitializeComponent();
     entityDetail      = eDetail;
     rootProcess       = rProcess;
     webApplicationUrl = url;
 }
        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);
        }
Esempio n. 3
0
        private void btnWFE_Click(object sender, EventArgs e)
        {
            if (cboEntities.SelectedItem == null || this.Service == null)
            {
                return;
            }

            entityDetail = ((EntityDetail)cboEntities.SelectedItem);
            WorkAsync(new WorkAsyncInfo
            {
                Message       = "Getting Process Info...",
                AsyncArgument = null,
                Work          = (worker, args) =>
                {
                    using (var cpm = new CRMProcessExplorerManager(this.Service))
                    {
                        args.Result = cpm.GetWorkflowsByEntity(entityDetail);
                    }
                },
                ProgressChanged = (args) =>
                {
                    SetWorkingMessage(args.UserState.ToString());
                },
                PostWorkCallBack = (args) =>
                {
                    if (args.Error != null)
                    {
                        MessageBox.Show(args.Error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    var result = args.Result as List <ProcessDetail>;

                    var rootComponent  = new ProcessDetailTN();
                    rootComponent.Type = ProcessDetail.eTypes.Entity;
                    rootComponent.PrimaryEntityName = entityDetail.LogicalName;
                    rootComponent.Text = entityDetail.DisplayName;
                    rootComponent.Id   = entityDetail.Metadata.MetadataId.Value;
                    result.ForEach(pd =>
                    {
                        AppendProcessNode(rootComponent, pd, 6);
                    });
                    _selectedNode = rootComponent;

                    var pdf           = new ProcessDiagram(entityDetail, _selectedNode, this.ConnectionDetail.WebApplicationUrl);
                    pdf.StartPosition = FormStartPosition.CenterParent;
                    pdf.Show();
                }
            });
        }
        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);
        }
Esempio n. 5
0
        private void InitilizeDataGridView()
        {
            lblInfo.Visible = false;

            using (var cpm = new CRMProcessExplorerManager(this.Service))
            {
                if (!QueryEntityInfo.IsBackgroundProcess.HasValue) // Plug-n Trace log
                {
                    if (QueryEntityInfo.TLMetadata == null)
                    {
                        var em = cpm.GetEntities("plugintracelog").FirstOrDefault();
                        QueryEntityInfo.TLMetadata = new EntityDetail(em);
                    }
                    entityDetail = QueryEntityInfo.TLMetadata;
                    _layoutXml   = QueryEntityInfo.TLLayoutXML;
                }
                else if (QueryEntityInfo.IsBackgroundProcess.Value) // background process
                {
                    if (QueryEntityInfo.AOMetadata == null)
                    {
                        var em = cpm.GetEntities("asyncoperation").FirstOrDefault();
                        QueryEntityInfo.AOMetadata = new EntityDetail(em);
                    }
                    entityDetail = QueryEntityInfo.AOMetadata;
                    _layoutXml   = QueryEntityInfo.AOLayoutXML;
                }
                else // real-time process
                {
                    if (QueryEntityInfo.PSMetadata == null)
                    {
                        var em = cpm.GetEntities("processsession").FirstOrDefault();
                        QueryEntityInfo.PSMetadata = new EntityDetail(em);
                    }
                    entityDetail = QueryEntityInfo.PSMetadata;
                    _layoutXml   = QueryEntityInfo.PSLayoutXML;
                }
            }

            dgvMain.Columns.Clear();
            dgvMain.Rows.Clear();
            dgvMain.Refresh();

            var layout = new XmlDocument();

            layout.LoadXml(_layoutXml);

            var cols = layout.SelectNodes("//cell");

            dgvMain.ColumnCount = cols.Count + 4;
            var loop = 0;

            dgvMain.Columns[loop].Name    = "#";
            dgvMain.Columns[loop].Visible = false;
            loop++;
            foreach (XmlNode cell in cols)
            {
                var ch = dgvMain.Columns[loop++];
                try
                {
                    ch.Width = int.Parse(cell.Attributes["width"].Value);
                    if (entityDetail != null && entityDetail.Metadata != null)
                    {
                        ch.Name = entityDetail.Metadata.Attributes.FirstOrDefault(a => a.LogicalName == cell.Attributes["name"].Value).DisplayName.UserLocalizedLabel.Label;
                    }
                }
                catch
                {
                    ch.Name = cell.Attributes["name"].Value;
                }
            }
            // primary id field
            dgvMain.Columns[loop].Name    = entityDetail.Metadata.PrimaryIdAttribute;
            dgvMain.Columns[loop].Visible = false;
            // primary name field
            dgvMain.Columns[++loop].Name  = "pkn";
            dgvMain.Columns[loop].Visible = false;
            // xml field
            dgvMain.Columns[++loop].Name  = "xml";
            dgvMain.Columns[loop].Visible = false;
        }
        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);
        }