예제 #1
0
        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");
            }
        }
예제 #2
0
 public static void DisableLogger()
 {
     GrpcEnvironment.DisableLogging();
 }
예제 #3
0
        public static async Task Run(BigtableConfig config)
        {
            GrpcEnvironment.DisableLogging();
            try
            {
                var credentials = await BigtableCredentials.UseApplicationDefaultCredentialsAsync();

                // Admin client
                using (var loader = new Loader(credentials, config))
                {
                    // Examine cluster
                    await loader.Initialize();

                    // Ensure pricing table exists
                    if (loader.NoExampleTables)
                    {
                        var state    = "Missing example tables.";
                        var question = "Would you like to create and populate the example tables?";
                        if (!AskUserPermission(state, question))
                        {
                            return;
                        }
                    }
                    else if (loader.SomeExampleTables)
                    {
                        var state    = "Missing some of the example tables.";
                        var question = "Would you like to create and populate the missing tables?";
                        if (!AskUserPermission(state, question))
                        {
                            return;
                        }
                    }
                    else
                    {
                        var state    = "Example tables are present.";
                        var question = "Would you like to DROP, recreate, and populate the example tables?";
                        if (!AskUserPermission(state, question))
                        {
                            return;
                        }
                    }
                    await loader.LoadTables();
                }
            }
            catch (Exception exception)
            {
                // Notify user
                CommandLine.InformUser("Oops", "Bootstrapping did not work out as planned.");
                CommandLine.RenderException(exception);

                // Giveup
                return;
            }
            finally
            {
                // Give user a chance to read screen
                if (Debugger.IsAttached)
                {
                    CommandLine.WaitForUserAndThen("exit");
                }
            }
        }
예제 #4
0
        public static async Task Run()
        {
            // Disable Grpc logging
            GrpcEnvironment.DisableLogging();

            try
            {
                // Create config
                var config = Utilities.GetConfig();

                // Create credentials
                var credentials = await BigtableCredentials.UseApplicationDefaultCredentialsAsync();

                // Mapper client
                using (var bigtable = new Bigtable(credentials, config))
                {
                    var tableExists = await bigtable.TableExists <Pricing>();

                    // Ensure pricing table exists
                    if (!tableExists)
                    {
                        // Inform user
                        CommandLine.InformUser("Setup", "Missing example table.  Please run the Examples.Bootstrap project.");

                        // Hard stop
                        return;
                    }

                    // -----------------------------------------------------------------------------------------------------------------///

                    // Inform User
                    CommandLine.InformUser("Start", "Getting first pricing poco record");

                    // Seek one record
                    var firstPricing = await bigtable.GetFirstRowAsync <Pricing>();

                    // Show user
                    DisplayPricing(firstPricing);

                    // -----------------------------------------------------------------------------------------------------------------///

                    // Inform User
                    CommandLine.WaitForUserAndThen("get keyed pricing poco");

                    // Seek one record
                    var pricing = await bigtable.GetAsync(new Pricing { Id = Constants.SeekId, Date = Constants.SeekDate });

                    // Show user
                    DisplayPricing(pricing);

                    // -----------------------------------------------------------------------------------------------------------------///

                    // Inform User
                    CommandLine.WaitForUserAndThen("get alternate-schema pricing poco");

                    // Seek one record using alternate schema
                    var simplePricing = await bigtable.GetAsync(new SimplePricing { Id = Constants.SeekId, Date = Constants.SeekDate });

                    // Show user
                    DisplayPricing(FromSimplePricing(simplePricing));

                    // -----------------------------------------------------------------------------------------------------------------///

                    // Inform User
                    CommandLine.WaitForUserAndThen("scan partially-keyed pricing poco");

                    // Seek one record
                    var pricings = await bigtable.ScanAsync(new Pricing { Id = Constants.SeekId }, new Pricing { Id = Constants.SeekId + 1 });

                    // Show user
                    DisplayPricing(pricings.ToArray());


                    // -----------------------------------------------------------------------------------------------------------------///

                    // Inform User
                    CommandLine.WaitForUserAndThen("read write read");

                    // Seek one record
                    var rewrite = await bigtable.GetAsync(new Pricing { Id = Constants.SeekId, Date = Constants.SeekDate + 1 });

                    DisplayPricing(rewrite);

                    var tempHigh = rewrite.High;
                    var tempLow  = rewrite.Low;

                    rewrite.High = 142;
                    rewrite.Low  = null;

                    await bigtable.UpdateAsync(rewrite);

                    var rewriteRead = await bigtable.GetAsync(new Pricing { Id = Constants.SeekId, Date = Constants.SeekDate + 1 });

                    DisplayPricing(rewrite, rewriteRead);
                    rewrite.High = tempHigh;
                    rewrite.Low  = tempLow;
                    await bigtable.UpdateAsync(rewrite);
                }
            }
            catch (Exception exception)
            {
                CommandLine.InformUser("Oops", "Example didn't work out as planned");
                CommandLine.RenderException(exception);
            }
            finally
            {
                // All done
                CommandLine.WaitForUserAndThen("exit");
            }
        }
예제 #5
0
        public static async Task Run()
        {
            // Disable Grpc logging
            GrpcEnvironment.DisableLogging();

            // Locals
            var client = default(SimpleClient);

            try
            {
                // Get examples config
                var config = Utilities.GetConfig();

                // Create a Native .Net BigTable Client
                client = new SimpleClient(config);

                // Connect to the Googles
                await client.Connect();

                // Get a list of table names
                var tableNames = client.GetTableNames().Result;

                // Ensure pricing table exists
                if (!tableNames.Value.Contains(Constants.PricingTable))
                {
                    // Inform user
                    CommandLine.InformUser("Setup", "Missing example table.  Please run the Examples.Bootstrap project.");

                    // Hard stop
                    return;
                }

                // Show the user
                DisplayTables(tableNames);

                // Wait for keypress
                CommandLine.WaitForUserAndThen("scan for rows");

                // Scan for data
                var rows = client.Scan(Constants.PricingTable, Constants.ScanKeyStart, Constants.ScanKeyEnd).Result;

                // Show the user
                DisplayRows(rows);

                // Wait for keypress
                CommandLine.WaitForUserAndThen("seek for row");

                // Seek for data
                var row = client.Seek(Constants.PricingTable, Constants.SeekKey).Result;

                // Show the user
                DisplayRows(row);
            }
            catch (Exception exception)
            {
                CommandLine.InformUser("Oops", "Example didn't work out as planned");
                CommandLine.RenderException(exception);
            }
            finally
            {
                // Pretty
                Console.WriteLine();

                // Dispose
                if (client != default(SimpleClient))
                {
                    client.Dispose();
                }

                // All done
                CommandLine.WaitForUserAndThen("exit");
            }
        }