public void EnableTraktScrobbleHandlerWhenUserChanged()
        {
            // Arrange
            IMediaPortalServices mediaPortalServices = Substitute.For <IMediaPortalServices>();

            mediaPortalServices.GetTraktUserHomePath().Returns(DataPath);
            TraktPluginSettings settings = new TraktPluginSettings
            {
                IsScrobbleEnabled = false
            };
            ITraktSettingsChangeWatcher settingsChangeWatcher = Substitute.For <ITraktSettingsChangeWatcher>();

            settingsChangeWatcher.TraktSettings.Returns(settings);
            mediaPortalServices.GetTraktSettingsWatcher().Returns(settingsChangeWatcher);

            IUserMessageHandler userMessageHandler = Substitute.For <IUserMessageHandler>();

            mediaPortalServices.GetUserMessageHandler().Returns(userMessageHandler);

            ITraktClient    traktClient    = Substitute.For <ITraktClient>();
            IFileOperations fileOperations = Substitute.For <IFileOperations>();

            fileOperations.FileExists(Path.Combine(DataPath, FileName.Authorization.Value)).Returns(true);

            TraktScrobbleHandlerManager traktScrobbleHandler = new TraktScrobbleHandlerManager(mediaPortalServices, traktClient, fileOperations);

            // Act
            settings.IsScrobbleEnabled           = true;
            userMessageHandler.UserChangedProxy += Raise.Event();

            // Assert
            Assert.True(traktScrobbleHandler.IsActive);
        }
Esempio n. 2
0
        public void ShouldEnableTraktSyncHandlerWhenSettingsChange()
        {
            // Arrange
            IMediaPortalServices mediaPortalServices = Substitute.For <IMediaPortalServices>();

            mediaPortalServices.GetTraktUserHomePath().Returns(DataPath);
            TraktPluginSettings settings = new TraktPluginSettings
            {
                IsAutomaticLibrarySyncEnabled = false
            };
            ITraktSettingsChangeWatcher settingsChangeWatcher = Substitute.For <ITraktSettingsChangeWatcher>();

            settingsChangeWatcher.TraktSettings.Returns(settings);
            mediaPortalServices.GetTraktSettingsWatcher().Returns(settingsChangeWatcher);

            ISettingsManager settingsManager = Substitute.For <ISettingsManager>();

            settingsManager.Load <TraktPluginSettings>().Returns(settings);
            mediaPortalServices.GetSettingsManager().Returns(settingsManager);

            ILibrarySynchronization librarySynchronization = Substitute.For <ILibrarySynchronization>();
            IFileOperations         fileOperations         = Substitute.For <IFileOperations>();

            fileOperations.FileExists(Path.Combine(DataPath, FileName.Authorization.Value)).Returns(true);

            TraktSyncHandlerManager traktSyncHandler = new TraktSyncHandlerManager(mediaPortalServices, librarySynchronization, fileOperations);

            // Act
            settings.IsAutomaticLibrarySyncEnabled      = true;
            settingsChangeWatcher.TraktSettingsChanged += Raise.Event();

            // Assert
            Assert.True(traktSyncHandler.IsActive);
        }
Esempio n. 3
0
 public TraktScrobbleHandlerManager(IMediaPortalServices mediaPortalServices, ITraktClient traktClient, IFileOperations fileOperations)
 {
     _mediaPortalServices = mediaPortalServices;
     _traktClient         = traktClient;
     _fileOperations      = fileOperations;
     _mediaPortalServices.GetTraktSettingsWatcher().TraktSettingsChanged += ConfigureHandler;
     _mediaPortalServices.GetUserMessageHandler().UserChangedProxy       += ConfigureHandler;
     ConfigureHandler();
 }
 public TraktSyncHandlerManager(IMediaPortalServices mediaPortalServices, ILibrarySynchronization librarySynchronization, IFileOperations fileOperations)
 {
     _mediaPortalServices    = mediaPortalServices;
     _fileOperations         = fileOperations;
     _librarySynchronization = librarySynchronization;
     _mediaPortalServices.GetTraktSettingsWatcher().TraktSettingsChanged += ConfigureHandler;
     _mediaPortalServices.GetUserMessageHandler().UserChangedProxy       += ConfigureHandler;
     ConfigureHandler();
 }
        private void ConfigureHandler()
        {
            string authorizationFilePath  = Path.Combine(_mediaPortalServices.GetTraktUserHomePath(), FileName.Authorization.Value);
            bool   isUserAuthorized       = _fileOperations.FileExists(authorizationFilePath);
            bool   isAutomaticSyncEnabled = _mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.IsAutomaticLibrarySyncEnabled;

            if (isUserAuthorized && isAutomaticSyncEnabled)
            {
                SubscribeToMessages();
                IsActive = true;
                _mediaPortalServices.GetLogger().Info("Trakt: enabled trakt sync handler.");
            }
            else
            {
                UnsubscribeFromMessages();
                IsActive = false;
                _mediaPortalServices.GetLogger().Info("Trakt: disabled trakt sync handler.");
            }
        }
        private void SetSettings(IMediaPortalServices mediaPortalServices, TraktPluginSettings settings)
        {
            ITraktSettingsChangeWatcher settingsChangeWatcher = Substitute.For <ITraktSettingsChangeWatcher>();

            settingsChangeWatcher.TraktSettings.Returns(settings);
            mediaPortalServices.GetTraktSettingsWatcher().Returns(settingsChangeWatcher);

            ISettingsManager settingsManager = Substitute.For <ISettingsManager>();

            settingsManager.Load <TraktPluginSettings>().Returns(settings);
            mediaPortalServices.GetSettingsManager().Returns(settingsManager);
        }
Esempio n. 7
0
        public void SyncMediaToTrakt()
        {
            if (!IsSynchronizing)
            {
                try
                {
                    IsSynchronizing = true;
                    IThreadPool threadPool = _mediaPortalServices.GetThreadPool();
                    threadPool.Add(() =>
                    {
                        if (_mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.SyncOnlyMovies || _mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.SyncSeriesAndMovies)
                        {
                            TestStatus = "[Trakt.SyncMovies]";
                            _librarySynchronization.SyncMovies();
                        }

                        if (_mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.SyncOnlySeries || _mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.SyncSeriesAndMovies)
                        {
                            TestStatus = "[Trakt.SyncSeries]";
                            _librarySynchronization.SyncSeries();
                        }
                        IsSynchronizing = false;
                        TestStatus      = "[Trakt.SyncFinished]";
                    }, ThreadPriority.BelowNormal);
                }
                catch (MediaLibraryNotConnectedException ex)
                {
                    TestStatus = "[Trakt.MediaLibraryNotConnected]";
                    _mediaPortalServices.GetLogger().Error(ex.Message);
                }
                catch (Exception ex)
                {
                    TestStatus = "[Trakt.SyncingFailed]";
                    _mediaPortalServices.GetLogger().Error(ex.Message);
                }
            }
        }