示例#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();
 }
示例#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));
        }
示例#3
0
        /// <summary>
        /// Creates a logical storage stream to write messages to.
        /// </summary>
        /// <param name="streamId">The id of the stream, unique for this store. All messages with this stream id will be written to this storage stream.</param>
        /// <param name="streamName">The name of the stream. This name can be later used to open the sorage stream for reading.</param>
        /// <param name="indexed">Indicates whether the stream is indexed or not. Indexed streams have a small index entry in the main data file and the actual message body in a large data file.</param>
        /// <param name="typeName">A name identifying the type of the messages in this stream. This is usually a fully-qualified type name or a data contract name, but can be anything that the caller wants.</param>
        /// <returns>The complete metadata for the storage stream just created.</returns>
        public PsiStreamMetadata OpenStream(int streamId, string streamName, bool indexed, string typeName)
        {
            if (this.metadata.ContainsKey(streamId))
            {
                throw new InvalidOperationException($"The stream id {streamId} has already been registered with this writer.");
            }

            var meta = new PsiStreamMetadata(streamName, streamId, typeName);

            meta.Opened             = Time.GetCurrentTime();
            meta.IsPersisted        = true;
            meta.IsIndexed          = indexed;
            meta.PartitionName      = this.name;
            meta.PartitionPath      = this.path;
            this.metadata[streamId] = meta;
            this.WriteToCatalog(meta);

            // make sure we have a large file if needed
            if (indexed)
            {
                this.largeMessageWriter = this.largeMessageWriter ?? new MessageWriter(StoreCommon.GetLargeDataFileName(this.name), this.path, this.append);
            }

            return(meta);
        }