public virtual void DeleteSubBox(string name, bool throwExceptionIfNotExists) { var normalizedName = this.NomalizeName(name); if (!this.SubBoxExists(normalizedName)) { if (throwExceptionIfNotExists) { throw new InvalidOperationException("SubBox with name '{0}' doesn't exist.".FormatWith(name)); } return; } try { PermanentInfoStorage.ModificationsSyncRoot.EnterReadLock(); if (this.InnerBoxes.ContainsKey(normalizedName)) { StorageBox boxToDelete = this.InnerBoxes[normalizedName]; this.InnerBoxes.Remove(normalizedName); this.UnderlyingBucket.DeleteInnerBucket(boxToDelete.UnderlyingBucket); } else { this.UnderlyingBucket.DeleteInnerBucket(normalizedName); } } finally { PermanentInfoStorage.ModificationsSyncRoot.ExitReadLock(); this.HandleSaveRequest(); } }
protected virtual StorageBox ResolveNamedSubContainer(string name, ISaveStrategy saveStrategy) { this.AssertBoxIsNotDeleted(); name = this.NomalizeName(name); if (this.InnerBoxes.ContainsKey(name)) { return(this.InnerBoxes[name]); } try { PermanentInfoStorage.ModificationsSyncRoot.EnterReadLock(); var appropriateBucket = this.GetOrCreateInnerBucket(name); var box = new StorageBox(appropriateBucket, saveStrategy, this.HandleSaveRequest); this.InnerBoxes[name] = box; return(box); } finally { PermanentInfoStorage.ModificationsSyncRoot.ExitReadLock(); this.HandleSaveRequest(); } }