Exemplo n.º 1
0
        public Guid GetRecordUniqueId(EntityReference record)
        {
            if (string.IsNullOrWhiteSpace(record.LogicalName))
            {
                throw new InvalidOperationException("The entity logical name must not be null or empty.");
            }

            // Don't fail with invalid operation exception, if no record of this entity exists, but entity is known
            if (!Data.ContainsKey(record.LogicalName) && !EntityMetadata.ContainsKey(record.LogicalName))
            {
                if (ProxyTypesAssembly == null)
                {
                    throw new InvalidOperationException($"The entity logical name {record.LogicalName} is not valid.");
                }

                if (!ProxyTypesAssembly.GetTypes().Any(type => FindReflectedType(record.LogicalName) != null))
                {
                    throw new InvalidOperationException($"The entity logical name {record.LogicalName} is not valid.");
                }
            }

#if !FAKE_XRM_EASY && !FAKE_XRM_EASY_2013 && !FAKE_XRM_EASY_2015
            if (record.Id == Guid.Empty && record.HasKeyAttributes())
            {
                if (EntityMetadata.ContainsKey(record.LogicalName))
                {
                    var entityMetadata = EntityMetadata[record.LogicalName];
                    foreach (var key in entityMetadata.Keys)
                    {
                        if (record.KeyAttributes.Keys.Count == key.KeyAttributes.Length && key.KeyAttributes.All(x => record.KeyAttributes.Keys.Contains(x)))
                        {
                            var matchedRecord = Data[record.LogicalName].Values.SingleOrDefault(x => record.KeyAttributes.All(k => x.Attributes.ContainsKey(k.Key) && x.Attributes[k.Key] != null && x.Attributes[k.Key].Equals(k.Value)));
                            if (matchedRecord == null)
                            {
                                new FaultException <OrganizationServiceFault>(new OrganizationServiceFault(), $"{record.LogicalName} with the specified Alternate Keys Does Not Exist");
                            }
                            return(matchedRecord.Id);
                        }
                    }
                    throw new InvalidOperationException($"The requested key attributes do not exist for the entity {record.LogicalName}");
                }
                else
                {
                    throw new InvalidOperationException($"The requested key attributes do not exist for the entity {record.LogicalName}");
                }
            }
#endif

            /*
             * if (record.Id == Guid.Empty)
             * {
             *  throw new InvalidOperationException("The id must not be empty.");
             * }
             */

            return(record.Id);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Builds a text value that is unique to the connection values.
        /// </summary>
        /// <returns></returns>
        public string GetConnectionId()
        {
            var client = GetUserName(ClientCredentials);
            var device = GetUserName(DeviceCredentials);
            var proxy  = ProxyTypesAssembly != null?ProxyTypesAssembly.ToString() : null;

            var text = "ServiceUri={0};HomeRealmUri={1};UserName={2};DeviceId={3};ProxyTypesEnabled={4};ProxyTypesAssembly={5};CallerId={6};ServiceConfigurationInstanceMode={7};UserTokenExpiryWindow={8};".FormatWith(
                ServiceUri, HomeRealmUri, client, device, ProxyTypesEnabled, proxy, CallerId, ServiceConfigurationInstanceMode, UserTokenExpiryWindow);

            return(text);
        }