Esempio n. 1
0
        private void LoadEntities()
        {
            txtSearchEntity.Text = string.Empty;
            lvEntities.Items.Clear();
            gbEntities.Enabled       = false;
            tsbPublishEntity.Enabled = false;
            tsbPublishAll.Enabled    = false;
            tsbSaveViews.Enabled     = false;

            lvSourceViews.Items.Clear();
            lvTargetViews.Items.Clear();
            lvSourceViewLayoutPreview.Columns.Clear();

            WorkAsync(new WorkAsyncInfo
            {
                Message = "Loading entities...",
                Work    = (bw, e) =>
                {
                    e.Result = MetadataHelper.RetrieveEntities(Service);
                },
                PostWorkCallBack = e =>
                {
                    if (e.Error != null)
                    {
                        string errorMessage = CrmExceptionHelper.GetErrorMessage(e.Error, true);
                        CommonDelegates.DisplayMessageBox(ParentForm, errorMessage, "Error", MessageBoxButtons.OK,
                                                          MessageBoxIcon.Error);
                    }
                    else
                    {
                        entitiesCache = (List <EntityMetadata>)e.Result;
                        lvEntities.Items.Clear();
                        var list = new List <ListViewItem>();
                        foreach (EntityMetadata emd in (List <EntityMetadata>)e.Result)
                        {
                            var item = new ListViewItem {
                                Text = emd.DisplayName.UserLocalizedLabel.Label, Tag = emd.LogicalName
                            };
                            item.SubItems.Add(emd.LogicalName);
                            list.Add(item);
                        }

                        this.listViewItemsCache = list.ToArray();
                        lvEntities.Items.AddRange(listViewItemsCache);

                        gbEntities.Enabled       = true;
                        tsbPublishEntity.Enabled = true;
                        tsbPublishAll.Enabled    = true;
                        tsbSaveViews.Enabled     = true;
                    }
                }
            });
        }
        private void LoadEntities()
        {
            fetchXml = string.Empty;
            lvEntities.Items.Clear();
            gbEntities.Enabled      = false;
            tsbLoadEntities.Enabled = false;
            tsbRefresh.Enabled      = false;
            tsbExportExcel.Enabled  = false;
            tsbEditInFxb.Enabled    = false;
            lvViews.Items.Clear();
            txtFetchXml.Text = "";
            WorkAsync(new WorkAsyncInfo("Loading entities...", e =>
            {
                e.Result = MetadataHelper.RetrieveEntities(Service);
            })
            {
                PostWorkCallBack = completedargs =>
                {
                    if (completedargs.Error != null)
                    {
                        string errorMessage = CrmExceptionHelper.GetErrorMessage(completedargs.Error, true);
                        CommonDelegates.DisplayMessageBox(ParentForm, errorMessage, "Error", MessageBoxButtons.OK,
                                                          MessageBoxIcon.Error);
                    }
                    else
                    {
                        entitiesCache = (List <EntityMetadata>)completedargs.Result;
                        lvEntities.Items.Clear();
                        var list = new List <ListViewItem>();
                        foreach (EntityMetadata emd in (List <EntityMetadata>)completedargs.Result)
                        {
                            var item = new ListViewItem {
                                Text = emd.DisplayName.UserLocalizedLabel.Label, Tag = emd.LogicalName
                            };
                            item.SubItems.Add(emd.LogicalName);
                            list.Add(item);
                        }

                        lvEntities.Items.AddRange(list.ToArray());
                        lvEntities.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                        gbEntities.Enabled      = true;
                        gbEntities.Enabled      = true;
                        tsbLoadEntities.Enabled = true;
                        tsbRefresh.Enabled      = true;
                    }
                }
            });
        }
Esempio n. 3
0
        private void BwFillEntitiesRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                string errorMessage = CrmExceptionHelper.GetErrorMessage(e.Error, true);
                CommonDelegates.DisplayMessageBox(ParentForm, errorMessage, "Error", MessageBoxButtons.OK,
                                                  MessageBoxIcon.Error);
            }
            else
            {
                gbEntities.Enabled       = true;
                tsbPublishEntity.Enabled = true;
                tsbPublishAll.Enabled    = true;
            }

            Controls.Remove(informationPanel);
            CommonDelegates.SetCursor(this, Cursors.Default);
        }
