public IBranch GetBranch(VPath vpath) { using (Vault.ExposeReadOnly()) { return vpath.Steps.Aggregate(this, (curr, step) => curr == null ? null : curr.Children.Branches[step]); } }
public CompiledProperty(CompiledNode parent, String name, VPath vpath, Func<IEsathObject> eval) { Parent = parent; Name = name; VPath = vpath; _eval = eval; }
private static TreeNode MatchNodeAndPath(this TreeNode ctx, VPath vpath) { if (ctx == null || vpath == VPath.Empty) return null; if (ctx.Text != vpath.Steps.First()) return null; if (vpath.Steps.Count() == 1) return ctx; return SelectNode(ctx.Nodes, vpath.Steps.Skip(1).ToArray()); }
public IBranch GetBranch(VPath vpath) { if (!_branches.ContainsKey(vpath)) { _branches.Add(vpath, _vault.GetBranch(vpath)); } return _branches[vpath]; }
public IValue GetValue(VPath vpath) { if (!_values.ContainsKey(vpath)) { _values.Add(vpath, _vault.GetValue(vpath)); } return _values[vpath]; }
public ICompiledNode Child(VPath vpath) { if (!_allChildrenRecursive.ContainsKey(vpath)) { throw new NotImplementedException(String.Format("There's no compiled node at VPath '{0}'.", vpath)); } return _allChildrenRecursive[vpath]; }
public IValue GetValue(VPath vpath) { using (Vault.ExposeReadOnly()) { var steps = vpath.Steps.ToArray(); var parent = (Branch)GetBranch(steps.Take(steps.Length - 1).ToArray()); return parent == null ? null : parent.Children.Values[steps.Last()]; } }
public bool Equals(VPath obj) { if (ReferenceEquals(null, obj)) { return(false); } if (ReferenceEquals(this, obj)) { return(true); } return(Equals(obj._path, _path)); }
public FsVaultEntry(DirectoryInfo root, FileSystemInfo fsItem) { Root = root; FsItem = fsItem; FsItem.Exists.AssertTrue(); FsItem.FullName.StartsWith(Root.FullName).AssertTrue(); Streams = new List<FileStream>(); _absPathCached = FsItem.FullName; _relPathCached = _absPathCached.Substring(Root.FullName.Length); if (FsItem is DirectoryInfo && !_relPathCached.EndsWith(@"\")) _relPathCached += @"\"; if (!_relPathCached.StartsWith(@"\")) _relPathCached = @"\" + _relPathCached; try { _vpathCached = new VPath(_relPathCached.Unbux()); } catch { } }
protected void UnregisterRecursively(VPath vpath) { Registry.RemoveRange(Registry.Keys.Where(path => path > vpath)); }
protected void Unregister(VPath vpath) { Registry.Remove(vpath); }
protected void Register(VPath vpath, Func<CompiledNode, CompiledNode> factory) { Registry[vpath] = factory; }
internal void VerifyMutation(VPath effectiveVPath) { int exposedRO, exposedRW; using (Vault.ExposeReadOnly(out exposedRO, out exposedRW)) { int exposedInternal; using (Vault.InternalExpose(out exposedInternal)) { // mutation is never allowed in unexposed state // exposition might be either regular (most public ops) or internal (ctor/save) if (exposedRW != 0 || exposedInternal != 0) { // mutation is then allowed for non-internal elements var mutationAprioriAllowed = !this.IsInternal(effectiveVPath); if (mutationAprioriAllowed) return; // for internal values mutation is only allowed when it // comes during construction and/or saving of different kinds if (exposedInternal != 0) return; // otherwise the mutation is illegal throw new NotSupportedException(String.Format( "Completing this operation would mutate a value at effective vpath '{0}'. " + "This is prohibited because this vpath is reserved by the vault for internal purposes.", effectiveVPath)); } else { // mutation is never allowed in unexposed state throw new NotSupportedException(String.Format( "Completing this operation would mutate the node '{0}'. " + "This is prohibited because mutations are never allowed in unexposed state.", effectiveVPath)); } } } }
public static IValue GetOrCreateValue(this IBranch branch, VPath vpath, String content) { return(branch.GetOrCreateValue(vpath, content.AsLazyStream())); }
public static TreeNode SelectNode(this TreeNode ctx, VPath vpath) { return vpath == VPath.Empty ? ctx : SelectNode(ctx.Nodes, vpath); }
public IValue CreateValue(VPath vpath, Func<Stream> content, ValueKind valueKind) { using (Vault.ExposeReadWrite()) { GetValue(vpath).AssertNull(); return GetOrCreateValue(vpath, content, valueKind); } }
IValue IBranch.CreateValue(VPath vpath, Func<Stream> content) { return CreateValue(vpath, content, ValueKind.Regular); }
public IBranch CreateBranch(VPath vpath) { using (Vault.ExposeReadWrite()) { GetBranch(vpath).AssertNull(); return GetOrCreateBranch(vpath); } }
public IValue GetOrCreateValue(VPath vpath, Func<Stream> content, ValueKind valueKind) { using (Vault.ExposeReadOnly()) { var steps = vpath.Steps.ToArray(); var parent = (Branch)GetOrCreateBranch(steps.Take(steps.Length - 1).ToArray()); var regularValue = (valueKind & ValueKind.Regular) != 0 ? parent.Children.Values[steps.Last()] : null; var internalValue = (valueKind & ValueKind.Internal) != 0 ? parent.Children.InternalValues[steps.Last()] : null; var value = regularValue ?? internalValue; if (value != null) { return value; } else { using (Vault.ExposeReadWrite()) { var newValue = new Value(Vault, steps.Last(), null); newValue.Parent = parent; newValue.SetContent(content); return newValue; } } } }
public IBranch GetOrCreateBranch(VPath vpath) { using (Vault.ExposeReadOnly()) { return vpath.Steps.Aggregate(this, (curr, step) => { var next = curr.Children.Branches[step]; if (next != null) { return next; } else { using (Vault.ExposeReadWrite()) { return new Branch(Vault, step, null){Parent = curr}; } } }); } }
public static IValue GetOrCreateValue(this IBranch branch, VPath vpath, Stream content) { return(branch.GetOrCreateValue(vpath, () => content)); }
public Func<CompiledNode, CompiledNode> FactoryFor(VPath vpath) { return Registry.ContainsKey(vpath) ? Registry[vpath] : null; }
public CompiledNode CreateNode(VPath vpath, CompiledNode parent) { var factoryMethod = Factory.FactoryFor(vpath); return factoryMethod == null ? null : factoryMethod(parent); }
public IEsathObject Eval(VPath vpath) { return Property(vpath).Eval(); }
private static TreeNode SelectNode(this TreeNodeCollection nodes, VPath vpath) { return nodes.Cast<TreeNode>().Select(n => MatchNodeAndPath(n, vpath)).SingleOrDefault(n => n != null); }
public bool Equals(VPath obj) { if(ReferenceEquals(null, obj)) return false; if(ReferenceEquals(this, obj)) return true; return Equals(obj._path, _path); }
public static TreeNode SelectNode(this TreeView tree, VPath vpath) { return SelectNode(tree.Nodes, vpath); }
public static IValue GetOrCreateValue(this IBranch branch, VPath vpath) { return(branch.GetOrCreateValue(vpath, ((String)null).AsLazyStream())); }
public VPathAttribute(String vpath) { VPath = vpath; }
public ICompiledProperty Property(VPath vpath) { if (!_allPropertiesRecursive.ContainsKey(vpath)) { throw new NotImplementedException(String.Format("There's no compiled property at VPath '{0}'.", vpath)); } return _allPropertiesRecursive[vpath]; }