Exemplo n.º 1
0
        public PlaybackControlsViewModelBase(IContainerProvider container) : base(container)
        {
            this.PlaybackService = container.Resolve <IPlaybackService>();
            this.DialogService   = container.Resolve <IDialogService>();
            this.PlaybackService.PlaybackProgressChanged += (_, __) => this.UpdateTime();

            this.ShowEqualizerCommand = new DelegateCommand(() =>
            {
                EqualizerControl view = container.Resolve <EqualizerControl>();
                view.DataContext      = container.Resolve <EqualizerControlViewModel>();

                this.DialogService.ShowCustomDialog(
                    new EqualizerIcon()
                {
                    IsDialogIcon = true
                },
                    0,
                    ResourceUtils.GetString("Language_Equalizer"),
                    view,
                    570,
                    0,
                    false,
                    true,
                    true,
                    false,
                    ResourceUtils.GetString("Language_Close"),
                    string.Empty,
                    null);
            });

            this.Reset();
        }
        public CollectionPlaybackControlsViewModel(IUnityContainer container, IDialogService dialogService) : base(container)
        {
            this.playbackService.PlaybackStopped += (_, __) =>
            {
                this.Reset();
                RaisePropertyChanged(nameof(this.IsPlaying));
            };

            this.ShowEqualizerCommand = new DelegateCommand(() =>
            {
                EqualizerControl view = container.Resolve <EqualizerControl>();
                view.DataContext      = container.Resolve <EqualizerControlViewModel>();

                dialogService.ShowCustomDialog(
                    new EqualizerIcon()
                {
                    IsDialogIcon = true
                },
                    0,
                    ResourceUtils.GetString("Language_Equalizer"),
                    view,
                    570,
                    0,
                    false,
                    true,
                    true,
                    false,
                    ResourceUtils.GetString("Language_Close"),
                    string.Empty,
                    null);
            });

            this.playbackService.PlaybackFailed  += (_, __) => RaisePropertyChanged(nameof(this.IsPlaying));
            this.playbackService.PlaybackPaused  += (_, __) => RaisePropertyChanged(nameof(this.IsPlaying));
            this.playbackService.PlaybackResumed += (_, __) => RaisePropertyChanged(nameof(this.IsPlaying));
            this.playbackService.PlaybackSuccess += (_) => RaisePropertyChanged(nameof(this.IsPlaying));
        }
Exemplo n.º 3
0
        public ShellViewModel(IUnityContainer container, IRegionManager regionManager, IDialogService dialogService, IPlaybackService playbackService, II18nService i18nService, ITaskbarService taskbarService, IJumpListService jumpListService, IFileService fileService, IScrobblingService scrobblingService)
        {
            this.container         = container;
            this.regionManager     = regionManager;
            this.dialogService     = dialogService;
            this.playbackService   = playbackService;
            this.i18nService       = i18nService;
            this.taskbarService    = taskbarService;
            this.jumpListService   = jumpListService;
            this.fileService       = fileService;
            this.scrobblingService = scrobblingService; // Not used here, but needs to be instantiated in the main window to ensure scrobbling is enabled.

            // Event handlers
            this.dialogService.DialogVisibleChanged += isDialogVisible => { this.IsOverlayVisible = isDialogVisible; };

            this.ShowLogfileCommand = new DelegateCommand(() =>
            {
                try
                {
                    Actions.TryViewInExplorer(LogClient.Logfile());
                }
                catch (Exception ex)
                {
                    LogClient.Error("Could not view the log file {0} in explorer. Exception: {1}", LogClient.Logfile(), ex.Message);
                }
            });

            this.OpenPathCommand = new DelegateCommand <string>((string path) =>
            {
                try
                {
                    Actions.TryOpenPath(path);
                }
                catch (Exception ex)
                {
                    LogClient.Error("Could not open the path {0} in Explorer. Exception: {1}", path, ex.Message);
                }
            });
            ApplicationCommands.OpenPathCommand.RegisterCommand(this.OpenPathCommand);

            this.OpenLinkCommand = new DelegateCommand <string>((string link) =>
            {
                try
                {
                    Actions.TryOpenLink(link);
                }
                catch (Exception ex)
                {
                    LogClient.Error("Could not open the link {0} in Internet Explorer. Exception: {1}", link, ex.Message);
                }
            });
            ApplicationCommands.OpenLinkCommand.RegisterCommand(this.OpenLinkCommand);

            this.PreviousCommand = new DelegateCommand(async() => await this.playbackService.PlayPreviousAsync());
            this.NextCommand     = new DelegateCommand(async() => await this.playbackService.PlayNextAsync());

            this.LoadedCommand = new DelegateCommand(() => this.fileService.ProcessArguments(Environment.GetCommandLineArgs()));

            this.playbackService.PlaybackFailed += (sender, playbackFailedEventArgs) =>
            {
                switch (playbackFailedEventArgs.FailureReason)
                {
                case PlaybackFailureReason.FileNotFound:
                    this.dialogService.ShowNotification(0xe711, 16, ResourceUtils.GetStringResource("Language_Error"), ResourceUtils.GetStringResource("Language_Error_Cannot_Play_This_Song_File_Not_Found"), ResourceUtils.GetStringResource("Language_Ok"), false, string.Empty);
                    break;

                default:
                    this.dialogService.ShowNotification(0xe711, 16, ResourceUtils.GetStringResource("Language_Error"), ResourceUtils.GetStringResource("Language_Error_Cannot_Play_This_Song"), ResourceUtils.GetStringResource("Language_Ok"), true, ResourceUtils.GetStringResource("Language_Log_File"));
                    break;
                }
            };

            // Equalizer
            this.ShowEqualizerCommand = new DelegateCommand(() =>
            {
                EqualizerControl view = this.container.Resolve <EqualizerControl>();
                view.DataContext      = this.container.Resolve <EqualizerControlViewModel>();

                this.dialogService.ShowCustomDialog(
                    new EqualizerIcon()
                {
                    IsDialogIcon = true
                },
                    ResourceUtils.GetStringResource("Language_Equalizer"),
                    view,
                    570,
                    0,
                    false,
                    true,
                    true,
                    false,
                    ResourceUtils.GetStringResource("Language_Close"),
                    string.Empty,
                    null);
            });

            ApplicationCommands.ShowEqualizerCommand.RegisterCommand(this.ShowEqualizerCommand);

            // Populate the JumpList
            this.jumpListService.PopulateJumpListAsync();
        }