コード例 #1
0
ファイル: LoginViewModel.cs プロジェクト: salfab/open-syno
        public LoginViewModel(IPageSwitchingService pageSwitchingService, IEventAggregator eventAggregator, IAudioStationSession audioStationSession, IOpenSynoSettings synoSettings, ISignInService signInService, IPlaybackService playbackService)
        {
            if (pageSwitchingService == null) throw new ArgumentNullException("pageSwitchingService");
            if (eventAggregator == null) throw new ArgumentNullException("eventAggregator");
            if (audioStationSession == null) throw new ArgumentNullException("audioStationSession");
            SignInCommand = new DelegateCommand(OnSignIn);
            _pageSwitchingService = pageSwitchingService;
            _eventAggregator = eventAggregator;
            _audioStationSession = audioStationSession;
            _synoSettings = synoSettings;
            _signInService = signInService;
            _signInService.SignInCompleted += OnSignInCompleted;

            // Unregister the registered events to make sure we don't execute the event handler twice in case of exceptions
            _signInService.CheckTokenValidityCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                    _signInService.CheckTokenValidityCompleted -= OnCheckTokenValidityCompleted;
                }
            };

            _playbackService = playbackService;
            UserName = _synoSettings.UserName;
            UseSsl = _synoSettings.UseSsl;
            Password = _synoSettings.Password;
            Host = _synoSettings.Host;
            Port = _synoSettings.Port;
        }
コード例 #2
0
        public LastFmScrobblingService(IPlaybackService playbackService)
        {
            this.playbackService = playbackService;

            this.playbackService.PlaybackSuccess         += PlaybackService_PlaybackSuccess;
            this.playbackService.PlaybackProgressChanged += PlaybackService_PlaybackProgressChanged;
            this.playbackService.PlaybackSkipped         += PlaybackService_PlaybackSkipped;

            this.username   = SettingsClient.Get <string>("Lastfm", "Username");
            this.password   = SettingsClient.Get <string>("Lastfm", "Password");
            this.sessionKey = SettingsClient.Get <string>("Lastfm", "Key");

            if (!string.IsNullOrEmpty(this.username) && !string.IsNullOrEmpty(this.password) && !string.IsNullOrEmpty(this.sessionKey))
            {
                this.signInState = SignInState.SignedIn;
            }
            else
            {
                this.signInState = SignInState.SignedOut;
            }
        }
コード例 #3
0
        public ApplicationViewModel(ISyllablesService syllablesService, ITranscriptionService transcriptionService,
                                    IPlaybackService playbackService)
        {
            Guard.NotNull(syllablesService, "syllablesService");
            Guard.NotNull(transcriptionService, "transcriptionService");
            Guard.NotNull(playbackService, "playbackService");

            this._syllablesService     = syllablesService;
            this._transcriptionService = transcriptionService;
            this._playbackService      = playbackService;

            this._playbackService.PlaybackCompleted += this.PlaybackServiceOnPlaybackCompleted;

            this._inputText             = "";
            this._isInputTextBoxEnabled = true;
            this._outputMode            = OutputMode.Transcription;
            this.OutputText             = "";
            this._words = new List <string>();

            this.Commands = new ApplicationViewModelCommands(this);
        }
コード例 #4
0
        public ApplicationViewModel(ISyllablesService syllablesService, ITranscriptionService transcriptionService,
                                    IPlaybackService playbackService)
        {
            Guard.NotNull(syllablesService, "syllablesService");
            Guard.NotNull(transcriptionService, "transcriptionService");
            Guard.NotNull(playbackService, "playbackService");

            this._syllablesService = syllablesService;
            this._transcriptionService = transcriptionService;
            this._playbackService = playbackService;

            this._playbackService.PlaybackCompleted += this.PlaybackServiceOnPlaybackCompleted;

            this._inputText = "";
            this._isInputTextBoxEnabled = true;
            this._outputMode = OutputMode.Transcription;
            this.OutputText = "";
            this._words = new List<string>();

            this.Commands = new ApplicationViewModelCommands(this);
        }
コード例 #5
0
        public PlaybackInfoControlViewModel(IPlaybackService playbackService)
        {
            this.playbackService = playbackService;

            this.refreshTimer.Interval = this.refreshTimerIntervalMilliseconds;
            this.refreshTimer.Elapsed += RefreshTimer_Elapsed;

            this.playbackService.PlaybackSuccess += (isPlayingPreviousTrack) =>
            {
                this.SlideDirection = isPlayingPreviousTrack ? SlideDirection.UpToDown : SlideDirection.DownToUp;
                this.refreshTimer.Stop();
                this.refreshTimer.Start();
            };

            this.playbackService.PlaybackProgressChanged         += (_, __) => this.UpdateTime();
            this.playbackService.PlayingTrackPlaybackInfoChanged += (_, __) => this.RefreshPlaybackInfoAsync(this.playbackService.CurrentTrack.Value, true);

            // Defaults
            this.SlideDirection = SlideDirection.DownToUp;
            this.RefreshPlaybackInfoAsync(this.playbackService.CurrentTrack.Value, false);
        }
