public void HandleReadFile() { const string fileName = "FileName"; const string fileContent = "TheContent"; _fileHandler.ReadText = fileContent; FileInfo fileInfo = new FileInfo(fileName); _sendAndMoveHandler.HandleReadFile(fileInfo); Assert.IsTrue(_fileHandler.FileMoved); Message fileReadMessage = _fileReadNotifier.SentMessages.FirstOrDefault(); Assert.IsNotNull(fileReadMessage); Assert.IsInstanceOfType(fileReadMessage, typeof(FileReadMessage)); Assert.AreEqual(fileReadMessage.Type, nameof(FileReadMessage)); FileReadMessage fileReadMessageCasted = (FileReadMessage)fileReadMessage; Assert.AreEqual(fileReadMessageCasted.FileName, fileName); Message fileContentMessage = _fileContentNotifier.SentMessages.FirstOrDefault(); Assert.IsNotNull(fileContentMessage); Assert.IsInstanceOfType(fileContentMessage, typeof(FileContentMessage)); Assert.AreEqual(fileContentMessage.Type, nameof(FileContentMessage)); FileContentMessage fileContentMessageCasted = (FileContentMessage)fileContentMessage; Assert.AreEqual(fileContentMessageCasted.FileName, fileName); Assert.AreEqual(fileContentMessageCasted.Payload, fileContent); }
/// <summary> /// Handle a file transmission by writing the file to the appropriate /// location in the cache folder for the currently registered build. /// </summary> void HandleFileContents(FileContentMessage message) { // Map the root path on the client to the local cached version; if this // fails, the client is sending us files for a root it didn't tell us // about when it started the build, so trigger an error. string local_path; if (current_build_folders.TryGetValue(message.RootPath, out local_path) == false) { SendError(true, 2000, "Unrecognized root path {0}", message.RootPath); return; } // Now we can combine the relative path of the file in the root with our // locally mapped root in order to get an entire complete absolute file // name. // // Once we do that, ensure that the directory that contains the file // esists (since it may have never before seen relative parts) and then // write it there. var local_file = Path.Combine(local_path, message.RelativeName); Directory.CreateDirectory(Path.GetDirectoryName(local_file)); File.WriteAllText(local_file, message.FileContent, Encoding.UTF8); // Now that we're done, tell the client that we have received the file // and handled it so they can send the next one or start the build. Acknowledge(MessageType.FileContent); }
private void OnMessageReceived(MessageReceivedEventArgs e) { Console.WriteLine("Received"); Console.WriteLine(e.Message); FileContentMessage fileContentMessage = JsonConvert.DeserializeObject <FileContentMessage>(e.Message); Console.WriteLine(fileContentMessage.Payload); }
private void SendFileContentMessage(FileInfo fileInfo) { string payload = _fileHandler.ReadAllText(fileInfo.FullName); FileContentMessage message = new FileContentMessage() { FileName = fileInfo.Name, Payload = payload }; _fileContentNotifier.Notify(message); }
public bool TryFire(RequestMessage request, out ResponseMessage response) { response = ResponseMessage.Error; var filepath = this.BasePath + request.Path; if (File.Exists(filepath)) { //response = new StringResponseMessage(200, File.ReadAllText(filepath)); response = new FileContentMessage(200, filepath); return(true); } return(false); }
public bool TryFire(RequestMessage request, out ResponseMessage response) { response = ResponseMessage.Error; if (!request.Path.StartsWith(this.EndpointPath)) { return(false); } var path = this.DirectoryPath + request.Path; if (Directory.Exists(path)) { string ul = "<ul>"; if (request.Path.Contains("../")) { return(false); } foreach (var file in Directory.GetFiles(path)) { ul += $"<li><a href=\"{request.Path + "/" + Path.GetFileName(file)}\">{Path.GetFileName(file)}</a></li>"; } foreach (var folder in Directory.GetDirectories(path)) { var folderName = folder.Replace(path, ""); ul += $"<li><a href=\"{request.Path + folderName}\">{folderName}</a></li>"; } ul += "</ul>"; response = new StringResponseMessage(200, $"<html><head><title>Public folder</title></head><h1>ASP.Majda public folder</h1><body>{ul}</body></html>"); return(true); } if (File.Exists(path)) { response = new FileContentMessage(200, path); return(true); } return(false); }