public IValue SetContent(Func <Stream> content) { content = content ?? (() => null); using (Vault.ExposeReadWrite()) { var oldContent = _content; if (Metadata[CoreConstants.ContentIsNullSection].IsNeitherNullNorEmpty()) { oldContent = () => null; } var corrId = BoundVault.ReportChanging(EventReason.Content, this, oldContent, content); VerifyMutation(VPath); _content = content; _saveMyContentPlease = true; using (Vault.InternalExpose()) { _isContentCached = false; _isContentStringCached = false; Metadata[CoreConstants.ContentIsNullSection] = null; } BoundVault.ReportChanged(corrId, EventReason.Content, this, oldContent, content); return(this); } }
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); } } } } }
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); } }
public override IMetadata InitializeFrom(IMetadata metadata) { using (Vault.ExposeReadWrite()) { var oldMetadata = Clone(); var newMetadata = metadata; var corrId = BoundVault.ReportChanging(EventReason.Metadata, Element, oldMetadata, newMetadata); VerifyMutation(); _lazySource = null; var externalImpl = metadata == null ? new Dictionary <String, String>() : ((Metadata)metadata).Impl; externalImpl = externalImpl ?? new Dictionary <String, String>(); _dontUseThisForGetUsePropertyInstead = new Dictionary <String, String>(externalImpl); SaveMePlease = true; BoundVault.ReportChanged(corrId, EventReason.Metadata, Element, oldMetadata, newMetadata); return(this); } }
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); } }
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); } }
public virtual IElement Rename(String name) { IsRoot.AssertFalse(); (VPath + name).AssertNotNull(); using (Vault.ExposeReadOnly()) { var oldName = Name; var corrId = Guid.Empty; if (name != oldName) { corrId = BoundVault.ReportChanging(EventReason.Rename, this, oldName, name); } if (name != oldName) { using (Vault.ExposeReadWrite()) { Name = name; var index = Parent == null ? null : Parent.Children as IndexedNodeCollection; if (index != null) { index.Reindex(this); } } } // do not insert the check "Name == name" here // it will break branch name changes propagation // i.e. if a parent has been renamed, all his children should get // the _saveMyNamePlease flag since their position @ the physical storage has changed _saveMyNamePlease = true; if (name != oldName) { (corrId != Guid.Empty).AssertTrue(); BoundVault.ReportChanged(corrId, EventReason.Rename, this, oldName, name); } return(this); } }
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); } } } } }
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); } } } } }