public byte[] GetResult()
 {
     this.PreResult();
     using (MemoryStream st = new MemoryStream())
     {
         st.Write(Encoding.Default.GetBytes($" {Protocol} {Code} {Msg}\r\n"));
         st.Write(Encoding.Default.GetBytes($"Server: MoonHttp Server\r\n"));
         st.Write(Encoding.Default.GetBytes($"Date: {DateTime.Now.ToUniversalTime().ToString("r")}\r\n"));
         while (Headers.Count > 0)
         {
             st.Write(Encoding.Default.GetBytes($"{Headers.Dequeue()}\r\n"));
         }
         st.Write(Encoding.Default.GetBytes($"\r\n"));
         st.Write(Content);
         return(st.ToArray());
     }
 }
Exemple #2
0
        public void Print(Graphics g, int cellsOnXAxis, int cellsOnYAxis)
        {
            int smallFontSize = 33 / cellsOnXAxis;
            int largeFontSize = 200 / cellsOnXAxis;

            using (Font fnt = new Font("Arial", smallFontSize))
            {
                using (Font largeFnt = new Font("Arial", largeFontSize))
                {
                    using (var pen = new Pen(Color.Black, 1))
                    {
                        int cellWidth = 732 / cellsOnXAxis;
                        int celHeight = 1060 / cellsOnYAxis;

                        int startPosition = 35;
                        int margin        = cellWidth * 57 / 1000;  // ~14 (3x5)
                        int marginTop     = celHeight * 132 / 1000; // ~ 28 (3x5)
                        int barMargin     = 10;

                        for (int j = 0; j < cellsOnYAxis; j++)
                        {
                            for (int i = 0; i < cellsOnXAxis; i++)
                            {
                                if (!IsProcessed)
                                {
                                    var cellLeftPosition = i * cellWidth + startPosition;
                                    var cellTopPosition  = j * celHeight + startPosition;

                                    var innerPosX  = cellLeftPosition + margin;
                                    var innerWidth = cellWidth - 2 * margin;

                                    var captionPosX = innerPosX;
                                    var captionPosY = cellTopPosition + marginTop;

                                    var barHeight = celHeight / 10;
                                    var barWidth  = innerWidth * 3 / 4;
                                    var barPosX   = innerPosX + (cellWidth / 2) - margin - (barWidth / 2);
                                    var barPosY   = captionPosY + smallFontSize + barMargin;

                                    // Outer rect
                                    g.DrawRectangle(pen, cellLeftPosition, cellTopPosition, cellWidth, celHeight);

                                    // Caption
                                    var questionFrm = Headers.Dequeue();
                                    g.DrawString(questionFrm.Caption, fnt, System.Drawing.Brushes.Black, captionPosX, captionPosY);

                                    // Draw in rectangle
                                    g.DrawImage(questionFrm.BarCode, new Rectangle(barPosX, barPosY, barWidth, barHeight));
                                    //g.DrawRectangle(pen, barPosX, barPosY, barWidth, barHeight);

                                    // Big number
                                    var numPosX = questionFrm.EndToEndQuestionId < 10 ? cellLeftPosition + cellWidth / 3 : cellLeftPosition + cellWidth * 22 / 100;
                                    var numPosY = cellTopPosition + celHeight * 5 / 12;
                                    g.DrawString(questionFrm.EndToEndQuestionId.ToString(), largeFnt, Brushes.LightGray, (int)numPosX, numPosY);
                                }
                            }
                        }
                    }
                }
            }
        }