コード例 #1
0
        /// <summary>
        /// Detects if this Identity is equals to another Identity instance.
        /// </summary>
        /// <param name="other"> Identity object to compare. </param>
        /// <returns> True if they are equal, otherwise False. </returns>
        public bool Equals(ResourceIdentity other)
        {
            if (ReferenceEquals(other, null))
            {
                return(false);
            }

            if (UserAssignedIdentities.Count == other.UserAssignedIdentities.Count)
            {
                foreach (var identity in UserAssignedIdentities)
                {
                    UserAssignedIdentity value;
                    if (other.UserAssignedIdentities.TryGetValue(identity.Key, out value))
                    {
                        if (!UserAssignedIdentity.Equals(identity.Value, value))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            return(SystemAssignedIdentity.Equals(SystemAssignedIdentity, other.SystemAssignedIdentity));
        }
        internal static ManagedServiceIdentity DeserializeManagedServiceIdentity(JsonElement element)
        {
            Optional <ManagedServiceIdentityType> type = default;
            Optional <IDictionary <string, UserAssignedIdentity> > userAssignedIdentities = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("type"))
                {
                    type = new ManagedServiceIdentityType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("userAssignedIdentities"))
                {
                    Dictionary <string, UserAssignedIdentity> dictionary = new Dictionary <string, UserAssignedIdentity>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, UserAssignedIdentity.DeserializeUserAssignedIdentity(property0.Value));
                    }
                    userAssignedIdentities = dictionary;
                    continue;
                }
            }
            return(new ManagedServiceIdentity(Optional.ToNullable(type), Optional.ToDictionary(userAssignedIdentities)));
        }
コード例 #3
0
        /// <summary>
        /// Converts a <see cref="JsonElement"/> into an <see cref="ResourceIdentity"/> object.
        /// </summary>
        /// <param name="element"> A <see cref="JsonElement"/> containing an <see cref="ResourceIdentity"/>. </param>
        /// <returns> New Identity object with JSON values. </returns>
        internal static ResourceIdentity DeserializeResourceIdentity(JsonElement element)
        {
            if (element.ValueKind == JsonValueKind.Undefined)
            {
                throw new ArgumentException("JsonElement cannot be undefined ", nameof(element));
            }

            Optional <SystemAssignedIdentity> systemAssignedIdentity = default;
            IDictionary <ResourceIdentifier, UserAssignedIdentity> userAssignedIdentities = new Dictionary <ResourceIdentifier, UserAssignedIdentity>();
            string type = string.Empty;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("userAssignedIdentities"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        userAssignedIdentities = null;
                        continue;
                    }

                    string resourceId = string.Empty;
                    foreach (var keyValuePair in property.Value.EnumerateObject())
                    {
                        resourceId = keyValuePair.Name;
                        var userAssignedIdentity = UserAssignedIdentity.DeserializeUserAssignedIdentity(keyValuePair.Value);
                        userAssignedIdentities.Add(new ResourceIdentifier(resourceId), userAssignedIdentity);
                    }

                    continue;
                }

                if (property.NameEquals("type"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        throw new InvalidOperationException("The type property had a JsonValueKind equal to Null");
                    }

                    type = property.Value.GetString();
                }

                if (type.Equals(SystemAssigned))
                {
                    systemAssignedIdentity = SystemAssignedIdentity.DeserializeSystemAssignedIdentity(element);
                    continue;
                }

                if (type.Equals(SystemAndUserAssigned))
                {
                    systemAssignedIdentity = SystemAssignedIdentity.DeserializeSystemAssignedIdentity(element);
                    continue;
                }
            }

            return(new ResourceIdentity(systemAssignedIdentity, userAssignedIdentities));
        }
コード例 #4
0
        internal static ManagedServiceIdentity DeserializeManagedServiceIdentity(JsonElement element)
        {
            string type = default;
            IDictionary <string, UserAssignedIdentity> userAssignedIdentities = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("type"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    type = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("userAssignedIdentities"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    Dictionary <string, UserAssignedIdentity> dictionary = new Dictionary <string, UserAssignedIdentity>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.Value.ValueKind == JsonValueKind.Null)
                        {
                            dictionary.Add(property0.Name, null);
                        }
                        else
                        {
                            dictionary.Add(property0.Name, UserAssignedIdentity.DeserializeUserAssignedIdentity(property0.Value));
                        }
                    }
                    userAssignedIdentities = dictionary;
                    continue;
                }
            }
            return(new ManagedServiceIdentity(type, userAssignedIdentities));
        }