/// <summary> /// Create and save a matrix from given special class with given arguments and name /// </summary> public async Task OnPostAddMatrixSpecial() { if (_frontService.CheckCmdDate(HttpContext.Session.Get <DateTime>(SessionLastCommandDate))) { DateTime LastCmdDate = DateTime.Now; Dictionary <string, string> reqdict = new Dictionary <string, string>(); await _utils.ReadAndDecodeRequest(Request.Body, Encoding.Default, IgnoredParams, reqdict); if (reqdict.ContainsKey(MatrisNameParam) && reqdict.ContainsKey(MatrisSpecialFuncParam) && reqdict.ContainsKey(MatrisSpecialArgsParam)) { Dictionary <string, MatrisBase <dynamic> > _dict = HttpContext.Session.GetMatrixDict(SessionMatrisDict, SessionSeedDict); if (_dict.ContainsKey(reqdict[MatrisNameParam])) { HttpContext.Session.Set(SessionLastCommandDate, LastCmdDate); using CommandMessage msg = new CommandMessage(CompilerMessage.MAT_NAME_ALREADY_EXISTS(reqdict[MatrisNameParam]), CommandState.WARNING); HttpContext.Session.SetLastMsg( SessionLastMessage, msg ); return; } else if (HttpContext.Session.GetDfSettings(SessionDfSettings).ContainsKey(reqdict[MatrisNameParam])) { HttpContext.Session.Set(SessionLastCommandDate, LastCmdDate); using CommandMessage msg = new CommandMessage(CompilerMessage.DF_NAME_ALREADY_EXISTS(reqdict[MatrisNameParam]), CommandState.WARNING); HttpContext.Session.SetLastMsg( SessionLastMessage, msg ); return; } string actualFuncName = reqdict[MatrisSpecialFuncParam][1..reqdict[MatrisSpecialFuncParam].IndexOf("(", StringComparison.CurrentCulture)];
/// <summary> /// Create and save a dataframe with given name and values from text /// </summary> public async Task OnPostAddDataframe() { if (_frontService.CheckCmdDate(HttpContext.Session.Get <DateTime>(SessionLastCommandDate))) { DateTime LastCmdDate = DateTime.Now; Dictionary <string, string> reqdict = new Dictionary <string, string>(); await _utils.ReadAndDecodeRequest(Request.Body, Encoding.Default, IgnoredParams, reqdict); if (reqdict.ContainsKey(DfNameParam) && reqdict.ContainsKey(DfValsParam) && reqdict.ContainsKey(DfDelimParam) && reqdict.ContainsKey(DfNewLineParam) ) { Dictionary <string, Dataframe> _dict = HttpContext.Session.GetDfDict(SessionDfDict, SessionDfLabels, SessionDfSettings); if (!HttpContext.Session.GetMatrixDict(SessionMatrisDict, SessionSeedDict).ContainsKey(reqdict[DfNameParam])) { if (!_dict.ContainsKey(reqdict[DfNameParam])) { try { Validations.ValidMatrixName(reqdict[DfNameParam], throwOnBadName: true); reqdict[DfDelimParam] = _utils.FixLiterals(reqdict[DfDelimParam]); reqdict[DfNewLineParam] = _utils.FixLiterals(reqdict[DfNewLineParam]); reqdict[DfValsParam] = _utils.FixLiterals(reqdict[DfValsParam]); List <string> optlist = _utils.GetOptionList(reqdict); using Dataframe df = new Dataframe ( _utils.StringTo2DList ( reqdict[DfValsParam], reqdict[DfDelimParam], reqdict[DfNewLineParam], true, (int)DataframeLimits.forRows, (int)DataframeLimits.forCols, true, optlist ), optlist ); _frontService.AddToDfDict ( reqdict[DfNameParam], df, _dict ); Dictionary <string, List <List <object> > > vals = HttpContext.Session.GetMatVals(SessionDfDict, true); Dictionary <string, Dictionary <string, dynamic> > settings = HttpContext.Session.GetDfSettings(SessionDfSettings); Dictionary <string, Dictionary <string, List <LabelList> > > labels = HttpContext.Session.GetDfLabels(SessionDfLabels); _frontService.SetDfDicts(_dict, vals, labels, settings); HttpContext.Session.Set(SessionDfDict, vals); HttpContext.Session.SetDfLabels(SessionDfLabels, labels); HttpContext.Session.SetDfSettings(SessionDfSettings, settings); using CommandMessage msg = new CommandMessage(CompilerMessage.SAVED_DF(reqdict[DfNameParam]), CommandState.SUCCESS); HttpContext.Session.SetLastMsg( SessionLastMessage, msg ); _utils.DisposeDfDicts(null, labels); vals.Clear(); labels.Clear(); settings.Clear(); } catch (Exception err) { using CommandMessage msg = err.InnerException != null ? new CommandMessage(err.InnerException.Message, CommandState.ERROR) : new CommandMessage(err.Message, CommandState.ERROR); HttpContext.Session.SetLastMsg( SessionLastMessage, msg ); } } else { using CommandMessage msg = new CommandMessage(CompilerMessage.DF_NAME_ALREADY_EXISTS(reqdict[DfNameParam]), CommandState.WARNING); HttpContext.Session.SetLastMsg( SessionLastMessage, msg ); } } else { using CommandMessage msg = new CommandMessage(CompilerMessage.MAT_NAME_ALREADY_EXISTS(reqdict[DfNameParam]), CommandState.WARNING); HttpContext.Session.SetLastMsg( SessionLastMessage, msg ); } _utils.DisposeDfDicts(_dict, null); _dict.Clear(); } else { using CommandMessage msg = new CommandMessage(RequestMessage.REQUEST_MISSING_KEYS("AddDataframe", new string[2] { DfNameParam, DfValsParam }), CommandState.ERROR); HttpContext.Session.SetLastMsg( SessionLastMessage, msg ); } HttpContext.Session.Set(SessionLastCommandDate, LastCmdDate); } else { using CommandMessage msg = new CommandMessage(RequestMessage.REQUEST_SPAM(HttpContext.Session.Get <DateTime>(SessionLastCommandDate)), CommandState.WARNING); HttpContext.Session.SetLastMsg( SessionLastMessage, msg ); } }
/// <summary> /// Create and save a matrix with given name and values from text /// </summary> public async Task OnPostAddMatrix() { if (_frontService.CheckCmdDate(HttpContext.Session.Get <DateTime>(SessionLastCommandDate))) { DateTime LastCmdDate = DateTime.Now; Dictionary <string, string> reqdict = new Dictionary <string, string>(); await _utils.ReadAndDecodeRequest(Request.Body, Encoding.Default, IgnoredParams, reqdict); if (reqdict.ContainsKey(MatrisNameParam) && reqdict.ContainsKey(MatrisValsParam) && reqdict.ContainsKey(MatrisDelimParam) && reqdict.ContainsKey(MatrisNewLineParam) ) { Dictionary <string, MatrisBase <dynamic> > _dict = HttpContext.Session.GetMatrixDict(SessionMatrisDict, SessionSeedDict); if (!HttpContext.Session.GetDfSettings(SessionDfSettings).ContainsKey(reqdict[MatrisNameParam])) { if (!_dict.ContainsKey(reqdict[MatrisNameParam])) { try { Validations.ValidMatrixName(reqdict[MatrisNameParam], throwOnBadName: true); Dictionary <string, List <List <object> > > vals = HttpContext.Session.GetMatVals(SessionMatrisDict) ?? new Dictionary <string, List <List <object> > >(); Dictionary <string, Dictionary <string, dynamic> > opts = HttpContext.Session.GetMatOptions(SessionSeedDict) ?? new Dictionary <string, Dictionary <string, dynamic> >(); reqdict[MatrisDelimParam] = _utils.FixLiterals(reqdict[MatrisDelimParam]); reqdict[MatrisNewLineParam] = _utils.FixLiterals(reqdict[MatrisNewLineParam]); reqdict[MatrisValsParam] = _utils.FixLiterals(reqdict[MatrisValsParam]); using MatrisBase <dynamic> mat = new MatrisBase <dynamic> ( _utils.StringTo2DList ( reqdict[MatrisValsParam], reqdict[MatrisDelimParam], reqdict[MatrisNewLineParam], nullfiller: typeof(float) ) ); _frontService.AddToMatrisDict ( reqdict[MatrisNameParam], mat, _dict ); _frontService.SetMatrixDicts(_dict, vals, opts); HttpContext.Session.Set(SessionMatrisDict, vals); HttpContext.Session.SetMatOptions(SessionSeedDict, opts); using CommandMessage msg = new CommandMessage(CompilerMessage.SAVED_MATRIX(reqdict[MatrisNameParam]), CommandState.SUCCESS); HttpContext.Session.SetLastMsg( SessionLastMessage, msg ); vals.Clear(); opts.Clear(); } catch (Exception err) { using CommandMessage msg = err.InnerException != null ? new CommandMessage(err.InnerException.Message, CommandState.ERROR) : new CommandMessage(err.Message, CommandState.ERROR); HttpContext.Session.SetLastMsg( SessionLastMessage, msg ); } } else { using CommandMessage msg = new CommandMessage(CompilerMessage.MAT_NAME_ALREADY_EXISTS(reqdict[MatrisNameParam]), CommandState.WARNING); HttpContext.Session.SetLastMsg( SessionLastMessage, msg ); } } else { using CommandMessage msg = new CommandMessage(CompilerMessage.DF_NAME_ALREADY_EXISTS(reqdict[MatrisNameParam]), CommandState.WARNING); HttpContext.Session.SetLastMsg( SessionLastMessage, msg ); } _dict.Clear(); } else { using CommandMessage msg = new CommandMessage(RequestMessage.REQUEST_MISSING_KEYS("AddMatrix", new string[2] { MatrisNameParam, MatrisValsParam }), CommandState.ERROR); HttpContext.Session.SetLastMsg( SessionLastMessage, msg ); } HttpContext.Session.Set(SessionLastCommandDate, LastCmdDate); } else { using CommandMessage msg = new CommandMessage(RequestMessage.REQUEST_SPAM(HttpContext.Session.Get <DateTime>(SessionLastCommandDate)), CommandState.WARNING); HttpContext.Session.SetLastMsg( SessionLastMessage, msg ); } }