Esempio n. 4
0
        private void BwTransferViewsDoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                List <Entity> checkedViews = new List <Entity>();

                foreach (ListViewItem item in ListViewDelegates.GetSelectedItems(lvSourceViews))
                {
                    checkedViews.Add((Entity)item.Tag);
                }

                e.Result = ViewHelper.TransferViews(checkedViews, service, targetService, _savedQueryMetadata);
            }
            catch (Exception error)
            {
                CommonDelegates.DisplayMessageBox(ParentForm, error.Message, "Error", MessageBoxButtons.OK,
                                                  MessageBoxIcon.Error);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Fills the entities listview
        /// </summary>
        public void FillEntitiesList()
        {
            try
            {
                ListViewDelegates.ClearItems(lvEntities);

                foreach (EntityMetadata emd in entitiesCache)
                {
                    var item = new ListViewItem {
                        Text = emd.DisplayName.UserLocalizedLabel.Label, Tag = emd.LogicalName
                    };
                    item.SubItems.Add(emd.LogicalName);
                    ListViewDelegates.AddItem(lvEntities, item);
                }
            }
            catch (Exception error)
            {
                string errorMessage = CrmExceptionHelper.GetErrorMessage(error, true);
                CommonDelegates.DisplayMessageBox(ParentForm, errorMessage, "Error", MessageBoxButtons.OK,
                                                  MessageBoxIcon.Error);
            }
        }
Esempio n. 6
0
        private void FillList()
        {
            try
            {
                ListViewDelegates.ClearItems(lstSolutions);

                EntityCollection ec = RetrieveSolutions();

                foreach (Entity solution in ec.Entities)
                {
                    ListViewItem item = new ListViewItem(solution["friendlyname"].ToString());
                    item.SubItems.Add(solution["version"].ToString());
                    item.SubItems.Add(((EntityReference)solution["publisherid"]).Name);
                    item.Tag = solution;

                    ListViewDelegates.AddItem(lstSolutions, item);
                }
            }
            catch (Exception error)
            {
                CommonDelegates.DisplayMessageBox(this, error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        void WorkerDoWork(object sender, DoWorkEventArgs e)
        {
            var worker = (BackgroundWorker)sender;

            foreach (var role in settings.SelectedRoles)
            {
                try
                {
                    worker.ReportProgress(1, string.Format("Retrieving privileges set for role \"{0}\"...", role["name"]));
                    var rolePrivileges = rManager.GetPrivilegesForRole(role.Id);

                    foreach (var pAction in settings.Actions)
                    {
                        if (pAction.Level == PrivilegeLevel.None)
                        {
                            worker.ReportProgress(1, string.Format("Removing privilege \"{0}\" from role \"{1}\"...", pAction.PrivilegeName, role["name"]));
                            rManager.RemovePrivilegeFromRole(rolePrivileges, pAction.PrivilegeId);
                        }
                        else
                        {
                            worker.ReportProgress(1, string.Format("Adding/Updating privilege \"{0}\" in role \"{1}\"...", pAction.PrivilegeName, role["name"]));
                            rManager.AddPrivilegeToRole(rolePrivileges, pAction);
                        }
                    }

                    worker.ReportProgress(1, string.Format("Replacing privileges set for role \"{0}\"...", role["name"]));
                    rManager.ApplyChanges(rolePrivileges, role.Id);
                }
                catch (Exception error)
                {
                    CommonDelegates.DisplayMessageBox(ParentForm,
                                                      "Error while updating role " + role["name"] + ": " + error.Message,
                                                      "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Esempio n. 8
0
        private void BwDisplayViewDoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (ListViewDelegates.GetSelectedItems(lvSourceViews).Count() > 1)
                {
                    ColumnHeader header = new ColumnHeader();
                    header.Width = 380;
                    header.Text  = "Layout preview cannot be displayed when multiple views are selected.";
                    ListViewDelegates.AddColumn(lvSourceViewLayoutPreview, header);
                }
                else
                {
                    // Gets current view data
                    Entity currentSelectedView = (Entity)ListViewDelegates.GetSelectedItems(lvSourceViews)[0].Tag;
                    string layoutXml           = currentSelectedView["layoutxml"].ToString();
                    string fetchXml            = currentSelectedView.Contains("fetchxml")
                                          ? currentSelectedView["fetchxml"].ToString()
                                          : string.Empty;
                    string currentEntityDisplayName = ListViewDelegates.GetSelectedItems(lvEntities)[0].Text;

                    EntityMetadata currentEmd =
                        entitiesCache.Find(
                            delegate(EntityMetadata emd)
                            { return(emd.DisplayName.UserLocalizedLabel.Label == currentEntityDisplayName); });

                    XmlDocument layoutDoc = new XmlDocument();
                    layoutDoc.LoadXml(layoutXml);

                    EntityMetadata emdWithItems = MetadataHelper.RetrieveEntity(currentEmd.LogicalName, service);

                    ListViewItem item = new ListViewItem();

                    foreach (XmlNode columnNode in layoutDoc.SelectNodes("grid/row/cell"))
                    {
                        ColumnHeader header = new ColumnHeader();

                        header.Text = MetadataHelper.RetrieveAttributeDisplayName(emdWithItems,
                                                                                  columnNode.Attributes["name"].Value,
                                                                                  fetchXml, service);

                        int columnWidth = columnNode.Attributes["width"] == null ? 0 : int.Parse(columnNode.Attributes["width"].Value);

                        header.Width = columnWidth;

                        ListViewDelegates.AddColumn(lvSourceViewLayoutPreview, header);

                        if (string.IsNullOrEmpty(item.Text))
                        {
                            item.Text = columnWidth == 0 ? "(undefined)": (columnWidth + "px");
                        }
                        else
                        {
                            item.SubItems.Add(columnWidth == 0 ? "(undefined)": (columnWidth + "px"));
                        }
                    }

                    ListViewDelegates.AddItem(lvSourceViewLayoutPreview, item);

                    GroupBoxDelegates.SetEnableState(gbSourceViewLayout, true);
                }
            }
            catch (Exception error)
            {
                CommonDelegates.DisplayMessageBox(ParentForm, "Error while displaying view: " + error.Message, "Error",
                                                  MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }