public void Close() { lock (_Locker) { if (this._blockfile != null) { this._blockfile.Close(); this._blockfile = null; } if (this.primaryIndex != null) { this.primaryIndex.Close(); } if (this.Indexes != null) { this.Indexes.CloseAll(); } } }
public ObjectStore <Tkey, TValue> GetOrCreateObjectStore <Tkey, TValue>(string StoreName, ObjectStoreParameters Parameters = null) { StoreName = StoreName.ToValidPath(); if (this.HasObjectStore(StoreName)) { return(this.GetObjectStore <Tkey, TValue>(StoreName)); } else { lock (_locker) { if (!HasObjectStore(StoreName)) { // Should be removed. #region TempUpgrade2017end var oldsettingfile = objectSettingFile(StoreName); if (System.IO.File.Exists(oldsettingfile)) { var oldsetting = SettingSerializer.DeserializeObjectStoreSetting(oldsettingfile); if (oldsetting.UseDefaultNETBinaryFormater) { //clean everything. does not want to upgrade those.... var folder = objectFolder(StoreName); System.IO.Directory.Delete(folder, true); return(GetOrCreateObjectStore <Tkey, TValue>(StoreName, Parameters)); } int keyoffset = oldsetting.primaryKeyLength; foreach (var item in oldsetting.ColumnList) { if (item.KeyType == typeof(string)) { keyoffset += item.length; } else { keyoffset += Helper.KeyHelper.GetKeyLen(item.KeyType, item.length); } } var oldfolder = this.objectFolder(StoreName); // primary key. var primaryIndex = new Btree.BtreeIndex <Tkey>(oldsetting.primaryKeyFieldName, true, oldsetting.primaryKeyLength, Helper.IndexHelper.GetIndexFileName(oldfolder, oldsetting.primaryKeyFieldName), oldsetting.MaxCacheLevel); string blockfileName = System.IO.Path.Combine(oldfolder, "Data.block"); var blockfile = new BlockFile(blockfileName); blockfile.OpenOrCreate(); var converter = new Serializer.Simple.SimpleConverter <TValue>(); string newname = "_koobootemp" + StoreName; var newfolder = this.objectFolder(newname); var upStore = this.GetOrCreateObjectStore <Tkey, TValue>(newname, Parameters); lock (_locker) { foreach (var item in primaryIndex.allItemCollection(true)) { var bytes = blockfile.GetContent(item, keyoffset); var newobj = converter.FromBytes(bytes); upStore.add(newobj); } blockfile.Close(); primaryIndex.Close(); upStore.Close(); this.DeleteObjectStore(StoreName); if (System.IO.Directory.Exists(oldfolder)) { System.IO.Directory.Delete(oldfolder, true); } System.IO.Directory.Move(newfolder, oldfolder); if (this.openStoreList.ContainsKey(StoreName)) { this.openStoreList.Remove(StoreName); } } return(this.GetOrCreateObjectStore <Tkey, TValue>(StoreName, Parameters)); } #endregion clearOpenStoreCache(); if (Parameters == null) { Parameters = new ObjectStoreParameters(); } ObjectStore <Tkey, TValue> newstore = new ObjectStore <Tkey, TValue>(StoreName, this, Parameters); this.openStoreList.Add(StoreName, newstore); } } return(this.openStoreList[StoreName] as ObjectStore <Tkey, TValue>); } }