示例#1
0
        private static async Task <string> GetPersonName(ICouchbaseCollection collection, string documentId)
        {
            // A) kis-nagybetű érzékeny: pontosan úgy kell írni a property nevét, ahogy a CB-ben van, különben null-t ad
            // B) ha property property-je kell, akkor lehet így: name.surname
            var getResult = await collection.LookupInAsync(documentId, specificationBuilder => specificationBuilder.Get("name"));

            return(getResult.ContentAs <string>(0));
        }
        internal static async Task <DocumentLookupResult> LookupDocumentAsync(ICouchbaseCollection collection, string docId, TimeSpan?keyValueTimeout, bool fullDocument = true)
        {
            var specs = new List <LookupInSpec>()
            {
                LookupInSpec.Get(TransactionFields.TransactionInterfacePrefixOnly, isXattr: true),
                LookupInSpec.Get("$document", isXattr: true),
                LookupInSpec.Get(TransactionFields.StagedData, isXattr: true)
            };

            var opts = new LookupInOptions().Defaults(keyValueTimeout).AccessDeleted(true);

            int?txnIndex        = 0;
            int docMetaIndex    = 1;
            int?stagedDataIndex = 2;

            int?fullDocIndex = null;

            if (fullDocument)
            {
                specs.Add(LookupInSpec.GetFull());
                fullDocIndex = specs.Count - 1;
            }

            ILookupInResult lookupInResult;

            try
            {
                lookupInResult = await collection.LookupInAsync(docId, specs, opts).CAF();
            }
            catch (PathInvalidException)
            {
                throw;
            }

            var docMeta = lookupInResult.ContentAs <DocumentMetadata>(docMetaIndex);

            IContentAsWrapper?unstagedContent = fullDocIndex.HasValue
                ? new LookupInContentAsWrapper(lookupInResult, fullDocIndex.Value)
                : null;

            var stagedContent = stagedDataIndex.HasValue && lookupInResult.Exists(stagedDataIndex.Value)
                ? new LookupInContentAsWrapper(lookupInResult, stagedDataIndex.Value)
                : null;

            var result = new DocumentLookupResult(docId,
                                                  unstagedContent,
                                                  stagedContent,
                                                  lookupInResult,
                                                  docMeta,
                                                  collection);

            if (txnIndex.HasValue && lookupInResult.Exists(txnIndex.Value))
            {
                result.TransactionXattrs = lookupInResult.ContentAs <TransactionXattrs>(txnIndex.Value);
            }

            return(result);
        }
        public static Task <ILookupInResult> LookupInAsync(this ICouchbaseCollection collection, string id,
                                                           IEnumerable <LookupInSpec> specs, Action <LookupInOptions> configureOptions)
        {
            var options = new LookupInOptions();

            configureOptions(options);

            return(collection.LookupInAsync(id, specs, options));
        }
        public static Task <ILookupInResult> LookupInAsync(this ICouchbaseCollection collection, string id,
                                                           Action <LookupInSpecBuilder> configureBuilder, LookupInOptions?options)
        {
            var lookupInSpec = new LookupInSpecBuilder();

            configureBuilder(lookupInSpec);

            return(collection.LookupInAsync(id, lookupInSpec.Specs, options));
        }
        public static Task <ILookupInResult> LookupInAsync(this ICouchbaseCollection collection, string id,
                                                           Action <LookupInSpecBuilder> configureBuilder)
        {
            var builder = new LookupInSpecBuilder();

            configureBuilder(builder);

            return(collection.LookupInAsync(id, builder.Specs, LookupInOptions.Default));
        }
        public static Task <ILookupInResult <TDocument> > LookupInAsync <TDocument>(this ICouchbaseCollection collection,
                                                                                    string id, Action <LookupInSpecBuilder <TDocument> > configureBuilder,
                                                                                    Action <LookupInOptions> configureOptions)
        {
            var options = new LookupInOptions();

            configureOptions(options);

            return(collection.LookupInAsync(id, configureBuilder, options));
        }
        public static async Task <ILookupInResult <TDocument> > LookupInAsync <TDocument>(this ICouchbaseCollection collection,
                                                                                          string id, Action <LookupInSpecBuilder <TDocument> > configureBuilder, LookupInOptions?options = null)
        {
            var serializer = options?.SerializerValue ??
                             collection.Scope.Bucket.Cluster.ClusterServices.GetRequiredService <ITypeSerializer>();

            var specBuilder = new LookupInSpecBuilder <TDocument>(serializer);

            configureBuilder(specBuilder);

            return(new LookupInResult <TDocument>(await collection.LookupInAsync(id, specBuilder.Specs, options)
                                                  .ConfigureAwait(false)));
        }
        public static async Task <AtrEntry?> FindEntryForTransaction(
            ICouchbaseCollection atrCollection,
            string atrId,
            string attemptId,
            TimeSpan?keyValueTimeout = null
            )
        {
            _ = atrCollection ?? throw new ArgumentNullException(nameof(atrCollection));
            _ = atrId ?? throw new ArgumentNullException(nameof(atrId));

            var lookupInResult = await atrCollection.LookupInAsync(atrId,
                                                                   specs => specs.Get(TransactionFields.AtrFieldAttempts, isXattr: true),
                                                                   opts => opts.Defaults(keyValueTimeout).AccessDeleted(true)).CAF();

            if (!lookupInResult.Exists(0))
            {
                return(null);
            }

            var asJson = lookupInResult.ContentAs <JObject>(0);

            if (asJson.TryGetValue(attemptId, out var entry))
            {
                var atrEntry = AtrEntry.CreateFrom(entry);
                if (atrEntry?.Cas == null && atrEntry?.State == default)
                {
                    throw new InvalidOperationException("ATR could not be parsed.");
                }

                return(atrEntry);
            }
            else
            {
                return(null);
            }
        }
示例#9
0
        private static async Task <string[]> GetPersonsBookTitles(ICouchbaseCollection collection, string documentId)
        {
            var lookupResult = await collection.LookupInAsync(documentId, builder => builder.Get(BookByTitlePropertyPath));

            return(lookupResult.ContentAs <string[]>(0));
        }
示例#10
0
        private static async Task <bool> PersonPropertyExists(ICouchbaseCollection collection, string documentId, string propertyName)
        {
            var lookupResult = await collection.LookupInAsync(documentId, builder => builder.Exists(propertyName));

            return(lookupResult.ContentAs <bool>(0));
        }
 public static Task <ILookupInResult> LookupInAsync(this ICouchbaseCollection collection, string id,
                                                    IEnumerable <LookupInSpec> specs)
 {
     return(collection.LookupInAsync(id, specs, LookupInOptions.Default));
 }