public async Task Readme(string configFile) { // Load configuration var config = BigtableConfig.Load(configFile); // Create credentials var credentials = await BigtableCredentials.UseApplicationDefaultCredentialsAsync(); // Data client using (var dataClient = new BigDataClient(credentials, config)) { // Scan myTable var rows = await dataClient.GetRowsAsync( tableName : "myTable", startKey : "abc", endKey : "def", rowLimit : 20 ); // Show the user foreach (var row in rows) { // Write key to console Console.WriteLine("Key: " + row.KeyString); // Iterate the families which were returned foreach (var family in row.FieldsByFamily) { // Results are organized by family var familyName = family.Key; // Iterate the fields in this family foreach (var field in family.Value) { var fieldName = field.Key; // Iterate the versions of the field foreach (var cell in field.Value) { // Write to console Console.WriteLine("{0}:{1} = {2}", familyName, cell.ColumnName, cell.StringValue); } } } } } }
public static async Task Run() { // Disable Grpc logging GrpcEnvironment.DisableLogging(); try { // Create config var config = Utilities.GetConfig(); // Create credentials var credentials = await BigtableCredentials.UseApplicationDefaultCredentialsAsync(); // Admin client using (var adminClient = new BigAdminClient(credentials, config)) { // Get tables var tables = (await adminClient.ListTablesAsync()).ToArray(); // Ensure pricing table exists if (tables.All(t => t.Name != Constants.PricingTable)) { // Inform user CommandLine.InformUser("Setup", "Missing example table. Please run the Examples.Bootstrap project."); // Hard stop return; } // Show user CommandLine.DisplayTables(tables); } // Wait for keypress CommandLine.WaitForUserAndThen("scan for rows"); // Data client using (var dataClient = new BigDataClient(credentials, config)) { // Target var pricingTable = new BigTable(Constants.PricingTable); // Scan pricing table var pricing = await dataClient.GetRowsAsync(pricingTable, Constants.ScanKeyStart, Constants.ScanKeyEnd, Constants.ScanLimit); // Show the user CommandLine.DisplayRows(pricing); // Wait for keypress CommandLine.WaitForUserAndThen("observe rows"); // Test observables var waitSource = new CancellationTokenSource(); // ReSharper disable once MethodSupportsCancellation var waitForObservation = Task.Run(() => Task.Delay(-1, waitSource.Token)); // Create a subscriber var subscriber = new TestSubscriber(() => waitSource.Cancel()); // ReSharper disable once MethodSupportsCancellation var observable = dataClient.ObserveRows(pricingTable, Constants.ScanKeyStart, Constants.ScanKeyEnd, Constants.ScanLimit); using (observable.Subscribe(subscriber)) { //await Task.Delay(1000); Task.WaitAny(waitForObservation); } // Wait for keypress CommandLine.WaitForUserAndThen("seek for row"); // Seek for data var row = await dataClient.GetRowAsync(pricingTable, Constants.SeekKey); // Show the user CommandLine.DisplayRows(new[] { row }); } } catch (Exception exception) { CommandLine.InformUser("Oops", "Example didn't work out as planned"); CommandLine.RenderException(exception); } finally { // All done CommandLine.WaitForUserAndThen("exit"); } }