当前位置: 首页>>代码示例>>C#>>正文


C# AuthType.ToString方法代码示例

本文整理汇总了C#中AuthType.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# AuthType.ToString方法的具体用法?C# AuthType.ToString怎么用?C# AuthType.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AuthType的用法示例。


在下文中一共展示了AuthType.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateBucketAsync

        /// <summary>
        /// Creates a new bucket on the cluster
        /// </summary>
        /// <param name="name">Required parameter. Name for new bucket.</param>
        /// <param name="ramQuota">The RAM quota in megabytes. The default is 100.</param>
        /// <param name="bucketType">Required parameter. Type of bucket to be created. “Memcached” configures as Memcached bucket. “Couchbase” configures as Couchbase bucket</param>
        /// <param name="replicaNumber">The number of replicas of each document: minimum 0, maximum 3.</param>
        /// <param name="authType">The authentication type.</param>
        /// <param name="indexReplicas">Disable or enable indexes for bucket replicas.</param>
        /// <param name="flushEnabled">Enables the flush functionality on the specified bucket.</param>
        /// <param name="parallelDbAndViewCompaction">Indicates whether database and view files on disk can be compacted simultaneously.</param>
        /// <param name="saslPassword">Optional Parameter. String. Password for SASL authentication. Required if SASL authentication has been enabled.</param>
        /// <param name="threadNumber">Optional Parameter. Integer from 2 to 8. Change the number of concurrent readers and writers for the data bucket. </param>
        /// <returns>A boolean value indicating the result.</returns>
        public async Task<IResult> CreateBucketAsync(string name, uint ramQuota = 100, BucketTypeEnum bucketType = BucketTypeEnum.Couchbase,
            ReplicaNumber replicaNumber = ReplicaNumber.Two, AuthType authType = AuthType.Sasl, bool indexReplicas = false, bool flushEnabled = false,
            bool parallelDbAndViewCompaction = false, string saslPassword = "", ThreadNumber threadNumber = ThreadNumber.Two)
        {
            IResult result;
            try
            {
                using (var handler = new HttpClientHandler
                {
                    Credentials = new NetworkCredential(_username, _password)
                })
                {
                    using (var client = new HttpClient(handler))
                    {
                        var uri = GetBucketAPIUri();

                        var contentType = new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded");
                        client.DefaultRequestHeaders.Accept.Add(contentType);
                        client.DefaultRequestHeaders.Host = uri.Authority;

                        var request = new HttpRequestMessage(HttpMethod.Post, uri);
                        request.Headers.Authorization = new AuthenticationHeaderValue("Basic",
                          Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Concat(_username, ":", _password))));

                        request.Content = new FormUrlEncodedContent(new Dictionary<string, string>
                        {
                            {"user", _username},
                            {"password", _password},
                            {"name", name},
                            {"authType", authType.ToString().ToLowerInvariant()},
                            {"bucketType", bucketType.ToString().ToLowerInvariant()},
                            {"flushEnabled", flushEnabled ? "0" : "1"},
                            {"proxyPort", 0.ToString(CultureInfo.InvariantCulture)},
                            {"parallelDBAndViewCompaction", parallelDbAndViewCompaction.ToString().ToLowerInvariant()},
                            {"ramQuotaMB", ramQuota.ToString(CultureInfo.InvariantCulture)},
                            {"replicaIndex", indexReplicas ? "0" : "1"},
                            {"replicaNumber", ((int) replicaNumber).ToString(CultureInfo.InvariantCulture)},
                            {"saslPassword", saslPassword},
                            {"threadsNumber", ((int)threadNumber).ToString(CultureInfo.InvariantCulture)}
                        });
                        request.Content.Headers.ContentType = contentType;

                        var task = client.PostAsync(uri, request.Content);

                        var postResult = await task;

                        result = await GetResult(postResult);
                    }
                }
            }
            catch (AggregateException e)
            {
                Log.Error(e);
                result = new DefaultResult(false, e.Message, e);
            }
            return result;
        }
开发者ID:kendallb,项目名称:couchbase-net-client,代码行数:71,代码来源:ClusterManager.cs

