Пример #1
0
        private async Task InvokeMethod(JObject request)
        {
            var node = SuperRoot.Get(request["path"].Value <string>());

            if (node?.ActionHandler != null)
            {
                if (request["permit"] == null || request["permit"].Value <string>().Equals(node.ActionHandler.Permission.ToString()))
                {
                    JArray columns;
                    if (node.Configs.Has(ConfigType.Columns))
                    {
                        columns = node.Configs.Get(ConfigType.Columns).JArray;
                    }
                    else
                    {
                        columns = new JArray();
                    }
                    var permit        = (request["permit"] != null) ? Permission.PermissionMap[request["permit"].Value <string>().ToLower()] : null;
                    var invokeRequest = new InvokeRequest(request["rid"].Value <int>(), request["path"].Value <string>(),
                                                          permit, request["params"].Value <JObject>(), link: Link,
                                                          columns: columns);
                    await Task.Run(() => node.ActionHandler.Function.Invoke(invokeRequest));
                }
            }
        }
Пример #2
0
        private void SetMethod(JArray responses, JObject request)
        {
            var node = SuperRoot.Get(request["path"].Value <string>());

            if (node != null)
            {
                if (request["permit"] == null ||
                    request["permit"].Value <string>().Equals(node.Configs.Get(ConfigType.Writable).String))
                {
                    node.Value.Set(request["value"]);
                    node.Value.InvokeRemoteSet();
                    responses.Add(new JObject
                    {
                        new JProperty("rid", request["rid"].Value <int>()),
                        new JProperty("stream", "closed")
                    });
                }
            }
        }
Пример #3
0
        private void SubscribeMethod(JArray responses, JObject request)
        {
            foreach (var pair in request["paths"].Value <JArray>())
            {
                var pathToken = pair["path"];
                var sidToken  = pair["sid"];
                if (pathToken == null || sidToken == null || pathToken.Type != JTokenType.String ||
                    sidToken.Type != JTokenType.Integer)
                {
                    continue;
                }
                var node = SuperRoot.Get(pathToken.Value <string>());
                if (node == null)
                {
                    continue;
                }
                var sid = sidToken.Value <int>();
                SubscriptionManager.Subscribe(sid, node);
                responses.Add(new JObject
                {
                    new JProperty("rid", 0),
                    new JProperty("updates", new JArray
                    {
                        new JArray
                        {
                            sid,
                            node.Value.JToken,
                            node.Value.LastUpdated
                        }
                    })
                });
            }

            responses.Add(new JObject
            {
                new JProperty("rid", request["rid"].Value <int>()),
                new JProperty("stream", "closed")
            });
        }
Пример #4
0
        private void ListMethod(JArray responses, JObject request)
        {
            var requestId = request["rid"].Value <int>();
            var value     = request["path"].Value <string>();

            var node = SuperRoot.Get(value);

            if (node != null)
            {
                StreamManager.OpenStream(requestId, node);
                responses.Add(new JObject
                {
                    new JProperty("rid", requestId),
                    new JProperty("stream", "open"),
                    new JProperty(
                        "updates",
                        SubscriptionManager.SerializeUpdates(
                            SuperRoot.Get(value)
                            )
                        )
                });
            }
            else
            {
                responses.Add(new JObject
                {
                    new JProperty("rid", requestId),
                    new JProperty("stream", "open"),
                    new JProperty(
                        "updates",
                        SubscriptionManager.SerializeUpdates(
                            new Node("", null, null)
                            )
                        )
                });
            }
        }