void AddFolderNode(TreeNode parent, RequestFolder folder) { TreeNode node = new TreeNode(folder.Name); node.Tag = folder; _folderNodes.Add(folder, node); if (parent == null) { tvTemplates.Nodes.Add(node); } else { parent.Nodes.Add(node); } foreach (RequestFolder child in folder.Folders) { AddFolderNode(node, child); } foreach (RequestFile file in folder.Requests) { AddRequestNode(node, file); } }
/// <summary> /// Saves request. /// </summary> /// <param name="path">Path to desired file.</param> /// <param name="content">Request string.</param> /// <returns>Structure with request file data.</returns> public RequestFile SaveRequest(string path, string content) { if (File.Exists(path)) { File.Delete(path); string dir = Path.GetDirectoryName(path); if (_foldersList.ContainsKey(dir)) { RequestFolder rf = _foldersList[dir]; RequestFile file = rf.Requests.Where(r => r.FileName == Path.GetFileName(path)).FirstOrDefault(); if (file != null) { rf.Requests.Remove(file); View.DeleteFile(file, rf); } } else { RequestFile file = _rootFiles.Where(r => r.FileName == Path.GetFileName(path)).FirstOrDefault(); View.DeleteFile(file, null); } } FileStream fs = File.Create(path); TextWriter tw = new StreamWriter(fs); tw.Write(content); tw.Close(); return(AddFileToHierarchy(path)); }
public PostomateSystemNetHttpExtensionsTests(ApiFixture fixture, ITestOutputHelper output) { api = fixture.Api; folder = fixture .PostmanCollection(output) .FindFolder("System.Net.Http"); }
RequestFile SaveRequest() { TreeNode node = tvTemplates.SelectedNode; string initialPath = null; if (node != null) { RequestFolder f = node.Tag as RequestFolder; if (f != null) { // folder is selected - save in this folder initialPath = f.Path; } else { // file is selected TreeNode parent = node.Parent; if (parent != null) { f = parent.Tag as RequestFolder; if (f != null) { // folder is selected - save in this folder initialPath = f.Path; } } } } if (initialPath == null) { initialPath = _controller.RequestsRootPath; } SaveFileDialog dlg = new SaveFileDialog(); dlg.InitialDirectory = initialPath; dlg.AddExtension = true; dlg.Filter = "XML files | *.xml"; dlg.DefaultExt = "xml"; dlg.OverwritePrompt = true; RequestFile newFile = null; if (dlg.ShowDialog() == DialogResult.OK) { string fileName = dlg.FileName; try { newFile = _controller.SaveRequest(fileName, tbRequest.Text); } catch (Exception) { ShowError("An error occured during saving the request. File was not saved."); } } return(newFile); }
/// <summary> /// Adds folder to folders dictionary. /// </summary> /// <param name="folder">Folder information.</param> void AddFolderToDictionary(RequestFolder folder) { _foldersList.Add(folder.Path, folder); foreach (RequestFolder child in folder.Folders) { AddFolderToDictionary(child); } }
public PostmanAutomationSteps(ApiFixture fixture, ITestOutputHelper output, ScenarioContext scenarioContext) { this.featureFolder = fixture.PostmanCollection(output).FindFolder("Features"); this.scenarioContext = scenarioContext; this.api = fixture.Api; variables = new ImmutableVariableContext(new { baseUrl = api.BaseAddress?.ToString().Trim('/') ?? "http://localhost:5042" }); }
public void AddFile(RequestFile file, RequestFolder parentFolder) { if (parentFolder == null) { AddRequestNode(null, file); } else { TreeNode parent = _folderNodes[parentFolder]; AddRequestNode(parent, file); } }
public void AddFolder(RequestFolder folder, RequestFolder parentFolder) { if (parentFolder == null) { AddFolderNode(null, folder); } else { TreeNode parent = _folderNodes[parentFolder]; AddFolderNode(parent, folder); } }
public IntegrationTests(ApiFixture fixture, ITestOutputHelper output) { sut = fixture.PostmanCollection(output); api = fixture.Api; client = fixture.ApiClient; variables = new ImmutableVariableContext(new { baseUrl = api.BaseAddress?.ToString().Trim('/') ?? "http://localhost:5042" }); folder = sut.FindFolder("Tests"); }
public void DeleteFile(RequestFile file, RequestFolder parentFolder) { TreeNode node = _requestNodes[file]; if (parentFolder == null) { tvTemplates.Nodes.Remove(node); } else { TreeNode parent = _folderNodes[parentFolder]; parent.Nodes.Remove(node); } }
public void DisplayFolders(RequestFolder rootFolder) { tvTemplates.Nodes.Clear(); _folderNodes.Clear(); _requestNodes.Clear(); foreach (RequestFolder folder in rootFolder.Folders) { AddFolderNode(null, folder); } foreach (RequestFile file in rootFolder.Requests) { AddRequestNode(null, file); } }
/// <summary> /// Performs initialization. /// </summary> public override void Initialize() { string thisApplicationData = RequestsRootPath; if (Directory.Exists(thisApplicationData)) { RequestFolder root = new RequestFolder(new DirectoryInfo(thisApplicationData)); root.Load(); _folders.AddRange(root.Folders); foreach (RequestFolder folder in root.Folders) { AddFolderToDictionary(folder); } _rootFiles.AddRange(root.Requests); View.DisplayFolders(root); } }
/// <summary> /// Adds new request to hierarchy. /// </summary> /// <param name="path">Request path.</param> /// <returns>Structure with request data.</returns> RequestFile AddFileToHierarchy(string path) { if (!path.StartsWith(RequestsRootPath)) { RequestFile requestFile = new RequestFile(new FileInfo(path)); View.AddFile(requestFile, null); return(requestFile); } // if no directory to add file exists in the hierarchy - go upstream until // parent folder is found. // folders to create List <string> newFolders = new List <string>(); // current folder string folderPath = Path.GetDirectoryName(path); // existing folder RequestFolder existing = null; // Go to the parent folder. Stop at the root or at some existing folder. while (!_foldersList.ContainsKey(folderPath) && (folderPath != _requestsRootPath)) { int idx = folderPath.LastIndexOf(Path.DirectorySeparatorChar); System.Diagnostics.Debug.WriteLine(string.Format("Create directory: {0}", folderPath.Substring(idx + 1))); newFolders.Insert(0, folderPath.Substring(idx + 1)); folderPath = folderPath.Substring(0, idx); System.Diagnostics.Debug.WriteLine(string.Format("Check if exists: {0}", folderPath)); if (!folderPath.Contains(Path.DirectorySeparatorChar)) { // user wants to create file out of hierarchy - create in root folder! folderPath = RequestsRootPath; newFolders.Clear(); break; } } if (_foldersList.ContainsKey(folderPath)) { System.Diagnostics.Debug.WriteLine(string.Format("Existing: {0}", folderPath)); existing = _foldersList[folderPath]; } else { System.Diagnostics.Debug.WriteLine("Add as root folder/file"); } // create new folders // top new folder RequestFolder topFolder = null; // folder to add file in RequestFolder parentFolder = existing; // enumerate new folders. foreach (string folder in newFolders) { // next name string newDirectory = Path.Combine(folderPath, folder); System.Diagnostics.Debug.WriteLine(string.Format("Create {0} in {1}", folder, folderPath)); // create directory DirectoryInfo directory = Directory.CreateDirectory(newDirectory); // add to the hierarchy RequestFolder requestFolder = new RequestFolder(directory); // save top folder if (topFolder == null) { topFolder = requestFolder; } // add to parent folder or directly to the list if (_foldersList.ContainsKey(folderPath)) { _foldersList[folderPath].Folders.Add(requestFolder); } else { _folders.Add(requestFolder); } // add to the dictionary _foldersList.Add(requestFolder.Path, requestFolder); // change current path folderPath = newDirectory; // folder where file should be added parentFolder = requestFolder; } // create file structure RequestFile newFile = new RequestFile(new FileInfo(path)); // add to parent folder if (parentFolder != null) { System.Diagnostics.Debug.WriteLine(string.Format("Add file to: {0}", parentFolder.Path)); parentFolder.Requests.Add(newFile); } else { _rootFiles.Add(newFile); } // add file in the view if (topFolder == null) { // add file only View.AddFile(newFile, existing); } else { // add top folder. Other will be added automatically. System.Diagnostics.Debug.WriteLine(string.Format("Add folder {0} to {1}", topFolder.Name, existing == null ? "TOP" : existing.Path)); View.AddFolder(topFolder, existing); } return(newFile); }