//We use this function to return either int 1 or 2 per session. The effect is to make the //product list random w.r.t. this session only and prevent having too much product variety in the NPC cart. private static int GetCountdownRandomizerValue(this HttpSessionStateBase session) { //returns 1 or 2 randomly based on the session countdown start time. int milliseconds = session.GetDataFromSession <DateTime>("countdownTimeCsKey").Millisecond; return(new System.Random(milliseconds).Next(0, 2) + 1); }
//if countdown already started, return this value. Otherwise return int.Minvalue. public static int GetRemainingTime(this HttpSessionStateBase session) { int remainingMilliseconds; // countdown time variable DateTime countdownTime = session.GetDataFromSession <DateTime>("countdownTimeCsKey"); if (countdownTime == DateTime.MinValue) { remainingMilliseconds = int.MinValue; } else { TimeSpan tsRemaining = countdownTime - DateTime.Now; remainingMilliseconds = (int)tsRemaining.TotalMilliseconds; //convert to integer for passing to view. remainingMilliseconds = Math.Max(remainingMilliseconds, -1); //if time expired just return -1. } return(remainingMilliseconds); }
//return countdown value, but also accounting for the allowed connection delay at checkout. If not extant, return int.Minvalue. public static int GetRemainingTimeAtCheckout(this HttpSessionStateBase session) { int remainingMilliseconds; // countdown time variable DateTime countdownTime = session.GetDataFromSession <DateTime>("countdownTimeCsKey"); if (countdownTime == DateTime.MinValue) { remainingMilliseconds = int.MinValue; } else { TimeSpan tsRemaining = countdownTime - DateTime.Now; remainingMilliseconds = (int)tsRemaining.TotalMilliseconds; //convert to integer remainingMilliseconds += checkoutConnToleranceMilliseconds; //any expired time value may be within the allowed tolerance, which we can add as an increment. remainingMilliseconds = Math.Max(remainingMilliseconds, -1); //if time expired just return -1. } return(remainingMilliseconds); }
//if countdown already started, return the remaining time. Otherwise return a start-time value. public static int GetRemainingTimeOrSetDefault(this HttpSessionStateBase session) { int remainingMilliseconds; // countdown time variable DateTime countdownTime = session.GetDataFromSession <DateTime>("countdownTimeCsKey"); if (countdownTime == DateTime.MinValue) { //set a new countdown time using a global constant. session.SetDataToSession <string>("countdownTimeCsKey", DateTime.Now.AddMilliseconds(shoppingTimeMilliseconds)); remainingMilliseconds = shoppingTimeMilliseconds; } else { TimeSpan tsRemaining = countdownTime - DateTime.Now; remainingMilliseconds = (int)tsRemaining.TotalMilliseconds; //convert to integer for passing to view. remainingMilliseconds = Math.Max(remainingMilliseconds, -1); //if time expired just return -1. } return(remainingMilliseconds); }
public static bool GetGameInProgress(this HttpSessionStateBase session) { return(session.GetDataFromSession <bool>("gameInProgress")); }
//flag to prevent user from navigating back to checkout screen using browser navigation after starting a new game. public static bool GetUserJustClickedCheckout(this HttpSessionStateBase session) { return(session.GetDataFromSession <bool>("userClickedCheckout")); }
public static int GetLastItemAddedByNpcPlayer(this HttpSessionStateBase session) { return(session.GetDataFromSession <int>("lastItemAdded")); }
public static bool GetShoppingByNpcCompleted(this HttpSessionStateBase session) { return(session.GetDataFromSession <bool>("shoppingCompleted")); }