/// <summary> /// To get list of telephone details /// </summary> /// <param name="primaryEntity"></param> /// <returns></returns> private AttributeCollection GetTelephoneDetails(Entity primaryEntity) { trace.Trace("GetTelephoneDetails - Start"); var attributes = new AttributeCollection(); attributes.AddRange(GetTelephone1Details(primaryEntity)); attributes.AddRange(GetTelephone2Details(primaryEntity)); attributes.AddRange(GetTelephone3Details(primaryEntity)); trace.Trace("GetTelephoneDetails - End"); return(attributes); }
/// <summary> /// To get selected attributes from entity image when any attribute was updated /// </summary> /// <param name="primaryEntity"></param> /// <param name="listOfAttributes"></param> /// <returns></returns> private AttributeCollection GetSelectedAttributesFromEntityImage(Entity primaryEntity, List <string> listOfAttributes) { trace.Trace("GetSelectedAttributesFromEntityImage - Start"); var attributes = new AttributeCollection(); if (primaryEntity == null || listOfAttributes == null || listOfAttributes.Count == 0) { return(attributes); } if (listOfAttributes.Any(a => primaryEntity.Attributes.Contains(a))) { var postImage = base.GetEntityImage(); attributes.AddRange(PrepareAttributesFromEntityImage(primaryEntity, postImage, listOfAttributes)); } trace.Trace("GetSelectedAttributesFromEntityImage - End"); return(attributes); }
public static AttributeCollection Copy(AttributeCollection source, ColumnSet columnSet = null) { if (source == null) { throw new ArgumentNullException(nameof(source)); } var attributeCopies = source.Select(Copy); if (columnSet != null && !columnSet.AllColumns) { attributeCopies = from copy in attributeCopies join column in columnSet.Columns on copy.Key equals column select copy; } var attributes = new AttributeCollection(); attributes.AddRange(attributeCopies); return(attributes); }
internal static T Unmock <T>(this object item) { if (item is MockOrgRequest request) { var collection = new ParameterCollection(); collection.AddRange(request.Parameters? .Select(e => new KeyValuePair <string, object>(e.Key, e.Value?.Unmock <object>())) ?? new KeyValuePair <string, object> [0]); return((T)(object) new OrganizationRequest { RequestName = request.Name, Parameters = collection }); } if (item is MockOrgResponse response) { var collection = new ParameterCollection(); collection.AddRange(response.Results? .Select(e => new KeyValuePair <string, object>(e.Key, e.Value?.Unmock <object>())) ?? new KeyValuePair <string, object> [0]); return((T)(object) new OrganizationResponse { ResponseName = response.Name, Results = collection }); } if (item is MockEntity entity) { var attributes = new AttributeCollection(); attributes.AddRange(entity.Attributes? .Select(e => new KeyValuePair <string, object>(e.Key, e.Value?.Unmock <object>())) ?? new KeyValuePair <string, object> [0]); var keys = new KeyAttributeCollection(); keys.AddRange(entity.Keys? .Select(e => new KeyValuePair <string, object>(e.Key, e.Value?.Unmock <object>())) ?? new KeyValuePair <string, object> [0]); return((T)(object) new Entity(entity.LogicalName, entity.Id) { Attributes = attributes, KeyAttributes = keys }); } if (item is MockEntityReference entityReference) { var keys = new KeyAttributeCollection(); keys.AddRange(entityReference.Keys? .Select(e => new KeyValuePair <string, object>(e.Key, e.Value?.Unmock <object>())) ?? new KeyValuePair <string, object> [0]); return((T)(object) new EntityReference(entityReference.LogicalName, entityReference.Id) { KeyAttributes = keys }); } if (item is MockEntityCollection entityCollection) { return((T)(object)new EntityCollection(entityCollection.Collection?.Select(e => e?.Unmock <Entity>()).ToList())); } if (item is MockEntityReferenceCollection entityReferenceCollection) { return((T)(object)new EntityReferenceCollection(entityReferenceCollection.Collection? .Select(e => e?.Unmock <EntityReference>()).ToList())); } if (item is MockColumnSet columnSet) { return((T)(object)(columnSet.Columns == null ? new ColumnSet(columnSet.AllColumns) : new ColumnSet(columnSet.Columns) { AllColumns = columnSet.AllColumns })); } return((T)item); }
/// /// Pack the translations into the name field when a Bilingual Item is Created or Updated /// Each translated name is packed into a pipe separated string /// This field is unpacked when the Bilingual Item entity is retrieved or related records are retrieved /// protected void PackTranslations(LocalPluginContext localContext) { if (!(localContext.PluginExecutionContext.InputParameters[InputParameter.Target] is Entity target)) { return; } Entity preImage = null; if (localContext.PluginExecutionContext.PreEntityImages.ContainsKey(PreImageAlias)) { preImage = localContext.PluginExecutionContext.PreEntityImages[PreImageAlias]; } var attributes = new AttributeCollection(); attributes.AddRange(target.Attributes); if (preImage != null) { attributes.AddRange(preImage.Attributes.Where(a => !attributes.ContainsKey(a.Key))); } // Check if the entity supports translations if (!attributes.TryGetValue(IsLocalizableAttribute, out _)) { return; } // Get the attributes for the current entity var response = localContext.OrganizationService.Execute( new RetrieveEntityRequest() { EntityFilters = EntityFilters.Attributes, LogicalName = localContext.PluginExecutionContext.PrimaryEntityName } ) as RetrieveEntityResponse; if (response == null) { return; } // Filter valid attributes var entityAttributes = response.EntityMetadata.Attributes .Where(a => a.AttributeType == AttributeTypeCode.String || a.AttributeType == AttributeTypeCode.Memo) .Select(a => a.LogicalName) .ToArray(); var translatedAttributes = entityAttributes.Where(a => LanguageSuffixes.Values.All(s => entityAttributes.Contains($"{a}{s}"))).ToArray(); foreach (var attribute in translatedAttributes) { var translations = new List <object>(); foreach (var suffix in LanguageSuffixes.Values) { var translatedAttribute = $"{attribute}{suffix}"; attributes.TryGetValue(translatedAttribute, out var translation); translations.Add(translation ?? string.Empty); } target[attribute] = $"{Prefix}{string.Join(Separator, translations)}"; } }