public StatusModel EditTopic(string scenarioId, string topicId, [FromBody] ApiFormInput formData) { if (formData == null) { return(CustomBadRequestResult <StatusModel>(Constants.InputDataIsMissing)); } if (!_authenticationManager.CheckAccessToken(formData.ticket)) { return(CustomBadRequestResult <StatusModel>(Constants.NotAuthorized)); } try { var scenarioFolder = _scenarioService.GetScenarioFolder(scenarioId); _topicService.EditTopic(scenarioFolder, formData.unique_id, topicId); } catch (Exception ex) { return(CustomBadRequestResult <StatusModel>(ex.Message)); } return(new StatusModel()); }
public async Task <AppLicenseDto> RequestLicense([FromBody] ApiFormInput formData) { if (string.IsNullOrWhiteSpace(formData?.key)) { return(new AppLicenseDto("License key not provided")); } System.Net.ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true; var licenseObtainResult = await _licenseManager.RequestLicenseOnline(formData.user, formData.key); return(licenseObtainResult); }
public FolderModel CreateCategory([FromBody] ApiFormInput formData) { FolderModel result = new FolderModel(); if (formData == null) { result.errors = ApiHelper.JsonError(400, new[] { "error" }); return(result); } if (string.IsNullOrWhiteSpace(formData.name)) { result.errors = ApiHelper.JsonError(400, new[] { "Incorrect name" }); return(result); } if (string.IsNullOrWhiteSpace(formData.name)) { result.errors = ApiHelper.JsonError(400, new string[] { "error" }); return(result); } if (!_authenticationManager.CheckAccessToken(formData.ticket)) { result.errors = ApiHelper.JsonError(400, new string[] { "wrong token" }); return(result); } if (formData.name.Length > 50) { result.errors = ApiHelper.JsonError(400, new[] { "Name is too long" }); //TODO: change all instances to ReflektBaseController.CustomBadRequestResult<T>() return(result); } result = ApiHelper.CreateFolder("", formData.name); if (result.folder != null) { result.folder.modified_utc = Scenarios.ConvertToUnixTimestamp(DateTime.Now); } SVNManager.SaveChanges(); return(result); }
//public string CreateScenario(string folder_id, string name, string description, string ticket = "") public ScenarioModel CreateScenario(string folder_id, [FromBody] ApiFormInput formData) { if (formData == null) { ScenarioModel model = new ScenarioModel(); model.errors = ApiHelper.JsonError(400, new string[] { "error" }); return(model); } if (string.IsNullOrWhiteSpace(formData.name)) { ScenarioModel model = new ScenarioModel(); model.errors = ApiHelper.JsonError(400, new string[] { "Incorrect name" }); return(model); } if (!_authenticationManager.CheckAccessToken(formData.ticket)) { ScenarioModel model = new ScenarioModel(); //return ApiHelper.JsonError(401, new string[] { "wrong token" }); model.errors = ApiHelper.JsonError(400, new string[] { "wrong token" }); return(model); } if (formData.name.Length > 50) { ScenarioModel model = new ScenarioModel(); model.errors = ApiHelper.JsonError(400, new string[] { "Name are too long" }); return(model); } ScenarioModel mod = ApiHelper.CreateScenarioModel(folder_id, formData.name, formData.description); if (mod.scenario != null) { mod.scenario.modified_utc = Scenarios.ConvertToUnixTimestamp(DateTime.Now); } SVNManager.SaveChanges(); return(mod); }
public FolderModel CreateProduct(string folder_id, [FromBody] ApiFormInput formData) { FolderModel result = new FolderModel(); if (formData == null) { result.errors = ApiHelper.JsonError(400, new[] { "error" }); return(result); } if (string.IsNullOrWhiteSpace(formData.name)) { result.errors = ApiHelper.JsonError(400, new[] { "Incorrect name" }); return(result); } if (!_authenticationManager.CheckAccessToken(formData.ticket)) { result.errors = ApiHelper.JsonError(400, new[] { "wrong token" }); return(result); } if (formData.name.Length > 50) { result.errors = ApiHelper.JsonError(400, new[] { "Name are too long" }); return(result); } result = ApiHelper.CreateFolder(folder_id, formData.name); if (result.folder != null) { result.folder.modified_utc = Scenarios.ConvertToUnixTimestamp(DateTime.Now); } SVNManager.SaveChanges(); return(result); }
public CortonaPathModel SetPath([FromBody] ApiFormInput formData) { var model = new CortonaPathModel(); if (formData == null) { model.errors = ApiHelper.JsonError(400, new[] { "empty body" }); return(model); } if (!_authenticationManager.CheckAccessToken(formData.ticket)) { model.errors = ApiHelper.JsonError(400, new[] { "wrong token" }); return(model); } var targetCortonaFile = new FileInfo(formData.path); if (targetCortonaFile.Name != "RapidManual.exe") { model.errors = ApiHelper.JsonError(400, new[] { "Cortona path should be pointing to RapidManual.exe file" }); return(model); } string toolsPath = PathHelper.GetUserProcessingFolder(); CortonaConfigModel config = JsonConvert.DeserializeObject <CortonaConfigModel>(IOFile.ReadAllText(Path.Combine(toolsPath, "cortona.config"))); config.Path = formData.path; model.path = formData.path; IOFile.WriteAllText(Path.Combine(toolsPath, "cortona.config"), JsonConvert.SerializeObject(config)); return(model); }
public TicketModel Post([FromBody] ApiFormInput formData) { if (formData == null) { return(new TicketModel { Errors = ApiHelper.JsonError(400, new[] { "User credentials are incomplete" }) }); } if (string.IsNullOrWhiteSpace(formData.username) && string.IsNullOrWhiteSpace(formData.password)) { return(new TicketModel { Errors = ApiHelper.JsonError(400, new[] { "Invalid login or password" }) }); } if (!_authenticationManager.Authenticate(formData.username, formData.password, out var authToken, out var refreshToken)) { return(new TicketModel { Errors = ApiHelper.JsonError(400, new[] { "Invalid login or password" }) }); } var resulTicketModel = new TicketModel { Token = authToken, RefreshToken = refreshToken }; var server = string.IsNullOrEmpty(formData.server) ? "localhost" : formData.server; SVNManager.Authorizate(server, formData.username, formData.password, _ => { }); return(resulTicketModel); }
public ImportedScenarioModel Import(string folder_id, [FromBody] ApiFormInput formData) { ImportedScenarioModel model = new ImportedScenarioModel(); if (!formData.local) { string fileName = formData.filename; string base64 = formData.file; formData.file = Path.Combine(PathHelper.GetViewerImagesFolder(), fileName); byte[] fileContent = ApiHelper.DecodeBase64(base64); IOFile.WriteAllBytes(formData.file, fileContent); } if (string.IsNullOrEmpty(formData.ticket)) { model.errors = ApiHelper.JsonError(400, new string[] { "error" }); return(model); } if (string.IsNullOrEmpty(formData.file)) { model.errors = ApiHelper.JsonError(400, new string[] { "File is required" }); return(model); } if (!PathHelper.CheckIfStringIsPathCompliant(Path.GetFileName(formData.file))) { model.errors = ApiHelper.JsonError(400, new[] { "Invalid file name provided" }); return(model); } if (!_authenticationManager.CheckAccessToken(formData.ticket)) { model.errors = ApiHelper.JsonError(400, new string[] { "wrong token" }); return(model); } formData.file = formData.file.Replace("file:///", ""); formData.file = formData.file.Replace("file://", ""); string ret = ApiHelper.FindFolderById(folder_id, PathHelper.GetRepoPath()); if (ret == null) { //return ApiHelper.JsonError(400, new string[] { "folder not exist" }); model.errors = ApiHelper.JsonError(400, new string[] { "file not exist" }); return(model); } if (!IOFile.Exists(formData.file)) { //return ApiHelper.JsonError(400, new string[] { "file not exist" }); model.errors = ApiHelper.JsonError(400, new string[] { "file not exist" }); return(model); } if (!string.IsNullOrEmpty(ret)) { ret = ret.Replace(PathHelper.GetRepoPath(), "").Replace("\\", "/"); Exporter.Import(formData.file, ret, formData.overRide, (res) => { model = res; }); } SVNManager.SaveChanges(); return(model); }
//public string UpdateFolder(string folder_id, string folder, string ticket = "") public FolderModel UpdateFolder(string folder_id, [FromBody] ApiFormInput formData) { FolderModel result = new FolderModel(); if (formData == null) { //return ApiHelper.JsonError(400, new string[] { "empty body" }); result.errors = ApiHelper.JsonError(400, new string[] { "empty body" }); return(result); } if (string.IsNullOrEmpty(formData.ticket)) { //return ApiHelper.JsonError(400, new string[] { "error" }); result.errors = ApiHelper.JsonError(400, new string[] { "error" }); return(result); } if (string.IsNullOrEmpty(formData.folder.name)) { result.errors = ApiHelper.JsonError(400, new string[] { "Incorrect name" }); return(result); } if (string.IsNullOrEmpty(formData.folder.name)) { result.errors = ApiHelper.JsonError(400, new string[] { "Folder name are empty" }); return(result); } if (!_authenticationManager.CheckAccessToken(formData.ticket)) { //return ApiHelper.JsonError(401, new string[] { "wrong token" }); result.errors = ApiHelper.JsonError(400, new string[] { "wrong token" }); return(result); } if (formData.folder.name.Length > 50) { result.errors = ApiHelper.JsonError(400, new string[] { "Name are too long" }); return(result); } string ret = ApiHelper.FindFolderById(folder_id, PathHelper.GetRepoPath()); if (ret == null) { //return ApiHelper.JsonError(400, new string[] { "folder not exist" }); result.errors = ApiHelper.JsonError(400, new string[] { "folder not exist" }); return(result); } try { string sc = formData.folder.name; if (sc != null) { string dir = new DirectoryInfo(ret).Name; CategoryModel model = JsonConvert.DeserializeObject <CategoryModel>(IOFile.ReadAllText(Path.Combine(ret, dir + ".info"))); model.title = sc; string newModel = JsonConvert.SerializeObject(model); IOFile.WriteAllText(Path.Combine(ret, dir + ".info"), newModel); //PathHelper.RenameFolder(ret, dir, sc); ret = ApiHelper.FindFolderById(folder_id, PathHelper.GetRepoPath()); result = ApiHelper.GetFolderInfo(folder_id, Path.Combine(PathHelper.GetRepoPath(), ret)); string oldPath = new DirectoryInfo(ret).FullName.Replace("\\", "/"); //SVNManager.Rename(oldPath, oldPath.Replace(dir,sc)); SVNManager.SaveChanges(); return(result); } } catch (Exception e) { //return ApiHelper.JsonError(400, new string[] { "wrong folder object" }); result.errors = ApiHelper.JsonError(400, new string[] { "wrong folder object" }); return(result); } return(null); }
public ImportedTopicsModel ImportTopic(string scenario_id, [FromBody] ApiFormInput formData) { ImportedTopicsModel model = new ImportedTopicsModel(); if (!formData.local) { string fileName = formData.filename; string base64 = formData.file; formData.file = Path.Combine(PathHelper.GetViewerImagesFolder(), fileName); byte[] fileContent = ApiHelper.DecodeBase64(base64); System.IO.File.WriteAllBytes(formData.file, fileContent); } if (string.IsNullOrEmpty(formData.ticket)) { //return ApiHelper.JsonError(400, new string[] { "error" }); model.errors = ApiHelper.JsonError(400, new string[] { "error" }); return(model); } if (string.IsNullOrEmpty(formData.file)) { model.errors = ApiHelper.JsonError(400, new string[] { "File is required" }); return(model); } if (!_authenticationManager.CheckAccessToken(formData.ticket)) { //return ApiHelper.JsonError(401, new string[] { "wrong token" }); model.errors = ApiHelper.JsonError(400, new string[] { "wrong token" }); return(model); } formData.file = formData.file.Replace("file:///", ""); if (!System.IO.File.Exists(formData.file)) { //return ApiHelper.JsonError(400, new string[] { "file not exist" }); model.errors = ApiHelper.JsonError(400, new string[] { "file not exist" }); return(model); } string ret = ApiHelper.FindFolderById(scenario_id, PathHelper.GetRepoPath()); List <TopicObject> beforeImportTopics = ApiHelper.GetTopics(scenario_id); Exporter.ImportTopic(formData.file, ret, formData.overRide, (res) => { List <TopicObject> topics = ApiHelper.GetTopics(scenario_id); topics = topics.OrderBy(t => t.id).ToList(); List <TopicModel> orogintopics = ApiHelper.GetTopicsOrigin(scenario_id); List <int> ids = new List <int>(); foreach (TopicObject obj in topics) { int index = int.Parse(obj.id); while (ids.Contains(index)) { index += 1; } ids.Add(index); obj.id = index.ToString(); } ids.Clear(); foreach (TopicModel obj in orogintopics) { int index = obj.index; while (ids.Contains(index)) { index += 1; } obj.index = index; ids.Add(index); System.IO.File.WriteAllText(obj.infoPath, JsonConvert.SerializeObject(obj)); } foreach (TopicObject lastObj in beforeImportTopics) { topics.Remove(topics.Find(t => t.id == lastObj.id)); } topics = topics.OrderBy(t => t.id).ToList(); model.topics = topics; }); SVNManager.SaveChanges(); return(model); }