// The function is activated as soon as data is received in the socket private void ReceiveCallback(IAsyncResult AR) { try { clientSocket = AR.AsyncState as Socket; int received = clientSocket.EndReceive(AR); if (received == 0) { return; } string data = Encoding.ASCII.GetString(buffer); var dataFromServer = data.Split(new[] { '\r', '\n', '\0' }, 2); DBclient DBInstance = DBclient.Instance; switch (dataFromServer[0])// dddd { // Get uniqe id case ID: id = dataFromServer[1].Split('\r', '\n', '\0')[0]; DBInstance.fillGeneralDetailsTable("id", id); //ShowErrorDialog("get id"); break; // Get Setting to implement monitoring gg case SETTING: string setting = dataFromServer[1].Split('\0')[0]; setting = setting.Substring(setting.IndexOf("\n") + 1); // save setting DBInstance.fillGeneralDetailsTable("name", name); DBInstance.fillGeneralDetailsTable("ip", ip); DBInstance.fillGeneralDetailsTable("setting", setting); playAllTrigers(); //This method obtains the settings string from the server // Set Periodic Report // PeriodicReporting.setReportPeriodic(); break; // Launch the software in live reporting mode case LIVE: liveMode(clientSocket); break; // Stop live reporting mode case STOP_LIVE: // ShowErrorDialog("server send: |" + dataFromServer[0].Split('\0')[0] + "|"); stopLiveMode(clientSocket); break; // Stop live reporting mode case LAST_REPORT: // abo Console.WriteLine("accept request to last report"); sendLastReport(clientSocket); break; // Remove computer from monitoring case REMOVE_CLIENT: removeClient(); break; default: // ShowErrorDialog("server send: |" + dataFromServer[0].Split('\0')[0] + "|"); break; } buffer = new byte[clientSocket.ReceiveBufferSize]; clientSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, ReceiveCallback, clientSocket); } catch (SocketException ex) { //ShowErrorDialog("ReceiveCallback\n" + ex ); Console.WriteLine("ReceiveCallback SocketException - RECONNECT"); reConnect(); } catch (ObjectDisposedException ex) { ShowErrorDialog("ReceiveCallback ObjectDisposedException\n " + ex.Message + " \n\n" + ex); Console.WriteLine("ReceiveCallback ObjectDisposedException"); } }
private static void createReportFile() { stringReport = ""; //ShowErrorDialog(getReportString()); var Report = new Document(); DBclient DBInstance = DBclient.Instance; string projectDirectory = Environment.CurrentDirectory; string path = Directory.GetParent(projectDirectory).Parent.FullName; string userName = Environment.UserName; PdfWriter.GetInstance(Report, new FileStream(path + "/Report.pdf", FileMode.Create)); //PdfWriter.GetInstance(Report, new FileStream(path + "/logo.JPG", FileMode.Create)); Report.Open(); Image jpg = Image.GetInstance(path + "/logo.JPG"); jpg.ScalePercent(12f); jpg.SetAbsolutePosition(Report.PageSize.Width - 410f, Report.PageSize.Height - 130f); Report.Add(jpg); Report.Add(new Paragraph(DateTime.Now.ToString())); stringReport += DateTime.Now.ToString() + "\n"; Report.Add(new Paragraph("\n\n\n\n\n" + frequencyWord + " report for user: "******" report for user: "******"\n"; // add bad word trigger string wordsTrigger = DBInstance.getTriggerById(1); if (wordsTrigger.Length > 0) { Report.Add(new Paragraph("\nOn the dates listed, the following words were typed:")); Report.Add(new Paragraph(wordsTrigger)); stringReport += "On the dates listed, the following words were typed:\n" + wordsTrigger + "\n"; } else { Report.Add(new Paragraph("\nNO TRIGGER KIND BAD WORDS TO REPORT!")); stringReport += "NO TRIGGER KIND BAD WORDS TO REPORT!\n"; } // add site trigger string siteTrigger = DBInstance.getTriggerById(2); if (siteTrigger.Length > 0) { Report.Add(new Paragraph("\nOn the dates listed the user browsed the following sites:")); Report.Add(new Paragraph(siteTrigger)); stringReport += "On the dates listed the user browsed the following sites:\n" + siteTrigger + "\n"; } else { Report.Add(new Paragraph("\nNO TRIGGER KIND SITES TO REPORT!")); stringReport += "NO TRIGGER KIND SITES TO REPORT!\n"; } // installations trigger string installationsTrigger = DBInstance.getTriggerById(3); if (installationsTrigger.Length > 0) { Report.Add(new Paragraph("\nOn the dates listed The user has downloaded the following software:")); Report.Add(new Paragraph(installationsTrigger)); stringReport += "On the dates listed The user has downloaded the following software:" + installationsTrigger + "\n"; } else { Report.Add(new Paragraph("\nNO TRIGGER KIND INSTALLATIONS TO REPORT!")); stringReport += "NO TRIGGER KIND INSTALLATIONS TO REPORT!\n"; } Report.Close(); ShowErrorDialog("report created, send mail"); sendReportFileToMail("Report File", "Report.pdf"); //db.printClientData(); string pathLastReport = Path.Combine(path, "lastReport.txt"); DBInstance.fillGeneralDetailsTable("lastReport", stringReport); }