コード例 #6
0
        public SpectrumAnalyzerControlViewModel(IPlaybackService playbackService, IAppearanceService appearanceService, IEventAggregator eventAggregator)
        {
            this.playbackService   = playbackService;
            this.eventAggregator   = eventAggregator;
            this.appearanceService = appearanceService;

            this.playbackService.SpectrumVisibilityChanged += isSpectrumVisible => this.ShowSpectrumAnalyzer = isSpectrumVisible;

            this.appearanceService.ColorSchemeChanged += (_, __) =>
                                                         Application.Current.Dispatcher.Invoke(() => this.SetSpectrumStyle((SpectrumStyle)SettingsClient.Get <int>("Playback", "SpectrumStyle")));

            this.playbackService.PlaybackFailed  += (_, __) => this.IsPlaying = false;
            this.playbackService.PlaybackStopped += (_, __) => this.IsPlaying = false;
            this.playbackService.PlaybackPaused  += (_, __) => this.IsPlaying = false;
            this.playbackService.PlaybackResumed += (_, __) => this.IsPlaying = true;
            this.playbackService.PlaybackSuccess += (_, __) => this.IsPlaying = true;

            SettingsClient.SettingChanged += (_, e) =>
            {
                if (SettingsClient.IsSettingChanged(e, "Playback", "SpectrumStyle"))
                {
                    this.SetSpectrumStyle((SpectrumStyle)e.SettingValue);
                }
            };

            this.ShowSpectrumAnalyzer = SettingsClient.Get <bool>("Playback", "ShowSpectrumAnalyzer");

            // Initial value
            if (!this.playbackService.IsStopped & this.playbackService.IsPlaying)
            {
                this.IsPlaying = true;
            }
            else
            {
                this.IsPlaying = false;
            }

            // Default spectrum
            this.SetSpectrumStyle((SpectrumStyle)SettingsClient.Get <int>("Playback", "SpectrumStyle"));
        }
        public PlaybackControlsWithPlaylistNotificationViewModel(ICollectionService collectionService, IPlaybackService playbackService, IPlaylistService playlistService)
        {
            this.collectionService = collectionService;
            this.playbackService   = playbackService;
            this.playlistService   = playlistService;

            this.PlaylistNotificationMouseEnterCommand = new DelegateCommand(() => this.HideText());

            this.playlistService.TracksAdded += (numberTracksAdded, playlist) =>
            {
                string text = ResourceUtils.GetString("Language_Added_Track_To_Playlist");

                if (numberTracksAdded > 1)
                {
                    text = ResourceUtils.GetString("Language_Added_Tracks_To_Playlist");
                }

                this.AddedTracksToPlaylistText = text.Replace("%numberoftracks%", numberTracksAdded.ToString()).Replace("%playlistname%", playlist);

                this.ShowAddedTracksToPlaylistText = true;
            };

            this.playbackService.AddedTracksToQueue += iNumberOfTracks =>
            {
                string text = ResourceUtils.GetString("Language_Added_Track_To_Now_Playing");

                if (iNumberOfTracks > 1)
                {
                    text = ResourceUtils.GetString("Language_Added_Tracks_To_Now_Playing");
                }

                this.AddedTracksToPlaylistText = text.Replace("%numberoftracks%", iNumberOfTracks.ToString());

                this.ShowAddedTracksToPlaylistText = true;
            };

            this.showAddedTracksToPlaylistTextTimer          = new Timer();
            this.showAddedTracksToPlaylistTextTimer.Interval = TimeSpan.FromSeconds(this.showAddedTracksToPlaylistTextTimeout).TotalMilliseconds;
            this.showAddedTracksToPlaylistTextTimer.Elapsed += ShowAddedTracksToPlaylistTextTimerElapsedHandler;
        }
コード例 #8
0
        public CollectionFrequentViewModel(IAlbumRepository albumRepository, IPlaybackService playbackService, ICacheService cacheService, IIndexingService indexingService, IRegionManager regionManager)
        {
            this.albumRepository = albumRepository;
            this.playbackService = playbackService;
            this.cacheService    = cacheService;
            this.indexingService = indexingService;
            this.regionManager   = regionManager;

            this.playbackService.PlaybackCountersChanged += async(_, __) => await this.PopulateAlbumHistoryAsync();

            this.indexingService.IndexingStopped += async(_, __) => await this.PopulateAlbumHistoryAsync();

            this.ClickCommand = new DelegateCommand <object>((album) =>
            {
                try
                {
                    if (album != null)
                    {
                        this.playbackService.EnqueueAsync(((Album)album).ToList(), false, false);
                    }
                }
                catch (Exception ex)
                {
                    LogClient.Error("An error occurred during Album enqueue. Exception: {0}", ex.Message);
                }
            });

            this.LoadedCommand = new DelegateCommand(async() =>
            {
                if (!isFirstLoad)
                {
                    return;
                }

                isFirstLoad = false;

                await Task.Delay(Constants.CommonListLoadDelay);
                await this.PopulateAlbumHistoryAsync();
            });
        }
コード例 #9
0
        public TracksViewModelBase(IContainerProvider container) : base(container)
        {
            // Dependency injection
            this.container         = container;
            this.trackRepository   = container.Resolve <ITrackRepository>();
            this.dialogService     = container.Resolve <IDialogService>();
            this.searchService     = container.Resolve <ISearchService>();
            this.playbackService   = container.Resolve <IPlaybackService>();
            this.collectionService = container.Resolve <ICollectionService>();
            this.i18nService       = container.Resolve <II18nService>();
            this.eventAggregator   = container.Resolve <IEventAggregator>();
            this.providerService   = container.Resolve <IProviderService>();
            this.playlistService   = container.Resolve <IPlaylistService>();

            // Commands
            this.ToggleTrackOrderCommand      = new DelegateCommand(() => this.ToggleTrackOrder());
            this.AddTracksToPlaylistCommand   = new DelegateCommand <string>(async(playlistName) => await this.AddTracksToPlaylistAsync(playlistName, this.SelectedTracks));
            this.PlaySelectedCommand          = new DelegateCommand(async() => await this.PlaySelectedAsync());
            this.PlayNextCommand              = new DelegateCommand(async() => await this.PlayNextAsync());
            this.AddTracksToNowPlayingCommand = new DelegateCommand(async() => await this.AddTracksToNowPlayingAsync());

            // Settings
            SettingsClient.SettingChanged += (_, e) =>
            {
                if (SettingsClient.IsSettingChanged(e, "Behaviour", "ShowRemoveFromDisk"))
                {
                    RaisePropertyChanged(nameof(this.ShowRemoveFromDisk));
                }
            };

            // Events
            this.i18nService.LanguageChanged += (_, __) =>
            {
                RaisePropertyChanged(nameof(this.TotalDurationInformation));
                RaisePropertyChanged(nameof(this.TotalSizeInformation));
                this.RefreshLanguage();
            };

            this.playbackService.PlaybackCountersChanged += PlaybackService_PlaybackCountersChanged;
        }
