public void FSRollback() { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n :: Starting Rollback ::\n"); if (TransactionId == null) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nNo transaction to rollback, returning!"); return; } var rollbackRequest = new RollbackRequest(); rollbackRequest.Database = Parent; rollbackRequest.Transaction = TransactionId; try { FsClient.Rollback(rollbackRequest); } catch (Exception e) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "Exception caught\n" + e.Message); return; } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nSuccessfully rollback!"); // clear transactionId! ClearTransactionId(); }
public void FSGetDocument() { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n:: Fetch a Specific Document ::\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nEnter Collection [cities]: "); string collectionId = Console.ReadLine(); if (collectionId == "") { collectionId = "cities"; } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nEnter Document Id: "); String docId = Console.ReadLine(); Document retDoc = null; try { retDoc = GetDocument(docId, collectionId); } catch (Grpc.Core.RpcException e) { if (e.Status.StatusCode == Grpc.Core.StatusCode.NotFound) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "\nERROR: Document " + docId + " not found!"); } } if (retDoc != null) { Utils.ReadDocument(retDoc); } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nFinished getting document!\n"); }
public void FSBeginTransaction() { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n :: Starting New Transaction ::\n"); if (TransactionId != null) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "Transaction in play, returning!\n"); return; } var options = new TransactionOptions(); var beginTransactionRequest = new BeginTransactionRequest(); beginTransactionRequest.Database = Parent; beginTransactionRequest.Options = options; var beginTransactionResponse = new BeginTransactionResponse(); try { beginTransactionResponse = FsClient.BeginTransaction(beginTransactionRequest); } catch (Exception e) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "Exception caught\n" + e.Message); return; } TransactionId = beginTransactionResponse.Transaction; FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n Successfully began new transaction '"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, TransactionId.ToBase64().ToString()); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "'!"); }
public FirestoreTestClass(String parent, Firestore.FirestoreClient fsClient, FirestoreAdmin.FirestoreAdminClient fsAdminClient, String baseCollectionId) { Parent = parent; FsClient = fsClient; FsAdminClient = fsAdminClient; BaseCollectionId = baseCollectionId; Utils = new FirestoreTestUtils(); ClearTransactionId(); }
public void ListDocuments() { var listDocumentsRequest = new ListDocumentsRequest(); listDocumentsRequest.Parent = Parent; var listDocumentsResponse = FsClient.ListDocuments(listDocumentsRequest); var documents = listDocumentsResponse.Documents; int i = 0; foreach (var document in documents) { i++; FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nDocument " + i + ": " + document.Name + ""); } }
static void Run() { Ftc.Utils.LoadData(); while (true) { DrawMenu(); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nEnter an Option ('quit' to exit): "); // Prompt string line = Console.ReadLine(); // Get string from user line.Trim(); if (line.Contains("q")) // Check string { return; } ExecuteMenuEntry(line); } }
public void FSListCollectionIds() { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n:: Listing all Collection Ids from Document or Database... ::\n"); var listCollectionIdsRequest = new ListCollectionIdsRequest(); listCollectionIdsRequest.Parent = Parent; var listCollectionIdsResponse = FsClient.ListCollectionIds(listCollectionIdsRequest); var cids = listCollectionIdsResponse.CollectionIds; int i = 0; foreach (var cid in cids) { i++; FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\n:: Collection Id " + i + ": " + cid.ToString()); } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nFinished listing Collection Ids from Document or Database."); }
public static void DrawMenu() { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\n\n Google Firestore RPC Menu \n\n"); // draw.drawLineSeparator(); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, " 1|batchgetdocuments ........ BatchGetDocuments\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, " 2|begintransaction ........ BeginTransaction\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, " 3|commit ................... Commit\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, " 4|createdocument ........... CreateDocument\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, " 5|deletedocument ........... DeleteDocument\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, " 6|getdocument .............. GetDocument\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, " 7|listcollectionids ........ ListCollectionIds\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, " 8|listdocuments ............ ListDocuments\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, " 9|rollback ................. Rollback\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "10|runquery ................. RunQuery\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "11|updatedocument ........... UpdateDocument\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "12|write .................... Write\n\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, " Firestore Admin RPC's \n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "13|createindex .............. CreateIndex\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "14|deleteindex .............. DeleteIndex\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "15|getindex ................. GetIndex\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "16|listindexes .............. ListIndex\n\n"); }
public void FSGetIndex() { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n:: Fetch a Specific Index ::\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nAvailable Indexes:\n"); ListIndexes(); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nEnter Index Id: "); var indexId = Console.ReadLine(); var getIndexRequest = new GetIndexRequest(); getIndexRequest.Name = indexId; Index retIndex; try { retIndex = FsAdminClient.GetIndex(getIndexRequest); } catch (Grpc.Core.RpcException e) { if ((e.Status.StatusCode == Grpc.Core.StatusCode.NotFound) || (e.Status.StatusCode == Grpc.Core.StatusCode.InvalidArgument)) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "\nERROR: Index " + indexId + " not found!\n"); } else { Console.WriteLine("{0} Exception caught.", e); } return; } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); return; } Utils.PrintIndex(retIndex); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nFinished getting index!\n"); }
public void FSDeleteDocument() { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n:: Deleting a Document ::\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nEnter Collection [cities]: "); string collectionId = Console.ReadLine(); if (collectionId == "") { collectionId = "cities"; } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nEnter Document ID: "); var docId = Console.ReadLine(); var deleteDocumentRequest = new DeleteDocumentRequest(); deleteDocumentRequest.Name = Parent + "/documents/" + collectionId + "/" + docId; try { FsClient.DeleteDocument(deleteDocumentRequest); } catch (Grpc.Core.RpcException e) { if (e.Status.StatusCode == Grpc.Core.StatusCode.NotFound) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nDocument does not exists."); } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "\n" + e.Status.Detail); return; } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); return; } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nSuccessfully deleted document!"); }
public void ListIndexes() { var listIndexesRequest = new ListIndexesRequest(); listIndexesRequest.Parent = Parent; ListIndexesResponse listIndexesResponse = new ListIndexesResponse(); try { listIndexesResponse = FsAdminClient.ListIndexes(listIndexesRequest); } catch (Exception e) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "Exception caught\n" + e.Message); } var indexes = listIndexesResponse.Indexes; var i = 0; foreach (var index in indexes) { i++; FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nIndex " + i + ": " + index.Name); } }
public void FSDeleteIndex() { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n:: Delete an Index ::\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nAvailable Indexes:\n"); ListIndexes(); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nEnter Index Id: "); var indexId = Console.ReadLine(); var deleteIndexRequest = new DeleteIndexRequest(); deleteIndexRequest.Name = indexId; try { FsAdminClient.DeleteIndex(deleteIndexRequest); } catch (Grpc.Core.RpcException e) { if ((e.Status.StatusCode == Grpc.Core.StatusCode.NotFound) || (e.Status.StatusCode == Grpc.Core.StatusCode.InvalidArgument)) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "\nERROR: Index " + indexId + " not found!\n"); } else { Console.WriteLine("{0} Exception caught.", e); } return; } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); return; } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nSuccessfully deleted index!\n"); }
public void FSCommit() { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n :: Starting Commit ::\n"); if (TransactionId == null) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "No transaction to commit, returning!\n"); return; } var commitRequest = new CommitRequest(); commitRequest.Database = Parent; commitRequest.Transaction = TransactionId; var commitResponse = new CommitResponse(); try { commitResponse = FsClient.Commit(commitRequest); } catch (Exception e) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "Exception caught\n" + e.Message); return; } var timestamp = commitResponse.CommitTime; if (timestamp == null) { timestamp = new Google.Protobuf.WellKnownTypes.Timestamp(); // fix } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n Successfully commit at "); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, timestamp.ToDateTime().ToString()); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "!"); // clear transactionId! ClearTransactionId(); }
public void FSCreateDocument() { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n:: Creating a new Document ::\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nEnter Collection [cities]: "); string collectionId = Console.ReadLine(); if (collectionId == "") { collectionId = "cities"; } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nEnter Document: "); var docId = Console.ReadLine(); var createDocRequest = new CreateDocumentRequest(); createDocRequest.Parent = Parent; createDocRequest.DocumentId = docId; createDocRequest.CollectionId = collectionId; var fsDocument = new Document(); createDocRequest.Document = fsDocument; try { fsDocument = FsClient.CreateDocument(createDocRequest); } catch (Grpc.Core.RpcException e) { Grpc.Core.Status stat = e.Status; if (stat.StatusCode == Grpc.Core.StatusCode.AlreadyExists) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "\nDocument already exists."); } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\n" + stat.Detail); } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); } // get the document to ensure it was created Document retDoc; try { retDoc = GetDocument(docId, collectionId); } catch (Grpc.Core.RpcException e) { if (e.Status.StatusCode == Grpc.Core.StatusCode.NotFound) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "\nDocument was not added."); } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "\n" + e.Status.Detail); return; } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); return; } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nSuccessfully created new document!\nName:" + retDoc.Name + "\n"); }
public void FSUpdateDocument() { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n:: Update/Create a Document ::\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nEnter Collection [cities]: "); string collectionId = Console.ReadLine(); if (collectionId == "") { collectionId = "cities"; } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nEnter Document Id: "); String docId = Console.ReadLine(); Document updatedDoc = GetDocument(docId, collectionId); MapField <string, Value> fields; if (updatedDoc == null) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nDocument within " + collectionId + " does not exist, create it (y/n): "); String ynValue = Console.ReadLine(); if ((ynValue.ToLower() != "y") && (ynValue.ToLower() != "yes")) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "\nDocument update aborted, returning"); return; } updatedDoc = new Document(); updatedDoc.Name = Parent + "/documents/" + collectionId + "/" + docId; fields = new MapField <string, Value>(); } else { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nAvailable fields in this document to update:\n"); Utils.ProcessFields(updatedDoc); fields = updatedDoc.Fields; } // update/create fields while (true) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nEnter Field Name (blank when finished): "); string fieldName = Console.ReadLine(); if (fieldName != "") { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nEnter Field Value: "); string fieldInValue = Console.ReadLine(); // TODO must query for type and handle!!!! // TODO only handling string!!!! Value fieldValue = new Value(); fieldValue.StringValue = fieldInValue; if (fields.ContainsKey(fieldName)) { fields[fieldName].StringValue = fieldInValue; } else { fields.Add(fieldName, fieldValue); } } else { break; } } var updateDocumentRequest = new UpdateDocumentRequest(); updateDocumentRequest.Document = updatedDoc; Document returnDocument; try { returnDocument = FsClient.UpdateDocument(updateDocumentRequest); } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nSuccessfully updated document!\n"); }
public void FSCreateIndex() { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n:: Creating a Index ::\n"); var index = new Index(); while (true) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nEnter Field Name (blank when finished): "); string fieldName = Console.ReadLine(); if (fieldName != "") { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nEnter Mode (ASCENDING/DESCENDING) [ASCENDING]: "); string fieldMode = Console.ReadLine(); IndexField.Types.Mode indexFieldMode = IndexField.Types.Mode.Ascending; if (fieldMode == "" || fieldMode == "ASCENDING") { indexFieldMode = IndexField.Types.Mode.Ascending; } else if (fieldMode == "DESCENDING") { indexFieldMode = IndexField.Types.Mode.Descending; } else if (fieldMode != "ASCENDING" && fieldMode != "DESCENDING") { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "\nUnrecognized Mode - Choosing ASCENDING"); indexFieldMode = IndexField.Types.Mode.Ascending; } var indexField = new IndexField(); indexField.FieldPath = fieldName; indexField.Mode = indexFieldMode; index.Fields.Add(indexField); } else { var createIndexRequest = new CreateIndexRequest(); createIndexRequest.Parent = Parent; index.CollectionId = BaseCollectionId; createIndexRequest.Index = index; try { Operation operation = FsAdminClient.CreateIndex(createIndexRequest); } catch (Grpc.Core.RpcException e) { Grpc.Core.Status stat = e.Status; if (stat.StatusCode == Grpc.Core.StatusCode.AlreadyExists) { Console.WriteLine("\nIndex already exists."); } Console.WriteLine(stat.Detail); } catch (Exception e) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "\nException caught\n" + e.Message); } break; } } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nSuccessfully created new index!\n"); }
public void FSListDocuments() { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n:: Listing all documents from Firestore... ::\n"); ListDocuments(); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nFinished listing documents!\n"); }
public async Task FSWrite() { try { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n:: Streaming Writes to a Document ::\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nEnter Document Id: "); String docId = Console.ReadLine(); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nStreaming writes to "); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, docId); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "...\n"); Document updatedDoc = GetDocument(docId); MapField <string, Value> fields; if (updatedDoc == null) { updatedDoc = new Document(); updatedDoc.Name = Parent + "/documents/GrpcTestData/" + docId; fields = new MapField <string, Value>(); } else { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nAvailable fields in this document to update:\n"); Utils.ProcessFields(updatedDoc); fields = updatedDoc.Fields; } String streamId = ""; Google.Protobuf.ByteString streamToken = null; using (var writeCall = FsClient.Write()) { var writeRequest = new WriteRequest(); writeRequest.Database = Parent; await writeCall.RequestStream.WriteAsync(writeRequest); await writeCall.ResponseStream.MoveNext(); var responseStr = writeCall.ResponseStream.Current; streamId = responseStr.StreamId; streamToken = responseStr.StreamToken; var responseReaderTask = Task.Run(async() => { while (await writeCall.ResponseStream.MoveNext()) { var response = writeCall.ResponseStream.Current; var writeResults = response.WriteResults; foreach (var writeResult in writeResults) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nWrite result:" + writeResult.ToString()); } } }); var currentWrite = new Write(); var docMask = new DocumentMask(); // update/create fields while (true) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nEnter Field Name (blank when finished): "); string fieldName = Console.ReadLine(); if (fieldName == "") { break; } else { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nEnter Field Value: "); var fieldInValue = Console.ReadLine(); Utils.AddField(fields, fieldName, fieldInValue); docMask.FieldPaths.Add(fieldName); } } writeRequest.Database = Parent; currentWrite.Update = updatedDoc; currentWrite.UpdateMask = docMask; writeRequest.StreamId = streamId; writeRequest.StreamToken = streamToken; writeRequest.Writes.Add(currentWrite); await writeCall.RequestStream.WriteAsync(writeRequest); await writeCall.RequestStream.CompleteAsync(); await responseReaderTask; } } catch (Grpc.Core.RpcException e) { Console.WriteLine("RPC failed", e); throw; } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nSuccessfully streamed updates to the document!\n"); }
public async System.Threading.Tasks.Task FSRunQuery() { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n:: Running a query from Firestore... ::\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nUSA Cities with populations larger than 1 millon\n"); var runQueryRequest = new RunQueryRequest(); runQueryRequest.Parent = "projects/mch-test-49bba/databases/(default)" + "/documents"; StructuredQuery sq = new StructuredQuery(); // just look at cities! var colSel = new StructuredQuery.Types.CollectionSelector(); colSel.CollectionId = "cities"; sq.From.Add(colSel); // only get USA cities with more than 1 million people // define USA filter StructuredQuery.Types.Filter countryFilter = new StructuredQuery.Types.Filter(); StructuredQuery.Types.FieldFilter fieldFilter = new StructuredQuery.Types.FieldFilter(); StructuredQuery.Types.FieldReference field = new StructuredQuery.Types.FieldReference { FieldPath = "country" }; fieldFilter.Field = field; fieldFilter.Op = StructuredQuery.Types.FieldFilter.Types.Operator.Equal; Value filterValue = new Value { StringValue = "USA" }; fieldFilter.Value = filterValue; countryFilter.FieldFilter = fieldFilter; // define 1 Million filer StructuredQuery.Types.Filter populationFilter = new StructuredQuery.Types.Filter(); fieldFilter = new StructuredQuery.Types.FieldFilter(); field = new StructuredQuery.Types.FieldReference { FieldPath = "population" }; fieldFilter.Field = field; fieldFilter.Op = StructuredQuery.Types.FieldFilter.Types.Operator.GreaterThanOrEqual; filterValue = new Value { IntegerValue = 1000000 }; fieldFilter.Value = filterValue; populationFilter.FieldFilter = fieldFilter; StructuredQuery.Types.CompositeFilter compositeFilter = new StructuredQuery.Types.CompositeFilter(); compositeFilter.Filters.Add(countryFilter); compositeFilter.Filters.Add(populationFilter); compositeFilter.Op = StructuredQuery.Types.CompositeFilter.Types.Operator.And; var where = new StructuredQuery.Types.Filter(); where.CompositeFilter = compositeFilter; sq.Where = where; runQueryRequest.StructuredQuery = sq; var select = new StructuredQuery.Types.Projection(); var fields = select.Fields; var fieldRef = new StructuredQuery.Types.FieldReference { FieldPath = "name" }; fields.Add(fieldRef); fieldRef = new StructuredQuery.Types.FieldReference { FieldPath = "population" }; fields.Add(fieldRef); sq.Select = select; var runQueryResponse = new RunQueryResponse(); try { var ret = FsClient.RunQuery(runQueryRequest); var responseStream = ret.ResponseStream; var cancellationToken = new System.Threading.CancellationToken(); while (await responseStream.MoveNext(cancellationToken)) { runQueryResponse = responseStream.Current; Utils.ReadDocument(runQueryResponse.Document); } } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); return; } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nFinished running query!\n"); }
public async System.Threading.Tasks.Task FSBatchGetDocuments() { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n:: Batch Retrieve Documents ::\n"); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nAvailable Docments:\n"); ListDocuments(); var batchGetDocumentsRequest = new BatchGetDocumentsRequest(); batchGetDocumentsRequest.Database = Parent; while (true) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\n\nEnter Collection [cities]: "); string collectionId = Console.ReadLine(); if (collectionId == "") { collectionId = "cities"; } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nEnter Document Name (blank when finished): "); string documentName = Console.ReadLine(); if (documentName != "") { Document doc = null; try { doc = GetDocument(documentName, collectionId); } catch (Grpc.Core.RpcException e) { if (e.Status.StatusCode == Grpc.Core.StatusCode.NotFound) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "ERROR: Document " + documentName + " not found, ignoring ..."); } continue; } batchGetDocumentsRequest.Documents.Add(doc.Name); } else { break; } } var batchGetDocumentsResponse = new BatchGetDocumentsResponse(); try { var ret = FsClient.BatchGetDocuments(batchGetDocumentsRequest); var responseStream = ret.ResponseStream; var cancellationToken = new System.Threading.CancellationToken(); while (await responseStream.MoveNext(cancellationToken)) { batchGetDocumentsResponse = responseStream.Current; Utils.ReadDocument(batchGetDocumentsResponse.Found); } } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); return; } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nSuccessfully batch retrieved documents!\n"); }
public void FSListIndexes() { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n:: Listing all Indexes ::\n"); ListIndexes(); FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nFinished listing indexes!\n"); }
public static void ExecuteMenuEntry(string menuEntry) { switch (menuEntry) { case "1": Ftc.FSBatchGetDocuments().Wait(); break; case "2": Ftc.FSBeginTransaction(); break; case "3": Ftc.FSCommit(); break; case "4": Ftc.FSCreateDocument(); break; case "5": Ftc.FSDeleteDocument(); break; case "6": Ftc.FSGetDocument(); break; case "7": Ftc.FSListCollectionIds(); break; case "8": Ftc.FSListDocuments(); break; case "9": Ftc.FSRollback(); break; case "10": Ftc.FSRunQuery().Wait(); break; case "11": Ftc.FSUpdateDocument(); break; case "12": Ftc.FSWrite().Wait(); break; case "13": Ftc.FSCreateIndex(); break; case "14": Ftc.FSDeleteIndex(); break; case "15": Ftc.FSGetIndex(); break; case "16": Ftc.FSListIndexes(); break; default: FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "Not yet implemneted!\n"); break; } }