本文整理汇总了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);
}
示例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();
}
}