Exemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Monitoring App started. OK.");
                Task.Delay(1000);

                //Stage-1:  Get existing records -----------------------------------------------
                operations = new WeatherOperations();
                Task ExistingRecords = Task.Factory.StartNew(() => operations.GetExistingRecords());
                Task.Delay(1000);
                //------------------------------------------------------------------------------


                //Stage-2: SignalR bildrimleri bekle -------------------------------------------
                myHubConnection = new HubConnectionBuilder()
                                  .WithUrl("http://localhost:50217/NotificationHub")
                                  .Build();
                myHubConnection.Closed += MyHubConnection_Closed;
                myHubConnection.On <string>("ReceiveMessageFromServerHub", DataRecieved);
                myHubConnection.StartAsync();
                //------------------------------------------------------------------------------

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Main ERROR !");
                Console.WriteLine(ex.Message);
            }
        }
        public List <DataEx> Get()
        {
            // string lat = "59.913868"; string lon = "10.752245"; //oslo
            string            lat = "51.538320"; string lon = "-0.136910"; //london (camden town)
            WeatherOperations weatherOperations = new WeatherOperations();

            return(weatherOperations.GetWeatherDataOslo(lat, lon));
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var days = DaysGenerator.GetDays();

            Console.WriteLine("============================================");
            Console.WriteLine("Welcome to the Weather App!");
            Console.WriteLine("============================================");
            // The string that will represent the entered command.
            // Will be a substring of input.

            var command = string.Empty;

            Console.WriteLine("Choose a command(first two letters): ");
            Console.WriteLine("--------------------------------------------");
            Console.WriteLine("tc : <Temperature> - Temperature in ∘C");
            Console.WriteLine("ap : <Air Pressure> - Air Pressure in mbar");
            Console.WriteLine("pm : <Precipitation> - Precipitation in mm");
            Console.WriteLine("--------------------------------------------");
            Console.WriteLine("ex : - Exit");
            Console.WriteLine("============================================");

            while (command.ToUpper() != "EX")
            {
                // Read the command.
                Console.Write(">");
                var input = Console.ReadLine();

                if (string.IsNullOrWhiteSpace(input))
                {
                    Environment.Exit(0);
                }

                command = input.Substring(0, 2);
                WeatherOperations.GetInfo(input, days);
            }
            // Exit the application with exit code 0 (no errors).
            Environment.Exit(0);
        }
Exemplo n.º 4
0
        public static void CommandSwitchAp(string input, List <Day> dayList)
        {
            int numOfDays;
            IEnumerable <Day> days;
            var airPressureSum = 0;

            switch (input.ToUpper())
            {
            case "AD":
                Console.WriteLine("Please, enter amount of days:");
                numOfDays = WeatherOperations.GetNumberOfDays(Console.ReadLine());
                days      = dayList.Take(numOfDays);
                foreach (var day in days)
                {
                    Console.WriteLine("Day {0} - Air Pressure: {1} mbar", dayList.IndexOf(day) + 1, day.AirPressure);
                }
                break;

            case "CD":
                Console.WriteLine("Please, enter day number:");
                var dayNumber = WeatherOperations.GetNumberOfDays(Console.ReadLine());
                Console.WriteLine("Day {0} - Air Pressure: {1} mbar", dayNumber, dayList[dayNumber - 1].AirPressure);

                Console.WriteLine("Do you want to edit this entry? (Y/N)");
                var answer = Console.ReadLine();

                if (answer != null && (answer.ToUpper() == "Y" || answer.ToUpper() == "YES"))
                {
                    Console.WriteLine("Please, enter a new value for this day: ");
                    var newDay = WeatherOperations.GetNumberOfPressure(Console.ReadLine());
                    dayList[dayNumber - 1].AirPressure = newDay;

                    Console.WriteLine("Value changed successfully! : Day {0} - Air Pressure: {1} mbar", dayNumber, dayList[dayNumber - 1].AirPressure);

                    Console.WriteLine("Do you want to save changes in a external file? (Y/N)");
                    var saveAnswer = Console.ReadLine();

                    if (saveAnswer != null && (saveAnswer.ToUpper() == "Y" || saveAnswer.ToUpper() == "YES"))
                    {
                        SaveData.SaveAirPressure(dayList);
                        Console.WriteLine("Value saved successfully!");
                    }

                    else if (saveAnswer != null && (saveAnswer.ToUpper() == "N" || saveAnswer.ToUpper() == "NO"))
                    {
                        Environment.Exit(0);
                    }
                    else
                    {
                        Console.WriteLine("Unknown Command " + answer.ToLower());
                        Console.WriteLine("Please, make sure you are using the correct command or try again later.");
                    }
                }
                else
                {
                    Console.WriteLine("No changes commited");
                }

                break;

            case "AA":
                Console.WriteLine("Please, enter amount of days:");
                numOfDays = WeatherOperations.GetNumberOfDays(Console.ReadLine());
                days      = dayList.Take(numOfDays);
                foreach (var day in days)
                {
                    airPressureSum += day.AirPressure;
                }

                var average = airPressureSum / days.Count();
                Console.WriteLine("Average air Pressure for last {0} days: {1} mbar", days.Count(), average);
                break;

            case "DF":
                days = dayList.Take(10);
                foreach (var day in days)
                {
                    Console.WriteLine("Day {0} - Air Pressure: {1} mbar", dayList.IndexOf(day) + 1, day.AirPressure);
                    airPressureSum += day.AirPressure;
                }

                var defaultAverage = airPressureSum / days.Count();
                Console.WriteLine("Average air Pressure for last 10 days: {0} mbar", defaultAverage);
                Console.WriteLine();
                break;

            case "EX":
            {
                Console.WriteLine("Application closing...");
                Environment.Exit(0);
                break;
            }

            default:
                Console.WriteLine("Unknown Command " + input.ToLower());
                Console.WriteLine("Please, make sure you are using the correct command or try again later.");
                break;
            }
        }