public IActionResult Index(string city, int value)
        {
            var viewModel = new ApplicationWeather();

            if (value == 1)
            {
                var weatherResponse = GetNow.GetWeather(city, 1);

                if (weatherResponse != null)
                {
                    viewModel.CityName    = weatherResponse.Name;
                    viewModel.Temp        = weatherResponse.Main.Temp;
                    viewModel.Weather     = weatherResponse.Weather[0].Main;
                    viewModel.Description = weatherResponse.Weather[0].Description;
                }
                return(View(viewModel));
            }

            else if (value == 2)
            {
                var weatherResponse = GetTomorrow.GetWeather(city, 2);

                if (weatherResponse != null)
                {
                    viewModel.CityName    = weatherResponse.city.name;
                    viewModel.Temp        = weatherResponse.list[6].main.temp;
                    viewModel.Weather     = weatherResponse.list[6].weather[0].main;
                    viewModel.Description = weatherResponse.list[6].weather[0].description;
                }
                return(View(viewModel));
            }

            return(View(viewModel));
        }
Esempio n. 2
0
 /// <summary>Constructor</summary>
 /// <param name="capacity">the normal item limit for cache (Count may exeed capacity due to minAge)</param>
 /// <param name="minAge">the minimium time after an access before an item becomes eligible for removal, during this time
 /// the item is protected and will not be removed from cache even if over capacity</param>
 /// <param name="maxAge">the max time that an object will sit in the cache without being accessed, before being removed</param>
 /// <param name="getNow">A delegate to get the current time.</param>
 /// <param name="validateCache">
 /// An optional delegate used to determine if cache is out of date. Is called before index access not more than once per 10 seconds
 /// </param>
 public FluidCache(int capacity, TimeSpan minAge, TimeSpan maxAge, GetNow getNow, IsValid validateCache = null)
 {
     lifeSpan = new LifespanManager <T>(this, capacity, minAge, maxAge, getNow)
     {
         ValidateCache = validateCache
     };
 }
        public LifespanManager(FluidCache <T> owner, int capacity, TimeSpan minAge, TimeSpan maxAge, GetNow getNow)
        {
            this.owner = owner;
            double maxMS = Math.Min(maxAge.TotalMilliseconds, (double)12 * 60 * 60 * 1000);  // max = 12 hours

            this.minAge           = minAge;
            this.getNow           = getNow;
            this.maxAge           = TimeSpan.FromMilliseconds(maxMS);
            validatyCheckInterval = TimeSpan.FromMilliseconds(maxMS / 240.0); // max timeslice = 3 min
            bagItemLimit          = Math.Max(capacity / 20, 1);               // max 5% of capacity per bag

            const int nrBags = 265;                                           // based on 240 timeslices + 20 bags for ItemLimit + 5 bags empty buffer

            bags = new OrderedAgeBagCollection <T>(nrBags);

            Stats = new CacheStats(capacity, nrBags, bagItemLimit, minAge, this.maxAge, validatyCheckInterval);

            OpenBag(0);
        }
Esempio n. 4
0
        private const int nrBags = 265; // based on 240 timeslices + 20 bags for ItemLimit + 5 bags empty buffer

        public LifespanManager(FluidCache <T> owner, TimeSpan minAge, TimeSpan maxAge, GetNow getNow)
        {
            this.owner = owner;
            int maxMS = Math.Min((int)maxAge.TotalMilliseconds, 12 * 60 * 60 * 1000); // max = 12 hours

            this.minAge           = minAge;
            this.getNow           = getNow;
            this.maxAge           = TimeSpan.FromMilliseconds(maxMS);
            validatyCheckInterval = TimeSpan.FromMilliseconds(maxMS / 240.0); // max timeslice = 3 min
            bagItemLimit          = this.owner.Capacity / 20;                 // max 5% of capacity per bag
            bags = new AgeBag <T> [nrBags];

            for (int loop = nrBags - 1; loop >= 0; --loop)
            {
                bags[loop] = new AgeBag <T>();
            }

            OpenCurrentBag(getNow(), 0);
        }
Esempio n. 5
0
        public static string SetAuthenticated(string username, string firstname, string lastname, int status, int time = 60)
        {
            if (string.IsNullOrEmpty(username))
            {
                Authentication._User  = null;
                Authentication._Token = null;
                return(null);
            }

            Authentication._Token = Securities.JWTEncode(
                new Authentication {
                username  = username,
                firstname = firstname,
                lastname  = lastname,
                status    = status,
                exp       = GetNow.AddMinutes(time).ToBinary()
            });

            return(Authentication._Token);
        }
Esempio n. 6
0
        public static string SetAuthenticated(User custObj, int time = 60 *24 *365)
        {
            if (custObj == null)
            {
                Authentication._User  = null;
                Authentication._Token = null;
                return(null);
            }

            Authentication._Token = Securities.JWTEncode(
                new Authentication
            {
                username = custObj.username,
                Countday = custObj.Count_Expire_day,
                ep_day   = custObj.Expire_dt,
                exp      = GetNow.AddMinutes(time).ToBinary()
            });
            Authentication._User = custObj;

            return(Authentication._Token);
        }
Esempio n. 7
0
        public static string SetAuthenticated(Users custObj, int time = 60)
        {
            if (custObj == null)
            {
                Authentication._User  = null;
                Authentication._Token = null;
                return(null);
            }

            Authentication._Token = Securities.JWTEncode(
                new Authentication {
                username  = custObj.username,
                firstname = custObj.firstname,
                lastname  = custObj.lastname,
                status    = custObj.user_type_id,
                exp       = GetNow.AddMinutes(time).ToBinary()
            });
            Authentication._User = custObj;

            return(Authentication._Token);
        }
Esempio n. 8
0
        public LifespanManager(FluidCache <T> owner, int capacity, TimeSpan minAge, TimeSpan maxAge, GetNow getNow)
        {
            this.owner  = owner;
            this.minAge = minAge;
            this.getNow = getNow;

            this.maxAge = TimeSpan.FromMilliseconds(Math.Min(maxAge.TotalMilliseconds, MaxMaxAge.TotalMilliseconds));

            validatyCheckInterval =
                TimeSpan.FromMilliseconds(Math.Min(maxAge.TotalMilliseconds, MaxInterval.TotalMilliseconds));

            bagItemLimit = Math.Max(capacity / PreferedNrOfBags, 1);

            int nrTimeSlices = (int)(MaxMaxAge.TotalMilliseconds / MaxInterval.TotalMilliseconds);

            // NOTE: Based on 240 timeslices + 20 bags for ItemLimit + 5 bags empty buffer
            int nrBags = nrTimeSlices + PreferedNrOfBags + EmptyBagsBuffer;

            bags = new OrderedAgeBagCollection <T>(nrBags);

            Stats = new CacheStats(capacity, nrBags, bagItemLimit, minAge, this.maxAge, validatyCheckInterval);

            OpenBag(0);
        }