Пример #1
0
        public static new AzureResource FromJsonElement(JsonElement element)
        {
            NetworkSecurityGroup resource = new NetworkSecurityGroup();

            resource.Description = element;

            // basic information
            resource.ID       = element.GetProperty("id").GetString();
            resource.Name     = element.GetProperty("name").GetString();
            resource.Type     = element.GetProperty("type").GetString();
            resource.Location = element.GetProperty("location").GetString();

            JsonElement properties = element.GetProperty("properties");

            ArrayEnumerator e = properties.GetProperty("securityRules").EnumerateArray();

            while (e.MoveNext())
            {
                NetworkSecurityRule rule = NetworkSecurityRule.FromJsonElement(e.Current) as NetworkSecurityRule;
                resource.Rules.Add(rule);
            }

            JsonElement subnets;

            if (properties.TryGetProperty("subnets", out subnets))
            {
                ArrayEnumerator subnetEnum = subnets.EnumerateArray();
                while (subnetEnum.MoveNext())
                {
                    string subnetId = subnetEnum.Current.GetProperty("id").GetString();
                    // I only want the name, strip the rest
                    string[] parts = subnetId.Split('/');
                    resource.Subnets.Add(parts[parts.Length - 1]);
                }
            }

            return(resource);
        }
Пример #2
0
        public static new AzureResource FromJsonElement(JsonElement element)
        {
            NetworkSecurityRule resource = new NetworkSecurityRule();

            resource.Description = element;

            resource.Name = element.GetProperty("name").GetString();

            JsonElement properties = element.GetProperty("properties");

            resource.Protocol = properties.GetProperty("protocol").GetString();

            try
            {
                resource.SourcePortRange = properties.GetProperty("sourcePortRange").GetString();
            }
            catch
            {
            }

            try
            {
                resource.DestinationPortRange = properties.GetProperty("destinationPortRange").GetString();
            }
            catch
            {
            }

            try
            {
                resource.SourceAddressPrefix = properties.GetProperty("sourceAddressPrefix").GetString();
            }
            catch
            {
            }

            try
            {
                resource.DestinationAddressPrefix = properties.GetProperty("destinationAddressPrefix").GetString();
            }
            catch
            {
            }

            resource.Access    = properties.GetProperty("access").GetString();
            resource.Priority  = properties.GetProperty("priority").GetInt32();
            resource.Direction = properties.GetProperty("direction").GetString();

            var e = properties.GetProperty("sourcePortRanges").EnumerateArray();

            while (e.MoveNext())
            {
                resource.SourcePortRanges.Add(e.Current.GetString());
            }

            e = properties.GetProperty("destinationPortRanges").EnumerateArray();
            while (e.MoveNext())
            {
                resource.DestinationPortRanges.Add(e.Current.GetString());
            }

            e = properties.GetProperty("sourceAddressPrefixes").EnumerateArray();
            while (e.MoveNext())
            {
                resource.SourceAddressPrefixes.Add(e.Current.GetString());
            }

            e = properties.GetProperty("destinationAddressPrefixes").EnumerateArray();
            while (e.MoveNext())
            {
                resource.DestinationAddressPrefixes.Add(e.Current.GetString());
            }

            return(resource);
        }