Example #1
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 #2
0
 public void Response(bool success, JSC.JSValue value)
 {
     if (success) // value == null after connect
     {
         if (value != null && (value.ValueType != JSC.JSValueType.Boolean || !((bool)value)))
         {
             _cur._disposed = true;
             var parent = _cur.parent;
             if (parent != null)
             {
                 parent.RemoveChild(_cur);
                 _cur.ChangedReise(Art.RemoveChild, _cur);
                 parent.ChangedReise(Art.RemoveChild, _cur);
             }
         }
     }
     else
     {
         _tcs.TrySetException(new ApplicationException((value == null ? "TopicReqError" : value.ToString())));
     }
 }
Example #3
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);
                    }
                }
            }