本文整理汇总了C#中Lucene.Net.Store.Directory.FileExists方法的典型用法代码示例。如果您正苦于以下问题:C# Directory.FileExists方法的具体用法?C# Directory.FileExists怎么用?C# Directory.FileExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Store.Directory
的用法示例。
在下文中一共展示了Directory.FileExists方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnidirectionalSync
private static void UnidirectionalSync(AzureDirectory sourceDirectory, Directory destinationDirectory)
{
var sourceFiles = sourceDirectory.ListAll();
var fileNameFilter = IndexFileNameFilter.Filter;
byte[] buffer = new byte[16384];
foreach (string sourceFile in sourceFiles)
{
// only copy file if it is accepted by Lucene's default filter
// and it does not already exist (except for segment map files, we always want those)
if (fileNameFilter.Accept(null, sourceFile) && (!destinationDirectory.FileExists(sourceFile) || sourceFile.StartsWith("segment")))
{
IndexOutput indexOutput = null;
IndexInput indexInput = null;
try
{
indexOutput = destinationDirectory.CreateOutput(sourceFile);
indexInput = sourceDirectory.OpenInput(sourceFile);
long length = indexInput.Length();
long position = 0;
while (position < length)
{
int bytesToRead = position + 16384L > length ? (int)(length - position) : 16384;
indexInput.ReadBytes(buffer, 0, bytesToRead);
indexOutput.WriteBytes(buffer, bytesToRead);
position += bytesToRead;
}
}
finally
{
try
{
indexOutput?.Close();
}
finally
{
indexInput?.Close();
}
}
}
}
// we'll remove old files from both AzureDirectory's cache directory, as well as our destination directory
// (only when older than 45 minutes - old files may still have active searches on them so we need a margin)
var referenceTimestamp = LuceneTimestampFromDateTime(DateTime.UtcNow.AddMinutes(-45));
// remove old files from AzureDirectory cache directory
RemoveOldFiles(sourceDirectory.CacheDirectory, sourceFiles, referenceTimestamp);
// remove old files from destination directory
RemoveOldFiles(destinationDirectory, sourceFiles, referenceTimestamp);
}
示例2: EnsureIndexVersionMatches
private void EnsureIndexVersionMatches(LuceneDirectory directory)
{
if (directory.FileExists(IndexVersionFilename) == false)
throw new InvalidOperationException("Could not find " + IndexVersionFilename + " for '" + name + "', resetting index");
using (var indexInput = directory.OpenInput(IndexVersionFilename))
{
var versionToCheck = IndexVersion;
var versionFromDisk = indexInput.ReadString();
if (versionFromDisk != versionToCheck)
throw new InvalidOperationException("Index for " + name + " is of version " + versionFromDisk +
" which is not compatible with " + versionToCheck + ", resetting index");
}
}
示例3: CheckDirectoryFilter
// LUCENE-1468
private void CheckDirectoryFilter(Directory dir)
{
System.String name = "file";
try
{
dir.CreateOutput(name).Close();
Assert.IsTrue(dir.FileExists(name));
Assert.IsTrue(new System.Collections.ArrayList(dir.ListAll()).Contains(name));
}
finally
{
dir.Close();
}
}
示例4: EnsureIndexVersionMatches
private static void EnsureIndexVersionMatches(Directory directory, IndexDefinition indexDefinition)
{
var versionToCheck = IndexVersion;
if (indexDefinition.IsMapReduce)
{
versionToCheck = MapReduceIndexVersion;
}
var indexVersion = IndexVersionFileName(indexDefinition);
if (directory.FileExists(indexVersion) == false)
{
throw new InvalidOperationException("Could not find " + indexVersion + " " + indexDefinition.IndexId + ", resetting index");
}
using (var indexInput = directory.OpenInput(indexVersion))
{
var versionFromDisk = indexInput.ReadString();
if (versionFromDisk != versionToCheck)
throw new InvalidOperationException("Index " + indexDefinition.IndexId + " is of version " + versionFromDisk +
" which is not compatible with " + versionToCheck + ", resetting index");
}
}
示例5: CreateSearcher
protected virtual IndexSearcher CreateSearcher(Directory dir)
{
if (!dir.FileExists("segments.gen"))
GetWriter().Commit();
var s = new IndexSearcher(dir, readOnly: true);
return s;
}
示例6: CreateSearcher
protected virtual IndexSearcher CreateSearcher(Directory dir)
{
if (!dir.FileExists("segments.gen"))
{
logger.Info("No segments.gen (whatever that means)");
GetWriter().Commit();
}
var s = new IndexSearcher(dir, readOnly: true);
return s;
}