Exemplo n.º 1
0
 private void ReloadSettings(object sender, EventArgs e)
 {
     _imageProvider = GetImageProvider();
     _hasImage      = false;
     ChangeImage();
 }
Exemplo n.º 2
0
        protected override async Task InitializeAsync(CancellationToken cancellationToken,
                                                      IProgress <ServiceProgressData> progress)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            Application.Current.MainWindow.Loaded += (s, e) =>
            {
                ThreadHelper.ThrowIfNotOnUIThread();
                _mainWindow = (Window)s;
                _settings   = Setting.Initialize((DTE)GetService(typeof(DTE)));
                _settings.OnChanged.AddEventHandler(ReloadSettings);
                if (ProvidersHolder.Instance.Providers == null)
                {
                    ProvidersHolder.Initialize(_settings, new List <ImageProvider>
                    {
                        new SingleImageEachProvider(_settings),
                        new SlideShowImageProvider(_settings),
                        new SingleImageProvider(_settings),
                        new SingleImageWebProvider(_settings),
                        new WebApiImageProvider(_settings)
                    });
                }

                _imageProviders         = ProvidersHolder.Instance.Providers;
                _imageProvider          = _imageProviders.FirstOrDefault(x => x.ProviderType == _settings.ImageBackgroundType);
                _imageProvider.IsActive = true;
                _imageProviders.ForEach(x => x.NewImageAvailable += InvokeChangeImage);

                NextImage.InitializeAsync(this)
                .FileAndForget("claudiaide/nextimage/initializeasync");
                PauseSlideshow.InitializeAsync(this).FileAndForget("claudiaide/pauseslideshow/initializeasync");
                SaveSolutionSettings.InitializeAsync(this, _settings)
                .FileAndForget("claudiaide/saveSolutionSettings/initializeasync");
                ;
                ReloadSettings(null, null);
            };
            Application.Current.MainWindow.Closing += (s, e) =>
            {
                _imageProviders.ForEach(x => x.NewImageAvailable -= InvokeChangeImage);
                if (_settings != null)
                {
                    _settings.OnChanged.RemoveEventHandler(ReloadSettings);
                }
            };
            ThreadHelper.JoinableTaskFactory.RunAsync(async() =>
            {
                try
                {
                    await JoinableTaskFactory.SwitchToMainThreadAsync(true, cancellationToken);
                    _settings = Setting.Initialize((DTE)await GetServiceAsync(typeof(DTE)));
                    if (_settings == null)
                    {
                        return;
                    }
                    _mainWindow = Application.Current.MainWindow;
                    _settings.OnChanged.AddEventHandler(ReloadSettings);
                    if (ProvidersHolder.Instance.Providers == null)
                    {
                        ProvidersHolder.Initialize(_settings, new List <ImageProvider>
                        {
                            new SingleImageEachProvider(_settings),
                            new SlideShowImageProvider(_settings),
                            new SingleImageProvider(_settings),
                            new SingleImageWebProvider(_settings),
                            new WebApiImageProvider(_settings)
                        });
                    }

                    _imageProviders = ProvidersHolder.Instance.Providers;
                    _imageProvider  =
                        _imageProviders.FirstOrDefault(x => x.ProviderType == _settings.ImageBackgroundType);
                    _imageProvider.IsActive = true;
                    _imageProviders.ForEach(x => x.NewImageAvailable += InvokeChangeImage);

                    await NextImage.InitializeAsync(this);
                    await PauseSlideshow.InitializeAsync(this);
                    await SaveSolutionSettings.InitializeAsync(this, _settings);
                    ReloadSettings(null, null);
                }
                catch
                {
                }
            }).FileAndForget("claudiaide/initializeasync");
        }