Beispiel #1
1
        static void Main(string[] args)
        {
            using (var client = new MyCouchClient("http://*****:*****@localhost:5984/foo"))
            {
                var r = client.Views.QueryAsync(new QueryViewRequest("test", "test")).Result;
                //client.Database.PutAsync().Wait();

                //var postEntity = client.Entities.PostAsync(new Doc
                //{
                //    Item = new Nested { EntityId = "Test" }
                //}).Result;

                //var getEntity = client.Entities.GetAsync<Doc>(postEntity.Id).Result;
                //var getJson = client.Documents.GetAsync(postEntity.Id).Result;

                //var all = client.Views.QueryAsync<Doc>(new QueryViewRequest("test", "all")).Result;
            }
        }
 public async Task<SiaqodbDocument> Get(string bucketName, string key, string version)
 {
     using (var client = new MyCouchClient(DbServerUrl , bucketName))
     {
         var startTime = DateTime.Now;
         var response = await client.Documents.GetAsync(key, version);
         if (response.IsSuccess)
         {
             var size = response.Content == null ? 0 : response.Content.Length;
            
             if (size == 0) return null;
             var doc = client.Serializer.Deserialize<CouchDBDocument>(response.Content);
             return Mapper.ToSiaqodbDocument(doc);
         }
         else if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
         {
             if (response.Reason == "no_db_file")
                 throw new BucketNotFoundException(bucketName);
             else
                 throw new DocumentNotFoundException(key, version);
         }
         else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
         {
             throw new InvalidVersionFormatException();
         }
         else throw new GenericCouchDBException(response.Reason, response.StatusCode);
     }
 }
 /// <summary>
 /// Function in <see cref="LocalDB"/> to transmit a single <see cref="Record"/>.
 /// </summary>
 /// <param name="client">Target <see cref="MyCouchClient"/></param>
 /// <param name="card"><see cref="Card"/> to transmit</param>
 public static async void Transmit(MyCouchClient client, Card card)
 {
     MyCouch.Requests.PostEntityRequest<Card> insert = new MyCouch.Requests.PostEntityRequest<Card>(card);
     MyCouch.Responses.EntityResponse<Card> reponse = await client.Entities.PostAsync(insert);
     Console.WriteLine("Response finished");
     Console.ReadLine();
 }
        public async Task<ActionResult> GetResult(int measurePoint, int minutesAgo)
        {
            var viewModel = new TrafficQueryViewModel();
            using (var client = new MyCouchClient("http://db-couchdb.cloudapp.net:5984", "bekk4"))
            {
                var startTime = DateTime.Now.Subtract(new TimeSpan(0, minutesAgo, 0)).ToString("O");
                var startKey = new object[] {measurePoint, startTime};
                var endKey = new object[] {measurePoint, DateTime.Now.ToString("O")};
                var carCountQuery = new QueryViewRequest("stats", "count").Configure(x => x.StartKey(startKey).EndKey(endKey));
                var carCountResult = await client.Views.QueryAsync(carCountQuery);
                var averageSpeedQuery = new QueryViewRequest("stats", "speed").Configure(x => x.StartKey(startKey).EndKey(endKey));
                var averageSpeedResult = await client.Views.QueryAsync(averageSpeedQuery);
                viewModel.MeasurePoint = measurePoint;
                var carCount = carCountResult.Rows.FirstOrDefault();
                if (carCount != null)
                    viewModel.NumberOfCars = int.Parse(carCount.Value);
                var averageSpeed = averageSpeedResult.Rows.FirstOrDefault();
                if (averageSpeed != null)
                {
                    viewModel.AverageSpeed = float.Parse(averageSpeed.Value, CultureInfo.InvariantCulture);
                }
            }

            return PartialView(viewModel);
        } 
