Example #1
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;
                    }
                }
            });
        }
Example #2
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;
        }