public override void SendResponse()
        {
            ResponseBuilder pageBuilder = new PageBuilder()
            {
                Response = new Response()
                {
                    AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork,
                    IsConnected = true,
                    ContentLength = 120,
                    StatusDesc = this.MyServer.State.DescriptionState,
                    ContentType = "text/html",
                    StatusCode = this.MyServer.State.CodeState,
                    Charset = System.Text.Encoding.UTF8,
                    DateTimeResponse = DateTime.Now,
                    ProtocolType = System.Net.Sockets.ProtocolType.Tcp
                }
            };
            this.Response = pageBuilder.CreateResponse();

            // Приведем строку к виду массива байт
            byte[] buffer = Encoding.UTF8.GetBytes(this.Response);
            // Отправим его клиенту
            //this._mediator.Client.GetStream().Write(buffer, 0, buffer.Length);
            // Закроем соединение
            //this._mediator.Client.Close();
        }
Exemple #2
0
        protected override void SendResponse()
        {
            string _path = System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));
            string _pathToFolder = _path + "\\Website\\Styles\\SimplePageStyle.css";
            string css = string.Empty;

            using (System.IO.StreamReader reader = new System.IO.StreamReader(_pathToFolder))
            {
                css = reader.ReadToEnd();
            }

            _dataIp = IpConfig.IpConfig.GetIpInfo();
            string html = "<html>" +
                            "<head>" +
                                "<title>Weaher</title>" +
                                "<style type=\"text/css\">" + css + "</style>" +
                            "</head>" +
                                "<body>" +
                                    "<h1>Ip information</h1>" + "<hr>" +
                                    "<h3>IP: </h3>" + "<i>" + this._dataIp.Ip + "</i>" +
                                    "<h3>City: </h3>" + "<i>" + this._dataIp.City + "</i>" +
                                    "<h3>Country: </h3>" + "<i>" + this._dataIp.Country + "</i>" +
                                    "<h3>Region: </h3>" + "<i>" + this._dataIp.Region + "</i>" +
                                    "<h3>Host name: </h3>" + "<i>" + this._dataIp.HostName + "</i>" +
                                    "<h3>Organization: </h3>" + "<i>" + this._dataIp.Organization + "</i>" +
                                    "<h3>Location: </h3>" + "<i>" + this._dataIp.Location + "</i>" +
                                 "</body>" +
                           "</html>";

            ResponseBuilder builder = new PageBuilder()
            {
                Response = new Response()
                {
                    AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork,
                    IsConnected = true,
                    Html = html,
                    ContentLength = html.Length,
                    StatusDesc = ((HttpStatusCode)200).ToString(),
                    ContentType = "text/html",
                    StatusCode = 200,
                    Charset = System.Text.Encoding.UTF8,
                    DateTimeResponse = DateTime.Now,
                    ProtocolType = System.Net.Sockets.ProtocolType.Tcp
                }
            };
            string str = builder.CreateResponse();

            // Приведем строку к виду массива байт
            byte[] buffer = Encoding.UTF8.GetBytes(str);
            // Отправим его клиенту
            this.Client.GetStream().Write(buffer, 0, buffer.Length);
            // Закроем соединение
            this.Client.Close();
        }
        protected override void SendResponse()
        {
            string _pathToFolder = string.Empty;
            string _path = System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));
            // Detect the type to return value
            if (this.Action == _logInTrue)
            {
                _pathToFolder = _path + "\\Website\\Pages\\Main.html";
            }
            else if (this.Action == _logInFalse)
            {
                _pathToFolder = _path + "\\Website\\Pages\\ErrorPages\\logInError.html";
            }
            else
                _pathToFolder = _path + "\\Website\\Pages\\LogIn.html";

            string htmlPage = string.Empty;

            using (System.IO.StreamReader reader = new System.IO.StreamReader(_pathToFolder))
            {
                htmlPage = reader.ReadToEnd();
            }

            ResponseBuilder builder = new PageBuilder()
            {
                Response = new Response()
                {
                    AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork,
                    IsConnected = true,
                    Html = htmlPage,
                    ContentLength = htmlPage.Length,
                    StatusDesc = ((HttpStatusCode)200).ToString(),
                    ContentType = "text/html",
                    StatusCode = 200,
                    Charset = System.Text.Encoding.UTF8,
                    DateTimeResponse = DateTime.Now,
                    ProtocolType = System.Net.Sockets.ProtocolType.Tcp
                }
            };
            string str = builder.CreateResponse();

            // Приведем строку к виду массива байт
            byte[] buffer = Encoding.UTF8.GetBytes(str);
            // Отправим его клиенту
            this.Client.GetStream().Write(buffer, 0, buffer.Length);
            // Закроем соединение
            this.Client.Close();
        }
 public override void Create(string name, Format myFormat)
 {
     ResponseBuilder builder = new PageBuilder()
     {
         Response = new Response()
         {
             AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork,
             IsConnected = true,
             Html = myFormat.Content,
             ContentLength = myFormat.Length,
             StatusDesc = ((HttpStatusCode)200).ToString(),
             ContentType = "text/html",
             StatusCode = 200,
             Charset = System.Text.Encoding.UTF8,
             DateTimeResponse = DateTime.Now,
             ProtocolType = System.Net.Sockets.ProtocolType.Tcp
         }
     };
     string str = builder.CreateResponse();
 }
        public override void SendResponse(int code)
        {
            string codeStr = code.ToString() + " " + ((HttpStatusCode)code).ToString();
            Quote q = new Quote();

            string html = "<html>" +
                                "<body>" +
                                    "<h1>" + codeStr + "</h1>" +
                                    "<h3>Quote of the day</h3>" +
                                    "<blockquote><h3><i>" + q.GetQuote() + "</i></h3></blockquote>" +
                                    "<h3>Черномырдин Виктор Степанович</h3>" +
                                 "</body>" +
                           "</html>";

            ResponseBuilder builder = new PageBuilder()
            {
                Response = new Response()
                {
                    AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork,
                    IsConnected = true,
                    Html = html,
                    ContentLength = html.Length,
                    StatusDesc = ((HttpStatusCode)code).ToString(),
                    ContentType = "text/html",
                    StatusCode = code,
                    Charset = System.Text.Encoding.UTF8,
                    DateTimeResponse = DateTime.Now,
                    ProtocolType = System.Net.Sockets.ProtocolType.Tcp
                }
            };

            string str = builder.CreateResponse();

            // Приведем строку к виду массива байт
            byte[] buffer = Encoding.UTF8.GetBytes(str);
            // Отправим его клиенту
            // this.Client.GetStream().Write(buffer, 0, buffer.Length);
            // Закроем соединение
            // this.Client.Close();
        }
        public void TestResponseCreate()
        {
            ResponseBuilder errorBuilder = new PageBuilder()
            {
                Response = new Response()
                {
                    AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork,
                    IsConnected = true,
                    ContentLength = 120,
                    ContentType = "text/html",
                    StatusCode = 200,
                    Charset = System.Text.Encoding.ASCII,
                    ProtocolType = System.Net.Sockets.ProtocolType.Tcp
                }
            };

            string resActual = errorBuilder.CreateResponse();
            string resExpected = "HTTP/1.1 200 OK \nContent-Length: 120 \nContent-Type: text/html; charset=US-ASCII " +
                                 "\nProtocolType: Tcp \nAddressFamily: InterNetwork \nIsConnected: True" +
                                 "<html> \n<head> </head> \n<body> </body> \n</html> ";

            // Not equals because the DateTime is different
            Assert.AreNotEqual(resExpected, resActual);
        }
        protected override void SendResponse()
        {
            _weather = new Weather(Route.Value); // value the city to get weather
            Tuple<WeatherCondition, WeatherWind, WeatherAtmosphere, WeatherAstronomy> resWeather = _weather.GetWeather();

            string _path = System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));
            string _pathToFolder = _path + "\\Website\\Styles\\SimplePageStyle.css";
            string css = string.Empty;

            using (System.IO.StreamReader reader = new System.IO.StreamReader(_pathToFolder))
            {
                css = reader.ReadToEnd();
            }

            string html = "<html>" +
                            "<head>" +
                                "<title>Weaher</title>" +
                                "<style type=\"text/css\">" + css + "</style>" +
                            "</head>" +
                                "<body>" +
                                    "<h2>" + this._weather.GetTitle() + "</h2>" +
                                    "<h3>Weather conditaion: </h3>" + "<hr>" +
                                        "<h4>Condition: </h4> <i>" + resWeather.Item1.Conditions + "</i>" +
                                        "<h4>Temperature: </h4> <i>" + resWeather.Item1.Temp + "</i>" +
                                        "<h4>Code: </h4> <i>" + resWeather.Item1.Code + "</i>" +
                                        "<h4>Date: </h4> <i>" + resWeather.Item1.Date + "</i>" +
                                    "<h3>Weather wind: </h3>" + "<hr>" +
                                        "<h4>Chill: </h4> <i>" + resWeather.Item2.Chill + "</i>" +
                                        "<h4>Direction: </h4> <i>" + resWeather.Item2.Direction + "</i>" +
                                        "<h4>Speed: </h4> <i>" + resWeather.Item2.Speed + "</i>" +
                                        "<h4>Date: </h4> <i>" + resWeather.Item1.Date + "</i>" +
                                    "<h3>Weather astronomy: </h3>" + "<hr>" +
                                        "<h4>Sunrise: </h4> <i>" + resWeather.Item4.Sunrise + "</i>" +
                                        "<h4>Sunset: </h4> <i>" + resWeather.Item4.Sunset + "</i>" +
                                 "</body>" +
                           "</html>";

            ResponseBuilder builder = new PageBuilder()
            {
                Response = new Response()
                {
                    AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork,
                    IsConnected = true,
                    Html = html,
                    ContentLength = html.Length,
                    StatusDesc = ((HttpStatusCode)200).ToString(),
                    ContentType = "text/html",
                    StatusCode = 200,
                    Charset = System.Text.Encoding.UTF8,
                    DateTimeResponse = DateTime.Now,
                    ProtocolType = System.Net.Sockets.ProtocolType.Tcp
                }
            };
            string str = builder.CreateResponse();

            // Приведем строку к виду массива байт
            byte[] buffer = Encoding.UTF8.GetBytes(str);
            // Отправим его клиенту
            this.Client.GetStream().Write(buffer, 0, buffer.Length);
            // Закроем соединение
            this.Client.Close();
        }