Beispiel #5
0
 public Serializer()
 {
     //				serializer = new MyCouch.Serialization.DefaultSerializer(new MyCouch.Serialization.SerializationConfiguration();
     using (var cl = new MyCouch.MyCouchClient("https://127.0.0.1", "none"))
     {
         serializer = cl.Entities.Serializer;
     }
     Console.WriteLine(serializer.GetType());
 }
 // GET api/values
 public IEnumerable<object> Get()
 {
     using (var client = new MyCouchClient("http://db-couchdb.cloudapp.net:5984", "bekk4"))
     {
         var query = new QueryViewRequest("test", "all").Configure(q => q.Reduce(false));
         var result = client.Views.QueryAsync(query).Result;
         return result.Rows.Select(row => row.Value);
     }
 }
        public async Task<List<Notification>> Get()
        {
            var uriBuilder = GetCouchUrl();

            using (var client = new MyCouchClient(uriBuilder.Build()))
            {
                var notifications = await client.Views.QueryAsync<Notification>(new QueryViewRequest("notifications-doc", "all-notifications"));
                return notifications.Rows.Select(r => r.Value).ToList();
            }
        }
        public async Task<Notification> Post(Notification notification)
        {
            var uriBuilder = GetCouchUrl();

            using (var client = new MyCouchClient(uriBuilder.Build()))
            {
                var response = await client.Entities.PostAsync(notification);

                return response.Content;
            }
        }
 // GET: OverView
 public async Task<ActionResult> Index()
 {
     var viewModel = new OverviewViewModel();
     using (var client = new MyCouchClient("http://db-couchdb.cloudapp.net:5984", "bekk4"))
     {
         var query = new QueryViewRequest("test", "measurepoints").Configure(x => x.Group(true));
         var result = await client.Views.QueryAsync(query);
         viewModel.MeasurementPoints = result.Rows.Select(x => x.Key);
     }
     return View(viewModel);
 }
Beispiel #10
0
        private async static Task Test()
        {
            using (var client = new MyCouchClient("http://*****:*****@localhost:5984/", "foo"))
            {
                var db = await client.Database.PutAsync();

                var put = await client.Entities.PutAsync(
                    new Person { Id = "persons/1", Name = "Daniel" });

                var get = await client.Entities.GetAsync<Person>(put.Id);
            }
        }
Beispiel #11
0
 public static void MainHello(String[] args)
 {
     using(var client = new MyCouchClient(new MyCouchUriBuilder("http://localhost:5984/").SetDbName("hellodb").SetBasicCredentials("tpnosql", "tpnosql").Build()))
     {
         client.Entities.PutAsync(new HelloWorld()
             {
                 Id = "HelloWorldId",
                 Hello = "Hello World !",
             }).Wait();
         var hello = client.Entities.GetAsync<HelloWorld>("HelloWorldId");
         Console.WriteLine(hello.Result.Content.Hello);
         client.Entities.DeleteAsync(hello);
     }
 }
        public async Task<StoreResponse> Delete(string bucketName, string key, string version)
        {
            using (var client = new MyCouchClient(DbServerUrl, bucketName))
            {
                
                if (version == null)
                {
                    var response = await client.Documents.GetAsync(key);
                    if (response.IsSuccess)
                    {
                        if (response.Content != null)
                        {
                            CouchDBDocument doc = client.Serializer.Deserialize<CouchDBDocument>(response.Content);
                            version = doc._rev;
                        }

                    }
                    else if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
                    {
                        if (response.Reason == "no_db_file")
                            throw new BucketNotFoundException(bucketName);
                        else
                            throw new DocumentNotFoundException(key, version);
                    }
                    else throw new GenericCouchDBException(response.Reason, response.StatusCode);


                }
                var deletedResponse = await client.Documents.DeleteAsync(key, version);
                if (deletedResponse.IsSuccess)
                {
                    return new StoreResponse() { Key = deletedResponse.Id, Version = deletedResponse.Rev };
                }
                else if (deletedResponse.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    if (deletedResponse.Reason == "no_db_file")
                        throw new BucketNotFoundException(bucketName);
                    else
                        throw new DocumentNotFoundException(key, version);
                }
                else if (deletedResponse.StatusCode == System.Net.HttpStatusCode.BadRequest)
                {
                    throw new InvalidVersionFormatException();
                }
                else throw new GenericCouchDBException(deletedResponse.Reason, deletedResponse.StatusCode);


            }
        }
 public void Add(IList<TrafficMeasurement> trafficMeasurements)
 {
     foreach (var trafficMeasurement in trafficMeasurements)
     {
         try
         {
             var result = _client.Documents.PostAsync(JsonConvert.SerializeObject(trafficMeasurement)).Result;
             if(!result.IsSuccess) throw new Exception();
         }
         catch (Exception)
         {
             _client.Dispose();
             _client = new MyCouchClient("http://db-couchdb.cloudapp.net:5984", "bekk4");
         }
     }
 }
		public async Task<TShirt> Persist(TShirt tshirt)
		{
			// TODO:
			// replace stubed tshirt with actual one
			var tshirtStub = new TShirt();
			tshirtStub.Id = 5;
			tshirtStub.PrintTechnique = "special technique";
			tshirtStub.Title = "stubed tshirt";

			using (var client = new MyCouchClient("http://localhost:5984", "cshirts")) {
				var response = await client.Entities.PostAsync (tshirtStub);
				Console.WriteLine (response); // TODO: remove WriteLine
			}

			// TODO: if successfull
			return tshirtStub;
		}
