using System;
using System.Text;
namespace RoboSharp
{
///
/// RoboCopy switches for how to react if a copy/move operation errors
///
///
///
///
public class RetryOptions : ICloneable
{
#region Constructors
///
/// Create new RetryOptions with Default Settings
///
public RetryOptions() { }
///
/// Clone a RetryOptions Object
///
/// RetryOptions object to clone
public RetryOptions(RetryOptions options)
{
WaitForSharenames = options.WaitForSharenames;
SaveToRegistry = options.SaveToRegistry;
RetryWaitTime = options.RetryWaitTime;
RetryCount = options.RetryCount;
}
///
public RetryOptions Clone() => new RetryOptions(this);
object ICloneable.Clone() => Clone();
#endregion
internal const string RETRY_COUNT = "/R:{0} ";
internal const string RETRY_WAIT_TIME = "/W:{0} ";
internal const string SAVE_TO_REGISTRY = "/REG ";
internal const string WAIT_FOR_SHARENAMES = "/TBD ";
private int retryCount = 0;
private int retryWaitTime = 30;
///
/// Specifies the number of retries N on failed copies (default is 0).
/// [/R:N]
///
public virtual int RetryCount
{
get { return retryCount; }
set { retryCount = value; }
}
///
/// Specifies the wait time N in seconds between retries (default is 30).
/// [/W:N]
///
public virtual int RetryWaitTime
{
get { return retryWaitTime; }
set { retryWaitTime = value; }
}
///
/// Saves RetryCount and RetryWaitTime in the Registry as default settings.
/// [/REG]
///
public virtual bool SaveToRegistry { get; set; }
///
/// Wait for sharenames to be defined.
/// [/TBD]
///
public virtual bool WaitForSharenames { get; set; }
internal string Parse()
{
var options = new StringBuilder();
options.Append(string.Format(RETRY_COUNT, RetryCount));
options.Append(string.Format(RETRY_WAIT_TIME, RetryWaitTime));
if (SaveToRegistry)
options.Append(SAVE_TO_REGISTRY);
if (WaitForSharenames)
options.Append(WAIT_FOR_SHARENAMES);
return options.ToString();
}
///
/// Combine this object with another RetryOptions object.
/// Any properties marked as true take priority. IEnumerable items are combined.
/// String Values will only be replaced if the primary object has a null/empty value for that property.
///
///
public void Merge(RetryOptions options)
{
RetryCount = RetryCount.GetGreaterVal(options.RetryCount);
RetryWaitTime = RetryWaitTime.GetGreaterVal(options.RetryWaitTime);
WaitForSharenames |= options.WaitForSharenames;
SaveToRegistry |= options.SaveToRegistry;
}
}
}