예제 #1
0
        /// <summary>
        /// </summary>
        /// <returns>
        /// </returns>
        public IObservable <SettingsContract> GetSettingsAsync()
        {
            lock (this.syncRoot)
            {
                if (this.userSettings != null)
                {
                    return(Observable.Return(this.userSettings));
                }
            }

            return((from settings in this.storage.LoadJsonAsync <SettingsContract>(SettingsFilePath)
                    select settings ??
                    new SettingsContract
            {
                CensorshipEnabled = true,
                PlayNextMix = true,
                PreferredList = PreferredLists.Liked,
                PlayOverWifiOnly = false
            }).Do(
                       s =>
            {
                lock (this.syncRoot)
                {
                    this.userSettings = s;
                }
            }));
        }
        public async Task EnableHardKillSwitch()
        {
            SettingsContract settingsContract = _settingsContractProvider.GetSettingsContract();

            settingsContract.KillSwitchMode = KillSwitchMode.Hard;
            await UpdateServiceSettingsInternal(settingsContract);
        }
예제 #3
0
 public void Apply(SettingsContract settings)
 {
     using (ServiceChannel <ISettingsContract> channel = _channelFactory.Create <ISettingsContract>(Endpoint))
     {
         channel.Proxy.Apply(settings);
     }
 }
예제 #4
0
        private void Load()
        {
            if (_settings != null)
            {
                return;
            }

            _settings = _storage.Get() ?? new SettingsContract();
        }
예제 #5
0
        public void Apply(SettingsContract settings)
        {
            Ensure.NotNull(settings, nameof(settings));

            _settings = settings;
            Save();

            SettingsChanged?.Invoke(this, settings);
        }
예제 #6
0
        public Task Disconnect(SettingsContract settings, VpnErrorTypeContract vpnError)
        {
            _logger.Info("Disconnect requested");

            _serviceSettings.Apply(settings);

            _vpnConnection.Disconnect(Map(vpnError));

            return(Task.CompletedTask);
        }
예제 #7
0
        /// <summary>
        /// </summary>
        /// <param name="userSettings">
        /// </param>
        private void LoadSettings(SettingsContract userSettings)
        {
            this.isSettingsLoaded = false;

            this.CensorshipEnabled = userSettings.CensorshipEnabled;
            this.PlayOverWifiOnly  = userSettings.PlayOverWifiOnly;
            this.PlayNextMix       = userSettings.PlayNextMix;
            this.PreferredList     = this.preferredListMap[userSettings.PreferredList ?? PreferredLists.Created];
            this.isSettingsLoaded  = true;
        }
예제 #8
0
 /// <summary>
 /// </summary>
 /// <param name="settings">
 /// </param>
 /// <returns>
 /// </returns>
 public IObservable <PortableUnit> SaveSettingsAsync(SettingsContract settings)
 {
     return(this.storage.SaveJsonAsync(SettingsFilePath, settings).Do(
                s =>
     {
         lock (this.syncRoot)
         {
             this.userSettings = settings;
         }
     }));
 }
 private async Task UpdateServiceSettingsInternal(SettingsContract settingsContract)
 {
     try
     {
         await Task.Run(() => _client.Apply(settingsContract));
     }
     catch (Exception ex) when(ex is CommunicationException || ex is TimeoutException || ex is TaskCanceledException)
     {
         _logger.Error(ex.CombinedMessage());
     }
 }
예제 #10
0
        public void Save(SettingsContract settings)
        {
            var filename = _config.ServiceSettingsFilePath;

            HandleException(() =>
            {
                using var stream = new StreamWriter(filename);
                using var writer = new JsonTextWriter(stream);
                _serializer.Serialize(writer, settings);
            },
                            "Saving");
        }
예제 #11
0
        public SettingsContract Load()
        {
            var filename            = _config.ServiceSettingsFilePath;
            SettingsContract result = null;

            HandleException(() =>
            {
                using var stream = new StreamReader(filename);
                using var reader = new JsonTextReader(stream);

                result = _serializer.Deserialize <SettingsContract>(reader);
            },
                            "Loading");

            return(result);
        }
예제 #12
0
        public void Apply(SettingsContract settings)
        {
            Ensure.NotNull(settings, nameof(settings));

            _settings.Apply(settings);
        }
예제 #13
0
 private IObservable <PlayingMixContract> LoadNowPlayingAsync()
 {
     return(from settings in ProfileService.Instance.GetSettingsAsync().Do(s => this.userSettings = s)
            from nowPlaying in PlayerService.LoadNowPlayingAsync().Do(v => this.NowPlaying = v)
            select nowPlaying);
 }
예제 #14
0
 public void Set(SettingsContract value)
 {
     _origin.Set(value);
 }