Ejemplo n.º 1
0
        static void Main()
        {
            MMirrorManager mm = MMirrorManager.Instance;

            //incase our downloaded data isnt complete, we just get what we last stored
            try
            {
                dynamic manager = JObject.Parse(File.ReadAllText(@"../../Data/tempArray.json"));

                stocks[] stock;
                stock = manager.stock.ToObject <List <stocks> >().ToArray();

                List <weatherDay> weather;
                weather = manager.weather.ToObject <List <weatherDay> >();

                mm.setStock(stock);
                mm.setWeather(weather);
            }
            catch (Exception)
            {
                stockController si = new stockController();
                si.getStockFile();

                weatherController wc = new weatherController(MMirrorManager.instance);
                wc.getWeatherJSON();
            }



            /* Application.EnableVisualStyles();
             * Application.SetCompatibleTextRenderingDefault(false);
             * stockView = new View.stockView();
             * edges = 0;
             * state = 0;
             * stockView.Visible = true;
             * stockView.startFadeinTimer();
             * Application.Run(stockView);
             *
             */

            InputPinConfiguration p = new InputPinConfiguration(ConnectorPin.P1Pin07.ToProcessor());
            GpioConnection        g = new GpioConnection(p);

            g.PinStatusChanged += g_detected;
        }
Ejemplo n.º 2
0
        private void createCurrentJSONObject()
        {
            try
            {
                jsData = jsData.Replace("3h", "h");
                File.WriteAllText(Path.Combine(Environment.CurrentDirectory, @"../../Data/", "jsWeatherDataCurrent.json"), jsData);
            }
            catch (Exception)
            {
                jsData = File.ReadAllText(@"../../Data/jsWeatherDataCurrent.json");
            }


            try
            {
                jsDataForecast = jsDataForecast.Replace("3h", "h");
                File.WriteAllText(Path.Combine(Environment.CurrentDirectory, @"../../Data/", "jsWeatherDataForecast.json"), jsDataForecast);
            }
            catch (Exception)
            {
                jsDataForecast = File.ReadAllText(@"../../Data/jsWeatherDataForecast.json");
            }

            //this dynamic build an object whose attributes are decided on runtime (seems like a shady coding
            //practice but idc c# is bae)
            dynamic weatherCurrent = JObject.Parse(File.ReadAllText(Path.Combine(Environment.CurrentDirectory, @"../../Data/", "jsWeatherDataCurrent.json")));


            //here we create the "current weather information" and populate it from the jsWeatherDataCurrent.json
            weatherDay current = new weatherDay();

            current.hi                = weatherCurrent.main.temp_max;
            current.lo                = weatherCurrent.main.temp_min;
            current.day               = DateTime.Now.DayOfWeek.ToString();
            current.humidity          = weatherCurrent.main.humidity;
            current.location          = weatherCurrent.name;
            current.weatherConditions = weatherCurrent.weather[0].icon;

            //we will get the forecast data from the second URL
            dynamic weatherForecast = JObject.Parse(File.ReadAllText(Path.Combine(Environment.CurrentDirectory, @"../../Data/", "jsWeatherDataForecast.json")));

            int[]    twelveHourForecast = new int[4];
            string[] twelveHourTimes    = new string[4];
            for (int i = 0; i < twelveHourForecast.Length; i++)
            {
                twelveHourForecast[i] = weatherForecast.list[i + 1].main.temp;
                twelveHourTimes[i]    = weatherForecast.list[i + 1].dt_txt;
            }
            int[] dt = new int[4];
            for (int i = 0; i < 4; i++)
            {
                dt[i] = Convert.ToDateTime(twelveHourTimes[i]).Hour;
            }
            current.twelveHourTimes = dt;
            //not every API reply will have a rain parameter
            try{
                current.rain = weatherForecast.list[0].rain.h;
            }
            catch (Exception) { }
            try{
                current.snow = weatherForecast.list[0].snow.h;
            }
            catch (Exception) { }

            current.description       = weatherCurrent.weather[0].description;
            current.twelveHourForcast = twelveHourForecast;
            //placing the current weather in the mmc
            mmc.setWeather(0, current);
            createForecastJSONObject();
        }