public Programmer(Calc_MainPage mainPage) { this.InitializeComponent(); this.calcStateInternal = Calc_MainPage.programmerCalcState; this._mainPage = mainPage; }
public PortraitScientific(Calc_MainPage mainPage) { this.InitializeComponent(); scientificCalcStateInternal = Calc_MainPage.scientificCalcState; this._mainPage = mainPage; }
public void InitializeWindow(Calc_MainPage page) { this._page = page; isProgrammer = true; _type = Calc_MainPage.CalcStateValues.Dec; }
public Statistical(Calc_MainPage mainPage) { this.InitializeComponent(); this._mainPage = mainPage; _currentStatValues = new List <string>(); }
public TextWindow(TextBlock window, bool isMainWindow, Calc_MainPage mainPage) { _window = window; _inputSequence = new List <InputValue>(); _clearOnNextUse = true; _isMainWindow = isMainWindow; _mainPage = mainPage; }
/// <summary> /// Saves data into the Windows.Storage.ApplicaitonDataContainer object with the App.Apps enum /// as the key. Note: this will fail if the state to be saved is larger than 8k /// </summary> /// <param name="app">The calling app's identity</param> /// <param name="key">A unique key for the type of memory being saved, handy if the app saves more than one type of state</param> /// <param name="value">The object which represents the state to be serialized and saved into roaming state</param> /// <returns>True if the save was successfull, false otherwise</returns> public static bool SaveRoamingState(App.Apps app, string key, object value) { // Because there are many "calc" views but we want the memory to be preserved in between // all of the views if (Calc_MainPage.IsCalculator(app)) { app = App.Apps.Calculator; } try { Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings; string serialized = string.Empty; List <object> memoryItemsObj = new List <object>(); // Calc specific if (value is ObservableCollection <Calculator.MemoryItem> ) { foreach (Calculator.MemoryItem memItem in value as ObservableCollection <Calculator.MemoryItem> ) { memoryItemsObj.Add(memItem as object); } } else if (value is List <PCalender.Period> ) { foreach (PCalender.Period period in value as List <PCalender.Period> ) { memoryItemsObj.Add(period as object); } } // TODO other apps serialized = JSONCode.JSON.JsonEncode(memoryItemsObj); // add the value into the roaming state array if (roamingSettings.Values.ContainsKey(app.ToString() + key)) { roamingSettings.Values[app.ToString() + key] = serialized; } else { roamingSettings.Values.Add(app.ToString() + key, serialized); } } catch { return(false); } return(true); }
/// <summary> /// Converts the object into a List<MemoryItem>. /// </summary> /// <param name="obj">Expects this object to be the following List<object> where each object /// is a List<object> where each sub-object is Key,Value pair of Text, Value, Type</param> /// <param name="success"></param> /// <returns></returns> private static object ConvertToCalc(object obj, ref bool success, Calc_MainPage page) { success = false; // if there's no valid page to link to if (page == null) { return(null); } List <Calculator.MemoryItem> returnList = new List <MemoryItem>(); try { List <object> firstList = obj as List <object>; foreach (object val in firstList) { Dictionary <string, object> dict = val as Dictionary <string, object>; // create a new item MemoryItem mi = new MemoryItem(); mi.InitializeWindow(page); mi.Text = dict[CalcState.Text.ToString()] as string; // the first part is the value mi.Value = (dict[CalcState.Value.ToString()] as string); mi.Type = (Calc_MainPage.CalcStateValues) int.Parse(dict[CalcState.Type.ToString()].ToString()); returnList.Add(mi); } success = true; } catch { return(null); } return(returnList); }
/// <summary> /// Evaluates the given list of tokens and returns the result. /// Tokens must appear in postfix order. /// </summary> /// <param name="tokens">List of tokens to evaluate.</param> /// <returns></returns> protected double ExecuteTokens(List <string> tokens) { Stack <double> stack = new Stack <double>(); double tmp, tmp2; foreach (string token in tokens) { // Is this a value token? double tokenValue = 0; if (double.TryParse(token, out tokenValue)) { stack.Push(tokenValue); } else if (token == "+") { stack.Push(stack.Pop() + stack.Pop()); } else if (token == "-") { tmp = stack.Pop(); tmp2 = stack.Pop(); stack.Push(tmp2 - tmp); } else if (token == "×" || token == "*") { stack.Push(stack.Pop() * stack.Pop()); } else if (token == "÷" || token == "/") { tmp = stack.Pop(); tmp2 = stack.Pop(); stack.Push(tmp2 / tmp); } else if (token == "^") { tmp = stack.Pop(); tmp2 = stack.Pop(); stack.Push(Math.Pow(tmp2, tmp)); } else if (token == UnaryMinus) { double value = stack.Pop(); if (value > 0) { stack.Push(-value); } } // Logical // AND else if (token == "&") { stack.Push(((long)stack.Pop()) & ((long)stack.Pop())); } // OR else if (token == "|") { stack.Push(((long)stack.Pop()) | ((long)stack.Pop())); } // XOR else if (token == "⊕") { stack.Push(((long)stack.Pop()) ^ ((long)stack.Pop())); } // RIGHT SHIFT else if (token == "<") { tmp = stack.Pop(); tmp2 = stack.Pop(); stack.Push(((long)tmp2) << ((int)tmp)); } // LEFT SHIFT else if (token == ">") { tmp = stack.Pop(); tmp2 = stack.Pop(); stack.Push(((long)tmp2) >> ((int)tmp)); } // LEFT SHIFT else if (token == "%") { tmp = stack.Pop(); tmp2 = stack.Pop(); stack.Push((long)tmp2 % (int)tmp); } //Statistical else if (token == "P") { tmp = stack.Pop(); tmp2 = stack.Pop(); // n! / (n-k)! double val = double.Parse(Calc_MainPage.factorial(tmp2)) / double.Parse(Calc_MainPage.factorial(tmp2 - tmp)); stack.Push(val); } else if (token == "C") { tmp = stack.Pop(); tmp2 = stack.Pop(); // n! / (k! * (n-k)!) double val = double.Parse(Calc_MainPage.factorial(tmp2)) / (double.Parse(Calc_MainPage.factorial(tmp2 - tmp)) * double.Parse(Calc_MainPage.factorial(tmp))); stack.Push(val); } } // Remaining item on stack contains result return((stack.Count > 0) ? stack.Pop() : 0.0); }
public Snapped(Calc_MainPage mainPage) { this.InitializeComponent(); this._mainPage = mainPage; }
public Portrait(Calc_MainPage mainPage) { this.InitializeComponent(); this._mainPage = mainPage; }
/// <summary> /// Deserializes the input string into a c# generic object /// </summary> /// <param name="app">The calling app's identity</param> /// <param name="success">True if the clear was successfull, false otherwise</param> /// <returns>The deserialized generic object. If the method fails the return is null</returns> public static object LoadRoamingState(App.Apps app, string key, ref bool success, Calc_MainPage page = null) { success = false; try { Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings; string serialized = roamingSettings.Values[app.ToString() + key] as string; if (serialized.StartsWith("{") || serialized.StartsWith("[")) { object obj = JSONCode.JSON.JsonDecode(serialized, ref success); // Calculator specific if (app == App.Apps.Calculator) { return(ConvertToCalc(obj, ref success, page)); } // PCalendar specific else if (app == App.Apps.PCalendar) { return(ConvertToPCal(obj, ref success)); } // TODO other apps } else { return(serialized); } } catch { return(null); } return(null); }