public string AppendPath(FolderRelativePath path2) { if (path2 == null) { return(_value); } return(Path.Combine(_value, path2)); }
/// <summary> /// Save the request and response to a file; this same file can be used later to be returned as a response /// it will not save or throw an error if there is no response (an exception occurred) /// </summary> /// <param name="relativeFolder">Relative folder inside the base folder where your stubs will be saved</param> /// <param name="fileName">stub filename, should not contain the extension, if none passed the HttpStatus will be the name</param> /// <param name="howManyFilesToKeep">if 0, it will keep an infinite number of files, and add a number at the end, example: FILENAME_0001, FILENAME_0002 /// if 1, it will keep just one, and overwrite it everytime /// if >1, it will create files with a number at the end, but once the limit is reached, it will stop creating files, no overwritting</param> /// <returns>a task to be awaited</returns> public async Task SaveAsRecording(FolderRelativePath relativeFolder = null, FileName fileName = null, int howManyFilesToKeep = 0) { if (Response == null) { return; // nothing to save if we have no response (an exception occurred) } var requestResponse = await RecordingFormatter.Summarize(Request, Response, Duration); var finalFileName = Global.GlobalRecordingManager.Save(requestResponse, relativeFolder, fileName, howManyFilesToKeep); var recording = new Recording() { File = finalFileName, DateTime = DateTime.Now, Request = Request, Response = Response }; RecordingCollection.Recordings.Add(recording); }
public string Save(RequestResponse log, FolderRelativePath relativeFolder = null, FileName fileName = null, int howManyFilesToKeep = 0) { var finalFolder = baseDirectory.AppendPath(relativeFolder); if (!Directory.Exists(finalFolder)) { Directory.CreateDirectory(finalFolder); } if (fileName == null) { fileName = log.Response.Status.ToString(); } var finalFileName = GetFinalFileName(finalFolder, fileName, howManyFilesToKeep); if (finalFileName == null) { return(null); // limit reached } SaveToFile(Path.Combine(finalFolder, finalFileName), log); return(finalFileName); }