You are viewing a plain text version of this content. The canonical link for it is here.
Posted to stonehenge-commits@incubator.apache.org by be...@apache.org on 2009/11/11 03:14:24 UTC

svn commit: r834749 - in /incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade: ./ Controls/ Images/Config/

Author: bendewey
Date: Wed Nov 11 03:14:24 2009
New Revision: 834749

URL: http://svn.apache.org/viewvc?rev=834749&view=rev
Log:
STONEHENGE-78, Thanks Nick

Added:
    incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Controls/ConfigurationDisplay.ascx
    incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Controls/ConfigurationDisplay.ascx.cs
    incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Images/Config/
    incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Images/Config/DOTNET.png   (with props)
    incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Images/Config/METRO.gif   (with props)
Modified:
    incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Configuration.aspx.cs
    incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Site.master

Modified: incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Configuration.aspx.cs
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Configuration.aspx.cs?rev=834749&r1=834748&r2=834749&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Configuration.aspx.cs (original)
+++ incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Configuration.aspx.cs Wed Nov 11 03:14:24 2009
@@ -21,6 +21,7 @@
 using Trade.ConfigClient;
 using Trade.ConfigServiceDataContract;
 using Trade.StockTraderWebApplicationSettings;
+using System.Web;
 
 namespace Trade.Web
 {
@@ -79,6 +80,9 @@
             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
@@ -91,11 +95,17 @@
                 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;

Added: incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Controls/ConfigurationDisplay.ascx
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Controls/ConfigurationDisplay.ascx?rev=834749&view=auto
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Controls/ConfigurationDisplay.ascx (added)
+++ incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Controls/ConfigurationDisplay.ascx Wed Nov 11 03:14:24 2009
@@ -0,0 +1,25 @@
+<%@ Control
+    Language="C#"
+    AutoEventWireup="true"
+    CodeFile="ConfigurationDisplay.ascx.cs"
+    Inherits="Trade.Web.ConfigurationDisplay" %>
+<%@ OutputCache Shared="true" Duration="300" VaryByParam="none" %>
+<% /* 
+ 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.
+*/
+%>
+Business Service <asp:Image ID="businessServiceImage" runat="server" /><asp:Label ID="businessServiceLabel" runat="server"></asp:Label><br />
+Order Processing Service <asp:Image ID="orderProcessingServiceImage" runat="server" /><asp:Label ID="orderProcessingServiceLabel" runat="server"></asp:Label><br />

Added: incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Controls/ConfigurationDisplay.ascx.cs
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Controls/ConfigurationDisplay.ascx.cs?rev=834749&view=auto
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Controls/ConfigurationDisplay.ascx.cs (added)
+++ incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Controls/ConfigurationDisplay.ascx.cs Wed Nov 11 03:14:24 2009
@@ -0,0 +1,284 @@
+//
+// 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
+
+using System;
+using System.Web;
+using System.Web.UI;
+using System.Web.UI.HtmlControls;
+using System.Web.UI.WebControls;
+using System.Web.UI.WebControls.WebParts;
+using Trade.ConfigClient;
+using Trade.ConfigServiceDataContract;
+using Trade.ConfigServiceConfigurationSettings;
+using System.Collections.Generic;
+using System.IO;
+using System.Web.Caching;
+
+namespace Trade.Web
+{
+
+    public partial class ConfigurationDisplay : System.Web.UI.UserControl
+    {
+
+        private const string BsNameCacheKey = "BSNAME";
+        private const string BsImageCacheKey = "BSIMAGE";
+        private const string OpsNameCacheKey = "OPSNAME";
+        private const string OpsImageCacheKey = "OPSIMAGE";
+        
+        private static string ImagesDir = string.Format("Images{0}Config{0}", Path.DirectorySeparatorChar);
+        private static string ImagesVirtualDir = "~/Images/Config/";
+        private static string[] ImageExtensions = new string[] { ".gif", ".png", ".jpg" };
+
+        /// <summary>
+        /// Gets or sets the name of the business service endpoint currently in use.
+        /// </summary>
+        public string BsName {
+            get
+            {
+                object o = HttpRuntime.Cache[BsNameCacheKey];
+                return (o == null) ? string.Empty : o as string;
+            }
+            set
+            {
+                HttpRuntime.Cache.Insert(BsNameCacheKey, value);
+            }
+        }
+
+        /// <summary>
+        /// Gets or sets the name of the order processing service endpoint currently in use.
+        /// </summary>
+        public string OpsName
+        {
+            get
+            {
+                object o = HttpRuntime.Cache[OpsNameCacheKey];
+                return (o == null) ? string.Empty : o as string;
+            }
+            set
+            {
+                HttpRuntime.Cache.Insert(OpsNameCacheKey, value);
+            }
+        }
+
+        /// <summary>
+        /// Gets or sets the path to a representative image for the Business Service
+        /// </summary>
+        public string BsImagePath
+        {
+            get
+            {
+                
+                object o = HttpRuntime.Cache[BsImageCacheKey];
+
+                // Image path in cache, return path
+                if (o != null) return o as string;
+
+                // Image path not in cache, determine image path
+                string bsName = BsName;
+
+                if (string.IsNullOrEmpty(bsName))
+                {
+                    loadCurrentSettings();
+                    bsName = BsName;
+                }
+
+                string result = buildImagePath(bsName);
+
+                // Cache result
+                BsImagePath = result;
+
+                return result;
+
+            }
+            set
+            {
+
+                // Cache the image path for 5 minutes beyond last access,
+                // invalidated by change in business service name
+                HttpRuntime.Cache.Insert(BsImageCacheKey, value,
+                    new System.Web.Caching.CacheDependency(null, new string[] { BsNameCacheKey }),
+                    System.Web.Caching.Cache.NoAbsoluteExpiration,
+                    new TimeSpan(0, 5, 0));
+                        
+            }
+        }
+
+        /// <summary>
+        /// Gets or sets the path to a representative image for the Order Processing Service
+        /// </summary>
+        public string OpsImagePath
+        {
+            get
+            {
+
+                object o = HttpRuntime.Cache[OpsImageCacheKey];
+
+                // Image path in cache, return path
+                if (o != null) return o as string;
+
+                // Image path not in cache, determine image path
+                string opsName = OpsName;
+
+                if (string.IsNullOrEmpty(opsName))
+                {
+                    loadCurrentSettings();
+                    opsName = OpsName;
+                }
+
+                string result = buildImagePath(opsName);
+
+                // Cache result
+                OpsImagePath = result;
+
+                return result;
+
+            }
+            set
+            {
+
+                // Cache the image path for 5 minutes beyond last access,
+                // invalidated by change in business service name
+                HttpRuntime.Cache.Insert(OpsImageCacheKey, value,
+                    new System.Web.Caching.CacheDependency(null, new string[] { OpsNameCacheKey }),
+                    System.Web.Caching.Cache.NoAbsoluteExpiration,
+                    new TimeSpan(0, 5, 0));
+
+            }
+        }
+
+        protected void Page_Load(object sender, EventArgs e)
+        {
+            
+            this.CachePolicy.Dependency = new CacheDependency(null, new string[] {
+                BsNameCacheKey, OpsNameCacheKey });
+
+            if (this.BsImagePath != string.Empty)
+            {
+                businessServiceImage.Visible = true;
+                businessServiceImage.ImageUrl = this.BsImagePath;
+                businessServiceLabel.Visible = false;
+            }
+            else
+            {
+                businessServiceLabel.Visible = true;
+                businessServiceLabel.Text = this.BsName;
+                businessServiceImage.Visible = false;
+            }
+
+            if (this.OpsImagePath != string.Empty)
+            {
+                orderProcessingServiceImage.Visible = true;
+                orderProcessingServiceImage.ImageUrl = this.OpsImagePath;
+                orderProcessingServiceLabel.Visible = false;
+            }
+            else
+            {
+                orderProcessingServiceLabel.Visible = true;
+                orderProcessingServiceLabel.Text = this.OpsName;
+                orderProcessingServiceImage.Visible = false;
+            }
+        
+        }
+
+        /// <summary>
+        /// Builds a path to an image representing a service
+        /// </summary>
+        /// <param name="serviceName">Name of the service for which to generate an image path</param>
+        /// <returns>A string representation of a URI pointing to an image, or empty if no
+        /// image is available</returns>
+        /// <remarks>
+        /// <para>
+        /// This method searches the images directory for an appropriate image to display
+        /// for the service name passed. Service names typically are in the format of "PLATFORM_SERVICE".
+        /// In the case that they are in this format, this method will search the image directory for
+        /// files named "PLATFORM.extension", where extension could be any extension in a hardcoded
+        /// list of extensions for image files. In the case that the service name is in any other format,
+        /// this method will simply search for files named "SERVICENAME", where service name is the service
+        /// name passed.
+        /// </para>
+        /// <para>
+        /// In the case that no suitable image can be found, an empty string is returned. In the case of
+        /// an empty string (indicating an absense of an image), the UI will simply display the moniker
+        /// associated with the current service implementation.
+        /// </para>
+        /// <para>
+        /// Portability note: This method does not do a case-insensitive search of the file system.
+        /// </para>
+        /// </remarks>
+        private string buildImagePath(string serviceName)
+        {
+
+            // Locate the absolute path for the images directory
+            string imagesAbsoluteDir = Path.Combine(Request.PhysicalApplicationPath,
+                                                        ConfigurationDisplay.ImagesDir);
+
+            if (!Directory.Exists(imagesAbsoluteDir))
+            {
+                return string.Empty; // Image url could not be created because image does not exist
+            }
+
+            // Determine the file name for which to look
+            string fileName = serviceName;
+            
+            if (serviceName.Contains("_") && serviceName[0] != '_')
+            {
+                fileName = serviceName.Split('_')[0];
+            }
+
+            // Iterate through possible extensions, looking for valid images
+            foreach (string ext in ConfigurationDisplay.ImageExtensions)
+            {
+
+                string currentFile = fileName + ext;
+                
+                if (File.Exists(Path.Combine(imagesAbsoluteDir, currentFile)))
+                    return string.Format("{0}{1}",
+                                ConfigurationDisplay.ImagesVirtualDir,
+                                currentFile);
+
+            }
+
+            return string.Empty;
+
+        }
+
+        /// <summary>
+        /// Loads the current configuration from the configuration service
+        /// </summary>
+        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 = "DOTNET_CLIENT";
+
+            BsName = configClient.GetClientConfig(existingClientConfig).BSName;
+
+            BSConfigRequest existingBsConfig = new BSConfigRequest();
+            existingBsConfig.BSName = BsName;
+                        
+            OpsName = configClient.GetBSConfig(existingBsConfig).OPSName;
+
+        }
+    }
+
+}

