public void upload(string filename, string savePath) { object locker = new object(); lock (locker) { string fqname = string.Empty; if (filename.EndsWith(".txt")) { fqname = Directory.GetFiles(ToSendPath, filename)[0]; } else { fqname = Path.Combine(ToSendPath, filename); } using (var inputStream = new FileStream(fqname, FileMode.Open)) { FileTransferMessage msg = new FileTransferMessage(); msg.filename = filename; msg.savePath = savePath; msg.transferStream = inputStream; channel.upLoadFile(msg); // call service's uploadfile } Console.Write("\n Uploaded file \"{0}\"", filename); } }
/// <summary>Forwards result file, received from TH, to the corresponding client</summary> /// <param name="Msg">Specifies the result message /// received from the TestHarness</param> private void ForwardResult(Message Msg) { if (Msg.command != Message.Command.Results) { return; } Message msg = new Message(); msg.Source = receiver.CommAddress; msg.Destination = Msg.Owner; msg.command = Message.Command.Results; msg.Body = Msg.Body; sendingQueue.enQ(msg); string filePath = Path.GetFullPath(Path.Combine(receiver.GetResultsPath(), msg.Body)); if (!sender.StreamChannelExists(ConnectedStreams[Msg.Owner])) { sender.CreateStreamingChannel(ConnectedStreams[Msg.Owner], Msg.Owner); } try { Console.Write("\n Sending file {0} to {1} ... ", Msg.Body, Msg.Owner); sender.UploadFile(filePath, FileTransferMessage. FileType.Result, Msg.Owner); Console.Write("Sent successfully"); } catch (Exception) { Console.Write("Failed\n Blocking file {0} untill {1} is connected", Msg.Body, Msg.Owner); FileTransferMessage file = new FileTransferMessage(); file.Filename = filePath; file.Type = FileTransferMessage.FileType.Result; if (BlockedFiles.ContainsKey(Msg.Owner)) { BlockedFiles[Msg.Owner].Add(file); } else { List <FileTransferMessage> temp = new List <FileTransferMessage>(); temp.Add(file); BlockedFiles.Add(Msg.Owner, temp); } } }
public void uploadFile(string filename, string ToSendPath, string SavePath) { string fqname = Path.Combine(ToSendPath, filename); try { hrt.Start(); using (var inputStream = new FileStream(fqname, FileMode.Open)) { FileTransferMessage msg = new FileTransferMessage(); msg.filename = filename; msg.transferStream = inputStream; msg.savePath = SavePath; channel.upLoadFile(msg); } hrt.Stop(); Console.Write("\n Uploaded file \"{0}\" in {1} microsec.", filename, hrt.ElapsedMicroseconds); } catch { Console.Write("\n can't find \"{0}\"", fqname); } }
/// <summary>Responds to client's request and sends the required test result </summary> /// <param name="Msg">Specifies the result request body</param> private void SendResult(Message Msg) { ThreadStart ts = new ThreadStart(() => { List <string> ToSend = new List <string>(); foreach (string Filename in ResultsList) { if (Filename.StartsWith(Msg.Body.Trim())) { ToSend.Add(Filename); } } // send no results reply if nothing was found if (ToSend.Count == 0) { Message msg = new Message(); msg.Source = receiver.CommAddress; msg.Destination = Msg.Owner; msg.command = Message.Command.NoResult; msg.Body = "No results found for \"" + Msg.Body + "\""; sendingQueue.enQ(msg); return; } foreach (string Filename in ToSend) { Message msg = new Message(); msg.Source = receiver.CommAddress; msg.Destination = Msg.Owner; msg.command = Message.Command.Results; msg.Body = Filename; sendingQueue.enQ(msg); string filePath = Path.GetFullPath(Path.Combine(receiver.GetResultsPath(), Filename)); if (!sender.StreamChannelExists(ConnectedStreams[Msg.Owner])) { sender.CreateStreamingChannel(ConnectedStreams[Msg.Owner], Msg.Owner); } try { Console.Write("\n Sending file {0} to {1} ... ", Filename, Msg.Owner); sender.UploadFile(filePath, FileTransferMessage. FileType.Result, Msg.Owner); Console.Write("Sent successfully"); } catch (Exception) { Console.Write("Failed\n Blocking file {0} untill {1} is connected", Filename, Msg.Owner); FileTransferMessage file = new FileTransferMessage(); file.Filename = filePath; file.Type = FileTransferMessage.FileType.Result; if (BlockedFiles.ContainsKey(Msg.Owner)) { BlockedFiles[Msg.Owner].Add(file); } else { List <FileTransferMessage> temp = new List <FileTransferMessage>(); temp.Add(file); BlockedFiles.Add(Msg.Owner, temp); } } } }); new Thread(ts).Start(); }