/// <summary> /// Fills the list of entities /// </summary> private void FillEntities() { // Displays entities if (entityCache == null) { MessageBox.Show(this, "You are not connected to an organization, so it is not possible to display a list of entities\n\nPlease use menu \"More actions\" to load entities and web resources", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); Close(); } foreach (var emd in entityCache) { if (emd.DisplayName.UserLocalizedLabel != null) { var item = new ListViewItem { Text = emd.DisplayName.UserLocalizedLabel.Label, Tag = emd }; ListViewDelegates.AddItem(lvSelectedEntities, item); } } // Enables controls ListViewDelegates.Sort(lvSelectedEntities); ListViewDelegates.SetEnableState(lvSelectedEntities, true); CommonDelegates.SetEnableState(btnCancel, true); CommonDelegates.SetEnableState(btnValidate, true); }
private void RoleSelectionControlLoad(object sender, EventArgs e) { // Loads roles in the list view control foreach (var role in roles) { var item = new ListViewItem { Text = role["name"].ToString(), Tag = role }; item.SubItems.Add(((EntityReference)role["businessunitid"]).Name); ListViewDelegates.AddItem(lvRoles, item); if (settings != null && settings.SelectedRoles.Count > 0) { if (settings.SelectedRoles.Any(x => x["name"] == role["name"])) { item.Selected = true; } } } lvRoles.Columns[lvRoles.Columns.Count - 1].Width = -2; }
private void FillImageList() { ListViewDelegates.ClearItems(lstWebResources); if (webResourcesImageCache == null || webResourcesImageCache.Count == 0) { webResourcesImageCache = new List <Entity>(); QueryExpression qe = new QueryExpression("webresource"); ConditionExpression ce = new ConditionExpression(); ce.AttributeName = "webresourcetype"; if (requestedType == (int)WebResourceType.Image) { ce.Operator = ConditionOperator.In; ce.Values.AddRange(5, 6, 7); } else { ce.Operator = ConditionOperator.Equal; ce.Values.Add(requestedType); } qe.Criteria.AddCondition(ce); qe.ColumnSet.AllColumns = true; EntityCollection ec = service.RetrieveMultiple(qe); foreach (Entity webresource in ec.Entities) { webResourcesImageCache.Add(webresource); } } foreach (Entity webresource in webResourcesImageCache) { if (requestedType == 11 && webresource.GetAttributeValue <OptionSetValue>("webresourcetype").Value == 11 || requestedType != 11 && webresource.GetAttributeValue <OptionSetValue>("webresourcetype").Value != 11) { ListViewItem item = new ListViewItem(webresource.Contains("displayname") ? webresource["displayname"].ToString() : "N/A"); item.SubItems.Add(webresource["name"].ToString()); item.Tag = webresource; ListViewDelegates.AddItem(lstWebResources, item); } } ListViewDelegates.Sort(lstWebResources); ListViewDelegates.SetEnableState(lstWebResources, true); CommonDelegates.SetEnableState(btnWebResourcePickerCancel, true); CommonDelegates.SetEnableState(btnWebResourcePickerValidate, true); CommonDelegates.SetEnableState(btnNewResource, true); CommonDelegates.SetEnableState(btnRefresh, true); }
private void BwFillViewsDoWork(object sender, DoWorkEventArgs e) { string entityLogicalName = e.Argument.ToString(); List <Entity> viewsList = ViewHelper.RetrieveViews(entityLogicalName, entitiesCache, service); viewsList.AddRange(ViewHelper.RetrieveUserViews(entityLogicalName, entitiesCache, service)); foreach (Entity view in viewsList) { bool display = true; var item = new ListViewItem(view["name"].ToString()); item.Tag = view; display = ShouldDisplayItem(item); if (display) { if (view.Contains("statecode")) { int statecodeValue = ((OptionSetValue)view["statecode"]).Value; switch (statecodeValue) { case ViewHelper.VIEW_STATECODE_ACTIVE: item.SubItems.Add("Active"); break; case ViewHelper.VIEW_STATECODE_INACTIVE: item.SubItems.Add("Inactive"); break; } } // Add view to each list of views (source and target) ListViewItem clonedItem = (ListViewItem)item.Clone(); ListViewDelegates.AddItem(lvSourceViews, item); if (view.Contains("iscustomizable") && ((BooleanManagedProperty)view["iscustomizable"]).Value == false) { clonedItem.ForeColor = Color.Gray; clonedItem.ToolTipText = "This view has not been defined as customizable"; } //ListViewDelegates.AddItem(lvTargetViews, clonedItem); } } }
/// <summary> /// Fills the list of entities /// </summary> private void FillEntities() { // Checks the application cache and load it if needed //if (entityCache == null || entityCache.Count == 0) //{ // entityCache = new List<EntityMetadata>(); // var request = new RetrieveAllEntitiesRequest // { // EntityFilters = EntityFilters.Entity // }; // var response = (RetrieveAllEntitiesResponse)SiteMapEditor.service.Execute(request); // foreach (var emd in response.EntityMetadata) // { // SiteMapEditor.entityCache.Add(emd); // } //} // Displays entities foreach (var emd in entityCache) { if ((emd.IsCustomizable.Value || emd.IsManaged.Value == false) && emd.DisplayName.UserLocalizedLabel != null) { var item = new ListViewItem { Text = emd.DisplayName.UserLocalizedLabel.Label, Tag = emd }; ListViewDelegates.AddItem(lvSelectedEntities, item); } } // Enables controls ListViewDelegates.Sort(lvSelectedEntities); ListViewDelegates.SetEnableState(lvSelectedEntities, true); CommonDelegates.SetEnableState(btnCancel, true); CommonDelegates.SetEnableState(btnValidate, true); }
/// <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); } }
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); } }
public void UpdateFormEventHanders(Entity form, string eventName, List <FormEvent> formEvents) { WorkAsync(new WorkAsyncInfo { Message = "Updating Form " + form.GetAttributeValue <string>("name") + "...", Work = (bw, e) => { try { var manager = new FormManager(Service); manager.UpdateFormEventHandlers(form, eventName, formEvents); bw.ReportProgress(0, string.Format("Publishing entity '{0}'...", form.GetAttributeValue <string>("objecttypecode"))); new FormManager(Service).PublishEntity(form.GetAttributeValue <string>("objecttypecode")); ListViewDelegates.AddItem(lvLogs, new ListViewItem { Text = form.GetAttributeValue <string>("objecttypecode"), SubItems = { new ListViewItem.ListViewSubItem { Text = form.GetAttributeValue <string>("name") }, new ListViewItem.ListViewSubItem { Text = eventName }, new ListViewItem.ListViewSubItem { Text = "Updated!" } }, ForeColor = Color.Green }); } catch (Exception error) { ListViewDelegates.AddItem(lvLogs, new ListViewItem { Text = form.GetAttributeValue <string>("objecttypecode"), SubItems = { new ListViewItem.ListViewSubItem { Text = form.GetAttributeValue <string>("name") }, new ListViewItem.ListViewSubItem { Text = eventName }, new ListViewItem.ListViewSubItem { Text = error.Message } }, ForeColor = Color.Red }); } }, PostWorkCallBack = e => { if (e.Error != null) { MessageBox.Show(ParentForm, "An error occured:" + e.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }, ProgressChanged = e => { SetWorkingMessage(e.UserState.ToString()); } }); }
private void tsbRemoveCheckedScripts_Click(object sender, EventArgs e) { lvLogs.Items.Clear(); var scriptsParam = crmScriptsTreeView1.GetSelectedScripts(); var formsParam = crmForms1.GetSelectedForms(); if (scriptsParam.Count == 0) { MessageBox.Show(ParentForm, "Please select at least one script", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (formsParam.Count == 0) { MessageBox.Show(ParentForm, "Please select at least one form", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } WorkAsync(new WorkAsyncInfo { Message = "Updating forms...", AsyncArgument = new[] { scriptsParam, formsParam }, Work = (bw, evt) => { var argArray = (List <Entity>[])evt.Argument; var scripts = argArray[0]; var forms = argArray[1]; var fManager = new FormManager(Service); bool atLeastOneSuccess = false; bool atLeastOneSuccessForForm = false; foreach (var form in forms) { bw.ReportProgress(0, string.Format("Updating form '{0}' ({1})...", form.GetAttributeValue <string>("name"), form.GetAttributeValue <string>("objecttypecode"))); foreach (var script in scripts) { try { if (fManager.RemoveLibrary(form, script.GetAttributeValue <string>("name"), ParentForm)) { atLeastOneSuccessForForm = true; ListViewDelegates.AddItem(lvLogs, new ListViewItem { Text = form.GetAttributeValue <string>("objecttypecode"), SubItems = { new ListViewItem.ListViewSubItem { Text = form.GetAttributeValue <string>("name") }, new ListViewItem.ListViewSubItem { Text = script.GetAttributeValue <string>("name") }, new ListViewItem.ListViewSubItem { Text = "Removed!" } }, ForeColor = Color.Green }); } else { ListViewDelegates.AddItem(lvLogs, new ListViewItem { Text = form.GetAttributeValue <string>("objecttypecode"), SubItems = { new ListViewItem.ListViewSubItem { Text = form.GetAttributeValue <string>("name") }, new ListViewItem.ListViewSubItem { Text = script.GetAttributeValue <string>("name") }, new ListViewItem.ListViewSubItem { Text = "Canceled!" } }, ForeColor = Color.DarkOrange }); } } catch (Exception error) { ListViewDelegates.AddItem(lvLogs, new ListViewItem { Text = form.GetAttributeValue <string>("objecttypecode"), SubItems = { new ListViewItem.ListViewSubItem { Text = form.GetAttributeValue <string>("name") }, new ListViewItem.ListViewSubItem { Text = script.GetAttributeValue <string>("name") }, new ListViewItem.ListViewSubItem { Text = error.Message } }, ForeColor = Color.Red }); } } if (atLeastOneSuccessForForm) { fManager.UpdateForm(form); atLeastOneSuccess = true; } } if (!atLeastOneSuccess) { return; } foreach (var entitiesToPublish in forms.Select(f => f.GetAttributeValue <string>("objecttypecode")).Distinct()) { bw.ReportProgress(0, string.Format("Publishing entity '{0}'...", entitiesToPublish)); fManager.PublishEntity(entitiesToPublish); } }, PostWorkCallBack = evt => { if (evt.Error != null) { MessageBox.Show(ParentForm, "An error occured:" + evt.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }, ProgressChanged = evt => { SetWorkingMessage(evt.UserState.ToString()); } }); }
private void tsbAddCheckedScripts_Click(object sender, EventArgs e) { lvLogs.Items.Clear(); var scripts = crmScriptsTreeView1.GetSelectedScripts(); var forms = crmForms1.GetSelectedForms(); if (scripts.Count == 0) { MessageBox.Show(ParentForm, "Please select at least one script", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (forms.Count == 0) { MessageBox.Show(ParentForm, "Please select at least one form", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var sod = new ScriptsOrderDialog(scripts, false) { StartPosition = FormStartPosition.CenterParent }; if (sod.ShowDialog(ParentForm) == DialogResult.Cancel) { return; } WorkAsync(new WorkAsyncInfo { Message = "Updating forms...", AsyncArgument = new object[] { sod.Scripts, sod.AddFirst, forms }, Work = (bw, evt) => { var scriptsArg = (List <Entity>)((object[])evt.Argument)[0]; var addFirstArg = (bool)((object[])evt.Argument)[1]; var formsArg = (List <Entity>)((object[])evt.Argument)[2]; var formsUpdated = new HashSet <Entity>(); if (addFirstArg) { scripts.Reverse(); } var fManager = new FormManager(Service); bool atLeastOneSuccess = false; foreach (var form in formsArg) { bw.ReportProgress(0, string.Format("Updating form '{0}' ({1})...", form.GetAttributeValue <string>("name"), form.GetAttributeValue <string>("objecttypecode"))); bool atLeastOneScriptSucess = false; foreach (var script in scriptsArg) { try { fManager.AddLibrary(form, script.GetAttributeValue <string>("name"), addFirstArg); atLeastOneScriptSucess = true; atLeastOneSuccess = true; if (!formsUpdated.Contains(form)) { formsUpdated.Add(form); } ListViewDelegates.AddItem(lvLogs, new ListViewItem { Text = form.GetAttributeValue <string>("objecttypecode"), SubItems = { new ListViewItem.ListViewSubItem { Text = form.GetAttributeValue <string>("name") }, new ListViewItem.ListViewSubItem { Text = script.GetAttributeValue <string>("name") }, new ListViewItem.ListViewSubItem { Text = "Added!" } }, ForeColor = Color.Green }); } catch (Exception error) { ListViewDelegates.AddItem(lvLogs, new ListViewItem { Text = form.GetAttributeValue <string>("objecttypecode"), SubItems = { new ListViewItem.ListViewSubItem { Text = form.GetAttributeValue <string>("name") }, new ListViewItem.ListViewSubItem { Text = script.GetAttributeValue <string>("name") }, new ListViewItem.ListViewSubItem { Text = error.Message } }, ForeColor = Color.Red }); } } if (atLeastOneScriptSucess) { fManager.UpdateForm(form); } } if (!atLeastOneSuccess) { return; } foreach (var entityToPublish in formsUpdated.Select(f => f.GetAttributeValue <string>("objecttypecode")).Distinct()) { bw.ReportProgress(0, string.Format("Publishing entity '{0}'...", entityToPublish)); fManager.PublishEntity(entityToPublish); } }, PostWorkCallBack = evt => { if (evt.Error != null) { MessageBox.Show(ParentForm, "An error occured:" + evt.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }, ProgressChanged = evt => { SetWorkingMessage(evt.UserState.ToString()); } }); }
public void UpdateFormLibraryOrder(Entity form, XmlNode formLibrariesNode) { WorkAsync(new WorkAsyncInfo { Message = "Reordering Libraries For Form " + form.GetAttributeValue <string>("name") + "...", AsyncArgument = new object[] { form, formLibrariesNode }, Work = (bw, e) => { var selectedForm = (Entity)((object[])e.Argument)[0]; try { var node = (XmlNode)((object[])e.Argument)[1]; selectedForm["formxml"] = node.OwnerDocument.OuterXml; Service.Update(selectedForm); bw.ReportProgress(0, string.Format("Publishing entity '{0}'...", selectedForm.GetAttributeValue <string>("objecttypecode"))); new FormManager(Service).PublishEntity(selectedForm.GetAttributeValue <string>("objecttypecode")); ListViewDelegates.AddItem(lvLogs, new ListViewItem { Text = selectedForm.GetAttributeValue <string>("objecttypecode"), SubItems = { new ListViewItem.ListViewSubItem { Text = selectedForm.GetAttributeValue <string>("name") }, new ListViewItem.ListViewSubItem { Text = "Reordering Form Libraries" }, new ListViewItem.ListViewSubItem { Text = "Updated!" } }, ForeColor = Color.Green }); } catch (Exception error) { ListViewDelegates.AddItem(lvLogs, new ListViewItem { Text = selectedForm.GetAttributeValue <string>("objecttypecode"), SubItems = { new ListViewItem.ListViewSubItem { Text = selectedForm.GetAttributeValue <string>("name") }, new ListViewItem.ListViewSubItem { Text = "Reordering Form Libraries" }, new ListViewItem.ListViewSubItem { Text = error.Message } }, ForeColor = Color.Red }); } }, PostWorkCallBack = e => { if (e.Error != null) { MessageBox.Show(ParentForm, "An error occured:" + e.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }, ProgressChanged = e => { SetWorkingMessage(e.UserState.ToString()); } }); }
private void BwFillViewsDoWork(object sender, DoWorkEventArgs e) { string entityLogicalName = e.Argument.ToString(); List <Entity> viewsList = ViewHelper.RetrieveViews(entityLogicalName, entitiesCache, Service); viewsList.AddRange(ViewHelper.RetrieveUserViews(entityLogicalName, entitiesCache, Service)); foreach (Entity view in viewsList) { bool display = true; var item = new ListViewItem(view["name"].ToString()); item.Tag = view; #region Gestion de l'image associée à la vue switch ((int)view["querytype"]) { case ViewHelper.VIEW_BASIC: { if (view.LogicalName == "savedquery") { if ((bool)view["isdefault"]) { item.SubItems.Add("Default public view"); item.ImageIndex = 3; } else { item.SubItems.Add("Public view"); item.ImageIndex = 0; } } else { item.SubItems.Add("User view"); item.ImageIndex = 6; } } break; case ViewHelper.VIEW_ADVANCEDFIND: { item.SubItems.Add("Advanced find view"); item.ImageIndex = 1; } break; case ViewHelper.VIEW_ASSOCIATED: { item.SubItems.Add("Associated view"); item.ImageIndex = 2; } break; case ViewHelper.VIEW_QUICKFIND: { item.SubItems.Add("QuickFind view"); item.ImageIndex = 5; } break; case ViewHelper.VIEW_SEARCH: { item.SubItems.Add("Lookup view"); item.ImageIndex = 4; } break; default: { //item.SubItems.Add(view["name"].ToString()); display = false; } break; } #endregion if (display) { // Add view to each list of views (source and target) ListViewItem clonedItem = (ListViewItem)item.Clone(); ListViewDelegates.AddItem(lvSourceViews, item); if (view.Contains("iscustomizable") && ((BooleanManagedProperty)view["iscustomizable"]).Value == false && view.Contains("ismanaged") && (bool)view["ismanaged"]) { clonedItem.ForeColor = Color.Gray; clonedItem.ToolTipText = "This managed view has not been defined as customizable"; } ListViewDelegates.AddItem(lvTargetViews, clonedItem); } } }
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); } }