Exemplo n.º 1
0
        //public WeatherData[] WeatherDataToday()
        //{

        //    WeatherToday today = new WeatherToday();
        //    WeatherData[] DataToday = DefineWeather(today.Url, today.XPathTemp_1, null, today.XPathPressure,
        //                                               today.XPathWindSpeed, null, today.XPathWindDirection, today.XPathHumidity, null, (int)Param.param3Days);
        //    return DataToday;
        //}
        //public WeatherData[] WeatherDataTomorrow()
        //{

        //    WeatherTomorrow tomorrow = new WeatherTomorrow();
        //    WeatherData[] DataTomorrow = DefineWeather(tomorrow.Url, tomorrow.XPathTemp_1, null, tomorrow.XPathPressure,
        //                                               tomorrow.XPathWindSpeed, null, tomorrow.XPathWindDirection, tomorrow.XPathHumidity, null, (int)Param.param3Days);
        //    return DataTomorrow;
        //}
        //public WeatherData[] WeatherDataDayAfterTomorrow()
        //{

        //    WeatherDayAfterTomorrow dayAfterTomorrow = new WeatherDayAfterTomorrow();
        //    WeatherData[] DataDayAfterTomorrow = DefineWeather(dayAfterTomorrow.Url, dayAfterTomorrow.XPathTemp_1, null, dayAfterTomorrow.XPathPressure,
        //                                               dayAfterTomorrow.XPathWindSpeed, null, dayAfterTomorrow.XPathWindDirection, dayAfterTomorrow.XPathHumidity, null, (int)Param.param3Days);
        //    return DataDayAfterTomorrow;
        //}
        //public WeatherData[] WeatherData4Day()
        //{

        //    Weather4Day w4day = new Weather4Day();
        //    WeatherData[] Data4Day = DefineWeather(w4day.Url, w4day.XPathTemp_1, null, w4day.XPathPressure,
        //                                               w4day.XPathWindSpeed, null, w4day.XPathWindDirection, w4day.XPathHumidity, null, (int)Param.param3Days);
        //    return Data4Day;
        //}
        public WeatherData[] GetWeatherData(string url)
        {
            WeatherLink weather = new WeatherLink();

            WeatherData[] weatherData = DefineWeather(url, weather.XPathTemp_1, null, weather.XPathPressure,
                                                      weather.XPathWindSpeed, null, weather.XPathWindDirection, weather.XPathHumidity, null, (int)Param.paramDays);
            return(weatherData);
        }
