/// <summary> /// Raises event 'BeforeSort' /// </summary> protected virtual void OnBeforeSort() { if (BeforeSort != null) { BeforeSort.Invoke(this, System.EventArgs.Empty); } }
public void SortByOneDate(DateTime dt, string pattern = "") { try { DirectoryInfo drInfo = new DirectoryInfo(_logPath); var files = drInfo.GetFiles(pattern).ToList(); var dr = _logPath + @"\" + dt.ToString("yyyy-MM-dd"); if (!Directory.Exists(dr)) { var newDrInfo = Directory.CreateDirectory(dr); if (NewDirection_Create != null) { NewDirection_Create.BeginInvoke(dr, null, null); } } if (BeforeSort != null) { BeforeSort.Invoke(files.Count); } var index = 0; files.ForEach(x => { if (BeforeSortOne_Update != null) { BeforeSortOne_Update.Invoke(index, x.Name); } try { File.Move(x.FullName, dr + @"\" + x.Name); } catch (Exception ex) { if (AfterSortOne_Exception != null) { AfterSortOne_Exception.Invoke(index, x.Name, ex); } } if (AfterSortOne_Update != null) { AfterSortOne_Update.Invoke(index, x.Name); } index++; }); if (AfterSort != null) { AfterSort.Invoke(); } } catch (Exception ex) { throw ex; } }