private void dispose() { if (_store != null) { if (IsOpen) { Close(); } if (_store != null) { _store.Locker.Invoke(() => { _store.Dispose(); if (_storeAddress == -1) { _storeAddress = _store.DataAddress; } }); _store = null; } if (DeletedCollections != null) { DeletedCollections.Dispose(); if (_deletedCollectionsAddress == -1) { _deletedCollectionsAddress = DeletedCollections.DataAddress; } DeletedCollections = null; } CollectionsPool = null; Parent = null; Server = null; } }
/// <summary> /// Returns Name of this instance /// </summary> /// <returns></returns> public override string ToString() { #if (DEBUG) return(string.Format("File {0}, Store {1}, DeletedCollections {2}", this.Filename, ((Sop.OnDisk.Algorithm.SortedDictionary.SortedDictionaryOnDisk)Store).GetHeaderInfo(), DeletedCollections != null ? DeletedCollections.ToString() : "")); #else return(Filename); #endif }
/// <summary> /// Close the file /// </summary> public virtual void Close() { if (IsClosing || _store == null || _store.FileStream == null) { return; } if (IsDirty) { Flush(); } if (_storeAddress == -1) { _storeAddress = _store.DataAddress; } IsClosing = true; try { if (DeletedCollections != null) { DeletedCollections.Close(); if (_deletedCollectionsAddress == -1) { _deletedCollectionsAddress = DeletedCollections.DataAddress; } } if (CollectionsPool != null && CollectionsPool.Count > 0) { var colls = new Algorithm.Collection.ICollectionOnDisk[CollectionsPool.Count]; CollectionsPool.Values.CopyTo(colls, 0); for (int i = 0; i < colls.Length; i++) { colls[i].Close(); } CollectionsPool.Clear(); } if (_store != null) { _store.Close(); } _store = null; if (_diskBuffer != null) { _diskBuffer.ClearData(); } } finally { IsClosing = false; } }
/// <summary> /// Pack this File object /// </summary> /// <param name="parent"></param> /// <param name="writer"></param> public void Pack(IInternalPersistent parent, BinaryWriter writer) { writer.Write(Size); writer.Write(Name); writer.Write(Filename); //** save the profile info Profile.Pack(writer); bool hasDeletedBlocks = DeletedCollections != null || _deletedCollectionsAddress != -1; writer.Write(hasDeletedBlocks); if (hasDeletedBlocks) { if (DeletedCollections != null && DeletedCollections.DataAddress < 0) { DeletedCollections.Flush(); } if (_deletedCollectionsAddress == -1 && DeletedCollections != null) { _deletedCollectionsAddress = DeletedCollections.DataAddress; } writer.Write(_deletedCollectionsAddress); } writer.Write(_store != null || _storeAddress != -1); if (_store != null) { if (_store.IsOpen && _store.IsDirty) { _store.RegisterChange(); _store.Flush(); } if (_storeAddress == -1) { _storeAddress = _store.DataAddress; } } if (_storeAddress != -1) { writer.Write(_storeAddress); } }
private void dispose() { if (_store != null) { if (IsOpen) { Close(); } _store.Dispose(); _store = null; if (DeletedCollections != null) { DeletedCollections.Dispose(); DeletedCollections = null; } CollectionsPool = null; Parent = null; Server = null; } }
/// <summary> /// Save ObjectStores of this File Object /// </summary> public void Flush() { if (DeletedCollections != null) { DeletedCollections.Flush(); } if (CollectionsPool != null && CollectionsPool.Count > 0) { foreach (Algorithm.Collection.ICollectionOnDisk coll in CollectionsPool.Values) { if (coll != _store) { coll.Flush(); } } } if (_store != null) { _store.Flush(); } _isDirty = false; }
/// <summary> /// Save ObjectStores of this File Object /// </summary> public void Flush() { if (DeletedCollections != null) { DeletedCollections.Flush(); } if (CollectionsPool != null && CollectionsPool.Count > 0) { foreach (Algorithm.Collection.ICollectionOnDisk coll in CollectionsPool.Values) { if (coll != _store && coll.SyncRoot != null) { ((ISynchronizer)coll.SyncRoot).Invoke(() => { coll.Flush(); }); } } } if (_store != null) { _store.Locker.Invoke(() => { _store.Flush(); }); } _isDirty = false; }
/// <summary> /// Pack this File object /// </summary> /// <param name="parent"></param> /// <param name="writer"></param> public void Pack(IInternalPersistent parent, BinaryWriter writer) { writer.Write(Size); writer.Write(Name); writer.Write(Filename); //** save the profile info //Writer.Write((short)Profile.ProfileScheme); //Writer.Write((int)((ServerProfile)Profile).DataBlockSize); //Writer.Write(((ServerProfile)Profile).BTreeSlotLength); //Writer.Write(((ServerProfile)Profile).CollectionSegmentSize); //Writer.Write(((ServerProfile)Profile).HasTrashBin); //writer.Write(CollectionGrowthSizeInNob); //bool HasDeletedBlocks = DeletedCollections != null; bool hasDeletedBlocks = DeletedCollections != null; writer.Write(hasDeletedBlocks); if (hasDeletedBlocks) { if (DeletedCollections.DataAddress < 0) { DeletedCollections.Flush(); } writer.Write(DeletedCollections.DataAddress); } writer.Write(_store != null); if (_store != null) { if (_store.IsOpen && _store.IsDirty) { _store.RegisterChange(); _store.Flush(); } writer.Write(_store.DataAddress); } }
/// <summary> /// Unpack this object /// </summary> /// <param name="parent"></param> /// <param name="reader"></param> public void Unpack(IInternalPersistent parent, BinaryReader reader) { if (this.Server == null && parent is Algorithm.Collection.ICollectionOnDisk) { this.Server = ((Algorithm.Collection.ICollectionOnDisk)parent).File.Server; } Size = reader.ReadInt64(); _name = reader.ReadString(); this.Filename = reader.ReadString(); if (Server != null && (Server.HomePath != Server.Path && !System.IO.File.Exists(Filename) && Filename.StartsWith(Server.HomePath))) { //** c://SopBin/o.dta -> c://SopBin3/o.dta string nameOfFile = Filename.Substring(Server.HomePath.Length); string newFilename = string.Format("{0}{1}", Server.Path, nameOfFile); if (System.IO.File.Exists(newFilename)) { Filename = newFilename; } } //** Read the profile info... //ProfileSchemeType ps = (ProfileSchemeType)Reader.ReadInt16(); //DataBlockSize dbs = (DataBlockSize)Reader.ReadInt32(); //Profile.ProfileScheme = ps; //Profile.DataBlockSize = dbs; Profile = new Profile(((Algorithm.Collection.ICollectionOnDisk)parent).File.Profile); //CollectionGrowthSizeInNob = reader.ReadInt32(); bool hasDeletedBlocks = reader.ReadBoolean(); long collectionRecycler = -1; if (hasDeletedBlocks) { collectionRecycler = reader.ReadInt64(); } bool deserializeObjectStore = reader.ReadBoolean(); if (deserializeObjectStore) { _store = Transaction != null ? ((Transaction.TransactionBase)Transaction).CreateCollection(this) : ObjectServer.CreateDictionaryOnDisk(this); _store.DataAddress = reader.ReadInt64(); if (!_store.IsOpen) { _store.Open(); } } if (Server != null && Server.HasTrashBin) { if (collectionRecycler >= 0) { if (DeletedCollections == null) { CreateDeletedCollections(); } DeletedCollections.DataAddress = collectionRecycler; DeletedCollections.Load(); } else if (DeletedCollections == null) { CreateDeletedCollections(); } } }
/// <summary> /// Open the file. /// </summary> /// <param name="filename">name of file to open</param> /// <param name="accessMode">AccessMode's are Read Only, Read/Write</param> protected internal virtual void Open(string filename, AccessMode accessMode) { if (!IsOpen) { this.Filename = filename; this.AccessMode = accessMode; bool justCreated = false; if (_store == null) { justCreated = true; if (Transaction != null) { _store = ((Sop.Transaction.TransactionBase)Transaction.GetOuterChild()).CreateCollection(this); } else { _store = ObjectServer.CreateDictionaryOnDisk(this); } } else { _store.Open(); } if (_store.FileStream != null && (Size == 0 || Size < _store.FileStream.Length)) { Size = _store.FileStream.Length; } if (Server.TrashBinType != TrashBinType.Nothing) { if (DeletedCollections == null) { CreateDeletedCollections(); } else { DeletedCollections.Open(); } } if (Server != null) { if (this == this.Server.SystemFile) { Store.DataAddress = ((IInternalPersistent)this).DiskBuffer.DataAddress; } Store.Open(); if (justCreated) { justCreated = Store.IsDirty; if (justCreated && !Server.ReadOnly) { //** save the ObjectStore as we need the "System" Stores //** persisted right after initialization and Open... Store.Flush(); } } } if (DeletedCollections != null) { DeletedCollections.Open(); } } else if (Server.HasTrashBin) { CreateDeletedCollections(); } }