Exemplo n.º 2
0
        public void SaveWeather()
        {
            string pathMain = @"C:/MonitoringWeather";

            if (!Directory.Exists(pathMain))
            {
                Directory.CreateDirectory(pathMain);
            }

            using (FileStream fileTemperature = File.Open("C:/MonitoringWeather/Temperature.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite))
                using (FileStream filePressure = File.Open("C:/MonitoringWeather/Pressure.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite))
                    using (FileStream fileWindSpeed = File.Open("C:/MonitoringWeather/WindSpeed.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite))
                        using (FileStream fileWindDirection = File.Open("C:/MonitoringWeather/WindDirection.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite))
                            using (FileStream fileHumidity = File.Open("C:/MonitoringWeather/Humidity.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite))
                            {
                                ;
                            }

            WeatherLink weather = new WeatherLink();

            string[] weatherUrls = weather.WeatherUrls;

            DateTime today = DateTime.Now;

            int countForDay = 0;

            foreach (string url in weatherUrls)
            {
                WeatherData[] Data = GetWeatherData(url);

                foreach (WeatherData data in Data)
                {
                    using (StreamWriter fileTemperature = new StreamWriter("C:/MonitoringWeather/Temperature.txt", true))
                    {
                        if (countForDay == 0)
                        {
                            fileTemperature.WriteLine();
                        }
                        if (countForDay % 8 == 0)
                        {
                            fileTemperature.Write($"{today.ToShortDateString()} ");
                        }
                        fileTemperature.Write($"{data.Temperature} ");
                    }

                    using (StreamWriter filePressure = new StreamWriter("C:/MonitoringWeather/Pressure.txt", true))
                    {
                        if (countForDay == 0)
                        {
                            filePressure.WriteLine();
                        }
                        if (countForDay % 8 == 0)
                        {
                            filePressure.Write($"{today.ToShortDateString()} ");
                        }
                        filePressure.Write($"{data.Pressure} ");
                    }

                    using (StreamWriter fileWindSpeed = new StreamWriter("C:/MonitoringWeather/WindSpeed.txt", true))
                    {
                        if (countForDay == 0)
                        {
                            fileWindSpeed.WriteLine();
                        }
                        if (countForDay % 8 == 0)
                        {
                            fileWindSpeed.Write($"{today.ToShortDateString()} ");
                        }
                        if (data.WindSpeed_2 != 0)
                        {
                            fileWindSpeed.Write($"{data.WindSpeed_1} - {data.WindSpeed_2} ");
                        }
                        else
                        {
                            fileWindSpeed.Write($"{data.WindSpeed_1} ");
                        }
                    }

                    using (StreamWriter fileWindDirection = new StreamWriter("C:/MonitoringWeather/WindDirection.txt", true))
                    {
                        if (countForDay == 0)
                        {
                            fileWindDirection.WriteLine();
                        }
                        if (countForDay % 8 == 0)
                        {
                            fileWindDirection.Write($"{today.ToShortDateString()} ");
                        }
                        fileWindDirection.Write($"{data.WindDirection} ");
                    }

                    using (StreamWriter fileHumidity = new StreamWriter("C:/MonitoringWeather/Humidity.txt", true))
                    {
                        if (countForDay == 0)
                        {
                            fileHumidity.WriteLine();
                        }
                        if (countForDay % 8 == 0)
                        {
                            fileHumidity.Write($"{today.ToShortDateString()} ");
                        }
                        fileHumidity.Write($"{data.Humidity} ");
                    }
                    ++countForDay;
                }
                today = today.AddDays(1);
            }
        }
Exemplo n.º 3
0
        public void Output_3Days() //вывод погоды "Сегодня, Завтра, Послезавтра"
        {
            List <string[]> data3Days = new List <string[]>();

            WeatherLink weather = new WeatherLink();

            string[] weatherUrls = weather.WeatherUrls;

            DateTime today = DateTime.Now;

            StringBuilder date          = new StringBuilder($"{today.Day}.{today.Month}.{today.Year} ");
            StringBuilder temperature   = new StringBuilder("Температура ");
            StringBuilder pressure      = new StringBuilder("Давление ");
            StringBuilder windSpeed     = new StringBuilder("Скорость_ветра ");
            StringBuilder windDirection = new StringBuilder("Направление_ветра ");
            StringBuilder humidity      = new StringBuilder("Влажность ");


            for (int i = 0; i < 3; ++i)
            {
                string        url  = weatherUrls[i];
                WeatherData[] Data = GetWeatherData(url);

                int hour = 1;
                foreach (WeatherData data in Data)
                {
                    date.Append($"{hour}.00 ");
                    temperature.Append($"{data.Temperature} ");

                    pressure.Append($"{data.Pressure} ");

                    if (data.WindSpeed_2 != 0)
                    {
                        windSpeed.Append($"{data.WindSpeed_1}-{data.WindSpeed_2} ");
                    }
                    else
                    {
                        windSpeed.Append($"{data.WindSpeed_1} ");
                    }

                    windDirection.Append($"{data.WindDirection} ");

                    humidity.Append($"{data.Humidity} ");

                    hour += 3;
                }
                if (i != 2)
                {
                    today = today.AddDays(1);
                    date.Append($"{today.Day}.{today.Month}.{today.Year} ");
                }
            }


            data3Days.Add(date.ToString().Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
            data3Days.Add(temperature.ToString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
            data3Days.Add(pressure.ToString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
            data3Days.Add(windSpeed.ToString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
            data3Days.Add(windDirection.ToString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
            data3Days.Add(humidity.ToString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));

            var dt = new DataTable();

            int columnCount = data3Days[0].Length;

            for (int i = 0; i < columnCount; ++i)
            {
                dt.Columns.Add();
            }

            StringBuilder str = new StringBuilder();

            for (int i = 0; i < data3Days.Count; ++i)
            {
                if (i > 0)
                {
                    for (int j = 0; j < data3Days[i].Length; ++j)
                    {
                        if ((j - 1) % 8 == 0 && (j - 1) != 0)
                        {
                            str.Append(" _ ");
                        }

                        str.Append($"{data3Days[i][j]} ");
                    }

                    dt.Rows.Add(str.ToString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
                    str.Clear();
                }
                else
                {
                    dt.Rows.Add(data3Days[i]);
                }
            }

            dataGrid.DataContext = dt.DefaultView;

            dataGrid.HeadersVisibility = DataGridHeadersVisibility.None;
        }