mirror of https://github.com/winsw/winsw
Use built-in types
parent
9808ae88e8
commit
08bae2a682
|
@ -143,7 +143,7 @@ namespace winsw
|
|||
return logAppender;
|
||||
}
|
||||
|
||||
public void LogEvent(String message)
|
||||
public void LogEvent(string message)
|
||||
{
|
||||
if (_systemShuttingdown)
|
||||
{
|
||||
|
@ -162,7 +162,7 @@ namespace winsw
|
|||
}
|
||||
}
|
||||
|
||||
public void LogEvent(String message, EventLogEntryType type)
|
||||
public void LogEvent(string message, EventLogEntryType type)
|
||||
{
|
||||
if (_systemShuttingdown)
|
||||
{
|
||||
|
@ -196,7 +196,7 @@ namespace winsw
|
|||
// handle downloads
|
||||
foreach (Download d in _descriptor.Downloads)
|
||||
{
|
||||
String downloadMsg = "Downloading: " + d.From + " to " + d.To + ". failOnError=" + d.FailOnError;
|
||||
string downloadMsg = "Downloading: " + d.From + " to " + d.To + ". failOnError=" + d.FailOnError;
|
||||
LogEvent(downloadMsg);
|
||||
Log.Info(downloadMsg);
|
||||
try
|
||||
|
@ -303,7 +303,7 @@ namespace winsw
|
|||
stoparguments += " " + _descriptor.Arguments;
|
||||
|
||||
Process stopProcess = new Process();
|
||||
String executable = _descriptor.StopExecutable;
|
||||
string executable = _descriptor.StopExecutable;
|
||||
|
||||
if (executable == null)
|
||||
{
|
||||
|
@ -335,11 +335,11 @@ namespace winsw
|
|||
SignalShutdownPending();
|
||||
|
||||
int effectiveProcessWaitSleepTime;
|
||||
if (_descriptor.SleepTime.TotalMilliseconds > Int32.MaxValue)
|
||||
if (_descriptor.SleepTime.TotalMilliseconds > int.MaxValue)
|
||||
{
|
||||
Log.Warn("The requested sleep time " + _descriptor.SleepTime.TotalMilliseconds + "is greater that the max value " +
|
||||
Int32.MaxValue + ". The value will be truncated");
|
||||
effectiveProcessWaitSleepTime = Int32.MaxValue;
|
||||
int.MaxValue + ". The value will be truncated");
|
||||
effectiveProcessWaitSleepTime = int.MaxValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -367,11 +367,11 @@ namespace winsw
|
|||
private void SignalShutdownPending()
|
||||
{
|
||||
int effectiveWaitHint;
|
||||
if (_descriptor.WaitHint.TotalMilliseconds > Int32.MaxValue)
|
||||
if (_descriptor.WaitHint.TotalMilliseconds > int.MaxValue)
|
||||
{
|
||||
Log.Warn("The requested WaitHint value (" + _descriptor.WaitHint.TotalMilliseconds + " ms) is greater that the max value " +
|
||||
Int32.MaxValue + ". The value will be truncated");
|
||||
effectiveWaitHint = Int32.MaxValue;
|
||||
int.MaxValue + ". The value will be truncated");
|
||||
effectiveWaitHint = int.MaxValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -395,7 +395,7 @@ namespace winsw
|
|||
Advapi32.SetServiceStatus(handle, ref _wrapperServiceStatus);
|
||||
}
|
||||
|
||||
private void StartProcess(Process processToStart, string arguments, String executable, LogHandler logHandler, bool redirectStdin)
|
||||
private void StartProcess(Process processToStart, string arguments, string executable, LogHandler logHandler, bool redirectStdin)
|
||||
{
|
||||
// Define handler of the completed process
|
||||
ProcessCompletionCallback processCompletionCallback = proc =>
|
||||
|
@ -790,7 +790,7 @@ namespace winsw
|
|||
List<IAppender> appenders = new List<IAppender>();
|
||||
|
||||
// wrapper.log
|
||||
String wrapperLogPath = Path.Combine(d.LogDirectory, d.BaseName + ".wrapper.log");
|
||||
string wrapperLogPath = Path.Combine(d.LogDirectory, d.BaseName + ".wrapper.log");
|
||||
var wrapperLog = new FileAppender
|
||||
{
|
||||
AppendToFile = true,
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace winsw
|
|||
private static extern bool SetConsoleCtrlHandler(ConsoleCtrlDelegate HandlerRoutine, bool Add);
|
||||
|
||||
// Delegate type to be used as the Handler Routine for SCCH
|
||||
private delegate Boolean ConsoleCtrlDelegate(CtrlTypes CtrlType);
|
||||
private delegate bool ConsoleCtrlDelegate(CtrlTypes CtrlType);
|
||||
|
||||
// Enumerated type for the control messages sent to the handler routine
|
||||
private enum CtrlTypes : uint
|
||||
|
|
|
@ -55,15 +55,15 @@ namespace winsw
|
|||
/// <exception cref="InvalidDataException">The required attribute is missing or the configuration is invalid</exception>
|
||||
internal Download(XmlElement n)
|
||||
{
|
||||
From = XmlHelper.SingleAttribute<String>(n, "from");
|
||||
To = XmlHelper.SingleAttribute<String>(n, "to");
|
||||
From = XmlHelper.SingleAttribute<string>(n, "from");
|
||||
To = XmlHelper.SingleAttribute<string>(n, "to");
|
||||
|
||||
// All arguments below are optional
|
||||
FailOnError = XmlHelper.SingleAttribute(n, "failOnError", false);
|
||||
|
||||
Auth = XmlHelper.EnumAttribute(n, "auth", AuthType.none);
|
||||
Username = XmlHelper.SingleAttribute<String>(n, "user", null);
|
||||
Password = XmlHelper.SingleAttribute<String>(n, "password", null);
|
||||
Username = XmlHelper.SingleAttribute<string>(n, "user", null);
|
||||
Password = XmlHelper.SingleAttribute<string>(n, "password", null);
|
||||
UnsecureAuth = XmlHelper.SingleAttribute(n, "unsecureAuth", false);
|
||||
|
||||
if (Auth == AuthType.basic)
|
||||
|
@ -89,7 +89,7 @@ namespace winsw
|
|||
}
|
||||
|
||||
// Source: http://stackoverflow.com/questions/2764577/forcing-basic-authentication-in-webrequest
|
||||
private void SetBasicAuthHeader(WebRequest request, String username, String password)
|
||||
private void SetBasicAuthHeader(WebRequest request, string username, string password)
|
||||
{
|
||||
string authInfo = username + ":" + password;
|
||||
authInfo = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(authInfo));
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace DynamicProxy
|
|||
public class ProxyFactory
|
||||
{
|
||||
private static ProxyFactory _instance;
|
||||
private static readonly Object LockObj = new Object();
|
||||
private static readonly object LockObj = new object();
|
||||
|
||||
private readonly Hashtable _typeMap = Hashtable.Synchronized(new Hashtable());
|
||||
private static readonly Hashtable OpCodeTypeMapper = new Hashtable();
|
||||
|
@ -100,14 +100,14 @@ namespace DynamicProxy
|
|||
// return types, used in the Emit process.
|
||||
static ProxyFactory()
|
||||
{
|
||||
OpCodeTypeMapper.Add(typeof(Boolean), OpCodes.Ldind_I1);
|
||||
OpCodeTypeMapper.Add(typeof(Int16), OpCodes.Ldind_I2);
|
||||
OpCodeTypeMapper.Add(typeof(Int32), OpCodes.Ldind_I4);
|
||||
OpCodeTypeMapper.Add(typeof(Int64), OpCodes.Ldind_I8);
|
||||
OpCodeTypeMapper.Add(typeof(Double), OpCodes.Ldind_R8);
|
||||
OpCodeTypeMapper.Add(typeof(Single), OpCodes.Ldind_R4);
|
||||
OpCodeTypeMapper.Add(typeof(UInt16), OpCodes.Ldind_U2);
|
||||
OpCodeTypeMapper.Add(typeof(UInt32), OpCodes.Ldind_U4);
|
||||
OpCodeTypeMapper.Add(typeof(bool), OpCodes.Ldind_I1);
|
||||
OpCodeTypeMapper.Add(typeof(short), OpCodes.Ldind_I2);
|
||||
OpCodeTypeMapper.Add(typeof(int), OpCodes.Ldind_I4);
|
||||
OpCodeTypeMapper.Add(typeof(long), OpCodes.Ldind_I8);
|
||||
OpCodeTypeMapper.Add(typeof(double), OpCodes.Ldind_R8);
|
||||
OpCodeTypeMapper.Add(typeof(float), OpCodes.Ldind_R4);
|
||||
OpCodeTypeMapper.Add(typeof(ushort), OpCodes.Ldind_U2);
|
||||
OpCodeTypeMapper.Add(typeof(uint), OpCodes.Ldind_U4);
|
||||
}
|
||||
|
||||
private ProxyFactory()
|
||||
|
@ -135,7 +135,7 @@ namespace DynamicProxy
|
|||
}
|
||||
}
|
||||
|
||||
public Object Create(IProxyInvocationHandler handler, Type objType, bool isObjInterface)
|
||||
public object Create(IProxyInvocationHandler handler, Type objType, bool isObjInterface)
|
||||
{
|
||||
string typeName = objType.FullName + PROXY_SUFFIX;
|
||||
Type type = (Type)_typeMap[typeName];
|
||||
|
@ -160,7 +160,7 @@ namespace DynamicProxy
|
|||
return Activator.CreateInstance(type, new object[] { handler });
|
||||
}
|
||||
|
||||
public Object Create(IProxyInvocationHandler handler, Type objType)
|
||||
public object Create(IProxyInvocationHandler handler, Type objType)
|
||||
{
|
||||
return Create(handler, objType, false);
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ namespace DynamicProxy
|
|||
|
||||
if (handler != null && interfaces != null)
|
||||
{
|
||||
Type objType = typeof(Object);
|
||||
Type objType = typeof(object);
|
||||
Type handlerType = typeof(IProxyInvocationHandler);
|
||||
|
||||
AppDomain domain = Thread.GetDomain();
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace winsw.Extensions
|
|||
{
|
||||
public abstract class AbstractWinSWExtension : IWinSWExtension
|
||||
{
|
||||
public abstract String DisplayName { get; }
|
||||
public abstract string DisplayName { get; }
|
||||
|
||||
public WinSWExtensionDescriptor Descriptor { get; set; }
|
||||
|
||||
|
|
|
@ -4,15 +4,15 @@ namespace winsw.Extensions
|
|||
{
|
||||
public class ExtensionException : WinSWException
|
||||
{
|
||||
public String ExtensionId { get; private set; }
|
||||
public string ExtensionId { get; private set; }
|
||||
|
||||
public ExtensionException(String extensionName, String message)
|
||||
public ExtensionException(string extensionName, string message)
|
||||
: base(message)
|
||||
{
|
||||
ExtensionId = extensionName;
|
||||
}
|
||||
|
||||
public ExtensionException(String extensionName, String message, Exception innerException)
|
||||
public ExtensionException(string extensionName, string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
ExtensionId = extensionName;
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace winsw.Extensions
|
|||
/// <summary>
|
||||
/// Extension name to be displayed in logs
|
||||
/// </summary>
|
||||
String DisplayName { get; }
|
||||
string DisplayName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Extension descriptor
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace winsw.Extensions
|
|||
/// <summary>
|
||||
/// Unique extension ID
|
||||
/// </summary>
|
||||
public String Id { get; private set; }
|
||||
public string Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Exception is enabled
|
||||
|
@ -25,7 +25,7 @@ namespace winsw.Extensions
|
|||
/// <summary>
|
||||
/// Extension classname
|
||||
/// </summary>
|
||||
public String ClassName { get; private set; }
|
||||
public string ClassName { get; private set; }
|
||||
|
||||
private WinSWExtensionDescriptor(string id, string className, bool enabled)
|
||||
{
|
||||
|
|
|
@ -109,7 +109,7 @@ namespace winsw.Extensions
|
|||
public void LoadExtensions()
|
||||
{
|
||||
var extensionIds = ServiceDescriptor.ExtensionIds;
|
||||
foreach (String extensionId in extensionIds)
|
||||
foreach (string extensionId in extensionIds)
|
||||
{
|
||||
LoadExtension(extensionId);
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ namespace winsw.Extensions
|
|||
{
|
||||
ActivationContext ac = AppDomain.CurrentDomain.ActivationContext;
|
||||
Assembly assembly = Assembly.GetCallingAssembly();
|
||||
Object created;
|
||||
object created;
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -591,7 +591,7 @@ namespace winsw
|
|||
private int GetNextFileNumber(string ext, string baseDirectory, string baseFileName, DateTime now)
|
||||
{
|
||||
var nextFileNumber = 0;
|
||||
var files = Directory.GetFiles(baseDirectory, String.Format("{0}.{1}.#*{2}", baseFileName, now.ToString(FilePattern), ext));
|
||||
var files = Directory.GetFiles(baseDirectory, string.Format("{0}.{1}.#*{2}", baseFileName, now.ToString(FilePattern), ext));
|
||||
if (files.Length == 0)
|
||||
{
|
||||
nextFileNumber = 1;
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace winsw.Native
|
|||
_handle = Advapi32.OpenSCManager(null, null, (uint)SCM_ACCESS.SC_MANAGER_ALL_ACCESS);
|
||||
if (_handle == IntPtr.Zero)
|
||||
{
|
||||
throw new Exception(String.Format("Error connecting to Service Control Manager. Error provided was: 0x{0:X}", Marshal.GetLastWin32Error()));
|
||||
throw new Exception(string.Format("Error connecting to Service Control Manager. Error provided was: 0x{0:X}", Marshal.GetLastWin32Error()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ namespace winsw.Native
|
|||
IntPtr svcHandle = Advapi32.OpenService(_handle, serviceName, (int)SERVICE_ACCESS.SERVICE_ALL_ACCESS);
|
||||
if (svcHandle == IntPtr.Zero)
|
||||
{
|
||||
throw new Exception(String.Format("Error opening service for modifying. Error returned was: 0x{0:X}", Marshal.GetLastWin32Error()));
|
||||
throw new Exception(string.Format("Error opening service for modifying. Error returned was: 0x{0:X}", Marshal.GetLastWin32Error()));
|
||||
}
|
||||
|
||||
return new Service(svcHandle);
|
||||
|
@ -164,7 +164,7 @@ namespace winsw.Native
|
|||
/// <param name="accountName">Name of an account - "domain\account" or only "account"</param>
|
||||
/// <param name="privilegeName">Name ofthe privilege</param>
|
||||
/// <returns>The windows error code returned by LsaAddAccountRights</returns>
|
||||
private static long SetRight(String accountName, String privilegeName)
|
||||
private static long SetRight(string accountName, string privilegeName)
|
||||
{
|
||||
long winErrorCode; // contains the last error
|
||||
|
||||
|
@ -178,14 +178,14 @@ namespace winsw.Native
|
|||
int accountType = 0;
|
||||
|
||||
// get required buffer size
|
||||
Advapi32.LookupAccountName(String.Empty, accountName, sid, ref sidSize, domainName, ref nameSize, ref accountType);
|
||||
Advapi32.LookupAccountName(string.Empty, accountName, sid, ref sidSize, domainName, ref nameSize, ref accountType);
|
||||
|
||||
// allocate buffers
|
||||
domainName = new StringBuilder(nameSize);
|
||||
sid = Marshal.AllocHGlobal(sidSize);
|
||||
|
||||
// lookup the SID for the account
|
||||
bool result = Advapi32.LookupAccountName(String.Empty, accountName, sid, ref sidSize, domainName, ref nameSize,
|
||||
bool result = Advapi32.LookupAccountName(string.Empty, accountName, sid, ref sidSize, domainName, ref nameSize,
|
||||
ref accountType);
|
||||
|
||||
// say what you're doing
|
||||
|
@ -247,8 +247,8 @@ namespace winsw.Native
|
|||
LSA_UNICODE_STRING[] userRights = new LSA_UNICODE_STRING[1];
|
||||
userRights[0] = default;
|
||||
userRights[0].Buffer = Marshal.StringToHGlobalUni(privilegeName);
|
||||
userRights[0].Length = (UInt16)(privilegeName.Length * UnicodeEncoding.CharSize);
|
||||
userRights[0].MaximumLength = (UInt16)((privilegeName.Length + 1) * UnicodeEncoding.CharSize);
|
||||
userRights[0].Length = (ushort)(privilegeName.Length * UnicodeEncoding.CharSize);
|
||||
userRights[0].MaximumLength = (ushort)((privilegeName.Length + 1) * UnicodeEncoding.CharSize);
|
||||
|
||||
// add the right to the account
|
||||
uint res = Advapi32.LsaAddAccountRights(policyHandle, sid, userRights, 1);
|
||||
|
@ -300,7 +300,7 @@ namespace winsw.Native
|
|||
public static extern bool SetServiceStatus(IntPtr hServiceStatus, ref SERVICE_STATUS lpServiceStatus);
|
||||
|
||||
[DllImport("advapi32.dll", PreserveSig = true)]
|
||||
internal static extern UInt32 LsaOpenPolicy(ref LSA_UNICODE_STRING SystemName, ref LSA_OBJECT_ATTRIBUTES ObjectAttributes, Int32 DesiredAccess,
|
||||
internal static extern uint LsaOpenPolicy(ref LSA_UNICODE_STRING SystemName, ref LSA_OBJECT_ATTRIBUTES ObjectAttributes, int DesiredAccess,
|
||||
out IntPtr PolicyHandle);
|
||||
|
||||
[DllImport("advapi32.dll", SetLastError = true, PreserveSig = true)]
|
||||
|
@ -341,8 +341,8 @@ namespace winsw.Native
|
|||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct LSA_UNICODE_STRING
|
||||
{
|
||||
public UInt16 Length;
|
||||
public UInt16 MaximumLength;
|
||||
public ushort Length;
|
||||
public ushort MaximumLength;
|
||||
public IntPtr Buffer;
|
||||
}
|
||||
|
||||
|
@ -352,7 +352,7 @@ namespace winsw.Native
|
|||
public int Length;
|
||||
public IntPtr RootDirectory;
|
||||
public LSA_UNICODE_STRING ObjectName;
|
||||
public UInt32 Attributes;
|
||||
public uint Attributes;
|
||||
public IntPtr SecurityDescriptor;
|
||||
public IntPtr SecurityQualityOfService;
|
||||
}
|
||||
|
|
|
@ -36,20 +36,20 @@ namespace winsw.Native
|
|||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
public struct STARTUPINFO
|
||||
{
|
||||
public Int32 cb;
|
||||
public int cb;
|
||||
public string lpReserved;
|
||||
public string lpDesktop;
|
||||
public string lpTitle;
|
||||
public Int32 dwX;
|
||||
public Int32 dwY;
|
||||
public Int32 dwXSize;
|
||||
public Int32 dwYSize;
|
||||
public Int32 dwXCountChars;
|
||||
public Int32 dwYCountChars;
|
||||
public Int32 dwFillAttribute;
|
||||
public Int32 dwFlags;
|
||||
public Int16 wShowWindow;
|
||||
public Int16 cbReserved2;
|
||||
public int dwX;
|
||||
public int dwY;
|
||||
public int dwXSize;
|
||||
public int dwYSize;
|
||||
public int dwXCountChars;
|
||||
public int dwYCountChars;
|
||||
public int dwFillAttribute;
|
||||
public int dwFlags;
|
||||
public short wShowWindow;
|
||||
public short cbReserved2;
|
||||
public IntPtr lpReserved2;
|
||||
public IntPtr hStdInput;
|
||||
public IntPtr hStdOutput;
|
||||
|
|
|
@ -96,7 +96,7 @@ namespace winsw
|
|||
|
||||
public PeriodicityType periodicityType { get; set; }
|
||||
|
||||
public Boolean shouldRoll
|
||||
public bool shouldRoll
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
|
@ -218,7 +218,7 @@ namespace winsw
|
|||
get
|
||||
{
|
||||
var wd = SingleElement("workingdirectory", true);
|
||||
return String.IsNullOrEmpty(wd) ? Defaults.WorkingDirectory : wd;
|
||||
return string.IsNullOrEmpty(wd) ? Defaults.WorkingDirectory : wd;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,7 +235,7 @@ namespace winsw
|
|||
foreach (XmlNode e in extensions)
|
||||
{
|
||||
XmlElement extension = (XmlElement)e;
|
||||
String extensionId = XmlHelper.SingleAttribute<string>(extension, "id");
|
||||
string extensionId = XmlHelper.SingleAttribute<string>(extension, "id");
|
||||
res.Add(extensionId);
|
||||
}
|
||||
}
|
||||
|
@ -675,7 +675,7 @@ namespace winsw
|
|||
{
|
||||
if (AllowServiceLogon != null)
|
||||
{
|
||||
if (Boolean.TryParse(AllowServiceLogon, out bool parsedvalue))
|
||||
if (bool.TryParse(AllowServiceLogon, out bool parsedvalue))
|
||||
{
|
||||
return parsedvalue;
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ namespace winsw.Util
|
|||
/// <param name="callback">Completion callback. If null, the completion won't be monitored</param>
|
||||
/// <param name="logHandler">Log handler. If enabled, logs will be redirected to the process and then reported</param>
|
||||
/// <param name="redirectStdin">Redirect standard input</param>
|
||||
public static void StartProcessAndCallbackForExit(Process processToStart, String executable = null, string arguments = null, Dictionary<string, string> envVars = null,
|
||||
public static void StartProcessAndCallbackForExit(Process processToStart, string executable = null, string arguments = null, Dictionary<string, string> envVars = null,
|
||||
string workingDirectory = null, ProcessPriorityClass? priority = null, ProcessCompletionCallback callback = null, bool redirectStdin = true, LogHandler logHandler = null, bool hideWindow = false)
|
||||
{
|
||||
var ps = processToStart.StartInfo;
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace winsw.Util
|
|||
private static extern bool SetConsoleCtrlHandler(ConsoleCtrlDelegate HandlerRoutine, bool Add);
|
||||
|
||||
// Delegate type to be used as the Handler Routine for SCCH
|
||||
private delegate Boolean ConsoleCtrlDelegate(CtrlTypes CtrlType);
|
||||
private delegate bool ConsoleCtrlDelegate(CtrlTypes CtrlType);
|
||||
|
||||
// Enumerated type for the control messages sent to the handler routine
|
||||
private enum CtrlTypes : uint
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace winsw.Util
|
|||
/// <param name="optional">If optional, don't throw an exception if the elemen is missing</param>
|
||||
/// <returns>String value or null</returns>
|
||||
/// <exception cref="InvalidDataException">The required element is missing</exception>
|
||||
public static string SingleElement(XmlNode node, string tagName, Boolean optional)
|
||||
public static string SingleElement(XmlNode node, string tagName, bool optional)
|
||||
{
|
||||
var n = node.SelectSingleNode(tagName);
|
||||
if (n == null && !optional)
|
||||
|
@ -31,7 +31,7 @@ namespace winsw.Util
|
|||
/// <param name="optional">If otional, don't throw an exception if the elemen is missing</param>
|
||||
/// <returns>String value or null</returns>
|
||||
/// <exception cref="InvalidDataException">The required element is missing</exception>
|
||||
public static XmlNode SingleNode(XmlNode node, string tagName, Boolean optional)
|
||||
public static XmlNode SingleNode(XmlNode node, string tagName, bool optional)
|
||||
{
|
||||
var n = node.SelectSingleNode(tagName);
|
||||
if (n == null && !optional)
|
||||
|
|
|
@ -4,11 +4,11 @@ namespace winsw
|
|||
{
|
||||
public class WinSWException : Exception
|
||||
{
|
||||
public WinSWException(String message)
|
||||
public WinSWException(string message)
|
||||
: base(message)
|
||||
{ }
|
||||
|
||||
public WinSWException(String message, Exception innerException)
|
||||
public WinSWException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{ }
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ namespace WMI
|
|||
string path;
|
||||
|
||||
if (machineName != null)
|
||||
path = String.Format(@"\\{0}\root\cimv2", machineName);
|
||||
path = string.Format(@"\\{0}\root\cimv2", machineName);
|
||||
else
|
||||
path = @"\root\cimv2";
|
||||
scope = new ManagementScope(path, options);
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace winsw.Plugins.RunawayProcessKiller
|
|||
/// <summary>
|
||||
/// Absolute path to the PID file, which stores ID of the previously launched process.
|
||||
/// </summary>
|
||||
public String Pidfile { get; private set; }
|
||||
public string Pidfile { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines the process termination timeout in milliseconds.
|
||||
|
@ -34,9 +34,9 @@ namespace winsw.Plugins.RunawayProcessKiller
|
|||
/// </summary>
|
||||
public bool CheckWinSWEnvironmentVariable { get; private set; }
|
||||
|
||||
public override String DisplayName => "Runaway Process Killer";
|
||||
public override string DisplayName => "Runaway Process Killer";
|
||||
|
||||
private String ServiceId { get; set; }
|
||||
private string ServiceId { get; set; }
|
||||
|
||||
private static readonly ILog Logger = LogManager.GetLogger(typeof(RunawayProcessKillerExtension));
|
||||
|
||||
|
@ -45,7 +45,7 @@ namespace winsw.Plugins.RunawayProcessKiller
|
|||
// Default initializer
|
||||
}
|
||||
|
||||
public RunawayProcessKillerExtension(String pidfile, int stopTimeoutMs = 5000, bool stopParentFirst = false, bool checkWinSWEnvironmentVariable = true)
|
||||
public RunawayProcessKillerExtension(string pidfile, int stopTimeoutMs = 5000, bool stopParentFirst = false, bool checkWinSWEnvironmentVariable = true)
|
||||
{
|
||||
this.Pidfile = pidfile;
|
||||
this.StopTimeout = TimeSpan.FromMilliseconds(stopTimeoutMs);
|
||||
|
@ -58,12 +58,12 @@ namespace winsw.Plugins.RunawayProcessKiller
|
|||
// We expect the upper logic to process any errors
|
||||
// TODO: a better parser API for types would be useful
|
||||
Pidfile = XmlHelper.SingleElement(node, "pidfile", false);
|
||||
StopTimeout = TimeSpan.FromMilliseconds(Int32.Parse(XmlHelper.SingleElement(node, "stopTimeout", false)));
|
||||
StopParentProcessFirst = Boolean.Parse(XmlHelper.SingleElement(node, "stopParentFirst", false));
|
||||
StopTimeout = TimeSpan.FromMilliseconds(int.Parse(XmlHelper.SingleElement(node, "stopTimeout", false)));
|
||||
StopParentProcessFirst = bool.Parse(XmlHelper.SingleElement(node, "stopParentFirst", false));
|
||||
ServiceId = descriptor.Id;
|
||||
// TODO: Consider making it documented
|
||||
var checkWinSWEnvironmentVariable = XmlHelper.SingleElement(node, "checkWinSWEnvironmentVariable", true);
|
||||
CheckWinSWEnvironmentVariable = checkWinSWEnvironmentVariable != null ? Boolean.Parse(checkWinSWEnvironmentVariable) : true;
|
||||
CheckWinSWEnvironmentVariable = checkWinSWEnvironmentVariable != null ? bool.Parse(checkWinSWEnvironmentVariable) : true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -89,7 +89,7 @@ namespace winsw.Plugins.RunawayProcessKiller
|
|||
|
||||
try
|
||||
{
|
||||
pid = Int32.Parse(pidstring);
|
||||
pid = int.Parse(pidstring);
|
||||
}
|
||||
catch (FormatException e)
|
||||
{
|
||||
|
@ -117,11 +117,11 @@ namespace winsw.Plugins.RunawayProcessKiller
|
|||
}
|
||||
|
||||
// Ensure the process references the service
|
||||
String affiliatedServiceId;
|
||||
string affiliatedServiceId;
|
||||
// TODO: This method is not ideal since it works only for vars explicitly mentioned in the start info
|
||||
// No Windows 10- compatible solution for EnvVars retrieval, see https://blog.gapotchenko.com/eazfuscator.net/reading-environment-variables
|
||||
StringDictionary previousProcessEnvVars = proc.StartInfo.EnvironmentVariables;
|
||||
String expectedEnvVarName = WinSWSystem.ENVVAR_NAME_SERVICE_ID;
|
||||
string expectedEnvVarName = WinSWSystem.ENVVAR_NAME_SERVICE_ID;
|
||||
if (previousProcessEnvVars.ContainsKey(expectedEnvVarName))
|
||||
{
|
||||
// StringDictionary is case-insensitive, hence it will fetch variable definitions in any case
|
||||
|
@ -134,9 +134,9 @@ namespace winsw.Plugins.RunawayProcessKiller
|
|||
if (Logger.IsDebugEnabled)
|
||||
{
|
||||
// TODO replace by String.Join() in .NET 4
|
||||
String[] keys = new String[previousProcessEnvVars.Count];
|
||||
string[] keys = new string[previousProcessEnvVars.Count];
|
||||
previousProcessEnvVars.Keys.CopyTo(keys, 0);
|
||||
Logger.DebugFormat("Env vars of the process with PID={0}: {1}", new Object[] { pid, String.Join(",", keys) });
|
||||
Logger.DebugFormat("Env vars of the process with PID={0}: {1}", new object[] { pid, string.Join(",", keys) });
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace winsw.Plugins.SharedDirectoryMapper
|
|||
private readonly SharedDirectoryMappingHelper _mapper = new SharedDirectoryMappingHelper();
|
||||
private readonly List<SharedDirectoryMapperConfig> _entries = new List<SharedDirectoryMapperConfig>();
|
||||
|
||||
public override String DisplayName => "Shared Directory Mapper";
|
||||
public override string DisplayName => "Shared Directory Mapper";
|
||||
|
||||
private static readonly ILog Logger = LogManager.GetLogger(typeof(SharedDirectoryMapper));
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ namespace winsw.Plugins.SharedDirectoryMapper
|
|||
public class SharedDirectoryMapperConfig
|
||||
{
|
||||
public bool EnableMapping { get; set; }
|
||||
public String Label { get; set; }
|
||||
public String UNCPath { get; set; }
|
||||
public string Label { get; set; }
|
||||
public string UNCPath { get; set; }
|
||||
|
||||
public SharedDirectoryMapperConfig(bool enableMapping, string label, string uncPath)
|
||||
{
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace winsw.Plugins.SharedDirectoryMapper
|
|||
/// <param name="command">Command to be executed</param>
|
||||
/// <param name="args">Command arguments</param>
|
||||
/// <exception cref="MapperException">Operation failure</exception>
|
||||
private void InvokeCommand(String command, String args)
|
||||
private void InvokeCommand(string command, string args)
|
||||
{
|
||||
Process p = new Process
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ namespace winsw.Plugins.SharedDirectoryMapper
|
|||
/// <param name="label">Disk label</param>
|
||||
/// <param name="uncPath">UNC path to the directory</param>
|
||||
/// <exception cref="MapperException">Operation failure</exception>
|
||||
public void MapDirectory(String label, String uncPath)
|
||||
public void MapDirectory(string label, string uncPath)
|
||||
{
|
||||
InvokeCommand("net.exe", " use " + label + " " + uncPath);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ namespace winsw.Plugins.SharedDirectoryMapper
|
|||
/// </summary>
|
||||
/// <param name="label">Disk label</param>
|
||||
/// <exception cref="MapperException">Operation failure</exception>
|
||||
public void UnmapDirectory(String label)
|
||||
public void UnmapDirectory(string label)
|
||||
{
|
||||
InvokeCommand("net.exe", " use /DELETE /YES " + label);
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ namespace winsw.Plugins.SharedDirectoryMapper
|
|||
|
||||
class MapperException : WinSWException
|
||||
{
|
||||
public String Call { get; private set; }
|
||||
public string Call { get; private set; }
|
||||
public Process Process { get; private set; }
|
||||
|
||||
public MapperException(Process process, string command, string args)
|
||||
|
|
|
@ -71,7 +71,7 @@ namespace winswTests
|
|||
[TestCase("file:///")]
|
||||
[TestCase("jar://")]
|
||||
[TestCase("\\\\")] // UNC
|
||||
public void ShouldReject_BasicAuth_with_UnsecureProtocol(String protocolPrefix)
|
||||
public void ShouldReject_BasicAuth_with_UnsecureProtocol(string protocolPrefix)
|
||||
{
|
||||
var d = new Download(protocolPrefix + "myServer.com:8080/file.txt", To,
|
||||
auth: Download.AuthType.basic, username: "aUser", password: "aPassword");
|
||||
|
@ -127,7 +127,7 @@ namespace winswTests
|
|||
[TestCase("SSPI")]
|
||||
[TestCase("SsPI")]
|
||||
[TestCase("Sspi")]
|
||||
public void AuthType_Is_CaseInsensitive(String authType)
|
||||
public void AuthType_Is_CaseInsensitive(string authType)
|
||||
{
|
||||
var sd = ConfigXmlBuilder.create()
|
||||
.WithRawEntry("<download from=\"http://www.nosuchhostexists.foo.myorg/foo.xml\" to=\"%BASE%\\foo.xml\" auth=\"" + authType + "\"/>")
|
||||
|
@ -157,7 +157,7 @@ namespace winswTests
|
|||
return downloads[0];
|
||||
}
|
||||
|
||||
private void AssertInitializationFails(Download download, String expectedMessagePart = null, Type expectedExceptionType = null)
|
||||
private void AssertInitializationFails(Download download, string expectedMessagePart = null, Type expectedExceptionType = null)
|
||||
{
|
||||
var sd = ConfigXmlBuilder.create()
|
||||
.WithDownload(download)
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace winswTests.Extensions
|
|||
/// </summary>
|
||||
/// <param name="type">Type of the extension</param>
|
||||
/// <returns>String for Type locator, which includes class and assembly names</returns>
|
||||
public static String GetExtensionClassNameWithAssembly(Type type)
|
||||
public static string GetExtensionClassNameWithAssembly(Type type)
|
||||
{
|
||||
return type.ToString() + ", " + type.Assembly;
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ namespace winswTests.Extensions
|
|||
var tmpDir = FilesystemTestHelper.CreateTmpDirectory();
|
||||
|
||||
// Prepare the env var
|
||||
String varName = WinSWSystem.ENVVAR_NAME_SERVICE_ID;
|
||||
string varName = WinSWSystem.ENVVAR_NAME_SERVICE_ID;
|
||||
var env = new Dictionary<string, string>();
|
||||
env.Add(varName, winswId);
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace winswTests.Util
|
|||
/// <returns>STDOUT if there's no exceptions</returns>
|
||||
/// <exception cref="Exception">Command failure</exception>
|
||||
[NotNull]
|
||||
public static string CLITest(String[] args, ServiceDescriptor descriptor = null)
|
||||
public static string CLITest(string[] args, ServiceDescriptor descriptor = null)
|
||||
{
|
||||
using (StringWriter sw = new StringWriter())
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ namespace winswTests.Util
|
|||
/// <param name="descriptor">Optional Service descriptor (will be used for initializationpurposes)</param>
|
||||
/// <returns>Test results</returns>
|
||||
[NotNull]
|
||||
public static CLITestResult CLIErrorTest(String[] args, ServiceDescriptor descriptor = null)
|
||||
public static CLITestResult CLIErrorTest(string[] args, ServiceDescriptor descriptor = null)
|
||||
{
|
||||
StringWriter swOut, swErr;
|
||||
Exception testEx = null;
|
||||
|
@ -99,17 +99,17 @@ namespace winswTests.Util
|
|||
public class CLITestResult
|
||||
{
|
||||
[NotNull]
|
||||
public String Out { get; private set; }
|
||||
public string Out { get; private set; }
|
||||
|
||||
[NotNull]
|
||||
public String Err { get; private set; }
|
||||
public string Err { get; private set; }
|
||||
|
||||
[CanBeNull]
|
||||
public Exception Exception { get; private set; }
|
||||
|
||||
public bool HasException => Exception != null;
|
||||
|
||||
public CLITestResult(String output, String err, Exception exception = null)
|
||||
public CLITestResult(string output, string err, Exception exception = null)
|
||||
{
|
||||
Out = output;
|
||||
Err = err;
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace winswTests.Util
|
|||
public string XMLComment { get; set; }
|
||||
public List<string> ExtensionXmls { get; private set; }
|
||||
|
||||
private List<String> configEntries;
|
||||
private List<string> configEntries;
|
||||
|
||||
// TODO: Switch to the initializer?
|
||||
private ConfigXmlBuilder()
|
||||
|
@ -64,7 +64,7 @@ namespace winswTests.Util
|
|||
str.AppendFormat(" <name>{0}</name>\n", Name);
|
||||
str.AppendFormat(" <description>{0}</description>\n", Description);
|
||||
str.AppendFormat(" <executable>{0}</executable>\n", Executable);
|
||||
foreach (String entry in configEntries)
|
||||
foreach (string entry in configEntries)
|
||||
{
|
||||
// We do not care much about pretty formatting here
|
||||
str.AppendFormat(" {0}\n", entry);
|
||||
|
@ -106,14 +106,14 @@ namespace winswTests.Util
|
|||
|
||||
public ConfigXmlBuilder WithTag(string tagName, string value)
|
||||
{
|
||||
return WithRawEntry(String.Format("<{0}>{1}</{0}>", tagName, value));
|
||||
return WithRawEntry(string.Format("<{0}>{1}</{0}>", tagName, value));
|
||||
}
|
||||
|
||||
public ConfigXmlBuilder WithRunawayProcessKiller(RunawayProcessKillerExtension ext, string extensionId = "killRunawayProcess", bool enabled = true)
|
||||
{
|
||||
var fullyQualifiedExtensionName = ExtensionTestBase.GetExtensionClassNameWithAssembly(typeof(RunawayProcessKillerExtension));
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.AppendFormat(" <extension enabled=\"{0}\" className=\"{1}\" id=\"{2}\">\n", new Object[] { enabled, fullyQualifiedExtensionName, extensionId });
|
||||
str.AppendFormat(" <extension enabled=\"{0}\" className=\"{1}\" id=\"{2}\">\n", new object[] { enabled, fullyQualifiedExtensionName, extensionId });
|
||||
str.AppendFormat(" <pidfile>{0}</pidfile>\n", ext.Pidfile);
|
||||
str.AppendFormat(" <stopTimeout>{0}</stopTimeout>\n", ext.StopTimeout.TotalMilliseconds);
|
||||
str.AppendFormat(" <stopParentFirst>{0}</stopParentFirst>\n", ext.StopParentProcessFirst);
|
||||
|
@ -127,7 +127,7 @@ namespace winswTests.Util
|
|||
public ConfigXmlBuilder WithDownload(Download download)
|
||||
{
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.AppendFormat("<download from=\"{0}\" to=\"{1}\" failOnError=\"{2}\"", new Object[] { download.From, download.To, download.FailOnError });
|
||||
str.AppendFormat("<download from=\"{0}\" to=\"{1}\" failOnError=\"{2}\"", new object[] { download.From, download.To, download.FailOnError });
|
||||
|
||||
// Authentication
|
||||
if (download.Auth != Download.AuthType.none)
|
||||
|
@ -135,7 +135,7 @@ namespace winswTests.Util
|
|||
str.AppendFormat(" auth=\"{0}\"", download.Auth);
|
||||
if (download.Auth == Download.AuthType.basic)
|
||||
{
|
||||
str.AppendFormat(" user=\"{0}\" password=\"{1}\"", new Object[] { download.Username, download.Password });
|
||||
str.AppendFormat(" user=\"{0}\" password=\"{1}\"", new object[] { download.Username, download.Password });
|
||||
}
|
||||
|
||||
if (download.UnsecureAuth)
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace winswTests.Util
|
|||
{
|
||||
class ExceptionHelper
|
||||
{
|
||||
public static void assertFails(String expectedMessagePart, Type expectedExceptionType, ExceptionHelperExecutionBody body)
|
||||
public static void assertFails(string expectedMessagePart, Type expectedExceptionType, ExceptionHelperExecutionBody body)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace winswTests.Util
|
|||
/// Creates a temporary directory for testing.
|
||||
/// </summary>
|
||||
/// <returns>tmp Dir</returns>
|
||||
public static string CreateTmpDirectory(String testName = null)
|
||||
public static string CreateTmpDirectory(string testName = null)
|
||||
{
|
||||
string tempDirectory = Path.Combine(Path.GetTempPath(), "winswTests_" + (testName ?? string.Empty) + Path.GetRandomFileName());
|
||||
Directory.CreateDirectory(tempDirectory);
|
||||
|
|
|
@ -19,8 +19,8 @@ namespace winswTests.Util
|
|||
Environment.SetEnvironmentVariable("TEST_KEY", "TEST_VALUE");
|
||||
|
||||
var tmpDir = FilesystemTestHelper.CreateTmpDirectory();
|
||||
String envFile = Path.Combine(tmpDir, "env.properties");
|
||||
String scriptFile = Path.Combine(tmpDir, "printenv.bat");
|
||||
string envFile = Path.Combine(tmpDir, "env.properties");
|
||||
string scriptFile = Path.Combine(tmpDir, "printenv.bat");
|
||||
File.WriteAllText(scriptFile, "set > " + envFile);
|
||||
|
||||
Process proc = new Process();
|
||||
|
@ -36,9 +36,9 @@ namespace winswTests.Util
|
|||
|
||||
// Check several veriables, which are expected to be in Uppercase
|
||||
var envVars = FilesystemTestHelper.parseSetOutput(envFile);
|
||||
String[] keys = new String[envVars.Count];
|
||||
string[] keys = new string[envVars.Count];
|
||||
envVars.Keys.CopyTo(keys, 0);
|
||||
String availableVars = "[" + String.Join(",", keys) + "]";
|
||||
String availableVars = "[" + string.Join(",", keys) + "]";
|
||||
Assert.That(envVars.ContainsKey("TEST_KEY"), "No TEST_KEY in the injected vars: " + availableVars);
|
||||
|
||||
// And just ensure that the parsing logic is case-sensitive
|
||||
|
@ -50,7 +50,7 @@ namespace winswTests.Util
|
|||
public void ShouldNotHangWhenWritingLargeStringToStdOut()
|
||||
{
|
||||
var tmpDir = FilesystemTestHelper.CreateTmpDirectory();
|
||||
String scriptFile = Path.Combine(tmpDir, "print_lots_to_stdout.bat");
|
||||
string scriptFile = Path.Combine(tmpDir, "print_lots_to_stdout.bat");
|
||||
var lotsOfStdOut = string.Join(string.Empty, _Range(1, 1000));
|
||||
File.WriteAllText(scriptFile, string.Format("echo \"{0}\"", lotsOfStdOut));
|
||||
|
||||
|
|
Loading…
Reference in New Issue