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; }
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); } } } } }
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)); }
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); } }
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); }
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"); } }
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); }
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); }
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); } }
public ConnectionViewModel(NodePin outputPinControl, NodePin inputPinControl) { this.OutputPinControl = outputPinControl; this.InputPinControl = inputPinControl; OutputPinControl.PropertyChanged += PinOnPropertyChanged; InputPinControl.PropertyChanged += PinOnPropertyChanged; }
public NodeEditorPinView GetPinView(NodePin pin) { if (HasNodeView(pin.Node)) { return(_nodeViews[pin.Node].GetPinViewData(pin)); } return(null); }
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); }
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; } }
private void AddPinView(NodePin obj) { bool containsKey = _pinViews.ContainsKey(obj); Assert.IsFalse(containsKey); if (!containsKey) { _pinViews.Add(obj, new NodeEditorPinView(obj, new Rect())); } }
private void RemovePinView(NodePin obj) { bool containsKey = _pinViews.ContainsKey(obj); Assert.IsTrue(containsKey); if (containsKey) { _pinViews.Remove(obj); } }
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; } }
/// <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(); } } }
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; } }
void Input_MouseUp() { if (_modifyingConnection != null) { NodeEditor.Logger.Log <NodeEditorPinConnector>("Removing a modified connection."); _graph.Disconnect(_modifyingConnection); } _view.EndDrawState(); _modifyingConnection = null; _sourcePin = null; }
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)); }
public void SaveChanges(NodePin pin) { if (pin.IsDeleted) { Storage.Destroy(pin.Handle.StoreHandle); } else { Storage.Update(pin.Handle.StoreHandle, NodeSerializer, pin.Ptr); } UpdateNode(pin); }
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); }
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(); } } }
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); }