// // 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 StockTraderuserid Sample WCF Application for Benchmarking, Performance Analysis and Design Considerations for Service-Oriented Applications using System; using System.Collections.Generic; using System.Web; using System.Web.Caching; using System.Web.Security; using Trade.StockTraderWebApplicationSettings; using Trade.StockTraderWebApplicationModelClasses; using Trade.StockTraderWebApplicationServiceClient; namespace Trade.Web { /// /// The info-loaded Home Page. /// public partial class TradeHome : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { decimal gain = (decimal)0.00; decimal percentGain = (decimal)0.00; TotalHoldingsUI totalHoldings; string userid; //Must get/decrypt FormsAuthentication ticket on this page only to get session created date for display. //Would recommend not displaying session create date if really do not need to; depending on //configured Forms authentication protection level, decrypting ticket might be expensive! //We are needing to do here only to maintain same functionality as WebSphere Trade 6.1 //for consistency and comparative benchmarking reasons. If not for this, would simply need to grab userid //(from which all logic/queries in this app are driven off of), from httpcontext. You will note //in other authenticated pages where we do not need to display session created date on the aspx page for the user, //we just get userid from a property on the child ClosedOrders.Ascx control, which has gotten it //from HttpContext.Current.User.Identity.Name. This control is embedded on every authenticated page per //Trade 6.1 design. This also avoids use of server-side Session state object entirely. Its not that this is //much faster than session state, the BIG advantage is that for deploying to web farms/clusters you never //have to worry about using ASP.NET state server or database configuration; it's "cluster-safe/webfarm-ready" //out of the box. HttpCookie authcookie = Request.Cookies[FormsAuthentication.FormsCookieName]; FormsAuthenticationTicket ticket = (FormsAuthenticationTicket)FormsAuthentication.Decrypt(authcookie.Value); userid = ticket.Name; SessionCreateDate.Text = ticket.IssueDate.ToString(); BSLClient businessServicesClient = new BSLClient(); AccountDataUI customer = businessServicesClient.getAccountData(userid); totalHoldings = businessServicesClient.getHoldings(userid); Name.Text = customer.profileID + "!"; AccountID.Text = customer.accountID.ToString(); CreationDate.Text = customer.creationDate.ToString(); LoginCount.Text = customer.loginCount.ToString(); OpenBalance.Text = string.Format("{0:C}", customer.openBalance); Balance.Text = string.Format("{0:C}", customer.balance); NumHoldings.Text = totalHoldings.holdings.Count.ToString(); HoldingsTotal.Text = string.Format("{0:C}", totalHoldings.marketValue); decimal totalcashandholdings = totalHoldings.marketValue + customer.balance; SumOfCashHoldings.Text = string.Format("{0:C}", totalcashandholdings); gain = totalcashandholdings - customer.openBalance; if (customer.openBalance != 0) percentGain = gain / customer.openBalance * 100; else percentGain = 0; if (gain > 0) { Gain.CssClass = Settings.GAINSTYLECSS; PercentGain.CssClass = Settings.GAINSTYLECSS; } else if (gain < 0) { Gain.CssClass = Settings.LOSSSTYLECSS; PercentGain.CssClass = Settings.LOSSSTYLECSS; } Gain.Text = string.Format("{0:C}", gain); PercentGain.Text = string.Format("{0:N}%", percentGain); ; } } }