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


C# Directory.DeleteFile方法代码示例

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


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

示例1: RemoveOldFiles

 private static void RemoveOldFiles(Directory directory, string[] skipFiles, long referenceTimestamp)
 {
     var destinationFiles = directory.ListAll();
     var filesToRemove = destinationFiles.Except(skipFiles);
     foreach (var file in filesToRemove)
     {
         if (directory.FileModified(file) < referenceTimestamp)
         {
             directory.DeleteFile(file);
         }
     }
 }
开发者ID:NuGet,项目名称:NuGet.Services.Metadata,代码行数:12,代码来源:AzureDirectorySynchronizer.cs

示例2: Write

        private void Write(Directory directory)
        {
            string segmentsFileName = NextSegmentFileName;

            // Always advance the generation on write:
            if (_generation == -1)
            {
                _generation = 1;
            }
            else
            {
                _generation++;
            }

            IndexOutput segnOutput = null;
            bool success = false;

            var upgradedSIFiles = new HashSet<string>();

            try
            {
                segnOutput = directory.CreateOutput(segmentsFileName, IOContext.DEFAULT);
                CodecUtil.WriteHeader(segnOutput, "segments", VERSION_48);
                segnOutput.WriteLong(Version);
                segnOutput.WriteInt(Counter); // write counter
                segnOutput.WriteInt(Size()); // write infos
                foreach (SegmentCommitInfo siPerCommit in segments)
                {
                    SegmentInfo si = siPerCommit.Info;
                    segnOutput.WriteString(si.Name);
                    segnOutput.WriteString(si.Codec.Name);
                    segnOutput.WriteLong(siPerCommit.DelGen);
                    int delCount = siPerCommit.DelCount;
                    if (delCount < 0 || delCount > si.DocCount)
                    {
                        throw new InvalidOperationException("cannot write segment: invalid docCount segment=" + si.Name + " docCount=" + si.DocCount + " delCount=" + delCount);
                    }
                    segnOutput.WriteInt(delCount);
                    segnOutput.WriteLong(siPerCommit.FieldInfosGen);
                    IDictionary<long, ISet<string>> genUpdatesFiles = siPerCommit.UpdatesFiles;
                    segnOutput.WriteInt(genUpdatesFiles.Count);
                    foreach (KeyValuePair<long, ISet<string>> e in genUpdatesFiles)
                    {
                        segnOutput.WriteLong(e.Key);
                        segnOutput.WriteStringSet(e.Value);
                    }
                    Debug.Assert(si.Dir == directory);

                    // If this segment is pre-4.x, perform a one-time
                    // "ugprade" to write the .si file for it:
                    string version = si.Version;
                    if (version == null || StringHelper.VersionComparator.Compare(version, "4.0") < 0)
                    {
                        if (!SegmentWasUpgraded(directory, si))
                        {
                            string markerFileName = IndexFileNames.SegmentFileName(si.Name, "upgraded", Lucene3xSegmentInfoFormat.UPGRADED_SI_EXTENSION);
                            si.AddFile(markerFileName);

                            string segmentFileName = Write3xInfo(directory, si, IOContext.DEFAULT);
                            upgradedSIFiles.Add(segmentFileName);
                            directory.Sync(/*Collections.singletonList(*/new[] { segmentFileName }/*)*/);

                            // Write separate marker file indicating upgrade
                            // is completed.  this way, if there is a JVM
                            // kill/crash, OS crash, power loss, etc. while
                            // writing the upgraded file, the marker file
                            // will be missing:
                            IndexOutput @out = directory.CreateOutput(markerFileName, IOContext.DEFAULT);
                            try
                            {
                                CodecUtil.WriteHeader(@out, SEGMENT_INFO_UPGRADE_CODEC, SEGMENT_INFO_UPGRADE_VERSION);
                            }
                            finally
                            {
                                @out.Dispose();
                            }
                            upgradedSIFiles.Add(markerFileName);
                            directory.Sync(/*Collections.SingletonList(*/new[] { markerFileName }/*)*/);
                        }
                    }
                }
                segnOutput.WriteStringStringMap(_userData);
                PendingSegnOutput = segnOutput;
                success = true;
            }
            finally
            {
                if (!success)
                {
                    // We hit an exception above; try to close the file
                    // but suppress any exception:
                    IOUtils.CloseWhileHandlingException(segnOutput);

                    foreach (string fileName in upgradedSIFiles)
                    {
                        try
                        {
                            directory.DeleteFile(fileName);
                        }
                        catch (Exception)
//.........这里部分代码省略.........
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:101,代码来源:SegmentInfos.cs

示例3: FinishCommit

        internal void FinishCommit(Directory dir)
        {
            if (PendingSegnOutput == null)
            {
                throw new InvalidOperationException("prepareCommit was not called");
            }
            bool success = false;
            try
            {
                CodecUtil.WriteFooter(PendingSegnOutput);
                success = true;
            }
            finally
            {
                if (!success)
                {
                    // Closes pendingSegnOutput & deletes partial segments_N:
                    RollbackCommit(dir);
                }
                else
                {
                    success = false;
                    try
                    {
                        PendingSegnOutput.Dispose();
                        success = true;
                    }
                    finally
                    {
                        if (!success)
                        {
                            // Closes pendingSegnOutput & deletes partial segments_N:
                            RollbackCommit(dir);
                        }
                        else
                        {
                            PendingSegnOutput = null;
                        }
                    }
                }
            }

            // NOTE: if we crash here, we have left a segments_N
            // file in the directory in a possibly corrupt state (if
            // some bytes made it to stable storage and others
            // didn't).  But, the segments_N file includes checksum
            // at the end, which should catch this case.  So when a
            // reader tries to read it, it will throw a
            // CorruptIndexException, which should cause the retry
            // logic in SegmentInfos to kick in and load the last
            // good (previous) segments_N-1 file.

            var fileName = IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", _generation);
            success = false;
            try
            {
                dir.Sync(Collections.Singleton(fileName));
                success = true;
            }
            finally
            {
                if (!success)
                {
                    try
                    {
                        dir.DeleteFile(fileName);
                    }
                    catch (Exception)
                    {
                        // Suppress so we keep throwing the original exception
                    }
                }
            }

            _lastGeneration = _generation;
            WriteSegmentsGen(dir, _generation);
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:77,代码来源:SegmentInfos.cs

示例4: WriteSegmentsGen

 /// <summary>
 /// A utility for writing the <seealso cref="IndexFileNames#SEGMENTS_GEN"/> file to a
 /// <seealso cref="Directory"/>.
 ///
 /// <p>
 /// <b>NOTE:</b> this is an internal utility which is kept public so that it's
 /// accessible by code from other packages. You should avoid calling this
 /// method unless you're absolutely sure what you're doing!
 ///
 /// @lucene.internal
 /// </summary>
 public static void WriteSegmentsGen(Directory dir, long generation)
 {
     try
     {
         IndexOutput genOutput = dir.CreateOutput(IndexFileNames.SEGMENTS_GEN, IOContext.READONCE);
         try
         {
             genOutput.WriteInt(FORMAT_SEGMENTS_GEN_CURRENT);
             genOutput.WriteLong(generation);
             genOutput.WriteLong(generation);
             CodecUtil.WriteFooter(genOutput);
         }
         finally
         {
             genOutput.Dispose();
             dir.Sync(Collections.Singleton(IndexFileNames.SEGMENTS_GEN));
         }
     }
     catch (Exception)
     {
         // It's OK if we fail to write this file since it's
         // used only as one of the retry fallbacks.
         try
         {
             dir.DeleteFile(IndexFileNames.SEGMENTS_GEN);
         }
         catch (Exception)
         {
             // Ignore; this file is only used in a retry
             // fallback on init.
         }
     }
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:44,代码来源:SegmentInfos.cs

示例5: Copy

 /// <summary>
 /// Copies the file <i>src</i> to <seealso cref="Directory"/> <i>to</i> under the new
 /// file name <i>dest</i>.
 /// <p>
 /// If you want to copy the entire source directory to the destination one, you
 /// can do so like this:
 ///
 /// <pre class="prettyprint">
 /// Directory to; // the directory to copy to
 /// for (String file : dir.listAll()) {
 ///   dir.copy(to, file, newFile, IOContext.DEFAULT); // newFile can be either file, or a new name
 /// }
 /// </pre>
 /// <p>
 /// <b>NOTE:</b> this method does not check whether <i>dest</i> exist and will
 /// overwrite it if it does.
 /// </summary>
 public virtual void Copy(Directory to, string src, string dest, IOContext context)
 {
     IndexOutput os = null;
     IndexInput @is = null;
     System.IO.IOException priorException = null;
     try
     {
         os = to.CreateOutput(dest, context);
         @is = OpenInput(src, context);
         os.CopyBytes(@is, @is.Length());
     }
     catch (System.IO.IOException ioe)
     {
         priorException = ioe;
     }
     finally
     {
         bool success = false;
         try
         {
             IOUtils.CloseWhileHandlingException(priorException, os, @is);
             success = true;
         }
         finally
         {
             if (!success)
             {
                 try
                 {
                     to.DeleteFile(dest);
                 }
                 catch (Exception)
                 {
                 }
             }
         }
     }
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:55,代码来源:Directory.cs


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