/// <summary>Snippet for ListDocuments</summary>
        public async Task ListDocumentsRequestObjectAsync()
        {
            // Snippet: ListDocumentsAsync(ListDocumentsRequest, CallSettings)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            ListDocumentsRequest request = new ListDocumentsRequest
            {
                Parent       = "",
                CollectionId = "",
                OrderBy      = "",
                Mask         = new DocumentMask(),
                Transaction  = ByteString.Empty,
                ReadTime     = new Timestamp(),
                ShowMissing  = false,
            };
            // Make the request
            PagedAsyncEnumerable <ListDocumentsResponse, Document> response = firestoreClient.ListDocumentsAsync(request);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((Document item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over pages (of server-defined size), performing one RPC per page
            await response.AsRawResponses().ForEachAsync((ListDocumentsResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Document item in page)
                {
                    // Do something with each item
                    Console.WriteLine(item);
                }
            });

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int             pageSize   = 10;
            Page <Document> singlePage = await response.ReadPageAsync(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (Document item in singlePage)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
Пример #2
0
        /// <summary>Snippet for PartitionQueryAsync</summary>
        public async Task PartitionQueryRequestObjectAsync()
        {
            // Snippet: PartitionQueryAsync(PartitionQueryRequest, CallSettings)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            PartitionQueryRequest request = new PartitionQueryRequest
            {
                Parent          = "",
                StructuredQuery = new StructuredQuery(),
                PartitionCount  = 0L,
            };
            // Make the request
            PagedAsyncEnumerable <PartitionQueryResponse, Cursor> response = firestoreClient.PartitionQueryAsync(request);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((Cursor item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over pages (of server-defined size), performing one RPC per page
            await response.AsRawResponses().ForEachAsync((PartitionQueryResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Cursor item in page)
                {
                    // Do something with each item
                    Console.WriteLine(item);
                }
            });

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int           pageSize   = 10;
            Page <Cursor> singlePage = await response.ReadPageAsync(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (Cursor item in singlePage)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
Пример #3
0
        /// <summary>Snippet for BeginTransactionAsync</summary>
        public async Task BeginTransactionAsync()
        {
            // Snippet: BeginTransactionAsync(string, CallSettings)
            // Additional: BeginTransactionAsync(string, CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            string database = "";
            // Make the request
            BeginTransactionResponse response = await firestoreClient.BeginTransactionAsync(database);

            // End snippet
        }
        /// <summary>Snippet for DeleteDocumentAsync</summary>
        public async Task DeleteDocumentAsync()
        {
            // Snippet: DeleteDocumentAsync(string,CallSettings)
            // Additional: DeleteDocumentAsync(string,CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            string formattedName = new AnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]").ToString();
            // Make the request
            await firestoreClient.DeleteDocumentAsync(formattedName);

            // End snippet
        }
Пример #5
0
        /// <summary>Snippet for DeleteDocumentAsync</summary>
        public async Task DeleteDocumentAsync()
        {
            // Snippet: DeleteDocumentAsync(string, CallSettings)
            // Additional: DeleteDocumentAsync(string, CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            string name = "";
            // Make the request
            await firestoreClient.DeleteDocumentAsync(name);

            // End snippet
        }
        /// <summary>Snippet for BeginTransactionAsync</summary>
        public async Task BeginTransactionAsync()
        {
            // Snippet: BeginTransactionAsync(string,CallSettings)
            // Additional: BeginTransactionAsync(string,CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            string formattedDatabase = new DatabaseRootName("[PROJECT]", "[DATABASE]").ToString();
            // Make the request
            BeginTransactionResponse response = await firestoreClient.BeginTransactionAsync(formattedDatabase);

            // End snippet
        }
Пример #7
0
        /// <summary>Snippet for CommitAsync</summary>
        public async Task CommitAsync()
        {
            // Snippet: CommitAsync(string, IEnumerable<Write>, CallSettings)
            // Additional: CommitAsync(string, IEnumerable<Write>, CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            string database            = "";
            IEnumerable <Write> writes = new Write[] { new Write(), };
            // Make the request
            CommitResponse response = await firestoreClient.CommitAsync(database, writes);

            // End snippet
        }
        /// <summary>Snippet for UpdateDocumentAsync</summary>
        public async Task UpdateDocumentAsync()
        {
            // Snippet: UpdateDocumentAsync(Document,DocumentMask,CallSettings)
            // Additional: UpdateDocumentAsync(Document,DocumentMask,CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            Document     document   = new Document();
            DocumentMask updateMask = new DocumentMask();
            // Make the request
            Document response = await firestoreClient.UpdateDocumentAsync(document, updateMask);

            // End snippet
        }
        /// <summary>Snippet for CommitAsync</summary>
        public async Task CommitAsync()
        {
            // Snippet: CommitAsync(string,IEnumerable<Write>,CallSettings)
            // Additional: CommitAsync(string,IEnumerable<Write>,CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            string formattedDatabase   = new DatabaseRootName("[PROJECT]", "[DATABASE]").ToString();
            IEnumerable <Write> writes = new List <Write>();
            // Make the request
            CommitResponse response = await firestoreClient.CommitAsync(formattedDatabase, writes);

            // End snippet
        }
        /// <summary>Snippet for RollbackAsync</summary>
        public async Task RollbackAsync()
        {
            // Snippet: RollbackAsync(string,ByteString,CallSettings)
            // Additional: RollbackAsync(string,ByteString,CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            string     formattedDatabase = new DatabaseRootName("[PROJECT]", "[DATABASE]").ToString();
            ByteString transaction       = ByteString.CopyFromUtf8("");
            // Make the request
            await firestoreClient.RollbackAsync(formattedDatabase, transaction);

            // End snippet
        }
Пример #11
0
        /// <summary>Snippet for RollbackAsync</summary>
        public async Task RollbackAsync()
        {
            // Snippet: RollbackAsync(string, ByteString, CallSettings)
            // Additional: RollbackAsync(string, ByteString, CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            string     database    = "";
            ByteString transaction = ByteString.Empty;
            // Make the request
            await firestoreClient.RollbackAsync(database, transaction);

            // End snippet
        }
        /// <summary>Snippet for ListDocumentsAsync</summary>
        public async Task ListDocumentsAsync_RequestObject()
        {
            // Snippet: ListDocumentsAsync(ListDocumentsRequest,CallSettings)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            ListDocumentsRequest request = new ListDocumentsRequest
            {
                Parent       = new AnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]").ToString(),
                CollectionId = "",
            };
            // Make the request
            PagedAsyncEnumerable <ListDocumentsResponse, Document> response =
                firestoreClient.ListDocumentsAsync(request);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((Document item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over pages (of server-defined size), performing one RPC per page
            await response.AsRawResponses().ForEachAsync((ListDocumentsResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Document item in page)
                {
                    Console.WriteLine(item);
                }
            });

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int             pageSize   = 10;
            Page <Document> singlePage = await response.ReadPageAsync(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (Document item in singlePage)
            {
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
        /// <summary>Snippet for BeginTransactionAsync</summary>
        public async Task BeginTransactionAsync_RequestObject()
        {
            // Snippet: BeginTransactionAsync(BeginTransactionRequest,CallSettings)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            BeginTransactionRequest request = new BeginTransactionRequest
            {
                Database = new DatabaseRootName("[PROJECT]", "[DATABASE]").ToString(),
            };
            // Make the request
            BeginTransactionResponse response = await firestoreClient.BeginTransactionAsync(request);

            // End snippet
        }
        /// <summary>Snippet for GetDocumentAsync</summary>
        public async Task GetDocumentAsync_RequestObject()
        {
            // Snippet: GetDocumentAsync(GetDocumentRequest,CallSettings)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            GetDocumentRequest request = new GetDocumentRequest
            {
                Name = new AnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]").ToString(),
            };
            // Make the request
            Document response = await firestoreClient.GetDocumentAsync(request);

            // End snippet
        }
        /// <summary>Snippet for CommitAsync</summary>
        public async Task CommitAsync_RequestObject()
        {
            // Snippet: CommitAsync(CommitRequest,CallSettings)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            CommitRequest request = new CommitRequest
            {
                Database = new DatabaseRootName("[PROJECT]", "[DATABASE]").ToString(),
                Writes   = { },
            };
            // Make the request
            CommitResponse response = await firestoreClient.CommitAsync(request);

            // End snippet
        }
Пример #16
0
        /// <summary>Snippet for DeleteDocumentAsync</summary>
        public async Task DeleteDocumentAsync_RequestObject()
        {
            // Snippet: DeleteDocumentAsync(DeleteDocumentRequest,CallSettings)
            // Additional: DeleteDocumentAsync(DeleteDocumentRequest,CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            DeleteDocumentRequest request = new DeleteDocumentRequest
            {
                AnyPathName = new AnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]"),
            };
            // Make the request
            await firestoreClient.DeleteDocumentAsync(request);

            // End snippet
        }
        /// <summary>Snippet for RollbackAsync</summary>
        public async Task RollbackAsync_RequestObject()
        {
            // Snippet: RollbackAsync(RollbackRequest,CallSettings)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            RollbackRequest request = new RollbackRequest
            {
                Database    = new DatabaseRootName("[PROJECT]", "[DATABASE]").ToString(),
                Transaction = ByteString.CopyFromUtf8(""),
            };
            // Make the request
            await firestoreClient.RollbackAsync(request);

            // End snippet
        }
        /// <summary>Snippet for UpdateDocumentAsync</summary>
        public async Task UpdateDocumentAsync_RequestObject()
        {
            // Snippet: UpdateDocumentAsync(UpdateDocumentRequest,CallSettings)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            UpdateDocumentRequest request = new UpdateDocumentRequest
            {
                Document   = new Document(),
                UpdateMask = new DocumentMask(),
            };
            // Make the request
            Document response = await firestoreClient.UpdateDocumentAsync(request);

            // End snippet
        }
Пример #19
0
        /// <summary>Snippet for ListCollectionIdsAsync</summary>
        public async Task ListCollectionIdsAsync()
        {
            // Snippet: ListCollectionIdsAsync(string, string, int?, CallSettings)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            string parent = "";
            // Make the request
            PagedAsyncEnumerable <ListCollectionIdsResponse, string> response = firestoreClient.ListCollectionIdsAsync(parent);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((string item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over pages (of server-defined size), performing one RPC per page
            await response.AsRawResponses().ForEachAsync((ListCollectionIdsResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (string item in page)
                {
                    // Do something with each item
                    Console.WriteLine(item);
                }
            });

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int           pageSize   = 10;
            Page <string> singlePage = await response.ReadPageAsync(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (string item in singlePage)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
Пример #20
0
        /// <summary>Snippet for BeginTransactionAsync</summary>
        public async Task BeginTransactionRequestObjectAsync()
        {
            // Snippet: BeginTransactionAsync(BeginTransactionRequest, CallSettings)
            // Additional: BeginTransactionAsync(BeginTransactionRequest, CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            BeginTransactionRequest request = new BeginTransactionRequest
            {
                Database = "",
                Options  = new TransactionOptions(),
            };
            // Make the request
            BeginTransactionResponse response = await firestoreClient.BeginTransactionAsync(request);

            // End snippet
        }
Пример #21
0
        /// <summary>Snippet for DeleteDocumentAsync</summary>
        public async Task DeleteDocumentRequestObjectAsync()
        {
            // Snippet: DeleteDocumentAsync(DeleteDocumentRequest, CallSettings)
            // Additional: DeleteDocumentAsync(DeleteDocumentRequest, CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            DeleteDocumentRequest request = new DeleteDocumentRequest
            {
                Name            = "",
                CurrentDocument = new Precondition(),
            };
            // Make the request
            await firestoreClient.DeleteDocumentAsync(request);

            // End snippet
        }
Пример #22
0
        /// <summary>Snippet for RollbackAsync</summary>
        public async Task RollbackRequestObjectAsync()
        {
            // Snippet: RollbackAsync(RollbackRequest, CallSettings)
            // Additional: RollbackAsync(RollbackRequest, CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            RollbackRequest request = new RollbackRequest
            {
                Database    = "",
                Transaction = ByteString.Empty,
            };
            // Make the request
            await firestoreClient.RollbackAsync(request);

            // End snippet
        }
Пример #23
0
        /// <summary>Snippet for BatchWriteAsync</summary>
        public async Task BatchWriteRequestObjectAsync()
        {
            // Snippet: BatchWriteAsync(BatchWriteRequest, CallSettings)
            // Additional: BatchWriteAsync(BatchWriteRequest, CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            BatchWriteRequest request = new BatchWriteRequest
            {
                Database = "",
                Writes   = { new Write(), },
                Labels   = { { "", "" }, },
            };
            // Make the request
            BatchWriteResponse response = await firestoreClient.BatchWriteAsync(request);

            // End snippet
        }
Пример #24
0
        /// <summary>Snippet for CommitAsync</summary>
        public async Task CommitRequestObjectAsync()
        {
            // Snippet: CommitAsync(CommitRequest, CallSettings)
            // Additional: CommitAsync(CommitRequest, CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            CommitRequest request = new CommitRequest
            {
                Database    = "",
                Writes      = { new Write(), },
                Transaction = ByteString.Empty,
            };
            // Make the request
            CommitResponse response = await firestoreClient.CommitAsync(request);

            // End snippet
        }
Пример #25
0
        /// <summary>Snippet for GetDocumentAsync</summary>
        public async Task GetDocumentRequestObjectAsync()
        {
            // Snippet: GetDocumentAsync(GetDocumentRequest, CallSettings)
            // Additional: GetDocumentAsync(GetDocumentRequest, CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            GetDocumentRequest request = new GetDocumentRequest
            {
                Name        = "",
                Mask        = new DocumentMask(),
                Transaction = ByteString.Empty,
            };
            // Make the request
            Document response = await firestoreClient.GetDocumentAsync(request);

            // End snippet
        }
        /// <summary>Snippet for CreateDocumentAsync</summary>
        public async Task CreateDocumentAsync_RequestObject()
        {
            // Snippet: CreateDocumentAsync(CreateDocumentRequest,CallSettings)
            // Additional: CreateDocumentAsync(CreateDocumentRequest,CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            CreateDocumentRequest request = new CreateDocumentRequest
            {
                Parent       = new AnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]").ToString(),
                CollectionId = "",
                DocumentId   = "",
                Document     = new Document(),
            };
            // Make the request
            Document response = await firestoreClient.CreateDocumentAsync(request);

            // End snippet
        }
Пример #27
0
        /// <summary>Snippet for UpdateDocumentAsync</summary>
        public async Task UpdateDocumentRequestObjectAsync()
        {
            // Snippet: UpdateDocumentAsync(UpdateDocumentRequest, CallSettings)
            // Additional: UpdateDocumentAsync(UpdateDocumentRequest, CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            UpdateDocumentRequest request = new UpdateDocumentRequest
            {
                Document        = new Document(),
                UpdateMask      = new DocumentMask(),
                Mask            = new DocumentMask(),
                CurrentDocument = new Precondition(),
            };
            // Make the request
            Document response = await firestoreClient.UpdateDocumentAsync(request);

            // End snippet
        }
Пример #28
0
        /// <summary>Snippet for CreateDocumentAsync</summary>
        public async Task CreateDocumentRequestObjectAsync()
        {
            // Snippet: CreateDocumentAsync(CreateDocumentRequest, CallSettings)
            // Additional: CreateDocumentAsync(CreateDocumentRequest, CancellationToken)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            CreateDocumentRequest request = new CreateDocumentRequest
            {
                Parent       = "",
                CollectionId = "",
                DocumentId   = "",
                Document     = new Document(),
                Mask         = new DocumentMask(),
            };
            // Make the request
            Document response = await firestoreClient.CreateDocumentAsync(request);

            // End snippet
        }
Пример #29
0
 /// <summary>
 /// Asynchronously creates an instance for the specified project and database, using the specified <see cref="FirestoreClient"/>
 /// for RPC operations.
 /// </summary>
 /// <param name="projectId">The ID of the Google Cloud Platform project that contains the database. May be null, in which case
 /// the project will be automatically detected if possible.</param>
 /// <param name="databaseId">The ID of the database within the project. May be null, in which case the default database will be used.</param>
 /// <param name="client">The client to use for RPC operations. May be null, in which case a client will be created with default credentials.</param>
 /// <returns>A task representing the asynchronous operation. When complete, the result of the task is the new instance.</returns>
 public static async Task <FirestoreDb> CreateAsync(string projectId = null, string databaseId = null, FirestoreClient client = null) =>
 new FirestoreDb(
     projectId ?? (await Platform.InstanceAsync().ConfigureAwait(false)).ProjectId,
     databaseId ?? DefaultDatabaseId,
     client ?? await FirestoreClient.CreateAsync().ConfigureAwait(false)
     );