internal static PagedModelDataCollection DeserializePagedModelDataCollection(JsonElement element)
        {
            Optional <IReadOnlyList <ModelData> > value = default;
            Optional <string> nextLink = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("value"))
                {
                    List <ModelData> array = new List <ModelData>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(ModelData.DeserializeModelData(item));
                    }
                    value = array;
                    continue;
                }
                if (property.NameEquals("nextLink"))
                {
                    nextLink = property.Value.GetString();
                    continue;
                }
            }
            return(new PagedModelDataCollection(Optional.ToList(value), nextLink.Value));
        }
예제 #2
0
        // The modelUpdates parameter needs to be changed from IEnumerable<object> to IEnumerable<string>
        // and not parsed like a json object.
        public async Task <Response <IReadOnlyList <ModelData> > > AddAsync(IEnumerable <string> models = null, CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope("DigitalTwinModelsClient.Add");
            scope.Start();
            try
            {
                using HttpMessage message = CreateAddRequest(models);
                await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

                switch (message.Response.Status)
                {
                case 200:
                case 201:
                {
                    IReadOnlyList <ModelData> value = default;
                    using JsonDocument document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);

                    List <ModelData> array = new List <ModelData>(document.RootElement.GetArrayLength());
                    foreach (JsonElement item in document.RootElement.EnumerateArray())
                    {
                        array.Add(ModelData.DeserializeModelData(item));
                    }
                    value = array;
                    return(Response.FromValue(value, message.Response));
                }
        internal static PagedModelDataCollection DeserializePagedModelDataCollection(JsonElement element)
        {
            IReadOnlyList <ModelData> value = default;
            string nextLink = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("value"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <ModelData> array = new List <ModelData>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(ModelData.DeserializeModelData(item));
                        }
                    }
                    value = array;
                    continue;
                }
                if (property.NameEquals("nextLink"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    nextLink = property.Value.GetString();
                    continue;
                }
            }
            return(new PagedModelDataCollection(value, nextLink));
        }