using System; using System.Linq; using System.Text.RegularExpressions; // Do Not change NameSpace here! -> Must be RoboSharp due to prior releases namespace RoboSharp { /// /// Information about an Error reported by the RoboCopy process /// public class ErrorEventArgs : EventArgs { /// /// Error Code /// public string Error { get; } /// /// Error Description /// public string ErrorDescription { get; } /// /// Error Code /// public int ErrorCode { get; } /// /// Signed Error Code /// public string SignedErrorCode { get; } /// /// The File or Directory Path the Error refers to /// public string ErrorPath { get; } /// /// DateTime the error occurred /// public DateTime DateTime { get; } /// /// Concatenate the and into a string seperated by an /// /// public override string ToString() { if (ErrorDescription.IsNullOrWhiteSpace()) return Error; else return String.Format("{0}{1}{2}", Error, Environment.NewLine, ErrorDescription); } /// /// /// /// /// /// /// Regex used to split the Error Code into its various parts.
/// Must have the following groups: Date, ErrCode, SignedErrCode, Descrip, Path /// internal ErrorEventArgs(string errorData, string descripData, Regex errTokenRegex) { var match = errTokenRegex.Match(errorData); var groups = match.Groups; //Date string dateStr = groups["Date"].Value; if (DateTime.TryParse(dateStr, out var DT)) this.DateTime = DT; else this.DateTime = DateTime.Now; //Path ErrorPath = groups["Path"].Value; //Error Code ErrorCode = Convert.ToInt32(groups["ErrCode"].Value); SignedErrorCode = groups["SignedErrCode"].Value; //Error String Error = errorData; ErrorDescription = descripData; } } }