public TopicField(DTopic t, string fPath, JSC.JSValue value) { _topic = t; _fPath = fPath; _value = value; _tcs = new TaskCompletionSource <JSC.JSValue>(); }
public TopicReq(DTopic cur, string path) { this._cur = cur; this._path = path; this._create = false; this._tcs = new TaskCompletionSource <DTopic>(); }
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); }
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); } }
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; } }
private void TypeLoaded(Art a, DTopic t) { if (a == Art.type && t == _cur && !_cur._typeLoading) { _cur.changed -= TypeLoaded; _tcs.SetResult(_cur); } }
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); } }
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>(); }
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); }
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); } } }
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); }
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; }
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); }
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); }
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); } } }
public TopicPublish(DTopic t, JSC.JSValue value) { _topic = t; _value = value; _tcs = new TaskCompletionSource <bool>(); }
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); }
public void Move(DTopic nParent, string nName) { Connection.SendReq(10, null, this.path, nParent.path, nName); }