From 2be4a5d5d5c14c19aa7d3ee7b21053419e241dbb Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Thu, 21 Feb 2019 22:59:16 -0600 Subject: [PATCH] Pass example name from arguments. --- Examples/IExample.cs | 11 ++++++++ "Examples/Plot2D/ExampleAr\321\201.cs" | 4 +-- Examples/Plot2D/ExampleHistogram.cs | 4 +-- Examples/Plot2D/ExamplePoint2D.cs | 4 +-- Examples/Plot2D/ExampleSin.cs | 4 +-- Examples/Plot2D/ExampleTimeAxis.cs | 4 +-- Examples/Plot2D/ExampleVisibility.cs | 4 +-- Examples/Program.cs | 37 +++++++++++++++++++------ Examples/Properties/launchSettings.json | 3 +- 9 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 Examples/IExample.cs diff --git a/Examples/IExample.cs b/Examples/IExample.cs new file mode 100644 index 0000000..69034a3 --- /dev/null +++ b/Examples/IExample.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Examples +{ + public interface IExample + { + void Run(string pythonExePath, string dasPlotPyPath); + } +} diff --git "a/Examples/Plot2D/ExampleAr\321\201.cs" "b/Examples/Plot2D/ExampleAr\321\201.cs" index 29cc44d..45bca97 100644 --- "a/Examples/Plot2D/ExampleAr\321\201.cs" +++ "b/Examples/Plot2D/ExampleAr\321\201.cs" @@ -8,12 +8,12 @@ namespace Examples.Plot2D { - class ExampleArс + class ExampleArс : IExample { /// /// Chart of sin /// - public static void Run(string pythonExePath, string dasPlotPyPath) + public void Run(string pythonExePath, string dasPlotPyPath) { #region create test data diff --git a/Examples/Plot2D/ExampleHistogram.cs b/Examples/Plot2D/ExampleHistogram.cs index b6a33c2..ca54faf 100644 --- a/Examples/Plot2D/ExampleHistogram.cs +++ b/Examples/Plot2D/ExampleHistogram.cs @@ -8,12 +8,12 @@ namespace Examples.Plot2D { - class ExampleHistogram + class ExampleHistogram : IExample { /// /// Chart of sin /// - public static void Run(string pythonExePath, string dasPlotPyPath) + public void Run(string pythonExePath, string dasPlotPyPath) { #region create test data diff --git a/Examples/Plot2D/ExamplePoint2D.cs b/Examples/Plot2D/ExamplePoint2D.cs index 761b072..67d16b1 100644 --- a/Examples/Plot2D/ExamplePoint2D.cs +++ b/Examples/Plot2D/ExamplePoint2D.cs @@ -8,12 +8,12 @@ namespace Examples.Plot2D { - class ExamplePoint2D + class ExamplePoint2D : IExample { /// /// Chart of sin /// - public static void Run(string pythonExePath, string dasPlotPyPath) + public void Run(string pythonExePath, string dasPlotPyPath) { // init engine with right paths var matplotlibCs = new MatplotlibCS.MatplotlibCS(pythonExePath, dasPlotPyPath); diff --git a/Examples/Plot2D/ExampleSin.cs b/Examples/Plot2D/ExampleSin.cs index f9942d2..ab620f8 100644 --- a/Examples/Plot2D/ExampleSin.cs +++ b/Examples/Plot2D/ExampleSin.cs @@ -8,12 +8,12 @@ namespace Examples.Plot2D { - class ExampleSin + class ExampleSin : IExample { /// /// Chart of sin /// - public static void Run(string pythonExePath, string dasPlotPyPath) + public void Run(string pythonExePath, string dasPlotPyPath) { #region create test data diff --git a/Examples/Plot2D/ExampleTimeAxis.cs b/Examples/Plot2D/ExampleTimeAxis.cs index 7be5efe..4ea429b 100644 --- a/Examples/Plot2D/ExampleTimeAxis.cs +++ b/Examples/Plot2D/ExampleTimeAxis.cs @@ -8,12 +8,12 @@ namespace Examples.Plot2D { - class ExampleTimeAxis + class ExampleTimeAxis : IExample { /// /// Chart of sin /// - public static void Run(string pythonExePath, string dasPlotPyPath) + public void Run(string pythonExePath, string dasPlotPyPath) { #region create test data diff --git a/Examples/Plot2D/ExampleVisibility.cs b/Examples/Plot2D/ExampleVisibility.cs index 8bf9f84..b9baf54 100644 --- a/Examples/Plot2D/ExampleVisibility.cs +++ b/Examples/Plot2D/ExampleVisibility.cs @@ -8,12 +8,12 @@ namespace Examples.Plot2D { - class ExampleVisibility + class ExampleVisibility : IExample { /// /// Chart of sin /// - public static void Run(string pythonExePath, string dasPlotPyPath) + public void Run(string pythonExePath, string dasPlotPyPath) { // init engine with right paths var matplotlibCs = new MatplotlibCS.MatplotlibCS(pythonExePath, dasPlotPyPath); diff --git a/Examples/Program.cs b/Examples/Program.cs index 44e95df..4b61e96 100644 --- a/Examples/Program.cs +++ b/Examples/Program.cs @@ -1,5 +1,7 @@ using Examples.Plot2D; using System; +using System.Linq; +using System.Reflection; namespace Examples { @@ -20,22 +22,39 @@ class Program static void Main(string[] args) { - if (args.Length != 2) + if (args.Length != 3) { Console.WriteLine("You must specify path to python.exe and to matplotlib_cs.py in command line arguments"); Console.ReadKey(); return; } - _pythonExePath = args[0]; - _matplotlibPyPath = args[1]; + _pythonExePath = args[1]; + _matplotlibPyPath = args[2]; + + var assembly = Assembly.GetEntryAssembly(); + foreach (Type type in assembly.GetTypes().Where(x => x.GetInterfaces().Contains(typeof(IExample)))) + { + if (args.Length > 0 && !args.Contains(type.Name)) + continue; + + Console.WriteLine($"{DateTime.UtcNow} Starting {type.Name}"); + + var example = (IExample)Activator.CreateInstance(type); + + try + { + example.Run(_pythonExePath, _matplotlibPyPath); + } + catch (Exception ex) + { + Console.WriteLine(ex); + } + + Console.WriteLine($"{DateTime.UtcNow} Completed {type.Name}"); + } - //ExampleSin.Run(_pythonExePath, _matplotlibPyPath); - ExampleArс.Run(_pythonExePath, _matplotlibPyPath); - //ExampleVisibility.Run(_pythonExePath, _matplotlibPyPath); - //ExampleHistogram.Run(_pythonExePath, _matplotlibPyPath); - //ExampleTimeAxis.Run(_pythonExePath, _matplotlibPyPath); - //ExamplePoint2D.Run(_pythonExePath, _matplotlibPyPath); + Console.ReadLine(); } } } diff --git a/Examples/Properties/launchSettings.json b/Examples/Properties/launchSettings.json index 1299a97..6d63fb3 100644 --- a/Examples/Properties/launchSettings.json +++ b/Examples/Properties/launchSettings.json @@ -1,7 +1,8 @@ { "profiles": { "Examples": { - "commandName": "Project" + "commandName": "Project", + "commandLineArgs": "ExamplePoint2D python.exe tmp" } } } \ No newline at end of file