Skip to content

Commit

Permalink
Change the framework to look for the SifFramework.config file in the …
Browse files Browse the repository at this point in the history
…current path first and the application folder second.
  • Loading branch information
rafidzal committed Apr 11, 2017
1 parent 462c5a0 commit c1c9661
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 Systemic Pty Ltd
* Copyright 2017 Systemic Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,9 @@
using Sif.Framework.Model.Infrastructure;
using System;
using System.Configuration;
using System.IO;
using System.Reflection;
using System.Web.Hosting;

namespace Sif.Framework.Model.Settings
{
Expand Down Expand Up @@ -44,11 +47,11 @@ protected bool GetBooleanSetting(string key, bool defaultValue)

try
{
value = Boolean.Parse(setting.Value);
value = bool.Parse(setting.Value);
}
catch (FormatException)
{
string message = String.Format("The valid values for the {0} setting are \"true\" or \"false\". The value \"{1}\" is not valid.", setting.Key, setting.Value);
string message = $"The valid values for the {setting.Key} setting are \"true\" or \"false\". The value \"{setting.Value}\" is not valid.";
throw new ConfigurationErrorsException(message);
}

Expand All @@ -73,11 +76,11 @@ protected int GetIntegerSetting(string key, int defaultValue)

try
{
value = Int32.Parse(setting.Value);
value = int.Parse(setting.Value);
}
catch (FormatException)
{
string message = String.Format("The value \"{1}\" is not a valid integer for the {0} setting.", setting.Key, setting.Value);
string message = $"The value \"{setting.Value}\" is not a valid integer for the {setting.Key} setting.";
throw new ConfigurationErrorsException(message);
}

Expand Down Expand Up @@ -120,7 +123,7 @@ protected string GetStringSetting(string key)
/// </summary>
protected ConfigFileBasedFrameworkSettings()
{
string configurationFilePath = System.Web.Hosting.HostingEnvironment.MapPath("~/SifFramework.config");
string configurationFilePath = HostingEnvironment.MapPath("~/SifFramework.config");

if (configurationFilePath == null)
{
Expand All @@ -133,14 +136,21 @@ protected ConfigFileBasedFrameworkSettings()

if (!configuration.HasFile)
{
string message = String.Format("Missing configuration file {0}.", configurationFilePath);
string fullPath = Assembly.GetExecutingAssembly().Location;
exeConfigurationFileMap.ExeConfigFilename = Path.GetDirectoryName(fullPath) + "\\SifFramework.config";
configuration = ConfigurationManager.OpenMappedExeConfiguration(exeConfigurationFileMap, ConfigurationUserLevel.None);
}

if (!configuration.HasFile)
{
string message = $"Missing configuration file {configurationFilePath}.";
throw new ConfigurationErrorsException(message);
}

}

/// <summary>
/// <see cref="Sif.Framework.Model.Settings.IFrameworkSettings.ApplicationKey"/>
/// <see cref="IFrameworkSettings.ApplicationKey"/>
/// </summary>
public string ApplicationKey
{
Expand All @@ -153,7 +163,7 @@ public string ApplicationKey
}

/// <summary>
/// <see cref="Sif.Framework.Model.Settings.IFrameworkSettings.AuthenticationMethod"/>
/// <see cref="IFrameworkSettings.AuthenticationMethod"/>
/// </summary>
public string AuthenticationMethod
{
Expand All @@ -166,7 +176,7 @@ public string AuthenticationMethod
}

/// <summary>
/// <see cref="Sif.Framework.Model.Settings.IFrameworkSettings.CompressPayload"/>
/// <see cref="IFrameworkSettings.CompressPayload"/>
/// </summary>
public bool CompressPayload
{
Expand All @@ -179,7 +189,7 @@ public bool CompressPayload
}

/// <summary>
/// <see cref="Sif.Framework.Model.Settings.IFrameworkSettings.ConsumerName"/>
/// <see cref="IFrameworkSettings.ConsumerName"/>
/// </summary>
public string ConsumerName
{
Expand All @@ -192,7 +202,7 @@ public string ConsumerName
}

/// <summary>
/// <see cref="Sif.Framework.Model.Settings.IFrameworkSettings.DataModelNamespace"/>
/// <see cref="IFrameworkSettings.DataModelNamespace"/>
/// </summary>
public string DataModelNamespace
{
Expand All @@ -205,7 +215,7 @@ public string DataModelNamespace
}

/// <summary>
/// <see cref="Sif.Framework.Model.Settings.IFrameworkSettings.InfrastructureNamespace"/>
/// <see cref="IFrameworkSettings.InfrastructureNamespace"/>
/// </summary>
public string InfrastructureNamespace
{
Expand All @@ -218,7 +228,7 @@ public string InfrastructureNamespace
}

/// <summary>
/// <see cref="Sif.Framework.Model.Settings.IFrameworkSettings.DeleteOnUnregister"/>
/// <see cref="IFrameworkSettings.DeleteOnUnregister"/>
/// </summary>
public bool DeleteOnUnregister
{
Expand All @@ -231,7 +241,7 @@ public bool DeleteOnUnregister
}

/// <summary>
/// <see cref="Sif.Framework.Model.Settings.IFrameworkSettings.EnvironmentType"/>
/// <see cref="IFrameworkSettings.EnvironmentType"/>
/// </summary>
public EnvironmentType EnvironmentType
{
Expand All @@ -254,7 +264,7 @@ public EnvironmentType EnvironmentType
}
else
{
string message = String.Format("The valid values for the {0} setting are \"BROKERED\" or \"DIRECT\". The value \"{1}\" is not valid.", setting.Key, setting.Value);
string message = $"The valid values for the {setting.Key} setting are \"BROKERED\" or \"DIRECT\". The value \"{setting.Value}\" is not valid.";
throw new ConfigurationErrorsException(message);
}

Expand All @@ -266,7 +276,7 @@ public EnvironmentType EnvironmentType
}

/// <summary>
/// <see cref="Sif.Framework.Model.Settings.IFrameworkSettings.EnvironmentUrl"/>
/// <see cref="IFrameworkSettings.EnvironmentUrl"/>
/// </summary>
public string EnvironmentUrl
{
Expand All @@ -279,7 +289,7 @@ public string EnvironmentUrl
}

/// <summary>
/// <see cref="Sif.Framework.Model.Settings.IFrameworkSettings.InstanceId"/>
/// <see cref="IFrameworkSettings.InstanceId"/>
/// </summary>
public string InstanceId
{
Expand All @@ -292,7 +302,7 @@ public string InstanceId
}

/// <summary>
/// <see cref="Sif.Framework.Model.Settings.IFrameworkSettings.NavigationPageSize"/>
/// <see cref="IFrameworkSettings.NavigationPageSize"/>
/// </summary>
public int NavigationPageSize
{
Expand All @@ -305,7 +315,7 @@ public int NavigationPageSize
}

/// <summary>
/// <see cref="Sif.Framework.Model.Settings.IFrameworkSettings.SharedSecret"/>
/// <see cref="IFrameworkSettings.SharedSecret"/>
/// </summary>
public string SharedSecret
{
Expand All @@ -318,7 +328,7 @@ public string SharedSecret
}

/// <summary>
/// <see cref="Sif.Framework.Model.Settings.IFrameworkSettings.SolutionId"/>
/// <see cref="IFrameworkSettings.SolutionId"/>
/// </summary>
public string SolutionId
{
Expand All @@ -331,7 +341,7 @@ public string SolutionId
}

/// <summary>
/// <see cref="Sif.Framework.Model.Settings.IFrameworkSettings.SupportedInfrastructureVersion"/>
/// <see cref="IFrameworkSettings.SupportedInfrastructureVersion"/>
/// </summary>
public string SupportedInfrastructureVersion
{
Expand All @@ -344,7 +354,7 @@ public string SupportedInfrastructureVersion
}

/// <summary>
/// <see cref="Sif.Framework.Model.Settings.IFrameworkSettings.UserToken"/>
/// <see cref="IFrameworkSettings.UserToken"/>
/// </summary>
public string UserToken
{
Expand Down Expand Up @@ -390,5 +400,7 @@ public int JobTimeoutFrequency
{
get { return GetIntegerSetting(SettingsPrefix + ".job.timeout.frequency", 60); }
}

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Systemic Pty Ltd
* Copyright 2017 Systemic Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,9 @@
using Sif.Framework.Model.Settings;
using System;
using System.Configuration;
using System.IO;
using System.Reflection;
using System.Web.Hosting;

namespace Sif.Framework.Service.Sessions
{
Expand All @@ -43,7 +46,7 @@ abstract class ConfigFileBasedSessionService : ISessionService
/// </summary>
public ConfigFileBasedSessionService()
{
string configurationFilePath = System.Web.Hosting.HostingEnvironment.MapPath("~/SifFramework.config");
string configurationFilePath = HostingEnvironment.MapPath("~/SifFramework.config");

if (configurationFilePath == null)
{
Expand All @@ -56,30 +59,37 @@ public ConfigFileBasedSessionService()

if (!Configuration.HasFile)
{
string message = String.Format("Missing configuration file {0}.", configurationFilePath);
string fullPath = Assembly.GetExecutingAssembly().Location;
exeConfigurationFileMap.ExeConfigFilename = Path.GetDirectoryName(fullPath) + "\\SifFramework.config";
Configuration = ConfigurationManager.OpenMappedExeConfiguration(exeConfigurationFileMap, ConfigurationUserLevel.None);
}

if (!Configuration.HasFile)
{
string message = $"Missing configuration file {configurationFilePath}.";
throw new ConfigurationErrorsException(message);
}

}

/// <summary>
/// <see cref="Sif.Framework.Service.Sessions.ISessionService.HasSession(System.String, System.String, System.String, System.String)"/>
/// <see cref="ISessionService.HasSession(string, string, string, string)"/>
/// </summary>
public bool HasSession(string applicationKey, string solutionId = null, string userToken = null, string instanceId = null)
{
return (RetrieveSessionToken(applicationKey, solutionId, userToken, instanceId) == null ? false : true);
}

/// <summary>
/// <see cref="Sif.Framework.Service.Sessions.ISessionService.HasSession(System.String)"/>
/// <see cref="ISessionService.HasSession(string)"/>
/// </summary>
public bool HasSession(string sessionToken)
{
return (SessionsSection.Sessions[sessionToken] == null ? false : true);
}

/// <summary>
/// <see cref="Sif.Framework.Service.Sessions.ISessionService.RemoveSession(System.String)"/>
/// <see cref="ISessionService.RemoveSession(string)"/>
/// </summary>
public void RemoveSession(string sessionToken)
{
Expand All @@ -94,7 +104,7 @@ public void RemoveSession(string sessionToken)
}

/// <summary>
/// <see cref="Sif.Framework.Service.Sessions.ISessionService.RetrieveEnvironmentUrl(System.String, System.String, System.String, System.String)"/>
/// <see cref="ISessionService.RetrieveEnvironmentUrl(string, string, string, string)"/>
/// </summary>
public string RetrieveEnvironmentUrl(string applicationKey, string solutionId = null, string userToken = null, string instanceId = null)
{
Expand All @@ -103,10 +113,10 @@ public string RetrieveEnvironmentUrl(string applicationKey, string solutionId =
foreach (SessionElement session in SessionsSection.Sessions)
{

if (String.Equals(applicationKey, session.ApplicationKey) &&
(solutionId == null ? String.IsNullOrWhiteSpace(session.SolutionId) : solutionId.Equals(session.SolutionId)) &&
(userToken == null ? String.IsNullOrWhiteSpace(session.UserToken) : userToken.Equals(session.UserToken)) &&
(instanceId == null ? String.IsNullOrWhiteSpace(session.InstanceId) : instanceId.Equals(session.InstanceId)))
if (string.Equals(applicationKey, session.ApplicationKey) &&
(solutionId == null ? string.IsNullOrWhiteSpace(session.SolutionId) : solutionId.Equals(session.SolutionId)) &&
(userToken == null ? string.IsNullOrWhiteSpace(session.UserToken) : userToken.Equals(session.UserToken)) &&
(instanceId == null ? string.IsNullOrWhiteSpace(session.InstanceId) : instanceId.Equals(session.InstanceId)))
{
environmentUrl = session.EnvironmentUrl;
break;
Expand All @@ -118,7 +128,7 @@ public string RetrieveEnvironmentUrl(string applicationKey, string solutionId =
}

/// <summary>
/// <see cref="Sif.Framework.Service.Sessions.ISessionService.RetrieveSessionToken(System.String, System.String, System.String, System.String)"/>
/// <see cref="ISessionService.RetrieveSessionToken(string, string, string, string)"/>
/// </summary>
public string RetrieveSessionToken(string applicationKey, string solutionId = null, string userToken = null, string instanceId = null)
{
Expand All @@ -127,10 +137,10 @@ public string RetrieveSessionToken(string applicationKey, string solutionId = nu
foreach (SessionElement session in SessionsSection.Sessions)
{

if (String.Equals(applicationKey, session.ApplicationKey) &&
(solutionId == null ? String.IsNullOrWhiteSpace(session.SolutionId) : solutionId.Equals(session.SolutionId)) &&
(userToken == null ? String.IsNullOrWhiteSpace(session.UserToken) : userToken.Equals(session.UserToken)) &&
(instanceId == null ? String.IsNullOrWhiteSpace(session.InstanceId) : instanceId.Equals(session.InstanceId)))
if (string.Equals(applicationKey, session.ApplicationKey) &&
(solutionId == null ? string.IsNullOrWhiteSpace(session.SolutionId) : solutionId.Equals(session.SolutionId)) &&
(userToken == null ? string.IsNullOrWhiteSpace(session.UserToken) : userToken.Equals(session.UserToken)) &&
(instanceId == null ? string.IsNullOrWhiteSpace(session.InstanceId) : instanceId.Equals(session.InstanceId)))
{
sessionToken = session.SessionToken;
break;
Expand All @@ -142,14 +152,14 @@ public string RetrieveSessionToken(string applicationKey, string solutionId = nu
}

/// <summary>
/// <see cref="Sif.Framework.Service.Sessions.ISessionService.StoreSession(System.String, System.String, System.String, System.String, System.String, System.String)"/>
/// <see cref="ISessionService.StoreSession(string, string, string, string, string, string)"/>
/// </summary>
public void StoreSession(string applicationKey, string sessionToken, string environmentUrl, string solutionId = null, string userToken = null, string instanceId = null)
{

if (HasSession(applicationKey, solutionId, userToken, instanceId))
{
string message = String.Format("Session with the following credentials already exists - [applicationKey={0}]{1}{2}{3}.",
string message = string.Format("Session with the following credentials already exists - [applicationKey={0}]{1}{2}{3}.",
applicationKey,
(solutionId == null ? "" : "[solutionId=" + solutionId + "]"),
(userToken == null ? "" : "[userToken=" + userToken + "]"),
Expand All @@ -159,7 +169,7 @@ public void StoreSession(string applicationKey, string sessionToken, string envi

if (HasSession(sessionToken))
{
string message = String.Format("Session already exists with a session token of {0}.", sessionToken);
string message = string.Format("Session already exists with a session token of {0}.", sessionToken);
throw new ConfigurationErrorsException(message);
}

Expand Down
Binary file modified SharedLibs/Sif.Framework 3.2.0/Sif.Framework.dll
Binary file not shown.

0 comments on commit c1c9661

Please sign in to comment.