Exemplo n.º 1
0
        public ShellViewModel(
            IScreen screen,
            Func <SettingsViewModel> getSettings,
            Func <CheckForUpdatesViewModel> getForegroundUpdater,
            Func <BackgroundUpdaterViewModel> getBackgroundUpdater)
        {
            HostScreen = screen;

            SettingsCommand = new ReactiveAsyncCommand();
            SettingsCommand.RegisterAsyncAction(o => {
                var viewModel = getSettings();
                HostScreen.Navigate(viewModel);
            });

            UpdateBasicsCommand = new ReactiveAsyncCommand();
            UpdateBasicsCommand.RegisterAsyncAction(o => {
                var viewModel = getForegroundUpdater();
                HostScreen.Navigate(viewModel);
            });

            BackgroundUpdaterCommand = new ReactiveAsyncCommand(Observable.Return(false));
            BackgroundUpdaterCommand.RegisterAsyncAction(o => {
                var viewModel = getBackgroundUpdater();
                HostScreen.Navigate(viewModel);
            });
        }
        public MainViewModel()
        {
            _informationEngine = new InformationEngine();
            _sessionViewModels =
                _informationEngine.Sessions.CreateDerivedCollection(x => new SessionViewModel(x) as ISessionViewModel);
            ((IEditableCollectionView) (CollectionViewSource.GetDefaultView(_sessionViewModels)))
                .NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtEnd;

            _showInitializationErrorMessage = () => MessageBox.Show(
                "Bei der Initialisierung des Receivers ist ein Fehler aufgetreten.\n" +
                "Bitte schließen Sie die Session und starten den Receiver neu.",
                "Fehler");

            _showCloseSessionErrorMessage = () => MessageBox.Show(
                "Beim Schließen der Session trat ein Fehler auf.",
                "Fehler");

            StartNewSessionCommand = new ReactiveCommand();
            StartNewSessionCommand.Subscribe(_ => StartNewSession());

            InitializeReceiverCommand = new ReactiveAsyncCommand();
            InitializeReceiverCommand.RegisterAsyncAction(x => InitializeReceiver((Tuple<Guid, IReceiver>) x));
            InitializeReceiverCommand.ThrownExceptions.Subscribe(
                ex => _showInitializationErrorMessage());

            CloseSessionCommand = new ReactiveCommand();
            CloseSessionCommand.Subscribe(x => CloseSession((ISessionViewModel) x));
            CloseSessionCommand.ThrownExceptions.Subscribe(ex => _showCloseSessionErrorMessage());
        }
Exemplo n.º 3
0
        public SettingsViewModel(
            IScreen screen,
            ISettingsProvider settingsProvider,
            IFolderHelper folderHelper, 
            IAppContext appContext)
        {
            HostScreen = screen;

            BackCommand = new ReactiveAsyncCommand();
            BackCommand.RegisterAsyncAction(_ => HostScreen.Router.NavigateBack.Execute(null));

            SelectFolder = new ReactiveAsyncCommand();
            SelectFolder.RegisterAsyncAction(_ =>
            {
                var result = folderHelper.SelectFolder();
                if (result.Result == true) {
                    UpdateLocation = result.Folder;
                }
            }, appContext.DispatcherScheduler);

            UpdateLocation = settingsProvider.UpdateLocation;

            _IsError = this.WhenAny(vm => vm.UpdateLocation, vm => vm.Value)
                           .DistinctUntilChanged()
                           .Throttle(TimeSpan.FromMilliseconds(500))
                           .ObserveOn(appContext.DispatcherScheduler)
                           .Select(text => !IsUrlOrFolder(text))
                           .Do(error => {
                                if (!error) {
                                    settingsProvider.UpdateLocation = UpdateLocation;
                                }
                            })
                            .ToProperty(this, vm => vm.IsError, setViaReflection: false);
        }
