Exemplo n.º 1
0
 // This is internal code.
 private Task <List <CouchView <TKey, TValue, CouchDbUser> > > GetViewAsync <TKey, TValue>(
     View <TKey, TValue, CouchDbUser> view,
     CouchViewOptions <TKey>?options     = null,
     CancellationToken cancellationToken = default)
 {
     return(_db.GetViewAsync <TKey, TValue>(view.Design, view.Value, options, cancellationToken));
 }
Exemplo n.º 2
0
        public JToken[] GetViewRows(string viewName, CouchViewOptions odmViewOptions)
        {
            var        loveSeatViewOption = ToLoveSeatOptions(odmViewOptions);
            ViewResult viewResult         = couchDB.View(viewName, loveSeatViewOption, viewName);

            return(viewResult.Rows.ToArray());
        }
Exemplo n.º 3
0
        public string GetDocIDFromView(string viewName, params object[] key)
        {
            var viewOptions = new CouchViewOptions {
                Key = key.ToList()
            };

            JToken[] rows = clientAdapter.GetViewRows(viewName, viewOptions);

            string docid;

            if (rows.Length > 1)
            {
                throw new Exception("More than one row found in view " + viewName);
            }
            else if (rows.Length == 0)
            {
                // No document found
                docid = null;
            }
            else
            {
                docid = rows[0].Value <string>(CouchDBFieldsConst.ResultRowId);
            }

            return(docid);
        }
Exemplo n.º 4
0
        public async Task GetViewQueryAsync()
        {
            // Arrange
            using var httpTest = new HttpTest();
            SetupViewQueryResponse(httpTest);
            var options = new CouchViewOptions <string[]>
            {
                Key  = new[] { "Luke", "Skywalker" },
                Skip = 10
            };
            var queries = new[]
            {
                options,
                options
            };

            // Act
            var results = await _rebels.GetViewQueryAsync <string[], RebelView>("jedi", "by_name", queries);

            // Assert
            Assert.Equal(2, results.Length);

            Assert.All(results, result =>
            {
                var rebel = Assert.Single(result);
                Assert.Equal("luke", rebel.Id);
                Assert.Equal(new[] { "Luke", "Skywalker" }, rebel.Key);
                Assert.Equal(3, rebel.Value.NumberOfBattles);
            });
            httpTest
            .ShouldHaveCalled("http://localhost/rebels/_design/jedi/_view/by_name/queries")
            .WithVerb(HttpMethod.Post)
            .WithRequestBody(@"{""queries"":[{""key"":[""Luke"",""Skywalker""],""skip"":10},{""key"":[""Luke"",""Skywalker""],""skip"":10}]}");
        }
Exemplo n.º 5
0
        public async Task GetDetailedViewAsync_WithOptions_CallPost()
        {
            // Arrange
            using var httpTest = new HttpTest();
            SetupViewResponse(httpTest);
            var options = new CouchViewOptions <string[]>
            {
                Key    = new[] { "Luke", "Skywalker" },
                Update = UpdateStyle.Lazy
            };

            // Act
            var list = await _rebels.GetDetailedViewAsync <string[], RebelView>("jedi", "by_name", options);

            // Assert
            Assert.Equal(10, list.Offset);
            Assert.Equal(20, list.TotalRows);
            var rebel = Assert.Single(list.Rows);

            Assert.Equal("luke", rebel.Id);
            Assert.Equal(new[] { "Luke", "Skywalker" }, rebel.Key);
            Assert.Equal(3, rebel.Value.NumberOfBattles);
            httpTest
            .ShouldHaveCalled("http://localhost/rebels/_design/jedi/_view/by_name")
            .WithVerb(HttpMethod.Post)
            .WithRequestBody(@"{""key"":[""Luke"",""Skywalker""],""update"":""lazy""}");
        }
Exemplo n.º 6
0
        public async Task GetViewAsync_WithOptions_CallPost()
        {
            // Arrange
            using var httpTest = new HttpTest();
            SetupViewResponse(httpTest);
            var options = new CouchViewOptions <string[]>
            {
                Key  = new[] { "Luke", "Skywalker" },
                Skip = 10
            };

            // Act
            var rebels = await _rebels.GetViewAsync <string[], RebelView>("jedi", "by_name", options);

            // Assert
            var rebel = Assert.Single(rebels);

            Assert.Equal("luke", rebel.Id);
            Assert.Equal(new[] { "Luke", "Skywalker" }, rebel.Key);
            Assert.Equal(3, rebel.Value.NumberOfBattles);
            httpTest
            .ShouldHaveCalled("http://localhost/rebels/_design/jedi/_view/by_name")
            .WithVerb(HttpMethod.Post)
            .WithRequestBody(@"{""key"":[""Luke"",""Skywalker""],""skip"":10}");
        }
Exemplo n.º 7
0
 public ReduceView(CouchDBContextImpl couchDBContext, string viewName)
 {
     this.couchDBContext = couchDBContext;
     this.viewName       = viewName;
     options             = new CouchViewOptions {
         Group = true
     };
 }
Exemplo n.º 8
0
 internal static Task <CouchViewList <TKey, TValue, TDoc> > GetDetailedViewAsync <TKey, TValue, TDoc>(
     this ICouchDatabase <TDoc> db,
     OpenIddictView <TKey, TValue, TDoc> view,
     CouchViewOptions <TKey>?options     = null,
     CancellationToken cancellationToken = default)
     where TDoc : CouchDocument
 {
     return(db.GetDetailedViewAsync <TKey, TValue>(view.Design, view.Value, options, cancellationToken));
 }
