public ViewDoubleSolutions(DisplayResultsForm frm, PlagCheck_Server.Solution sol1, PlagCheck_Server.Solution sol2, string sol1Name, string sol2Name, float similarity) { sourceForm = frm; sourceSolution1 = sol1; sourceSolution2 = sol2; InitializeComponent(); contentBox1.Text = sourceSolution1.Content.Replace("\r\n", "\n").Replace("\n", "\r\n"); contentBox2.Text = sourceSolution2.Content.Replace("\r\n", "\n").Replace("\n", "\r\n"); solNameBox1.Text = sol1Name; solNameBox2.Text = sol2Name; similarityBox.Text = string.Format("Similarity percentage: {0:00.00}%", similarity); }
public void SendRequest(Request req) { PlagCheck_Server.Response res = null; try { ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); ipAddress = ipHostInfo.AddressList[1]; clientSocket = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); clientSocket.SendBufferSize = 1048576; clientSocket.ReceiveBufferSize = 1048576; string ip = ipTextBox.Text; int port = int.Parse(portTextBox.Text); clientSocket.Connect(ip, port); string message = ""; using (StringWriter sw = new StringWriter()) { requestSerializer.Serialize(sw, req); message = sw.ToString(); } byte[] messageSent = Encoding.UTF8.GetBytes("<REQ>" + message + "<EOM>"); int byteSent = clientSocket.Send(messageSent); byte[] messageReceived = new byte[16777216]; int byteRecv = clientSocket.Receive(messageReceived); string received = Encoding.UTF8.GetString(messageReceived, 0, byteRecv); AddLogs(String.Format("Text received at {0} -> {1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss tt"), ((received.Length > 64 || received.Contains("\n")) ? (received.Substring(0, (received.IndexOf("\n") > 64) ? 64 : received.IndexOf("\n")) + "...") : received))); if (received.Length >= 5 && received.Substring(0, 5).Equals("<ACK>")) { AddLogs("Server responded."); using (TextReader tr = new StringReader(received.Substring(5))) { res = (PlagCheck_Server.Response)responseSerializer.Deserialize(tr); } } else { AddLogs("Failed to obtain server\'s response."); } } catch (Exception exc) { AddLogs(exc.Message); } if (res != null) { try { DisplayResultsForm display = new DisplayResultsForm(this, res, shortenedFileList); display.Show(); } catch (Exception exc) { AddLogs(exc.Message); } } clientSocket.Dispose(); }
public ViewSingleSolution(DisplayResultsForm frm, PlagCheck_Server.Solution sol) { sourceForm = frm; sourceSolution = sol; InitializeComponent(); contentBox.Text = sourceSolution.Content.Replace("\r\n", "\n").Replace("\n", "\r\n"); }