Пример #1
0
        /// <summary>
        /// Creates a new, empty file in the directory with the given name.
        /// Returns a stream writing this file.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public override IndexOutput CreateOutput(string name)
        {
            this.EnsureOpen();

            // create the file key
            var fileKey = GenerateFileKey(name);

            // attempt to get an existing object
            CacheFile cacheFile = this.objectCache.Get(fileKey, region) as CacheFile;

            // if the object exists, completely remove the item
            if (cacheFile != null)
            {
                DeleteFile(name);
            }

            // create a new instance of the cache file to be stored
            cacheFile = new CacheFile
            {
                Identifier = Guid.NewGuid().ToString(),
                LastModified = DateTimeOffset.UtcNow.Ticks / 10000L
            };

            // set the cache file info under the file key
            this.objectCache.Set(fileKey, cacheFile, region);

            // update the filesystem
            this.files.Add(name);

            Trace.WriteLine(string.Format("File {0} created", name));

            // return the stream to the new file
            return new CacheOutputStream(
                CreateStream(cacheFile));
        }
Пример #2
0
 /// <summary>
 /// Creates the stream.
 /// </summary>
 /// <param name="cacheFile">The cache file.</param>
 /// <returns></returns>
 protected virtual Stream CreateStream(CacheFile cacheFile)
 {
     // use the lucene segment stream to disable the checks that invalidate the stream
     // after it is disposed.
     return new LuceneSegmentStream(this.objectCache, cacheFile.Identifier);
 }