Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="APIException"/> class.
 /// </summary>
 /// <param name="error">The error.</param>
 public APIException(SerializableAPIError error)
     : base(error.ErrorMessage)
 {
     ErrorCode = error.ErrorCode;
 }
Beispiel #2
0
        /// <summary>
        /// Gets the credentials path.
        /// </summary>
        /// <param name="checkAuth">if set to <c>true</c> [check authentication].</param>
        /// <returns></returns>
        /// <exception cref="EVEMon.Common.Exceptions.APIException"></exception>
        private static string GetCredentialsPath(bool checkAuth = false)
        {
            Configuration configuration =
                ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);

            string certPath = Directory.GetParent(configuration.FilePath).Parent?.Parent?.FullName;

            bool fileExists = false;
            if (!String.IsNullOrWhiteSpace(certPath))
            {
                certPath = Path.Combine(certPath, CredentialsDirectory);
                string filePath = Path.Combine(certPath, $"{typeof(TokenResponse).FullName}-{UserId}");
                fileExists = File.Exists(filePath);
            }

            if (!checkAuth || fileExists)
                return certPath;

            SerializableAPIError error = new SerializableAPIError
            {
                ErrorCode = @"Authentication required",
                ErrorMessage = "Authentication required.\n\n" +
                               "Go to External Calendar options to request authentication.\n" +
                               "(i.e. Tools > Options... > Scheduler > External Calendar)"
            };

            throw new APIException(error);
        }