private bool Authenticate(FotoShoutData.Models.Credentials credential) { try { FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Authenticating for the \"{0}\" user...", credential.Email)); User = _fsWebService.Login(credential); if (User == null) { FotoShoutUtils.Log.LogManager.Error(_logger, "Unexpected error - There is no user on the central fotoShout associated with the fotoShout Authorization key.\r\n"); return(false); } FotoShoutUtils.Log.LogManager.Info(_logger, "Succeeded logged"); FotoShoutUtils.Log.LogManager.Info(_logger, "Getting publish configuration information..."); PublishAccount publishAccount = _fsWebService.GetPublishConfiguration(); if (publishAccount != null && !string.IsNullOrEmpty(publishAccount.Url)) { string url = publishAccount.Url.EndsWith("/") ? publishAccount.Url.Substring(0, publishAccount.Url.Length - 1) : publishAccount.Url; int lastIdx = url.LastIndexOf("/"); if (lastIdx != -1) { string baseAddress = url.Substring(0, lastIdx + 1); string prefix = url.Substring(lastIdx + 1); _c9WebService = new PublishApiWebService(baseAddress, prefix, FotoShoutUtils.Constants.MEDIATYPE_APPLICATION_JSON); string ret = _c9WebService.Authenticate(publishAccount.ApiKey.ToString(), new LoginModel { UserName = publishAccount.Email, Password = publishAccount.Password }); if (string.IsNullOrEmpty(ret)) { FotoShoutUtils.Log.LogManager.Error(_logger, "Unable to authorize to the publishing API.\r\n"); return(false); } } else { FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Unable to authorize to the publishing API - The \"{0}\" url is incorrect.\r\n", publishAccount.Url)); return(false); } } else { FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("There is no publish configuration for the \"{0}\" user.\r\n", publishAccount.Url)); return(false); } FotoShoutUtils.Log.LogManager.Info(_logger, "Successfully authenticated.\r\n"); return(true); } catch (HttpClientServiceException ex) { FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Failed to authenticate : {0} (Status Code: {1})\r\n", ex.Message, (int)ex.StatusCode)); } catch (Exception ex) { FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Failed to authenticate: {0}\r\n", ex.ToString())); } return(false); }
public PublishApiWebService GeneratePublishService() { try { PublishAccount publishAccount = fsWebService.GetPublishConfiguration(); if (publishAccount != null && !string.IsNullOrEmpty(publishAccount.Url)) { return(GeneratePublishService(publishAccount)); } } catch (Exception ex) { if (!ex.Message.Equals("Not Found", StringComparison.InvariantCultureIgnoreCase)) { FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString()); } } return(null); }