public static void DeleteAllFiles(this DirectoryInfo DI)
 {
     foreach (FileInfo FI in DI.GetFiles())
     {
         try
         {
             FI.Delete();
         }
         catch
         {
         }
     }
 }
Exemple #2
0
        private void ApplyRetainPolicy(DirectoryInfo directory)
        {
            FileInfo FI;

            try
            {
                List <FileInfo> FileList = directory.GetFiles("*.log", SearchOption.TopDirectoryOnly).OrderBy(fi => fi.CreationTime).ToList();
                while (FileList.Count >= 30)
                {
                    FI = FileList.First();
                    FI.Delete();
                    FileList.Remove(FI);
                }
            }
            catch
            {
            }
        }
Exemple #3
0
        void HandleDelete()
        {
            log.Write("Удаление: ");
            FileInfo      FI   = null;
            DirectoryInfo DI   = null;
            String        path = CNB.Br.ReadString();

            path = "ServerData/" + path;
            log.Write(path);
            string answer = "@@@";

            if (path.Contains('.'))
            {
                FI = new FileInfo(path);
            }
            else
            {
                DI = new DirectoryInfo(path);
            }
            if (FI != null)
            {
                try
                {
                    FI.Delete();
                    answer = "Файл успешно удалён";
                }
                catch (Exception E) { answer = $"Не удалось переместить файл - {E.Message}"; }
            }
            else
            {
                try
                {
                    DI.Delete();
                    answer = "Директория успешно удалена";
                }
                catch (Exception E) { answer = $"Не удалось переместить директорию - {E.Message}"; }
            }
            log.Write(answer);
            CNB.Bw.Write(answer);
            cs.Send(CNB.Ms_Buf);
            log.WriteLine("!");
        }
Exemple #4
0
        void ApplyRetainPolicy()
        {
            FileInfo FI;

            try
            {
                List <FileInfo> FileList = new DirectoryInfo(Settings.Folder)
                                           .GetFiles("*.log", SearchOption.TopDirectoryOnly)
                                           .OrderBy(fi => fi.CreationTime)
                                           .ToList();

                while (FileList.Count >= Settings.RetainPolicyFileCount)
                {
                    FI = FileList.First();
                    FI.Delete();
                    FileList.Remove(FI);
                }
            }
            catch
            {
            }
        }
        // TODO: excise the sink specific methods below to an appropriate interface.

        #region Sink specific methods

        /// <summary>Applies the log file retains policy according to options</summary>
        private void ApplyRetainPolicy()
        {
            FileInfo FI;

            try
            {
                List <FileInfo> FileList = new DirectoryInfo(LoggerOptions.Folder)
                                           .GetFiles("*.log", SearchOption.TopDirectoryOnly)
                                           .OrderBy(fi => fi.CreationTime)
                                           .ToList();

                while (FileList.Count >= LoggerOptions.RetainPolicyFileCount)
                {
                    FI = FileList.First();
                    FI.Delete();
                    FileList.Remove(FI);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message); // TODO: consider how to handle low level logging failures e.g. IOExceptions
            }
        }