Added: incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Images/Config/DOTNET.png
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Images/Config/DOTNET.png?rev=834749&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Images/Config/DOTNET.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Images/Config/METRO.gif
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Images/Config/METRO.gif?rev=834749&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Images/Config/METRO.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Site.master
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Site.master?rev=834749&r1=834748&r2=834749&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Site.master (original)
+++ incubator/stonehenge/trunk/stocktrader/dotnet/trader_client/Trade/Site.master Wed Nov 11 03:14:24 2009
@@ -1,5 +1,6 @@
 <%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="Site" %>
 <%@ Register assembly="Microsoft.IdentityModel, Version=0.6.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="Microsoft.IdentityModel.Web.Controls" tagprefix="idfx" %>
+<%@ Register TagPrefix="controls" TagName="ConfigurationDisplay" Src="~/Controls/ConfigurationDisplay.ascx" %>
 <% /* 
  
  Licensed to the Apache Software Foundation (ASF) under one or more
@@ -73,7 +74,10 @@
         <div id="footer">
             <div style="float: right;">
                 Powered by <a href="http://www.microsoft.com/net/">
-                    <img align="top" src="images/powered-by-logo.png" alt="Powered by Microsoft .NET" style="margin-top: -3px; margin-right: 5px;" /></a></div>
+                    <img align="top" src="images/powered-by-logo.png" alt="Powered by Microsoft .NET" style="margin-top: -3px; margin-right: 5px;" /></a>
+                    <br />
+                    <controls:ConfigurationDisplay runat="server" ID="configurationDisplay" />
+                    </div>
         </div>
     </div>
 </form>