Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            // Setup a service collection.
            var services = new Microsoft.Extensions.DependencyInjection.ServiceCollection()

                           // Add essential workflow services.
                           .AddElsaCore()

                           // Add Console activities (ReadLine and WriteLine).
                           .AddConsoleActivities()

                           .BuildServiceProvider();

            // Get a workflow builder.
            var workflowBuilder = services.GetRequiredService <IWorkflowBuilder>();

            // Define a workflow and add a single activity.
            var workflowDefinition = workflowBuilder
                                     .StartWith <WriteLine>(x => x.TextExpression = new LiteralExpression("Hello world!"))
                                     .Build();

            // Get a workflow invoker,
            var invoker = services.GetService <IWorkflowInvoker>();

            // Start the workflow.
            await invoker.StartAsync(workflowDefinition);

            // Prevent the console from shutting down until user hits a key.
            System.Console.ReadLine();
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            Parser.Default.ParseArguments <Options>(args)
            .WithParsed <Options>(o =>
            {
                if (o.Verbose)
                {
                    Log.Logger = new LoggerConfiguration()
                                 .MinimumLevel.Verbose()
                                 .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
                                 .WriteTo.File("log.log", rollingInterval: RollingInterval.Day, outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
                                 .CreateLogger();
                    Log.Information("Application started.");
                    Log.Verbose("Verbose output enabled.");
                }
                else
                {
                    Log.Logger = new LoggerConfiguration()
                                 .MinimumLevel.Information()
                                 .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
                                 .WriteTo.File("log.log", rollingInterval: RollingInterval.Day, outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
                                 .CreateLogger();
                    Log.Information("Application started.");
                    Log.Information("Error output enabled.");
                }
                Log.Information($"Application Start: {DateTime.Now}");

                if (!Directory.Exists(o.Source))
                {
                    var m = $"Source directory \"{o.Source}\" does not exist!";
                    Log.Error(m);
                    throw new Exception(m);
                }

                if (!Directory.Exists(o.Destination))
                {
                    var m = $"Destination directory \"{o.Destination}\" does not exist!";
                    Log.Error(m);
                    throw new Exception(m);
                }


                //setup our DI
                var serviceProvider = new Microsoft.Extensions.DependencyInjection.ServiceCollection()
                                      .AddLogging()
                                      .AddSingleton <IWatermarkService, WatermarkService>()
                                      .BuildServiceProvider();


                //do the actual work here
                var bar = serviceProvider.GetService <IWatermarkService>();
                bar.DoThing(5);

                Log.Information($"Application Finished: {DateTime.Now}");
            });
        }