81 lines
1.9 KiB
C#
81 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Specialized;
|
|
namespace SPSolutions.SharePoint.Administration
|
|
{
|
|
public abstract class CommandLineOperation
|
|
{
|
|
internal const int SuccessStatus = 0;
|
|
private StringDictionary m_keyValues;
|
|
private CommandLineParameterCollection m_parameters = new CommandLineParameterCollection();
|
|
public abstract string CommandName
|
|
{
|
|
get;
|
|
}
|
|
public abstract string HelpMessage
|
|
{
|
|
get;
|
|
}
|
|
private StringDictionary KeyValues
|
|
{
|
|
get
|
|
{
|
|
return this.m_keyValues;
|
|
}
|
|
}
|
|
public CommandLineParameterCollection Parameters
|
|
{
|
|
get
|
|
{
|
|
return this.m_parameters;
|
|
}
|
|
}
|
|
public CommandLineOperation()
|
|
{
|
|
}
|
|
public abstract void CreateParameters();
|
|
public abstract int Run(out string output);
|
|
public void Initialize(StringDictionary keyValues)
|
|
{
|
|
this.m_keyValues = keyValues;
|
|
foreach (CommandLineParameter current in this.Parameters.Values)
|
|
{
|
|
current.Initialize(keyValues);
|
|
}
|
|
}
|
|
protected virtual void Validate()
|
|
{
|
|
string text = null;
|
|
foreach (string text2 in this.KeyValues.Keys)
|
|
{
|
|
if (text2 != "o" && !this.Parameters.ContainsKey(text2))
|
|
{
|
|
text += string.Format("Unknown command line argument: {0}\n", text2);
|
|
}
|
|
}
|
|
foreach (CommandLineParameter current in this.Parameters.Values)
|
|
{
|
|
if (current.IsRequired && !current.UserTypedIn)
|
|
{
|
|
text += string.Format("Missing required argument: {0}\n", current.Name);
|
|
}
|
|
else
|
|
{
|
|
if (current.UserTypedIn && !current.Validate())
|
|
{
|
|
text += string.Format("Invalid argument value: {0}\n", current.Name);
|
|
if (!string.IsNullOrEmpty(current.HelpMessage))
|
|
{
|
|
text = text + "\t" + current.HelpMessage + "\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (text != null)
|
|
{
|
|
text += string.Format("\nstsadm.exe -o {0} \n{1}", this.CommandName, this.HelpMessage);
|
|
throw new Exception(text);
|
|
}
|
|
}
|
|
}
|
|
}
|