-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
68 lines (61 loc) · 2.34 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Google.Cloud.Firestore;
using Google.Cloud.Firestore.V1Beta1;
using static Google.Cloud.Firestore.V1Beta1.Target.Types;
using System.Linq;
using Google.Api.Gax;
using System.Collections.Concurrent;
using Google.Protobuf;
using Google.Api.Gax.Grpc;
using static Google.Cloud.Firestore.V1Beta1.StructuredQuery.Types;
namespace FirebaseDotNet
{
class Program
{
static string projectId = "playing-with-firestore";
//static string projectId = "playing-with-firestore-162c9";
static string databaseId = "(default)";
static void Main(string[] args)
{
//Create our database connection
FirestoreDb db = FirestoreDb.Create(projectId);
//Create a query
CollectionReference collection = db.Collection("cities");
Query qref = collection.Where("Capital", QueryOperator.Equal, true);
//Listen to realtime updates
FirebaseDocumentListener listener = qref.AddSnapshotListener();
//Listen to document changes
listener.DocumentChanged += (obj, e) =>
{
var city = e.DocumentSnapshot.Deserialize<City>();
Console.WriteLine(string.Format("City {0} Changed/Added with pop {1}", city.Name, city.Population));
};
//Listen to errors
listener.Error += (obj, e) =>
{
Console.WriteLine("Error => " + e.Message);
};
//Setup some other event handlers that may be interesting
listener.Current += (obj, e) =>
{
Console.WriteLine(string.Format("Listener is current - {0:O}", DateTime.Now.ToUniversalTime()));
};
listener.DocumentRemoved += (obj, e) =>
{
Console.WriteLine("Document Removed " + e.Id);
};
listener.DocumentDeleted += (obj, e) =>
{
Console.WriteLine("Document Deleted " + e.Id);
};
//Cleanup and Exit program if any key is pressed
Console.WriteLine("Press any key to quit");
Console.ReadKey();
Console.WriteLine("Canceling the listener");
listener.Cancel();
Console.WriteLine("Goodbye!");
}
}
}