Exemplo n.º 4
0
        public ShellViewModel(
            IScreen screen,
            Func<SettingsViewModel> getSettings,
            Func<CheckForUpdatesViewModel> getForegroundUpdater,
            Func<BackgroundUpdaterViewModel> getBackgroundUpdater)
        {
            HostScreen = screen;

            SettingsCommand = new ReactiveAsyncCommand();
            SettingsCommand.RegisterAsyncAction(o => {
                var viewModel = getSettings();
                HostScreen.Navigate(viewModel);
            });

            UpdateBasicsCommand = new ReactiveAsyncCommand();
            UpdateBasicsCommand.RegisterAsyncAction(o => {
                var viewModel = getForegroundUpdater();
                HostScreen.Navigate(viewModel);
            });

            BackgroundUpdaterCommand = new ReactiveAsyncCommand(Observable.Return(false));
            BackgroundUpdaterCommand.RegisterAsyncAction(o => {
                var viewModel = getBackgroundUpdater();
                HostScreen.Navigate(viewModel);
            });
        }
        public MainViewModel()
        {
            _informationEngine = new InformationEngine();
            _sessionViewModels =
                _informationEngine.Sessions.CreateDerivedCollection(x => new SessionViewModel(x) as ISessionViewModel);
            ((IEditableCollectionView)(CollectionViewSource.GetDefaultView(_sessionViewModels)))
            .NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtEnd;

            _showInitializationErrorMessage = () => MessageBox.Show(
                "Bei der Initialisierung des Receivers ist ein Fehler aufgetreten.\n" +
                "Bitte schließen Sie die Session und starten den Receiver neu.",
                "Fehler");

            _showCloseSessionErrorMessage = () => MessageBox.Show(
                "Beim Schließen der Session trat ein Fehler auf.",
                "Fehler");

            StartNewSessionCommand = new ReactiveCommand();
            StartNewSessionCommand.Subscribe(_ => StartNewSession());

            InitializeReceiverCommand = new ReactiveAsyncCommand();
            InitializeReceiverCommand.RegisterAsyncAction(x => InitializeReceiver((Tuple <Guid, IReceiver>)x));
            InitializeReceiverCommand.ThrownExceptions.Subscribe(
                ex => _showInitializationErrorMessage());

            CloseSessionCommand = new ReactiveCommand();
            CloseSessionCommand.Subscribe(x => CloseSession((ISessionViewModel)x));
            CloseSessionCommand.ThrownExceptions.Subscribe(ex => _showCloseSessionErrorMessage());
        }
Exemplo n.º 6
0
 public Manga(int IdOrder, Library owner, String Name)
 {
     this.Owner = owner;
     this.Name = Name;
     _MangaFromSources = new ObservableCollection<MangaFomSource>();
     MangaFromSources = new ReadOnlyObservableCollection<MangaFomSource>(_MangaFromSources);
     CreationDate = DateTime.Now;
     UpdateDate = DateTime.Now;
     GetDetailCmd = new ReactiveAsyncCommand();
     GetDetailCmd.RegisterAsyncAction(o => GetDetail(o as IList<MangaFomSource>));
     GetDetailCmd.ThrownExceptions.Subscribe(o => global::System.Windows.MessageBox.Show(o.Message));
 }
Exemplo n.º 7
0
 public ChapterFromSource(MangaFomSource owner, ChapterData chapterData)
 {
     this.Name = chapterData.Name;
     this.Source = chapterData.ChapterSource;
     Owner = owner;
     GetChapterCmd = new ReactiveAsyncCommand();
     GetChapterCmd.RegisterAsyncAction(o => Get());
     GetChapterCmd.ThrownExceptions.Subscribe(o => global::System.Windows.MessageBox.Show(o.Message));
     GoToLinkCmd = new ReactiveCommand();
     GoToLinkCmd.Subscribe((o) =>
     {
         App.Controller.NavigateTo(Source.Link);
     });
 }
        public MainViewModel()
        {
            DisplayCommand = new ReactiveCommand(this.WhenAny(x => x.Name, x => !string.IsNullOrEmpty(x.Value)));
            DisplayCommand.Subscribe(_ => MessageBox.Show("You clicked on DisplayCommand: Name is " + Name));

            StartAsyncCommand = new ReactiveAsyncCommand();
            StartAsyncCommand.RegisterAsyncAction(_ =>
            {
                Progress = 0;
                while (Progress <= 100)
                {
                    Progress += 10;
                    Thread.Sleep(100);
                }
            });
        }
        public MainViewModel()
        {
            DisplayCommand = new ReactiveCommand(this.WhenAny(x => x.Name, x => !string.IsNullOrEmpty(x.Value)));
            DisplayCommand.Subscribe(_ => MessageBox.Show("You clicked on DisplayCommand: Name is " + Name));

            StartAsyncCommand = new ReactiveAsyncCommand();
            StartAsyncCommand.RegisterAsyncAction(_ =>
            {
                Progress = 0;
                while (Progress <= 100)
                {
                    Progress += 10;
                    Thread.Sleep(100);
                }
            });

        }