コード例 #10
0
        public void UpdateMessage(IPlaybackService playbackService, IProtoService protoService, Message message)
        {
            _playbackService = playbackService;
            _protoService    = protoService;
            _message         = message;

            _playbackService.PropertyChanged      -= OnCurrentItemChanged;
            _playbackService.PropertyChanged      += OnCurrentItemChanged;
            _playbackService.PlaybackStateChanged -= OnPlaybackStateChanged;
            _playbackService.PlaybackStateChanged += OnPlaybackStateChanged;

            var voiceNote = GetContent(message.Content);

            if (voiceNote == null)
            {
                return;
            }

            var user = protoService.GetUser(message.SenderUserId);

            if (user != null)
            {
                Title.Text = user.GetFullName();
            }
            else
            {
                var chat = protoService.GetChat(message.ChatId);
                if (chat != null)
                {
                    Title.Text = chat.Title;
                }
                else
                {
                    Title.Text = string.Empty;
                }
            }

            UpdateFile(message, voiceNote.Voice);
        }
コード例 #11
0
        public CoverArtControlViewModel(IPlaybackService playbackService, ICacheService cacheService, IMetadataService metadataService)
        {
            this.playbackService = playbackService;
            this.cacheService    = cacheService;
            this.metadataService = metadataService;

            this.refreshTimer.Interval = this.refreshTimerIntervalMilliseconds;
            this.refreshTimer.Elapsed += RefreshTimer_Elapsed;

            this.playbackService.PlaybackSuccess += (_, e) =>
            {
                this.SlideDirection = e.IsPlayingPreviousTrack ? SlideDirection.UpToDown : SlideDirection.DownToUp;
                this.refreshTimer.Stop();
                this.refreshTimer.Start();
            };

            this.playbackService.PlayingTrackArtworkChanged += (_, __) => this.RefreshCoverArtAsync(this.playbackService.CurrentTrack);

            // Defaults
            this.SlideDirection = SlideDirection.DownToUp;
            this.RefreshCoverArtAsync(this.playbackService.CurrentTrack);
        }
コード例 #12
0
        public MainViewModel(IProtoService protoService, ICacheService cacheService, ISettingsService settingsService, IEventAggregator aggregator, INotificationsService pushService, IContactsService contactsService, IVibrationService vibrationService, ILiveLocationService liveLocationService, IPasscodeService passcodeService, ILifetimeService lifecycle, ISessionService session, IVoIPService voipService, ISettingsSearchService settingsSearchService, IEmojiSetService emojiSetService, IPlaybackService playbackService)
            : base(protoService, cacheService, settingsService, aggregator)
        {
            _pushService         = pushService;
            _contactsService     = contactsService;
            _vibrationService    = vibrationService;
            _liveLocationService = liveLocationService;
            _passcodeService     = passcodeService;
            _lifetimeService     = lifecycle;
            _sessionService      = session;
            _voipService         = voipService;
            _emojiSetService     = emojiSetService;
            _playbackService     = playbackService;

            Chats         = new ChatsViewModel(protoService, cacheService, settingsService, aggregator, pushService, new ChatListMain());
            ArchivedChats = new ChatsViewModel(protoService, cacheService, settingsService, aggregator, pushService, new ChatListArchive());
            Contacts      = new ContactsViewModel(protoService, cacheService, settingsService, aggregator, contactsService);
            Calls         = new CallsViewModel(protoService, cacheService, settingsService, aggregator);
            Settings      = new SettingsViewModel(protoService, cacheService, settingsService, aggregator, pushService, contactsService, settingsSearchService);

            // This must represent pivot tabs
            Children.Add(Chats);
            Children.Add(Contacts);
            Children.Add(Calls);
            Children.Add(Settings);

            // Any additional child
            Children.Add(ArchivedChats);
            Children.Add(_voipService as TLViewModelBase);

            aggregator.Subscribe(this);

            LiveLocationCommand     = new RelayCommand(LiveLocationExecute);
            StopLiveLocationCommand = new RelayCommand(StopLiveLocationExecute);

            ReturnToCallCommand = new RelayCommand(ReturnToCallExecute);

            ToggleArchiveCommand = new RelayCommand(ToggleArchiveExecute);
        }
コード例 #13
0
        public SettingsAppearanceViewModel(IPlaybackService playbackService, IEventAggregator eventAggregator)
        {
            this.playbackService = playbackService;
            this.eventAggregator = eventAggregator;

            this.ColorSchemesDirectory = System.IO.Path.Combine(SettingsClient.ApplicationFolder(), ApplicationPaths.ColorSchemesFolder);

            this.OpenColorSchemesDirectoryCommand = new DelegateCommand <string>((colorSchemesDirectory) =>
            {
                try
                {
                    Actions.TryOpenPath(colorSchemesDirectory);
                }
                catch (Exception ex)
                {
                    LogClient.Error("Could not open the ColorSchemes directory. Exception: {0}", ex.Message);
                }
            });

            this.GetCheckBoxesAsync();
            this.GetSpectrumStylesAsync();
        }
コード例 #14
0
        public AlbumsViewModelBase(IUnityContainer container) : base(container)
        {
            // Dependency injection
            this.container         = container;
            this.collectionService = container.Resolve <ICollectionService>();
            this.playbackService   = container.Resolve <IPlaybackService>();
            this.dialogService     = container.Resolve <IDialogService>();
            this.searchService     = container.Resolve <ISearchService>();
            this.playlistService   = container.Resolve <IPlaylistService>();
            this.albumRepository   = container.Resolve <IAlbumRepository>();
            this.cacheService      = container.Resolve <ICacheService>();

            // Commands
            this.ToggleAlbumOrderCommand      = new DelegateCommand(() => this.ToggleAlbumOrder());
            this.ShuffleSelectedAlbumsCommand = new DelegateCommand(async() => await this.playbackService.EnqueueAlbumsAsync(this.SelectedAlbumIds, true, false));
            this.AddAlbumsToPlaylistCommand   = new DelegateCommand <string>(async(playlistName) => await this.AddAlbumsToPlaylistAsync(this.SelectedAlbumIds, playlistName));
            this.EditAlbumCommand             = new DelegateCommand(() => this.EditSelectedAlbum(), () => !this.IsIndexing);
            this.AddAlbumsToNowPlayingCommand = new DelegateCommand(async() => await this.AddAlbumsToNowPlayingAsync(this.SelectedAlbumIds));
            this.DelaySelectedAlbumsCommand   = new DelegateCommand(() => this.delaySelectedAlbums = true);

            this.SelectedAlbumsCommand = new DelegateCommand <object>(async(parameter) =>
            {
                if (this.delaySelectedAlbums)
                {
                    await Task.Delay(Constants.DelaySelectedAlbumsDelay);
                }
                this.delaySelectedAlbums = false;
                await this.SelectedAlbumsHandlerAsync(parameter);
            });

            this.SetCoverSizeCommand = new DelegateCommand <string>(async(coverSize) =>
            {
                if (int.TryParse(coverSize, out int selectedCoverSize))
                {
                    await this.SetCoversizeAsync((CoverSizeType)selectedCoverSize);
                }
            });
        }
