Ejemplo n.º 1
0
        internal static SipConfiguration DeserializeSipConfiguration(JsonElement element)
        {
            Optional <IReadOnlyDictionary <string, SipTrunk> > trunks = default;
            Optional <IReadOnlyList <SipTrunkRoute> >          routes = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("trunks"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    Dictionary <string, SipTrunk> dictionary = new Dictionary <string, SipTrunk>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.Value.ValueKind == JsonValueKind.Null)
                        {
                            dictionary.Add(property0.Name, null);
                        }
                        else
                        {
                            var sipTrunk = SipTrunk.DeserializeSipTrunk(property0.Value);
                            sipTrunk.Fqdn = property0.Name;
                            dictionary.Add(property0.Name, sipTrunk);
                        }
                    }
                    trunks = dictionary;
                    continue;
                }
                if (property.NameEquals("routes"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }

                    List <SipTrunkRoute> array = new List <SipTrunkRoute>();

                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(SipTrunkRoute.DeserializeSipTrunkRoute(item));
                    }
                    routes = array;
                    continue;
                }
            }
            return(new SipConfiguration(Optional.ToDictionary(trunks), Optional.ToList(routes)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Set <see cref="SipTrunk"/> for resource. Other configuration settings are not affected.
        /// </summary>
        /// <param name="trunk">SIP trunk configuration.</param>
        /// <param name="cancellationToken">Optional cancellation token.</param>
        public virtual Response SetTrunk(
            SipTrunk trunk,
            CancellationToken cancellationToken = default)
        {
            var config = new SipConfiguration(new Dictionary <string, SipTrunk> {
                { trunk.Fqdn, trunk }
            });

            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SipRoutingClient)}.{nameof(SetTrunk)}");
            scope.Start();
            try
            {
                var response = _restClient.PatchSipConfiguration(config, cancellationToken);
                return(response.GetRawResponse());
            }
            catch (Exception ex)
            {
                scope.Failed(ex);
                throw;
            }
        }