public ActionResult Create(CreatedFile file) { if (file.IsFolder) { try { this.fileManager.CreateFolder(file.Path); } catch (UnauthorizedAccessException) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } catch (Exception) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } } else { try { this.fileManager.CreateFile(file.Path); } catch (UnauthorizedAccessException) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } catch (Exception) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } } return(Json(file)); }
public void CreateFolderException() { Mock <IFileManager> mock = new Mock <IFileManager>(); string name = "1"; string path = "/D:\\1"; int expectedStatusCode = 403; CreatedFile file = new CreatedFile() { Name = name, IsFolder = true, Path = path }; mock.Setup(m => m.CreateFolder(path)).Throws(new UnauthorizedAccessException()); FilesController controller = new FilesController(mock.Object); HttpStatusCodeResult result = controller.Create(file) as HttpStatusCodeResult; Assert.IsNotNull(result); Assert.AreEqual(expectedStatusCode, result.StatusCode); }
public void CreateFolder() { Mock <IFileManager> mock = new Mock <IFileManager>(); string name = "1"; string path = "/D:\\1"; CreatedFile file = new CreatedFile() { Name = name, IsFolder = true, Path = path }; mock.Setup(m => m.CreateFolder(path)); FilesController controller = new FilesController(mock.Object); JsonResult result = controller.Create(file) as JsonResult; Assert.IsNotNull(result); Assert.AreEqual(JsonConvert.SerializeObject(file), JsonConvert.SerializeObject(result.Data)); mock.Verify(x => x.CreateFolder(path)); }
public void CreateFolder() { Mock <IFileManager> mock = new Mock <IFileManager>(); string name = "1"; string path = "/C"; string expectedRouteValue = "C"; string expectedRouteName = "FileSystem"; string expectedPath = "C:\\1"; CreatedFile file = new CreatedFile() { Name = name, IsFolder = true, Path = path }; mock.Setup(m => m.CreateFolder(path)); HomeController controller = new HomeController(mock.Object); RedirectToRouteResult result = controller.Create(file) as RedirectToRouteResult; Assert.IsNotNull(result); Assert.AreEqual(expectedRouteValue, result.RouteValues["url"]); Assert.AreEqual(expectedRouteName, result.RouteName); mock.Verify(x => x.CreateFolder(expectedPath)); }
public ActionResult Create(CreatedFile file) { string currentPathTmp = file.Path.Substring(1, file.Path.Length - 1); string currentUrl = currentPathTmp.Substring(currentPathTmp.IndexOf('/') + 1, currentPathTmp.Length - currentPathTmp.IndexOf('/') - 1); string path = UrlPathHelper.UrlToPath(currentUrl + "/" + file.Name); if (file.IsFolder) { try { this.fileManager.CreateFolder(path); } catch (Exception) { return(RedirectToRoute("FileSystem", new { url = currentUrl })); } } else { try { this.fileManager.CreateFile(path); } catch (UnauthorizedAccessException) { return(RedirectToRoute("FileSystem", new { url = currentUrl })); } catch (Exception) { return(RedirectToRoute("FileSystem", new { url = currentUrl })); } } return(RedirectToRoute("FileSystem", new { url = currentUrl })); }
protected virtual void OnCreatedFile(FileInfo e) { CreatedFile?.Invoke(this, e); }
public override bool Execute() { if (ProjectNames == null) { return(true); } try { var builder = new StringBuilder(); foreach (var value in ProjectNames) { builder.Append(value); builder.Append('.'); } LogFormat("Message", "----------------------------------"); LogFormat("Message", "GenerateSolutionFiles Logging Info"); LogFormat("Message", "----------------------------------"); LogFormat("Message", CreatedFile); LogFormat("Message", builder.ToString()); var content = ""; using (var tr = new StreamReader(OriginalFile, true)) { content = tr.ReadToEnd(); } var globalIndex = content.IndexOf("Global"); var globalSection = content.Substring(globalIndex, content.Length - globalIndex); var globalSections = globalSection.Split(new string[] { "GlobalSection(" }, StringSplitOptions.RemoveEmptyEntries); var projectsSection = content.Substring(0, globalIndex); projectsSection = projectsSection.Remove(0, projectsSection.IndexOf("Project(")); var projects = projectsSection.Split(new string[] { "Project(" }, StringSplitOptions.RemoveEmptyEntries); var nestedProjectsSection = string.Empty; if (RemoveTfsBindings) { //Remove the TFS section. content = globalSections.Where(glb => glb.Contains("TeamFoundationVersionControl")).Aggregate(content, (current, glb) => current.Replace(string.Concat("GlobalSection(", glb), string.Empty)); content = content.Replace("SAK", string.Empty); } foreach (var glb in globalSections.Where(glb => glb.Contains("NestedProjects"))) { nestedProjectsSection = string.Concat("GlobalSection(", glb); } var nestedProjects = nestedProjectsSection.Split(new char[] { '\r', '\n', '\t', '\t' }, StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (var projectName in ProjectNames) { ProcessProject(projectName, ref projects, ref content, ref nestedProjects); } var filteredNestedProjects = string.Concat(string.Join("\r\n\t\t", nestedProjects.ToArray()), "\r\n\t").Replace("\tEndGlobalSection", "EndGlobalSection"); content = content.Replace(nestedProjectsSection, filteredNestedProjects); if (Replacements != null) { for (var index = 0; index <= Replacements.Length - 1; index = index + 2) { content = content.Replace(Replacements[index], Replacements[index + 1]); } } if (CreatedFile.Contains("_VS2008")) { //Convert a copy to VS2008 content = content.Replace("# Visual Studio 2010", "# Visual Studio 2008"); content = content.Replace("Microsoft Visual Studio Solution File, Format Version 11.00", "Microsoft Visual Studio Solution File, Format Version 10.00"); content = content.Replace("vbproj", "VS2008.vbproj").Replace("csproj", "VS2008.csproj"); } if (content.StartsWith(_byteOrderMarkUtf8)) { LogFormat("Message", "Removed Byte Order Mark"); content = content.Remove(0, _byteOrderMarkUtf8.Length); } using (TextWriter tw = File.CreateText(CreatedFile)) { tw.Write(content); } LogFormat("Message", "New File " + CreatedFile); LogFormat("Message", "--------------------------------------"); LogFormat("Message", "End GenerateSolutionFiles Logging Info"); LogFormat("Message", "--------------------------------------"); } catch (Exception ex) { LogFormat("Error", ex.StackTrace); return(false); } return(true); }
/// <summary> /// The OnCreatedFile /// </summary> /// <param name="e">The e<see cref="CreatedFileEventArgs"/></param> protected virtual void OnCreatedFile(CreatedFileEventArgs e) { CreatedFile?.Invoke(this, e); }