コード例 #15
0
        public LoginViewModel(IPageSwitchingService pageSwitchingService, IEventAggregator eventAggregator, IAudioStationSession audioStationSession, IOpenSynoSettings synoSettings, ISignInService signInService, IPlaybackService playbackService)
        {
            if (pageSwitchingService == null)
            {
                throw new ArgumentNullException("pageSwitchingService");
            }
            if (eventAggregator == null)
            {
                throw new ArgumentNullException("eventAggregator");
            }
            if (audioStationSession == null)
            {
                throw new ArgumentNullException("audioStationSession");
            }
            SignInCommand                   = new DelegateCommand(OnSignIn);
            _pageSwitchingService           = pageSwitchingService;
            _eventAggregator                = eventAggregator;
            _audioStationSession            = audioStationSession;
            _synoSettings                   = synoSettings;
            _signInService                  = signInService;
            _signInService.SignInCompleted += OnSignInCompleted;

            // Unregister the registered events to make sure we don't execute the event handler twice in case of exceptions
            _signInService.CheckTokenValidityCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                    _signInService.CheckTokenValidityCompleted -= OnCheckTokenValidityCompleted;
                }
            };

            _playbackService = playbackService;
            UserName         = _synoSettings.UserName;
            UseSsl           = _synoSettings.UseSsl;
            Password         = _synoSettings.Password;
            Host             = _synoSettings.Host;
            Port             = _synoSettings.Port;
        }
コード例 #16
0
        /// <summary>
        /// Parameterless Constructor used by child classes.
        /// </summary>
        /// <remarks></remarks>
        public CommonTracksViewModel()
        {
            // Unity Container
            this.container = ServiceLocator.Current.GetInstance <IUnityContainer>();

            // EventAggregator
            this.eventAggregator = ServiceLocator.Current.GetInstance <IEventAggregator>();

            // Services
            this.indexingService   = ServiceLocator.Current.GetInstance <IIndexingService>();
            this.playbackService   = ServiceLocator.Current.GetInstance <IPlaybackService>();
            this.searchService     = ServiceLocator.Current.GetInstance <ISearchService>();
            this.dialogService     = ServiceLocator.Current.GetInstance <IDialogService>();
            this.collectionService = ServiceLocator.Current.GetInstance <ICollectionService>();
            this.metadataService   = ServiceLocator.Current.GetInstance <IMetadataService>();
            this.i18nService       = ServiceLocator.Current.GetInstance <II18nService>();

            // Repositories
            this.trackRepository = ServiceLocator.Current.GetInstance <ITrackRepository>();

            // Initialize
            this.Initialize();
        }
コード例 #17
0
        /// <summary>
        /// Constructor which allows Dependency Injection. This can be useful for Unit Testing.
        /// </summary>
        /// <param name="container"></param>
        /// <param name="indexingService"></param>
        /// <param name="eventAggregator"></param>
        /// <param name="playbackService"></param>
        /// <param name="searchService"></param>
        /// <param name="dialogService"></param>
        /// <param name="collectionService"></param>
        /// <param name="trackRepository"></param>
        /// <param name="i18nService"></param>
        /// <remarks></remarks>
        public CommonTracksViewModel(IUnityContainer container, IIndexingService indexingService, IEventAggregator eventAggregator, IPlaybackService playbackService, ISearchService searchService, IDialogService dialogService, ICollectionService collectionService, ITrackRepository trackRepository, IMetadataService metadataService, II18nService i18nService)
        {
            // Unity Container
            this.container = container;

            // EventAggregator
            this.eventAggregator = eventAggregator;

            // Services
            this.indexingService   = indexingService;
            this.playbackService   = playbackService;
            this.searchService     = searchService;
            this.dialogService     = dialogService;
            this.collectionService = collectionService;
            this.metadataService   = metadataService;
            this.i18nService       = i18nService;

            // Repositories
            this.trackRepository = trackRepository;

            // Initialize
            this.Initialize();
        }
コード例 #18
0
        public MetadataService(ICacheService cacheService, IPlaybackService playbackService, ITrackRepository trackRepository,
                               IFileMetadataFactory metadataFactory, IContainerProvider container)
        {
            this.cacheService    = cacheService;
            this.playbackService = playbackService;

            this.trackRepository = trackRepository;
            this.metadataFactory = metadataFactory;

            this.container = container;

            this.fileMetadataDictionary = new Dictionary <string, IFileMetadata>();

            this.updateFileMetadataTimer          = new Timer();
            this.updateFileMetadataTimer.Interval = this.updateFileMetadataLongTimeout;
            this.updateFileMetadataTimer.Elapsed += async(_, __) => await this.UpdateFileMetadataAsync();

            this.playbackService.PlaybackStopped += async(_, __) => await this.UpdateFileMetadataAsync();

            this.playbackService.PlaybackFailed += async(_, __) => await this.UpdateFileMetadataAsync();

            this.playbackService.PlaybackSuccess += async(_, __) => await this.UpdateFileMetadataAsync();
        }
コード例 #19
0
        public void Update(IProtoService cacheService, IPlaybackService playbackService, INavigationService navigationService, IEventAggregator aggregator)
        {
            _cacheService      = cacheService;
            _playbackService   = playbackService;
            _navigationService = navigationService;
            _aggregator        = aggregator;

            _playbackService.MediaFailed          -= OnMediaFailed;
            _playbackService.MediaFailed          += OnMediaFailed;
            _playbackService.PropertyChanged      -= OnCurrentItemChanged;
            _playbackService.PropertyChanged      += OnCurrentItemChanged;
            _playbackService.PlaybackStateChanged -= OnPlaybackStateChanged;
            _playbackService.PlaybackStateChanged += OnPlaybackStateChanged;
            _playbackService.PositionChanged      -= OnPositionChanged;
            _playbackService.PositionChanged      += OnPositionChanged;
            _playbackService.PlaylistChanged      -= OnPlaylistChanged;
            _playbackService.PlaylistChanged      += OnPlaylistChanged;

            Items.ItemsSource = _playbackService.Items;

            UpdateRate();
            UpdateGlyph();
        }
