Example #1
0
        public ControllerService(ISyncLocalStorageService localStorageService)
        {
            this.httpClient = new HttpClient
            {
                Timeout = TimeSpan.FromSeconds(3)
            };
            this.localStorageService = localStorageService;
            macAddress  = localStorageService.ContainKey(nameof(MacAddress)) ? localStorageService.GetItemAsString(nameof(MacAddress)) : "";
            baseAddress = localStorageService.ContainKey(nameof(BaseAddress)) ? localStorageService.GetItemAsString(nameof(BaseAddress)) : "";
            pin         = localStorageService.ContainKey(nameof(PIN)) ? localStorageService.GetItemAsString(nameof(PIN)) : "";

            var cmds = Enum.GetValues(typeof(ControllerCommandType)).Cast <ControllerCommandType>()
                       .Select(o => new LabeledCommand(o.ToString(), new Command(() => InvokeCommandInBackground(o))))
                       .ToList();

            SupportedCommands = new[]
            {
                new LabeledCommand("WoL", new Command(() => WakeOnLan()))
            }
            .Concat(cmds)
            .ToList();

            pinger = new Ping();

            Task.Run(async() =>
            {
                while (!isDisposed)
                {
                    var start = DateTime.Now;

                    (Status, ErrorMessage) = await GetStatusAsync();

                    var time = TimeSpan.FromSeconds(3) - (DateTime.Now - start);
                    if (time.Ticks > 0)
                    {
                        await Task.Delay(time);
                    }
                    else
                    {
                        await Task.Yield();
                    }
                }
            });
        }
Example #2
0
        public StateContainer(ISyncLocalStorageService localStorage)
        {
            var data = localStorage.GetItemAsString("playerData");

            if (data != null)
            {
                var settings = new JsonSerializerSettings()
                {
                    ObjectCreationHandling = ObjectCreationHandling.Replace
                };
                PlayerData = JsonConvert.DeserializeObject <PlayerData>(data, settings);
            }
        }
Example #3
0
        public UserProvider(
            ISyncLocalStorageService localStorage,
            HttpClient http,
            JsonSerializerOptions serializerOptions,
            IConfiguration config
            )
        {
            _localStorage      = localStorage;
            _http              = http;
            _serializerOptions = serializerOptions;
            _config            = config;

            if (_localStorage.ContainKey("Token"))
            {
                _ = SetDetailsAsync(_localStorage.GetItemAsString("Token"));
            }
            else
            {
                StartingDetailsChecked = true;
            }
        }
Example #4
0
        public static Guid GetUserIdSync(this ISyncLocalStorageService LocalStorage)
        {
            String userGuid = LocalStorage.GetItemAsString("userid");

            return(Guid.TryParse(userGuid, out Guid UserId) ? UserId : Guid.Empty);
        }