예제 #1
0
        private void SearchFrm_Load(object sender, EventArgs e)
        {
            var defaultIndex = -1;

            using (var cpm = new CRMProcessExplorerManager(this.service))
            {
                cboViews.Items.Clear();
                var views = cpm.GetSavedQuery(metadata.LogicalName);
                var loop  = 0;
                views.ForEach(v =>
                {
                    if (v.GetAttributeValueSafe <bool>("isdefault") && v.GetAttributeValueSafe <int>("querytype").Equals(4))
                    {
                        defaultIndex = loop;
                    }
                    cboViews.Items.Add(new ViewDetail {
                        Entity = v
                    });
                    loop++;
                });
            }

            cboViews.SelectedIndex = defaultIndex;

            dgvSearch.CellMouseEnter += new System.Windows.Forms.DataGridViewCellEventHandler(dgvSearch_CellMouseEnter);
            dgvSearch.CellMouseLeave += new System.Windows.Forms.DataGridViewCellEventHandler(dgvSearch_CellMouseLeave);
        }
예제 #2
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();
                }
            });
        }
예제 #3
0
        private void FetchEntities()
        {
            cboEntities.Items.Clear();
            WorkAsync(new WorkAsyncInfo
            {
                Message       = "Fetching Entities...",
                AsyncArgument = null,
                Work          = (worker, args) =>
                {
                    using (var cpm = new CRMProcessExplorerManager(this.Service))
                    {
                        args.Result = cpm.GetEntities();
                    }
                },
                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 <EntityMetadata>;
                    if (result != null)
                    {
                        var lst = new List <EntityDetail>();
                        foreach (var em in result)
                        {
                            lst.Add(new EntityDetail(em));
                        }

                        cboEntities.DataSource    = lst.Where(l => !l.DisplayName.Equals("NULL")).ToList();
                        cboEntities.DisplayMember = "Name";

                        cboEntities.SelectedIndex = 0;
                    }
                }
            });
        }
