public CCTableModule() : base("/cctable") { this.RequiresAuthentication(); Get["/"] = x => { dynamic vmod = new ExpandoObject(); vmod.list = CCTableRepository.GetAll(); return(View["_page-cctable", vmod]); }; Post["/"] = x => { string tbl = (string)this.Request.Form.Alias; if (tbl != "") { CCTableRepository.CreateTable(tbl); } return(Response.AsRedirect("/cctable")); }; Post["/row"] = x => { string table = (string)this.Request.Form.TableGuid; string tableName = (string)this.Request.Form.TableName; string label = (string)this.Request.Form.Label; string inputType = (string)this.Request.Form.InputType.Value; string inputValue = (string)this.Request.Form.InputLabel; string inputCommand = (string)this.Request.Form.InputCommand; string notes = (string)this.Request.Form.Notes; CCTableRepository.CreateRow(table, tableName, label, inputType, inputValue, inputCommand, notes); string command = this.Request.Form.CCTableCommand; string inputid = "New" + tableName.UppercaseAllFirstLetters().RemoveWhiteSpace() + label.UppercaseAllFirstLetters().RemoveWhiteSpace(); string inputlocation = "CCTable" + this.Request.Form.TableName; CommandDB.Create(inputid, command, command, inputlocation, notes); return(Response.AsRedirect("/cctable")); }; Get["/delete/table/{guid}"] = x => { string guid = x.guid; CCTableRepository.DeleteTable(guid); return(Response.AsJson("CCTable deleted")); }; }
public CcTableModule() { this.RequiresAuthentication(); Get["/cctable/cctable"] = x => { dynamic vmod = new ExpandoObject(); vmod.list = CCTableRepository.GetAll(); return(View["_page-cctable", vmod]); }; Post["/cctable/cctable"] = x => { var tbl = (string)Request.Form.Alias; var context = (string)Request.Form.Context; var tblType = (string)Request.Form.TableType; if (tbl.RemoveWhiteSpace().Length > 0) { CCTableRepository.CreateTable(tbl, tblType, context); } var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable"; return(Response.AsRedirect(redirect)); }; Post["/cctable/row"] = x => { var tableGuid = (string)Request.Form.TableGuid; var tableName = (string)Request.Form.TableName; var label = (string)Request.Form.Label; var inputType = (string)Request.Form.InputType.Value; var inputLabel = (string)Request.Form.InputLabel; var notes = (string)Request.Form.Notes; var osi = (string)Request.Form.FlagOSI.Value; var func = (string)Request.Form.FlagFunction.Value; var vOsi = CCTableRepository.GetOsiLevel(osi); var vFunc = CCTableRepository.GetCommandFunction(func); var inputId = "New" + tableName.UppercaseAllFirstLetters().RemoveWhiteSpace() + label.UppercaseAllFirstLetters().RemoveWhiteSpace(); string inputLocation = "CCTable" + Request.Form.TableName; string command; var commandGet = (string)Request.Form.InputCommand; switch (inputType) { case "hidden": command = Request.Form.CCTableCommandNone; CCTableRepository.CreateRowForDirectCommand(tableGuid, tableName, label, inputLabel, command, notes, vOsi, vFunc, inputId, inputLocation); break; case "text": command = Request.Form.CCTableCommandText; CCTableRepository.CreateRowForTextInputCommand(tableGuid, tableName, label, inputLabel, command, commandGet, notes, vOsi, vFunc, inputId, inputLocation); break; case "checkbox": string commandTrue = Request.Form.CCTableCommandBooleanTrue; string commandFalse = Request.Form.CCTableCommandBooleanFalse; CCTableRepository.CreateRowForBooleanPairCommand(tableGuid, tableName, label, inputLabel, commandTrue, commandFalse, notes, vOsi, vFunc, inputId, inputLocation); break; } var context = (string)Request.Form.Context; var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable"; return(Response.AsRedirect(redirect)); }; Post["/cctable/row/dataview"] = x => { var table = (string)Request.Form.TableGuid; var tableName = (string)Request.Form.TableName; var label = (string)Request.Form.Label; var commandString = (string)Request.Form.Command; var resultString = (string)Request.Form.Result; ConsoleLogger.Log(commandString); if (commandString != "") { var thisResult = resultString == "" ? Terminal.Execute(commandString) : resultString; CCTableRepository.CreateRowDataView(table, tableName, label, commandString, thisResult); } ConsoleLogger.Log(commandString); var context = (string)Request.Form.Context; var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable"; return(Response.AsRedirect(redirect)); }; Post["/cctable/row/mapdata"] = x => { var rowGuid = (string)Request.Form.ItemGuid; var labelArray = (string)Request.Form.MapLabel; var indexArray = (string)Request.Form.MapLabelIndex; CCTableRepository.SaveMapData(rowGuid, labelArray, indexArray); var context = (string)Request.Form.Context; var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable"; return(Response.AsRedirect(redirect)); }; Post["/cctable/row/refresh"] = x => { var guid = (string)Request.Form.Guid; CCTableRepository.Refresh(guid); return(Response.AsJson(true)); }; Get["/cctable/delete/table/{guid}"] = x => { string guid = x.guid; CCTableRepository.DeleteTable(guid); return(Response.AsJson("CCTable deleted")); }; Get["/cctable/delete/row/{guid}"] = x => { string guid = x.guid; CCTableRepository.DeleteTableRow(guid); return(Response.AsJson("CCTable Row deleted")); }; Get["/cctable/edit/row/{guid}/{cmd*}"] = x => { string guid = x.guid; string cmd = x.cmd; CCTableRepository.EditTableRow(guid, cmd); return(Response.AsJson("CCTable Row deleted")); }; Post["/cctable/Launch"] = x => { var commandType = (string)Request.Form.Type; var rowGuid = (string)Request.Form.RowGuid; var newValue = (string)Request.Form.NewValue; var boolSelected = (string)Request.Form.BoolSelected; var row = CCTableRepository.GetRow(rowGuid); switch (commandType) { case "direct": Terminal.Execute(row.CommandDirect); break; case "text": Terminal.Execute(row.CommandSet.Replace("{Value}", newValue)); break; case "bool": if (boolSelected == "true") { Terminal.Execute(row.CommandTrue); } else if (boolSelected == "false") { Terminal.Execute(row.CommandFalse); } else { Terminal.Execute("echo COMMAND NOT FOUND"); } break; } return(Response.AsJson(true)); }; Post["/cctable/row/conf"] = x => { var table = (string)Request.Form.TableGuid; var tableName = (string)Request.Form.TableName; var file = (string)Request.Form.File; var type = file.EndsWith(".conf") ? CCTableFlags.ConfType.File : CCTableFlags.ConfType.Directory; if (file != "") { CCTableRepository.CreateRowConf(table, tableName, file, type); } var context = (string)Request.Form.Context; var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable"; return(Response.AsRedirect(redirect)); }; Get["/cctable/conf/files"] = x => Response.AsJson(CCTableRepository.GetEtcConfs()); Post["/cctable/update/conf"] = x => { var file = (string)Request.Form.FileName; var text = (string)Request.Form.FileText; CCTableRepository.UpdateConfFile(file, text); var context = (string)Request.Form.Context; var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable"; return(Response.AsRedirect(redirect)); }; Post["/cctable/map/conf"] = x => { var guid = Guid.NewGuid().ToString(); var commentInput = ((string)Request.Form.CharComment).ToCharArray(); var comment = commentInput.Length > 0 ? commentInput[0] : ' '; var filePath = (string)Request.Form.FilePath; bool hasInclude = Request.Form.PermitsInclude.HasValue; var include = (string)Request.Form.VerbInclude; bool hasSection = Request.Form.PermitsSection.HasValue; var sectionOpenInput = ((string)Request.Form.CharSectionOpen).ToCharArray(); var sectionOpen = sectionOpenInput.Length > 0 ? sectionOpenInput[0] : ' '; var sectionCloseInput = ((string)Request.Form.CharSectionClose).ToCharArray(); var sectionClose = sectionCloseInput.Length > 0 ? sectionCloseInput[0] : ' '; var dataSeparatorInput = ((string)Request.Form.CharKevValueSeparator).ToCharArray(); var dataSeparator = dataSeparatorInput.Length > 0 ? dataSeparatorInput[0] : ' '; bool hasBlock = Request.Form.PermitsBlock.HasValue; var blockOpenInput = ((string)Request.Form.CharBlockOpen).ToCharArray(); var blockOpen = blockOpenInput.Length > 0 ? blockOpenInput[0] : ' '; var blockCloseInput = ((string)Request.Form.CharBlockClose).ToCharArray(); var blockClose = blockCloseInput.Length > 0 ? blockCloseInput[0] : ' '; var endOfLineInput = ((string)Request.Form.CharEndOfLine).ToCharArray(); var endOfLine = endOfLineInput.Length > 0 ? endOfLineInput[0] : '\n'; CCTableConf.Mapping.Repository.Create(guid, filePath, comment, hasInclude, include, hasSection, sectionOpen, sectionClose, dataSeparator, hasBlock, blockOpen, blockClose, endOfLine); var number = (string)Request.Form.LineNumber; var numbers = number.Split(new[] { "," }, StringSplitOptions.None).ToIntArray(); var type = (string)Request.Form.LineType; var types = type.Split(new[] { "," }, StringSplitOptions.None).ToArray(); //linee e typi dovrebbero essere uguali if (numbers.Length == types.Length) { var l = (numbers.Length + types.Length) / 2; for (var i = 0; i < l; i++) { var ti = CCTableConf.Mapping.Repository.ConvertToDataType(types[i]); CCTableConf.Mapping.Repository.AddLine(guid, numbers[i], ti); } } var context = (string)Request.Form.Context; var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable"; return(Response.AsRedirect(redirect)); }; }