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

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

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