Exemplo n.º 10
0
        public MainWindowViewModel()
        {
            this.Tools = new ReactiveCollection<IToolViewModel> { IoC.Instance.Resolve<ITestsTreeViewModel>() };
            this.Charts = new ObservableCollection<IChartViewModel>();

            MessageBus.Current.Listen<TestCheckChanged>().Subscribe(OnTestCheckChanged);

            var errorHandler = IoC.Instance.Resolve<ErrorHandler>();

            MessageBus.Current.Listen<LoadAssembly>()
                      .Subscribe(OnLoadAssembly);

            MessageBus.Current.Listen<ClearAssembliesList>().Subscribe(OnClearAssembliesList);

            DocClosed = new ReactiveAsyncCommand();
            DocClosed.RegisterAsyncAction(OnDocumentClosed, RxApp.DeferredScheduler);
            errorHandler.HandleErrors(this.DocClosed);
        }
Exemplo n.º 11
0
 public Library()
 {
     _Mangas = new ObservableCollection<Manga>();
     Mangas = new ReadOnlyObservableCollection<Manga>(_Mangas);
     _Source = new ObservableCollection<Source>();
     Sources = new ReadOnlyObservableCollection<Source>(_Source);
     _Source.Add(new Source("MangaHere", MangaHere.getMangas, MangaHere.getNews, MangaHere.getDetailManga, MangaHere.getChapters));
     _Source.Add(new Source("MangaReader", MangaReader.getMangas, MangaReader.getNews, MangaReader.getDetailManga, MangaReader.getChapters));
     dispatcher = Dispatcher.CurrentDispatcher;
     GetNewsCmd = new ReactiveAsyncCommand();
     GetNewsCmd.RegisterAsyncAction(o => GetNews(o as IList<Source>));
     GetNewsCmd.ThrownExceptions.Subscribe(o => global::System.Windows.MessageBox.Show(o.Message));
     GetMangasCmd = new ReactiveAsyncCommand();
     GetMangasCmd.RegisterAsyncAction(o => GetMangas(o as IList<Source>));
     GetMangasCmd.ThrownExceptions.Subscribe(o => global::System.Windows.MessageBox.Show(o.Message));
     //  if (!DesignTimeHelper.IsDesignTime())
     //GetNewsCmd.Execute(_Source);
 }
        public MainWindowViewModel()
        {
            this.Tools = new ReactiveCollection <IToolViewModel> {
                IoC.Instance.Resolve <ITestsTreeViewModel>()
            };
            this.Charts = new ObservableCollection <IChartViewModel>();

            MessageBus.Current.Listen <TestCheckChanged>().Subscribe(OnTestCheckChanged);

            var errorHandler = IoC.Instance.Resolve <ErrorHandler>();

            MessageBus.Current.Listen <LoadAssembly>()
            .Subscribe(OnLoadAssembly);

            MessageBus.Current.Listen <ClearAssembliesList>().Subscribe(OnClearAssembliesList);

            DocClosed = new ReactiveAsyncCommand();
            DocClosed.RegisterAsyncAction(OnDocumentClosed, RxApp.DeferredScheduler);
            errorHandler.HandleErrors(this.DocClosed);
        }
Exemplo n.º 13
0
        public SettingsViewModel(
            IScreen screen,
            ISettingsProvider settingsProvider,
            IFolderHelper folderHelper,
            IAppContext appContext)
        {
            HostScreen = screen;

            BackCommand = new ReactiveAsyncCommand();
            BackCommand.RegisterAsyncAction(_ => HostScreen.Router.NavigateBack.Execute(null));

            SelectFolder = new ReactiveAsyncCommand();
            SelectFolder.RegisterAsyncAction(_ =>
            {
                var result = folderHelper.SelectFolder();
                if (result.Result == true)
                {
                    UpdateLocation = result.Folder;
                }
            }, appContext.DispatcherScheduler);

            UpdateLocation = settingsProvider.UpdateLocation;

            _IsError = this.WhenAny(vm => vm.UpdateLocation, vm => vm.Value)
                       .DistinctUntilChanged()
                       .Throttle(TimeSpan.FromMilliseconds(500))
                       .ObserveOn(appContext.DispatcherScheduler)
                       .Select(text => !IsUrlOrFolder(text))
                       .Do(error => {
                if (!error)
                {
                    settingsProvider.UpdateLocation = UpdateLocation;
                }
            })
                       .ToProperty(this, vm => vm.IsError, setViaReflection: false);
        }
