diff --git a/Installer/Installer.vdproj b/Installer/Installer.vdproj index b413416..c344b47 100644 --- a/Installer/Installer.vdproj +++ b/Installer/Installer.vdproj @@ -106,12 +106,6 @@ "Entry" { "MsmKey" = "8:_UNDEFINED" - "OwnerKey" = "8:_F7997D5DC4D27D0859699C68A19B4274" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { - "MsmKey" = "8:_UNDEFINED" "OwnerKey" = "8:_7BCB868A2CAA4D33BE94750D68006132" "MsmSig" = "8:_UNDEFINED" } @@ -157,6 +151,12 @@ "OwnerKey" = "8:_98642F03DFBEE1CE810E683399B503CA" "MsmSig" = "8:_UNDEFINED" } + "Entry" + { + "MsmKey" = "8:_UNDEFINED" + "OwnerKey" = "8:_F7997D5DC4D27D0859699C68A19B4274" + "MsmSig" = "8:_UNDEFINED" + } } "Configurations" { @@ -165,7 +165,7 @@ "DisplayName" = "8:Debug" "IsDebugOnly" = "11:TRUE" "IsReleaseOnly" = "11:FALSE" - "OutputFilename" = "8:Debug\\Installer.msi" + "OutputFilename" = "8:Debug\\TimberWinR-1.1.0.msi" "PackageFilesAs" = "3:2" "PackageFileSize" = "3:-2147483648" "CabType" = "3:1" @@ -175,13 +175,29 @@ "PrivateKeyFile" = "8:" "TimeStampServer" = "8:" "InstallerBootstrapper" = "3:2" + "BootstrapperCfg:{63ACBE69-63AA-4F98-B2B6-99F9E24495F2}" + { + "Enabled" = "11:TRUE" + "PromptEnabled" = "11:TRUE" + "PrerequisitesLocation" = "2:1" + "Url" = "8:" + "ComponentsUrl" = "8:" + "Items" + { + "{EDC2488A-8267-493A-A98E-7D9C3B36CDF3}:.NETFramework,Version=v4.5" + { + "Name" = "8:Microsoft .NET Framework 4.5 (x86 and x64)" + "ProductCode" = "8:.NETFramework,Version=v4.5" + } + } + } } "Release" { "DisplayName" = "8:Release" "IsDebugOnly" = "11:FALSE" "IsReleaseOnly" = "11:TRUE" - "OutputFilename" = "8:Release\\Installer.msi" + "OutputFilename" = "8:Release\\TimberWinR-1.1.0.msi" "PackageFilesAs" = "3:2" "PackageFileSize" = "3:-2147483648" "CabType" = "3:1" @@ -191,6 +207,14 @@ "PrivateKeyFile" = "8:" "TimeStampServer" = "8:" "InstallerBootstrapper" = "3:2" + "BootstrapperCfg:{63ACBE69-63AA-4F98-B2B6-99F9E24495F2}" + { + "Enabled" = "11:TRUE" + "PromptEnabled" = "11:TRUE" + "PrerequisitesLocation" = "2:1" + "Url" = "8:" + "ComponentsUrl" = "8:" + } } } "Deployable" @@ -199,7 +223,7 @@ { "{4AA51A2D-7D85-4A59-BA75-B0809FC8B380}:_1AF00E3D0BF342E0B27D1286AAF50918" { - "Name" = "8:Primary output from TimberWinR.ServiceHost (Active)" + "Name" = "8:Service Install" "Condition" = "8:" "Object" = "8:_7BCB868A2CAA4D33BE94750D68006132" "FileType" = "3:2" @@ -211,44 +235,58 @@ "InstallerClass" = "11:FALSE" "CustomActionData" = "8:" } + "{4AA51A2D-7D85-4A59-BA75-B0809FC8B380}:_35606DFD709D464CAF3CF5B5B7E89A52" + { + "Name" = "8:Setup Config Path" + "Condition" = "8:" + "Object" = "8:_7BCB868A2CAA4D33BE94750D68006132" + "FileType" = "3:2" + "InstallAction" = "3:1" + "Arguments" = "8:" + "EntryPoint" = "8:" + "Sequence" = "3:2" + "Identifier" = "8:_B3BE21EE_6D61_41A5_841F_42DE009A4CBD" + "InstallerClass" = "11:TRUE" + "CustomActionData" = "8:/configFile=\"[CONFIGFILE]\" /logdir=\"[LOGDIR]\"" + } "{4AA51A2D-7D85-4A59-BA75-B0809FC8B380}:_57135C50CEA24E3C9D356E7ABCBC9671" { - "Name" = "8:Primary output from TimberWinR.ServiceHost (Active)" + "Name" = "8:Stop Service" "Condition" = "8:" "Object" = "8:_7BCB868A2CAA4D33BE94750D68006132" "FileType" = "3:2" "InstallAction" = "3:4" "Arguments" = "8:stop" "EntryPoint" = "8:" - "Sequence" = "3:2" + "Sequence" = "3:1" "Identifier" = "8:_B30B9234_9E99_4218_ABDF_55E5948259E3" "InstallerClass" = "11:FALSE" "CustomActionData" = "8:" } "{4AA51A2D-7D85-4A59-BA75-B0809FC8B380}:_639BE1FAFE984C5A8AEEA2240422F1A2" { - "Name" = "8:Primary output from TimberWinR.ServiceHost (Active)" + "Name" = "8:Start Service" "Condition" = "8:" "Object" = "8:_7BCB868A2CAA4D33BE94750D68006132" "FileType" = "3:2" "InstallAction" = "3:1" "Arguments" = "8:start" "EntryPoint" = "8:" - "Sequence" = "3:2" + "Sequence" = "3:3" "Identifier" = "8:_EA07A56B_5CC6_45F3_B610_24D63C0111B2" "InstallerClass" = "11:FALSE" "CustomActionData" = "8:" } "{4AA51A2D-7D85-4A59-BA75-B0809FC8B380}:_AF7EB1BB260845F1806BD079A8212C6F" { - "Name" = "8:Primary output from TimberWinR.ServiceHost (Active)" + "Name" = "8:Uninstall Service" "Condition" = "8:" "Object" = "8:_7BCB868A2CAA4D33BE94750D68006132" "FileType" = "3:2" "InstallAction" = "3:4" "Arguments" = "8:uninstall" "EntryPoint" = "8:" - "Sequence" = "3:1" + "Sequence" = "3:2" "Identifier" = "8:_8224C98F_5305_468F_B717_C41E5E696513" "InstallerClass" = "11:FALSE" "CustomActionData" = "8:" @@ -581,7 +619,7 @@ "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:TimberWinR" "ProductCode" = "8:{6A92C26D-917E-4B93-80CA-5CF1FD3C4FC4}" - "PackageCode" = "8:{DF28AD86-47D2-417E-B2C2-D0FCB92EF21F}" + "PackageCode" = "8:{E45032FC-7473-4294-BAB9-EA73A78548EA}" "UpgradeCode" = "8:{B2219A12-A350-4DF0-B12D-F1C0BD16FF64}" "AspNetVersion" = "8:4.0.30319.0" "RestartWWWService" = "11:FALSE" diff --git a/TimberWinR.ServiceHost/Installer.Designer.cs b/TimberWinR.ServiceHost/Installer.Designer.cs new file mode 100644 index 0000000..ac905c2 --- /dev/null +++ b/TimberWinR.ServiceHost/Installer.Designer.cs @@ -0,0 +1,36 @@ +namespace TimberWinR.ServiceHost +{ + partial class Installer + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} \ No newline at end of file diff --git a/TimberWinR.ServiceHost/Installer.cs b/TimberWinR.ServiceHost/Installer.cs new file mode 100644 index 0000000..e0e419e --- /dev/null +++ b/TimberWinR.ServiceHost/Installer.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Configuration.Install; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.Win32; + +namespace TimberWinR.ServiceHost +{ + [RunInstaller(true)] + public partial class Installer : System.Configuration.Install.Installer + { + public Installer() + { + InitializeComponent(); + } + + public override void Install(IDictionary stateSaver) + { + base.Install(stateSaver); + + string keyPath = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\TimberWinR"; + string keyName = "ImagePath"; + + string currentValue = Registry.GetValue(keyPath, keyName, "").ToString(); + if (!string.IsNullOrEmpty(currentValue)) + { + string configFile = Context.Parameters["configfile"]; + if (!string.IsNullOrEmpty(configFile) && !currentValue.Contains("-configFile ")) + { + currentValue += string.Format(" -configFile \"{0}\"", configFile.Replace("\\\\", "\\")); + Registry.SetValue(keyPath, keyName, currentValue); + } + + currentValue = Registry.GetValue(keyPath, keyName, "").ToString(); + + string logDir = Context.Parameters["logdir"]; + if (!string.IsNullOrEmpty(logDir) && !currentValue.Contains("-logDir ")) + { + currentValue += string.Format(" -logDir \"{0}\"", logDir.Replace("\\\\", "\\")); + Registry.SetValue(keyPath, keyName, currentValue); + } + } + } + } +} diff --git a/TimberWinR.ServiceHost/Program.cs b/TimberWinR.ServiceHost/Program.cs index 56c953d..0363468 100644 --- a/TimberWinR.ServiceHost/Program.cs +++ b/TimberWinR.ServiceHost/Program.cs @@ -36,7 +36,8 @@ namespace TimberWinR.ServiceHost }); hostConfigurator.AddCommandLineDefinition("configFile", c => arguments.ConfigFile = c); - hostConfigurator.AddCommandLineDefinition("logLevel", c => arguments.LogLevel = c); + hostConfigurator.AddCommandLineDefinition("logLevel", c => arguments.LogLevel = c); + hostConfigurator.AddCommandLineDefinition("logDir", c => arguments.LogfileDir = c); hostConfigurator.ApplyCommandLine(); hostConfigurator.RunAsLocalSystem(); diff --git a/TimberWinR.ServiceHost/TimberWinR.ServiceHost.csproj b/TimberWinR.ServiceHost/TimberWinR.ServiceHost.csproj index 33bd0d5..1934ff8 100644 --- a/TimberWinR.ServiceHost/TimberWinR.ServiceHost.csproj +++ b/TimberWinR.ServiceHost/TimberWinR.ServiceHost.csproj @@ -36,7 +36,9 @@ ..\packages\RapidRegex.Core.1.0.0.2\lib\net40\RapidRegex.Core.dll + + @@ -47,6 +49,12 @@ + + Component + + + Installer.cs + diff --git a/TimberWinR/Inputs/TcpInputListener.cs b/TimberWinR/Inputs/TcpInputListener.cs index 7ae6462..d885115 100644 --- a/TimberWinR/Inputs/TcpInputListener.cs +++ b/TimberWinR/Inputs/TcpInputListener.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading; @@ -13,9 +14,8 @@ namespace TimberWinR.Inputs public class TcpInputListener : InputListener { private readonly System.Net.Sockets.TcpListener _tcpListener; - private Thread _listenThread; - const int bufferSize = 16535; - private int _port; + private Thread _listenThread; + private readonly int _port; public TcpInputListener(CancellationToken cancelToken, int port = 5140) : base(cancelToken, "Win32-Tcp") @@ -66,41 +66,24 @@ namespace TimberWinR.Inputs { var tcpClient = (TcpClient)client; NetworkStream clientStream = tcpClient.GetStream(); - - var message = new byte[bufferSize]; - while (!CancelToken.IsCancellationRequested) + var stream = new StreamReader(clientStream); + + string line; + while ((line = stream.ReadLine()) != null) { - var bytesRead = 0; try { - //blocks until a client sends a message - bytesRead = clientStream.Read(message, 0, bufferSize); - } - catch - { - //a socket error has occured - break; - } - - if (bytesRead == 0) - { - //the client has disconnected from the server - break; - } - - //message has successfully been received - var encoder = new ASCIIEncoding(); - var encodedMessage = encoder.GetString(message, 0, bytesRead); - try - { - JObject json = JObject.Parse(encodedMessage); + JObject json = JObject.Parse(line); ProcessJson(json); } catch (Exception) - { - } + { + } + if (CancelToken.IsCancellationRequested) + break; } - tcpClient.Close(); + clientStream.Close(); + tcpClient.Close(); Finished(); } } diff --git a/TimberWinR/Manager.cs b/TimberWinR/Manager.cs index eda4ae1..83d9e3f 100644 --- a/TimberWinR/Manager.cs +++ b/TimberWinR/Manager.cs @@ -59,11 +59,13 @@ namespace TimberWinR // Is it a directory? if (Directory.Exists(jsonConfigFile)) { - Config = Configuration.FromDirectory(jsonConfigFile); LogManager.GetCurrentClassLogger().Info("Initialized, Reading Configurations From {0}", jsonConfigFile); + Config = Configuration.FromDirectory(jsonConfigFile); } else { + LogManager.GetCurrentClassLogger().Info("Initialized, Reading Configurations From File: {0}", jsonConfigFile); + var fi = new FileInfo(jsonConfigFile); if (!fi.Exists)