public void GetSitesTest() { var sites = IoCContainer.GetSites(WeatherParameter.Current); Assert.IsNotNull(sites); Assert.IsTrue(sites.Count == 3); Assert.IsNotNull(sites.Find(x => x.Name == "OpenWeather")); Assert.IsNotNull(sites.Find(x => x.Name == "TomorrowIO")); Assert.IsNotNull(sites.Find(x => x.Name == "StormGlass")); }
public void RemoveSiteFromContainerTest() { IoCContainer.RemoveSiteFromContainer(SitesName.TomorrowIO); var sites = IoCContainer.GetSites(WeatherParameter.Current); Assert.IsNotNull(sites); Assert.IsTrue(sites.Count == 2); Assert.IsNotNull(sites.Find(x => x.Name == "OpenWeather")); Assert.IsNull(sites.Find(x => x.Name == "TomorrowIO")); Assert.IsNotNull(sites.Find(x => x.Name == "StormGlass")); }
public void GetSitesTest() { List <ISite> sites = IoCContainer.GetSites().ToList(); Assert.IsNotNull(sites); var types = sites.Select(x => x.GetType()).ToList(); Assert.AreEqual(types.Count, 3); Assert.True(types.Contains(typeof(OpenWeatherMap))); Assert.True(types.Contains(typeof(TomorrowIO))); Assert.True(types.Contains(typeof(StormGlassIO))); }
private void UpdateButton_Click(object sender, RoutedEventArgs e) { forecasts.Clear(); if (updateSites) { sites = IoCContainer.GetSites(currentParameter); } foreach (var site in sites) { forecasts.Add(site.GetCityWeatherForecast()); } ChangeCurrentForecast(); }
private void UpdateButton_Click(object sender, EventArgs e) { forecasts.Clear(); if (requestSitesFlag) { sites = IoCContainer.GetSites(displayer.Parameter); } foreach (var site in sites) { forecasts.Add(site.GetCityWeatherForecast()); } if (this.Controls.Contains(weatherInfo)) { ChangeCurrentForecasts(); } }
public static void Main() { IEnumerable <ISite> sites; Console.WriteLine("This program shows data (temperature (degrees and Fahrenheit), clouds, humidity, precipitation,\nwind direction and speed) of the current weather in the city of St. Petersburg from three different sources."); string sources = "===> openweathermap, tomorrow.io, stormglass.io <==="; Console.ForegroundColor = ConsoleColor.DarkCyan; PrintTools.PrintCentrally(sources); Console.ResetColor(); Console.WriteLine(); while (true) { Console.ForegroundColor = ConsoleColor.Green; string?availableServices = IoCContainer.Sites.FirstOrDefault()?.Name; for (int i = 1; i < IoCContainer.Sites.Count; i++) { availableServices = availableServices + ", " + IoCContainer.Sites[i].Name; } if (availableServices is not null) { PrintTools.PrintCentrally($"{availableServices} are connected."); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("None of the sites are connected."); } Console.ResetColor(); sites = IoCContainer.GetSites(); foreach (var site in sites) { PrintTools.PrintCentrally($"Requesting data from the site: {site.SiteAddress} ..."); site.GetRequest(); PrintTools.PrintCentrally("The data is being processed..."); site.Parse(); } Console.WriteLine(); PrintTools.PrintForecast(sites.ToList()); Console.WriteLine(); PrintTools.PrintCentrally("Press the Esc key to exit the application, the A key to go to adding sites,"); PrintTools.PrintCentrally("the D key to go to deleting sites or any other key to update the weather data"); ConsoleKey usersRequest = Console.ReadKey(true).Key; Console.Clear(); if (usersRequest == ConsoleKey.Escape) { break; } else if (usersRequest == ConsoleKey.A || usersRequest == ConsoleKey.D) { List <Type> types = new List <Type>(); Console.ForegroundColor = ConsoleColor.DarkBlue; PrintTools.PrintCentrally("You are in the services setup menu, to exit from here, type \"exit\"."); PrintTools.PrintCentrally("To interact with the website service, just type its name (for example: \"OpenWeatherMap\", \"TomorrowIO\" or \"StormGlassIO\")"); Console.ResetColor(); Console.WriteLine(); while (true) { Type?type; bool conditionToExit; if (usersRequest == ConsoleKey.A) { Console.Write("Add a site with the name: "); } else { Console.Write("Delete a site with the name: "); } (type, conditionToExit) = UserInputHandler.ReadType(Console.ReadLine()); if (conditionToExit) { Console.WriteLine("You are exiting the service setup menu..."); break; } Console.ForegroundColor = ConsoleColor.Red; if (type is not null) { if (usersRequest == ConsoleKey.A) { if (IoCContainer.ConnectSite(type)) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Service successfully added."); } else { Console.WriteLine("Service was already available."); } } else { if (IoCContainer.DisconnectSite(type)) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Service successfully deleted"); } else { Console.WriteLine("Service was already unavailable."); } } } else { Console.WriteLine("The web service with this name was not found, try again...\navailable services: >>> OpenWeatherMap, TomorrowIO, StormGlassIO <<<\ncommands: >> exit << "); } Console.ResetColor(); } } Console.Clear(); } Console.ForegroundColor = ConsoleColor.Magenta; PrintTools.PrintCentrally("I hope these sources helped you, thank you for using my application, see you soon ^_^"); Console.ResetColor(); }
public static void Main() { Console.WriteLine("The program shows the weather from 3 source\n"); var sites = IoCContainer.GetSites(WeatherParameter.Current); bool flag = true; bool updateFlag = true; bool changedFlag = false; while (flag) { if (updateFlag) { foreach (var site in sites) { Console.WriteLine(Tool.ConvertWeatherToString(site.GetCityWeatherForecast())); } updateFlag = false; } if (changedFlag) { sites = IoCContainer.GetSites(WeatherParameter.Current); changedFlag = false; } Console.WriteLine("If you want to update data from sites, then write - 'Update'.\nAvailable sites: OpenWeather, StormGlass, TomorrowIO\n" + "You may add or delete site using such command: 'Add [site name]' or 'Delete [site Name]'\nYou can also view the sites " + "from which data is requested using command: 'Sites'\nIf you want to close the program, then write - 'Exit'.\n"); var userAnswer = Console.ReadLine().ToLower(); var commands = userAnswer.Split(" "); while (userAnswer.Last() == ' ') { userAnswer = userAnswer.Remove(userAnswer.Length - 1); } while (userAnswer != "exit" && userAnswer != "update" && !Tool.CheckCommand(commands)) { Console.WriteLine("Wrong command. Try again, please.\nIf you want to update data from sites, then write - 'Update'.\n" + "You may add or delete site using such command: 'Add [site name]' or 'Delete [site name]'\nYou can also view " + "the sites from which data is requested using command: 'Sites'\nIf you want to close the program, then write - 'Exit'.\n"); userAnswer = Console.ReadLine().ToLower().Replace(" ", ""); commands = userAnswer.Split(" "); while (userAnswer.Last() == ' ') { userAnswer.Remove(userAnswer.Length - 1); } } if (userAnswer == "exit") { flag = false; } else if (commands[0] == "sites") { Console.Write("\nThese sites are connected: "); foreach (var site in sites) { Console.Write(site.Name + " "); } Console.WriteLine("\n"); } else if (commands[0] == "add") { var name = Tool.GetSite(commands[1]); if (IoCContainer.ConnectedSites.Contains(name)) { Console.WriteLine("\nThis site is alreade connected :)"); } else { IoCContainer.AddSiteToContainer(name); changedFlag = true; } Console.WriteLine("\n"); } else if (commands[0] == "delete") { var name = Tool.GetSite(commands[1]); if (!IoCContainer.ConnectedSites.Contains(name)) { Console.WriteLine("\nThis site is alreade disconnected :)"); } else { IoCContainer.RemoveSiteFromContainer(name); changedFlag = true; } Console.WriteLine("\n"); } else if (commands[0] == "update") { updateFlag = true; } } Console.WriteLine("\nThat's all! Thank you!\n"); return; }