Пример #1
0
        /// <summary>set topics field</summary>
        /// <param name="args">
        /// REQUEST: [14, msgId, path, fieldName, value]
        /// RESPONSE: [3, msgId, success, [errorMsg] ]
        /// </param>
        private void SetField(EsMessage msg)
        {
            if (msg.Count != 5 || !msg[1].IsNumber || msg[2].ValueType != JSC.JSValueType.String || msg[3].ValueType != JSC.JSValueType.String)
            {
                if (_basePl.verbose)
                {
                    Log.Warning("Syntax error: {0}", msg);
                }
                return;
            }
            Topic t = Topic.root.Get(msg[2].Value as string, false, _owner);

            if (t != null)
            {
                if (t.TrySetField(msg[3].Value as string, msg[4], _owner))
                {
                    msg.Response(3, msg[1], true);
                }
                else
                {
                    msg.Response(3, msg[1], false, "FieldAccessError");
                }
            }
            else
            {
                msg.Response(3, msg[1], false, "TopicNotExist");
            }
        }
Пример #2
0
        /// <summary>set topics state</summary>
        /// <param name="args">
        /// REQUEST: [6, msgId, path, value]
        /// RESPONSE: [3, msgId, success, [errorMsg] ]
        /// </param>
        private void SetState(EsMessage msg)
        {
            if (msg.Count != 4 || !msg[1].IsNumber || msg[2].ValueType != JSC.JSValueType.String)
            {
                if (_basePl.verbose)
                {
                    Log.Warning("Syntax error: {0}", msg);
                }
                return;
            }
            string path = msg[2].Value as string;

            Topic t = Topic.root.Get(path, false, _owner);

            if (t != null)
            {
                t.SetState(msg[3], _owner);
                msg.Response(3, msg[1], true);
            }
            else
            {
                msg.Response(3, msg[1], false, "TopicNotExist");
            }
        }
Пример #3
0
        /// <summary>Subscribe topics</summary>
        /// <param name="args">
        /// REQUEST:  [4, msgId, path, mask], mask: 1 - data, 2 - children
        /// RESPONSE: [3, msgId, success, exist]
        /// </param>
        private void Subscribe(EsMessage msg)
        {
            if (msg.Count != 4 || !msg[1].IsNumber || msg[2].ValueType != JSC.JSValueType.String || !msg[3].IsNumber)
            {
                if (_basePl.verbose)
                {
                    Log.Warning("Syntax error: {0}", msg);
                }
                return;
            }
            Topic parent = Topic.root.Get(msg[2].Value as string, false, _owner);

            if (parent != null)
            {
                var sr1 = parent.Subscribe(SubRec.SubMask.Value | SubRec.SubMask.Field | SubRec.SubMask.Once | SubRec.SubMask.Chldren, string.Empty, _subCB);
                lock (_subscriptions) {
                    _subscriptions.Add(new Tuple <SubRec, EsMessage>(sr1, msg));
                }
            }
            else
            {
                msg.Response(3, msg[1], true, false);
            }
        }