Example #1
0
 public TopicField(DTopic t, string fPath, JSC.JSValue value)
 {
     _topic = t;
     _fPath = fPath;
     _value = value;
     _tcs   = new TaskCompletionSource <JSC.JSValue>();
 }
Example #2
0
 public TopicReq(DTopic cur, string path)
 {
     this._cur    = cur;
     this._path   = path;
     this._create = false;
     this._tcs    = new TaskCompletionSource <DTopic>();
 }
Example #3
0
 private DTopic(DTopic parent, string name)
 {
     this.parent     = parent;
     this.Connection = this.parent.Connection;
     this.name       = name;
     this.path       = this.parent == Connection.root ? ("/" + name) : (this.parent.path + "/" + name);
 }
Example #4
0
 private void ChangedReise(Art art, DTopic src)
 {
     if (changed != null && App.mainWindow != null)
     {
         App.mainWindow.Dispatcher.BeginInvoke(changed, System.Windows.Threading.DispatcherPriority.DataBind, art, src);
     }
 }
Example #5
0
        private void RemoveChild(DTopic t)
        {
            if (_children == null)
            {
                return;
            }
            int min = 0, max = _children.Count - 1, cmp, mid = 0;

            while (min <= max)
            {
                mid = (min + max) / 2;
                cmp = string.Compare(_children[mid].name, t.name);
                if (cmp < 0)
                {
                    min = mid + 1;
                    mid = min;
                }
                else if (cmp > 0)
                {
                    max = mid - 1;
                    mid = max;
                }
                else
                {
                    _children.RemoveAt(mid);
                    t.ChangedReise(Art.RemoveChild, t);
                    ChangedReise(Art.RemoveChild, t);
                    break;
                }
            }
            if (!_children.Any())
            {
                _children = null;
            }
        }
Example #6
0
 private void TypeLoaded(Art a, DTopic t)
 {
     if (a == Art.type && t == _cur && !_cur._typeLoading)
     {
         _cur.changed -= TypeLoaded;
         _tcs.SetResult(_cur);
     }
 }
Example #7
0
 private void _typeTopic_changed(DTopic.Art art, DTopic t)
 {
     if (art == Art.value)
     {
         ProtoDeep(_manifest, (_typeTopic == null || _typeTopic.State.ValueType != JSC.JSValueType.Object) ? null : _typeTopic.State.ToObject());
         ChangedReise(Art.type, this);
     }
 }
Example #8
0
 public TopicReq(DTopic cur, string path, JSC.JSValue st, JSC.JSValue manifest)
 {
     this._cur      = cur;
     this._path     = path;
     this._create   = true;
     this._state    = st;
     this._manifest = manifest;
     this._tcs      = new TaskCompletionSource <DTopic>();
 }
Example #9
0
 private void TypeLoaded(Task <DTopic> td)
 {
     if (td.IsCompleted && !td.IsFaulted && td.Result != null)
     {
         _typeTopic          = td.Result;
         _typeTopic.changed += _typeTopic_changed;
     }
     _typeLoading = false;
     _typeTopic_changed(Art.value, _typeTopic);
 }
Example #10
0
 private void LoadCoreTypes(Task <DTopic> tt)
 {
     if (!tt.IsFaulted && tt.IsCompleted && tt.Result != null)
     {
         this.CoreTypes = tt.Result;
         foreach (var t in CoreTypes.children)
         {
             t.GetAsync(null);
         }
     }
 }
Example #11
0
 public Client(string server, int port, string userName, string password, string alias = null)
 {
     this.server   = server;
     this.port     = port;
     this.userName = userName;
     this.password = password;
     this.alias    = alias;
     _connEvnt     = new List <WaitConnect>();
     _reqs         = new LinkedList <ClRequest>();
     root          = new DTopic(this);
 }
Example #12
0
            public ClientEvent(DTopic root, string path, int cmd, JSC.JSValue p1, JSC.JSValue p2)
            {
                if (root == null)
                {
                    throw new ArgumentNullException("root");
                }
                if (path == null)
                {
                    throw new ArgumentNullException("path");
                }

                _root = root;
                _path = path;
                _cmd  = cmd;
                _p1   = p1;
                _p2   = p2;
            }
Example #13
0
        private void SetChild(DTopic t)
        {
            if (_children == null)
            {
                _children = new List <DTopic>();
            }
            int cmp, mid;

            for (mid = _children.Count - 1; mid >= 0; mid--)
            {
                cmp = string.Compare(_children[mid].name, t.name);
                if (cmp == 0)
                {
                    _children[mid] = t;
                    return;
                }
                if (cmp < 0)
                {
                    break;
                }
            }
            this._children.Insert(mid + 1, t);
        }
Example #14
0
        private DTopic GetChild(string cName, bool create)
        {
            if (_children == null)
            {
                if (create)
                {
                    _children = new List <DTopic>();
                }
                else
                {
                    return(null);
                }
            }
            int cmp, mid;

            for (mid = _children.Count - 1; mid >= 0; mid--)
            {
                cmp = string.Compare(_children[mid].name, cName);
                if (cmp == 0)
                {
                    return(_children[mid]);
                }
                if (cmp < 0)
                {
                    break;
                }
            }

            if (create)
            {
                var t = new DTopic(this, cName);
                this._children.Insert(mid + 1, t);
                ChangedReise(Art.addChild, t);
                return(t);
            }
            return(null);
        }
