예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PsiStoreReader"/> 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 PsiStoreReader(string name, string path, Action <IEnumerable <Metadata>, RuntimeInfo> metadataUpdateHandler, bool autoOpenAllStreams = false)
        {
            this.Name = name;
            this.Path = PsiStore.GetPathToLatestVersion(name, path);
            this.AutoOpenAllStreams = autoOpenAllStreams;

            // open the data readers
            this.messageReader      = new MessageReader(PsiStoreCommon.GetDataFileName(this.Name), this.Path);
            this.largeMessageReader = new MessageReader(PsiStoreCommon.GetLargeDataFileName(this.Name), this.Path);
            this.indexCache         = Shared.Create(new PageIndexCache(name, this.Path));
            this.metadataCache      = Shared.Create(new MetadataCache(name, this.Path, metadataUpdateHandler));
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JsonStoreReader"/> 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="extension">The extension for the underlying file.</param>
        public JsonStoreReader(string name, string path, string extension = DefaultExtension)
            : base(extension)
        {
            this.Name = name;
            this.Path = PsiStore.GetPathToLatestVersion(name, path);

            // load catalog
            string metadataPath = System.IO.Path.Combine(this.Path, PsiStoreCommon.GetCatalogFileName(this.Name) + this.Extension);

            this.Size = new FileInfo(metadataPath).Length;
            using (var file = File.OpenText(metadataPath))
                using (var reader = new JsonTextReader(file))
                {
                    this.catalog = this.Serializer.Deserialize <List <JsonStreamMetadata> >(reader);
                }

            // compute originating time interval
            this.originatingTimeInterval = TimeInterval.Empty;
            foreach (var metadata in this.catalog)
            {
                var metadataTimeInterval = new TimeInterval(metadata.FirstMessageOriginatingTime, metadata.LastMessageOriginatingTime);
                this.originatingTimeInterval = TimeInterval.Coverage(new TimeInterval[] { this.originatingTimeInterval, metadataTimeInterval });
            }
        }