public MainWindowViewModel()
        {
            TorrentSelected = new ReactiveCommand();
            DownloadAll = new ReactiveAsyncCommand();
            DeleteSelected = new ReactiveAsyncCommand();

            DeleteSelected.Subscribe(new AnonymousObserver<object>(x =>
            {
                App.streamza.RemoveTorrent(_selectedTorrent.id);
            }));

            DownloadAll.Subscribe(new AnonymousObserver<object>(x =>
            {
                var sel = _selectedTorrent;
                var s = new VistaFolderBrowserDialog();
                var res = s.ShowDialog();
                if (!res.HasValue || res.Value != true) return;

                var files = App.streamza.GetTorrentFiles(sel);
                foreach (var file in files)
                {
                    var uri = App.streamza.GetDownloadLink(file);
                    var cl = new WebClient();
                    var path = Path.Combine(s.SelectedPath, file.path);
                    if (!Directory.Exists(Path.GetDirectoryName(path)))
                        Directory.CreateDirectory(Path.GetDirectoryName(path));
                    cl.DownloadFile(new Uri(uri), path);
                }

                // This probably works best when there are lots of small files; doesn't
                // offer any improvement when there are only a couple of large files.
                // TODO: Check file count and set parallelism appropriately
                //Parallel.ForEach(files,
                //    new ParallelOptions { MaxDegreeOfParallelism = 4 },
                //    (file) =>
                //    {
                //        var uri = App.streamza.GetDownloadLink(file);
                //        var cl = new WebClient();
                //        var path = Path.Combine(s.SelectedPath, file.path);
                //        if (!Directory.Exists(Path.GetDirectoryName(path)))
                //            Directory.CreateDirectory(Path.GetDirectoryName(path));
                //        cl.DownloadFile(new Uri(uri), path);
                //    });
            }));

            _torrents = App.streamza.Torrents;

            Observable
                .Start(() =>
                {
                    Observable
                         .Interval(TimeSpan.FromSeconds(10))
                         .Subscribe(i =>
                         {
                             if (FetchingFiles) return;
                             _torrents = App.streamza.Torrents;
                             raisePropertyChanged("Torrents");
                         });
                });
        }
Example #2
0
        public TrackViewModel(Track model, IFileSystemBrowser fileSystemBrowser, IWebAccessProxy webAccessProxy)
        {
            this.Model        = model;
            FileSystemBrowser = fileSystemBrowser;
            WebAccessProxy    = webAccessProxy;

            var noOngoingDownloadObservable =
                WebAccessProxy.FileLocationObservable.Select(x => x != FileLocation.Downloading);

            _TrackLocation = WebAccessProxy.FileLocationObservable
                             .Select(x => x.ToString()).ToProperty(this, x => x.TrackLocation);

            Download = new ReactiveAsyncCommand(noOngoingDownloadObservable, 1);
            Download.Subscribe(_ =>
            {
                string fileName = GetFileName();

                string destinationPath = FileSystemBrowser.GetSaveAsLocation(fileName);

                if (String.IsNullOrEmpty(destinationPath))
                {
                    log.Info("Download cancelled - " + Model.Uri);
                    return;
                }

                log.Info(String.Format("Download started. From {0} to {1}", Model.Uri,
                                       destinationPath));
                SaveTo(destinationPath);
            });

            _Duration = Model.DurationObservable.Select(DurationToString).ToProperty(this, x => x.Duration);
        }
Example #3
0
        public TrackReporter(IObservable <Mix> currentMixObservable, IObservable <double> currentPositionObservable, IRequestExecutor requestExecutor)
        {
            this.requestExecutor = new RequestExecutionAdapter(requestExecutor);
            IObservable <bool> reportingMarkReached = currentPositionObservable
                                                      .BufferWithCount(2, 1)
                                                      .Select(positions => (positions[0] < reportingMark && positions[1] > reportingMark));

            currentMixObservable.Subscribe(mix =>
            {
                currentMix = mix;
            });

            ReactiveAsyncCommand reportTrack = new ReactiveAsyncCommand();

            reportTrack.Subscribe(_ =>
            {
                int mixId   = currentMix.MixId;
                Track track = currentMix.GetCurrentTrack();
                Report(track, mixId);
            });

            reportingMarkReached
            .Where(x => x)                                        // we crossed the mark
            .Where(_ => !currentMix.GetCurrentTrack().IsReported) //it's not previously reported
            .Subscribe(_ => reportTrack.Execute(null));
        }
        public ErrorViewModel(IScreen screen,
                              Func <ShellViewModel> getShellViewModel)
        {
            HostScreen = screen;

            Back = new ReactiveAsyncCommand();
            Back.Subscribe(_ => HostScreen.Router.NavigateAndReset.Execute(getShellViewModel()));
        }