Exemplo n.º 9
0
        private EntitiesProcessResult ExecuteView(CouchViewOptions viewOptions)
        {
            JToken[] rows = couchDBContext.ClientAdaper.GetViewRows(viewName, viewOptions);
            var      processingOptions = new OdmViewProcessingOptions(assoicateCollectionsToLoad);

            EntitiesProcessResult processResult = couchDBContext.Process(rows, processingOptions);

            return(processResult);
        }
Exemplo n.º 10
0
        public OdmView(CouchDBContextImpl couchDBContext, string viewName)
        {
            this.couchDBContext = couchDBContext;
            this.viewName       = viewName;

            assoicateCollectionsToLoad = new List <Tuple <string, object> >();
            options = new CouchViewOptions
            {
                IncludeDocs = true
            };
        }
Exemplo n.º 11
0
        private LoveSeat.ViewOptions ToLoveSeatOptions(CouchViewOptions odmViewOptions)
        {
            var opt = new LoveSeat.ViewOptions
            {
                Limit       = odmViewOptions.Limit,
                IncludeDocs = odmViewOptions.IncludeDocs,
                Descending  = odmViewOptions.Descending,
                Reduce      = odmViewOptions.Reduce,
                Group       = odmViewOptions.Group,
                Keys        = odmViewOptions.Keys.Count == 0 ? null : odmViewOptions.Keys.Select(x => new KeyOptions(x)).ToArray()
            };

            CopyKeys(odmViewOptions.Key, opt.Key);
            CopyKeys(odmViewOptions.StartKey, opt.StartKey);
            CopyKeys(odmViewOptions.EndKey, opt.EndKey);


            return(opt);
        }
        /// <inheritdoc/>
        public virtual async ValueTask <TApplication?> FindByClientIdAsync(string identifier,
                                                                           CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(identifier))
            {
                throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
            }

            var options = new CouchViewOptions <string>
            {
                Key         = identifier,
                IncludeDocs = true
            };

            return((await GetDatabase()
                    .GetViewAsync(OpenIddictViews.Application <TApplication> .ClientId, options, cancellationToken)
                    .ConfigureAwait(false))
                   .FirstOrDefault()
                   ?.Document);
        }
Exemplo n.º 13
0
        private Dictionary <string, EntitiesProcessResult> SelectToManyFromViews(LoadRelatedPreProcessInfo preProcessInfo)
        {
            var viewSelectResult = new Dictionary <string, EntitiesProcessResult>();

            foreach (KeyValuePair <string, string[]> viewSelectionInfo in preProcessInfo.ViewsToSelect)
            {
                CouchViewOptions viewOptions = new CouchViewOptions
                {
                    IncludeDocs = true,
                    Keys        = viewSelectionInfo.Value.Cast <object>().ToList()
                };

                JToken[] rows = clientAdapter.GetViewRows(viewSelectionInfo.Key, viewOptions);
                EntitiesProcessResult processResult = Process(rows, new OdmViewProcessingOptions());

                viewSelectResult.Add(viewSelectionInfo.Key, processResult);
            }

            return(viewSelectResult);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Execute the delete.
        /// </summary>
        public void Execute()
        {
            var viewOptions = new CouchViewOptions {
                Key         = new System.Collections.Generic.List <object>(new object[] { key }),
                IncludeDocs = false
            };

            JToken[]    viewRows    = couchDBContext.ClientAdaper.GetViewRows(viewName, viewOptions);
            BulkUpdater bulkUpdater = couchDBContext.ClientAdaper.CreateBulkUpdater(false);

            foreach (JToken viewRow in viewRows)
            {
                string id = viewRow.Value <string>(CouchDBFieldsConst.ResultRowId);
                // We assume the view contain a field call _rev in the value field.
                string rev = viewRow[CouchDBFieldsConst.ViewValue].Value <string>(CouchDBFieldsConst.DocRev);

                bulkUpdater.Delete(id, rev);
            }

            bulkUpdater.Execute();
        }
Exemplo n.º 15
0
        /// <inheritdoc/>
        public Task <CouchViewList <TKey, TValue, TSource> > GetDetailedViewAsync <TKey, TValue>(string design, string view,
                                                                                                 CouchViewOptions <TKey>?options = null, CancellationToken cancellationToken = default)
        {
            Check.NotNull(design, nameof(design));
            Check.NotNull(view, nameof(view));

            IFlurlRequest request = NewRequest()
                                    .AppendPathSegments("_design", design, "_view", view);

            Task <CouchViewList <TKey, TValue, TSource> >?requestTask = options == null
                ? request.GetJsonAsync <CouchViewList <TKey, TValue, TSource> >(cancellationToken)
                : request
                                                                        .PostJsonAsync(options, cancellationToken)
                                                                        .ReceiveJson <CouchViewList <TKey, TValue, TSource> >();

            return(requestTask.SendRequestAsync());
        }
Exemplo n.º 16
0
        /// <inheritdoc/>
        public async Task <List <CouchView <TKey, TValue, TSource> > > GetViewAsync <TKey, TValue>(string design, string view,
                                                                                                   CouchViewOptions <TKey>?options = null, CancellationToken cancellationToken = default)
        {
            CouchViewList <TKey, TValue, TSource> result =
                await GetDetailedViewAsync <TKey, TValue>(design, view, options, cancellationToken)
                .ConfigureAwait(false);

            return(result.Rows);
        }
Exemplo n.º 17
0
 public Newtonsoft.Json.Linq.JToken[] GetViewRows(string viewName, CouchViewOptions viewOptions)
 {
     return(ParseViewResponse(rawResponse));
 }