예제 #1
0
        protected Element(VaultBase vault, String name, IEnumerable<Element> children)
        {
            Vault = vault.AssertNotNull();
            Bind(Vault);

            // setting parent auto-adds the child to this collection
            // so it should be initialized as an empty one
            _children = new IndexedNodeCollection(this);
            (children ?? Enumerable.Empty<Element>()).ForEach(c => c.Parent = (Branch)this);

            Name = name;
            _metadata = new Metadata(this);
        }
예제 #2
0
        public Metadata InitializeFrom(Func<Stream> lazyStream)
        {
            using (Vault.ExposeReadWrite())
            {
                var oldMetadata = Clone();
                var newMetadata = new Metadata(_element, lazyStream);
                var corrId = BoundVault.ReportChanging(EventReason.Metadata, Element, oldMetadata, newMetadata);

                VerifyMutation();
                _lazySource = lazyStream;
                SaveMePlease = true;

                BoundVault.ReportChanged(corrId, EventReason.Metadata, Element, oldMetadata, newMetadata);
                return this;
            }
        }
예제 #3
0
        public override String this[String key]
        {
            get
            {
                using (Vault.ExposeReadOnly())
                {
                    EnsureDefault();
                    lock (_isomorphicWritesLock)
                    {
                        if (!ContainsKey(key))
                        {
                            Impl.Add(key, null);
                        }
                    }

                    return Impl[key];
                }
            }
            set
            {
                using (Vault.ExposeReadOnly())
                {
                    EnsureDefault();

                    if (ContainsKey(key) && Impl[key] == value)
                    {
                        return;
                    }
                    else
                    {
                        using (Vault.ExposeReadWrite())
                        {
                            var oldMetadata = Clone();
                            var newImpl = new Dictionary<String, String>(Impl);
                            newImpl[key] = value;
                            var newMetadata = new Metadata(_element, newImpl);
                            var corrId = BoundVault.ReportChanging(EventReason.Metadata, Element, oldMetadata, newMetadata);

                            VerifyMutation();
                            Impl[key] = value;
                            SaveMePlease = true;

                            BoundVault.ReportChanged(corrId, EventReason.Metadata, Element, oldMetadata, newMetadata);
                        }
                    }
                }
            }
        }
예제 #4
0
        public override bool Remove(String key)
        {
            using (Vault.ExposeReadOnly())
            {
                if (!Impl.ContainsKey(key))
                {
                    return false;
                }
                else
                {
                    if (Impl[key] == null)
                    {
                        return false;
                    }
                    else
                    {
                        using (Vault.ExposeReadWrite())
                        {
                            var oldMetadata = Clone();
                            var newImpl = new Dictionary<String, String>(Impl);
                            newImpl.Remove(key);
                            var newMetadata = new Metadata(_element, newImpl);
                            var corrId = BoundVault.ReportChanging(EventReason.Metadata, Element, oldMetadata, newMetadata);

                            VerifyMutation();
                            var result = Impl.Remove(key);
                            EnsureDefault();
                            SaveMePlease = true;

                            BoundVault.ReportChanged(corrId, EventReason.Metadata, Element, oldMetadata, newMetadata);
                            return result;
                        }
                    }
                }
            }
        }
예제 #5
0
        public override void Add(String key, String value)
        {
            using (Vault.ExposeReadWrite())
            {
                EnsureDefault();

                var oldMetadata = Clone();
                var newImpl = new Dictionary<String, String>(Impl);
                newImpl.Add(key, value);
                var newMetadata = new Metadata(_element, newImpl);
                var corrId = BoundVault.ReportChanging(EventReason.Metadata, Element, oldMetadata, newMetadata);

                VerifyMutation();
                Impl.Add(key, value);
                SaveMePlease = true;

                BoundVault.ReportChanged(corrId, EventReason.Metadata, Element, oldMetadata, newMetadata);
            }
        }
예제 #6
0
        public override bool Remove(KeyValuePair<String, String> item)
        {
            var key = item.Key;
            var value = item.Value;
            using (Vault.ExposeReadOnly())
            {
                if (!Impl.ContainsKey(key))
                {
                    return false;
                }
                else
                {
                    if (Impl[key] == value)
                    {
                        return false;
                    }
                    else
                    {
                        using (Vault.ExposeReadWrite())
                        {
                            var oldMetadata = Clone();
                            var newImpl = new Dictionary<String, String>(Impl);
                            ((ICollection<KeyValuePair<String, String>>)newImpl).Remove(item);
                            var newMetadata = new Metadata(_element, newImpl);
                            var corrId = BoundVault.ReportChanging(EventReason.Metadata, Element, oldMetadata, newMetadata);

                            VerifyMutation();
                            var result = ((ICollection<KeyValuePair<String, String>>)Impl).Remove(item);
                            EnsureDefault();
                            SaveMePlease = true;

                            BoundVault.ReportChanged(corrId, EventReason.Metadata, Element, oldMetadata, newMetadata);
                            return result;
                        }
                    }
                }
            }
        }
예제 #7
0
        public override void Add(KeyValuePair<String, String> item)
        {
            using (Vault.ExposeReadWrite())
            {
                EnsureDefault();

                var oldMetadata = Clone();
                var newImpl = new Dictionary<String, String>(Impl);
                ((ICollection<KeyValuePair<String, String>>)newImpl).Add(item);
                var newMetadata = new Metadata(_element, newImpl);
                var corrId = BoundVault.ReportChanging(EventReason.Metadata, Element, oldMetadata, newMetadata);

                VerifyMutation();
                ((ICollection<KeyValuePair<String, String>>)Impl).Add(item);
                SaveMePlease = true;

                BoundVault.ReportChanged(corrId, EventReason.Metadata, Element, oldMetadata, newMetadata);
            }
        }