// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to You under the Apache License, Version 2.0 // (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // .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.Collections.Specialized; 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 CS_DOTNET_ENDPOINT_CONFIG_HTTP; 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; public static string BS_LABEL; public static string OPS_LABEL; public static string OPS_USERID; public static string OPS_PASSWORD; public static string OPS_SSL_CERTIFICATE; //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; static Settings() { Settings.CS_DOTNET_ENDPOINT_CONFIG_HTTP = ConfigurationManager.AppSettings.Get("CS_DOTNET_ENDPOINT_CONFIG_HTTP"); 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.BSL_VALID_USERID = ConfigurationManager.AppSettings.Get("BSL_VALID_USERID"); Settings.BSL_VALID_PASSWORD = ConfigurationManager.AppSettings.Get("BSL_VALID_PASSWORD"); Settings.BS_LABEL = ConfigurationManager.AppSettings.Get("BS_LABEL"); Settings.OPS_LABEL = ConfigurationManager.AppSettings.Get("OPS_LABEL"); Settings.OPS_USERID = ConfigurationManager.AppSettings.Get("OPS_USERID"); Settings.OPS_PASSWORD = ConfigurationManager.AppSettings.Get("OPS_PASSWORD"); Settings.OPS_SSL_CERTIFICATE = ConfigurationManager.AppSettings.Get("OPS_SSL_CERTIFICATE"); buildConnString(); setTxModel(); } /// /// 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 static 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; } } } } }