Esempio n. 1
0
        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);
        }
        /// <summary>
        /// Retrieve an Entity Key Metadata record 
        /// </summary>
        /// <param name="service"></param>
        /// <param name="config"></param>
        /// <param name="entity"></param>
        /// <param name="retrieveAsIfPublished"></param>
        /// <returns></returns>
        public static EntityKeyMetadata RetrieveEntityKey(IOrganizationService service, ConfigurationInfo config, EntityMetadata entity, bool retrieveAsIfPublished)
        {
            var req = new RetrieveEntityKeyRequest() {
                EntityLogicalName = entity.LogicalName,
                RetrieveAsIfPublished = true
            };

            var resp = service.Execute(req) as RetrieveEntityKeyResponse;
            return resp.EntityKeyMetadata;
        }
Esempio n. 3
0
        public static EntityKeyMetadata GetEntityKeyMetadata(IOrganizationService service, string entityLogicalName, Guid objectId)
        {
            RetrieveEntityKeyRequest attributeRequest = new RetrieveEntityKeyRequest
            {
                MetadataId            = objectId,
                RetrieveAsIfPublished = true,
                EntityLogicalName     = entityLogicalName,
            };
            RetrieveEntityKeyResponse attributeResponse =
                (RetrieveEntityKeyResponse)service.Execute(attributeRequest);

            return(attributeResponse.EntityKeyMetadata);
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        public EntityKeyMetadata GetEntityKeyMetadata(Guid idKey)
        {
            if (_dictKey.ContainsKey(idKey))
            {
                return(_dictKey[idKey]);
            }

            try
            {
                if (this._allMetadataDownloaded)
                {
                    return(null);
                }

                var request = new RetrieveEntityKeyRequest()
                {
                    MetadataId = idKey,
                };

                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.GetEntityKeyMetadataByGuidFormat1, idKey);

                return(null);
            }
        }