Esempio n. 1
0
        private void listViewExamples_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            try
            {
                if (listViewExamples.SelectedItems.Count == 0)
                {
                    return;
                }

                this.Enabled = false;
                this.Cursor  = Cursors.WaitCursor;

                IExample selectedExample = listViewExamples.SelectedItems[0].Tag as IExample;
                if (null == selectedExample.Panel)
                {
                    selectedExample.RunExample();
                }
                else
                {
                    panelExamples.Controls.Add(selectedExample.Panel);
                    selectedExample.Panel.Dock    = DockStyle.Fill;
                    selectedExample.Panel.Visible = true;
                }
            }
            catch (Exception exception)
            {
                FormError.Show(this, exception);
            }
            finally
            {
                this.Enabled = true;
                this.Cursor  = Cursors.Default;
            }
        }
Esempio n. 2
0
 private static void RunOne(IExample oneExample, string[] argumentsForExample)
 {
     try {
         oneExample.ExampleMessage += Example_OnExampleMessage;
         oneExample.RunExample(argumentsForExample);
         oneExample.ExampleMessage -= Example_OnExampleMessage;
     }
     catch (Exception e) {
         Console.WriteLine($"{oneExample.GetType().Name} threw exception {e.Message}");
     }
 }
Esempio n. 3
0
 private static void Execute(IExample example)
 {
     try
     {
         var response = example.RunExample();
         Console.WriteLine(response);
         Console.WriteLine($"JSON: {JsonConvert.SerializeObject(response, Formatting.Indented)}");
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Esempio n. 4
0
        static async Task Main(string[] args)
        {
            List <IExample> examples = new List <IExample>
            {
                new DownloadImageToFile(),
                new EnumerateSearchQuery(),
                new DownloadSvgImages(),
                new PauseAndCancelImageDownload(),
                new GetTagsForImage(),
            };

            // Set up logging
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.Console()
                         .CreateLogger();
            Sibusten.Philomena.Client.Logging.Logger.Factory = LoggerFactory.Create(configure =>
            {
                configure.SetMinimumLevel(LogLevel.Debug);
                configure.AddSerilog();
            });

            // Configure retry policies
            PhilomenaClientRetryLogic.UseDefaultHttpRetryLogic();

            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("Philomena Client examples");

                // Write the list of examples
                for (int i = 0; i < examples.Count; i++)
                {
                    Console.WriteLine($"  {i:#0} - {examples[i].Description}");
                }

                // Write the quit option
                Console.WriteLine($"  {examples.Count} - Quit");

                Console.WriteLine();
                Console.WriteLine("Enter the number of the example to run: ");
                string input = Console.ReadLine();

                // Parse the input and validate
                if (!int.TryParse(input, out int choice))
                {
                    Console.WriteLine($"Invalid input: '{input}'");
                    continue;
                }

                // Ensure the choice is in range
                if (choice < 0 || choice > examples.Count)
                {
                    Console.WriteLine($"Invalid choice: {choice}");
                    continue;
                }

                // Check for the quit choice
                if (choice == examples.Count)
                {
                    return;
                }

                // Run the example
                IExample exampleToRun = examples[choice];
                Console.WriteLine();
                Console.WriteLine("----");
                Console.WriteLine(exampleToRun.Description);
                Console.WriteLine("----");
                Console.WriteLine();
                await exampleToRun.RunExample();
            }
        }