Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StoreReader"/> class.
 /// This provides a fast way to create a reader,
 /// by reusing the metadata and index already loaded by an existing store reader.
 /// </summary>
 /// <param name="other">Another reader pointing to the same store.</param>
 public StoreReader(StoreReader other)
 {
     this.name = other.Name;
     this.path = other.Path;
     this.autoOpenAllStreams = other.AutoOpenAllStreams;
     this.messageReader      = new MessageReader(StoreCommon.GetDataFileName(this.name), this.path);
     this.largeMessageReader = new MessageReader(StoreCommon.GetLargeDataFileName(this.name), this.path);
     this.indexCache         = other.indexCache.AddRef();
     this.metadataCache      = other.metadataCache.AddRef();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StoreReader"/> 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 the main persisted file resides or will reside, or null to create a volatile data store.</param>
        /// <param name="metadataUpdateHandler">Delegate to call.</param>
        /// <param name="autoOpenAllStreams">Automatically open all streams.</param>
        public StoreReader(string name, string path, Action <IEnumerable <Metadata>, RuntimeInfo> metadataUpdateHandler, bool autoOpenAllStreams = false)
        {
            this.name = name;
            this.path = StoreCommon.GetPathToLatestVersion(name, path);
            this.autoOpenAllStreams = autoOpenAllStreams;

            // open the data readers
            this.messageReader      = new MessageReader(StoreCommon.GetDataFileName(this.name), this.path);
            this.largeMessageReader = new MessageReader(StoreCommon.GetLargeDataFileName(this.name), this.path);
            this.indexCache         = Shared.Create(new PageIndexCache(name, this.path));
            this.metadataCache      = Shared.Create(new MetadataCache(name, this.path, metadataUpdateHandler));
        }
Ejemplo n.º 3
0
        /// <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));
        }