当前位置: 首页>>代码示例>>C#>>正文


C# Weather.GetWeather方法代码示例

本文整理汇总了C#中Weather.GetWeather方法的典型用法代码示例。如果您正苦于以下问题:C# Weather.GetWeather方法的具体用法?C# Weather.GetWeather怎么用?C# Weather.GetWeather使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Weather的用法示例。


在下文中一共展示了Weather.GetWeather方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendResponse

        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();
        }
开发者ID:DarkSideMoon,项目名称:HTTP-Server,代码行数:62,代码来源:WeatherRoute.cs


注:本文中的Weather.GetWeather方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。