removed hardcoded string for WebApp endpoint (previously "http://*:8800")

The app now pulls in the port from the app.config file.
Also added some commented out code to load a config file in a different directory (i.e.: to allow config files in "configs" directory to be pulled in).
If the port isnt specified in the app.config, will default to 8800.
#27
This commit is contained in:
Chris.Watts90@outlook.com 2017-02-21 11:48:24 +00:00 committed by chris.watts90@outlook.com
parent f21088d0a0
commit b20a506d3a
3 changed files with 14 additions and 3 deletions

View File

@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using CardReaderService.DefaultComponents;

View File

@ -3,6 +3,7 @@
<appSettings>
<add key="NLogConfigFilePath" value="Configs/NLogConfig.xml" />
<add key="DefaultPageSize" value="20" />
<add key="WebsiteHttpPort" value="8800"/>
<add key="SwipeTimeGap" value="3" />
<add key="BugSubmissionEmailAddress" value="incoming+WattsC/FlexiTimeTrackerTool+24qrefn8e1urhl4iqct7we2jl@gitlab.com"/>
</appSettings>

View File

@ -1,4 +1,7 @@
using System;
using System.Configuration;
using System.IO;
using System.Reflection;
using System.ServiceProcess;
using System.Threading;
using Interfaces;
@ -31,6 +34,12 @@ namespace WindowsDataCenter
protected override void OnStart(string[] args)
{
var configPath = string.Concat(System.Reflection.Assembly.GetEntryAssembly().Location, ".config");
//var configsDir = new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "configs")).LocalPath;
//var exeName = Assembly.GetEntryAssembly().ManifestModule.ScopeName;
//var appConfigPath = Path.Combine(configsDir, string.Format("{0}.config", exeName));
//AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", appConfigPath);
//var val = ConfigurationManager.AppSettings["TEST"];
//Initialise the Ninject system.
var ninjectInstance = NinjectHelper.GetInstance();
_logger = NinjectHelper.GetInstance().Get<ILogger>();
@ -42,10 +51,12 @@ namespace WindowsDataCenter
IsBackground = false,
Name = "OWIN SELF HOST MAIN THREAD"
};
//TODO: use app.config for endpoint config.
var endpointPort = ConfigurationManager.AppSettings["WebsiteHttpPort"] ?? "8800";
try
{
_webApp = WebApp.Start<StartOwin>("http://*:8800");
var endpoint = string.Format("http://*:{0}", endpointPort);
_webApp = WebApp.Start<StartOwin>(endpoint);
}
catch (Exception ex)
{