// ----------------< Proceesed Server Request >---------------- public static void serverProcessing(SvcMsg msg) { if (msg.cmd.ToString().Equals("Response")) { Console.Write("\nThis is the Response from Server............\n\n"); msg.ShowMessage(); responeFromServerTesting(msg.body.ToString()); } if (msg.cmd.ToString().Equals("Request")) { Console.Write("\nThis is the Request from Server for TypeTable............\n\n"); msg.ShowMessage(); Intermediator im = new Intermediator(); string typeTable = im.getTypeTable(); SvcMsg msg1 = new SvcMsg(); msg1.src = new Uri(src); msg1.dst = new Uri(dst); msg1.cmd = SvcMsg.Command.Response; msg1.body = typeTable; Sender.sendingServer(msg1); } }
// ----------------< Proceesed client Request >---------------- public static void clientProcessing(SvcMsg msg) { Intermediator im = new Intermediator(); im.clearRepository(); if (msg.cmd.ToString().Equals("Dependency")) { Console.Write("\n This is the new Request from Client for Dependency............\n\n"); msg.ShowMessage(); dependencyProcessing(msg); } if (msg.cmd.ToString().Equals("DependencyAll")) { Console.Write("\n This is the slients Request from Client for All Package Dependency ............\n\n"); msg.ShowMessage(); allDependencyProcessing(msg); } if (msg.cmd.ToString().Equals("ProjectList")) { Console.Write("\n This is the new Request from Client for ProjectList............\n\n"); msg.ShowMessage(); projectListProcessing(msg); } }
static void projectListProcessing(SvcMsg msg) { Intermediator im = new Intermediator(); msg.body = im.getprojectList(); clientConnect(msg); }
public static void ThreadProcedureServer() { while (true) { SvcMsg msg = GetMessageServer(); Dispatcher.serverProcessing(msg); } }
public static void ThreadProcedure() { while (true) { SvcMsg msg = GetMessage(); Dispatcher.clientProcessing(msg); } }
public static void serverConnect() { Console.Write("\nEntering in to server to server communication: \n"); SvcMsg msg1 = new SvcMsg(); msg1.src = new Uri(src); msg1.dst = new Uri(dst); msg1.cmd = SvcMsg.Command.Request; Sender.sendingServer(msg1); }
public static void clientConnect(SvcMsg msg) { SvcMsg msg1 = new SvcMsg(); msg1.src = new Uri(msg.dst.ToString()); msg1.dst = new Uri(msg.src.ToString()); msg1.cmd = msg.cmd; msg1.body = msg.body; Sender.sendingClient(msg1); }
public static void sendingServer(SvcMsg msg) { try { IMessageService proxy = CreateClientChannel(msg.dst.ToString()); proxy.ServerMessage(msg); } catch (Exception ex) { Console.Write("\n\n" + ex.Message); } }
// send request to appropiate server for projectList public void sendRequestForprojectList(string dst) { IMessageService proxy = CreateClientChannel(dst); SvcMsg msg = new SvcMsg(); msg.cmd = SvcMsg.Command.ProjectList; msg.src = new Uri(src); msg.dst = new Uri(dst); msg.body = ""; proxy.PostMessage(msg); }
//----< receive thread processing >------------------------------ void ThreadProc() { while (true) { rcvdMsg = recvr.GetMessage(); // call window functions on UI thread this.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, OnNewMessage, rcvdMsg); } }
static void Main(string[] args) { string src = "http://localhost:9001/MessageService"; string dst = "http://localhost:9001/MessageService"; SvcMsg msg = new SvcMsg(); msg.src = new Uri(src); msg.dst = new Uri(dst); msg.cmd = SvcMsg.Command.ProjectList; msg.body = ""; clientProcessing(msg); SvcMsg msg1 = new SvcMsg(); msg1.src = new Uri(src); msg1.dst = new Uri(dst); msg1.cmd = SvcMsg.Command.Request; msg1.body = ""; serverProcessing(msg); }
static void dependencyProcessing(SvcMsg msg) { string temp = ""; bool connect = false; DateTime timeout = DateTime.Now; timeout.AddSeconds(5); try { serverConnect(); } catch (Exception ex) { Console.Write("\n\n" + ex.Message); } finally { while (true) { if (check == true) { temp = typeFromOtherServer; connect = true; break; } if (DateTime.Compare(timeout, DateTime.Now) < 0) { connect = false; break; } } Intermediator im = new Intermediator(); if (connect) { im.typeTableMerging(typeFromOtherServer); } im.dependencyAnalysis(msg.body.ToString()); msg.body = im.getDependencyResult(); clientConnect(msg); } }
static void dependencyProcessing(SvcMsg msg) { string temp = ""; bool connect = false; DateTime timeout = DateTime.Now; timeout.AddSeconds(5); try { serverConnect(); } catch (Exception ex) { Console.Write("\n\n" + ex.Message); } finally { while (true) { if (check == true) { temp = typeFromOtherServer; connect = true; break; } if (DateTime.Compare(timeout,DateTime.Now) < 0 ) { connect = false; break; } } Intermediator im = new Intermediator(); if (connect) { im.typeTableMerging(typeFromOtherServer); } im.dependencyAnalysis(msg.body.ToString()); msg.body = im.getDependencyResult(); clientConnect(msg); } }
//----< called by UI thread when dispatched from rcvThrd >------- void OnNewMessageHandler(SvcMsg msg) { if (msg.cmd.ToString().Equals("ProjectList")) { messageCounter++; message_listbox.Items.Insert(0, " "); message_listbox.Items.Insert(0, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff")); message_listbox.Items.Insert(0, messageCounter+". Response for ProjectList From: " + msg.src.ToString()); listbox1.Items.Clear(); List<string> projectList = pc.getProjectList(msg.body.ToString()); if (projectList!=null) { foreach (string s in projectList) listbox1.Items.Add(s); } else { dependency_Result.Items.Add("There is Projects Available on Server"); } } if (msg.cmd.ToString().Equals("Dependency")) { messageCounter++; message_listbox.Items.Insert(0, " "); message_listbox.Items.Insert(0, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff")); message_listbox.Items.Insert(0, messageCounter+". Response for Dependency From: " + msg.src.ToString()); pc.outGoingResultAnalysis(msg.body.ToString()); // dependency_Result.Text = msg.body.ToString(); } if (msg.cmd.ToString().Equals("DependencyAll")) { pc.inComingResultAnalysis(msg.body.ToString()); } }
// send request to appropiate server for Dependency public void sendRequestForAnalysis(string directory, string destination) { string dst1 = ""; string dst2 = ""; if (destination.Equals("http://localhost:9001/MessageService")) { dst1 = "http://localhost:9001/MessageService"; dst2 = "http://localhost:9002/MessageService"; } else { dst2 = "http://localhost:9001/MessageService"; dst1 = "http://localhost:9002/MessageService"; } IMessageService proxy = CreateClientChannel(dst1); SvcMsg msg = new SvcMsg(); msg.cmd = SvcMsg.Command.Dependency; msg.src = new Uri(src); msg.dst = new Uri(dst1); msg.body = directory; proxy.PostMessage(msg); try { IMessageService proxy1 = CreateClientChannel(dst2); SvcMsg msg1 = new SvcMsg(); msg1.cmd = SvcMsg.Command.DependencyAll; msg1.src = new Uri(src); msg1.dst = new Uri(dst2); msg1.body = directory; proxy1.PostMessage(msg1); } catch { } }
// ------< Implement service method to receive messages from other Client >------- public void PostMessage(SvcMsg msg) { rcvBlockingQ.enQ(msg); }
public void ServerMessage(SvcMsg msg) { }
// ------< Implement service method to receive messages from other Server >------- public void ServerMessage(SvcMsg msg) { rcvBlockingQServer.enQ(msg); }
// Implement service method to receive messages from other Peers public void PostMessage(SvcMsg msg) { msg.ShowMessage(); rcvBlockingQ.enQ(msg); }
static void Main(string[] args) { string src = "http://localhost:9001/MessageService"; string dst = "http://localhost:9001/MessageService"; SvcMsg msg = new SvcMsg(); msg.src = new Uri(src); msg.dst = new Uri(dst); msg.cmd = SvcMsg.Command.ProjectList; msg.body =""; clientProcessing(msg); SvcMsg msg1 = new SvcMsg(); msg1.src = new Uri(src); msg1.dst = new Uri(dst); msg1.cmd = SvcMsg.Command.Request; msg1.body = ""; serverProcessing(msg); }