当前位置: 首页>>代码示例>>C#>>正文


C# Lucene.Net.Store.Directory.FileModified方法代码示例

本文整理汇总了C#中Lucene.Net.Store.Directory.FileModified方法的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Store.Directory.FileModified方法的具体用法?C# Lucene.Net.Store.Directory.FileModified怎么用?C# Lucene.Net.Store.Directory.FileModified使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lucene.Net.Store.Directory的用法示例。


在下文中一共展示了Lucene.Net.Store.Directory.FileModified方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LastModified

 /// <summary> Returns the time the index in the named directory was last modified. 
 /// Do not use this to check whether the reader is still up-to-date, use
 /// {@link #IsCurrent()} instead. 
 /// </summary>
 public static long LastModified(Directory directory)
 {
     return directory.FileModified(IndexFileNames.SEGMENTS);
 }
开发者ID:kiichi7,项目名称:Search-Engine,代码行数:8,代码来源:IndexReader.cs

示例2: CachedIndexInput

        public CachedIndexInput( ICloudProvider CloudProvider, Directory CacheDirectory, string Name )
        {
            this.name = Name;

            #if FULLDEBUG
            Debug.WriteLine( "Opening " + this.name );
            #endif
            this.fileMutex = BlobMutexManager.GrabMutex( this.name );
            this.fileMutex.WaitOne();
            try {

                bool fFileNeeded = false;
                FileMetadata cloudMetadata = CloudProvider.FileMetadata( this.name );
                if ( !cloudMetadata.Exists ) {
                    fFileNeeded = false;
                    // TODO: Delete local if it doesn't exist on cloud?
                    /*
                    if (CacheDirectory.FileExists(this.name)) {
                        CacheDirectory.DeleteFile(this.name);
                    }
                    */
                } else if ( !CacheDirectory.FileExists( this.name ) ) {
                    fFileNeeded = true;
                } else {
                    long cachedLength = CacheDirectory.FileLength( this.name );

                    long blobLength = cloudMetadata.Length;
                    DateTime blobLastModifiedUTC = cloudMetadata.LastModified.ToUniversalTime();

                    if ( !cloudMetadata.Exists || cachedLength != blobLength ) {
                        fFileNeeded = true;
                    } else {
                        // there seems to be an error of 1 tick which happens every once in a while
                        // for now we will say that if they are within 1 tick of each other and same length
                        DateTime cachedLastModifiedUTC = new DateTime( CacheDirectory.FileModified( this.name ), DateTimeKind.Local ).ToUniversalTime();
                        if ( cachedLastModifiedUTC < blobLastModifiedUTC ) {
                            TimeSpan timeSpan = blobLastModifiedUTC.Subtract( cachedLastModifiedUTC );
                            if ( timeSpan.TotalSeconds > 1 ) {
                                fFileNeeded = true;
                            } else {
            #if FULLDEBUG
                                Debug.WriteLine( "Using cache for " + this.name + ": " + timeSpan.TotalSeconds );
            #endif
                                // file not needed
                            }
                        }
                    }
                }

                // if the file does not exist
                // or if it exists and it is older then the lastmodified time in the blobproperties (which always comes from the blob storage)
                if ( fFileNeeded ) {
                    using ( StreamOutput fileStream = new StreamOutput( CacheDirectory.CreateOutput( this.name ) ) ) {

                        Stream blobStream = CloudProvider.Download( this.name );
                        blobStream.CopyTo( fileStream );

                        fileStream.Flush();
                        Debug.WriteLine( "GET {0} RETREIVED {1} bytes", this.name, fileStream.Length );

                    }
                } else {
            #if FULLDEBUG
                    if ( !cloudMetadata.Exists ) {
                        Debug.WriteLine( "Cloud doesn't have " + this.name );
                    } else {
                        Debug.WriteLine( "Using cached file for " + this.name );
                    }
            #endif
                }

                // open the file in read only mode
                this.indexInput = CacheDirectory.OpenInput( this.name );
            } finally {
                this.fileMutex.ReleaseMutex();
            }
        }
开发者ID:robrich,项目名称:LuceneCloudDirectory,代码行数:77,代码来源:CachedIndexInput.cs


注:本文中的Lucene.Net.Store.Directory.FileModified方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。