コード例 #1
0
        WebPubSubHub IOperationSource <WebPubSubHub> .CreateResult(Response response, CancellationToken cancellationToken)
        {
            using var document = JsonDocument.Parse(response.ContentStream);
            var data = WebPubSubHubData.DeserializeWebPubSubHubData(document.RootElement);

            return(new WebPubSubHub(_armClient, data));
        }
        internal static WebPubSubHubList DeserializeWebPubSubHubList(JsonElement element)
        {
            Optional <IReadOnlyList <WebPubSubHubData> > value = default;
            Optional <string> nextLink = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("value"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <WebPubSubHubData> array = new List <WebPubSubHubData>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(WebPubSubHubData.DeserializeWebPubSubHubData(item));
                    }
                    value = array;
                    continue;
                }
                if (property.NameEquals("nextLink"))
                {
                    nextLink = property.Value.GetString();
                    continue;
                }
            }
            return(new WebPubSubHubList(Optional.ToList(value), nextLink.Value));
        }
コード例 #3
0
        private async Task <WebPubSubHub> CreateDefaultWebPubSubHub(WebPubSubHubCollection collection, string name)
        {
            IList <Models.EventHandler> eventHandlers = new List <Models.EventHandler>()
            {
                new Models.EventHandler("http://example.com/api/{hub}/{event}")
                {
                    SystemEvents = { "none" },
                    Auth         = new UpstreamAuthSettings(),
                },
            };
            var webPubSubHubProperties = new WebPubSubHubProperties(eventHandlers, "Deny");
            WebPubSubHubData data      = new WebPubSubHubData(webPubSubHubProperties)
            {
            };
            var hub = await collection.CreateOrUpdateAsync(true, name, data);

            return(hub.Value);
        }