public bool ViewExist(string designName, string viewName)
 {
     try
     {
         var doc = _cluster.RetrieveDesignDocument(_bucket, designName);
         if (!VerifyDesignDocumentContainsView(doc, viewName))
         {
             if (_isDevMode)
             {
                 var devDoc = _cluster.RetrieveDesignDocument(_bucket, "dev_" + designName);
                 return(VerifyDesignDocumentContainsView(devDoc, viewName));
             }
             return(false);
         }
         return(true);
     }
     catch (WebException wex)
     {
         if (((HttpWebResponse)wex.Response).StatusCode == HttpStatusCode.NotFound)
         {
             return(false);
         }
         throw;
     }
 }
 public bool ViewExist(string designName, string viewName)
 {
     try
     {
         var doc = _cluster.RetrieveDesignDocument(_bucket, designName);
         if (string.IsNullOrEmpty(doc) ||
             !doc.Contains(string.Format("\"{0}\"", viewName), StringComparison.InvariantCultureIgnoreCase))
         {
             if (_isDevMode)
             {
                 var devDoc = _cluster.RetrieveDesignDocument(_bucket, "dev_" + designName);
                 return(!string.IsNullOrEmpty(devDoc) &&
                        devDoc.Contains(string.Format("\"{0}\"", viewName),
                                        StringComparison.InvariantCultureIgnoreCase));
             }
             return(false);
         }
         return(true);
     }
     catch (WebException wex)
     {
         if (((HttpWebResponse)wex.Response).StatusCode == HttpStatusCode.NotFound)     // If the design document is not found, it will return Error 404
         {
             return(false);
         }
         throw;
     }
 }
        public void Create(string designDocName, string designDoc, Action <string> callback = null)
        {
            var doc = "";

            try
            {
                _cluster.RetrieveDesignDocument(_config.Servers.Bucket, designDocName);
            }
            catch (WebException ex)
            {
                if (!ex.Message.Contains("404"))
                {
                    throw ex;
                }
                //Do nothing on 404
            }

            if (!string.IsNullOrEmpty(doc))
            {
                _cluster.DeleteDesignDocument(_config.Servers.Bucket, designDocName);
            }

            _cluster.CreateDesignDocument(_config.Servers.Bucket, designDocName, designDoc);

            if (callback != null)
            {
                callback(designDocName);
            }
        }