Beispiel #1
0
        /// <summary>
        /// Constructs a ProKnowApi object
        /// </summary>
        /// <param name="baseUrl">The base URL to ProKnow, e.g. 'https://example.proknow.com'</param>
        /// <param name="credentialsFile">The path to the ProKnow credentials JSON file</param>
        /// <param name="lockRenewalBuffer">The number of seconds to use as a buffer when renewing a lock for a draft
        /// structure set</param>
        /// <exception cref="ProKnow.Exceptions.ProKnowException">If the credentials file could not be read or is invalid</exception>
        public ProKnowApi(string baseUrl, string credentialsFile, int lockRenewalBuffer = 30)
        {
            _logger = ProKnowLogging.CreateLogger(typeof(ProKnowApi).FullName);
            ProKnowCredentials proKnowCredentials = null;

            try
            {
                using (StreamReader sr = new StreamReader(credentialsFile))
                {
                    proKnowCredentials = JsonSerializer.Deserialize <ProKnowCredentials>(sr.ReadToEnd());
                }
            }
            catch (DirectoryNotFoundException)
            {
                var message = $"The credentials file '{credentialsFile}' was not found.";
                _logger.LogError(message);
                throw new ProKnowException(message);
            }
            catch (FileNotFoundException)
            {
                var message = $"The credentials file '{credentialsFile}' was not found.";
                _logger.LogError(message);
                throw new ProKnowException(message);
            }
            catch (Exception)
            {
                var message = $"The credentials file '{credentialsFile}' is not valid JSON.";
                _logger.LogError(message);
                throw new ProKnowException(message);
            }
            if (proKnowCredentials.Id == null || proKnowCredentials.Secret == null)
            {
                var message = $"The 'id' and/or 'secret' in the credentials file '{credentialsFile}' are missing.";
                _logger.LogError(message);
                throw new ProKnowException(message);
            }
            ConstructorHelper(baseUrl, proKnowCredentials.Id, proKnowCredentials.Secret, lockRenewalBuffer);
        }
Beispiel #2
0
 /// <summary>
 /// Constructs a ProKnowApi object
 /// </summary>
 /// <param name="baseUrl">The base URL to ProKnow, e.g. 'https://example.proknow.com'</param>
 /// <param name="credentialsId">The ID from the ProKnow credentials JSON file</param>
 /// <param name="credentialsSecret">The secret from the ProKnow credentials JSON file</param>
 /// <param name="lockRenewalBuffer">The number of seconds to use as a buffer when renewing a lock for a draft
 /// structure set</param>
 public ProKnowApi(string baseUrl, string credentialsId, string credentialsSecret, int lockRenewalBuffer = 30)
 {
     _logger = ProKnowLogging.CreateLogger(typeof(ProKnowApi).FullName);
     ConstructorHelper(baseUrl, credentialsId, credentialsSecret, lockRenewalBuffer);
 }