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; }
public SignInService(IOpenSynoSettings openSynoSettings, IEventAggregator eventAggregator, INotificationService notificationService, ILogService logService, IVersionDependentResourcesProvider versionDependentResourcesProvider) { _openSynoSettings = openSynoSettings; _eventAggregator = eventAggregator; _notificationService = notificationService; _logService = logService; _versionDependentResourcesProvider = versionDependentResourcesProvider; }
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; }
/// <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); }
/// <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); }
private void InitializeSettings() { EventAggregator eventAggregator = new EventAggregator(); IoC.Container.Bind<IEventAggregator>().ToConstant(eventAggregator); string synoSettings = "SynoSettings"; _openSynoSettings = IsolatedStorageSettings.ApplicationSettings.Contains(synoSettings) ? (OpenSynoSettings)IsolatedStorageSettings.ApplicationSettings[synoSettings] : new OpenSynoSettings(); // FIXME : Try to get rid of thses registrations and use DI instead. IoC.Container.Bind<IOpenSynoSettings>().ToConstant(_openSynoSettings); // FIXME : Load from config files instead of hard-coded bindings. IVersionDependentResourcesProvider versionDependentResourcesProvider = new VersionDependentResourcesProvider(); IoC.Container.Bind<IVersionDependentResourcesProvider>().ToConstant(versionDependentResourcesProvider).InSingletonScope(); // Retrieve the type IAudioStationSession from a config file, so we can change it. // Also possible : RemoteFileMockAudioStationSession IAudioStationSession audioStationSession; if (PhoneApplicationService.Current.State.ContainsKey("IAudioStationSession")) { audioStationSession = (IAudioStationSession)PhoneApplicationService.Current.State["IAudioStationSession"]; } else { audioStationSession = new AudioStationSession(versionDependentResourcesProvider, _openSynoSettings.DsmVersion) { Host = _openSynoSettings.Host, Port = _openSynoSettings.Port, Token = _openSynoSettings.Token }; } IoC.Container.Bind<IAudioStationSession>().ToConstant(audioStationSession).InSingletonScope(); // Retrieve the type SearchService from a config file, so we can change it. // also possible: MockSearchService; // IoC.Container.Bind<ISearchService>().To(typeof(MockSearchService)).InSingletonScope(); IoC.Container.Bind<ISearchService>().To(typeof(SearchService)).InSingletonScope(); IoC.Container.Bind<ISignInService>().To(typeof(SignInService)).InSingletonScope(); IoC.Container.Bind<IPageSwitchingService>().To<PageSwitchingService>().InSingletonScope(); IoC.Container.Bind<INavigatorService>().To<NavigatorService>().InSingletonScope(); IoC.Container.Bind<ISearchAllResultsViewModelFactory>().To<SearchAllResultsViewModelFactory>().InSingletonScope(); IoC.Container.Bind<SearchViewModel>().ToSelf().InSingletonScope(); IoC.Container.Bind<SearchResultsViewModelFactory>().ToSelf().InSingletonScope(); IoC.Container.Bind<ArtistPanoramaViewModelFactory>().ToSelf().InSingletonScope(); IoC.Container.Bind<ArtistDetailViewModelFactory>().To<ArtistDetailViewModelFactory>().InSingletonScope(); IoC.Container.Bind<ITrackViewModelFactory>().To<TrackViewModelFactory>(); IoC.Container.Bind<PlayQueueViewModel>().ToSelf().InSingletonScope(); IoC.Container.Bind<SearchResultsViewModel>().ToSelf().InSingletonScope(); _logService = new IsolatedStorageLogService(); IoC.Container.Bind<ILogService>().ToConstant(_logService).InSingletonScope(); IoC.Container.Bind<ISearchResultItemViewModelFactory>().To<SearchResultItemViewModelFactory>().InSingletonScope(); IoC.Container.Bind<IUrlParameterToObjectsPlateHeater>().To<UrlParameterToObjectsPlateHeater>().InSingletonScope(); IoC.Container.Bind<IAudioTrackFactory>().To<AudioTrackFactory>().InSingletonScope(); _notificationService = new NotificationService(); IoC.Container.Bind<INotificationService>().ToConstant(_notificationService).InSingletonScope(); ImageCachingService imageCachingService; if (IsolatedStorageSettings.ApplicationSettings.Contains("ImageCachingService")) { imageCachingService = (ImageCachingService)IsolatedStorageSettings.ApplicationSettings["ImageCachingService"]; imageCachingService.Initialize(); } else { // Todo : we should use a factory in order to have a mockable service. imageCachingService = new ImageCachingService(_logService); } imageCachingService.SaveRequested += this.ImageCachingServiceSaveRequested; IoC.Container.Bind<ImageCachingService>().ToConstant(imageCachingService).InSingletonScope(); IoC.Container.Bind<IPlaybackService>().To<PlaybackService>().InSingletonScope(); IoC.Container.Bind<AlbumViewModelFactory>().To<AlbumViewModelFactory>(); ActivateEagerTypes(); ResolvePrivateMembers(); }