//
// 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 Service Configuration V2.0 for Design Considerations for Service-Oriented Applications based on Windows Communication Foundation. Created with Microsoft .NET Framework 3.5 and Microsoft Visual Studio. Copyright 2008, Microsoft Corporation.
using System;
using Trade.ConfigClient;
using Trade.ConfigServiceDataContract;
using Trade.StockTraderWebApplicationSettings;
using System.Web;
namespace Trade.Web
{
public partial class Configuration : System.Web.UI.Page
{
public void Page_Init(object sender, EventArgs e)
{
LoadDropDownList();
}
public void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LoadCurrentSettings();
}
}
///
/// Loads the dropdown lists with the business services and order processing services
/// If this method isn't called as PostBack, the default value will be set to current config
///
private void LoadDropDownList()
{
ConfigServiceClient configClient = new ConfigServiceClient();
//Populate the dropdown lists
BsName.DataSource = configClient.GetBSLocations();
BsName.DataTextField = "ServiceName";
BsName.DataValueField = "ServiceName";
BsName.DataBind();
OpsName.DataSource = configClient.GetOPSLocations();
OpsName.DataTextField = "ServiceName";
OpsName.DataValueField = "ServiceName";
OpsName.DataBind();
}
///
/// Sets the BS and OPS dropdowns to the current values from the configuration service
///
private void LoadCurrentSettings()
{
ConfigServiceClient configClient = new ConfigServiceClient();
//Select the current configuration settings as the default values in the dropdown list
ClientConfigRequest existingClientConfig = new ClientConfigRequest();
existingClientConfig.ClientName = Settings.CLIENT_LABEL;
BsName.SelectedValue = configClient.GetClientConfig(existingClientConfig).BSName;
BSConfigRequest existingBsConfig = new BSConfigRequest();
existingBsConfig.BSName = BsName.SelectedValue;
OpsName.SelectedValue = configClient.GetBSConfig(existingBsConfig).OPSName;
}
private const string BsNameCacheKey = "BSNAME";
private const string OpsNameCacheKey = "OPSNAME";
protected void SetButton_Click(object sender, EventArgs e)
{
try
{
ConfigServiceClient configClient = new ConfigServiceClient();
// Update Client -> BS
ClientToBS clientRequest = new ClientToBS();
clientRequest.Client = Settings.CLIENT_LABEL;
clientRequest.Bs = this.BsName.SelectedItem.Value;
configClient.SetClientToBS(clientRequest);
if (HttpRuntime.Cache[BsNameCacheKey] != null) HttpRuntime.Cache.Remove(BsNameCacheKey);
HttpRuntime.Cache.Insert(BsNameCacheKey, clientRequest.Bs);
// Update BS -> OPS
BSToOPS bsRequest = new BSToOPS();
bsRequest.Bs = this.BsName.SelectedItem.Value;
bsRequest.Ops = this.OpsName.SelectedItem.Value;
configClient.SetBSToOPS(bsRequest);
if (HttpRuntime.Cache[OpsNameCacheKey] != null) HttpRuntime.Cache.Remove(OpsNameCacheKey);
HttpRuntime.Cache.Insert(OpsNameCacheKey, bsRequest.Ops);
ConfirmationText.Text = ("Configuration successfully changed to: "+Settings.CLIENT_LABEL+" -> " + clientRequest.Bs + " -> " + bsRequest.Ops);
ConfirmationText.ForeColor = System.Drawing.Color.Green;
ConfirmationText.Visible = true;
}
catch
{
ConfirmationText.Text = ("Unsuccessful Configuration");
ConfirmationText.ForeColor = System.Drawing.Color.Red;
ConfirmationText.Visible = true;
throw;
}
}
protected void RestoreDefaults_Click(object sender, EventArgs e)
{
BsName.SelectedValue = Settings.BS_LABEL;
OpsName.SelectedValue = Settings.OPS_LABEL;
}
protected void AdvancedConfig_Click(object sender, EventArgs e)
{
Response.Redirect(Settings.PAGE_CONFIGURATION_ADVANCED, true);
}
}
}