예제 #4
0
        private void btnFetch_Click(object sender, EventArgs e)
        {
            try
            {
                lblInfo.Visible = false;
                dgvSearch.Rows.Clear();
                dgvSearch.Refresh();
                if (txtSearch.Text.Length == 0)
                {
                    txtSearch.Text = "*";
                }
                var searchString = txtSearch.Text.Trim().Replace("*", "%");

                if (cboViews.SelectedItem == null)
                {
                    var dName = metadata.DisplayName.UserLocalizedLabel.Label;
                    MessageBox.Show(this,
                                    $"The entity {dName}, {metadata.LogicalName} is not supported for query!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                var view      = ((ViewDetail)cboViews.SelectedItem).Entity;
                var layoutXml = view["layoutxml"].ToString();

                var fetchXml = view["fetchxml"].ToString();
                var fetchDoc = new XmlDocument();
                fetchDoc.LoadXml(fetchXml);

                var filterNodes = fetchDoc.SelectNodes("fetch/entity/filter");
                if (filterNodes.Count > 0)
                {
                    foreach (XmlNode node in filterNodes)
                    {
                        FilerCondition(node, searchString);
                    }

                    var filterNode = filterNodes[0];
                    var cond       = fetchDoc.CreateElement("condition");
                    cond.SetAttribute("attribute", metadata.PrimaryNameAttribute);
                    cond.SetAttribute("operator", "like");
                    cond.SetAttribute("value", $"{searchString}%");
                    filterNode.AppendChild(cond.Clone());
                }
                else
                {
                    var ele = fetchDoc.CreateElement("filter");
                    ele.SetAttribute("type", "and");
                    var cond = fetchDoc.CreateElement("condition");
                    cond.SetAttribute("attribute", metadata.PrimaryNameAttribute);
                    cond.SetAttribute("operator", "like");
                    cond.SetAttribute("value", $"{searchString}%");
                    ele.AppendChild(cond.Clone());

                    var entityNode = fetchDoc.SelectSingleNode("fetch/entity");
                    entityNode.AppendChild(ele.Clone());
                }

                var resultXml = string.Empty;
                using (var cpm = new CRMProcessExplorerManager(this.service))
                {
                    resultXml = cpm.ExecuteFetchXML(fetchDoc.OuterXml);
                }

                var isMoreRecords = false;
                var rowList       = Helper.ProcessXML(metadata, view["layoutxml"].ToString(), resultXml, out isMoreRecords);
                rowList.ForEach(r =>
                {
                    dgvSearch.Rows.Add(r);
                });

                if (isMoreRecords)
                {
                    lblInfo.Text    = "There are more than 5000 records that match your search! Please refine your search. Showing top 5000 results.";
                    lblInfo.Visible = true;
                    this.Text       = $"Search:- {rowList.Count}+ records";
                }
                else
                {
                    this.Text = $"Search:- {rowList.Count} record(s)";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this,
                                "Error(btnFetch_Click): " + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #5
0
        private void rbDates_CheckedChanged(object sender, EventArgs e)
        {
            if (!rbDates.Checked)
            {
                return;
            }
            if (!IsCheckConnection())
            {
                return;
            }
            ShowHideFilters();

            lblInfo.Visible  = false;
            gbDates.Visible  = true;
            gbRecord.Visible = false;
            dgvMain.Rows.Clear();
            dgvMain.Refresh();

            WorkAsync(new WorkAsyncInfo
            {
                Message       = "Load Info",
                AsyncArgument = null,
                Work          = (worker, args) =>
                {
                    using (var cpm = new CRMProcessExplorerManager(this.Service))
                    {
                        //if (entityDetail == null)
                        //{
                        //    var em = cpm.GetEntities("asyncoperation").FirstOrDefault();
                        //    entityDetail = new EntityDetail(em);
                        //}
                        if (cbOperationType.Items.Count <= 0)
                        {
                            args.Result = cpm.GetStringMap("asyncoperation", "operationtype");
                        }
                    }
                },
                ProgressChanged = (args) =>
                {
                    SetWorkingMessage(args.UserState.ToString());
                },
                PostWorkCallBack = (args) =>
                {
                    if (args.Error != null)
                    {
                        MessageBox.Show(args.Error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    if (cbOperationType.Items.Count <= 0)
                    {
                        var lst = args.Result;
                        cbOperationType.DataSource    = new BindingSource(lst, null);
                        cbOperationType.DisplayMember = "Value";
                        cbOperationType.ValueMember   = "Key";
                    }

                    LoadState();
                    LoadStatus();
                }
            });

            ExecuteMethod(InitilizeDataGridView);
            if (dgvMain.ColumnCount > 0)
            {
                ExecuteMethod(LoadDataGridView);
            }
        }
예제 #6
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;
        }
예제 #7
0
        private void LoadDataGridView()
        {
            lblInfo.Visible = false;
            dgvMain.Rows.Clear();
            dgvMain.Refresh();
            if (rbRecord.Enabled && rbRecord.Checked && (string.IsNullOrEmpty(txtID.Text.Trim()) || txtID.Text.Trim().Equals("GUID here...")))
            {
                return;
            }

            var id = new Guid();

            if (rbRecord.Enabled && rbRecord.Checked && Guid.TryParse(txtID.Text.Trim(), out id))
            {
                if (string.IsNullOrEmpty(txtName.Text) && cboEntities.SelectedItem != null)
                {
                    var md = ((EntityDetail)cboEntities.SelectedItem).Metadata;
                    using (var cpm = new CRMProcessExplorerManager(Service))
                    {
                        var name = string.Empty;
                        if (cpm.GetEntityRecordInfo(md.LogicalName, md.PrimaryNameAttribute, id, out name))
                        {
                            txtName.Text = name;
                        }
                        else
                        {
                            txtID.Text = string.Empty;
                            return;
                        }
                    }
                }
                else if (string.IsNullOrEmpty(txtName.Text) && cboEntities.SelectedItem == null)
                {
                    MessageBox.Show(this, $"Populate the entities and select the entity you want to view the process!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else if (rbRecord.Enabled && rbRecord.Checked && !string.IsNullOrEmpty(txtID.Text.Trim()))
            {
                MessageBox.Show(this, $"Invalid ID: {txtID.Text}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            WorkAsync(new WorkAsyncInfo
            {
                Message       = "Loading Data...",
                AsyncArgument = new List <string>()
                {
                    (rbRecord.Enabled ? txtID.Text.Trim() : ""), dtFrom.Value.ToString("yyyy-MM-dd"), dtTo.Value.ToString("yyyy-MM-dd"),
                    cbOperationType.Enabled && cbOperationType.Items.Count > 0 ? cbOperationType.SelectedValue.ToString() : "-1",
                    cboState.Enabled && cboState.Items.Count > 0? cboState.SelectedValue.ToString(): "-1",
                    cboStatus.Enabled && cboStatus.Items.Count > 0? cboStatus.SelectedValue.ToString() : "-1"
                },
                Work = (worker, args) =>
                {
                    var items = args.Argument as List <string>;

                    // load data
                    var resultXml = string.Empty;
                    using (var cpm = new CRMProcessExplorerManager(Service))
                    {
                        if (rbRecord.Enabled && rbRecord.Checked)
                        {
                            resultXml = cpm.GetProcessesResult(items[0]);
                        }
                        else if (rbDates.Checked && rbPTL.Checked)
                        {
                            resultXml = cpm.GetProcessesResult(null, items[1], items[2], items[5], items[4], items[3]);
                        }
                        else if (rbDates.Checked)
                        {
                            resultXml = cpm.GetProcessesResult(null, items[1], items[2], items[3], items[4], items[5]);
                        }
                    }
                    args.Result = resultXml;
                },
                ProgressChanged = (args) =>
                {
                    SetWorkingMessage(args.UserState.ToString());
                },
                PostWorkCallBack = (args) =>
                {
                    if (args.Error != null)
                    {
                        MessageBox.Show(args.Error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    // load data
                    var resultXml     = args.Result as string;
                    var isMoreRecords = false;
                    var rowList       = Helper.ProcessXML(entityDetail.Metadata, _layoutXml, resultXml, out isMoreRecords);
                    rowList.ForEach(r =>
                    {
                        dgvMain.Rows.Add(r);
                    });

                    if (isMoreRecords)
                    {
                        lblInfo.Text    = "There are more than 5000 records that match your search! Please refine your search. Showing top 5000 results.";
                        lblInfo.Visible = true;
                    }

                    ShowHeader(rowList.Count);
                }
            });
        }