コード例 #20
0
        public MetadataService(ICacheService cacheService, IPlaybackService playbackService, ITrackRepository trackRepository, ITrackStatisticRepository trackStatisticRepository, IAlbumRepository albumRepository, IGenreRepository genreRepository, IArtistRepository artistRepository)
        {
            this.cacheService    = cacheService;
            this.playbackService = playbackService;

            this.trackStatisticRepository = trackStatisticRepository;
            this.trackRepository          = trackRepository;
            this.albumRepository          = albumRepository;
            this.genreRepository          = genreRepository;
            this.artistRepository         = artistRepository;

            this.fileMetadataDictionary = new Dictionary <string, FileMetadata>();

            this.updateFileMetadataTimer          = new Timer();
            this.updateFileMetadataTimer.Interval = this.updateFileMetadataLongTimeout;
            this.updateFileMetadataTimer.Elapsed += async(_, __) => await this.UpdateFileMetadataAsync();

            this.playbackService.PlaybackStopped += async(_, __) => await this.UpdateFileMetadataAsync();

            this.playbackService.PlaybackFailed += async(_, __) => await this.UpdateFileMetadataAsync();

            this.playbackService.PlaybackSuccess += async(_) => await this.UpdateFileMetadataAsync();
        }
コード例 #21
0
ファイル: ShellViewModel.cs プロジェクト: llenroc/Dopamine
        public ShellViewModel(IPlaybackService playbackService, ITaskbarService taskbarService, IDialogService dialogService)
        {
            this.TaskbarService = taskbarService;
            this.dialogService  = dialogService;

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

            this.PlayPreviousCommand = new DelegateCommand(async() => await playbackService.PlayPreviousAsync());
            this.PlayNextCommand     = new DelegateCommand(async() => await playbackService.PlayNextAsync());
            this.PlayOrPauseCommand  = new DelegateCommand(async() => await playbackService.PlayOrPauseAsync());

            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);
                }
            });
        }
コード例 #22
0
        public EqualizerControlViewModel(IPlaybackService playbackService, IEqualizerService equalizerService, IDialogService dialogService)
        {
            // Variables
            this.playbackService  = playbackService;
            this.equalizerService = equalizerService;
            this.dialogService    = dialogService;

            this.IsEqualizerEnabled = XmlSettingsClient.Instance.Get <bool>("Equalizer", "IsEnabled");

            // Commands
            this.ResetCommand = new DelegateCommand(() =>
            {
                this.canApplyManualPreset = false;
                this.Band0 = this.Band1 = this.Band2 = this.Band3 = this.Band4 = this.Band5 = this.Band6 = this.Band7 = this.Band8 = this.Band9 = 0.0;
                this.canApplyManualPreset = true;

                this.ApplyManualPreset();
            });

            this.DeleteCommand = new DelegateCommand(async() => { await this.DeletePresetAsync(); }, () =>
            {
                if (this.SelectedPreset != null)
                {
                    return(this.SelectedPreset.IsRemovable);
                }
                else
                {
                    return(false);
                }
            });

            this.SaveCommand = new DelegateCommand(async() => { await this.SavePresetToFileAsync(); });

            // Initialize
            this.InitializeAsync();
        }
コード例 #23
0
        public CommonViewModelBase(IUnityContainer container) : base(container)
        {
            // EventAggregator
            this.eventAggregator = container.Resolve <IEventAggregator>();

            // Services
            this.indexingService   = container.Resolve <IIndexingService>();
            this.playbackService   = container.Resolve <IPlaybackService>();
            this.searchService     = container.Resolve <ISearchService>();
            this.dialogService     = container.Resolve <IDialogService>();
            this.collectionService = container.Resolve <ICollectionService>();
            this.metadataService   = container.Resolve <IMetadataService>();
            this.i18nService       = container.Resolve <II18nService>();
            this.playlistService   = container.Resolve <IPlaylistService>();

            // Handlers
            this.ProviderService.SearchProvidersChanged += (_, __) => { this.GetSearchProvidersAsync(); };

            // Initialize the search providers in the ContextMenu
            this.GetSearchProvidersAsync();

            // Initialize
            this.Initialize();
        }
コード例 #24
0
        public ArtistInfoControlViewModel(IUnityContainer container, IPlaybackService playbackService, II18nService i18nService)
        {
            this.container       = container;
            this.playbackService = playbackService;
            this.i18nService     = i18nService;

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

            this.playbackService.PlaybackSuccess += async(isPlayingPreviousTrack) =>
            {
                this.SlideDirection = isPlayingPreviousTrack ? SlideDirection.RightToLeft : SlideDirection.LeftToRight;
                await this.ShowArtistInfoAsync(this.playbackService.CurrentTrack.Value, false);
            };

            this.i18nService.LanguageChanged += async(_, __) =>
            {
                if (this.playbackService.HasCurrentTrack)
                {
                    await this.ShowArtistInfoAsync(this.playbackService.CurrentTrack.Value, true);
                }
            };

            // Defaults
            this.SlideDirection = SlideDirection.LeftToRight;
            this.ShowArtistInfoAsync(this.playbackService.CurrentTrack.Value, true);
        }
コード例 #25
0
        public SpectrumAnalyzerControlViewModel(IPlaybackService playbackService)
        {
            this.playbackService = playbackService;

            this.playbackService.SpectrumVisibilityChanged += isSpectrumVisible => this.ShowSpectrumAnalyzer = isSpectrumVisible;

            this.playbackService.PlaybackFailed  += (_, __) => this.IsPlaying = false;
            this.playbackService.PlaybackStopped += (_, __) => this.IsPlaying = false;
            this.playbackService.PlaybackPaused  += (_, __) => this.IsPlaying = false;
            this.playbackService.PlaybackResumed += (_, __) => this.IsPlaying = true;
            this.playbackService.PlaybackSuccess += (_) => this.IsPlaying = true;

            this.ShowSpectrumAnalyzer = XmlSettingsClient.Instance.Get <bool>("Playback", "ShowSpectrumAnalyzer");

            // Initial value
            if (!this.playbackService.IsStopped & this.playbackService.IsPlaying)
            {
                this.IsPlaying = true;
            }
            else
            {
                this.IsPlaying = false;
            }
        }
