Files
FSI.BT.IR.Tools/FSI.Lib/Tools/RoboSharp/EventArgObjects/ErrorEventArgs.cs
maier_S 907ad039c4 Squashed 'FSI.Lib/' changes from 6aa4846..4a27cd3
4a27cd3 RoboSharp eingefügt
1b2fc1f Erweiterungsmethode für Startparameter einefügt

git-subtree-dir: FSI.Lib
git-subtree-split: 4a27cd377a1959dc669625473b018e42c31ef147
2022-03-23 14:17:56 +01:00

90 lines
2.7 KiB
C#

using System;
using System.Linq;
using System.Text.RegularExpressions;
// Do Not change NameSpace here! -> Must be RoboSharp due to prior releases
namespace FSI.Lib.Tools.RoboSharp
{
/// <summary>
/// Information about an Error reported by the RoboCopy process
/// </summary>
public class ErrorEventArgs : EventArgs
{
/// <summary>
/// Error Code
/// </summary>
public string Error { get; }
/// <summary>
/// Error Description
/// </summary>
public string ErrorDescription { get; }
/// <summary>
/// Error Code
/// </summary>
public int ErrorCode { get; }
/// <summary>
/// Signed Error Code
/// </summary>
public string SignedErrorCode { get; }
/// <summary>
/// The File or Directory Path the Error refers to
/// </summary>
public string ErrorPath { get; }
/// <summary>
/// DateTime the error occurred
/// </summary>
public DateTime DateTime { get; }
/// <summary>
/// Concatenate the <see cref="Error"/> and <see cref="ErrorDescription"/> into a string seperated by an <see cref="Environment.NewLine"/>
/// </summary>
/// <returns></returns>
public override string ToString()
{
if (ErrorDescription.IsNullOrWhiteSpace())
return Error;
else
return String.Format("{0}{1}{2}", Error, Environment.NewLine, ErrorDescription);
}
/// <summary>
/// <inheritdoc cref="ErrorEventArgs"/>
/// </summary>
/// <param name="errorData"><inheritdoc cref="Error"/></param>
/// <param name="descripData"><inheritdoc cref="ErrorCode"/></param>
/// <param name="errTokenRegex">
/// Regex used to split the Error Code into its various parts. <br/>
/// Must have the following groups: Date, ErrCode, SignedErrCode, Descrip, Path
/// </param>
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;
}
}
}