Example #1
0
 public IBranch GetBranch(VPath vpath)
 {
     using (Vault.ExposeReadOnly())
     {
         return vpath.Steps.Aggregate(this, (curr, step) => curr == null ? null : curr.Children.Branches[step]);
     }
 }
Example #2
0
 public CompiledProperty(CompiledNode parent, String name, VPath vpath, Func<IEsathObject> eval)
 {
     Parent = parent;
     Name = name;
     VPath = vpath;
     _eval = eval;
 }
Example #3
0
 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());
 }
Example #4
0
        public IBranch GetBranch(VPath vpath)
        {
            if (!_branches.ContainsKey(vpath))
            {
                _branches.Add(vpath, _vault.GetBranch(vpath));
            }

            return _branches[vpath];
        }
Example #5
0
        public IValue GetValue(VPath vpath)
        {
            if (!_values.ContainsKey(vpath))
            {
                _values.Add(vpath, _vault.GetValue(vpath));
            }

            return _values[vpath];
        }
Example #6
0
        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];
        }
Example #7
0
 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()];
     }
 }
Example #8
0
 public bool Equals(VPath obj)
 {
     if (ReferenceEquals(null, obj))
     {
         return(false);
     }
     if (ReferenceEquals(this, obj))
     {
         return(true);
     }
     return(Equals(obj._path, _path));
 }
Example #9
0
        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 { }
        }
Example #10
0
 protected void UnregisterRecursively(VPath vpath)
 {
     Registry.RemoveRange(Registry.Keys.Where(path => path > vpath));
 }
Example #11
0
 protected void Unregister(VPath vpath)
 {
     Registry.Remove(vpath);
 }
Example #12
0
 protected void Register(VPath vpath, Func<CompiledNode, CompiledNode> factory)
 {
     Registry[vpath] = factory;
 }
Example #13
0
        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));
                    }
                }
            }
        }
Example #14
0
 public static IValue GetOrCreateValue(this IBranch branch, VPath vpath, String content)
 {
     return(branch.GetOrCreateValue(vpath, content.AsLazyStream()));
 }
Example #15
0
 public static TreeNode SelectNode(this TreeNode ctx, VPath vpath)
 {
     return vpath == VPath.Empty ? ctx : SelectNode(ctx.Nodes, vpath);
 }
Example #16
0
 public IValue CreateValue(VPath vpath, Func<Stream> content, ValueKind valueKind)
 {
     using (Vault.ExposeReadWrite())
     {
         GetValue(vpath).AssertNull();
         return GetOrCreateValue(vpath, content, valueKind);
     }
 }
Example #17
0
 IValue IBranch.CreateValue(VPath vpath, Func<Stream> content)
 {
     return CreateValue(vpath, content, ValueKind.Regular);
 }
Example #18
0
 public IBranch CreateBranch(VPath vpath)
 {
     using (Vault.ExposeReadWrite())
     {
         GetBranch(vpath).AssertNull();
         return GetOrCreateBranch(vpath);
     }
 }
Example #19
0
        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;
                    }
                }
            }
        }
Example #20
0
 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};
                 }
             }
         });
     }
 }
Example #21
0
 public static IValue GetOrCreateValue(this IBranch branch, VPath vpath, Stream content)
 {
     return(branch.GetOrCreateValue(vpath, () => content));
 }
Example #22
0
 public Func<CompiledNode, CompiledNode> FactoryFor(VPath vpath)
 {
     return Registry.ContainsKey(vpath) ? Registry[vpath] : null;
 }
Example #23
0
 public CompiledNode CreateNode(VPath vpath, CompiledNode parent)
 {
     var factoryMethod = Factory.FactoryFor(vpath);
     return factoryMethod == null ? null : factoryMethod(parent);
 }
Example #24
0
 public IEsathObject Eval(VPath vpath)
 {
     return Property(vpath).Eval();
 }
Example #25
0
 private static TreeNode SelectNode(this TreeNodeCollection nodes, VPath vpath)
 {
     return nodes.Cast<TreeNode>().Select(n => MatchNodeAndPath(n, vpath)).SingleOrDefault(n => n != null);
 }
Example #26
0
 public bool Equals(VPath obj)
 {
     if(ReferenceEquals(null, obj)) return false;
     if(ReferenceEquals(this, obj)) return true;
     return Equals(obj._path, _path);
 }
Example #27
0
 public static TreeNode SelectNode(this TreeView tree, VPath vpath)
 {
     return SelectNode(tree.Nodes, vpath);
 }
Example #28
0
 public static IValue GetOrCreateValue(this IBranch branch, VPath vpath)
 {
     return(branch.GetOrCreateValue(vpath, ((String)null).AsLazyStream()));
 }
Example #29
0
 public VPathAttribute(String vpath)
 {
     VPath = vpath;
 }
Example #30
0
        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];
        }