コード例 #26
0
        public ArtistInfoControlViewModel(IUnityContainer container, IPlaybackService playbackService, II18nService i18nService)
        {
            this.container       = container;
            this.playbackService = playbackService;
            this.i18nService     = i18nService;

            this.playbackService.PlaybackSuccess += async(isPlayingPreviousTrack) =>
            {
                this.SlideDirection = isPlayingPreviousTrack ? SlideDirection.RightToLeft : SlideDirection.LeftToRight;
                await this.ShowArtistInfoAsync(this.playbackService.CurrentTrack.Value, false);
            };

            this.i18nService.LanguageChanged += async(_, __) =>
            {
                if (this.playbackService.HasCurrentTrack)
                {
                    await this.ShowArtistInfoAsync(this.playbackService.CurrentTrack.Value, true);
                }
            };

            // Defaults
            this.SlideDirection = SlideDirection.LeftToRight;
            this.ShowArtistInfoAsync(this.playbackService.CurrentTrack.Value, true);
        }
コード例 #27
0
        public ChatSharedMediaViewModel(IProtoService protoService, ICacheService cacheService, ISettingsService settingsService, IStorageService storageService, IEventAggregator aggregator, IPlaybackService playbackService)
            : base(protoService, cacheService, settingsService, aggregator)
        {
            _playbackService = playbackService;
            _storageService  = storageService;

            Items = new ObservableCollection <ProfileItem>();

            Media      = new SearchCollection <MessageWithOwner, MediaCollection>(SetSearch, new SearchMessagesFilterPhotoAndVideo(), new MessageDiffHandler());
            Files      = new SearchCollection <MessageWithOwner, MediaCollection>(SetSearch, new SearchMessagesFilterDocument(), new MessageDiffHandler());
            Links      = new SearchCollection <MessageWithOwner, MediaCollection>(SetSearch, new SearchMessagesFilterUrl(), new MessageDiffHandler());
            Music      = new SearchCollection <MessageWithOwner, MediaCollection>(SetSearch, new SearchMessagesFilterAudio(), new MessageDiffHandler());
            Voice      = new SearchCollection <MessageWithOwner, MediaCollection>(SetSearch, new SearchMessagesFilterVoiceNote(), new MessageDiffHandler());
            Animations = new SearchCollection <MessageWithOwner, MediaCollection>(SetSearch, new SearchMessagesFilterAnimation(), new MessageDiffHandler());

            MessagesForwardCommand  = new RelayCommand(MessagesForwardExecute, MessagesForwardCanExecute);
            MessagesDeleteCommand   = new RelayCommand(MessagesDeleteExecute, MessagesDeleteCanExecute);
            MessagesUnselectCommand = new RelayCommand(MessagesUnselectExecute);
            MessageViewCommand      = new RelayCommand <MessageWithOwner>(MessageViewExecute);
            MessageSaveCommand      = new RelayCommand <MessageWithOwner>(MessageSaveExecute);
            MessageDeleteCommand    = new RelayCommand <MessageWithOwner>(MessageDeleteExecute);
            MessageForwardCommand   = new RelayCommand <MessageWithOwner>(MessageForwardExecute);
            MessageSelectCommand    = new RelayCommand <MessageWithOwner>(MessageSelectExecute);
        }
コード例 #28
0
        public CollectionPlaylistsViewModel(IContainerProvider container, IDialogService dialogService,
                                            IPlaybackService playbackService, IPlaylistService playlistService, IMetadataService metadataService,
                                            IFileService fileService, IEventAggregator eventAggregator) : base(container)
        {
            this.dialogService   = dialogService;
            this.playlistService = playlistService;
            this.playbackService = playbackService;
            this.fileService     = fileService;
            this.eventAggregator = eventAggregator;
            this.dialogService   = dialogService;
            this.metadataService = metadataService;
            this.container       = container;

            // Events
            this.playlistService.PlaylistFolderChanged += PlaylistService_PlaylistFolderChanged;
            this.playlistService.TracksAdded           += PlaylistService_TracksAdded;
            this.playlistService.TracksDeleted         += PlaylistService_TracksDeleted;

            this.metadataService.LoveChanged += async(_) => await this.GetTracksIfSmartPlaylistSelectedAsync();

            this.metadataService.RatingChanged += async(_) => await this.GetTracksIfSmartPlaylistSelectedAsync();

            this.metadataService.MetadataChanged += async(_) => await this.GetTracksIfSmartPlaylistSelectedAsync();

            this.playbackService.PlaybackCountersChanged += async(_) => await this.GetTracksIfSmartPlaylistSelectedAsync();

            // Commands
            this.EditSelectedPlaylistCommand    = new DelegateCommand(async() => await this.EditSelectedPlaylistAsync());
            this.DeletePlaylistCommand          = new DelegateCommand <PlaylistViewModel>(async(playlist) => await this.ConfirmDeletePlaylistAsync(playlist));
            this.ImportPlaylistsCommand         = new DelegateCommand(async() => await this.ImportPlaylistsAsync());
            this.AddPlaylistToNowPlayingCommand = new DelegateCommand(async() => await this.AddPlaylistToNowPlayingAsync());
            this.ShuffleSelectedPlaylistCommand = new DelegateCommand(async() => await this.ShuffleSelectedPlaylistAsync());
            this.LoadedCommand               = new DelegateCommand(async() => await this.LoadedCommandAsync());
            this.NewPlaylistCommand          = new DelegateCommand(async() => await this.ConfirmCreateNewPlaylistAsync());
            this.RemoveSelectedTracksCommand = new DelegateCommand(async() => await this.DeleteTracksFromPlaylistsAsync());

            this.DeleteSelectedPlaylistCommand = new DelegateCommand(async() =>
            {
                if (this.IsPlaylistSelected)
                {
                    await this.ConfirmDeletePlaylistAsync(this.SelectedPlaylist);
                }
            });

            // Settings changed
            SettingsClient.SettingChanged += (_, e) =>
            {
                if (SettingsClient.IsSettingChanged(e, "Behaviour", "EnableRating"))
                {
                    this.EnableRating = (bool)e.Entry.Value;
                }

                if (SettingsClient.IsSettingChanged(e, "Behaviour", "EnableLove"))
                {
                    this.EnableLove = (bool)e.Entry.Value;
                }
            };

            // Load settings
            this.LeftPaneWidthPercent = SettingsClient.Get <int>("ColumnWidths", "PlaylistsLeftPaneWidthPercent");
        }
