public void FillSolutionComponent(ICollection <SolutionComponent> result, SolutionImageComponent solutionImageComponent) { if (solutionImageComponent == null || string.IsNullOrEmpty(solutionImageComponent.SchemaName) || string.IsNullOrEmpty(solutionImageComponent.ParentSchemaName) ) { return; } EntityKeyMetadata metaData = _source.GetEntityKeyMetadata(solutionImageComponent.ParentSchemaName, solutionImageComponent.SchemaName); if (metaData != null) { var component = new SolutionComponent() { ComponentType = new OptionSetValue(this.ComponentTypeValue), ObjectId = metaData.MetadataId.Value, RootComponentBehaviorEnum = SolutionComponent.Schema.OptionSets.rootcomponentbehavior.Include_Subcomponents_0, }; if (solutionImageComponent.RootComponentBehavior.HasValue) { component.RootComponentBehavior = new OptionSetValue(solutionImageComponent.RootComponentBehavior.Value); } result.Add(component); } }
/// <summary> /// /// </summary> /// <param name="service"></param> /// <param name="entityLogicalName"></param> /// <param name="logicalName"></param> /// <param name="keyDisplayName"></param> /// <param name="keyAttributes"></param> public static string CreateEntityKey(IOrganizationService service, string entityLogicalName, string logicalName, string keyDisplayName, List <string> keyAttributes) { try { var entKeyMeta = new EntityKeyMetadata() { KeyAttributes = keyAttributes.ToArray(), LogicalName = logicalName, DisplayName = new Label(keyDisplayName, 1033), SchemaName = logicalName }; var req = new CreateEntityKeyRequest() { EntityKey = entKeyMeta, EntityName = entityLogicalName }; var resp = service.Execute(req) as CreateEntityKeyResponse; return(null); } catch (Exception ex) { return($"Error createing the new Alternate Key: {keyDisplayName} ({logicalName}): \n{ex.Message}"); } }
public static EntityKeyMetadata RetrieveEntityKeyMetadata(string entityLogicalName, string logicalName, Boolean retrieveAsIfPublished, IOrganizationService organizationService) { EntityKeyMetadata entityKeyMetadata = null; if (!string.IsNullOrEmpty(entityLogicalName) && !string.IsNullOrEmpty(logicalName)) { try { RetrieveEntityKeyRequest retrieveEntityKeyRequest = new RetrieveEntityKeyRequest() { EntityLogicalName = entityLogicalName, LogicalName = logicalName, MetadataId = Guid.Empty, RetrieveAsIfPublished = retrieveAsIfPublished, }; RetrieveEntityKeyResponse retrieveEntityKeyResponse = (RetrieveEntityKeyResponse)organizationService.Execute(retrieveEntityKeyRequest); //Null validation if (retrieveEntityKeyResponse != null) { entityKeyMetadata = retrieveEntityKeyResponse.EntityKeyMetadata; } } catch { } } return(entityKeyMetadata); }
public string GenerateDescriptionSingle(SolutionComponent solutionComponent, bool withManaged, bool withSolutionInfo, bool withUrls) { EntityKeyMetadata metaData = _source.GetEntityKeyMetadata(solutionComponent.ObjectId.Value); if (metaData != null) { string behavior = SolutionComponent.GetRootComponentBehaviorName(solutionComponent.RootComponentBehavior?.Value); FormatTextTableHandler handler = new FormatTextTableHandler(); handler.SetHeader("EntityKeyName", "IsCustomizable", "Behavior"); if (withManaged) { handler.AppendHeader("IsManaged"); } handler.AppendHeader("KeyAttributes"); if (withUrls) { handler.AppendHeader("Url"); } List <string> values = new List <string>(); values.AddRange(new[] { string.Format("{0}.{1}", metaData.EntityLogicalName, metaData.LogicalName) , metaData.IsCustomizable?.Value.ToString() , behavior }); if (withManaged) { values.Add(metaData.IsManaged.ToString()); } values.Add(string.Join(",", metaData.KeyAttributes.OrderBy(s => s))); if (withUrls) { var entityMetadata = _source.GetEntityMetadata(metaData.EntityLogicalName); if (entityMetadata != null) { values.Add(_source.Service.ConnectionData?.GetEntityKeyMetadataUrl(entityMetadata.MetadataId.Value, metaData.MetadataId.Value)); } } handler.AddLine(values); var str = handler.GetFormatedLinesWithHeadersInLine(false).FirstOrDefault(); return(string.Format("{0} {1}", this.ComponentTypeEnum.ToString(), str)); } return(solutionComponent.ToString()); }
/// <summary> /// Delete a selected Entity Alternate Key /// </summary> /// <param name="service"></param> /// <param name="key"></param> public static void DeleteEntityKey(IOrganizationService service, EntityKeyMetadata key) { var req = new DeleteEntityKeyRequest() { EntityLogicalName = key.EntityLogicalName, Name = key.LogicalName }; var resp = service.Execute(req) as DeleteEntityKeyResponse; }
public string GetDisplayName(SolutionComponent solutionComponent) { EntityKeyMetadata metaData = _source.GetEntityKeyMetadata(solutionComponent.ObjectId.Value); if (metaData != null) { return(metaData.DisplayName?.UserLocalizedLabel?.Label); } return(null); }
public string GetCustomizableName(SolutionComponent solutionComponent) { EntityKeyMetadata metaData = _source.GetEntityKeyMetadata(solutionComponent.ObjectId.Value); if (metaData != null) { return(metaData.IsCustomizable?.Value.ToString()); } return(null); }
public string GetManagedName(SolutionComponent solutionComponent) { EntityKeyMetadata metaData = _source.GetEntityKeyMetadata(solutionComponent.ObjectId.Value); if (metaData != null) { return(metaData.IsManaged.ToString()); } return(null); }
public string GetFileName(string connectionName, Guid objectId, string fieldTitle, FileExtension extension) { EntityKeyMetadata metaData = _source.GetEntityKeyMetadata(objectId); if (metaData != null) { return(string.Format("{0}.EntityKey {1}.{2} - {3}.{4}", connectionName, metaData.EntityLogicalName, metaData.LogicalName, fieldTitle, extension.ToStr())); } return(string.Format("{0}.ComponentType {1} - {2} - {3}.{4}", connectionName, this.ComponentTypeValue, objectId, fieldTitle, extension.ToStr())); }
private List <string> GetDifferenceKey(EntityKeyMetadata key1, EntityKeyMetadata key2) { List <string> strDifference = new List <string>(); { FormatTextTableHandler tableFormatter = new FormatTextTableHandler(true); tableFormatter.CalculateLineLengths("LanguageCode", "Value"); tableFormatter.CalculateLineLengths("LanguageCode", "Organization", "Value"); var isDifferentDisplayName = LabelComparer.GetDifference(key1.DisplayName, key2.DisplayName); isDifferentDisplayName.LabelsOnlyIn1.ForEach(i => tableFormatter.CalculateLineLengths(i.Locale, i.Value)); isDifferentDisplayName.LabelsOnlyIn2.ForEach(i => tableFormatter.CalculateLineLengths(i.Locale, i.Value)); isDifferentDisplayName.LabelDifference.ForEach(i => { tableFormatter.CalculateLineLengths(i.Locale, _connectionName1, i.Value1); tableFormatter.CalculateLineLengths(i.Locale, _connectionName2, i.Value2); }); if (!isDifferentDisplayName.IsEmpty) { if (isDifferentDisplayName.LabelsOnlyIn1.Count > 0) { strDifference.Add(string.Format("DisplayNames ONLY in {0}: {1}", _connectionName1, isDifferentDisplayName.LabelsOnlyIn1.Count)); strDifference.Add(_tabSpacer + tableFormatter.FormatLine("LanguageCode", "Value")); isDifferentDisplayName.LabelsOnlyIn1.ForEach(e => strDifference.Add(_tabSpacer + tableFormatter.FormatLine(e.Locale, e.Value))); } if (isDifferentDisplayName.LabelsOnlyIn2.Count > 0) { strDifference.Add(string.Format("DisplayNames ONLY in {0}: {1}", _connectionName2, isDifferentDisplayName.LabelsOnlyIn2.Count)); strDifference.Add(_tabSpacer + tableFormatter.FormatLine("LanguageCode", "Value")); isDifferentDisplayName.LabelsOnlyIn2.ForEach(e => strDifference.Add(_tabSpacer + tableFormatter.FormatLine(e.Locale, e.Value))); } if (isDifferentDisplayName.LabelDifference.Count > 0) { strDifference.Add(string.Format("DisplayNames DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, isDifferentDisplayName.LabelDifference.Count)); strDifference.Add(_tabSpacer + tableFormatter.FormatLine("LanguageCode", "Organization", "Value")); isDifferentDisplayName.LabelDifference.ForEach(i => { strDifference.Add(_tabSpacer + tableFormatter.FormatLine(i.Locale, _connectionName1, i.Value1)); strDifference.Add(_tabSpacer + tableFormatter.FormatLine(i.Locale, _connectionName2, i.Value2)); }); } } } return(strDifference); }
public Guid AddEntityKey(string entity, EntityKeyMetadata key) { OrganizationRequest request = new OrganizationRequest("CreateEntityKey") { Parameters = new ParameterCollection { { "EntityName", entity }, { "EntityKey", key } } }; OrganizationResponse response = CrmContext.OrganizationProxy.Execute(request); return((Guid)response.Results["EntityKeyId"]); }
/// <summary> /// Update the other UI elements now that the selected Alternate Key has changed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ListViewKeyList_SelectedIndexChanged(object sender, EventArgs e) { EntityKeyMetadata key = null; UpdateKeysToolbar(); var selected = ListViewKeyList.SelectedItems; if (selected.Count == 1) { key = selected[0].Tag as EntityKeyMetadata; } UpdateKeyDetailsPane(key); }
public string GetName(SolutionComponent solutionComponent) { if (solutionComponent == null || !solutionComponent.ObjectId.HasValue) { return("null"); } EntityKeyMetadata metaData = _source.GetEntityKeyMetadata(solutionComponent.ObjectId.Value); if (metaData != null) { return(string.Format("{0}.{1}", metaData.EntityLogicalName, metaData.LogicalName)); } return(solutionComponent.ObjectId.ToString()); }
/// <summary> /// Reactivate an Entity Key /// </summary> /// <param name="service"></param> /// <param name="key"></param> /// <returns></returns> public static List<string> ReactivateEntityKey(IOrganizationService service, EntityKeyMetadata key) { try { // call the Activate action for the selected key var req = new ReactivateEntityKeyRequest() { EntityKeyLogicalName = key.SchemaName, EntityLogicalName = key.EntityLogicalName }; var resp = (ReactivateEntityKeyResponse)service.Execute(req); return null; } catch(Exception ex) { return new List<string>() {$"Error reactivating key {key.SchemaName}: \n{ex.Message}" }; } }
public EntityKeyMetadata GetEntityKeyMetadata(string entityName, string keyName) { EntityKeyMetadata result = null; result = _dictKey.Values.FirstOrDefault(a => string.Equals(entityName, a.EntityLogicalName, StringComparison.InvariantCultureIgnoreCase) && string.Equals(keyName, a.LogicalName, StringComparison.InvariantCultureIgnoreCase)); if (result != null) { return(result); } try { if (this._allMetadataDownloaded) { return(null); } var request = new RetrieveEntityKeyRequest() { EntityLogicalName = entityName, LogicalName = keyName, }; var response = (RetrieveEntityKeyResponse)Service.Execute(request); var metaKey = response.EntityKeyMetadata; if (!_dictKey.ContainsKey(metaKey.MetadataId.Value)) { _dictKey.TryAdd(metaKey.MetadataId.Value, metaKey); } return(_dictKey[metaKey.MetadataId.Value]); } catch (Exception ex) { DTEHelper.WriteExceptionToLog(ex, Properties.OutputStrings.GetEntityKeyMetadataByStringStringFormat2, entityName, keyName); return(null); } }
private void CreateAlternateKey(string entityName, List <string> entityFieldName, string keyDisplayName, string keyLogicalName) { EntityKeyMetadata Data = new EntityKeyMetadata(); Data.KeyAttributes = entityFieldName.ToArray(); Data.DisplayName = new Label(keyDisplayName, 1033); Data.LogicalName = keyLogicalName; Data.SchemaName = keyLogicalName; CreateEntityKeyRequest request1 = new CreateEntityKeyRequest() { EntityKey = Data, EntityName = entityName, }; IOrganizationService service = CRMHelper.ConnectToMSCRM(); CreateEntityKeyResponse response = (CreateEntityKeyResponse)service.Execute(request1); }
public void FillSolutionImageComponent(ICollection <SolutionImageComponent> result, SolutionComponent solutionComponent) { EntityKeyMetadata metaData = _source.GetEntityKeyMetadata(solutionComponent.ObjectId.Value); if (metaData != null) { result.Add(new SolutionImageComponent() { ComponentType = (int)ComponentType.EntityKey, SchemaName = metaData.LogicalName, ParentSchemaName = metaData.EntityLogicalName, RootComponentBehavior = (int)solutionComponent.RootComponentBehaviorEnum.GetValueOrDefault(SolutionComponent.Schema.OptionSets.rootcomponentbehavior.Include_Subcomponents_0), Description = GenerateDescriptionSingle(solutionComponent, true, false, false), }); } }
/// <summary> /// Populate the Key Details pane controls with the Key Info /// </summary> /// <param name="key"></param> private void UpdateKeyDetailsPane(EntityKeyMetadata key) { labelKeyLogicalNameValue.Text = null; labelKeyIsManagedValue.Text = null; labelKeyMetadataIdValue.Text = null; labelKeySchemaNameValue.Text = null; labelKeyNameValue.Text = null; labelKeyStatusValue.Text = null; labelScheduledJobValue.Text = null; if (key != null) { labelKeyNameValue.Text = CrmActions.GetLocalizedLabel(key.DisplayName, key.SchemaName); labelKeyLogicalNameValue.Text = key.LogicalName; labelKeySchemaNameValue.Text = key.SchemaName; labelKeyStatusValue.Text = key.EntityKeyIndexStatus.ToString(); labelKeyIsManagedValue.Text = key.IsManaged.Value.ToString(); labelKeyMetadataIdValue.Text = key.MetadataId.Value.ToString("b"); labelScheduledJobValue.Text = (key.AsyncJob != null) ? ((EntityReference)key.AsyncJob).Name : null; } }
public IEnumerable <SolutionComponent> GetLinkedComponents(SolutionComponent solutionComponent) { var result = new List <SolutionComponent>(); EntityKeyMetadata metaData = _source.GetEntityKeyMetadata(solutionComponent.ObjectId.Value); if (metaData != null) { var entityMetadata = _source.GetEntityMetadata(metaData.EntityLogicalName); if (entityMetadata != null) { result.Add(new SolutionComponent() { ObjectId = entityMetadata.MetadataId, ComponentType = new OptionSetValue((int)ComponentType.Entity), }); } } return(result); }
public void LoadData(EntityKeyMetadata item) { if (item.MetadataId.HasValue) { this.MetadataId = item.MetadataId; } if (!string.IsNullOrEmpty(item.LogicalName)) { this.LogicalName = item.LogicalName; } if (!string.IsNullOrEmpty(item.EntityLogicalName)) { this.EntityLogicalName = item.EntityLogicalName; } if (item.KeyAttributes != null) { this.KeyAttributes = item.KeyAttributes; } }
protected override void ExecuteCmdlet() { base.ExecuteCmdlet(); switch (this.ParameterSetName) { case AddEntityKeyParameterSet: EntityKeyMetadata key = new EntityKeyMetadata() { LogicalName = Name, SchemaName = Name, DisplayName = new Label(DisplayName, CrmContext.Language) }; key.KeyAttributes = Attributes; if (!string.IsNullOrWhiteSpace(SchemaName)) { key.SchemaName = SchemaName; } Guid id1 = _repository.AddEntityKey(Entity, key); if (PassThru) { WriteObject(_repository.GetEntityKey(id1)); } break; case AddEntityKeyByInputObjectParameterSet: Guid id2 = _repository.AddEntityKey(Entity, InputObject); if (PassThru) { WriteObject(_repository.GetEntityKey(id2)); } break; default: break; } }
public KeyMetadataInfo(EntityKeyMetadata ekm) { this.ekm = ekm; }
internal override void StoreResult(HttpResponseMessage httpResponse) { XDocument xdoc = XDocument.Parse(httpResponse.Content.ReadAsStringAsync().Result, LoadOptions.None); foreach (var result in xdoc.Descendants(Util.ns.a + "Results").Elements(Util.ns.a + "KeyValuePairOfstringanyType")) { if (result.Element(Util.ns.b + "key").Value == "EntityKeyMetadata") this.EntityKeyMetadata = EntityKeyMetadata.LoadFromXml(result.Element(Util.ns.b + "value")); } }
public void BulkUpsertRequest() { IOrganizationService service = CRMHelper.ConnectToMSCRM(); //var multipleRequest = new ExecuteMultipleRequest() //{ // // Assign settings that define execution behavior: continue on error, return responses. // Settings = new ExecuteMultipleSettings() // { // ContinueOnError = false, // ReturnResponses = true // }, // // Create an empty organization request collection. // Requests = new OrganizationRequestCollection() //}; //string accountKey = "accountnumber"; //string keyValue = string.Empty; //// First Account Record //keyValue = "123"; //Entity Account = new Entity("account", accountKey, "123"); //Account.Attributes.Add("name", keyValue); //UpsertRequest upReq = new UpsertRequest(); //upReq.Target = Account; //multipleRequest.Requests.Add(upReq); //// Second Account Record //keyValue = "456"; //Account = new Entity("account", accountKey, keyValue); //Account.Attributes.Add("name", keyValue); //upReq = new UpsertRequest(); //upReq.Target = Account; //multipleRequest.Requests.Add(upReq); //// Third Account Record //keyValue = "789"; //Account = new Entity("account", accountKey, keyValue); //Account.Attributes.Add("name", keyValue); //// Third Account Record //keyValue = "7890"; //Account = new Entity("account", accountKey, keyValue); //Account.Attributes.Add("name", keyValue); //upReq = new UpsertRequest(); //upReq.Target = Account; //multipleRequest.Requests.Add(upReq); //ExecuteMultipleResponse multipleResponse = (ExecuteMultipleResponse)service.Execute(multipleRequest); EntityKeyMetadata Data = new EntityKeyMetadata(); Data.KeyAttributes = new string[] { "apttus_contactnumber" }; Data.DisplayName = new Label("Contact Number", 1033); Data.LogicalName = "apttus_contactnumber"; Data.SchemaName = "apttus_telephone1"; CreateEntityKeyRequest request1 = new CreateEntityKeyRequest() { EntityKey = Data, EntityName = "contact", }; CreateEntityKeyResponse response = (CreateEntityKeyResponse)service.Execute(request1); }
//public AttributeMetadata EntityPrimaryKeyMetadata { get; private set; } = null; public KeyItem(EntityKeyMetadata entityKeyMetadata) { EntityKeyMetadata = entityKeyMetadata; }
/// <summary> /// Alternate keys may not be active immediately after a solution defining them is installed. /// This method polls the metadata for a specific entity /// to delay execution of the rest of the sample until the alternate keys are ready. /// </summary> /// <param name="service">Specifies the service to connect to.</param> /// <param name="asyncJob">The system job that creates the index to support the alternate key</param> /// <param name="iteration">The number of times this method has been called.</param> /// private static bool VerifyBookCodeKeyIsActive(IOrganizationService service, EntityReference asyncJob = null, int iteration = 0) { if (iteration > 5) { //Give up return(false); } if (iteration == 0) //only the first time { //Get whether the Entity Key index is active from the metadata EntityQueryExpression entityQuery = new EntityQueryExpression(); entityQuery.Criteria = new MetadataFilterExpression(LogicalOperator.And) { Conditions = { { new MetadataConditionExpression("LogicalName", MetadataConditionOperator.Equals, "sample_book") } } }; entityQuery.Properties = new MetadataPropertiesExpression("Keys"); RetrieveMetadataChangesRequest metadataRequest = new RetrieveMetadataChangesRequest() { Query = entityQuery }; RetrieveMetadataChangesResponse metadataResponse = (RetrieveMetadataChangesResponse)service.Execute(metadataRequest); EntityKeyMetadata bookcodekey = metadataResponse.EntityMetadata.FirstOrDefault().Keys.FirstOrDefault(); if (bookcodekey.EntityKeyIndexStatus == EntityKeyIndexStatus.Active) { return(true); } else { iteration++; return(VerifyBookCodeKeyIsActive(service, bookcodekey.AsyncJob, iteration)); } } else { //Check the status of the system job that is should indicate that the alternate key index is active. AsyncOperation systemJob = (AsyncOperation)service.Retrieve(asyncJob.LogicalName, asyncJob.Id, new ColumnSet("statecode", "statuscode")); if (systemJob.StateCode == AsyncOperationState.Completed) //Completed { if (!systemJob.StatusCode.Value.Equals(30)) //Not Succeeded { //Delete the system job and try to reactivate service.Delete(asyncJob.LogicalName, asyncJob.Id); ReactivateEntityKeyRequest reactivateRequest = new ReactivateEntityKeyRequest() { EntityLogicalName = "sample_book", EntityKeyLogicalName = "sample_bookcode" }; ReactivateEntityKeyResponse reactivateResponse = (ReactivateEntityKeyResponse)service.Execute(reactivateRequest); //Get the system job created by the reactivate request QueryByAttribute systemJobQuery = new QueryByAttribute("asyncoperation"); systemJobQuery.AddAttributeValue("primaryentitytype", "sample_book"); systemJobQuery.AddOrder("createdon", OrderType.Descending); systemJobQuery.TopCount = 1; systemJobQuery.ColumnSet = new ColumnSet("asyncoperationid", "name"); EntityCollection systemJobs = service.RetrieveMultiple(systemJobQuery); asyncJob = systemJobs.Entities.FirstOrDefault().ToEntityReference(); iteration++; return(VerifyBookCodeKeyIsActive(service, asyncJob, iteration)); } else { //It succeeded return(true); } } else { //Give it more time to complete Thread.Sleep(TimeSpan.FromSeconds(30)); iteration++; return(VerifyBookCodeKeyIsActive(service, asyncJob, iteration)); } } }
public void GenerateDescription(StringBuilder builder, IEnumerable <SolutionComponent> components, bool withManaged, bool withSolutionInfo, bool withUrls) { FormatTextTableHandler handler = new FormatTextTableHandler(); handler.SetHeader("Name", "IsCustomizable", "Behavior"); if (withManaged) { handler.AppendHeader("IsManaged"); } handler.AppendHeader("KeyAttributes"); if (withUrls) { handler.AppendHeader("Url"); } foreach (var comp in components) { string behavior = SolutionComponent.GetRootComponentBehaviorName(comp.RootComponentBehavior?.Value); EntityKeyMetadata metaData = _source.GetEntityKeyMetadata(comp.ObjectId.Value); if (metaData != null) { List <string> values = new List <string>(); values.AddRange(new[] { string.Format("{0}.{1}", metaData.EntityLogicalName, metaData.LogicalName) , metaData.IsCustomizable?.Value.ToString() , behavior }); if (withManaged) { values.Add(metaData.IsManaged.ToString()); } values.Add(string.Join(",", metaData.KeyAttributes.OrderBy(s => s))); if (withUrls) { var entityMetadata = _source.GetEntityMetadata(metaData.EntityLogicalName); if (entityMetadata != null) { values.Add(_source.Service.ConnectionData?.GetEntityKeyMetadataUrl(entityMetadata.MetadataId.Value, metaData.MetadataId.Value)); } } handler.AddLine(values); } else { handler.AddLine(comp.ObjectId.ToString(), behavior); } } List <string> lines = handler.GetFormatedLines(true); lines.ForEach(item => builder.AppendFormat(formatSpacer, item).AppendLine()); }