コード例 #1
0
        /// <summary>
        /// Returns the default target service endpoint.
        ///
        /// </summary>
        /// <returns> the computed service endpoint </returns>
        /// <exception cref="FormatException"> if the endpoint specified in the client configuration is not a valid URI. </exception>
        public string ComputeEndpoint(BceClientConfiguration config)
        {
            if (config.Endpoint != null)
            {
                return(config.Endpoint);
            }
            string protocol = config.Protocol ?? BceConstants.Protocol.Http;
            string region   = config.Region ?? BceConstants.Region.Beijing;

            return(string.Format(this.serviceEndpointFormat, protocol, region));
        }
コード例 #2
0
        internal static BceClientConfiguration CreateWithDefaultValues()
        {
            var config = new BceClientConfiguration();

            config.Region                   = BceConstants.Region.Beijing;
            config.Protocol                 = BceConstants.Protocol.Http;
            config.TimeoutInMillis          = BceClientConfiguration.DefaultTimeoutInMillis;
            config.ReadWriteTimeoutInMillis = BceClientConfiguration.DefaultReadWriteTimeoutInMillis;
            config.UseNagleAlgorithm        = true;
            config.MaxIdleTimeInMillis      = BceClientConfiguration.DefaultMaxIdleTimeInMillis;
            config.ConnectionLimit          = BceClientConfiguration.DefaultConnectionLimit;
            config.SocketBufferSizeInBytes  = BceClientConfiguration.DefaultSocketBufferSizeInBytes;
            config.Signer                   = new BceV1Signer();
            config.SignOptions              = new SignOptions();
            config.RetryPolicy              = new DefaultRetryPolicy();
            return(config);
        }
コード例 #3
0
 public BceClientConfiguration(BceClientConfiguration other)
 {
     this.Credentials              = other.Credentials;
     this.Region                   = other.Region;
     this.Endpoint                 = other.Endpoint;
     this.Protocol                 = other.Protocol;
     this.TimeoutInMillis          = other.TimeoutInMillis;
     this.ReadWriteTimeoutInMillis = other.ReadWriteTimeoutInMillis;
     this.ProxyHost                = other.ProxyHost;
     this.ProxyPort                = other.ProxyPort;
     this.ProxyCredentials         = other.ProxyCredentials;
     this.UseNagleAlgorithm        = other.UseNagleAlgorithm;
     this.MaxIdleTimeInMillis      = other.MaxIdleTimeInMillis;
     this.ConnectionLimit          = other.ConnectionLimit;
     this.SocketBufferSizeInBytes  = other.SocketBufferSizeInBytes;
     this.Signer                   = other.Signer;
     this.SignOptions              = other.SignOptions;
     this.RetryPolicy              = other.RetryPolicy;
 }
コード例 #4
0
        protected InternalRequest CreateInternalRequest(
            BceClientConfiguration config, string httpMethod, string[] pathComponents)
        {
            var internalRequest = new InternalRequest();

            internalRequest.Config = this.config.Merge(config);
            internalRequest.Uri    = new Uri(
                HttpUtils.AppendUri(this.ComputeEndpoint(internalRequest.Config), pathComponents));
            internalRequest.HttpMethod = httpMethod;
            var timestamp = internalRequest.Config.SignOptions.Timestamp;

            if (timestamp == DateTime.MinValue)
            {
                timestamp = DateTime.Now;
            }
            internalRequest.Headers[BceConstants.HttpHeaders.BceDate] = DateUtils.FormatAlternateIso8601Date(timestamp);
            internalRequest.Headers[BceConstants.HttpHeaders.Host]    = HttpUtils.GenerateHostHeader(internalRequest.Uri);
            return(internalRequest);
        }
