public void Handle(IConsoleAdapter console, IErrorAdapter error)
        {
            console.WrapLine("Default table format");
            console.WriteLine();
            var data1 = Enumerable.Range(0, 5)
                                  .Select(i => new {Text = string.Format("item {0}", i), Index = i});
            console.FormatTable(data1);
            console.WriteLine();

            var report = Enumerable.Range(0, 5)
                                 .Select(i => new {Text = string.Format("item {0}", i), Index = i})
                                 .AsReport(x => x.AddColumn(c => c.Index, d => d.Heading("Just The Index"))
                                                 .AddColumn(c => string.Format("{0} miles", c.Index*2),
                                                            d => d.Heading("Index in miles")));
            console.WriteLine();
            console.WrapLine("Report with custom headings");
            console.WriteLine();
            console.FormatTable(report);
            console.WriteLine();

            var report2 = Enumerable.Range(0, 5)
                                 .Select(i => new {Text = string.Format("item {0}", i), Index = i})
                                 .AsReport(x => x.AddColumn(c => c.Index, d => d.Heading("Fixed Width Index (12 wide)")
                                                                                .Width(12))
                                                 .AddColumn(c => string.Format("{0} miles", c.Index*2),
                                                            d => d.Heading("Index in miles")));
            console.WriteLine();
            console.WrapLine("Report with fixed width column");
            console.WriteLine();
            console.FormatTable(report2);
        }
