From 08bae2a6825f902f4586e151aebdb13ddc9d118a Mon Sep 17 00:00:00 2001 From: NextTurn <45985406+NextTurn@users.noreply.github.com> Date: Fri, 7 Dec 2018 00:00:00 +0800 Subject: [PATCH] Use built-in types --- src/Core/ServiceWrapper/Main.cs | 24 +++++++++---------- src/Core/ServiceWrapper/SigIntHelper.cs | 2 +- src/Core/WinSWCore/Download.cs | 10 ++++---- src/Core/WinSWCore/DynamicProxy.cs | 24 +++++++++---------- .../Extensions/AbstractWinSWExtension.cs | 2 +- .../Extensions/ExtensionException.cs | 6 ++--- .../WinSWCore/Extensions/IWinSWExtension.cs | 2 +- .../Extensions/WinSWExtensionDescriptor.cs | 4 ++-- .../Extensions/WinSWExtensionManager.cs | 4 ++-- src/Core/WinSWCore/LogAppenders.cs | 2 +- src/Core/WinSWCore/Native/Advapi32.cs | 22 ++++++++--------- src/Core/WinSWCore/Native/Kernel32.cs | 22 ++++++++--------- src/Core/WinSWCore/PeriodicRollingCalendar.cs | 2 +- src/Core/WinSWCore/ServiceDescriptor.cs | 6 ++--- src/Core/WinSWCore/Util/ProcessHelper.cs | 2 +- src/Core/WinSWCore/Util/SigIntHelper.cs | 2 +- src/Core/WinSWCore/Util/XmlHelper.cs | 4 ++-- src/Core/WinSWCore/WinSWException.cs | 4 ++-- src/Core/WinSWCore/Wmi.cs | 2 +- .../RunawayProcessKillerExtension.cs | 24 +++++++++---------- .../SharedDirectoryMapper.cs | 2 +- .../SharedDirectoryMapperConfig.cs | 4 ++-- .../SharedDirectoryMapperHelper.cs | 8 +++---- src/Test/winswTests/DownloadTest.cs | 6 ++--- .../Extensions/ExtensionTestBase.cs | 2 +- .../Extensions/RunawayProcessKillerTest.cs | 2 +- src/Test/winswTests/Util/CLITestHelper.cs | 10 ++++---- src/Test/winswTests/Util/ConfigXmlBuilder.cs | 12 +++++----- src/Test/winswTests/Util/ExceptionHelper.cs | 2 +- .../winswTests/Util/FilesystemTestHelper.cs | 2 +- src/Test/winswTests/Util/ProcessHelperTest.cs | 12 +++++----- 31 files changed, 116 insertions(+), 116 deletions(-) diff --git a/src/Core/ServiceWrapper/Main.cs b/src/Core/ServiceWrapper/Main.cs index 6c17079..93465fd 100644 --- a/src/Core/ServiceWrapper/Main.cs +++ b/src/Core/ServiceWrapper/Main.cs @@ -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 appenders = new List(); // 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, diff --git a/src/Core/ServiceWrapper/SigIntHelper.cs b/src/Core/ServiceWrapper/SigIntHelper.cs index 0c1374f..7dfabe6 100644 --- a/src/Core/ServiceWrapper/SigIntHelper.cs +++ b/src/Core/ServiceWrapper/SigIntHelper.cs @@ -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 diff --git a/src/Core/WinSWCore/Download.cs b/src/Core/WinSWCore/Download.cs index e02817a..b6fe87b 100755 --- a/src/Core/WinSWCore/Download.cs +++ b/src/Core/WinSWCore/Download.cs @@ -55,15 +55,15 @@ namespace winsw /// The required attribute is missing or the configuration is invalid internal Download(XmlElement n) { - From = XmlHelper.SingleAttribute(n, "from"); - To = XmlHelper.SingleAttribute(n, "to"); + From = XmlHelper.SingleAttribute(n, "from"); + To = XmlHelper.SingleAttribute(n, "to"); // All arguments below are optional FailOnError = XmlHelper.SingleAttribute(n, "failOnError", false); Auth = XmlHelper.EnumAttribute(n, "auth", AuthType.none); - Username = XmlHelper.SingleAttribute(n, "user", null); - Password = XmlHelper.SingleAttribute(n, "password", null); + Username = XmlHelper.SingleAttribute(n, "user", null); + Password = XmlHelper.SingleAttribute(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)); diff --git a/src/Core/WinSWCore/DynamicProxy.cs b/src/Core/WinSWCore/DynamicProxy.cs index 8862059..dcda669 100644 --- a/src/Core/WinSWCore/DynamicProxy.cs +++ b/src/Core/WinSWCore/DynamicProxy.cs @@ -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(); diff --git a/src/Core/WinSWCore/Extensions/AbstractWinSWExtension.cs b/src/Core/WinSWCore/Extensions/AbstractWinSWExtension.cs index 01cc11a..d665a2c 100644 --- a/src/Core/WinSWCore/Extensions/AbstractWinSWExtension.cs +++ b/src/Core/WinSWCore/Extensions/AbstractWinSWExtension.cs @@ -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; } diff --git a/src/Core/WinSWCore/Extensions/ExtensionException.cs b/src/Core/WinSWCore/Extensions/ExtensionException.cs index 498761d..48a5ae2 100644 --- a/src/Core/WinSWCore/Extensions/ExtensionException.cs +++ b/src/Core/WinSWCore/Extensions/ExtensionException.cs @@ -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; diff --git a/src/Core/WinSWCore/Extensions/IWinSWExtension.cs b/src/Core/WinSWCore/Extensions/IWinSWExtension.cs index 76a65e7..4562c4f 100644 --- a/src/Core/WinSWCore/Extensions/IWinSWExtension.cs +++ b/src/Core/WinSWCore/Extensions/IWinSWExtension.cs @@ -16,7 +16,7 @@ namespace winsw.Extensions /// /// Extension name to be displayed in logs /// - String DisplayName { get; } + string DisplayName { get; } /// /// Extension descriptor diff --git a/src/Core/WinSWCore/Extensions/WinSWExtensionDescriptor.cs b/src/Core/WinSWCore/Extensions/WinSWExtensionDescriptor.cs index 3d58c73..004560c 100644 --- a/src/Core/WinSWCore/Extensions/WinSWExtensionDescriptor.cs +++ b/src/Core/WinSWCore/Extensions/WinSWExtensionDescriptor.cs @@ -15,7 +15,7 @@ namespace winsw.Extensions /// /// Unique extension ID /// - public String Id { get; private set; } + public string Id { get; private set; } /// /// Exception is enabled @@ -25,7 +25,7 @@ namespace winsw.Extensions /// /// Extension classname /// - public String ClassName { get; private set; } + public string ClassName { get; private set; } private WinSWExtensionDescriptor(string id, string className, bool enabled) { diff --git a/src/Core/WinSWCore/Extensions/WinSWExtensionManager.cs b/src/Core/WinSWCore/Extensions/WinSWExtensionManager.cs index 88834ca..0ac834e 100644 --- a/src/Core/WinSWCore/Extensions/WinSWExtensionManager.cs +++ b/src/Core/WinSWCore/Extensions/WinSWExtensionManager.cs @@ -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 { diff --git a/src/Core/WinSWCore/LogAppenders.cs b/src/Core/WinSWCore/LogAppenders.cs index 16122af..7df463f 100644 --- a/src/Core/WinSWCore/LogAppenders.cs +++ b/src/Core/WinSWCore/LogAppenders.cs @@ -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; diff --git a/src/Core/WinSWCore/Native/Advapi32.cs b/src/Core/WinSWCore/Native/Advapi32.cs index fac5ec6..99f23ba 100755 --- a/src/Core/WinSWCore/Native/Advapi32.cs +++ b/src/Core/WinSWCore/Native/Advapi32.cs @@ -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 /// Name of an account - "domain\account" or only "account" /// Name ofthe privilege /// The windows error code returned by LsaAddAccountRights - 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; } diff --git a/src/Core/WinSWCore/Native/Kernel32.cs b/src/Core/WinSWCore/Native/Kernel32.cs index 302dc80..abc7c85 100755 --- a/src/Core/WinSWCore/Native/Kernel32.cs +++ b/src/Core/WinSWCore/Native/Kernel32.cs @@ -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; diff --git a/src/Core/WinSWCore/PeriodicRollingCalendar.cs b/src/Core/WinSWCore/PeriodicRollingCalendar.cs index 8af541c..3a77d7c 100644 --- a/src/Core/WinSWCore/PeriodicRollingCalendar.cs +++ b/src/Core/WinSWCore/PeriodicRollingCalendar.cs @@ -96,7 +96,7 @@ namespace winsw public PeriodicityType periodicityType { get; set; } - public Boolean shouldRoll + public bool shouldRoll { get { diff --git a/src/Core/WinSWCore/ServiceDescriptor.cs b/src/Core/WinSWCore/ServiceDescriptor.cs index aa4ae13..510206e 100755 --- a/src/Core/WinSWCore/ServiceDescriptor.cs +++ b/src/Core/WinSWCore/ServiceDescriptor.cs @@ -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(extension, "id"); + string extensionId = XmlHelper.SingleAttribute(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; } diff --git a/src/Core/WinSWCore/Util/ProcessHelper.cs b/src/Core/WinSWCore/Util/ProcessHelper.cs index fe588e4..c8d6e77 100644 --- a/src/Core/WinSWCore/Util/ProcessHelper.cs +++ b/src/Core/WinSWCore/Util/ProcessHelper.cs @@ -131,7 +131,7 @@ namespace winsw.Util /// Completion callback. If null, the completion won't be monitored /// Log handler. If enabled, logs will be redirected to the process and then reported /// Redirect standard input - public static void StartProcessAndCallbackForExit(Process processToStart, String executable = null, string arguments = null, Dictionary envVars = null, + public static void StartProcessAndCallbackForExit(Process processToStart, string executable = null, string arguments = null, Dictionary envVars = null, string workingDirectory = null, ProcessPriorityClass? priority = null, ProcessCompletionCallback callback = null, bool redirectStdin = true, LogHandler logHandler = null, bool hideWindow = false) { var ps = processToStart.StartInfo; diff --git a/src/Core/WinSWCore/Util/SigIntHelper.cs b/src/Core/WinSWCore/Util/SigIntHelper.cs index d6a0a67..d6e639c 100644 --- a/src/Core/WinSWCore/Util/SigIntHelper.cs +++ b/src/Core/WinSWCore/Util/SigIntHelper.cs @@ -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 diff --git a/src/Core/WinSWCore/Util/XmlHelper.cs b/src/Core/WinSWCore/Util/XmlHelper.cs index 1f58694..e5c98e5 100644 --- a/src/Core/WinSWCore/Util/XmlHelper.cs +++ b/src/Core/WinSWCore/Util/XmlHelper.cs @@ -14,7 +14,7 @@ namespace winsw.Util /// If optional, don't throw an exception if the elemen is missing /// String value or null /// The required element is missing - 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 /// If otional, don't throw an exception if the elemen is missing /// String value or null /// The required element is missing - 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) diff --git a/src/Core/WinSWCore/WinSWException.cs b/src/Core/WinSWCore/WinSWException.cs index 80eef21..6fed7b7 100644 --- a/src/Core/WinSWCore/WinSWException.cs +++ b/src/Core/WinSWCore/WinSWException.cs @@ -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) { } } diff --git a/src/Core/WinSWCore/Wmi.cs b/src/Core/WinSWCore/Wmi.cs index f36e559..d8837ba 100755 --- a/src/Core/WinSWCore/Wmi.cs +++ b/src/Core/WinSWCore/Wmi.cs @@ -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); diff --git a/src/Plugins/RunawayProcessKiller/RunawayProcessKillerExtension.cs b/src/Plugins/RunawayProcessKiller/RunawayProcessKillerExtension.cs index 2ba9594..974cfa3 100644 --- a/src/Plugins/RunawayProcessKiller/RunawayProcessKillerExtension.cs +++ b/src/Plugins/RunawayProcessKiller/RunawayProcessKillerExtension.cs @@ -15,7 +15,7 @@ namespace winsw.Plugins.RunawayProcessKiller /// /// Absolute path to the PID file, which stores ID of the previously launched process. /// - public String Pidfile { get; private set; } + public string Pidfile { get; private set; } /// /// Defines the process termination timeout in milliseconds. @@ -34,9 +34,9 @@ namespace winsw.Plugins.RunawayProcessKiller /// 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; } /// @@ -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; diff --git a/src/Plugins/SharedDirectoryMapper/SharedDirectoryMapper.cs b/src/Plugins/SharedDirectoryMapper/SharedDirectoryMapper.cs index d437da8..27d6f74 100644 --- a/src/Plugins/SharedDirectoryMapper/SharedDirectoryMapper.cs +++ b/src/Plugins/SharedDirectoryMapper/SharedDirectoryMapper.cs @@ -12,7 +12,7 @@ namespace winsw.Plugins.SharedDirectoryMapper private readonly SharedDirectoryMappingHelper _mapper = new SharedDirectoryMappingHelper(); private readonly List _entries = new List(); - public override String DisplayName => "Shared Directory Mapper"; + public override string DisplayName => "Shared Directory Mapper"; private static readonly ILog Logger = LogManager.GetLogger(typeof(SharedDirectoryMapper)); diff --git a/src/Plugins/SharedDirectoryMapper/SharedDirectoryMapperConfig.cs b/src/Plugins/SharedDirectoryMapper/SharedDirectoryMapperConfig.cs index 59276e8..68f7335 100644 --- a/src/Plugins/SharedDirectoryMapper/SharedDirectoryMapperConfig.cs +++ b/src/Plugins/SharedDirectoryMapper/SharedDirectoryMapperConfig.cs @@ -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) { diff --git a/src/Plugins/SharedDirectoryMapper/SharedDirectoryMapperHelper.cs b/src/Plugins/SharedDirectoryMapper/SharedDirectoryMapperHelper.cs index 8538f21..8647a5c 100644 --- a/src/Plugins/SharedDirectoryMapper/SharedDirectoryMapperHelper.cs +++ b/src/Plugins/SharedDirectoryMapper/SharedDirectoryMapperHelper.cs @@ -12,7 +12,7 @@ namespace winsw.Plugins.SharedDirectoryMapper /// Command to be executed /// Command arguments /// Operation failure - 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 /// Disk label /// UNC path to the directory /// Operation failure - 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 /// /// Disk label /// Operation failure - 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) diff --git a/src/Test/winswTests/DownloadTest.cs b/src/Test/winswTests/DownloadTest.cs index 98c7ce1..7a4452f 100644 --- a/src/Test/winswTests/DownloadTest.cs +++ b/src/Test/winswTests/DownloadTest.cs @@ -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("") @@ -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) diff --git a/src/Test/winswTests/Extensions/ExtensionTestBase.cs b/src/Test/winswTests/Extensions/ExtensionTestBase.cs index f9219bc..74f85cc 100644 --- a/src/Test/winswTests/Extensions/ExtensionTestBase.cs +++ b/src/Test/winswTests/Extensions/ExtensionTestBase.cs @@ -13,7 +13,7 @@ namespace winswTests.Extensions /// /// Type of the extension /// String for Type locator, which includes class and assembly names - public static String GetExtensionClassNameWithAssembly(Type type) + public static string GetExtensionClassNameWithAssembly(Type type) { return type.ToString() + ", " + type.Assembly; } diff --git a/src/Test/winswTests/Extensions/RunawayProcessKillerTest.cs b/src/Test/winswTests/Extensions/RunawayProcessKillerTest.cs index 0c47ac4..e9b1972 100644 --- a/src/Test/winswTests/Extensions/RunawayProcessKillerTest.cs +++ b/src/Test/winswTests/Extensions/RunawayProcessKillerTest.cs @@ -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(); env.Add(varName, winswId); diff --git a/src/Test/winswTests/Util/CLITestHelper.cs b/src/Test/winswTests/Util/CLITestHelper.cs index 843ef02..9dddb3f 100644 --- a/src/Test/winswTests/Util/CLITestHelper.cs +++ b/src/Test/winswTests/Util/CLITestHelper.cs @@ -33,7 +33,7 @@ namespace winswTests.Util /// STDOUT if there's no exceptions /// Command failure [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 /// Optional Service descriptor (will be used for initializationpurposes) /// Test results [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; diff --git a/src/Test/winswTests/Util/ConfigXmlBuilder.cs b/src/Test/winswTests/Util/ConfigXmlBuilder.cs index 26bc11b..fce4951 100644 --- a/src/Test/winswTests/Util/ConfigXmlBuilder.cs +++ b/src/Test/winswTests/Util/ConfigXmlBuilder.cs @@ -20,7 +20,7 @@ namespace winswTests.Util public string XMLComment { get; set; } public List ExtensionXmls { get; private set; } - private List configEntries; + private List configEntries; // TODO: Switch to the initializer? private ConfigXmlBuilder() @@ -64,7 +64,7 @@ namespace winswTests.Util str.AppendFormat(" {0}\n", Name); str.AppendFormat(" {0}\n", Description); str.AppendFormat(" {0}\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}", tagName, value)); + return WithRawEntry(string.Format("<{0}>{1}", 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(" \n", new Object[] { enabled, fullyQualifiedExtensionName, extensionId }); + str.AppendFormat(" \n", new object[] { enabled, fullyQualifiedExtensionName, extensionId }); str.AppendFormat(" {0}\n", ext.Pidfile); str.AppendFormat(" {0}\n", ext.StopTimeout.TotalMilliseconds); str.AppendFormat(" {0}\n", ext.StopParentProcessFirst); @@ -127,7 +127,7 @@ namespace winswTests.Util public ConfigXmlBuilder WithDownload(Download download) { StringBuilder str = new StringBuilder(); - str.AppendFormat(" /// tmp Dir - 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); diff --git a/src/Test/winswTests/Util/ProcessHelperTest.cs b/src/Test/winswTests/Util/ProcessHelperTest.cs index 9d6871e..499aca3 100644 --- a/src/Test/winswTests/Util/ProcessHelperTest.cs +++ b/src/Test/winswTests/Util/ProcessHelperTest.cs @@ -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,11 +36,11 @@ 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 Assert.That(!envVars.ContainsKey("test_key"), "Test error: the environment parsing logic is case-insensitive"); @@ -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));