Couchbase.Management.Bucket.IsValid C# (CSharp) Method

IsValid() public method

public IsValid ( ) : bool
return bool
        public bool IsValid()
        {
            ValidationErrors = new Dictionary<string, string>();

            if (string.IsNullOrEmpty(Name))
                ValidationErrors["Name"] = "Name must be specified";

            if (RamQuotaMB < MIN_RAM_QUOTA)
                ValidationErrors["RamQuotaMB"] = "RamQuotaMB must be at least " + MIN_RAM_QUOTA;

            if (AuthType == AuthTypes.None && (ProxyPort == null || !ProxyPort.HasValue))
                ValidationErrors["ProxyPort"] = "ProxyPort is required when AuthType is 'none'";

            if (AuthType == AuthTypes.Sasl && (ProxyPort != null && ProxyPort.HasValue))
                ValidationErrors["ProxyPort"] = "ProxyPort may not be used with AuthType 'sasl'";

            return ValidationErrors.Keys.Count == 0;
        }

Usage Example

Ejemplo n.º 1
0
        public void CreateBucket(Bucket bucket)
        {
            if (!bucket.IsValid())
            {
                var message = string.Join(Environment.NewLine, bucket.ValidationErrors.Values.ToArray());
                throw new ArgumentException(message);
            }

            var sb = new StringBuilder();

            sb.AppendFormat("name={0}", bucket.Name);
            sb.AppendFormat("&ramQuotaMB={0}", bucket.RamQuotaMB);

            if (bucket.AuthType == AuthTypes.None)
            {
                sb.AppendFormat("&proxyPort={0}", bucket.ProxyPort);
            }
            if (bucket.AuthType == AuthTypes.Sasl && !string.IsNullOrEmpty(bucket.Password))
            {
                sb.AppendFormat("&saslPassword={0}", bucket.Password);
            }

            sb.AppendFormat("&authType={0}", Enum.GetName(typeof(AuthTypes), bucket.AuthType).ToLower());;
            sb.AppendFormat("&bucketType={0}", Enum.GetName(typeof(BucketTypes), bucket.BucketType).ToLower());
            sb.AppendFormat("&replicaNumber={0}", bucket.ReplicaNumber);

            HttpHelper.Post(_bucketUri, _username, _password, sb.ToString(), HttpHelper.CONTENT_TYPE_FORM);
        }
All Usage Examples Of Couchbase.Management.Bucket::IsValid
Bucket