Beispiel #1
0
        public Loader(BigtableCredentials credentials, BigtableConfig config)
        {
            GrpcEnvironment.SetThreadPoolSize(BatchAndPoolSize);

            _adminClient = new BigAdminClient(credentials, config);
            _dataClient  = new BigDataClient(credentials, config);
        }
Beispiel #2
0
        public void Setup()
        {
            var test   = "test";
            var config = new BigtableConfig(test, test, test);
            var creds  = new BigtableCredentials();

            _admin = new BigAdminClient(creds, config);
            _data  = new BigDataClient(creds, config);
        }
Beispiel #3
0
        public HttpResponseMessage BigData(string typeDoc, string responseSize)
        {
            //Vtora verzija, vrakjame byte[] fileBytes
            var client = new BigDataClient();

            try
            {
                var timeCameInApi = DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss.fff tt");
                var output        = client.GetLargeDoc(typeDoc, responseSize);

                _logger.Info("Came on API in " + timeCameInApi + " , recesived response on API in " + DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss.fff tt"), "APIHaveResult");
                if (output.HasDocument)
                {
                    var context     = HttpContext.Current;
                    var contextBase = new HttpContextWrapper(context);
                    var routeData   = new RouteData();
                    routeData.Values.Add("controller", "Template");

                    var result = new HttpResponseMessage(HttpStatusCode.OK);
                    var date   = DateTime.Now.ToString("ddMMyyyy HH:mm:ss");
                    result.Content = new ByteArrayContent(output.Document);

                    if (typeDoc == "doc")
                    {
                        result.Content.Headers.Add("Content-Encoding", "UTF-8");
                        result.Content.Headers.Add("Charset", "UTF-8");
                        result.Content.Headers.ContentType        = new MediaTypeHeaderValue("application/msword");
                        result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                        {
                            FileName = "BigDocumentDoc" + date
                        };
                    }
                    else if (typeDoc == "pdf")
                    {
                        result.Content.Headers.ContentType        = new MediaTypeHeaderValue("application/pdf");
                        result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                        {
                            FileName = "BigDocumentPdf" + date
                        };
                    }

                    _logger.Info("Rezultat se prakja na UI vo " + DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss.fff tt") + " casot!", "ResultToUI");
                    return(result);
                }
                throw new Exception(output.Message);
            }
            catch (FaultException ex)
            {
                _logger.Info("dosol vo fault exception.");
                _logger.Error("Error koj se vrakja od fault exception e: ", ex);
                throw;
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
        }
Beispiel #4
0
        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);
                            }
                        }
                    }
                }
            }
        }
Beispiel #5
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");
            }
        }