using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration; using Yaulw.Assembly; using Yaulw.Tools; namespace PlutoServer.MSL { public static class Configuration { private const string DEFAULT_REGISTRATION_HOST_N_PORT_URL = "http://services.ndchealthvar.com/mobile1/REGURL.htm"; private const string DEFAULT_REGISTRATION_HOST_URL = "services.ndchealthvar.com"; private const int DEFAULT_REGISTRATION_CHANNEL_PORT = 443; private const string DEFAULT_CHECK_VERSION_URL = "http://services.ndchealthvar.com/mobile1/PUBLISH.htm"; private const string DEFAULT_DOWNLOAD_SETUP_URL = "http://services.ndchealthvar.com/mobile1/Setup.exe"; private const string DEFAULT_DOWNLOAD_MINISETUP_URL = "http://services.ndchealthvar.com/mobile1/SetupMini.exe"; private const string DEFAULT_DETERMINE_EXTERNAL_IP_ADDRESS_URL = "http://services.ndchealthvar.com/GetIP/default.aspx"; private static System.Configuration.Configuration _Configuration = null; /// /// Load the PlutoServer.MSL.Exe configuration (writing Configuration class this way) allows /// DiagnoseMobile.exe (RegistrationAPI_Tester to reuse this code/link this class) and is therefore /// more generic way of retrieving the settings /// /// public static bool Load(bool bReload) { try { if (_Configuration == null || bReload) { string curPath = AssemblyW.SpecializedAssemblyInfo.GetAssemblyPath(AssemblyW.AssemblyST.Executing); string ConfigNameNPath = PathNaming.PathEndsWithSlash(curPath) + "PlutoServer.MSL.exe"; _Configuration = ConfigurationManager.OpenExeConfiguration(ConfigNameNPath); return (_Configuration != null); } } catch (Exception) { /* ignore */} return false; } #region Setting Getters /// /// Returns true if passed in object is valid and is not empty /// /// an object to validate /// true if valid, false otherwise private static bool IsNotNullAndNotEmpty(object oToValidate) { if ((oToValidate != null) && (oToValidate.ToString() != String.Empty)) return true; else return false; } /// /// Check to make sure the configuration is set and that there is a setting that is not blank /// /// /// private static bool IsValidSetting(string setting) { if (_Configuration != null && !String.IsNullOrEmpty(setting) && IsNotNullAndNotEmpty(_Configuration.AppSettings.Settings[setting])) { var v = _Configuration.AppSettings.Settings[setting]; return IsNotNullAndNotEmpty(v.Value); } return false; } /// /// Retrieves a setting or "" if setting is not valid/not found/not configured /// /// /// private static string RetrieveSetting(string setting) { if (IsValidSetting(setting)) { var v = _Configuration.AppSettings.Settings[setting]; return v.Value.ToString(); } return String.Empty; } #endregion /// /// Default Registration URL to determine what Registration server to use (allows us to be more dynamic) /// public static string REGISTRATION_HOST_N_PORT_URL { get { if (IsValidSetting("REGISTRATION_HOST_N_PORT_URL")) return RetrieveSetting("REGISTRATION_HOST_N_PORT_URL"); else return DEFAULT_REGISTRATION_HOST_N_PORT_URL; } } /// /// Default Registration HOST URL To Use (can be configured via App.Config) /// public static string REGISTRATION_HOST_URL { get { if (IsValidSetting("REGISTRATION_HOST_URL")) return RetrieveSetting("REGISTRATION_HOST_URL"); else return DEFAULT_REGISTRATION_HOST_URL; } } /// /// Default Registration Port To Use (can be configured via App.Config) /// public static int REGISTRATION_CHANNEL_PORT { get { if (IsValidSetting("REGISTRATION_CHANNEL_PORT")) { int nPort = 0; if (int.TryParse(RetrieveSetting("REGISTRATION_CHANNEL_PORT"), out nPort) && nPort > 0) return nPort; } return DEFAULT_REGISTRATION_CHANNEL_PORT; } } /// /// Default CHECK_VERSION_URL To Use (can be configured via App.Config) /// public static string CHECK_VERSION_URL { get { if (IsValidSetting("CHECK_VERSION_URL")) return RetrieveSetting("CHECK_VERSION_URL"); else return DEFAULT_CHECK_VERSION_URL; } } /// /// Default DOWNLOAD_SETUP_URL To Use (can be configured via App.Config) /// public static string DOWNLOAD_SETUP_URL { get { if (IsValidSetting("DOWNLOAD_SETUP_URL")) return RetrieveSetting("DOWNLOAD_SETUP_URL"); else return DEFAULT_DOWNLOAD_SETUP_URL; } } /// /// Default DOWNLOAD_MINISETUP_URL To Use (can be configured via App.Config) /// public static string DOWNLOAD_MINISETUP_URL { get { if (IsValidSetting("DOWNLOAD_MINISETUP_URL")) return RetrieveSetting("DOWNLOAD_MINISETUP_URL"); else return DEFAULT_DOWNLOAD_MINISETUP_URL; } } /// /// Default DETERMINE_EXTERNAL_IP_ADDRESS_URL to use (can be configured via App.Config) /// public static string DETERMINE_EXTERNAL_IP_ADDRESS_URL { get { if (IsValidSetting("DETERMINE_EXTERNAL_IP_ADDRESS_URL")) return RetrieveSetting("DETERMINE_EXTERNAL_IP_ADDRESS_URL"); else return DEFAULT_DOWNLOAD_MINISETUP_URL; } } } }