/// <summary> /// Indicates whether the specified file is already loaded by a reader or writer. /// </summary> /// <param name="name">Infinite file name.</param> /// <param name="path">Infinite file path.</param> /// <returns>Returns true if the store is already loaded.</returns> public static bool IsActive(string name, string path) { if (!EventWaitHandle.TryOpenExisting(InfiniteFileWriter.PulseEventName(path, name), out EventWaitHandle eventHandle)) { return(false); } eventHandle.Dispose(); return(true); }
/// <summary> /// Indicates whether the specified data store has an active writer. /// </summary> /// <param name="storeName">The store name.</param> /// <param name="storePath">The store path.</param> /// <returns>Returns true if there is an active data file writer to this store.</returns> public static bool IsStoreLive(string storeName, string storePath) { if (!Mutex.TryOpenExisting(InfiniteFileWriter.ActiveWriterMutexName(storePath, PsiStoreCommon.GetCatalogFileName(storeName)), out Mutex writerActiveMutex)) { return(false); } writerActiveMutex.Dispose(); return(true); }
public InfiniteFileReader(string path, string fileName, int fileId = 0) { this.path = path; this.fileName = fileName; this.fileId = fileId; Mutex pulse; Mutex.TryOpenExisting(InfiniteFileWriter.PulseEventName(path, fileName), out pulse); this.writePulse = pulse ?? new Mutex(false); }
/// <summary> /// Indicates whether the specified file has an active writer. /// </summary> /// <param name="name">Infinite file name.</param> /// <param name="path">Infinite file path.</param> /// <returns>Returns true if there is an active writer to this file.</returns> public static bool IsActive(string name, string path) { Mutex writerActiveMutex; if (!Mutex.TryOpenExisting(InfiniteFileWriter.ActiveWriterMutexName(path, name), out writerActiveMutex)) { return(false); } writerActiveMutex.Dispose(); return(true); }
public MessageWriter(string name, string path, int extentSize = 0) { if (extentSize == 0) { extentSize = Environment.Is64BitProcess ? DefaultExtentCapacity64 : DefaultExtentCapacity32; } if (path != null) { this.fileWriter = new InfiniteFileWriter(path, name, extentSize); } else { int retentionQueueLength = Environment.Is64BitProcess ? DefaultRetentionQueueLength64 : DefaultRetentionQueueLength32; this.fileWriter = new InfiniteFileWriter(name, extentSize, retentionQueueLength); } }
/// <summary> /// Initializes a new instance of the <see cref="StoreWriter"/> class. /// </summary> /// <param name="name">The name of the application that generated the persisted files, or the root name of the files.</param> /// <param name="path">The directory in which to create the partition, or null to create a volatile data store.</param> /// <param name="createSubdirectory">If true, a numbered sub-directory is created for this store.</param> /// <param name="append">If true, the store is opened in append mode.</param> public StoreWriter(string name, string path, bool createSubdirectory = true, bool append = false) { this.name = name; this.append = append; if (path != null) { int id = 0; this.path = System.IO.Path.GetFullPath(path); if (createSubdirectory) { // if the root directory already exists, look for the next available id if (Directory.Exists(this.path)) { var existingIds = Directory.EnumerateDirectories(this.path, this.name + ".????") .Select(d => d.Split('.').Last()) .Where( n => { int i; return(int.TryParse(n, out i)); }) .Select(n => int.Parse(n)); id = (existingIds.Count() == 0) ? 0 : existingIds.Max() + 1; } this.path = System.IO.Path.Combine(this.path, $"{this.name}.{id:0000}"); } if (!Directory.Exists(this.path)) { Directory.CreateDirectory(this.path); } } this.catalogWriter = new InfiniteFileWriter(this.path, StoreCommon.GetCatalogFileName(this.name), CatalogExtentSize, append); this.pageIndexWriter = new InfiniteFileWriter(this.path, StoreCommon.GetIndexFileName(this.name), IndexExtentSize, append); this.writer = new MessageWriter(StoreCommon.GetDataFileName(this.name), this.path, append); // write the first index entry this.UpdatePageIndex(0, default(Envelope)); }
/// <summary> /// Indicates whether more data might be added to this file /// (i.e. the file still has an active writer). /// </summary> /// <returns>Returns true if there is an active writer to this file.</returns> public bool IsMoreDataExpected() { return(InfiniteFileWriter.IsActive(this.fileName, this.path)); }
public void Dispose() { this.fileWriter.Dispose(); this.fileWriter = null; }