Esempio n. 1
0
        public AddNodeMessage(Type nodeType, NodeGraph graph, double posX, double posY, NodePin suggestionPin, params object[] constructorParameters)
        {
            if (!nodeType.IsSubclassOf(typeof(Node)) || nodeType.IsAbstract)
            {
                throw new ArgumentException("Invalid type for node");
            }

            if (nodeType == typeof(RerouteNode))
            {
                if (suggestionPin == null)
                {
                    throw new ArgumentException("Reroute needs template pin");
                }
            }
            else
            {
                var constructorParamTypes = new[] { graph.GetType() }
                .Concat(constructorParameters.Select(p => p.GetType()))
                .ToArray();

                if (nodeType.GetConstructor(constructorParamTypes) == null)
                {
                    throw new ArgumentException($"Invalid parameters for constructor of {nodeType.FullName}");
                }
            }

            NodeType              = nodeType;
            Graph                 = graph;
            PositionX             = posX;
            PositionY             = posY;
            SuggestionPin         = suggestionPin;
            ConstructorParameters = constructorParameters;
        }
Esempio n. 2
0
        private void DeleteTree(NodePin pin)
        {
            List <NodeHandle> children = new List <NodeHandle>();

            if (!pin.Ptr.IsLeaf)
            {
                for (int i = 0; i < pin.Ptr.Count; i++)
                {
                    children.Add(pin.Ptr[i].ChildNode);
                }
            }

            try
            {
                using (var trans = _storage.BeginTransaction())
                {
                    trans.Destroy(pin);
                    trans.Commit();
                }
            }
            finally
            {
                if (children.Count > 0)
                {
                    foreach (NodeHandle h in children)
                    {
                        using (NodePin ch = _storage.Lock(pin, h))
                        {
                            DeleteTree(ch);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        void Input_SelectPin(NodePin nodePin)
        {
            if (nodePin.IsInput)
            {
                _modifyingConnection = _graph.Helper.GetConnection(nodePin);

                if (_modifyingConnection != null)
                {
                    NodeEditor.Logger.Log <NodeEditorPinConnector>("Modifying a connection...");

                    _modifyingConnection.Hide();

                    _sourcePin = _modifyingConnection.SourcePin;

                    // Executes flow left to right so get the correct starting pin.
                    _view.EnterDrawState(_modifyingConnection.SourcePin);
                }
            }
            else
            {
                NodeEditor.Logger.Log <NodeEditorPinConnector>("Creating a new connection...");

                _sourcePin = nodePin;

                _view.EnterDrawState(nodePin);
            }
        }
        public static NodeEditorPinView Draw(NodePin pin, bool highlighted)
        {
            GUILayout.BeginHorizontal();

            // Hack to align the element to the right.
            if (!pin.IsInput)
            {
                GUILayout.FlexibleSpace();
            }

            Rect pinRect = new Rect();

            if (pin.IsInput)
            {
                pinRect = DrawPin(pin, highlighted);
                DrawLabel(pin);
            }
            else
            {
                DrawLabel(pin);
                pinRect = DrawPin(pin, highlighted);
            }

            GUILayout.EndHorizontal();

            return(new NodeEditorPinView(pin, pinRect));
        }
Esempio n. 5
0
            private void FinalizeCommit()
            {
                NodePin pin = _created;

                while (pin != null)
                {
                    pin.CommitChanges();
                    pin = (NodePin)pin.Next;
                }

                if (_parentItem != null)
                {
                    _parentItem.CommitChanges();
                }

                pin = _deleted;
                while (pin != null)
                {
                    pin.CommitChanges();
                    pin = (NodePin)pin.Next;
                }

                if (_deleted != null)
                {
                    _cache.AddVersion(_deleted);
                }

                if (_hasLogToken)
                {
                    _hasLogToken = false;
                    _cache.Options.LogFile.CommitTransaction(ref _logToken);
                }
            }
Esempio n. 6
0
            protected Node CreateRoot(NodeHandle rootHandle)
            {
                NodeHandle hChild;

                using (NodeTransaction t = BeginTransaction())
                {
                    using (NodePin child = t.Create(LockType.Insert, true))
                    {
                        hChild = child.Handle;
                        t.Commit();
                    }
                }

                object   refobj;
                RootNode rootNode = new RootNode(rootHandle.StoreHandle);

                ILockStrategy lck = CreateLock(rootHandle, out refobj);

                using (lck.Write(Options.LockTimeout))
                {
                    using (NodePin rootPin = new NodePin(rootHandle, lck, LockType.Insert, LockType.Insert, refobj, rootNode, null))
                        using (NodeTransaction t = BeginTransaction())
                        {
                            rootNode = (RootNode)t.BeginUpdate(rootPin);
                            rootNode.ReplaceChild(0, null, hChild);
                            t.Commit();
                        }
                }

                return(rootNode);
            }
Esempio n. 7
0
            public override void UpdateNode(NodePin node)
            {
                if (ReferenceEquals(node.Original, node.Ptr))
                {
                    return;
                }

                CacheEntry entry = node.Reference as CacheEntry;

                if (entry == null)
                {
                    throw new AssertionFailedException("Invalid node pin in update.");
                }

                if (node.IsDeleted)
                {
                    Assert(node.LockType != LockType.Read);
                    //With lockless-reads we leave instances in cache until GC collects, otherwise we could remove them.
                    //using (node.Lock.Write(Options.LockTimeout))
                    //    node.Original.Invalidate();
                    //entry.Node = null;
                }
                else if (node.Ptr.IsRoot && _root.Node == null)
                {
                    _root.Node = node.Ptr;
                }
                else
                {
                    Node old = Interlocked.CompareExchange(ref entry.Node, node.Ptr, node.Original);
                    Assert(ReferenceEquals(old, node.Original), "Node was modified without lock");
                }
            }
Esempio n. 8
0
        public void NewConnectionToThis(ScriptNodeConnection connection)
        {
            var     pinInfo = connection.InputPin;
            NodePin pinList;

            m_ToThisNodePin.TryGetValue(pinInfo.Name, out pinList);
            if (pinList == null)
            {
                pinList = new NodePin()
                {
                    Name   = new NameString(pinInfo.Name),
                    Type   = new NameString(pinInfo.PinType.Name),
                    LinkTo = new List <NodeLink>()
                };
            }

            if (pinList.LinkTo.Find(x => x.Connection == connection) == null)
            {
                var newPinInfo = new NodeLink()
                {
                    Connection = connection,
                    Target     = connection.InputElement.As <ScriptGraphNode>(),
                    Pin        = new NodePin()
                };
                pinList.LinkTo.Add(newPinInfo);
            }
        }
        private bool Update <T>(NodePin thisLock, TKey key, ref T value) where T : IUpdateValue <TKey, TValue>
        {
            NodePin pin;
            int     offset;

            if (Seek(thisLock, key, out pin, out offset))
            {
                using (pin)
                {
                    TValue newValue = pin.Ptr[offset].Payload;
                    if (value.UpdateValue(key, ref newValue))
                    {
                        using (NodeTransaction trans = _storage.BeginTransaction())
                        {
                            trans.BeginUpdate(pin);
                            pin.Ptr.SetValue(offset, key, newValue, _keyComparer);
                            trans.UpdateValue(key, newValue);
                            trans.Commit();
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 10
0
 public NodeEditorPinView(NodePin pin, Rect localRect)
 {
     Pin            = pin;
     LocalRect      = localRect;
     ScreenPosition = LocalRect.position + pin.Node.Position.ToVec2();
     ScreenRect     = new Rect(ScreenPosition.x, ScreenPosition.y, LocalRect.width, LocalRect.height);
 }
Esempio n. 11
0
 public RootLock(BPlusTree <TKey, TValue> tree, LockType type, bool exclusiveTreeAccess, string methodName)
 {
     tree.NotDisposed();
     _tree       = tree;
     _type       = type;
     _version    = type == LockType.Read ? tree._storage.CurrentVersion : null;
     _methodName = methodName;
     _exclusive  = exclusiveTreeAccess;
     _locked     = _exclusive ? _tree._selfLock.TryWrite(tree._options.LockTimeout) : _tree._selfLock.TryRead(tree._options.LockTimeout);
     LockTimeoutException.Assert(_locked);
     try
     {
         Pin = _tree._storage.LockRoot(type);
     }
     catch
     {
         if (_exclusive)
         {
             _tree._selfLock.ReleaseWrite();
         }
         else
         {
             _tree._selfLock.ReleaseRead();
         }
         throw;
     }
 }
        private void Print(NodePin node, TextWriter output, int depth, DebugFormat format)
        {
            bool   formatted = format != DebugFormat.Compact;
            string prefix    = formatted ? Environment.NewLine + new String(' ', depth << 1) : "";

            output.Write("{0}{{", formatted ? " " : "");
            if (formatted)
            {
                prefix += "  ";
            }

            for (int i = 0; i < node.Ptr.Count; i++)
            {
                if (i > 0 || node.Ptr[i].IsValue)
                {
                    output.Write("{0}{1}", prefix, node.Ptr[i].Key);
                }
                if (formatted && node.Ptr.IsLeaf)
                {
                    output.Write(" = {0}", node.Ptr[i].Payload);
                }
                if (format == DebugFormat.Full)
                {
                    output.Write(" (IsLeaf={0})", node.Ptr.IsLeaf);
                    output.Write(" (Count={0})", node.Ptr.Count);
                }

                if (node.Ptr[i].IsNode)
                {
                    using (NodePin child = _storage.Lock(node, node.Ptr[i].ChildNode))
                    {
                        Print(child, output, depth + 1, format);
#if DEBUG
                        if (format == DebugFormat.Full)
                        {
                            try { Validate(child, node, i, 1); }
                            catch (Exception ex)
                            {
                                output.WriteLine();
                                output.WriteLine("{0} Error = {1}", prefix, ex.Message);
                            }
                        }
#endif
                    }
                }
                else if (formatted)
                {
                    output.Write("={0}", node.Ptr[i].Payload);
                }
                if (i + 1 < node.Ptr.Count)
                {
                    output.Write(',');
                }
            }
            if (formatted)
            {
                prefix = prefix.Substring(0, prefix.Length - 2);
            }
            output.Write("{0}}}", prefix);
        }
 public override void UpdateNode(NodePin node)
 {
     if (node.IsDeleted)
     {
         using (_lock.Write(base.Options.LockTimeout))
             _list.Remove(node.Handle.StoreHandle);
     }
 }
Esempio n. 14
0
        public ConnectionViewModel(NodePin outputPinControl, NodePin inputPinControl)
        {
            this.OutputPinControl = outputPinControl;
            this.InputPinControl  = inputPinControl;

            OutputPinControl.PropertyChanged += PinOnPropertyChanged;
            InputPinControl.PropertyChanged  += PinOnPropertyChanged;
        }
Esempio n. 15
0
 public NodeEditorPinView GetPinView(NodePin pin)
 {
     if (HasNodeView(pin.Node))
     {
         return(_nodeViews[pin.Node].GetPinViewData(pin));
     }
     return(null);
 }
Esempio n. 16
0
 public Node BeginUpdate(NodePin pin)
 {
     Assert(pin.LockType != LockType.Read, "Node is not locked for update");
     Assert(_parentItem == null, "An update is already in this operation");
     _parentItem = pin;
     pin.BeginUpdate();
     return(pin.Ptr);
 }
Esempio n. 17
0
            private NodePin LockInternal(NodePin parent, LockType ltype, NodeHandle child, bool ignoreHandleComparison)
            {
                CacheEntry entry = GetCache(child, false);

                LockType locked = NoLock;

                if (ltype == LockType.Read && entry.Lock.TryRead(base.Options.LockTimeout))
                {
                    locked = LockType.Read;
                }
                if (ltype != LockType.Read && entry.Lock.TryWrite(base.Options.LockTimeout))
                {
                    locked = ltype;
                }

                DeadlockException.Assert(locked != NoLock);
                try
                {
                    Node node = entry.Node;
                    if (node == null)
                    {
                        using (new SafeLock <DeadlockException>(entry))
                        {
                            node = entry.Node;
                            if (node == null)
                            {
                                if (!(
                                        Storage.TryGetNode(child.StoreHandle, out node, NodeSerializer) &&
                                        node != null &&
                                        ignoreHandleComparison?true:node.StorageHandle.Equals(entry.Handle.StoreHandle)))
                                {
                                    LoggerManager.Instance.IndexLogger.Error("BPlusTree", "FileId Mismatch, Node:" + node.StorageHandle.ToString() + ", Entry:" + entry.Handle.StoreHandle.ToString());
                                    throw new InvalidNodeHandleException();
                                }


                                Node old = Interlocked.CompareExchange(ref entry.Node, node, null);
                                Assert(null == old, "Collision on cache load.");
                            }
                        }
                    }
                    return(new NodePin(child, entry.Lock, ltype, locked, entry, node, null));
                }
                catch
                {
                    if (locked == LockType.Read)
                    {
                        entry.Lock.ReleaseRead();
                    }
                    else if (locked != NoLock)
                    {
                        entry.Lock.ReleaseWrite();
                    }
                    throw;
                }
            }
Esempio n. 18
0
        private void AddPinView(NodePin obj)
        {
            bool containsKey = _pinViews.ContainsKey(obj);

            Assert.IsFalse(containsKey);
            if (!containsKey)
            {
                _pinViews.Add(obj, new NodeEditorPinView(obj, new Rect()));
            }
        }
Esempio n. 19
0
        private void RemovePinView(NodePin obj)
        {
            bool containsKey = _pinViews.ContainsKey(obj);

            Assert.IsTrue(containsKey);
            if (containsKey)
            {
                _pinViews.Remove(obj);
            }
        }
Esempio n. 20
0
        void DrawPin(NodePin pin)
        {
            var highlighted = _pinViews.ContainsKey(pin) && _pinViews[pin].ScreenRect.Contains(InputListener.MousePosition);
            var drawData    = NodeEditorPinDrawer.Draw(pin, highlighted);

            if (Event.current.type == EventType.Repaint && _pinViews.ContainsKey(pin))
            {
                _pinViews[pin] = drawData;
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Exclusive access, deep-locking enumeration for bulk-insert, essentially this enumerates
        /// while at the same time it chases existing writers out of the tree.
        /// </summary>
        private IEnumerable <KeyValuePair <TKey, TValue> > EnumerateNodeContents(NodePin root)
        {
            if (root.Ptr.IsLeaf)
            {
                for (int ix = 0; ix < root.Ptr.Count; ix++)
                {
                    yield return(root.Ptr[ix].ToKeyValuePair());
                }
                yield break;
            }

            Stack <KeyValuePair <NodePin, int> > todo = new Stack <KeyValuePair <NodePin, int> >();

            todo.Push(new KeyValuePair <NodePin, int>(root, 0));
            try
            {
                while (todo.Count > 0)
                {
                    KeyValuePair <NodePin, int> cur = todo.Pop();
                    if (cur.Value == cur.Key.Ptr.Count)
                    {
                        if (todo.Count == 0)
                        {
                            yield break;
                        }
                        cur.Key.Dispose();
                        continue;
                    }
                    todo.Push(new KeyValuePair <NodePin, int>(cur.Key, cur.Value + 1));

                    NodePin child = _storage.Lock(cur.Key, cur.Key.Ptr[cur.Value].ChildNode);
                    if (child.Ptr.IsLeaf)
                    {
                        using (child)
                        {
                            for (int ix = 0; ix < child.Ptr.Count; ix++)
                            {
                                yield return(child.Ptr[ix].ToKeyValuePair());
                            }
                        }
                    }
                    else
                    {
                        todo.Push(new KeyValuePair <NodePin, int>(child, 0));
                    }
                }
            }
            finally
            {
                while (todo.Count > 1)
                {
                    todo.Pop().Key.Dispose();
                }
            }
        }
Esempio n. 22
0
 public override void UpdateNode(NodePin node)
 {
     if (!node.IsDeleted)
     {
         NodeWithLock nlck;
         if (!node.Handle.TryGetCache(out nlck))
         {
             throw new AssertionFailedException("Unable to retrieve handle cache.");
         }
         nlck.Node = node.Ptr;
     }
 }
Esempio n. 23
0
        void Input_MouseUp()
        {
            if (_modifyingConnection != null)
            {
                NodeEditor.Logger.Log <NodeEditorPinConnector>("Removing a modified connection.");
                _graph.Disconnect(_modifyingConnection);
            }

            _view.EndDrawState();
            _modifyingConnection = null;
            _sourcePin           = null;
        }
Esempio n. 24
0
        public NodeCreateView(Vector2 mousePos, NodePin selected) : base("Node View")
        {
            mouseLoc = mousePos;
            // to DO
            size        = new Vector2(200, 100);
            scrollPos   = new Vector2();
            pinToAttach = selected;

            ops    = Enum.GetValues(typeof(MathNode.OpType));
            cTypes = Enum.GetValues(typeof(ControlNode.ControlType));
            fTypes = Enum.GetValues(typeof(FunctionNode.FunctionType));
        }
Esempio n. 25
0
            public void SaveChanges(NodePin pin)
            {
                if (pin.IsDeleted)
                {
                    Storage.Destroy(pin.Handle.StoreHandle);
                }
                else
                {
                    Storage.Update(pin.Handle.StoreHandle, NodeSerializer, pin.Ptr);
                }

                UpdateNode(pin);
            }
Esempio n. 26
0
            public NodePin Create(LockType ltype, bool isLeaf)
            {
                IStorageHandle storeHandle = _cache.Storage.Create();
                NodeHandle     handle      = new NodeHandle(storeHandle);
                object         refobj;
                ILockStrategy  lck = _cache.CreateLock(handle, out refobj);

                int     size = isLeaf ? _cache.Options.MaximumValueNodes : _cache.Options.MaximumChildNodes;
                NodePin pin  = new NodePin(handle, lck, ltype, LockType.Insert, refobj, null, new Node(handle.StoreHandle, size));

                NodePin.Append(ref _created, pin);
                return(pin);
            }
Esempio n. 27
0
        public void PromoteVariable(object o)
        {
            if (!o.GetType().Equals(typeof(NodePin)))
            {
                return;
            }
            NodePin pin = (NodePin)o;

            if (window.varCreateView != null)
            {
                window.varCreateView = new VariableCreateView(pin.Center, pin);
            }
        }
            private bool SeekNext(NodePin thisLock, TKey key, out NodePin pin, out int offset, out TKey nextKey, out bool hasMore)
            {
                pin     = null;
                offset  = -1;
                nextKey = default(TKey);
                hasMore = false;

                Element find    = new Element(key);
                NodePin next    = null;
                NodePin current = thisLock;

                try
                {
                    int ordinal;

                    while (true)
                    {
                        Node me = current.Ptr;
                        me.BinarySearch(_tree._itemComparer, find, out ordinal);
                        if (me.IsLeaf)
                        {
                            pin     = current;
                            offset  = ordinal;
                            current = null;
                            return(true);
                        }

                        if (me.Count > ordinal + 1)
                        {
                            nextKey = current.Ptr[ordinal + 1].Key;
                            hasMore = true;
                        }

                        next = _tree._storage.Lock(current, me[ordinal].ChildNode);
                        current.Dispose();
                        current = next;
                        next    = null;
                    }
                }
                finally
                {
                    if (current != null)
                    {
                        current.Dispose();
                    }
                    if (next != null)
                    {
                        next.Dispose();
                    }
                }
            }
Esempio n. 29
0
            protected override NodePin Lock(NodePin parent, LockType ltype, NodeHandle child)
            {
                CacheEntry entry = GetCache(child, false);

                LockType locked = NoLock;

                if (ltype == LockType.Read && entry.Lock.TryRead(base.Options.LockTimeout))
                {
                    locked = LockType.Read;
                }
                if (ltype != LockType.Read && entry.Lock.TryWrite(base.Options.LockTimeout))
                {
                    locked = ltype;
                }

                DeadlockException.Assert(locked != NoLock);
                try
                {
                    Node node = entry.Node;
                    if (node == null)
                    {
                        using (new SafeLock <DeadlockException>(entry))
                        {
                            node = entry.Node;
                            if (node == null)
                            {
                                InvalidNodeHandleException.Assert(
                                    Storage.TryGetNode(child.StoreHandle, out node, NodeSerializer) &&
                                    node != null &&
                                    node.StorageHandle.Equals(entry.Handle.StoreHandle)
                                    );
                                Node old = Interlocked.CompareExchange(ref entry.Node, node, null);
                                Assert(null == old, "Collision on cache load.");
                            }
                        }
                    }
                    return(new NodePin(child, entry.Lock, ltype, locked, entry, node, null));
                }
                catch
                {
                    if (locked == LockType.Read)
                    {
                        entry.Lock.ReleaseRead();
                    }
                    else if (locked != NoLock)
                    {
                        entry.Lock.ReleaseWrite();
                    }
                    throw;
                }
            }
        private bool Search(NodePin thisLock, TKey key, ref TValue value)
        {
            NodePin pin;
            int     offset;

            if (Seek(thisLock, key, out pin, out offset))
            {
                using (pin)
                {
                    value = pin.Ptr[offset].Payload;
                    return(true);
                }
            }
            return(false);
        }