/// <summary> /// 内存数据库物理层 /// </summary> /// <param name="fileName"></param> /// <param name="isDomainUnloadDispose"></param> public TmphPhysical(string fileName, bool isDomainUnloadDispose = true) { try { var file = new FileInfo(this.fileName = fileName + ".fmd"); path = file.Directory.fullName(); if (file.Exists) { currentLock = 1; loader = new TmphFileReader(this); } else fileWriter = new TmphFileStreamWriter(path + this.fileName, FileMode.CreateNew, FileShare.Read, FileOptions.None, true, null); if (isDomainUnloadDispose) TmphDomainUnload.Add(Dispose); } catch (Exception error) { LastException = error; currentLock = 2; Dispose(); } }
/// <summary> /// 打开日志文件 /// </summary> private void open() { try { fileStream = new TmphFileStreamWriter(fileName, FileMode.OpenOrCreate, FileShare.Read, FileOptions.None, false, TmphAppSetting.Encoding); } catch (Exception error) { Console.WriteLine(error.ToString()); } if (fileStream == null) { try { if (File.Exists(fileName)) fileStream = new TmphFileStreamWriter(TmphFile.MoveBakFileName(fileName), FileMode.OpenOrCreate, FileShare.Read, FileOptions.None, false, TmphAppSetting.Encoding); } catch (Exception error) { Console.WriteLine(error.ToString()); } } }
/// <summary> /// 读取数据完毕 /// </summary> /// <param name="isLoaded">是否成功</param> /// <returns></returns> public bool Loaded(bool isLoaded) { if (currentLock == 1) { if (isLoaded) { try { TmphPub.Dispose(ref loader); memoryPool.Push(ref loadBuffer); fileWriter = new TmphFileStreamWriter(path + fileName, FileMode.Open, FileShare.Read, FileOptions.None, true, null); return true; } catch (Exception error) { LastException = error; } finally { currentLock = 0; } } else currentLock = 0; } Dispose(); return false; }