// .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) { Date.Text = DateTime.Now.ToString("t"); 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; string percentGainString = ""; if (customer.openBalance != 0) percentGain = gain / customer.openBalance * 100; else percentGain = 0; if (gain > 0) { percentGainString = string.Format("{0:N}%" + Settings.UPARROWLINK, percentGain); Gain.ForeColor = System.Drawing.Color.DarkGreen; PercentGain.ForeColor = System.Drawing.Color.DarkGreen; } else if (gain < 0) { percentGainString = string.Format("{0:N}%" + Settings.DOWNARROWLINK, percentGain); Gain.ForeColor = System.Drawing.Color.DarkRed; PercentGain.ForeColor = System.Drawing.Color.DarkRed; } else { percentGainString = string.Format("{0:N}%", percentGain); } Gain.Text = string.Format("{0:C}", gain); PercentGain.Text = percentGainString; } } }