Exemple #2
0
        private void ReportDatabases(IConsoleAdapter console, Server srv)
        {
            console.FormatTable(new[] { new { Server = Server, Version = srv.Information.Version } });
            console.WriteLine();
            console.WrapLine("Databases");
            console.WriteLine();
            var databases = srv.Databases.Enumerate()
                            .Where(d => !d.IsSystemObject)
                            .Select(d => new { d.Name, d.CreateDate, Size = $"{d.Size} MB" })
                            .OrderBy(d => d.CreateDate);

            console.FormatTable(databases);
            console.WriteLine();
        }
        public void Handle(IConsoleAdapter console, IErrorAdapter error)
        {
            var context = BlobContextFactory.Get(this, true);

            var container = context.GetContainer("test");

            console.WrapLine("Getting a shared access signature:");
            console.WrapLine(container.GetSharedAccessSignature(30).Cyan());

            console.WrapLine("Uploading to test.txt");

            container.UploadText("test.txt", "my test text");

            console.WriteLine();
            console.WrapLine("Listing blobs");

            console.FormatTable(container.ListBlobs("").Select(s => new { BlobName = s }));

            console.WrapLine("Deleting blob");
            container.DeleteBlob("test.txt");
            console.WriteLine();
            console.WrapLine("Listing blobs again");
            console.FormatTable(container.ListBlobs("").Select(s => new { BlobName = s }));

            console.WriteLine();
            console.WrapLine("Uploading stream data");

            using (var data = File.OpenRead(Assembly.GetExecutingAssembly().Location))
            {
                container.Upload("exedata", data);
            }

            console.WriteLine();
            console.WrapLine("Downloading stream data");

            using (var stream = container.OpenStream("exedata"))
            {
                var bytesRead      = 0;
                var totalBytesRead = 0;
                var buffer         = new Byte[100];
                while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    totalBytesRead += bytesRead;
                }

                console.WrapLine($"{totalBytesRead} read.");
            }
        }
 private static void AddCommandListText(IConsoleAdapter console, CommandLineInterpreterConfiguration config, IOptionNameHelpAdorner adorner, CommandExecutionMode executionMode)
 {
     var commands = config.Commands.Where(c => c.Name != null && CommandModeFilter(executionMode, c)).OrderBy(c => c.Name).ToList();
     if (commands.Any())
     {
         console.WriteLine("Available commands");
         console.WriteLine();
         var commandItems = commands.Select(c => new { Command = c.Name, Text = FormatShortCommandDescription(c) });
         console.FormatTable(commandItems, FormattingOptions, ColumnSeperator);
     }
 }
        public void Handle(IConsoleAdapter console, IErrorAdapter error, IMapper mapper)
        {
            var ops = new UserOperations("https://senlabltd.eu.auth0.com/api/v2/", ClientId, Secret, mapper);

            try
            {
                console.FormatTable(ops.GetAllUsers().Select(c => new { c.Email, c.UserId }));
            }
            catch (AggregateException e)
            {
                error.WrapLine($"{e.InnerException.Message.Red()} (Aggregate)");
            }
            catch (Exception e)
            {
                error.WrapLine(e.Message.Red());
            }
        }
        public void Handle(IConsoleAdapter console, IErrorAdapter error)
        {
            var context = TableContextFactory.Get(this, Constants.ActivityTable, true);
            var query   = new TableQuery <DynamicTableEntity>();
            var items   = context.CreateDynamicQuery(query,
                                                     e => error.WrapLine($"Unable to complete query due to exception:\r\n{e.Message}"))
                          .Select(a =>
                                  new
            {
                Who            = PropertyOrEmptyString(a, "Who"),
                What           = PropertyOrEmptyString(a, "What"),
                WhenDidItStart = PropertyOrEmptyString(a, "WhenDidItStart"),
                HowLong        = PropertyOrEmptyString(a, "HowLong")
            })
                          .ToList();

            console.FormatTable(items);
        }
 public void Handle(IConsoleAdapter console, IErrorAdapter error)
 {
     console.FormatTable(Directory.EnumerateDirectories(Path).Select(d => new { Directory = d }));
 }
        public async void Handle(IConsoleAdapter console, IErrorAdapter error)
        {
            try
            {
                var table     = TableContextFactory.Get(this, Constants.TestTable, true);
                var variables = new[]
                {
                    "Alpha", "Beta", "Charlie", "Delta", "Echo"
                }.ToList();

                var partition = DateTime.Now.ToString("s");
                console.WrapLine($"Partition key = {partition}");

                var entities = Enumerable.Range(0, 20)
                               .Select(e =>
                {
                    var item = new TestEntity
                    {
                        Alpha        = variables[0],
                        Beta         = variables[1],
                        Charlie      = variables[2],
                        Delta        = variables[3],
                        Echo         = variables[4],
                        PartitionKey = partition,
                        RowKey       = variables[1] + " " + Guid.NewGuid().ToString()
                    };
                    var top = variables[0];
                    variables.RemoveAt(0);
                    variables.Add(top);
                    return(item);
                }).ToList();

                console.WrapLine("Generating entities using batch add...");
                foreach (var entity in entities)
                {
                    table.BatchAdd(entity);
                }

                table.BatchExecuteAsync().Wait();

                console.WrapLine("Performing batch updates");

                table.BatchDelete(entities[5]);
                entities[7].Alpha = "Updated (Batch)";
                table.BatchUpdate(entities[7]);
                entities[8].Beta = "Updated (Batch)";
                table.BatchUpdate(entities[8]);

                table.BatchExecuteAsync().Wait();

                console.WrapLine("Performing individual delete");

                table.DeleteAsync(entities[9]).Wait();

                console.WrapLine("Retrieving deleted item");

                var deletedItem = table.GetAsync <TestEntity>(entities[9].PartitionKey, entities[9].RowKey).Result;
                if (deletedItem == null)
                {
                    console.WrapLine("Deleted item not found");
                }
                else
                {
                    console.WrapLine("Deleted item found".Red());
                }

                console.WrapLine("Performing delete again");
                try
                {
                    table.DeleteAsync(entities[9]).Wait();
                }
                catch
                {
                    console.WrapLine("Caught exception");
                }

                console.WrapLine("Performing individual update");
                entities[10].Beta = "Updated (Individual)";
                table.UpdateAsync(entities[10]).Wait();

                console.WrapLine("Retrieving test partition:");

                var query = new TableQuery <TestEntity>();
                query.FilterString = TableQuery.GenerateFilterCondition("PartitionKey", "eq", partition);
                var items = table.Query(query,
                                        e => error.WrapLine($"Unable to complete query due to exception:\r\n{e.Message}"))
                            .Select(i => new { i.Alpha, i.Beta, i.Charlie, i.Delta, i.Echo })
                            .OrderBy(i => i.Alpha)
                            .ThenBy(i => i.Beta)
                            .ThenBy(i => i.Charlie)
                            .ThenBy(i => i.Delta)
                            .ThenBy(i => i.Echo);
                console.FormatTable(items);
                console.WriteLine();
                console.WrapLine("Running test query:");

                var whereForQuery = $"PartitionKey eq '{partition}' and (Alpha eq 'Delta' or Alpha eq 'Alpha' and Delta eq 'Beta')";

                var queryWithWhere = new TableQuery <TestEntity>().Where(whereForQuery);

                var resultWithWhere = table.Query(queryWithWhere,
                                                  e => error.WrapLine($"Unable to complete query due to exception:\r\n{e.Message}"))
                                      .Select(i => new { i.Alpha, i.Beta, i.Charlie, i.Delta, i.Echo })
                                      .OrderBy(i => i.Alpha)
                                      .ThenBy(i => i.Beta)
                                      .ThenBy(i => i.Charlie)
                                      .ThenBy(i => i.Delta)
                                      .ThenBy(i => i.Echo);

                console.WrapLine(whereForQuery);
                console.FormatTable(resultWithWhere);

                console.WriteLine();
                console.WrapLine("Dynamic query (same where)");

                var dynamicQ = new TableQuery <DynamicTableEntity> {
                    SelectColumns = new List <string> {
                        "Alpha", "Charlie"
                    }
                };
                var dynamicItems = table.CreateDynamicQuery(dynamicQ.Where(whereForQuery),
                                                            e => error.WrapLine($"Unable to complete query due to exception:\r\n{e.Message}"))
                                   .Select(a =>
                                           new
                {
                    Alpha   = a.Properties["Alpha"].StringValue,
                    Charlie = a.Properties["Charlie"].StringValue,
                })
                                   .OrderBy(i => i.Alpha)
                                   .ThenBy(i => i.Charlie)
                                   .ToList();
                console.FormatTable(dynamicItems);

                console.WrapLine("Done");
            }
            catch (Exception e)
            {
                error.WrapLine(e.ToString().Red());
                throw;
            }
        }
 private void FixedColumnsThatRequiredSixtyChars(IConsoleAdapter adapter)
 {
     var report = _data.AsReport(p => p.AddColumn(a => a,
                                           col => col.Heading("Character").Width(10))
                                       .AddColumn(a => a.Length,
                                           col => col.Heading("Name Length").Width(10))
                                       .AddColumn(a => new string(a.Reverse().ToArray()),
                                           col => col.Heading("Backwards").Width(10))
                                       .AddColumn(a => string.Join(" ", Enumerable.Repeat(a, a.Length)),
                                           col => col.Heading("Repeated").Width(27)));
     adapter.FormatTable(report);
 }