internal static Trigger DeserializeTrigger(JsonElement element)
        {
            if (element.TryGetProperty("type", out JsonElement discriminator))
            {
                switch (discriminator.GetString())
                {
                case "BlobEventsTrigger": return(BlobEventsTrigger.DeserializeBlobEventsTrigger(element));

                case "BlobTrigger": return(BlobTrigger.DeserializeBlobTrigger(element));

                case "ChainingTrigger": return(ChainingTrigger.DeserializeChainingTrigger(element));

                case "MultiplePipelineTrigger": return(MultiplePipelineTrigger.DeserializeMultiplePipelineTrigger(element));

                case "RerunTumblingWindowTrigger": return(RerunTumblingWindowTrigger.DeserializeRerunTumblingWindowTrigger(element));

                case "ScheduleTrigger": return(ScheduleTrigger.DeserializeScheduleTrigger(element));

                case "TumblingWindowTrigger": return(TumblingWindowTrigger.DeserializeTumblingWindowTrigger(element));
                }
            }
            string            type        = default;
            Optional <string> description = default;
            Optional <TriggerRuntimeState> runtimeState                   = default;
            Optional <IList <object> >     annotations                    = default;
            IDictionary <string, object>   additionalProperties           = default;
            Dictionary <string, object>    additionalPropertiesDictionary = new Dictionary <string, object>();

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("description"))
                {
                    description = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("runtimeState"))
                {
                    runtimeState = new TriggerRuntimeState(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("annotations"))
                {
                    List <object> array = new List <object>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetObject());
                    }
                    annotations = array;
                    continue;
                }
                additionalPropertiesDictionary.Add(property.Name, property.Value.GetObject());
            }
            additionalProperties = additionalPropertiesDictionary;
            return(new Trigger(type, description.Value, Optional.ToNullable(runtimeState), Optional.ToList(annotations), additionalProperties));
        }
示例#2
0
        internal static Trigger DeserializeTrigger(JsonElement element)
        {
            if (element.TryGetProperty("type", out JsonElement discriminator))
            {
                switch (discriminator.GetString())
                {
                case "MultiplePipelineTrigger": return(MultiplePipelineTrigger.DeserializeMultiplePipelineTrigger(element));

                case "RerunTumblingWindowTrigger": return(RerunTumblingWindowTrigger.DeserializeRerunTumblingWindowTrigger(element));
                }
            }
            string type        = default;
            string description = default;
            TriggerRuntimeState?         runtimeState                   = default;
            IList <object>               annotations                    = default;
            IDictionary <string, object> additionalProperties           = default;
            Dictionary <string, object>  additionalPropertiesDictionary = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("description"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    description = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("runtimeState"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    runtimeState = new TriggerRuntimeState(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("annotations"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <object> array = new List <object>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(item.GetObject());
                        }
                    }
                    annotations = array;
                    continue;
                }
                additionalPropertiesDictionary ??= new Dictionary <string, object>();
                if (property.Value.ValueKind == JsonValueKind.Null)
                {
                    additionalPropertiesDictionary.Add(property.Name, null);
                }
                else
                {
                    additionalPropertiesDictionary.Add(property.Name, property.Value.GetObject());
                }
            }
            additionalProperties = additionalPropertiesDictionary;
            return(new Trigger(type, description, runtimeState, annotations, additionalProperties));
        }