Beispiel #15
0
        /// <summary>
        /// Will acess thes given file stream and save the comments back to the given clientDB
        /// </summary>
        /// <param name="input"></param>
        /// <param name="clientDb"></param>
        /// <param name="importLimit">Maximum number of comments to read in</param>
        public void ReadInComment(FileStream input, MyCouchClient clientDb, int importLimit)
        {
            Task<EntityResponse<RedditData1.Comment>> t = null;
            StreamReader sr = new StreamReader(input);
            int i = 0;
            string line;

            while ((line = sr.ReadLine()) != null && i < importLimit) {
                Comment obj = JsonConvert.DeserializeObject<Comment>(line);
                t = clientDb.Entities.PostAsync(obj);
                i++;
            }

            logger.Info("Task completed, there were " + i + " comments in this file");

            //Don't return until the last web request has completed
            if (t != null && !t.IsCompleted) Thread.Sleep(100);
        }
        protected async void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            using (var client = new MyCouchClient(CreateUri()))
            {
                await client.Database.PutAsync();
                await client.EnsureDesignDocsExists();

                //var mgr = new UserManager<ApplicationUser>(new MyCouchUserStore<ApplicationUser>(client));
                //var usr = new ApplicationUser { UserName = "******" };
                //await mgr.CreateAsync(usr, "1q2w3e4r");
                //await mgr.AddToRoleAsync(usr.Id, "SuperHeroes");
            }
        }
		public async Task<IEnumerable<TShirt>> GetAll()
		{
			Task<ViewQueryResponse<TShirt>> tshirtTask;
			ViewQueryResponse<TShirt> tshirtResult;
			List<TShirt> tshirts = null;

			// TODO: inject client or replace client with store
			using (var client = new MyCouchClient("http://localhost:5984", "cshirts")) {
				var query = new QueryViewRequest("getAllTshirts");
				tshirtTask = client.Views.QueryAsync<TShirt>(query);
			}

			tshirtResult = await tshirtTask;

			foreach (var row in tshirtResult.Rows) {				
				var tshirt = new TShirt ();
				tshirt = row.Value;
				tshirts.Add (tshirt);
			}
			Console.WriteLine (tshirts);
			return tshirts;
		}
        private async Task CheckTagsViews(MyCouchClient client, string bucketName, Dictionary<string, object> tags)
        {
            if (tags != null && tags.Count > 0)
            {
                HashSet<string> viewsCache = new HashSet<string>();


                QueryViewRequest query = new QueryViewRequest("_all_docs");
                query.StartKey = "_design/";
                query.EndKey = "_design0";

                var all =await client.Views.QueryAsync(query);
                if (!all.IsSuccess)
                    CheckBucketNotFound(bucketName, all);
                if (all.Rows != null)
                {
                    foreach (var row in all.Rows)
                    {
                        string viewName = row.Key.ToString().Replace("_design/", "");
                        viewsCache.Add(viewName);

                    }
                }


                foreach (string tagName in tags.Keys)
                {
                    string viewName = "tags_" + tagName;
                    if (!viewsCache.Contains(viewName) && tags[tagName] != null)
                    {

                        string viewJSON = @"{""_id"":""_design/" + viewName + @""",""language"":""javascript"",""views"":{""" + viewName + @""":{""map"":
                            ""function(doc) {if(doc.tags." + tagName + @"!=null)emit(doc.tags." + tagName + @", null);}""}}}";
                        var getJson = await client.Documents.PostAsync(viewJSON);
                        if (!getJson.IsSuccess)
                            CheckBucketNotFound(bucketName, getJson);
                        viewsCache.Add(viewName);



                    }
                }

            }


        }
 private async Task<SyncLogItem> GetSyncLogItem(string uploadAnchor)
 {
     if (!string.IsNullOrEmpty(uploadAnchor))
     {
         using (var clientLog = new MyCouchClient(DbServerUrl, SyncLogBucket))
         {
             var item = await clientLog.Documents.GetAsync(uploadAnchor);
             if (item.IsSuccess)
             {
                 return Newtonsoft.Json.JsonConvert.DeserializeObject<SyncLogItem>(item.Content);
             }
         }
     }
     return null;
 }
        public async Task<BatchSet> GetChanges(string bucketName, Filter query, int limit, string anchor,string uploadAnchor)
        {
            using (var client = new MyCouchClient(DbServerUrl, bucketName))
            {
                
                GetChangesRequest changesReq = new GetChangesRequest();
                changesReq.Since = anchor;
                changesReq.Limit = limit;
                changesReq.IncludeDocs = true;
                var response = await client.Changes.GetAsync(changesReq);
                if (response.IsSuccess)
                {
                    BatchSet changeSet = new BatchSet();
                    if (response.Results != null)
                    {
                        SyncLogItem logItem = await this.GetSyncLogItem(uploadAnchor);

                        foreach (var row in response.Results)
                        {

                            if (row.Deleted)
                            {
                                this.AddDeletedDoc(changeSet, row, logItem);
                            }
                            else
                            {
                                this.AddChangedDoc(changeSet, row, logItem, query,client.Serializer );
                            }
                        }
                        changeSet.Anchor = response.LastSeq;
                    }

                    return changeSet;
                }
                else CheckBucketNotFound(bucketName, response);
                return null;

            }
        
        }
        public async Task<string> GetSecretAccessKey(string accessKeyId)
        {
            using (var client = new MyCouchClient(DbServerUrl, AccessKeysBucket))
            {
                var response = await client.Documents.GetAsync(accessKeyId);
                if (response.IsSuccess)
                {
                    var size = response.Content == null ? 0 : response.Content.Length;

                    if (size == 0) return null;
                    var doc = client.Serializer.Deserialize<AccessKey>(response.Content);
                    return doc.secretkey;
                }
                
            }
            return null;
        }
 /// <summary>
 /// Function in <see cref="LocalDB"/> to transmit a single <see cref="Record"/>.
 /// </summary>
 /// <param name="client">Target <see cref="MyCouchClient"/></param>
 /// <param name="record"><see cref="Record"/> to transmit</param>
 public static async void Transmit(MyCouchClient client, Record record)
 {
     MyCouch.Requests.PostEntityRequest<Record> insert = new MyCouch.Requests.PostEntityRequest<Record>(record);
     MyCouch.Responses.EntityResponse<Record> reponse = await client.Entities.PostAsync(insert);
 }
        public static List<MyCouch.Responses.EntityResponse<Record>> GetRecords(MyCouchClient client,bool uselessbool)
        {
            List<MyCouch.Responses.EntityResponse<Record>> list = new List<MyCouch.Responses.EntityResponse<Record>>();
            var query = new MyCouch.Requests.QueryViewRequest("view2", "fertigeRecords");

            try
            {
                var response = client.Views.QueryAsync<Record>(query);

                for (int i = 0; i < response.Result.RowCount; i++)
                {
                    MyCouch.Responses.EntityResponse<Record> recordresponse = copyEntry(response.Result.Rows[i].Id);
                    list.Add(recordresponse);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return null;
            }
            return list;
        }
Beispiel #24
0
 public CouchDBBenchmark(MyCouchClient db)
 {
     this.rng = new Random();
     this.db = db;
 }
 public TrafficCollection()
 {
     _client = new MyCouchClient("http://db-couchdb.cloudapp.net:5984", "bekk4");
 }
        private async Task StartRebuildViews(MyCouchClient client, SiaqodbDocument crObjForUpdateViews)
        {
            //force building the index at Store time avoiding to wait on Query time
            if (crObjForUpdateViews.Tags != null)
            {
                foreach (string tagName in crObjForUpdateViews.Tags.Keys)
                {
                    string viewName = "tags_" + tagName;
                    QueryViewRequest query = new QueryViewRequest(viewName, viewName);
                    query.Stale = Stale.UpdateAfter;
                    query.Limit = 1;
                    var res = await client.Views.QueryAsync(query);

                }
            }
        }
        public async Task<BatchResponse> Store(string bucketName, BatchSet batch)
        {
            using (var client = new MyCouchClient(DbServerUrl, bucketName))
            {

                var dbExists= await client.Database.HeadAsync();
                if (dbExists.IsSuccess)
                {
                    BulkRequest bulkRequest = new BulkRequest();

                    DateTime start = DateTime.Now;
                    int size = 0;
                    SiaqodbDocument crObjForUpdateViews = null;
                    if (batch.ChangedDocuments != null)
                    {
                        foreach (SiaqodbDocument obj in batch.ChangedDocuments)
                        {
                            if (obj != null)
                            {
                                if (crObjForUpdateViews == null)
                                    crObjForUpdateViews = obj;

                                await CheckTagsViews(client, bucketName, obj.Tags);
                                CouchDBDocument doc = Mapper.ToCouchDBDoc(obj);
                                var serializedObject = client.Serializer.Serialize<CouchDBDocument>(doc);
                                bulkRequest.Include(serializedObject);
                                size += serializedObject.Length;
                            }
                        }
                    }
                    if (batch.DeletedDocuments != null)
                    {
                        foreach (DeletedDocument obj in batch.DeletedDocuments)
                        {
                            if (obj != null)
                            {
                                if (obj.Version != null)//otherwise means is a non-existing object
                                {
                                    bulkRequest.Delete(obj.Key, obj.Version);
                                }
                            }

                        }
                    }
                    var response = await client.Documents.BulkAsync(bulkRequest);
                    if (response.IsSuccess)
                    {
                        var cnorResponse = new BatchResponse();
                        if (response.Rows != null)
                        {
                            cnorResponse.BatchItemResponses = new List<BatchItemResponse>();
                            SyncLogItem syncLogItem = new SyncLogItem();
                            syncLogItem.KeyVersion = new Dictionary<string, string>();
                            foreach (var row in response.Rows)
                            {
                                BatchItemResponse wresp = new BatchItemResponse();
                                if (!string.IsNullOrEmpty(row.Error))
                                {
                                    cnorResponse.ItemsWithErrors++;
                                }
                                wresp.Error = row.Error;
                                wresp.ErrorDesc = row.Reason;
                                wresp.Key = row.Id;
                                wresp.Version = row.Rev;
                                cnorResponse.BatchItemResponses.Add(wresp);
                                if (string.IsNullOrEmpty(row.Error))
                                {
                                    syncLogItem.KeyVersion.Add(row.Id, row.Rev);
                                }
                            }
                            if (syncLogItem.KeyVersion.Count > 0)
                            {
                                syncLogItem.TimeInserted = DateTime.UtcNow;
                                using (var clientLog = new MyCouchClient(DbServerUrl, SyncLogBucket))
                                {
                                    string serLogItem = Newtonsoft.Json.JsonConvert.SerializeObject(syncLogItem);
                                    var logResp = await clientLog.Documents.PostAsync(serLogItem);
                                    cnorResponse.UploadAnchor = logResp.Id;
                                }
                            }
                        }
                        if (crObjForUpdateViews != null)
                        {
                            await this.StartRebuildViews(client, crObjForUpdateViews);
                        }

                        return cnorResponse;
                    }
                    else CheckBucketNotFound(bucketName, response);
                }
                else if (dbExists.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    throw new BucketNotFoundException(bucketName);
                }
                return null;

            }
        }
Beispiel #28
0
 public CouchDBFixtures(MyCouchClient db)
 {
     this.rng = new Random();
     this.db = db;
 }
        static void MainAsync(string[] args)
        {
            // Display banner
            Console.WriteLine("╔═══════════════════════════════════════╗");
            Console.WriteLine("║         taskwatcher for ADAI          ║");
            Console.WriteLine("╚═══════════════════════════════════════╝");
            Console.WriteLine();

            // Collect credentials
            Console.Write("Enter username for " + DB + ": ");
            username = Console.ReadLine();
            Console.Write("Enter password (hidden): ");
            password = GetPassword();

            // Compose connection string
            connString = "Data Source=" + DB + "; User Id=" + username + "; Password="******"http://www.zeropumpkin.iriscouch.com/taskwatcher-fmb"))
            {
                // Connection never times out, since we use a continuous change feed
                Timeout = TimeSpan.FromMilliseconds(System.Threading.Timeout.Infinite)
            };

            //MyCouchClientBootstrapper bootstrapper = new MyCouchClientBootstrapper();
            //bootstrapper.DbConnectionFn = new Func<ConnectionInfo, IDbConnection>(ProxyDbConnection);

            using (MyCouchClient couch = new MyCouchClient(connInfo))
            {
                Console.Write("Checking remote DB...");

                // Create the database if it does not exist
                couch.Database.PutAsync().Wait();

                Task<DocumentHeaderResponse> headTask = couch.Documents.HeadAsync("_design/tasks");
                headTask.Wait();

                // Create design document with tasks view
                if (!headTask.Result.IsSuccess)
                {
                    string taskDesignDoc = "{ \"language\": \"javascript\", \"views\": { \"tasks\": { \"map\": \"function(doc) { if (doc.$doctype != 'adaiTask') return; emit(doc._id, { 'rev': doc._rev }); }\" } } }";
                    couch.Documents.PutAsync("_design/tasks", taskDesignDoc).Wait();
                }

                Console.WriteLine("exists");

                //using (MyCouchStore store = new MyCouchStore(couch))
                //{
                //    while (true)
                //    {
                //        Console.Write("Enter task ID: ");
                //        string taskID = Console.ReadLine();

                //        //ADAITask t = await store.GetByIdAsync<ADAITask>(taskID);

                //        ADAITask t = new ADAITask(Int32.Parse(taskID));
                //        t.LastUpdated = DateTime.Now;

                //        Console.WriteLine("Storing doc...");
                //        Task<ADAITask> task = store.StoreAsync(t);
                //        task.Wait();
                //        Console.WriteLine("Doc stored: " + t._id);
                //    }
                //}

                //// First get the changes feed to get the last seq nr
                //GetChangesRequest getChangesRequest = new GetChangesRequest
                //{
                //    Feed = ChangesFeed.Normal
                //};

                //Task<ChangesResponse> changesTask = couch.Changes.GetAsync(getChangesRequest);
                //changesTask.Wait();
                //string lastSeqNr = changesTask.Result.LastSeq;

                // Start timer - callback is called immediately
                workTimer = new Timer(WorkTimerCallback, couch, 0, TIMER_PERIOD);

                //// Now start continuous observation using the last seq nr
                //getChangesRequest = new GetChangesRequest
                //{
                //    Feed = ChangesFeed.Continuous,
                //    Since = lastSeqNr
                //};
                //CancellationToken cancellationToken = new CancellationToken();
                //IObservable<string> changes = couch.Changes.ObserveContinuous(getChangesRequest, cancellationToken);

                //changeObserver = new ChangeObserver(workTimer, TIMER_PERIOD);
                //changes.Subscribe(changeObserver);
                //Debug.WriteLine("Started continuous observation, from seq nr " + lastSeqNr);

                while (true)
                {
                    // Do nothing
                }
            }
        }
        public async Task<StoreResponse> Store(string bucketName, SiaqodbDocument document)
        {
            using (var client = new MyCouchClient(DbServerUrl, bucketName))
            {
                
                await CheckTagsViews(client, bucketName, document.Tags);
                CouchDBDocument doc = Mapper.ToCouchDBDoc(document);
                var serializedObj = client.Serializer.Serialize<CouchDBDocument>(doc);

                var response = await client.Documents.PostAsync(serializedObj);
                if (response.IsSuccess)
                {
                    var cnorResponse = new StoreResponse();
                    cnorResponse.Version = response.Rev;
                    cnorResponse.Key = response.Id;

                    await this.StartRebuildViews(client, document);
                    
                    return cnorResponse;
                }
                else if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    throw new BucketNotFoundException(bucketName);
                }
                else if (response.StatusCode == System.Net.HttpStatusCode.Conflict)
                {
                    throw new ConflictException(response.Reason);
                }
                else throw new GenericCouchDBException(response.Reason, response.StatusCode);
            }
        }
 /// <summary>
 /// Function in <see cref="LocalDB"/> to transmit all <see cref="Record"/>s in <see cref="LocalDB.Recordqueue"/> to the <see cref="MyCouchClient"/> every 10 seconds.
 /// </summary>
 /// <param name="client"><see cref="MyCouchClient"/></param>
 public static void Transmitter(MyCouchClient client)
 {
     while (true)
     {
         while (Recordqueue.Count >= 1)
         {
             Record queueitem = Recordqueue.Dequeue();
             Record record;
             if (checkRecords(queueitem.kartenNummer, out record))
             {
                 Notification.playsound(2);
                 record.completeRecord(queueitem.readerIDKommen, queueitem.kommen);
                 Transmit(client, record);
             }
             else
             {
                 Notification.playsound(1);
                 Transmit(client, queueitem);
             }
         }
     }
 }