public async Task GetServers_ReturnsPlexApiServers() { // Given var plexApiMock = new Mock <IPlexApi>(); var tautulliApiMock = new Mock <ITautulliApi>(); plexApiMock.Setup(x => x.GetServers()) .Returns(() => Task.FromResult( new List <Server>() { new Server() { Name = "Test Server 1" }, new Server() { Name = "Test Server 2" } }) ); var plexWrappedService = new WrappedService(plexApiMock.Object, tautulliApiMock.Object); // When var result = await plexWrappedService.GetServers(); // Then Assert.Equal(2, result.Count); Assert.Equal("Test Server 1", result[0].Name); Assert.Equal("Test Server 2", result[1].Name); }
/// <summary> /// Initializes a new instance of the <see cref="PrintingQueueNamesTypeEditor"/> class. /// </summary> public PrintingQueueNamesTypeEditor() { InitializeComponent(); _service = ServiceFactory.GetCallbackServiceWrapper <ISettingsService>(this); Load(); DataContext = this; }
protected void ResetButton_Click(object sender, EventArgs e) { try { using (WrappedService <IAlarmWorkflowServiceInternal> service = InternalServiceProxy.GetServiceInstance()) { service.Instance.AcknowledgeOperation(Int32.Parse(Request["id"])); Page page = this; ServiceConnection.Instance.RedirectToNoAlarm(ref page); } } catch (EndpointNotFoundException) { Page page = this; ServiceConnection.Instance.RedirectToErrorPage(ref page); } }
private void GetOperation(string id, out Operation operation) { operation = null; try { using (WrappedService <IAlarmWorkflowServiceInternal> service = InternalServiceProxy.GetServiceInstance()) { OperationItem operationItem = service.Instance.GetOperationById(int.Parse(id)); operation = operationItem.ToOperation(); } } catch (EndpointNotFoundException) { Page page = this; ServiceConnection.Instance.RedirectToErrorPage(ref page); } }
private void ReconnectIfError() { if (Error) { if (_dispositioningService != null) { _dispositioningService.Dispose(); } _dispositioningService = ServiceFactory.GetCallbackServiceWrapper <IDispositioningService>(this); if (_operationService != null) { _operationService.Dispose(); } _operationService = ServiceFactory.GetCallbackServiceWrapper <IOperationService>(this); } }
public void SetServer_SetsSelectedServer() { // Given var plexApiMock = new Mock <IPlexApi>(); var tautulliApiMock = new Mock <ITautulliApi>(); var plexWrappedService = new WrappedService(plexApiMock.Object, tautulliApiMock.Object) { SelectedServer = new Server() { Name = "Test Server 1" } }; // When // Then Assert.Equal("Test Server 1", plexWrappedService.SelectedServer.Name); }
internal ViewModel() : base() { Resources = new ObservableCollection<ResourceItem>(); Error = false; try { _dispositioningService = ServiceFactory.GetCallbackServiceWrapper<IDispositioningService>(this); _operationService = ServiceFactory.GetCallbackServiceWrapper<IOperationService>(this); } catch (EndpointNotFoundException) { Error = true; } Task.Factory.StartNew(Update); DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromMilliseconds(Constants.OfpInterval); timer.Tick += timer_Tick; timer.Start(); }
private void Load() { _settings = ServiceFactory.GetCallbackServiceWrapper <ISettingsService>(this); OperationViewer = _settings.Instance.GetSetting(UISettingKeys.OperationViewerKey).GetValue <string>(); FullscreenOnAlarm = _settings.Instance.GetSetting(UISettingKeys.FullscreenOnAlarmKey).GetValue <bool>(); string acknowledgeOperationKeyS = _settings.Instance.GetSetting(UISettingKeys.AcknowledgeOperationKeyKey).GetValue <string>(); Key acknowledgeOperationKey = Key.B; Enum.TryParse <Key>(acknowledgeOperationKeyS, out acknowledgeOperationKey); AcknowledgeOperationKey = acknowledgeOperationKey; AutomaticOperationAcknowledgement.IsEnabled = _settings.Instance.GetSetting(UISettingKeys.AOAIsEnabledKey).GetValue <bool>(); AutomaticOperationAcknowledgement.MaxAge = _settings.Instance.GetSetting(UISettingKeys.AOAMaxAgeKey).GetValue <int>(); AvoidScreensaver = _settings.Instance.GetSetting(UISettingKeys.AvoidScreensaverKey).GetValue <bool>(); MaxAlarmsInUI = _settings.Instance.GetSetting(UISettingKeys.MaxAlarmsInUIKey).GetValue <int>(); EnabledJobs = new ReadOnlyCollection <string>(_settings.Instance.GetSetting(UISettingKeys.JobsConfigurationKey).GetValue <ExportConfiguration>().GetEnabledExports()); EnabledIdleJobs = new ReadOnlyCollection <string>(_settings.Instance.GetSetting(UISettingKeys.IdleJobsConfigurationKey).GetValue <ExportConfiguration>().GetEnabledExports()); SwitchAlarms = _settings.Instance.GetSetting(UISettingKeys.SwitchAlarmsKey).GetValue <bool>(); SwitchTime = _settings.Instance.GetSetting(UISettingKeys.SwitchTimeKey).GetValue <int>(); }
public async Task GetMostPlayedArtists_ThreeArtists_ReturnsThreeMostPlayedArtistsOrderedByPlayCount() { // Given var plexApiMock = new Mock <IPlexApi>(); var tautulliApiMock = new Mock <ITautulliApi>(); plexApiMock.Setup(mock => mock.PlexToken).Returns(() => "token"); tautulliApiMock.Setup(x => x.GetPlaysHistory("Arsène lapostolet", 2021, "track")) .Returns(() => Task.FromResult(GeneratePlaysArtists())); var plexWrappedService = new WrappedService(plexApiMock.Object, tautulliApiMock.Object) { SelectedServer = new Server() { Address = "192.192.192.192", Port = 8080 } }; await plexWrappedService.LoadData("Arsène lapostolet", 2021, "track"); // When var result = plexWrappedService.GetMostPlayedArtists(3); // Then Assert.Equal(3, result.Count); Assert.Equal("Test Artist 1", result[0].Name); Assert.Equal("http://192.192.192.192:8080/library/metadata/1/thumb?X-Plex-Token=token", result[0].ThumbnailUrl); Assert.Equal("Test Artist 2", result[1].Name); Assert.Equal("http://192.192.192.192:8080/library/metadata/2/thumb?X-Plex-Token=token", result[1].ThumbnailUrl); Assert.Equal("Test Artist 3", result[2].Name); Assert.Equal("http://192.192.192.192:8080/library/metadata/3/thumb?X-Plex-Token=token", result[2].ThumbnailUrl); }
internal bool TryGetLatestOperation(out Operation operation, ref Page page) { int maxAgeInMinutes = WebsiteConfiguration.Instance.MaxAge; bool onlyNonAcknowledged = WebsiteConfiguration.Instance.NonAcknowledgedOnly; // For the moment, we are only interested about the latest operation (if any). const int limitAmount = 1; operation = null; try { using (WrappedService <IAlarmWorkflowServiceInternal> service = InternalServiceProxy.GetServiceInstance()) { if (service.IsFaulted) { return(false); } IList <int> ids = service.Instance.GetOperationIds(maxAgeInMinutes, onlyNonAcknowledged, limitAmount); if (ids.Count > 0) { // Retrieve the operation with full detail to allow us to access the route image OperationItem operationItem = service.Instance.GetOperationById(ids[0]); operation = operationItem.ToOperation(); } return(true); } } catch (EndpointNotFoundException) { if (page.GetType().BaseType == typeof(Default) || page.GetType().BaseType == typeof(Idle)) { RedirectToErrorPage(ref page); } } return(false); }
internal ViewModel() : base() { Resources = new ObservableCollection <ResourceItem>(); Error = false; try { _dispositioningService = ServiceFactory.GetCallbackServiceWrapper <IDispositioningService>(this); _operationService = ServiceFactory.GetCallbackServiceWrapper <IOperationService>(this); } catch (EndpointNotFoundException) { Error = true; } Task.Factory.StartNew(Update); DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromMilliseconds(Constants.OfpInterval); timer.Tick += timer_Tick; timer.Start(); }
public bool Initialize() { _service = ServiceFactory.GetCallbackServiceWrapper <ISettingsService>(this); LoadSettings(); return(true); }
private void ReconnectIfError() { if (Error) { if (_dispositioningService != null) { _dispositioningService.Dispose(); } _dispositioningService = ServiceFactory.GetCallbackServiceWrapper<IDispositioningService>(this); if (_operationService != null) { _operationService.Dispose(); } _operationService = ServiceFactory.GetCallbackServiceWrapper<IOperationService>(this); } }
private void Load() { _settings = ServiceFactory.GetCallbackServiceWrapper<ISettingsService>(this); OperationViewer = _settings.Instance.GetSetting(UISettingKeys.OperationViewerKey).GetValue<string>(); FullscreenOnAlarm = _settings.Instance.GetSetting(UISettingKeys.FullscreenOnAlarmKey).GetValue<bool>(); string acknowledgeOperationKeyS = _settings.Instance.GetSetting(UISettingKeys.AcknowledgeOperationKeyKey).GetValue<string>(); Key acknowledgeOperationKey = Key.B; Enum.TryParse<Key>(acknowledgeOperationKeyS, out acknowledgeOperationKey); AcknowledgeOperationKey = acknowledgeOperationKey; AutomaticOperationAcknowledgement.IsEnabled = _settings.Instance.GetSetting(UISettingKeys.AOAIsEnabledKey).GetValue<bool>(); AutomaticOperationAcknowledgement.MaxAge = _settings.Instance.GetSetting(UISettingKeys.AOAMaxAgeKey).GetValue<int>(); AvoidScreensaver = _settings.Instance.GetSetting(UISettingKeys.AvoidScreensaverKey).GetValue<bool>(); MaxAlarmsInUI = _settings.Instance.GetSetting(UISettingKeys.MaxAlarmsInUIKey).GetValue<int>(); EnabledJobs = new ReadOnlyCollection<string>(_settings.Instance.GetSetting(UISettingKeys.JobsConfigurationKey).GetValue<ExportConfiguration>().GetEnabledExports()); EnabledIdleJobs = new ReadOnlyCollection<string>(_settings.Instance.GetSetting(UISettingKeys.IdleJobsConfigurationKey).GetValue<ExportConfiguration>().GetEnabledExports()); SwitchAlarms = _settings.Instance.GetSetting(UISettingKeys.SwitchAlarmsKey).GetValue<bool>(); SwitchTime = _settings.Instance.GetSetting(UISettingKeys.SwitchTimeKey).GetValue<int>(); }