Exemplo n.º 1
0
        public void LoadSettings()
        {
            _settings = new Dictionary <string, Setting>();

            if (_userProvider.Username != null && _localStorage.ContainKey("SettingsData." + _userProvider.Username))
            {
                var settings = _localStorage.GetItem <Dictionary <string, Setting> >("SettingsData." + _userProvider.Username);
                foreach (var setting in settings)
                {
                    _settings[setting.Key] = setting.Value;
                }
            }

            if (_localStorage.ContainKey("SettingsData"))
            {
                var settings = _localStorage.GetItem <Dictionary <string, Setting> >("SettingsData");
                foreach (var setting in settings)
                {
                    setting.Value.Inherited = _userProvider.Username == null;
                    _settings[setting.Key]  = setting.Value;
                }
            }

            SettingsUpdated?.Invoke(this, new SettingsEventArgs
            {
                Settings = _settings.Values.ToArray()
            });
        }
        public AuthCredentialsKeeper(ISyncLocalStorageService localStorage)
        {
            _localStorage = localStorage;

            if (_localStorage.ContainKey(INDEX_USERNAME) && _localStorage.ContainKey(INDEX_TOKEN))
            {
                Username = _localStorage.GetItem <string>(INDEX_USERNAME);
                Token    = _localStorage.GetItem <string>(INDEX_TOKEN);
            }
        }
Exemplo n.º 3
0
        public bool CheckUserAuthenticatedAsync()
        {
            string authenticationToken = _localStorage
                                         .GetItem <string>("AuthenticationToken");

            DateTime expiresOn = _localStorage
                                 .GetItem <DateTime>("ExpiresOn");

            if (authenticationToken != null && authenticationToken.Length > 0 && expiresOn >= DateTime.Now)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        public Career GetCurrentCareer()
        {
            CareerDto currentGame = _localStorageService
                                    .GetItem <CareerDto>(LocalStorageKeys.CURRENT_CAREER);

            return(_mapper.Map <Career>(currentGame));
        }
Exemplo n.º 5
0
        public NotesController(List <Note> notes, ISyncLocalStorageService localStorage)
        {
            LocalStorage = localStorage;
            var te = localStorage.GetItem <List <Note> >("notes");

            Notes = te ?? new List <Note>();
        }
Exemplo n.º 6
0
        public T GetLocal <T>(string key)
        {
            string encryptData = _syncLocalStorageService.GetItem <string>(key);
            var    data        = JsonSerializer.Deserialize <T>(_encryptionService.Decrypt(encryptData));

            return(data);
        }
Exemplo n.º 7
0
        public Options(ISyncLocalStorageService localStorage, NavigationManager navigationManager, string inititalCosmos = null)
        {
            this.localStorage      = localStorage;
            this.navigationManager = navigationManager;
            IsHideValue            = localStorage.GetItem <bool>(HideValueKey);
            IsMonochrome           = localStorage.GetItem <bool>(MonochromeKey);

            if (inititalCosmos is null)
            {
                Cosmos = localStorage.GetItem <string>(CosmosKey);
            }
            else
            {
                Cosmos = inititalCosmos;
            }
        }
        public string LoadContent()
        {
            lock (thisLock)
            {
                string path = GetFileName();

                return(localStorage.GetItem <string>(path) ?? "");
            }
        }
Exemplo n.º 9
0
        private List <CartItemModel> ReadCartItemsFromLocalStorage()
        {
            if (localStorage.ContainKey(LocalStorageConstants.CartItems))
            {
                return(localStorage.GetItem <List <CartItemModel> >(LocalStorageConstants.CartItems));
            }

            return(new List <CartItemModel>());
        }
Exemplo n.º 10
0
        private async Task LoadRouteData()
        {
            await updateLock.WaitAsync();

            try
            {
                if (_userProvider.UserDetails != null && !_shipProvider.DataRefreshing)
                {
                    Dictionary <int, AutoRoute> newRouteData = null;
                    if (_localStorage.ContainKey("RouteData." + _userProvider.Username))
                    {
                        newRouteData = _localStorage.GetItem <Dictionary <int, AutoRoute> >("RouteData." + _userProvider.Username);
                    }
                    newRouteData ??= new Dictionary <int, AutoRoute>();

                    if (newRouteData != null)
                    {
                        foreach (var route in newRouteData)
                        {
                            foreach (var routeShip in route.Value.Ships)
                            {
                                routeShip.ShipData = _shipProvider.GetShipData(routeShip.ShipId);
                            }
                        }
                        foreach (var route in newRouteData)
                        {
                            route.Value.Ships = route.Value.Ships.Where(t => t.ShipData != null).ToArray();
                        }
                    }

                    _routeData = newRouteData;

                    SaveRouteData();
                }
                else
                {
                    _routeData = null;
                }

                RoutesUpdated?.Invoke(this, new RouteEventArgs
                {
                    Routes        = GetRouteData(),
                    IsFullRefresh = true
                });
            }
            finally
            {
                updateLock.Release();
            }
        }
Exemplo n.º 11
0
        private bool CheckToken()
        {
            string token = _localstorage.GetItem <string>(Constants.ACCESS_TOKEN_NAME);

            if (token is null or "null")
            {
                return(false);
            }
            try
            {
                var decoder = new JwtDecoder(new CustomJsonSerializer(), new JwtBase64UrlEncoder());
                var data    = decoder.DecodeToObject(token);
                data.TryGetValue("nbf", out object?_nbf);
                data.TryGetValue("exp", out object?_exp);

                if (_nbf != null && _exp != null)
                {
                    var nbf = DateTimeOffset.FromUnixTimeSeconds((_nbf as JsonElement?).GetValueOrDefault().GetInt64());
                    var exp = DateTimeOffset.FromUnixTimeSeconds((_exp as JsonElement?).GetValueOrDefault().GetInt64());
                    var now = DateTimeOffset.Now;
                    if (now < nbf)
                    {
                        return(false);
                    }
                    if (now > exp)
                    {
                        return(false);
                    }
                }
                if (_exp != null && _nbf == null)
                {
                    var exp = DateTimeOffset.FromUnixTimeSeconds((_exp as JsonElement?).GetValueOrDefault().GetInt64());
                    var now = DateTimeOffset.Now;
                    if (now > exp)
                    {
                        return(false);
                    }
                }
                if (_exp == null)
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine($"Check Token Exception: {e.Message} - {e.StackTrace}");
                return(false);
            }
            return(true);
        }
        public string LoadContent()
        {
            lock (thisLock)
            {
                string path = GetFileName();

                var data = localStorage.GetItem <string>(path);
                if (!string.IsNullOrEmpty(data))
                {
                    return(Decrypt(data));
                }

                return("");
            }
        }
Exemplo n.º 13
0
        public void Load()
        {
            var store = _localStorage.GetItem <UserProfile>("UserProfile");

            if (store != null)
            {
                _profile = store;
            }
            else
            {
                _profile = new UserProfile()
                {
                    UserId = Guid.NewGuid().ToString()
                }
            };
        }
Exemplo n.º 14
0
 public static string GetTokenType(this ISyncLocalStorageService localStorage)
 {
     return(localStorage.GetItem <string>(LocalStorageConstants.TokenType));
 }
Exemplo n.º 15
0
 public T Load <T>(string key)
 {
     return(_syncLocalStorageService.GetItem <T>(key));
 }
        public string Read()
        {
            var text = localStorage.GetItem <string>("TEXT");

            return(text);
        }
Exemplo n.º 17
0
 public string GetGuestUserName()
 {
     return(_syncLocalStorageService.GetItem <string>(_localStorageKey));
 }
Exemplo n.º 18
0
 public OpenWeatherApi(HttpClient httpClient, ISyncLocalStorageService localStorageService)
 {
     _httpClient        = httpClient;
     _openWeatherApiKey = localStorageService.GetItem <string>(Constants.KeyName_WeatherApiKey);
 }
Exemplo n.º 19
0
        public async Task RefreshShipData()
        {
            DataRefreshing = true;

            if (_userProvider.UserDetails != null)
            {
                Dictionary <string, ShipData> newShipData = null;
                var shipResponse = await _http.GetFromJsonAsync <ShipsResponse>("/my/ships", _serializerOptions);

                var ships = shipResponse?.Ships;

                if (_localStorage.ContainKey("ShipData." + _userProvider.Username))
                {
                    newShipData = _localStorage.GetItem <Dictionary <string, ShipData> >("ShipData." + _userProvider.Username);
                }
                newShipData ??= new Dictionary <string, ShipData>();

                if (newShipData.Count > 0)
                {
                    if (ships == null)
                    {
                        newShipData.Clear();
                    }
                    else
                    {
                        var shipsToRemove = newShipData.Keys.Where(t => !ships.Any(s => t == s.Id)).ToArray();
                        foreach (var key in shipsToRemove)
                        {
                            newShipData.Remove(key);
                        }
                    }
                }

                var takenIds = new List <int>();
                foreach (var ship in newShipData)
                {
                    if (takenIds.Contains(ship.Value.Id))
                    {
                        ship.Value.Id = GetNewShipId(newShipData.Values.ToArray());
                    }
                    takenIds.Add(ship.Value.Id);
                }

                if (ships != null)
                {
                    var shipsToAdd = ships.Where(t => !newShipData.ContainsKey(t.Id)).ToArray();
                    var currentIds = newShipData.Select(s => s.Value.Id);
                    for (var x = 0; x < shipsToAdd.Length; x++)
                    {
                        newShipData.Add(shipsToAdd[x].Id, new ShipData
                        {
                            Id          = GetNewShipId(newShipData.Values.ToArray()),
                            DisplayName = shipsToAdd[x].Id,
                            ServerId    = shipsToAdd[x].Id,
                        });
                    }
                }

                var timeNow = DateTimeOffset.UtcNow;
                foreach (var ship in newShipData)
                {
                    ship.Value.Ship = ships.First(t => t.Id == ship.Key);

                    if (ship.Value.Ship.Location == null && ship.Value.LastFlightPlan?.Id != ship.Value.Ship.FlightPlanId)
                    {
                        ship.Value.LastFlightPlan = null;

                        try
                        {
                            var flightPlanResponse = await _http.GetFromJsonAsync <FlightResponse>("/my/flight-plans/" + ship.Value.Ship.FlightPlanId, _serializerOptions);

                            ship.Value.LastFlightPlan = flightPlanResponse.FlightPlan;
                        }
                        catch (Exception) { }
                    }

                    if (ship.Value.LastFlightPlan != null)
                    {
                        ship.Value.LastFlightPlan.TimeRemainingInSeconds = (int)Math.Ceiling(ship.Value.LastFlightPlan.ArrivesAt.Subtract(timeNow).TotalSeconds);
                    }
                    ship.Value.FlightEnded = ship.Value.Ship.Location != null || ship.Value.LastFlightPlan == null || ship.Value.LastFlightPlan?.TimeRemainingInSeconds < 0;
                }

                _shipData = newShipData;

                AssignShipNames();
                SaveShipData();
            }
            else
            {
                _shipData = null;
            }

            DataRefreshing = false;
            LastUpdate     = DateTimeOffset.UtcNow;

            ShipsUpdated?.Invoke(this, new ShipEventArgs
            {
                ShipDetails   = GetShipData(),
                IsFullRefresh = true
            });
        }
Exemplo n.º 20
0
        internal bool GetVisible(string id)
        {
            var key = VisibleKey(id);

            return(!localStorage.ContainKey(key) || localStorage.GetItem <bool>(key));
        }
Exemplo n.º 21
0
 public static string GetAccessToken(this ISyncLocalStorageService localStorage)
 {
     return(localStorage.GetItem <string>(LocalStorageConstants.AccessToken));
 }
Exemplo n.º 22
0
 public static User GetCurrentUser(ISyncLocalStorageService localStorage) =>
 localStorage.GetItem <User>(Const.UserKey);
Exemplo n.º 23
0
 public CurrencyStorageService(ISyncLocalStorageService localStorage)
 {
     this.localStorage     = localStorage;
     this.storedCurrencies = localStorage.GetItem <Dictionary <string, StoredCurrency> >(storageKey) ?? new Dictionary <string, StoredCurrency>();
     CurrencyTotal         = this.GetCurrencyTotal();
 }