private string GetRev(MyCouchStore store, Guid id)
        {
            var doc = store.GetByIdAsync(id.ToString()).Result;

            if (doc == null)
            {
                return(null);
            }

            var retrieved = store.GetByIdAsync <BookOrderDto>(id.ToString()).Result;

            return(retrieved._rev);
        }
예제 #2
0
        public async Task <Car> GetObject(string id)
        {
            using (var db = new MyCouchStore("http://localhost:5984", "cars"))
            {
                var response = await db.GetByIdAsync <Car>(id);

                return(response);
            }
        }
예제 #3
0
파일: Utils.cs 프로젝트: Kethku/DiscordMud
 public static async Task <Member> GetMember(this MyCouchStore db, ulong id)
 {
     if (await db.ExistsAsync(id.ToString()))
     {
         return(await db.GetByIdAsync <Member>(id.ToString()));
     }
     else
     {
         throw new CommandFailedException($"User with id {id} is not in the backend database... Go ask Keith about it");
     }
 }
        public BookOrder Get(Guid id)
        {
            BookOrderDto retrieved;

            using (var store = new MyCouchStore(_databaseUri, _databaseName))
            {
                var doc = store.GetByIdAsync(id.ToString()).Result;

                if (doc == null)
                {
                    return(null);
                }

                retrieved = JsonConvert.DeserializeObject <BookOrderDto>(doc);
            }

            return(BookOrderMapper.MapFrom(retrieved));
        }
예제 #5
0
        public async Task <Comment> GetComment(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(null);
            }
            var comment = _commentCache.Get(id);

            if (comment == null)
            {
                comment = await _commentStore.GetByIdAsync <Comment>(id);

                if (comment != null)
                {
                    _commentCache.Add(comment.Id, comment);
                }
            }
            return(comment);
        }
예제 #6
0
        private static void EnsureViewsAreUpToDate(DatabaseHeaderResponse karinsFilmerDb)
        {
            using (var c = new MyCouchStore(karinsFilmerDb.RequestUri))
            {
                JObject viewJson = ReadViewFileFromSolution();
                string viewJsonString = viewJson.ToString(Formatting.None);

                string jsonFromDb = c.GetByIdAsync("_design/views").Result;
                if (jsonFromDb != null)
                {
                    var o = JsonConvert.DeserializeObject<JObject>(jsonFromDb);
                    o.Remove("_rev");
                    jsonFromDb = o.ToString(Formatting.None);
                }

                if (viewJsonString != jsonFromDb)
                {
                    c.SetAsync("_design/views", viewJsonString).Wait();
                }
            }
        }
예제 #7
0
        private async void ReadButton_Click(object sender, RoutedEventArgs e)
        {
            using (var store = new MyCouchStore("http://*****:*****@localhost:5984", "tv-series"))
            {
                //Get User given document ID with MyCouch.
                var retrieved = await store.GetByIdAsync(SearchIDTxt.Text);

                ReadTxt.Text = retrieved;

                //Aligning the text to be in JSON structure.
                ReadTxt.Text = ReadTxt.Text.Replace(",", "," + System.Environment.NewLine + "    ");
                ReadTxt.Text = ReadTxt.Text.Replace("{", "{" + System.Environment.NewLine + "    ");
                ReadTxt.Text = ReadTxt.Text.Replace("}", System.Environment.NewLine + "}");
                ReadTxt.Text = ReadTxt.Text.Replace(":", ": ");
                ReadTxt.Text = ReadTxt.Text.Replace("[", " [" + System.Environment.NewLine + "    ");
                ReadTxt.Text = ReadTxt.Text.Replace("]", System.Environment.NewLine + "    " + "]");

                SearchIDTxt.IsEnabled = false;
                ReadButton.IsEnabled  = false;
            }
        }
예제 #8
0
        public bool LoadFrom(string couchdb_host, string db_name, string config_name = null, bool track_changes = false)
        {
            using (var couch_store = new MyCouchStore(couchdb_host, db_name))
            {
                config_name = config_name ?? ((this.Config != null) ? this.Config.Id : typeof(T).Name);

                var task = couch_store.GetByIdAsync <T>(config_name);
                task.Wait();
                if (task.Result != null)
                {
                    if (task.Result.PreLoad())
                    {
                        task.Result.OnLoad();
                        this.Config = task.Result;
                        Logger.InfoFormat("Configuration is loaded from {0}/{1}/{2} successfully:\n\r{3}",
                                          couchdb_host, db_name, config_name, couch_store.Client.Serializer.Serialize(task.Result));
                    }
                    else
                    {
                        Logger.InfoFormat("Failed to load configuration from {0}/{1}/{2}", couchdb_host, db_name, config_name);
                        return(false);
                    }
                }
                else
                {
                    if (this.Config != null)
                    {
                        try
                        {
                            var write_task = couch_store.StoreAsync <T>(this.Config);
                            write_task.Wait();
                            Logger.InfoFormat("Configuration does not exist on {0}/{1}/{2}. So wrote back {3}:\n\r{4}",
                                              couchdb_host, db_name, config_name, write_task.Result, couch_store.Client.Serializer.Serialize(this.Config));
                        }
                        catch (Exception ex)
                        {
                            Logger.Warn("Failed to store back defaut configuration", ex);
                            return(false);
                        }
                    }
                }
            }

            if (false == track_changes)
            {
                return(true);
            }

            throw new NotImplementedException("configuration tracking is not available now");

            /*
             * var getChangesRequest = new GetChangesRequest
             * {
             *      Feed = ChangesFeed.Continuous,
             *      Heartbeat = 1000,
             * };
             *
             * _couch_client = new MyCouchClient(couchdb_host, db_name);
             * _cancellation = new CancellationTokenSource();
             * _couch_client.Changes.GetAsync(getChangesRequest, data => this.FeedData(data), _cancellation.Token);
             *
             * return true;
             */
        }
예제 #9
0
        public Opt <Lead> FindById(string leadId)
        {
            var lead = _store.GetByIdAsync <Lead>(leadId).Result;

            return(lead.ToOpt());
        }
예제 #10
0
        public Opt <Product> FindById(string productId)
        {
            var product = _store.GetByIdAsync <Product>(productId).Result;

            return(product.ToOpt());
        }