示例2: CreateBucketAsync

        /// <summary>
        /// Creates a new bucket on the cluster
        /// </summary>
        /// <param name="name">Required parameter. Name for new bucket.</param>
        /// <param name="ramQuota">The RAM quota in megabytes. The default is 100.</param>
        /// <param name="bucketType">Required parameter. Type of bucket to be created. “Memcached” configures as Memcached bucket. “Couchbase” configures as Couchbase bucket</param>
        /// <param name="replicaNumber">The number of replicas of each document: minimum 0, maximum 3.</param>
        /// <param name="authType">The authentication type.</param>
        /// <param name="indexReplicas">Disable or enable indexes for bucket replicas.</param>
        /// <param name="flushEnabled">Enables the flush functionality on the specified bucket.</param>
        /// <param name="parallelDbAndViewCompaction">Indicates whether database and view files on disk can be compacted simultaneously.</param>
        /// <param name="saslPassword">Optional Parameter. String. Password for SASL authentication. Required if SASL authentication has been enabled.</param>
        /// <param name="threadNumber">Optional Parameter. Integer from 2 to 8. Change the number of concurrent readers and writers for the data bucket. </param>
        /// <returns>A boolean value indicating the result.</returns>
        public async Task<IResult> CreateBucketAsync(string name, uint ramQuota = 100, BucketTypeEnum bucketType = BucketTypeEnum.Couchbase,
            ReplicaNumber replicaNumber = ReplicaNumber.Two, AuthType authType = AuthType.Sasl, bool indexReplicas = false, bool flushEnabled = false,
            bool parallelDbAndViewCompaction = false, string saslPassword = "", ThreadNumber threadNumber = ThreadNumber.Two)
        {
            var uri = GetBucketAPIUri();

            var formData = new Dictionary<string, string>
            {
                {"user", _username},
                {"password", _password},
                {"name", name},
                {"authType", authType.ToString().ToLowerInvariant()},
                {"bucketType", bucketType.ToString().ToLowerInvariant()},
                {"flushEnabled", flushEnabled ? "1" : "0"},
                {"proxyPort", 0.ToString(CultureInfo.InvariantCulture)},
                {"parallelDBAndViewCompaction", parallelDbAndViewCompaction.ToString().ToLowerInvariant()},
                {"ramQuotaMB", ramQuota.ToString(CultureInfo.InvariantCulture)},
                {"replicaIndex", indexReplicas ? "1" : "0"},
                {"replicaNumber", ((int) replicaNumber).ToString(CultureInfo.InvariantCulture)},
                {"saslPassword", saslPassword},
                {"threadsNumber", ((int)threadNumber).ToString(CultureInfo.InvariantCulture)}
            };

            return await PostFormDataAsync(uri, formData);
        }
开发者ID:RossMerr,项目名称:CouchbaseNetClient,代码行数:39,代码来源:ClusterManager.cs

示例3: CreateBucket

        /// <summary>
        /// Creates a new bucket on the cluster
        /// </summary>
        /// <param name="name">Required parameter. Name for new bucket.</param>
        /// <param name="ramQuota">The RAM quota in megabytes. The default is 100.</param>
        /// <param name="bucketType">Required parameter. Type of bucket to be created. “Memcached” configures as Memcached bucket. “Couchbase” configures as Couchbase bucket</param>
        /// <param name="replicaNumber">The number of replicas of each document: minimum 0, maximum 3.</param>
        /// <param name="authType">The authentication type.</param>
        /// <param name="indexReplicas">Disable or enable indexes for bucket replicas.</param>
        /// <param name="flushEnabled">Enables the flush functionality on the specified bucket.</param>
        /// <param name="parallelDbAndViewCompaction">Indicates whether database and view files on disk can be compacted simultaneously.</param>
        /// <param name="saslPassword">Optional Parameter. String. Password for SASL authentication. Required if SASL authentication has been enabled.</param>
        /// <param name="threadNumber">Optional Parameter. Integer from 2 to 8. Change the number of concurrent readers and writers for the data bucket. </param>
        /// <returns>A boolean value indicating the result.</returns>
        public IResult CreateBucket(string name, uint ramQuota = 100, BucketTypeEnum bucketType = BucketTypeEnum.Couchbase, ReplicaNumber replicaNumber = ReplicaNumber.Two, AuthType authType = AuthType.Sasl, bool indexReplicas = false, bool flushEnabled = false, bool parallelDbAndViewCompaction = false, string saslPassword = "", ThreadNumber threadNumber = ThreadNumber.Two)
        {
            IResult result;
            try
            {
                var uri = GetBucketAPIUri();

                var request = WebRequest.Create(uri) as HttpWebRequest;
                request.Method = "POST";
                request.Accept = request.ContentType = "application/x-www-form-urlencoded";
                request.Credentials = new NetworkCredential(_username, _password);
                var formData = new Dictionary<string, object>
                              {
                                    {"user", _username},
                                    {"password", _password},
                                    {"name", name},
                                    {"authType", authType.ToString().ToLowerInvariant()},
                                    {"bucketType", bucketType.ToString().ToLowerInvariant()},
                                    {"flushEnabled", flushEnabled ? "0" : "1"},
                                    {"proxyPort", 0.ToString(CultureInfo.InvariantCulture)},
                                    {"parallelDBAndViewCompaction", parallelDbAndViewCompaction.ToString().ToLowerInvariant()},
                                    {"ramQuotaMB", ramQuota.ToString(CultureInfo.InvariantCulture)},
                                    {"replicaIndex", indexReplicas ? "0" : "1"},
                                    {"replicaNumber", ((int) replicaNumber).ToString(CultureInfo.InvariantCulture)},
                                    {"saslPassword", saslPassword},
                                    {"threadsNumber", ((int)threadNumber).ToString(CultureInfo.InvariantCulture)}
                              };
                var bytes = System.Text.Encoding.UTF8.GetBytes(PostDataDicToString(formData));
                request.ContentLength = bytes.Length;

                using (var stream = request.GetRequestStream())
                {
                    stream.Write(bytes, 0, bytes.Length);
                }

                using (var response = request.GetResponse() as HttpWebResponse)
                {
                    using (var reqStream = response.GetResponseStream())
                    {
                        result = GetResult(response.StatusCode, reqStream);
                    }
                }
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    var stream = e.Response.GetResponseStream();
                    result = WebRequestError(e, GetString(stream));
                }
                else result = WebRequestError(e);
                Log.Error(e);
            }
            catch (Exception e)
            {
                result = WebRequestError(e);
                Log.Error(e);
            }
            return result;
        }
开发者ID:kendallb,项目名称:couchbase-net-client,代码行数:74,代码来源:ClusterManager.cs


注:本文中的AuthType.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。