private bool CanAcceptSocket(Socket socket) { try { var args = new SocketFilterEventArgs(socket); TextWrite.getWriteLogData("[소켓접속]" + "HttpListener | CanAcceptSocket"); SocketAccepted(this, args); return(args.IsSocketOk); } catch (Exception err) { _logger.Error("SocketAccepted trigger exception: " + err); return(true); } }
/// <summary> /// Interpret incoming data. /// </summary> /// <param name="ar"></param> private void OnReceive(IAsyncResult ar) { // been closed by our side. if (Stream == null) { return; } _context = this; HttpFactory.Current = HttpFactory; try { int bytesLeft = Stream.EndRead(ar); if (bytesLeft == 0) { TextWrite.getWriteLogData("HttpContext | OnReceive" + " [bytesLeft가 0]"); _logger.Trace("Client disconnected."); Close(); TextWrite.getWriteLogData("HttpContext | OnReceive" + " [CLOSE 사용]"); return; } _logger.Debug(Socket.RemoteEndPoint + " received " + bytesLeft + " bytes."); if (bytesLeft < 5000) { string temp = Encoding.Default.GetString(_buffer, 0, bytesLeft); _logger.Trace(temp); } string data = Encoding.UTF8.GetString(_buffer, 0, bytesLeft); int offset = ParseBuffer(bytesLeft); TextWrite.getWriteLogData("HttpContext | OnReceive" + " [받은데이터]" + data + " offset:" + offset.ToString() + " byteleft" + bytesLeft.ToString()); bytesLeft -= offset; TextWrite.getWriteLogData("HttpContext | OnReceive" + " [받은데이터]" + data); if (bytesLeft > 0) { _logger.Warning("Moving " + bytesLeft + " from " + offset + " to beginning of array."); Buffer.BlockCopy(_buffer, offset, _buffer, 0, bytesLeft); } if (Stream != null) { Stream.BeginRead(_buffer, 0, _buffer.Length - offset, OnReceive, null); } } catch (ParserException err) { _logger.Warning(err.ToString()); var response = new Response("HTTP/1.0", HttpStatusCode.BadRequest, err.Message); var generator = HttpFactory.Current.Get <ResponseWriter>(); generator.SendErrorPage(this, response, err); Close(); TextWrite.getWriteLogData("HttpContext | OnReceive" + " [ParserException err] CLOSE사용" + err.ToString()); } catch (Exception err) { if (!(err is IOException)) { _logger.Error("Failed to read from stream: " + err); var responseWriter = HttpFactory.Current.Get <ResponseWriter>(); var response = new Response("HTTP/1.0", HttpStatusCode.InternalServerError, err.Message); responseWriter.SendErrorPage(this, response, err); } Close(); TextWrite.getWriteLogData("HttpContext | OnReceive" + " [Exception err] CLOSE사용" + err.ToString()); } }
// // Method coded for generating the detailed summary private void DetailedSummaryReport() { string SummaryReportFileName = DateTime.Now.ToString("dd.MM.yyy") + "_DETAILED_SUMMARY_REPORT.txt"; try { StreamWriter TextWrite; // // to check if any transaction happened for that session, if yes than transactional data would also be included in the report if (DaySaleSummary != "") { if (File.Exists(SummaryReportFileName)) { TextWrite = File.AppendText(SummaryReportFileName); foreach (string str in Regex.Split(DaySaleSummary, "\n")) { TextWrite.WriteLine(str); } TextWrite.WriteLine("Places In Stock:"); for (int i = 0; i < EVENTSNAME.Length; i++) { for (int j = 0; j < LOCATIONNAMES.Length; j++) { TextWrite.Write(PlacesAvailableBeforeConfirmation[i, j] + "\t"); } TextWrite.Write("\n"); } TextWrite.Flush(); TextWrite.Close(); } else { TextWrite = File.CreateText(SummaryReportFileName); foreach (string str in Regex.Split(DaySaleSummary, "\n")) { TextWrite.WriteLine(str); } TextWrite.WriteLine("Places In Stock:"); for (int i = 0; i < EVENTSNAME.Length; i++) { for (int j = 0; j < LOCATIONNAMES.Length; j++) { TextWrite.Write(PlacesAvailableBeforeConfirmation[i, j] + "\t"); } TextWrite.Write("\n"); } } TextWrite.Close(); MessageBox.Show("Report Generated, Details of completed booking in this session and places available have been saved in the" + SummaryReportFileName, "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (File.Exists(SummaryReportFileName)) { TextWrite = File.AppendText(SummaryReportFileName); TextWrite.WriteLine("Places In Stock:"); for (int i = 0; i < EVENTSNAME.Length; i++) { for (int j = 0; j < LOCATIONNAMES.Length; j++) { TextWrite.Write(PlacesAvailableBeforeConfirmation[i, j] + "\t"); } TextWrite.Write("\n"); } } else { TextWrite = File.CreateText(SummaryReportFileName); TextWrite.WriteLine("Places In Stock:"); for (int i = 0; i < EVENTSNAME.Length; i++) { for (int j = 0; j < LOCATIONNAMES.Length; j++) { TextWrite.Write(PlacesAvailableBeforeConfirmation[i, j] + "\t"); } TextWrite.Write("\n"); } } TextWrite.Close(); MessageBox.Show("Report Generated, there was no cpmpleted booking in this session. Details of places available has been saved in the" + SummaryReportFileName, "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }