Esempio n. 1
0
            private void Purge()
            {
                if (KeepCount == 0)
                {
                    return;
                }
                try
                {
                    bool ResolveDate(FileItem item)
                    {
                        string dateCode = Path.GetFileNameWithoutExtension(item.FilePath).Replace(Code, string.Empty);

                        dateCode = dateCode.SplitNoEmptyLines(" (")[0];
                        try
                        {
                            item.Date = SQLiteDate.ToDateTime(dateCode.Trim());
                            return(true);
                        }
                        catch
                        {
                            return(false);
                        }
                    }
                    var list = Directory.GetFiles(Folder, $"{Code}*{Extension}")
                               .Select(path => new FileItem {
                        FilePath = path
                    })
                               .Where(item => ResolveDate(item));
                    DateTime limit;
                    switch (Mode)
                    {
                    case TraceFileRollOverMode.Daily:
                        limit = DateTime.Now.Date.AddDays(-KeepCount);
                        break;

                    case TraceFileRollOverMode.Monthly:
                        limit = DateTime.Now.Date.AddMonths(-KeepCount);
                        break;

                    default:
                        throw new AdvancedNotImplementedException(Mode);
                    }
                    foreach (var file in list.Where(f => f.Date <= limit))
                    {
                        try
                        {
                            File.Delete(file.FilePath);
                        }
                        catch
                        {
                        }
                    }
                }
                catch
                {
                }
            }
Esempio n. 2
0
            private string GenerateFilePath()
            {
                Purge();
                Date = DateTime.Today;
                string ProcessName = SystemManager.AllowMultipleInstances ? $" ({Globals.ProcessId})" : string.Empty;

                FilePath = Path.Combine(Folder, $"{Code} {SQLiteDate.ToString(Date)}{ProcessName}{Extension}");
                SystemManager.TryCatchManage(() => { Changed?.Invoke(this, FilePath); });
                return(FilePath);
            }