Exemplo n.º 14
0
        public PlaybackViewModel(IPlaybackController playbackController, Settings settings,
                                 IMixViewModelFactory mixViewModelFactory)
        {
            this.playbackController = playbackController;
            this.settings           = settings;
            var volumeString = (string)settings[volumeKey] ?? "50";

            Volume = Double.Parse(volumeString);

            _CurrentPosition = playbackController.CurrentPositionObservable
                               .ToProperty(this, x => x.CurrentPosition);

            _CurrentPositionAsString = playbackController.CurrentPositionObservable
                                       .Select(TimeSpan.FromSeconds)
                                       .Select(DurationToString)
                                       .ToProperty(this, x => x.CurrentPositionAsString);

            // connecting current mix being played to the viewmodel

            IObservable <MixViewModel> currentMixViewModelObservable = playbackController.CurrentMixObservable.Select(mixViewModelFactory.CreateMixViewModel);

            _CurrentMixViewModel = currentMixViewModelObservable
                                   .ToProperty(this, x => x.CurrentMixViewModel);


            IObservable <bool> _CurrentMixViewModelPresent =
                this.WhenAny(
                    x => x.CurrentMixViewModel,
                    mixViewModel => mixViewModel.Value != null &&
                    mixViewModel.Value.Model != Mix.NoMixAvailable);


            _CurrentTrackDurationAsString = playbackController.CurrentDurationObservable
                                            .Select(duration => DurationToString(TimeSpan.FromSeconds(duration)))
                                            .ToProperty(this, x => x.CurrentTrackDurationAsString);

            _CurrentTrackDuration = playbackController.CurrentDurationObservable
                                    .ToProperty(this, x => x.CurrentTrackDuration);


            // commands

            // going to the next song only if there is a mix currently loaded
            _NextSong = currentMixViewModelObservable
                        .Select(x => x.NextSong)
                        .ToProperty(this, x => x.NextSong);


            var audioPlayerState = playbackController.PlayerStateObservable;

            // both having a current mix and not running
            var audioPlayerNotRunning = audioPlayerState.Select(status =>
                                                                status == MediaStatus.Stopped ||
                                                                status == MediaStatus.Paused).CombineLatest(
                _CurrentMixViewModelPresent, (x, y) => x && y);

            Continue = new ReactiveAsyncCommand(audioPlayerNotRunning, 1);
            Continue.Subscribe(_ => playbackController.Continue());

            var audioPlayerRunning = audioPlayerState.Select(status => status == MediaStatus.Running);

            Pause = new ReactiveAsyncCommand(audioPlayerRunning, 1);
            Pause.Subscribe(_ => playbackController.Pause());

            var audioPlayerRunningOrPaused = audioPlayerState.Select(status =>
                                                                     status == MediaStatus.Running ||
                                                                     status == MediaStatus.Paused);

            Stop = new ReactiveAsyncCommand(audioPlayerRunningOrPaused, 1);
            Stop.Subscribe(_ => playbackController.Stop());

            NextMix = new ReactiveAsyncCommand(_CurrentMixViewModelPresent, 1);
            NextMix.RegisterAsyncAction(_ =>
            {
                try
                {
                    playbackController.NextMix();
                }
                catch (Exception e)
                {
                    log.Error("Unable to go to the next mix", e);
                }
            }
                                        );

            bool debugModeOn = ConfigurationManager.AppSettings["AudioPlayer"] != null && ConfigurationManager.AppSettings["AudioPlayer"].Equals("DirectX WMI 3.14169");

            _IsPositionSliderEnabled = audioPlayerRunningOrPaused
                                       .Select(a => a && debugModeOn)
                                       .ToProperty(this, x => x.IsPositionSliderEnabled);

            GoToTrack = new ReactiveAsyncCommand(_CurrentMixViewModelPresent, 1);
            GoToTrack.Subscribe(_ =>
            {
                if (debugModeOn)
                {
                    try
                    {
                        playbackController.GoToTrack(SelectedTrackIndex);
                    }
                    catch (Exception e)
                    {
                        log.Error("Unable to go to track " + SelectedTrackIndex, e);
                    }
                }
            });

            Skip = new ReactiveAsyncCommand(audioPlayerRunningOrPaused, 1);
            Skip.Subscribe(step =>
            {
                double newPosition = CurrentPosition + Double.Parse((string)step);
                if (newPosition >= 0 && newPosition <= CurrentTrackDuration)
                {
                    CurrentPosition = newPosition;
                }
            });

            ChangeVolume = new ReactiveAsyncCommand(null, 1);
            ChangeVolume.Subscribe(step =>
            {
                double newVolume = Volume + Double.Parse((string)step);
                if (newVolume >= 0 && newVolume <= 100)
                {
                    Volume = newVolume;
                }
            });
        }
