private async Task <Response> CheckStatus() { var plexSettings = await PlexSettings.GetSettingsAsync(); if (string.IsNullOrEmpty(plexSettings.PlexAuthToken) || string.IsNullOrEmpty(plexSettings.Ip)) { return(Response.AsJson(false)); } try { var status = PlexApi.GetStatus(plexSettings.PlexAuthToken, plexSettings.FullUri); return(Response.AsJson(status != null)); } catch (Exception) { return(Response.AsJson(false)); } }
private async Task <Response> CheckStatus() { var plexSettings = await PlexSettings.GetSettingsAsync(); if (plexSettings.Enable) { if (string.IsNullOrEmpty(plexSettings.PlexAuthToken) || string.IsNullOrEmpty(plexSettings.Ip)) { return(Response.AsJson(false)); } try { var status = PlexApi.GetStatus(plexSettings.PlexAuthToken, plexSettings.FullUri); return(Response.AsJson(status != null)); } catch (Exception) { return(Response.AsJson(false)); } } var emby = await EmbySettings.GetSettingsAsync(); if (emby.Enable) { if (string.IsNullOrEmpty(emby.AdministratorId) || string.IsNullOrEmpty(emby.Ip)) { return(Response.AsJson(false)); } try { var status = EmbyApi.GetSystemInformation(emby.ApiKey, emby.FullUri); return(Response.AsJson(status?.Version != null)); } catch (Exception) { return(Response.AsJson(false)); } } return(Response.AsJson(false)); }
private Response PlexTest() { var plexSettings = this.Bind <PlexSettings>(); var valid = this.Validate(plexSettings); if (!valid.IsValid) { return(Response.AsJson(valid.SendJsonError())); } var settings = AuthSettings.GetSettings(); if (settings?.PlexAuthToken == null) { return(Response.AsJson(new JsonResponseModel { Result = false, Message = "Plex is not setup yet, you need to update your Authentication settings" })); } try { var status = PlexApi.GetStatus(settings.PlexAuthToken, plexSettings.FullUri); return(status != null ? Response.AsJson(new JsonResponseModel { Result = true, Message = "Connected to Plex successfully!" }) : Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Plex, please check your settings." })); } catch (ApplicationException e) // Exceptions are expected, if we cannot connect so we will just log and swallow them. { Log.Warn("Exception thrown when attempting to get Plex's status: "); Log.Warn(e); var message = $"Could not connect to Plex, please check your settings. <strong>Exception Message:</strong> {e.Message}"; if (e.InnerException != null) { message = $"Could not connect to Plex, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}"; } return(Response.AsJson(new JsonResponseModel { Result = false, Message = message })); } }