/// <summary> /// Fetch a snapshot of the document specified by <paramref name="documentReference"/>, with respect to this transaction. /// This method cannot be called after any write operations have been created. /// </summary> /// <param name="documentReference">The document reference to fetch. Must not be null.</param> /// <param name="cancellationToken">A cancellation token to monitor for the asynchronous operation.</param> /// <returns>A snapshot of the given document with respect to this transaction.</returns> public Task <DocumentSnapshot> GetSnapshotAsync(DocumentReference documentReference, CancellationToken cancellationToken = default) { GaxPreconditions.CheckNotNull(documentReference, nameof(documentReference)); GaxPreconditions.CheckState(_writes.IsEmpty, "Firestore transactions require all reads to be executed before all writes."); CancellationToken effectiveToken = GetEffectiveCancellationToken(cancellationToken); return(documentReference.GetSnapshotAsync(TransactionId, effectiveToken)); }
/// <summary> /// Fetch a snapshot of the document specified by <paramref name="documentReference"/>, with respect to this transaction. /// This method cannot be called after any write operations have been created. /// </summary> /// <param name="documentReference">The document reference to fetch. Must not be null.</param> /// <param name="cancellationToken">A cancellation token to monitor for the asynchronous operation.</param> /// <returns>A snapshot of the given document with respect to this transaction.</returns> public Task <DocumentSnapshot> GetSnapshotAsync(DocumentReference documentReference, CancellationToken cancellationToken = default) { GaxPreconditions.CheckNotNull(documentReference, nameof(documentReference)); GaxPreconditions.CheckState(_writes.IsEmpty, "Firestore transactions require all reads to be executed before all writes."); using (var cts = CancellationTokenSource.CreateLinkedTokenSource(CancellationToken, cancellationToken)) { return(documentReference.GetSnapshotAsync(TransactionId, cts.Token)); } }
public async void getSnapshot() { Google.Cloud.Firestore.DocumentReference docRef = db.Collection(collecName).Document(docName); DocumentSnapshot snapshot = await docRef.GetSnapshotAsync(); if (snapshot.Exists) { Console.WriteLine("Document data for {0} document:", snapshot.Id); mediaTitle.Text = "Title: " + snapshot.Id; Dictionary <string, object> media = snapshot.ToDictionary(); foreach (KeyValuePair <string, object> pair in media) { Console.WriteLine("{0}: {1}", pair.Key, pair.Value); switch (pair.Key) { case "Desc": mediaDesc.Text = "Description: " + pair.Value.ToString(); break; case "Rating": mediaRating.Text = "Rating: " + pair.Value.ToString(); break; } } } else { Console.WriteLine("Document {0} does not exist!", snapshot.Id); } //Make Review blocks Query query = db.Collection(collecName).Document(docName).Collection("reviews"); QuerySnapshot allReviewsQuerySnapshot = await query.GetSnapshotAsync(); string rating = "", desc = ""; foreach (DocumentSnapshot documentSnapshot in allReviewsQuerySnapshot.Documents) { if (documentSnapshot.Exists) { Dictionary <string, object> media = documentSnapshot.ToDictionary(); foreach (KeyValuePair <string, object> pair in media) { Console.WriteLine("{0}: {1}", pair.Key, pair.Value); switch (pair.Key) { case "desc": desc = "Description: " + pair.Value.ToString(); break; case "rating": rating = "Rating: " + pair.Value.ToString() + "/10"; break; } } Border border = new Border(); border.MinWidth = 30; border.MinHeight = 20; border.Margin = new Thickness(10); border.BorderThickness = new Thickness(5); border.CornerRadius = new CornerRadius(5); border.BorderBrush = new SolidColorBrush(Colors.Black); StackPanel panel = new StackPanel(); panel.Background = new SolidColorBrush(Colors.Black); TextBlock nameBlock = new TextBlock(); nameBlock.Background = new SolidColorBrush(Colors.Black); nameBlock.Foreground = new SolidColorBrush(Colors.White); nameBlock.Text = "Name: " + documentSnapshot.Id; nameBlock.FontSize = 15; TextBlock ratingBlock = new TextBlock(); ratingBlock.Background = new SolidColorBrush(Colors.Black); ratingBlock.Foreground = new SolidColorBrush(Colors.White); ratingBlock.Text = rating; ratingBlock.FontSize = 15; TextBlock descBlock = new TextBlock(); descBlock.Background = new SolidColorBrush(Colors.Black); descBlock.Foreground = new SolidColorBrush(Colors.White); descBlock.Text = desc; descBlock.FontSize = 15; panel.Children.Add(nameBlock); panel.Children.Add(ratingBlock); panel.Children.Add(descBlock); border.Child = panel; reviewList.Children.Add(border); } else { Console.WriteLine("Document {0} does not exist!", documentSnapshot.Id); } } }