コード例 #5
0
 // see https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx
 // How to: Determine Which .NET Framework Versions Are Installed
 private static string GetFrameworkVersion()
 {
     using (RegistryKey ndpKey =
                Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\"))
     {
         if (ndpKey == null)
         {
             return("Unknown(NDP key not found)");
         }
         using (RegistryKey v4Key = ndpKey.OpenSubKey("v4"))
         {
             if (Environment.Version.Major >= 4 && v4Key != null)
             {
                 return(BceClientConfiguration.GetFrameworkVersionAfter4(v4Key));
             }
         }
         using (RegistryKey v35Key = ndpKey.OpenSubKey("v3.5"))
         {
             if (v35Key != null)
             {
                 return("3.5");
             }
         }
         using (RegistryKey v30Key = ndpKey.OpenSubKey("v3.0"))
         {
             if (v30Key != null)
             {
                 return("3.0");
             }
         }
         using (RegistryKey v20Key = ndpKey.OpenSubKey("v2.0.50727"))
         {
             if (v20Key != null)
             {
                 return("2.0");
             }
         }
     }
     return("Unknown");
 }
コード例 #6
0
        public BceClientConfiguration Merge(BceClientConfiguration other)
        {
            BceClientConfiguration ret = new BceClientConfiguration(this);

            if (other == null)
            {
                return(ret);
            }
            if (other.Credentials != null)
            {
                ret.Credentials = other.Credentials;
            }
            if (other.Region != null)
            {
                ret.Region = other.Region;
            }
            if (other.Endpoint != null)
            {
                ret.Endpoint = other.Endpoint;
            }
            if (other.Protocol != null)
            {
                ret.Protocol = other.Protocol;
            }
            if (other.TimeoutInMillis.HasValue)
            {
                ret.TimeoutInMillis = other.TimeoutInMillis;
            }
            if (other.ReadWriteTimeoutInMillis.HasValue)
            {
                ret.ReadWriteTimeoutInMillis = other.ReadWriteTimeoutInMillis;
            }
            if (other.ProxyHost != null)
            {
                ret.ProxyHost = other.ProxyHost;
            }
            if (other.ProxyPort.HasValue)
            {
                ret.ProxyPort = other.ProxyPort;
            }
            if (other.ProxyCredentials != null)
            {
                ret.ProxyCredentials = other.ProxyCredentials;
            }
            if (other.UseNagleAlgorithm.HasValue)
            {
                ret.UseNagleAlgorithm = other.UseNagleAlgorithm;
            }
            if (other.MaxIdleTimeInMillis.HasValue)
            {
                ret.MaxIdleTimeInMillis = other.MaxIdleTimeInMillis;
            }
            if (other.ConnectionLimit.HasValue)
            {
                ret.ConnectionLimit = other.ConnectionLimit;
            }
            if (other.SocketBufferSizeInBytes.HasValue)
            {
                ret.SocketBufferSizeInBytes = other.SocketBufferSizeInBytes;
            }
            if (other.Signer != null)
            {
                ret.Signer = other.Signer;
            }
            if (other.SignOptions != null)
            {
                ret.SignOptions = other.SignOptions;
            }
            if (other.RetryPolicy != null)
            {
                ret.RetryPolicy = other.RetryPolicy;
            }
            return(ret);
        }
コード例 #7
0
 /// <summary>
 /// Constructs a new AbstractBceClient with the specified client configuration.
 ///
 /// <para>
 /// The constructor will extract serviceId from the class name automatically.
 /// And if there is no endpoint specified in the client configuration, the constructor will create a default one.
 ///
 /// </para>
 /// </summary>
 /// <param name="config"> the client configuration. The constructor makes a copy of this parameter so that it is
 ///     safe to change the configuration after then. </param>
 /// <param name="serviceEndpointFormat"> the service domain name format. </param>
 public BceClientBase(BceClientConfiguration config, string serviceEndpointFormat)
 {
     this.serviceEndpointFormat = serviceEndpointFormat;
     this.config     = BceClientConfiguration.CreateWithDefaultValues().Merge(config);
     this.httpClient = new BceHttpClient();
 }