// .Net StockTrader Sample WCF Application for Benchmarking, Performance Analysis and Design Considerations for Service-Oriented Applications //====================================================================================================== // The Settings class for the Business Service Layer (BSL). Please note well that we only override the // inherited settings (with the new keyword) becuase of the special case StockTrader BSL allows for running // BSL in-process with the StockTrader Composite Web Application, vs. remote calls (and running the OPS in-process // with the BSL, optionally). You will NOT need to do this for your services--your Settings class will be // much simpler, simply using the *inherited* global settings, and only specifying app-specific settings here. //====================================================================================================== //====================================================================================================== // Code originally contributed by Microsoft Corporation. // This contribution to the Stonehenge project is limited strictly // to the source code that is submitted in this submission. // Any technology, including underlying platform technology, // that is referenced or required by the submitted source code // is not a part of the contribution. // For example and not by way of limitation, // any systems/Windows libraries (WPF, WCF, ASP.NET etc.) // required to run the submitted source code is not a part of the contribution //====================================================================================================== using System; using System.Collections.Generic; using System.Configuration; using System.Web; using System.ServiceModel; using System.ServiceModel.Channels; using System.Data; using System.Collections; using System.Diagnostics; using System.Text; using System.Reflection; using Trade.Utility; namespace Trade.BusinessServiceConfigurationSettings { /// /// Any app or service implementing the Configuration Service needs a custom Settings class that will contain it's /// app-specific config settings. These are loaded from the SQL repository on startup with current values as set for service. /// Your custom settings class should inherit from the ConfigurationSettingsBase class, which contains common /// settings used by all services implementing the config service, in addition to the app-specific settings defined here. /// public class Settings //db: ConfigurationSettingsBase //Inherit from base implementation!! { //Begin Repository Settings --------------------------------- //BEGIN REPOSITORY DEFINED SETTINGS. ANY CONFIG KEY SETTING DEFINED IN DB REPOSITORY MUST HAVE A MATCHING STATIC VARIABLE HERE. //NOTE WELL: THE VARIABLE NAME WILL MATCH THE REPOSITORY COLUMN SettingsClassFieldName IN THE TABLE CONFIGURATIONKEYS. // THE CONFIG MANAGEMENT SYSTEM AUTOMATICALLY COORDINATES/SYNCHRONIZES CONFIG SETTINGS ACROSS RUNNING // HOST INSTANCES ON DIFFERENT SERVERS. THEY ARE SET VIA REFLECTION ON APP INITIALIZATION FROM THE SERVICE REPOSITORY, // YET UPDATABLE ACROSS DISTRIBUTED HOST INSTANCES VIA THE CONFIG MANAGEMENT SYSTEM (CONFIGWEB). YOU WILL USE CONFIGWEB TO ADD // REPOSITORY CONFIGURATION KEYS TO MAP THE REPOSITORY SETTING TO A CUSTOM (APP-SPECIFIC) FIELD NAME IN THE SETTINGS CLASS, AS // WELL AS UPDATE SETTINGS ON LIVE CLUSTERED SYSTEMS WITHOUT APP RESTARTS. public static string EVENT_LOG; public static string OPS_DOTNET_ENDPOINT_CONFIG_HTTP; public static string OPS_DOTNET_ENDPOINT_CONFIG_WSHTTP; public static string OPS_WSO2_ENDPOINT_CONFIG_WSHTTP; public static string ORDER_PROCESSING_MODE; public static string DBServer; public static string Database; public static string UserID; public static string Password; public static int MinDBConnections; public static int MaxDBConnections; public static string TRADEDB_SQL_CONN_STRING; public static string DAL; public static string ENABLE_GLOBAL_SYSTEM_DOT_TRANSACTIONS_CONFIGSTRING; public static int SYSTEMDOTTRANSACTION_TIMEOUT; public static int MAX_QUERY_ORDERS; public static int MAX_QUERY_TOP_ORDERS; public static bool DISPLAY_WEBSERVICE_LOGINS; public static int LOGIN_ITERATIONSTO_DISPLAY; public static string BSL_VALID_USERID; public static string BSL_VALID_PASSWORD; //End Repository Settings ----------------------------------- /// /// Local Settings Not From Config Database Repository. Note that any of these could optionally be moved into the /// config repository instead of being initialized in code. /// /// //set on startup based on config settings from repository public static int TRANSACTION_MODEL = -1; public static int orderMode = -1; public Settings() { Settings.ORDER_PROCESSING_MODE = ConfigurationManager.AppSettings.Get("ORDER_PROCESSING_MODE"); Settings.EVENT_LOG = ConfigurationManager.AppSettings.Get("EVENT_LOG"); Settings.DBServer = ConfigurationManager.AppSettings.Get("DBServer"); Settings.Database = ConfigurationManager.AppSettings.Get("Database"); Settings.UserID = ConfigurationManager.AppSettings.Get("UserID"); Settings.Password = ConfigurationManager.AppSettings.Get("Password"); Settings.MinDBConnections = Convert.ToInt32(ConfigurationManager.AppSettings.Get("MinDBConnections")); Settings.MaxDBConnections = Convert.ToInt32(ConfigurationManager.AppSettings.Get("MaxDBConnections")); Settings.TRADEDB_SQL_CONN_STRING = ConfigurationManager.AppSettings.Get("TRADEDB_SQL_CONN_STRING"); Settings.DAL = ConfigurationManager.AppSettings.Get("DAL"); Settings.ENABLE_GLOBAL_SYSTEM_DOT_TRANSACTIONS_CONFIGSTRING = ConfigurationManager.AppSettings.Get("ENABLE_GLOBAL_SYSTEM_DOT_TRANSACTIONS_CONFIGSTRING"); Settings.SYSTEMDOTTRANSACTION_TIMEOUT = Convert.ToInt32(ConfigurationManager.AppSettings.Get("SYSTEMDOTTRANSACTION_TIMEOUT")); Settings.MAX_QUERY_ORDERS = Convert.ToInt32(ConfigurationManager.AppSettings.Get("MAX_QUERY_ORDERS")); Settings.MAX_QUERY_TOP_ORDERS = Convert.ToInt32(ConfigurationManager.AppSettings.Get("MAX_QUERY_TOP_ORDERS")); Settings.DISPLAY_WEBSERVICE_LOGINS = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("DISPLAY_WEBSERVICE_LOGINS")); Settings.LOGIN_ITERATIONSTO_DISPLAY = Convert.ToInt32(ConfigurationManager.AppSettings.Get("LOGIN_ITERATIONSTO_DISPLAY")); Settings.OPS_DOTNET_ENDPOINT_CONFIG_HTTP = ConfigurationManager.AppSettings.Get("OPS_DOTNET_ENDPOINT_CONFIG_HTTP"); Settings.OPS_DOTNET_ENDPOINT_CONFIG_WSHTTP = ConfigurationManager.AppSettings.Get("OPS_DOTNET_ENDPOINT_CONFIG_WSHTTP"); Settings.OPS_WSO2_ENDPOINT_CONFIG_WSHTTP = ConfigurationManager.AppSettings.Get("OPS_WSO2_ENDPOINT_CONFIG_WSHTTP"); Settings.BSL_VALID_USERID = ConfigurationManager.AppSettings.Get("BSL_VALID_USERID"); Settings.BSL_VALID_PASSWORD = ConfigurationManager.AppSettings.Get("BSL_VALID_PASSWORD"); buildConnString(); setOrderMode(); setTxModel(); } /// /// Sets the selected OrderMode to an int constant. Faster for switch statements than parsing a string. /// public static void setOrderMode() { switch (ORDER_PROCESSING_MODE) { case StockTraderUtility.ORDER_STRING_Sync: { orderMode = StockTraderUtility.ORDER_Sync; break; } case StockTraderUtility.ORDER_STRING_ASyncHttp: { orderMode = StockTraderUtility.ORDER_ASync_Http; break; } case StockTraderUtility.ORDER_STRING_ASyncHttpMSec: { orderMode = StockTraderUtility.ORDER_ASync_WSHttp; break; } case StockTraderUtility.ORDER_STRING_WSO2_HTTP_MSEC: { orderMode = StockTraderUtility.ORDER_ASync_WSHttp_WSO2; break; } default: { throw new Exception(ORDER_PROCESSING_MODE + ": " + StockTraderUtility.EXCEPTION_MESSAGE_INVALID_ORDERMODE_CONFIG); } } return; } /// /// Sets the selected transaction model to use to an int constant. /// public static void setTxModel() { switch (ENABLE_GLOBAL_SYSTEM_DOT_TRANSACTIONS_CONFIGSTRING) { case (StockTraderUtility.TRANSACTION_STRING_SYSTEMDOTTRANSACTION_TRANSACTION): { TRANSACTION_MODEL = StockTraderUtility.TRANSACTION_MODEL_SYSTEMDOTTRANSACTION_TRANSACTION; break; } case (StockTraderUtility.TRANSACTION_STRING_ADONET_TRANSACTION): { TRANSACTION_MODEL = StockTraderUtility.TRANSACTION_MODEL_ADONET_TRANSACTION; break; } } return; } /// /// This method builds a connection string based on DAL setting and settings for the database name, location, uid and password. /// Called on host initialization and also when the DAL or DB connection parameters are changed via ConfigWeb. /// private void buildConnString() { switch (Settings.DAL) { case Trade.Utility.StockTraderUtility.DAL_SQLSERVER: { Settings.TRADEDB_SQL_CONN_STRING = "server=" + Settings.DBServer + ";database=" + Settings.Database + ";user id=" + Settings.UserID + ";password=" + Settings.Password + ";min pool size=" + Settings.MinDBConnections + ";max pool size=" + Settings.MaxDBConnections; break; } case Trade.Utility.StockTraderUtility.DAL_ORACLE: { Settings.TRADEDB_SQL_CONN_STRING = "Data Source=" + Settings.Database + ";user id=" + Settings.UserID + ";password=" + Settings.Password + ";min pool size=" + Settings.MinDBConnections + ";max pool size=" + Settings.MaxDBConnections + ";enlist=dynamic;"; break; } case Trade.Utility.StockTraderUtility.DAL_DB2: { Settings.TRADEDB_SQL_CONN_STRING = "Network Transport Library=TCPIP;Network Address=" + Settings.DBServer + ";Initial Catalog=" + Settings.Database + ";Package Collection=" + Settings.Database + ";Default Schema=Schema;User ID=" + Settings.UserID + ";Password=" + Settings.Password + ";network port=50000;Units of Work=RUW; Connection Pooling=True;defer prepare=false;CCSID=37;PC Code Page=1252"; break; } } } } }