示例#1
0
        /// <summary>
        /// Instantiate the class specifying a DropZoneConfig object.
        /// </summary>
        /// <param name="config">DropZoneConfig with items populated</param>
        public RestApiCalls(DropZoneConfig config)
        {
            if (string.IsNullOrWhiteSpace(config.Password) ^ string.IsNullOrWhiteSpace(config.Salt))
            {
                throw new ArgumentException("Both password and salt must be a non-empty string, or both must be null or empty.  You can not specify just one.");
            }

            _Client.Timeout     = TimeSpan.FromSeconds(config.TimeoutSeconds);
            _Client.BaseAddress = new Uri(config.BaseUrl);
            if (!string.IsNullOrEmpty(config.AccessToken))
            {
                _Client.DefaultRequestHeaders.Add("AccessToken", config.AccessToken);
            }
            if (!string.IsNullOrEmpty(config.AdminToken))
            {
                _Client.DefaultRequestHeaders.Add("AdminToken", config.AdminToken);
            }
            _DropZoneConfig = new DropZoneConfig
            {
                BaseUrl        = config.BaseUrl,
                ZoneName       = config.ZoneName,
                AccessToken    = config.AccessToken,
                AdminToken     = config.AdminToken,
                Password       = config.Password,
                Salt           = config.Salt,
                UseEncryption  = config.UseEncryption && !string.IsNullOrEmpty(config.Password),
                TimeoutSeconds = config.TimeoutSeconds
            };
        }
示例#2
0
        /// <summary>
        /// Instantiate the class specifying a DropZoneConfig object.
        /// </summary>
        /// <param name="config">DropZoneConfig with items populated</param>
        public RestApiCalls(DropZoneConfig config)
        {
            if (config.UseEncryption)
            {
                if (string.IsNullOrWhiteSpace(config.Password) ^ string.IsNullOrWhiteSpace(config.Salt))
                {
                    throw new ArgumentException("Both password and salt must be a non-empty string, or both must be null or empty.  You can not specify just one.");
                }
            }

            _Client.Timeout     = TimeSpan.FromSeconds(config.TimeoutSeconds);
            _Client.BaseAddress = new Uri(config.BaseUrl);
            if (!string.IsNullOrEmpty(config.AccessToken))
            {
                _Client.DefaultRequestHeaders.Add("AccessToken", config.AccessToken);
            }
            if (!string.IsNullOrEmpty(config.AdminToken))
            {
                _Client.DefaultRequestHeaders.Add("AdminToken", config.AdminToken);
            }

            RestApiCalls._DropZoneConfig.BaseUrl = config.BaseUrl;
            RestApiCalls._DropZoneConfig.IgnoreSslCertProblems = config.IgnoreSslCertProblems;
            RestApiCalls._DropZoneConfig.ZoneName       = config.ZoneName;
            RestApiCalls._DropZoneConfig.AccessToken    = config.AccessToken;
            RestApiCalls._DropZoneConfig.AdminToken     = config.AdminToken;
            RestApiCalls._DropZoneConfig.Password       = config.UseEncryption ? config.Password : string.Empty;
            RestApiCalls._DropZoneConfig.Salt           = config.UseEncryption ? config.Salt : string.Empty;
            RestApiCalls._DropZoneConfig.UseEncryption  = config.UseEncryption && !string.IsNullOrEmpty(config.Password);
            RestApiCalls._DropZoneConfig.TimeoutSeconds = config.TimeoutSeconds;

            httpClientHandler.ServerCertificateCustomValidationCallback = ServerCertificateCustomValidation;
            _Client = new HttpClient(httpClientHandler);
        }