コード例 #29
0
        public MainViewModel(IProtoService protoService, ICacheService cacheService, ISettingsService settingsService, IEventAggregator aggregator, INotificationsService pushService, IContactsService contactsService, IVibrationService vibrationService, IPasscodeService passcodeService, ILifetimeService lifecycle, ISessionService session, IVoIPService voipService, ISettingsSearchService settingsSearchService, IEmojiSetService emojiSetService, IPlaybackService playbackService, IShortcutsService shortcutService)
            : base(protoService, cacheService, settingsService, aggregator)
#endif
        {
            _pushService      = pushService;
            _contactsService  = contactsService;
            _vibrationService = vibrationService;
            _passcodeService  = passcodeService;
            _lifetimeService  = lifecycle;
            _sessionService   = session;
            _voipService      = voipService;
            _emojiSetService  = emojiSetService;
#if CLOUDUPDATES
            _cloudUpdateService = cloudUpdateService;
#endif
            _playbackService = playbackService;
            _shortcutService = shortcutService;

            Filters = new ChatFilterCollection();

            Chats         = new ChatsViewModel(protoService, cacheService, settingsService, aggregator, pushService, new ChatListMain());
            ArchivedChats = new ChatsViewModel(protoService, cacheService, settingsService, aggregator, pushService, new ChatListArchive());
            Contacts      = new ContactsViewModel(protoService, cacheService, settingsService, aggregator, contactsService);
            Calls         = new CallsViewModel(protoService, cacheService, settingsService, aggregator);
            Settings      = new SettingsViewModel(protoService, cacheService, settingsService, aggregator, settingsSearchService);

            // This must represent pivot tabs
            Children.Add(Chats);
            Children.Add(Contacts);
            Children.Add(Calls);
            Children.Add(Settings);

            // Any additional child
            Children.Add(ArchivedChats);
            Children.Add(_voipService as TLViewModelBase);

            aggregator.Subscribe(this);

            ReturnToCallCommand = new RelayCommand(ReturnToCallExecute);

            ToggleArchiveCommand = new RelayCommand(ToggleArchiveExecute);

            CreateSecretChatCommand = new RelayCommand(CreateSecretChatExecute);

            SetupFiltersCommand = new RelayCommand(SetupFiltersExecute);
#if CLOUDUPDATES
            UpdateAppCommand = new RelayCommand(UpdateAppExecute);
#endif
            FilterEditCommand       = new RelayCommand <ChatFilterViewModel>(FilterEditExecute);
            FilterAddCommand        = new RelayCommand <ChatFilterViewModel>(FilterAddExecute);
            FilterMarkAsReadCommand = new RelayCommand <ChatFilterViewModel>(FilterMarkAsReadExecute);
            FilterDeleteCommand     = new RelayCommand <ChatFilterViewModel>(FilterDeleteExecute);
        }
コード例 #30
0
 public MainViewModel(IProtoService protoService, ICacheService cacheService, ISettingsService settingsService, IEventAggregator aggregator, INotificationsService pushService, IContactsService contactsService, IVibrationService vibrationService, IPasscodeService passcodeService, ILifetimeService lifecycle, ISessionService session, IVoIPService voipService, ISettingsSearchService settingsSearchService, IEmojiSetService emojiSetService, ICloudUpdateService cloudUpdateService, IPlaybackService playbackService, IShortcutsService shortcutService)
     : base(protoService, cacheService, settingsService, aggregator)
コード例 #31
0
 private void OnPositionChanged(IPlaybackService sender, object args)
 {
     this.BeginOnUIThread(UpdatePosition);
 }
コード例 #32
0
ファイル: App.xaml.cs プロジェクト: salfab/open-syno
 private void ResolvePrivateMembers()
 {
     _playbackService = IoC.Container.Get<IPlaybackService>();
 }
コード例 #33
0
        public CollectionGenresViewModel(IContainerProvider container) : base(container)
        {
            // Dependency injection
            this.collectionService = container.Resolve <ICollectionService>();
            this.dialogService     = container.Resolve <IDialogService>();
            this.indexingService   = container.Resolve <IIndexingService>();
            this.playbackService   = container.Resolve <IPlaybackService>();
            this.playlistService   = container.Resolve <IPlaylistService>();
            this.searchService     = container.Resolve <ISearchService>();
            this.eventAggregator   = container.Resolve <IEventAggregator>();

            // Commands
            this.ToggleTrackOrderCommand      = new DelegateCommand(async() => await this.ToggleTrackOrderAsync());
            this.ToggleAlbumOrderCommand      = new DelegateCommand(async() => await this.ToggleAlbumOrderAsync());
            this.RemoveSelectedTracksCommand  = new DelegateCommand(async() => await this.RemoveTracksFromCollectionAsync(this.SelectedTracks), () => !this.IsIndexing);
            this.AddGenresToPlaylistCommand   = new DelegateCommand <string>(async(playlistName) => await this.AddGenresToPlaylistAsync(this.SelectedGenres, playlistName));
            this.SelectedGenresCommand        = new DelegateCommand <object>(async(parameter) => await this.SelectedGenresHandlerAsync(parameter));
            this.ShowGenresZoomCommand        = new DelegateCommand(async() => await this.ShowSemanticZoomAsync());
            this.AddGenresToNowPlayingCommand = new DelegateCommand(async() => await this.AddGenresToNowPlayingAsync(this.SelectedGenres));
            this.ShuffleSelectedGenresCommand = new DelegateCommand(async() => await this.playbackService.EnqueueGenresAsync(this.SelectedGenres, true, false));

            this.SemanticJumpCommand = new DelegateCommand <string>((header) =>
            {
                this.HideSemanticZoom();
                this.eventAggregator.GetEvent <PerformSemanticJump>().Publish(new Tuple <string, string>("Genres", header));
            });

            // Settings
            SettingsClient.SettingChanged += async(_, e) =>
            {
                if (SettingsClient.IsSettingChanged(e, "Behaviour", "EnableRating"))
                {
                    this.EnableRating = (bool)e.SettingValue;
                    this.SetTrackOrder("GenresTrackOrder");
                    await this.GetTracksAsync(null, this.SelectedGenres, this.SelectedAlbums, this.TrackOrder);
                }

                if (SettingsClient.IsSettingChanged(e, "Behaviour", "EnableLove"))
                {
                    this.EnableLove = (bool)e.SettingValue;
                    this.SetTrackOrder("GenresTrackOrder");
                    await this.GetTracksAsync(null, this.SelectedGenres, this.SelectedAlbums, this.TrackOrder);
                }
            };

            // PubSub Events
            this.eventAggregator.GetEvent <ShellMouseUp>().Subscribe((_) => this.IsGenresZoomVisible = false);

            // Set the initial AlbumOrder
            this.AlbumOrder = (AlbumOrder)SettingsClient.Get <int>("Ordering", "GenresAlbumOrder");

            // Set the initial TrackOrder
            this.SetTrackOrder("GenresTrackOrder");

            // Set width of the panels
            this.LeftPaneWidthPercent  = SettingsClient.Get <int>("ColumnWidths", "GenresLeftPaneWidthPercent");
            this.RightPaneWidthPercent = SettingsClient.Get <int>("ColumnWidths", "GenresRightPaneWidthPercent");

            // Cover size
            this.SetCoversizeAsync((CoverSizeType)SettingsClient.Get <int>("CoverSizes", "GenresCoverSize"));
        }
