/// <summary>The thread that sends messages to their corresponding clients</summary> private void SendMessages() { while (true) { Message msg = sendingQueue.deQ(); if (msg.Body.ToLower().Equals("quit")) { break; } if (!sender.CommChannelExists(ConnectedEnds[msg.Destination])) { sender.CreateCommChannel(ConnectedEnds[msg.Destination], msg.Destination); } try { Console.Write("\n Sending message of type {0} to {1} ... ", msg.command, msg.Destination); sender.PostMessage(msg, msg.Destination); Console.Write("Sent successfully"); } catch (Exception) { Console.Write("Failed"); Console.Write("\n Blocking message until {0} is available", msg.Destination); if (BlockedMessages.ContainsKey(msg.Destination)) { BlockedMessages[msg.Destination].Add(msg); } else { List <Message> temp = new List <Message>(); temp.Add(msg); BlockedMessages.Add(msg.Destination, temp); } } } }
/// <summary>Processes test requests each in its AppDomain</summary> void ProcessTestRequest(string Name) { Console.Write("\n {0} intitiated", Name); XMLReader xReader = new XMLReader(); while (true) { Message msg = TestRequests.deQ(); // start timer Stopwatch watch = new Stopwatch(); watch.Start(); // if quit enqueue message again so other threads quit when they see it if (msg.Body.ToLower().Equals("quit")) { TestRequests.enQ(msg); break; } xReader.ProcessXMLString(msg.Body); string s = xReader.Author + " - " + xReader.TestRequest; Dispatcher.BeginInvoke(new Action(() => { lstBoxPendingTests.Items.Remove(s); lstBoxRunningTests.Items.Add(Name + ": " + s); })); string ResultFile = Path.Combine(sender.ResultsPath, xReader.Author + DateTime.Now.ToString("_MM_dd_yyyy_-_hh_mm_ss_") + xReader.TestRequest + ".log"); StringBuilder Log = new StringBuilder(); Log.Append("Author: " + xReader.Author + "\nTests:"); // downloads the required files from repository DownloadTestFiles(ref xReader, Name, ref Log); StringBuilder innerLog = new StringBuilder(); // start testing test drivers TestFiles(ref xReader, ref Log, ref innerLog, Name); Log.Append("\n\n" + innerLog.ToString()); // stop timer watch.Stop(); // finish log Log.Append("\n\nElapsed Time: " + watch.Elapsed.Seconds + " seconds"); // prepare results file File.WriteAllLines(ResultFile, Log.ToString().Split('\n')); //send results file to repository sender.UploadFile(ResultFile, FileTransferMessage.FileType.Result, "Repository"); PrepareResultsMessage(msg.Owner, ResultFile); DeleteTestFiles(Name); Dispatcher.BeginInvoke(new Action(() => { lstBoxRunningTests.Items.Remove(Name + ": " + s); lstBoxFinishedTests.Items.Add(s); })); } }
/// <summary>Downloads files from repository</summary> void DownloadFiles() { while (true) { FileTransferMessage file = FilesToDownload.deQ(); if (file.Filename.ToLower().Equals("quit")) { break; } try { sender.DownloadFile(file.Filename, file.Type, "Repository"); } catch (Exception) { Console.Write("\n Unable to download file {0} from the repository", file.Filename); } } }
/// <summary>The thread that sends communication messages</summary> void SendMessages() { while (true) { Message msg = sendingQueue.deQ(); if (msg.Body.ToLower().Equals("quit")) { break; } try { Console.Write("\n Sending message of type {0} to repository ... ", msg.command); sender.PostMessage(msg, msg.Destination); Console.Write("Sent successfully"); } catch (Exception) { Console.Write("Failed"); } } }
public Message GetMessage() { return(Queue.deQ()); }