/// <summary> /// Initializes a new instance of the <see cref="PsiStoreWriter"/> 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> public PsiStoreWriter(string name, string path, bool createSubdirectory = true) { this.name = name; 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, PsiStoreCommon.GetCatalogFileName(this.name), CatalogExtentSize); this.pageIndexWriter = new InfiniteFileWriter(this.path, PsiStoreCommon.GetIndexFileName(this.name), IndexExtentSize); this.writer = new MessageWriter(PsiStoreCommon.GetDataFileName(this.name), this.path); // write the first index entry this.UpdatePageIndex(0, default(Envelope)); }
public PageIndexCache(string name, string path) { this.indexReader = new InfiniteFileReader(path, PsiStoreCommon.GetIndexFileName(name)); }