public CrmForm(Entity form) { var emd = entitiesMetadatas.ToList().First(e => e.LogicalName == form.GetAttributeValue<string>("objecttypecode")); this.form = form; Name = form.GetAttributeValue<string>("name"); EntityLogicalName = form.GetAttributeValue<string>("objecttypecode"); EntityDisplayName = emd.DisplayName != null ? emd.DisplayName.UserLocalizedLabel.Label : "N/A"; Id = form.Id; ListParameters(); }
public static int UpdateRank(IOrganizationService service, Entity workflow) { var wf = service.Retrieve("workflow", workflow.Id, new ColumnSet("statecode")); if (wf.GetAttributeValue<OptionSetValue>("statecode").Value != 0) { service.Execute(new SetStateRequest { EntityMoniker = wf.ToEntityReference(), State = new OptionSetValue(0), Status = new OptionSetValue(-1) }); } workflow.Attributes.Remove("statecode"); workflow.Attributes.Remove("statuscode"); service.Update(workflow); if (wf.GetAttributeValue<OptionSetValue>("statecode").Value != 0) { service.Execute(new SetStateRequest { EntityMoniker = wf.ToEntityReference(), State = new OptionSetValue(1), Status = new OptionSetValue(-1) }); } return workflow.GetAttributeValue<int>("rank"); }
internal object GetAliasedValue(Entity entry, string attributeName) { if (!entry.Attributes.Contains(attributeName)) return null; var aliasedValue = entry.GetAttributeValue<AliasedValue>(attributeName); if (aliasedValue == null) return null; var entityReferenceValue = aliasedValue.Value as EntityReference; return entityReferenceValue != null ? entityReferenceValue.Id : aliasedValue.Value; }
public FormInfo(Entity form) { if (form.LogicalName != "systemform") { throw new ArgumentException("Only systemform entity can be used in FormInfo", "form"); } this.form = form; formXml = new XmlDocument(); formXml.LoadXml(form.GetAttributeValue<string>("formxml")); }
public SynchronousWorkflow(Entity workflow) { this.workflow = workflow; initialRank = Rank; // Stage if (workflow.GetAttributeValue<bool>("triggeroncreate")) { var stageCode = workflow.GetAttributeValue<OptionSetValue>("createstage"); Stage = stageCode != null ? stageCode.Value : 40; Message = "Create"; } else if (workflow.GetAttributeValue<bool>("triggeronupdate")) { var stageCode = workflow.GetAttributeValue<OptionSetValue>("updatestage"); Stage = stageCode != null ? stageCode.Value : 40; Message = "Update"; } else if (workflow.GetAttributeValue<bool>("triggerondelete")) { var stageCode = workflow.GetAttributeValue<OptionSetValue>("deletestage"); Stage = stageCode != null ? stageCode.Value : 20; Message = "Delete"; } else { // throw new Exception("Unexpected stage data"); } }
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()); } }); }
public void AddLibrary(Entity form, string libraryName, bool addFirst) { // Read the form xml content var formXml = form.GetAttributeValue<string>("formxml"); var formDoc = new XmlDocument(); formDoc.LoadXml(formXml); var formNode = formDoc.SelectSingleNode("form"); if (formNode == null) { throw new Exception("Expected node \"formNode\" was not found"); } var formLibrariesNode = formNode.SelectSingleNode("formLibraries"); if (formLibrariesNode == null) { formLibrariesNode = formDoc.CreateElement("formLibraries"); formNode.AppendChild(formLibrariesNode); } // Search for existing library var libraryNode = formLibrariesNode.SelectSingleNode(string.Format("Library[@name='{0}']", libraryName)); if (libraryNode != null) { throw new Exception("This library is already included in this form"); } // Create the new library node var nameAttribute = formDoc.CreateAttribute("name"); var libraryUniqueIdAttribute = formDoc.CreateAttribute("libraryUniqueId"); nameAttribute.Value = libraryName; libraryUniqueIdAttribute.Value = Guid.NewGuid().ToString("B"); libraryNode = formDoc.CreateElement("Library"); if (libraryNode.Attributes != null) { libraryNode.Attributes.Append(nameAttribute); libraryNode.Attributes.Append(libraryUniqueIdAttribute); } if (formLibrariesNode.ChildNodes.Count > 0 && addFirst) { formLibrariesNode.InsertBefore(libraryNode, formLibrariesNode.FirstChild); } else { formLibrariesNode.AppendChild(libraryNode); } // Update the form xml content form["formxml"] = formDoc.OuterXml; }
public PluginStep(Entity pluginStep, IEnumerable<Entity> sdkMessageFilers, IEnumerable<Entity> sdkMessages) { this.pluginStep = pluginStep; initialRank = Rank; // EntityLogicalName var messageFilter = sdkMessageFilers.FirstOrDefault( s => pluginStep.GetAttributeValue<EntityReference>("sdkmessagefilterid") != null && s.Id == pluginStep.GetAttributeValue<EntityReference>("sdkmessagefilterid").Id); if (messageFilter != null) { EntityLogicalName = messageFilter.GetAttributeValue<string>("primaryobjecttypecode"); if (EntityLogicalName.Length == 0) { EntityLogicalName = "None"; } var message = sdkMessages.FirstOrDefault( m => m.Id == messageFilter.GetAttributeValue<EntityReference>("sdkmessageid").Id); if (message != null) { Message = message.GetAttributeValue<string>("name"); } } else { EntityLogicalName = "(none)"; var message = sdkMessages.FirstOrDefault( m => m.Id == pluginStep.GetAttributeValue<EntityReference>("sdkmessageid").Id); if (message != null) { Message = message.GetAttributeValue<string>("name"); } } }
public IdentityUser(Entity entity) { if (entity == null) throw new ArgumentNullException("entity"); Entity = entity; KeyProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserKey); UserNameProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserName) ?? ProjectUtilities.FindNameProperty(entity); NormalizedUserNameProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserNormalizedName) ?? UserNameProperty; CreationDateProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserCreationDate); EmailProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserEmail); EmailConfirmedProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserEmailConfirmed); PhoneNumberProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserPhoneNumber); PhoneNumberConfirmedProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserPhoneNumberConfirmed); PasswordProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserPassword); LastPasswordChangeDateProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserLastPasswordChangeDate); FailedPasswordAttemptCountProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserFailedPasswordAttemptCount); FailedPasswordAttemptWindowStartProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserFailedPasswordAttemptWindowStart); LockoutEnabledProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserLockoutEnabled); LockoutEndDateProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserLockoutEndDate); LastProfileUpdateDateProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserLastProfileUpdateDate); TwoFactorEnabledProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserTwoFactorEnabled); SecurityStampProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserSecurityStamp); RolesProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserRoles); ClaimsProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserClaims); LoginsProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserLogins); LoadByKeyMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadUserByKey); if (LoadByKeyMethod != null) { LoadByKeyMethodName = LoadByKeyMethod.Name; } else if (KeyProperty != null && Entity.LoadByKeyMethod != null) { LoadByKeyMethod = Entity.LoadByKeyMethod; LoadByKeyMethodName = Entity.LoadByKeyMethod.Name; } else { LoadByKeyMethodName = "LoadByEntityKey"; } LoadByUserNameMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadUserByUserName) ?? Entity.LoadByCollectionKeyMethod; LoadByEmailMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadUserByEmail) ?? Entity.Methods.Find("LoadByEmail", StringComparison.OrdinalIgnoreCase) ?? (EmailProperty != null && EmailProperty.IsCollectionKey ? Entity.LoadByCollectionKeyMethod : null); LoadByUserLoginInfoMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadUserByUserLoginInfo); LoadAllMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadAllUsers) ?? Entity.LoadAllMethod; DeleteMethodName = ProjectUtilities.FindByMethodType(Entity, MethodType.DeleteUser)?.Name ?? Entity.GetAttributeValue("deleteMethodName", Constants.NamespaceUri, (string)null) ?? "Delete"; }
public static XmlNode GetFormLibraries(Entity form) { var formXml = form.GetAttributeValue<string>("formxml"); var formDoc = new XmlDocument(); formDoc.LoadXml(formXml); var formNode = formDoc.SelectSingleNode("form"); if (formNode == null) { throw new Exception("Expected node \"formNode\" was not found"); } var formLibrariesNode = formNode.SelectSingleNode("formLibraries"); if (formLibrariesNode == null) { formLibrariesNode = formDoc.CreateElement("formLibraries"); formNode.AppendChild(formLibrariesNode); } return formLibrariesNode; }
public decimal Execute(Entity autoNumber) { // Need to handle shared numbers and we're almost done!!! var internalAutoNumber = new Entity("smp_autonumber") {Id = autoNumber.Id}; internalAutoNumber["name"] = autoNumber["name"]; _organizationService.Update(internalAutoNumber); // Once here we have a transaction open. Get the autonumber again in case the number has moved var queryByAttribute = new QueryByAttribute("smp_autonumber"); queryByAttribute.AddAttributeValue("smp_name", autoNumber["name"]); queryByAttribute.ColumnSet = new ColumnSet("smp_name", "smp_nextnumber"); internalAutoNumber = _organizationService.RetrieveMultiple(queryByAttribute).Entities[0]; decimal number = internalAutoNumber.GetAttributeValue<decimal>("smp_nextnumber"); // Update the new number internalAutoNumber["smp_nextnumber"] = number + 1; _organizationService.Update(internalAutoNumber); return number; }
public void LoadWebResourcesGeneral(Entity specificSolution) { wrManager = new WebResourceManager(Service); tvWebResources.Nodes.Clear(); var dialog = new WebResourceTypeSelectorDialog(); if (dialog.ShowDialog(ParentForm) == DialogResult.OK) { var settings = new LoadCrmResourcesSettings { SolutionId = specificSolution != null ? specificSolution.Id : Guid.Empty, SolutionName = specificSolution != null ?specificSolution.GetAttributeValue<string>("friendlyname") : "", SolutionVersion = specificSolution != null ?specificSolution.GetAttributeValue<string>("version") : "", Types = dialog.TypesToLoad }; SetWorkingState(true); tvWebResources.Nodes.Clear(); WorkAsync("Loading web resources...", e => { Guid solutionId = e.Argument != null ? ((LoadCrmResourcesSettings)e.Argument).SolutionId : Guid.Empty; RetrieveWebResources(solutionId, ((LoadCrmResourcesSettings)e.Argument).Types); e.Result = e.Argument; }, e => { if (e.Error != null) { string errorMessage = CrmExceptionHelper.GetErrorMessage(e.Error, true); MessageBox.Show(this, errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { tvWebResources.Enabled = true; var currentSettings = (LoadCrmResourcesSettings)e.Result; tssCurrentlyLoadedSolution.Visible = currentSettings.SolutionId != Guid.Empty; tslCurrentlyLoadedSolution.Visible = currentSettings.SolutionId != Guid.Empty; tslCurrentlyLoadedSolution.Text = string.Format("Solution loaded: {0} - v{1}", currentSettings.SolutionName, currentSettings.SolutionVersion); } tvWebResources.ExpandAll(); tvWebResources.TreeViewNodeSorter = new NodeSorter(); tvWebResources.Sort(); TvWebResourcesAfterSelect(null, null); tsbClear.Visible = true; SetWorkingState(false); }, settings); } }
public string GetParameterValue(Entity Target) { if (Target.Contains(AttributeName)) { if (Target[AttributeName] is EntityReference) { // Lookup condition is based on GUID return Conditional.HasCondition ? Conditional.GetResult(Target.GetAttributeValue<EntityReference>(AttributeName).Id) : Target.GetAttributeValue<EntityReference>(AttributeName).Name; } else if (Target[AttributeName] is OptionSetValue) { // Conditional OptionSetValue is based on the integer value return Conditional.HasCondition ? Conditional.GetResult(Target.GetAttributeValue<OptionSetValue>(AttributeName).Value.ToString()) : Target.FormattedValues[AttributeName]; } else if (Target[AttributeName] is bool) { // Note: Boolean values ignore the match value, they just use the attribute value itself as the condition return Conditional.HasCondition ? Conditional.GetResult(Target.GetAttributeValue<bool>(AttributeName)) : Target.FormattedValues[AttributeName]; } else if (Target[AttributeName] is DateTime) { // If there is a format AND a condition, apply formatting first, then evaluate condition as a string // If there is a condition without any format, evaluate condition as DateTime return String.IsNullOrEmpty(StringFormatter) ? Conditional.GetResult(Target.GetAttributeValue<DateTime>(AttributeName)) : Conditional.GetResult(Target.GetAttributeValue<DateTime>(AttributeName).ToString(StringFormatter)); } else if (Target[AttributeName] is Money) { return Conditional.HasCondition ? Conditional.GetResult(Target.GetAttributeValue<Money>(AttributeName).Value) : Target.GetAttributeValue<Money>(AttributeName).Value.ToString(StringFormatter); } else if (Target[AttributeName] is int) { return Conditional.HasCondition ? Conditional.GetResult(Target.GetAttributeValue<double>(AttributeName)) : Target.GetAttributeValue<double>(AttributeName).ToString(StringFormatter); } else if (Target[AttributeName] is decimal) { return Conditional.HasCondition ? Conditional.GetResult(Target.GetAttributeValue<decimal>(AttributeName)) : Target.GetAttributeValue<decimal>(AttributeName).ToString(StringFormatter); } else if (Target[AttributeName] is double) { return Conditional.HasCondition ? Conditional.GetResult(Target.GetAttributeValue<double>(AttributeName)) : Target.GetAttributeValue<double>(AttributeName).ToString(StringFormatter); } else if (Target[AttributeName] is string) { return Conditional.GetResult(Target[AttributeName].ToString()); } } else if (AttributeName.Equals("rand")) { string length = ""; string stringStyle = "upper"; int stringLength = 5; // Seems like reasonable default if (StringFormatter.Contains('?')) { length = StringFormatter.Split('?')[0]; stringStyle = StringFormatter.Split('?')[1].ToLower(); } else { length = StringFormatter; } if (!Int32.TryParse(length, out stringLength)) { stringLength = 5; } string stringValues = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; if (stringStyle == "mix") { stringValues = stringValues + stringValues.ToLower(); } else if (stringStyle == "lower") { stringValues = stringValues.ToLower(); } Random rnd = new Random(); return String.Join("", Enumerable.Range(0, stringLength).Select(n => stringValues[rnd.Next(stringValues.Length)])); } return DefaultValue; }
public bool RemoveLibrary(Entity form, string libraryName, Form parentForm) { // Read the form xml content var formXml = form.GetAttributeValue<string>("formxml"); var formDoc = new XmlDocument(); formDoc.LoadXml(formXml); var formNode = formDoc.SelectSingleNode("form"); if (formNode == null) { throw new Exception("Expected node \"formNode\" was not found"); } // Retrieve events that use the library var eventNodes = formNode.SelectNodes(string.Format("events/event/Handlers/Handler[@libraryName='{0}']", libraryName)); if (eventNodes != null && eventNodes.Count > 0) { var result = MessageBox.Show(parentForm, string.Format( "The library '{2}' is used by {0} event{1}. If you remove the library, {0} event{1} will be removed too\r\n\r\nDo you want to continue?", eventNodes.Count, eventNodes.Count > 1 ? "s" : "", libraryName), "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { return false; } } var formLibrariesNode = formNode.SelectSingleNode("formLibraries"); if (formLibrariesNode == null) { throw new Exception("Expected node \"formLibraries\" was not found"); } // Search for existing library var libraryNode = formLibrariesNode.SelectSingleNode(string.Format("Library[@name='{0}']", libraryName)); if (libraryNode == null) { throw new Exception("This library is noy included in this form"); } // Remove library formLibrariesNode.RemoveChild(libraryNode); if (formLibrariesNode.ChildNodes.Count == 0) { formLibrariesNode.ParentNode.RemoveChild(formLibrariesNode); } // Remove events that was using the library foreach (XmlNode eventNode in eventNodes) { if (eventNode.ParentNode.ChildNodes.Count == 1) { formNode.SelectSingleNode("events").RemoveChild(eventNode.ParentNode.ParentNode); } else { eventNode.ParentNode.RemoveChild(eventNode); } } // Update the form xml content form["formxml"] = formDoc.OuterXml; return true; }
private void RemoveFormatting(Entity entity, string attribute) { var number = entity.GetAttributeValue<string>(attribute); if (number == null) { return; } entity[attribute] = new String(number.Where(char.IsNumber).ToArray()); }
internal object GetValue(Entity entry, string attributeName) { return entry.Attributes.Contains(attributeName) ? entry.GetAttributeValue<object>(attributeName) : null; }
public void UpdateRuleFromSystemView(Entity systemView, Entity rule, BackgroundWorker worker = null) { var ruleToUpdate = new Entity("savedquery") { Id = rule.Id }; // Remove Order nodes if Outlook template and Offline template ruleToUpdate["fetchxml"] = RemoveFetchOrderNodes(systemView.GetAttributeValue<string>("fetchxml")); service.Update(ruleToUpdate); if (worker != null && worker.WorkerReportsProgress) { worker.ReportProgress(0, string.Format("Publishing entity '{0}'...", rule.GetAttributeValue<string>("returnedtypecode"))); } var request = new PublishXmlRequest { ParameterXml = String.Format("<importexportxml><entities><entity>{0}</entity></entities></importexportxml>", rule.GetAttributeValue<string>("returnedtypecode")) }; service.Execute(request); }
private string GetMethodParameterNameFormat(Entity entity) { if (entity == null) return DefaultParameterNameFormat; var defaultValue = GetMethodParameterNameFormat(entity.Project); return entity.GetAttributeValue("defaultParameterNameFormat", NamespaceUri, defaultValue); }
private bool IsEnabled(Entity entity) { if (entity == null) return false; if (entity.SaveProcedure == null) return false; if (entity.Table == null) return false; bool defaultValue = entity.Project.GetAttributeValue("defaultEnabled", Namespace, false); return entity.GetAttributeValue("enabled", Namespace, defaultValue); }
private string ExtractSection(XmlNode sectionNode, int lcid, List<CrmFormSection> crmFormSections, Entity form, string tabName) { if (sectionNode.Attributes == null || sectionNode.Attributes["id"] == null) return string.Empty; var sectionId = sectionNode.Attributes["id"].Value; var sectionLabelNode = sectionNode.SelectSingleNode("labels/label[@languagecode='" + lcid + "']"); if (sectionLabelNode == null || sectionLabelNode.Attributes == null) return string.Empty; var sectionNameAttr = sectionLabelNode.Attributes["description"]; if (sectionNameAttr == null) return string.Empty; var sectionName = sectionNameAttr.Value; var crmFormSection = crmFormSections.FirstOrDefault( f => f.Id == new Guid(sectionId) && f.FormUniqueId == form.GetAttributeValue<Guid>("formidunique")); if (crmFormSection == null) { crmFormSection = new CrmFormSection { Id = new Guid(sectionId), FormUniqueId = form.GetAttributeValue<Guid>("formidunique"), FormId = form.GetAttributeValue<Guid>("formid"), Form = form.GetAttributeValue<string>("name"), Tab = tabName, Names = new Dictionary<int, string>() }; crmFormSections.Add(crmFormSection); } if (crmFormSection.Names.ContainsKey(lcid)) { return sectionName; } crmFormSection.Names.Add(lcid, sectionName); return sectionName; }
private string ExtractTabName(XmlNode tabNode, int lcid, List<CrmFormTab> crmFormTabs, Entity form) { if (tabNode.Attributes == null || tabNode.Attributes["id"] == null) return string.Empty; var tabId = tabNode.Attributes["id"].Value; var tabLabelNode = tabNode.SelectSingleNode("labels/label[@languagecode='" + lcid + "']"); if (tabLabelNode == null || tabLabelNode.Attributes == null) return string.Empty; var tabLabelDescAttr = tabLabelNode.Attributes["description"]; if (tabLabelDescAttr == null) return string.Empty; var tabName = tabLabelDescAttr.Value; var crmFormTab = crmFormTabs.FirstOrDefault( f => f.Id == new Guid(tabId) && f.FormUniqueId == form.GetAttributeValue<Guid>("formidunique")); if (crmFormTab == null) { crmFormTab = new CrmFormTab { Id = new Guid(tabId), FormUniqueId = form.GetAttributeValue<Guid>("formidunique"), FormId = form.GetAttributeValue<Guid>("formid"), Form = form.GetAttributeValue<string>("name"), Names = new Dictionary<int, string>() }; crmFormTabs.Add(crmFormTab); } if (crmFormTab.Names.ContainsKey(lcid)) { return tabName; } crmFormTab.Names.Add(lcid, tabName); return tabName; }
private bool IsEnabled(Entity entity) { if (entity == null) return false; bool defaultValue = IsEnabled(entity.Project); return entity.GetAttributeValue("defaultEnabled", NamespaceUri, defaultValue); }
private string GetDepth(Entity e) { try { var alias = e.GetAttributeValue<AliasedValue>("roleprivilege.privilegedepthmask"); var depth = (int)alias.Value; switch ((PrivilegeDepthMask)depth) { case PrivilegeDepthMask.Basic: return "User"; case PrivilegeDepthMask.Local: return "Business Unit"; case PrivilegeDepthMask.Deep: return "Parent: Child"; case PrivilegeDepthMask.Global: return "Organization"; } return "UKNOWN"; } catch { MessageBox.Show("Error encountered in GetDepth"); return "ERROR"; } }
private string GetEntityName(Entity e) { try { var entityName = string.Empty; if (e.Contains("privilegeobjecttypecode.objecttypecode")) { var alias = e.GetAttributeValue<AliasedValue>("privilegeobjecttypecode.objecttypecode"); entityName = alias != null ? alias.Value as string : string.Empty; } if (!string.IsNullOrEmpty(entityName)) { var entityMetadata = _entityMetadata .Where(m => m.LogicalName == entityName) .FirstOrDefault(); if (entityMetadata != null && entityMetadata.DisplayName != null && entityMetadata.DisplayName.UserLocalizedLabel != null) { entityName = entityMetadata.DisplayName.UserLocalizedLabel.Label; } } return entityName; } catch { MessageBox.Show("Error encountered in GetEntityName"); return "ERROR"; } }
private static void ReplaceLayoutXmlObjectTypeCode(Entity view, IOrganizationService targetService) { // Retrieve Metadata for target entity var response = (RetrieveEntityResponse) targetService.Execute(new RetrieveEntityRequest {LogicalName = view.GetAttributeValue<string>("returnedtypecode"),EntityFilters = EntityFilters.Entity}); var code = response.EntityMetadata.ObjectTypeCode.Value; var sXml = view.GetAttributeValue<string>("layoutxml"); var xml = new XmlDocument(); xml.LoadXml(sXml); var gridNode = xml.SelectSingleNode("grid"); gridNode.Attributes["object"].Value = code.ToString(CultureInfo.InvariantCulture); view["layoutxml"] = xml.OuterXml; }
private void minifyJS(Entity entity, CodeSettings settings) { Microsoft.Ajax.Utilities.Minifier minifier = new Microsoft.Ajax.Utilities.Minifier(); string name = entity.GetAttributeValue<string>("displayname"); byte[] jsFileBytes = Convert.FromBase64String(entity.GetAttributeValue<string>("content")); string originalJS = UnicodeEncoding.UTF8.GetString(jsFileBytes); string minifiedJs = minifier.MinifyJavaScript(originalJS, settings); byte[] minifiedJsBytes = UnicodeEncoding.UTF8.GetBytes(minifiedJs); string minifiedJsBytesString = Convert.ToBase64String(minifiedJsBytes); Entity updatedWebResource = new Entity(entity.LogicalName); updatedWebResource.Attributes.Add("content", minifiedJsBytesString); updatedWebResource.Id = entity.Id; this.service.Update(updatedWebResource); }
public void UpdateRuleFromSystemView(Entity systemView, Entity rule, BackgroundWorker worker = null) { var ruleToUpdate = new Entity("savedquery") { Id = rule.Id }; if (rule.GetAttributeValue<int>("querytype") == 256 || rule.GetAttributeValue<int>("querytype") == 131072) { // Remove Order nodes if Outlook template var fetchDoc = new XmlDocument(); fetchDoc.LoadXml(systemView.GetAttributeValue<string>("fetchxml")); var orderNodes = fetchDoc.SelectNodes("//order"); foreach (XmlNode orderNode in orderNodes) { orderNode.ParentNode.RemoveChild(orderNode); } rule["fetchxml"] = fetchDoc.OuterXml; } else { ruleToUpdate["fetchxml"] = systemView.GetAttributeValue<string>("fetchxml"); } service.Update(ruleToUpdate); if (worker != null && worker.WorkerReportsProgress) { worker.ReportProgress(0, string.Format("Publishing entity '{0}'...", rule.GetAttributeValue<string>("returnedtypecode"))); } var request = new PublishXmlRequest { ParameterXml = String.Format("<importexportxml><entities><entity>{0}</entity></entities></importexportxml>", rule.GetAttributeValue<string>("returnedtypecode")) }; service.Execute(request); }
private void ShowFetchXml(Entity entity) { if (entity != null) { var fxDialog = new XmlContentDisplayDialog(entity.GetAttributeValue<string>("fetchxml")); fxDialog.ShowDialog(this); } }
private void ExtractField(XmlNode cellNode, List<CrmFormLabel> crmFormLabels, Entity form, string tabName, string sectionName, int lcid) { if (cellNode.Attributes == null) return; var cellIdAttr = cellNode.Attributes["id"]; if (cellIdAttr == null) return; if (cellNode.ChildNodes.Count == 0) return; var controlNode = cellNode.SelectSingleNode("control"); if (controlNode == null || controlNode.Attributes == null) return; //var crmFormField = crmFormLabels.FirstOrDefault(f => f.Id == new Guid(cellIdAttr.Value) && f.FormId == form.Id); var crmFormField = crmFormLabels.FirstOrDefault( f => f.Id == new Guid(cellIdAttr.Value) && f.FormUniqueId == form.GetAttributeValue<Guid>("formidunique")); if (crmFormField == null) { crmFormField = new CrmFormLabel { Id = new Guid(cellIdAttr.Value), Form = form.GetAttributeValue<string>("name"), FormUniqueId = form.GetAttributeValue<Guid>("formidunique"), FormId = form.GetAttributeValue<Guid>("formid"), Tab = tabName, Section = sectionName, Attribute = controlNode.Attributes["id"].Value, Names = new Dictionary<int, string>() }; crmFormLabels.Add(crmFormField); } var labelNode = cellNode.SelectSingleNode("labels/label[@languagecode='" + lcid + "']"); var labelNodeAttributes = labelNode == null ? null : labelNode.Attributes; var labelDescription = labelNodeAttributes == null ? null : labelNodeAttributes["description"]; if (crmFormField.Names.ContainsKey(lcid)) { return; } crmFormField.Names.Add(lcid, labelDescription == null ? string.Empty : labelDescription.Value); }
private FilterFunctions GetDefaultFilterFunctions(Entity entity) { if (entity == null) return DefaultFilterFunctions; FilterFunctions defaultValue = GetDefaultFilterFunctions(entity.Project); return entity.GetAttributeValue("defaultFilterFunctions", NamespaceUri, defaultValue); }