Beispiel #1
0
        public FiveDayForecast fivedayforecast(string queryStr)
        {
            _cache = new CachingService();
            var key = queryStr;

            return(_cache.GetOrAdd(key, () =>
            {
                FiveDayForecast newQuery = new FiveDayForecast(openWeatherAPIKey, queryStr);
                if (newQuery.ValidRequest)
                {
                    return newQuery;
                }
                return null;
            }, new TimeSpan(3, 0, 0)));
        }
Beispiel #2
0
        private void DetectFieldsAndGetForecastDataHorizontally(int cityRow, int cityCounter, int cityColumn, int maxFieldCount)
        {
            var valuesOfTemperature = myDomainFields.GetValues("Temperature");
            var valuesOfWindSpeed   = myDomainFields.GetValues("Wind Speed");
            var valuesOfHumidity    = myDomainFields.GetValues("Humidity");
            var valuesOfSunset      = myDomainFields.GetValues("Sunset");
            var valuesOfDescription = myDomainFields.GetValues("Description");
            var valuesOfCity        = myDomainFields.GetValues("City");


            OpenWeatherAPI openWeatherAPI = new OpenWeatherAPI(getAPIKey());
            Worksheet      currentSheet   = Globals.ThisAddIn.getActiveWorkSheet();

            for (int fieldIndex_R = cityRow; fieldIndex_R <= cityRow + cityCounter; fieldIndex_R++)
            {
                if (IsCity(currentSheet.Cells[fieldIndex_R + 1, cityColumn].Value))
                {
                    //isHorizontal = true;
                    FiveDayForecast fivedayforecast   = openWeatherAPI.fivedayforecast(currentSheet.Cells[fieldIndex_R + 1, cityColumn].Value);
                    int             temperatureColumn = cityColumn + 1;
                    int             humidityColumn    = cityColumn + 2;
                    int             descriptionColumn = cityColumn + 3;
                    int             windColumn        = cityColumn + 4;
                    int             dateColumn        = cityColumn + 5;
                    int             fieldsRow         = cityRow + 1;

                    currentSheet.Cells[cityRow, temperatureColumn].Value = "Temperature";
                    currentSheet.Cells[cityRow, humidityColumn].Value    = "Humidity";
                    currentSheet.Cells[cityRow, descriptionColumn].Value = "Description"; //TODO:Add icon later.
                    currentSheet.Cells[cityRow, windColumn].Value        = "Wind Speed";  //TODO:Add icon.
                    currentSheet.Cells[cityRow, dateColumn].Value        = "Date";

                    foreach (var item in fivedayforecast.forecastList)
                    {
                        currentSheet.Cells[fieldsRow, humidityColumn].Value = item.
                                                                              currentSheet.Cells[fieldsRow, temperatureColumn] = checkedTempUnitIntoQuery(main.Temperature.celsiusCurrent);



                        currentSheet.Cells[fieldsRow, descriptionColumn].Value = weather.Description;



                        currentSheet.Cells[fieldsRow, windColumn].Value = fivedayforecast.Wind.SpeedMetersPerSecond;



                        currentSheet.Cells[fieldsRow, dateColumn].Value = date;
                        fieldsRow++;
                    }
                }
                else if (Array.IndexOf(valuesOfCity, currentSheet.Cells[fieldIndex_R + 1, cityColumn].Value) >= 0)
                {
                    break;
                }
                else
                {
                    continue;
                }
            }
            currentSheet.Columns.AutoFit();
        }