Example #5
0
        public ErrorViewModel(IScreen screen,
            Func<ShellViewModel> getShellViewModel)
        {
            HostScreen = screen;

            Back = new ReactiveAsyncCommand();
            Back.Subscribe(_ => HostScreen.Router.NavigateAndReset.Execute(getShellViewModel()));
        }
        public ApplyUpdatesViewModel(
            IScreen screen,
            Func <UpdateManager> getUpdateManager)
        {
            this.getUpdateManager = getUpdateManager;
            HostScreen            = screen;

            Apply = new ReactiveAsyncCommand();
            Apply.Subscribe(_ => applyUpdates());

            Restart = new ReactiveAsyncCommand();
            Restart.Subscribe(_ => restart());

            progress           = new Subject <int>();
            progressObservable = progress.ToProperty(this, vm => vm.Progress);
        }
        public ApplyUpdatesViewModel(
            IScreen screen,
            Func<UpdateManager> getUpdateManager)
        {
            this.getUpdateManager = getUpdateManager;
            HostScreen = screen;

            Apply = new ReactiveAsyncCommand();
            Apply.Subscribe(_ => applyUpdates());

            Restart = new ReactiveAsyncCommand();
            Restart.Subscribe(_ => restart());

            progress = new Subject<int>();
            progressObservable = progress.ToProperty(this, vm => vm.Progress);
        }
        public CheckForUpdatesViewModel(
            IScreen screen,
            ISettingsProvider settingsProvider,
            Func<UpdateManager> getUpdateManager,
            Lazy<DownloadUpdatesViewModel> getDownloadViewModel)
        {
            HostScreen = screen;
            this.settingsProvider = settingsProvider;
            this.getUpdateManager = getUpdateManager;
            this.getDownloadViewModel = getDownloadViewModel;

            CheckCommand = new ReactiveAsyncCommand();
            CheckCommand.Subscribe(_ => checkForUpdates());

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

            progress = new Subject<int>();
            progressObservable = progress.ToProperty(
                this,
                vm => vm.Progress);
        }
        public CheckForUpdatesViewModel(
            IScreen screen,
            ISettingsProvider settingsProvider,
            Func <UpdateManager> getUpdateManager,
            Lazy <DownloadUpdatesViewModel> getDownloadViewModel)
        {
            HostScreen                = screen;
            this.settingsProvider     = settingsProvider;
            this.getUpdateManager     = getUpdateManager;
            this.getDownloadViewModel = getDownloadViewModel;

            CheckCommand = new ReactiveAsyncCommand();
            CheckCommand.Subscribe(_ => checkForUpdates());

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

            progress           = new Subject <int>();
            progressObservable = progress.ToProperty(
                this,
                vm => vm.Progress);
        }
Example #10
0
        public DownloadUpdatesViewModel(
            IScreen screen,
            Func <UpdateManager> getUpdateManager,
            Lazy <ApplyUpdatesViewModel> getApplyViewModel)
        {
            HostScreen             = screen;
            this.getUpdateManager  = getUpdateManager;
            this.getApplyViewModel = getApplyViewModel;

            Download = new ReactiveAsyncCommand();
            Download.Subscribe(_ => downloadUpdates());

            progress    = new Subject <int>();
            progressObs = progress.ToProperty(
                this,
                vm => vm.Progress);

            var updateInfoChanges =
                this.WhenAny(vm => vm.UpdateInfo, x => x.Value)
                .Where(info => info != null);

            updateCountObs =
                updateInfoChanges
                .Select(info => info.ReleasesToApply.Count())
                .ToProperty(this, vm => vm.UpdateCount);

            updateSizeObs =
                updateInfoChanges
                .Select(info => info.ReleasesToApply.Sum(x => x.Filesize))
                .Select(total => String.Format("({0:n0} bytes)", total))
                .ToProperty(this, vm => vm.UpdateSize);

            latestVersionObs = updateInfoChanges
                               .Select(info => info.FutureReleaseEntry.Version.ToString())
                               .Where(x => !String.IsNullOrWhiteSpace(x))
                               .ToProperty(this, vm => vm.LatestVersion);
        }
        public DownloadUpdatesViewModel(
            IScreen screen,
            Func<UpdateManager> getUpdateManager,
            Lazy<ApplyUpdatesViewModel> getApplyViewModel)
        {
            HostScreen = screen;
            this.getUpdateManager = getUpdateManager;
            this.getApplyViewModel = getApplyViewModel;

            Download = new ReactiveAsyncCommand();
            Download.Subscribe(_ => downloadUpdates());

            progress = new Subject<int>();
            progressObs = progress.ToProperty(
                this,
                vm => vm.Progress);

            var updateInfoChanges = 
                this.WhenAny(vm => vm.UpdateInfo, x => x.Value)
                    .Where(info => info != null);

            updateCountObs =
                updateInfoChanges
                    .Select(info => info.ReleasesToApply.Count())
                    .ToProperty(this, vm => vm.UpdateCount);

            updateSizeObs =
                updateInfoChanges
                    .Select(info => info.ReleasesToApply.Sum(x => x.Filesize))
                    .Select(total => String.Format("({0:n0} bytes)", total))
                    .ToProperty(this, vm => vm.UpdateSize);

            latestVersionObs = updateInfoChanges
                .Select(info => info.FutureReleaseEntry.Version.ToString())
                .Where(x => !String.IsNullOrWhiteSpace(x))
                .ToProperty(this, vm => vm.LatestVersion);
        }
Example #12
0
 public IDisposable Subscribe(IObserver <object> a_observer)
 {
     return(m_subCommand.Subscribe(a_observer));
 }
Example #13
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;
                }
            });
        }