public JsonResult ExecuteCommand(Command command) { string fileNameFullPath, fileContents, newfileContents, searchTerm = "", newTerm = "", message, errorMessage; int startIndexSearchTerm, index; PageEntity pageEntity; try { if ((command.Cmd == "menu") || (command.Cmd == "sub1") || (command.Cmd == "sub2")) { fileNameFullPath = string.Format("C:\\git_cjonasl\\Leander\\Solutions\\Nr1\\WebApplication1\\Views\\Main\\_Layout{0}.cshtml", command.Page.ToString()); fileContents = Utility.ReturnFileContents(fileNameFullPath, out errorMessage); if (errorMessage != null) { return(Json(string.Format("ERROR!!\r\n{0}", errorMessage), JsonRequestBehavior.AllowGet)); } switch (command.Cmd) { case "menu": searchTerm = string.Format("<span class='title' data-location='Menu{0}'>", command.Menu.ToString()); break; case "sub1": searchTerm = string.Format("<span class='title' data-location='Menu{0}Sub{1}'>", command.Menu.ToString(), command.Sub1.ToString()); break; case "sub2": searchTerm = string.Format("<span class='title' data-location='Menu{0}Sub{1}Sub{2}'>", command.Menu.ToString(), command.Sub1.ToString(), command.Sub2.ToString()); break; } if (!Utility.IsSearchTermUniqueInString(fileContents, searchTerm, out startIndexSearchTerm, out errorMessage)) { return(Json(string.Format("ERROR!!\r\n{0}", errorMessage), JsonRequestBehavior.AllowGet)); } index = fileContents.IndexOf("</span>", startIndexSearchTerm + searchTerm.Length - 1); if (index == -1) { return(Json("ERROR!! Can't find </span> after search term!", JsonRequestBehavior.AllowGet)); } searchTerm = fileContents.Substring(startIndexSearchTerm, index + 7 - startIndexSearchTerm); switch (command.Cmd) { case "menu": newTerm = string.Format("<span class='title' data-location='Menu{0}'>{1}</span>", command.Menu.ToString(), command.Val); break; case "sub1": newTerm = string.Format("<span class='title' data-location='Menu{0}Sub{1}'>{2}</span>", command.Menu.ToString(), command.Sub1.ToString(), command.Val); break; case "sub2": newTerm = string.Format("<span class='title' data-location='Menu{0}Sub{1}Sub{2}'>{3}</span>", command.Menu.ToString(), command.Sub1.ToString(), command.Sub2.ToString(), command.Val); break; } newfileContents = fileContents.Replace(searchTerm, newTerm); Utility.CreateNewFile(fileNameFullPath, newfileContents); } else if ((command.Cmd == "icon") || (command.Cmd == "title") || ((command.Cmd.Length >= 3) && (command.Cmd.Substring(0, 3) == "tab"))) { if ((command.Cmd == "icon") && !Utility.IconExists(command.Val)) { return(Json("ERROR!! The icon does not exist!!", JsonRequestBehavior.AllowGet)); } switch (command.Cmd) { case "icon": pageEntity = PageEntity.Icon; break; case "title": pageEntity = PageEntity.Title; break; default: pageEntity = PageEntity.Tab; break; } HandleSaveOfPageEntity(pageEntity, command.Page, command.Menu, command.Sub1, command.Sub2, command.Tab, command.Val); } else if ((command.Cmd == "nr") || (command.Cmd == "er")) //New resource or edit resource { LoadResourceData loadResourceData = new LoadResourceData(); loadResourceData.ArrayWithKeyWords = KeyWordUtility.ReturnArrayWithKeyWords(out errorMessage); if (errorMessage != null) { return(Json(errorMessage, JsonRequestBehavior.AllowGet)); } if (command.Cmd == "nr") { ResourcesType resourcesType; switch (command.Val) { case "ThumbUpLocation": resourcesType = ResourcesType.ThumbUpLocation; break; case "Html": resourcesType = ResourcesType.Html; break; case "Self": resourcesType = ResourcesType.Self; break; default: return(Json("ERROR!! Incorrect ResourcesType!", JsonRequestBehavior.AllowGet)); } loadResourceData.Resource = new Resource(0, resourcesType, "", "", "", "", 0, 0, "", "", "", ""); } else { loadResourceData.Resource = ResourceUtility.GetResource(int.Parse(command.Val), out errorMessage); if (errorMessage != null) { return(Json(string.Format("ERROR!!\r\n", errorMessage), JsonRequestBehavior.AllowGet)); } } return(Json(loadResourceData, JsonRequestBehavior.AllowGet)); } else if ((command.Cmd == "r") && (command.Val == "rg")) { ResourcePresentationInSearchUtility.RegenerateResourceFile(out message); return(Json(message, JsonRequestBehavior.AllowGet)); } else if ((command.Cmd == "r") && (command.Val == "check")) { ResourcePresentationInSearchUtility.CheckResourceFile(out message); return(Json(message, JsonRequestBehavior.AllowGet)); } else if (command.Cmd == "task") { WorkUtility.CreateTask(command.Val, out message); return(Json(message, JsonRequestBehavior.AllowGet)); } else { return(Json(string.Format("ERROR!! The command \"{0}\" is not supported", command.Cmd), JsonRequestBehavior.AllowGet)); } } catch (Exception e) { return(Json(string.Format("ERROR!! An Exception happened! e.Message:\r\n{0}", e.Message), JsonRequestBehavior.AllowGet)); } return(Json("Success", JsonRequestBehavior.AllowGet)); }
public ActionResult NewLocation(Location location) { string errorMessage, searchTerm; bool todaysDayIsInFile; try { string locationStr = string.Format("Page{0}Menu{1}Sub{2}Sub{3}Tab{4}", location.Page, location.Menu, location.Sub1, location.Sub2, location.Tab); //Start switch non-default locations switch (locationStr) { //## will be replaced by \ in _LayoutTopLevel.cshtml (does not work if put \\) case "Page1Menu0Sub0Sub0Tab1": ViewBag.ListWithThumbUpLocationInfo = ThumbUpLocationInfoUtility.GetLocations(true, out errorMessage); ViewBag.ErrorMessage = errorMessage; return(View("Locations", GetDocumentReadyDataForNonDefaultLocation(location, "Views##Main##Locations.cshtml"))); case "Page1Menu0Sub0Sub0Tab2": ViewBag.ListWithThumbUpLocationInfo = ThumbUpLocationInfoUtility.GetLocations(false, out errorMessage); ViewBag.ErrorMessage = errorMessage; return(View("Locations", GetDocumentReadyDataForNonDefaultLocation(location, "Views##Main##Locations.cshtml"))); case "Page1Menu0Sub0Sub0Tab3": return(View("HelpSearchResources", GetDocumentReadyDataForNonDefaultLocation(location, "Views##Main##HelpSearchResources.cshtml"))); case "Page1Menu0Sub0Sub0Tab4": ViewBag.ListWithKeyWords = KeyWordUtility.GetKeyWords(); return(View("AddEditKeyWords", GetDocumentReadyDataForNonDefaultLocation(location, "Views##Main##AddEditKeyWords.cshtml"))); case "Page1Menu0Sub0Sub0Tab5": ViewBag.FileNameFullPathToConfigFile = "C:##git_cjonasl##Leander##Solutions##Nr1##WebApplication1##Text##Page1Menu1Sub1Sub1Tab1.txt"; ViewBag.ListWithKeyWords = KeyWordUtility.GetKeyWords(); return(View("AdhocCode", GetDocumentReadyDataForNonDefaultLocation(location, "Views##Main##AdhocCode.cshtml"))); case "Page1Menu0Sub0Sub0Tab7": return(View("Links", GetDocumentReadyDataForNonDefaultLocation(location, "Views##Main##Links.cshtml"))); case "Page1Menu1Sub1Sub2Tab2": ViewBag.FileNameFullPathToConfigFile = "C:##git_cjonasl##Leander##Solutions##Nr1##WebApplication1##Text##Page1Menu1Sub1Sub2Tab1.txt"; return(View("Communication1", GetDocumentReadyDataForNonDefaultLocation(location, "Views##Main##Communication1.cshtml"))); case "Page1Menu2Sub1Sub1Tab1": ViewBag.WorkFolder = "C:##git_cjonasl##Leander##Work##Fixzone"; ViewBag.ListWithDayDateDiaryBytesInDiary = DayDateDiaryBytesInDiaryUtility.ReturnListWithDayDateDiaryBytesInDiary(@"C:\git_cjonasl\Leander\Work\Fixzone", out todaysDayIsInFile, out errorMessage); ViewBag.TodaysDayIsInFile = todaysDayIsInFile; ViewBag.ErrorMessage = errorMessage; return(View("DayDateDiaryBytesInDiary", GetDocumentReadyDataForNonDefaultLocation(location, "Views##Main##DayDateDiaryBytesInDiary.cshtml"))); case "Page1Menu2Sub1Sub1Tab2": searchTerm = "ka(Task,Fixzone)"; ViewBag.List = ResourcePresentationInSearchUtility.GetResourcePresentationInSearchList(searchTerm); ViewBag.SearchTerm = searchTerm; return(View("ConstantResourceSearch", GetDocumentReadyDataForNonDefaultLocation(location, "Views##Main##ConstantResourceSearch.cshtml"))); case "Page1Menu3Sub1Sub1Tab1": searchTerm = "ka(Thumb up)"; ViewBag.List = ResourcePresentationInSearchUtility.GetResourcePresentationInSearchList(searchTerm); ViewBag.SearchTerm = searchTerm; return(View("ConstantResourceSearch", GetDocumentReadyDataForNonDefaultLocation(location, "Views##Main##ConstantResourceSearch.cshtml"))); case "Page1Menu3Sub1Sub1Tab2": searchTerm = "ka(C#)"; ViewBag.List = ResourcePresentationInSearchUtility.GetResourcePresentationInSearchList(searchTerm); ViewBag.SearchTerm = searchTerm; return(View("ConstantResourceSearch", GetDocumentReadyDataForNonDefaultLocation(location, "Views##Main##ConstantResourceSearch.cshtml"))); case "Page3Menu1Sub1Sub1Tab1": return(View("InfoThumbUp", GetDocumentReadyDataForNonDefaultLocation(location, "Views##Main##InfoThumbUp.cshtml"))); default: return(Json(GetDefaultDataForNewLocation(location), JsonRequestBehavior.AllowGet)); } //End switch non-default locations } catch (Exception e) { return(Json(string.Format("ERROR!! An Exception happened! e.Message:\r\n{0}", e.Message), JsonRequestBehavior.AllowGet)); } }