diff --git a/RoboSharp/Results/RoboCopyExitCodes.cs b/RoboSharp/Results/RoboCopyExitCodes.cs
index 22867e66..0241f9bd 100644
--- a/RoboSharp/Results/RoboCopyExitCodes.cs
+++ b/RoboSharp/Results/RoboCopyExitCodes.cs
@@ -34,5 +34,7 @@ public enum RoboCopyExitCodes
/// Either a usage error or an error due to insufficient access privileges on the source or destination directorie
///
SeriousErrorOccoured = 0x10,
+ /// The Robocopy process exited prior to completion
+ Cancelled = -1,
}
-}
\ No newline at end of file
+}
diff --git a/RoboSharp/Results/RoboCopyResults.cs b/RoboSharp/Results/RoboCopyResults.cs
index 6fa87f2d..18a56bc2 100644
--- a/RoboSharp/Results/RoboCopyResults.cs
+++ b/RoboSharp/Results/RoboCopyResults.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.Text;
namespace RoboSharp.Results
{
@@ -37,5 +38,93 @@ public override string ToString()
return str;
}
+
+ #pragma warning disable CS1734
+ // paramref produces a cleaner remark statement, but since they aren't method params, it causes this warning.
+
+ ///
+ /// Combines the RoboCopyResults object with this RoboCopyResults object.
+ ///
+ ///
+ /// RoboCopyResults object to combine with this one.
+ ///
+ /// The , , properties will be added together.
+ /// The properties will be averaged together.
+ /// The will be appended into a single large array.
+ /// The property will represent the combined results.
+ ///
+ public void CombineResult(RoboCopyResults resultsToCombine)
+ {
+ this.BytesStatistic.AddStatistic(resultsToCombine.BytesStatistic);
+ this.FilesStatistic.AddStatistic(resultsToCombine.FilesStatistic);
+ this.DirectoriesStatistic.AddStatistic(resultsToCombine.DirectoriesStatistic);
+ this.SpeedStatistic.AverageStatistic(resultsToCombine.SpeedStatistic);
+
+ List combinedlog = new List();
+ combinedlog.AddRange(this.LogLines);
+ combinedlog.AddRange(resultsToCombine.LogLines);
+ this.LogLines = combinedlog.ToArray();
+ }
+
+ ///
+ /// Combines the array of RoboCopyResults object with this RoboCopyResult object.
+ ///
+ /// Array or List of RoboCopyResults
+ ///
+ public void CombineResult(IEnumerable resultsToCombine)
+ {
+ //Initialize List Objects
+ List bytes = new List { };
+ List files = new List { };
+ List dirs = new List { };
+ List speed = new List { };
+ List status = new List { };
+ List combinedlog = new List();
+ combinedlog.AddRange(this.LogLines);
+
+ //Add all results to their respective lists
+ foreach (RoboCopyResults R in resultsToCombine)
+ {
+ bytes.Add(R.BytesStatistic);
+ files.Add(R.FilesStatistic);
+ dirs.Add(R.DirectoriesStatistic);
+ speed.Add(R.SpeedStatistic);
+ status.Add(R.Status);
+ combinedlog.AddRange(R.LogLines);
+ }
+
+ //Combine all results -> Done like this to reduce jumping in and out of functions repeatedly during the loop
+ this.BytesStatistic.AddStatistic(bytes);
+ this.FilesStatistic.AddStatistic(files);
+ this.DirectoriesStatistic.AddStatistic(dirs);
+ this.SpeedStatistic.AverageStatistic(speed);
+ this.Status.CombineStatus(status);
+ this.LogLines = combinedlog.ToArray();
+ }
+
+
+ ///
+ /// New RoboCopy Results Object.
+ ///
+ ///
+ public static RoboCopyResults CombineResults(RoboCopyResults resultsToCombine)
+ {
+ RoboCopyResults ret = new RoboCopyResults();
+ ret.CombineResult(resultsToCombine);
+ return ret;
+ }
+
+ ///
+ /// New RoboCopy Results Object.
+ ///
+ ///
+ public static RoboCopyResults CombineResults(IEnumerable resultsToCombine)
+ {
+ RoboCopyResults ret = new RoboCopyResults();
+ ret.CombineResult(resultsToCombine);
+ return ret;
+ }
+
+ #pragma warning restore CS1734
}
-}
\ No newline at end of file
+}
diff --git a/RoboSharp/Results/RoboCopyResultsStatus.cs b/RoboSharp/Results/RoboCopyResultsStatus.cs
index 2f4f9e9a..a3d214be 100644
--- a/RoboSharp/Results/RoboCopyResultsStatus.cs
+++ b/RoboSharp/Results/RoboCopyResultsStatus.cs
@@ -1,4 +1,6 @@
-namespace RoboSharp.Results
+using System.Collections.Generic;
+
+namespace RoboSharp.Results
{
///
/// Object that evaluates the ExitCode reported after RoboCopy finishes executing.
@@ -11,10 +13,11 @@ public class RoboCopyExitStatus
public RoboCopyExitStatus(int exitCodeValue)
{
ExitCodeValue = exitCodeValue;
+ IsCombinedStatus = false;
}
/// ExitCode as reported by RoboCopy
- public int ExitCodeValue { get; }
+ public int ExitCodeValue { get; private set; }
/// ExitCode reported by RoboCopy converted into the Enum
public RoboCopyExitCodes ExitCode => (RoboCopyExitCodes)ExitCodeValue;
@@ -28,6 +31,18 @@ public RoboCopyExitStatus(int exitCodeValue)
///
public bool HasErrors => ExitCodeValue >= 0x10;
+ ///
+ public bool WasCancelled => wascancelled || ExitCodeValue < 0x0;
+
+ ///
+ /// If this object is the result of two RoboCopyExitStatus objects being combined, this will be TRUE.
+ /// Otherwise this will be false.
+ ///
+ public bool IsCombinedStatus { get; private set; }
+
+ /// This is purely to facilitate the CombineStatus method
+ private bool wascancelled;
+
///
/// Returns a string that represents the current object.
///
@@ -35,5 +50,47 @@ public override string ToString()
{
return $"ExitCode: {ExitCodeValue} ({ExitCode})";
}
+
+ ///
+ /// Combine the RoboCopyExitCodes of the supplied ExitStatus with this ExitStatus.
+ ///
+ /// If any were Cancelled, set the WasCancelled property to TRUE. Otherwise combine the exit codes.
+ /// ExitStatus to combine with
+ public void CombineStatus(RoboCopyExitStatus status)
+ {
+ if (status.WasCancelled)
+ {
+ this.wascancelled = true;
+ }
+ else
+ {
+ RoboCopyExitCodes code = this.ExitCode & status.ExitCode;
+ this.ExitCodeValue = (int)code;
+ }
+ this.IsCombinedStatus = true;
+ }
+
+ ///
+ /// Combine all the RoboCopyExitStatuses together.
+ ///
+ /// Array or List of ExitStatuses to combine.
+ public void CombineStatus(IEnumerable status)
+ {
+ foreach (RoboCopyExitStatus s in status)
+ this.CombineStatus(s);
+ }
+
+ ///
+ /// Combine all the RoboCopyExitStatuses together.
+ ///
+ /// Array or List of ExitStatuses to combine.
+ /// new RoboCopyExitStatus object
+ public static RoboCopyExitStatus CombineStatuses(IEnumerable statuses)
+ {
+ RoboCopyExitStatus ret = new RoboCopyExitStatus(0);
+ ret.CombineStatus(statuses);
+ return ret;
+ }
+
}
-}
\ No newline at end of file
+}
diff --git a/RoboSharp/Results/SpeedStatistic.cs b/RoboSharp/Results/SpeedStatistic.cs
index 51bd4a07..1ff7a7fa 100644
--- a/RoboSharp/Results/SpeedStatistic.cs
+++ b/RoboSharp/Results/SpeedStatistic.cs
@@ -79,6 +79,13 @@ private static SpeedStatistic AddStatistics(IEnumerable stats)
#region AVERAGE
+
+ ///
+ /// Average the supplied object with this object.
+ ///
+ /// Object to average with
+ public void AverageStatistic(SpeedStatistic stat) => this.AddStatistic(new SpeedStatistic[] { stat });
+
///
/// Combine the supplied objects, then get the average.
///