Exemplo n.º 15
0
        public MixViewModel(Mix mixModel, IPlaybackController playbackController,
                            IMediaLibraryBrowser mediaLibraryBrowser, IObservable <bool> userLoggedInObservable)
        {
            mixModel.CurrentTrackIndexObservable.Subscribe(x =>
            {
                // if we're playing a track that has already been added
                CurrentTrackIndex = x;
                UpdateCurrentTrackIndicator();
            });
            mixModel.LikedByCurrentUserObservable.Subscribe(x => LikedByCurrentUser = x);

            this.Model = mixModel;

            Play = ReactiveCommand.Create(_ => true);
            Play.Subscribe(_ => playbackController.Play(Model));


            ToggleLike = Model != Mix.NoMixAvailable
                             ? new ReactiveAsyncCommand(userLoggedInObservable, 1)
                             : new ReactiveAsyncCommand(Observable.Return(false), 1);

            ToggleLike.RegisterAsyncAction(_ => mediaLibraryBrowser.ToggleLike(Model));

            this.isUserRequested = ConfigurationManager.AppSettings["AudioPlayer"] == null || !ConfigurationManager.AppSettings["AudioPlayer"].Equals("DirectX WMI 3.14169");
            ReplaySubject <bool> skippingSongAllowed = new ReplaySubject <bool>(1);

            //skipping not allowed if there are no tracks in the mix
            Model.CurrentTrackIndexObservable.Select(trackIndex => trackIndex < Model.Tracks.Count && trackIndex >= 0
                                                                       ? Model.Tracks[trackIndex].IsSkipAllowed
                                                                       : false).Subscribe(skippingSongAllowed.OnNext);

            NextSong = new ReactiveAsyncCommand(skippingSongAllowed, 1);
            NextSong.RegisterAsyncAction(_ =>
            {
                try
                {
                    playbackController.NextSong(isUserRequested);
                }
                catch (Exception e)
                {
                    log.Error("Unable to go to the next song", e);
                }
            });

            Tracks = new DispatchedReactiveCollection <TrackViewModel>();

            // merge current items and future ones
            Observable.Merge(Model.Tracks.ToObservable(), Model.Tracks.ItemsAdded)
            .Select(CreateTrackViewModel)
            .Subscribe(trackViewModel =>
            {
                Tracks.Add(trackViewModel);
                UpdateCurrentTrackIndicator();
            });

            Download = ReactiveCommand.Create(_ => Model != Mix.NoMixAvailable);
            Download.Subscribe(_ =>
            {
                string destinationFolder = FileSystemBrowser.GetSaveToDirectory();

                if (String.IsNullOrEmpty(destinationFolder))
                {
                    return;
                }

                destinationFolder += Path.DirectorySeparatorChar + Model.Name;
                FileSystemBrowser.TryCreateDirectory(destinationFolder);

                Tracks
//                                           .Where(
//                                               trackViewModel =>
//                                               trackViewModel.TrackLocation.Equals(FileLocation.Online.ToString()))
                .ToObservable()
                .Subscribe(trackViewModel => SaveTrack(trackViewModel, destinationFolder));
            });

            FileSystemBrowser = new FileSystemBrowser();
            WebAccessProxy    = new WebAccessProxy();

//            _TotalNumberOfTracks = Tracks.CollectionCountChanged
//                .ToProperty(this, x => x.TotalNumberOfTracks);
            CurrentTrackIndexAsString = "0";

            skippingSongAllowed.OnNext(false);
        }