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


C# Directory.FileExists方法代码示例

本文整理汇总了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);
        }
开发者ID:NuGet,项目名称:NuGet.Services.Metadata,代码行数:55,代码来源:AzureDirectorySynchronizer.cs

示例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");
     }
 }
开发者ID:j2jensen,项目名称:ravendb,代码行数:14,代码来源:IndexStorage.cs

示例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();
			}
		}
开发者ID:synhershko,项目名称:lucene.net,代码行数:15,代码来源:TestDirectory.cs

示例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");
     }
 }
开发者ID:IdanHaim,项目名称:ravendb,代码行数:20,代码来源:IndexStorage.cs

示例5: CreateSearcher

		protected virtual IndexSearcher CreateSearcher(Directory dir)
		{
			if (!dir.FileExists("segments.gen"))
				GetWriter().Commit();
			var s = new IndexSearcher(dir, readOnly: true);
			return s;
		}
开发者ID:meixger,项目名称:n2cms,代码行数:7,代码来源:LuceneAccesor.cs

示例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;
        }
开发者ID:Biswo,项目名称:n2cms,代码行数:10,代码来源:LuceneAccesor.cs


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