Example #15
0
            public void Process()
            {
                var    ps = _path.Split(PATH_SEPARATOR, StringSplitOptions.RemoveEmptyEntries);
                DTopic cur = _root, next;
                bool   noCreation = (_cmd == 12 && _p1 == null && _p2 == null) || (_cmd == 10 && _p1 != null && _p1.ValueType == JSC.JSValueType.String && _p2 != null && _p2.ValueType == JSC.JSValueType.String);

                for (int i = 0; i < ps.Length; i++)
                {
                    next = cur.GetChild(ps[i], !noCreation);
                    if (next == null) // Topic not exist
                    {
                        return;
                    }
                    cur = next;
                }
                if (noCreation)
                {
                    if (_cmd == 10) // move
                    {
                        DTopic parent = _root;
                        ps = (_p1.Value as string).Split(PATH_SEPARATOR, StringSplitOptions.RemoveEmptyEntries); //-V3095
                        for (int i = 0; i < ps.Length; i++)
                        {
                            next = parent.GetChild(ps[i], false);
                            if (next == null) // Topic not exist
                            {
                                return;
                            }
                            parent = next;
                        }
                        next            = new DTopic(parent, _p2.Value as string); //-V3095
                        next._children  = cur._children;
                        next._state     = cur._state;
                        next._manifest  = cur._manifest;
                        next._typeTopic = cur._typeTopic;

                        cur.parent.ChangedReise(Art.RemoveChild, cur);
                        cur.parent._children.Remove(cur);

                        parent.SetChild(next);
                        next.UpdatePath();
                        parent.ChangedReise(Art.addChild, next);
                    }
                    else if (_cmd == 12) // delete
                    {
                        cur._disposed = true;
                        var parent = cur.parent;
                        if (parent != null)
                        {
                            parent.RemoveChild(cur);
                            cur.ChangedReise(Art.RemoveChild, cur);
                            parent.ChangedReise(Art.RemoveChild, cur);
                        }
                    }
                }
                else
                {
                    if (_p1 != null)
                    {
                        cur.ValuePublished(_p1);
                    }
                    if (_p2 != null)
                    {
                        cur.ManifestPublished(_p2);
                    }
                }
            }
Example #16
0
 public TopicPublish(DTopic t, JSC.JSValue value)
 {
     _topic = t;
     _value = value;
     _tcs   = new TaskCompletionSource <bool>();
 }
Example #17
0
            public void Process()
            {
                int idx1 = _cur.path.Length;

                if (idx1 > 1)
                {
                    idx1++;
                }
                if (_path == null || _path.Length <= _cur.path.Length)
                {
                    if (_cur._disposed)
                    {
                        _tcs.SetResult(null);
                        lock (_cur) {
                            _cur._req = null;
                            if (this._reqs != null)
                            {
                                foreach (var r in _reqs)
                                {
                                    App.PostMsg(r);
                                }
                            }
                        }
                    }
                    else if (_cur._state != null)
                    {
                        if (_cur._typeLoading)
                        {
                            _cur.changed += TypeLoaded;
                        }
                        else
                        {
                            _tcs.SetResult(_cur);
                        }
                        lock (_cur) {
                            _cur._req = null;
                            if (this._reqs != null)
                            {
                                foreach (var r in _reqs)
                                {
                                    App.PostMsg(r);
                                }
                            }
                        }
                    }
                    else
                    {
                        lock (_cur) {
                            if (_cur._req != null && _cur._req != this) //-V3054
                            {
                                if (_cur._req._reqs == null)
                                {
                                    _cur._req._reqs = new List <TopicReq>();
                                }
                                _cur._req._reqs.Add(this);
                                return;
                            }
                            else
                            {
                                _cur._req = this;
                            }
                        }
                        _cur.Connection.SendReq(4, this, _cur.path, 3);
                    }
                    return;
                }
                DTopic next = null;
                int    idx2 = _path.IndexOf('/', idx1);

                if (idx2 < 0)
                {
                    idx2 = _path.Length;
                }
                string name = _path.Substring(idx1, idx2 - idx1);

                if (_cur._children == null && _cur._state == null)
                {
                    lock (_cur) {
                        if (_cur._req != null && _cur._req != this) //-V3054
                        {
                            if (_cur._req._reqs == null)
                            {
                                _cur._req._reqs = new List <TopicReq>();
                            }
                            _cur._req._reqs.Add(this);
                            return;
                        }
                        else
                        {
                            _cur._req = this;
                        }
                    }
                    _cur.Connection.SendReq(4, this, _cur.path, 3);
                    return;
                }
                next = _cur.GetChild(name, false);
                if (next == null)
                {
                    if (_create)
                    {
                        _create = false;
                        if (_path.Length <= idx2 && _state != null)
                        {
                            _cur.Connection.SendReq(8, this, _path.Substring(0, idx2), _state, _manifest);
                        }
                        else
                        {
                            _cur.Connection.SendReq(8, this, _path.Substring(0, idx2));
                        }
                    }
                    else
                    {
                        _tcs.SetResult(null);
                        lock (_cur) {
                            _cur._req = null;
                            if (this._reqs != null)
                            {
                                foreach (var r in _reqs)
                                {
                                    App.PostMsg(r);
                                }
                            }
                        }
                    }
                    return;
                }
                _cur = next;
                App.PostMsg(this);
            }
Example #18
0
 public void Move(DTopic nParent, string nName)
 {
     Connection.SendReq(10, null, this.path, nParent.path, nName);
 }