コード例 #34
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PlayQueueViewModel"/> class.
        /// </summary>
        /// <param name="eventAggregator">The event aggregator.</param>
        /// <param name="playbackService">The playback service.</param>
        /// <param name="openSynoSettings"></param>
        public PlayQueueViewModel(IEventAggregator eventAggregator, IPlaybackService playbackService, INotificationService notificationService, IOpenSynoSettings openSynoSettings, ILogService logService, ITrackViewModelFactory trackViewModelFactory, IPageSwitchingService pageSwitchingService)
        {
            if (eventAggregator == null)
            {
                throw new ArgumentNullException("eventAggregator");
            }

            if (playbackService == null)
            {
                throw new ArgumentNullException("playbackService");
            }

            if (notificationService == null)
            {
                throw new ArgumentNullException("notificationService");
            }

            if (openSynoSettings == null)
            {
                throw new ArgumentNullException("openSynoSettings");
            }

            if (trackViewModelFactory == null)
            {
                throw new ArgumentNullException("trackViewModelFactory");
            }

            if (pageSwitchingService == null)
            {
                throw new ArgumentNullException("pageSwitchingService");
            }

            _trackViewModelFactory = trackViewModelFactory;

            RemoveTracksFromQueueCommand = new DelegateCommand<IEnumerable<object>>(OnRemoveTracksFromQueue);

            Action consecutiveAlbumsIdPatcher = () =>
            {
                var previousAlbumGuid = Guid.Empty;
                string previousAlbumId = null;
                foreach (var trackViewModel in this.PlayQueueItems)
                {
                    if (previousAlbumId != trackViewModel.TrackInfo.ItemPid)
                    {
                        previousAlbumId = trackViewModel.TrackInfo.ItemPid;
                        previousAlbumGuid = Guid.NewGuid();
                    }
                    trackViewModel.ConsecutiveAlbumIdentifier = previousAlbumGuid;
                }
            };

            _playbackService = playbackService;
            this.PlayQueueItems = new ObservableCollection<TrackViewModel>(playbackService.GetTracksInQueue().Select(o => _trackViewModelFactory.Create(o.Guid, o.Track, this._pageSwitchingService)));
            this.PlayQueueItems.CollectionChanged += (s, ea) =>
                                                         {
                                                             consecutiveAlbumsIdPatcher();
                                                         };
            consecutiveAlbumsIdPatcher();
            _playbackService.PlayqueueChanged += this.OnPlayqueueChanged;

            // FIXME : using aggregated event is not a great idea here : we'd rather use a service : that would be cleaner and easier to debug !
            eventAggregator.GetEvent<CompositePresentationEvent<PlayListOperationAggregatedEvent>>().Subscribe(OnPlayListOperation, true);
            this._notificationService = notificationService;
            _openSynoSettings = openSynoSettings;
            _logService = logService;
            _pageSwitchingService = pageSwitchingService;
            _playbackService.TrackStarted += (o, e) =>
                                                 {
                                                     CurrentArtwork = new Uri(e.Track.AlbumArtUrl, UriKind.Absolute);
                                                     this.ActiveTrack = this._trackViewModelFactory.Create(e.Guid, e.Track, this._pageSwitchingService);
                                                 };

            _playbackService.BufferingProgressUpdated += (o, e) =>
                {
                    // throttle refresh through binding.
                    if (_lastBufferProgressUpdate.AddMilliseconds(500) < DateTime.Now || e.BytesLeft == 0)
                    {
                        _lastBufferProgressUpdate = DateTime.Now;
                        this.BufferedBytesCount = e.FileSize - e.BytesLeft;
                        this.CurrentFileSize = e.FileSize;
                        Debug.WriteLine("Download progress : " + (double)(e.FileSize - e.BytesLeft) / (double)e.FileSize * (double)100.0);
                    }
                };

            _playbackService.TrackCurrentPositionChanged += (o, e) =>
                {
                    CurrentPlaybackPercentComplete = e.PlaybackPercentComplete;;
                    CurrentTrackPosition = e.Position;
                };

            PlayCommand = new DelegateCommand<TrackViewModel>(o => OnPlay(o), track => track != null);
            PlayNextCommand = new DelegateCommand(OnPlayNext);
            PausePlaybackCommand = new DelegateCommand(OnPausePlayback);
            ResumePlaybackCommand = new DelegateCommand(OnResumePlayback);
            PlayPreviousCommand = new DelegateCommand(OnPlayPrevious);
            SavePlaylistCommand = new DelegateCommand<IEnumerable<TrackViewModel>>(OnSavePlaylist);
            SelectAllAlbumTracksCommand = new DelegateCommand<Guid>(OnSelectAllAlbumTracks);
        }