Example #1
0
        public static IQueueLifeCycleBuilder Command <T>(T command) where T : AbstractCommand
        {
            var settings = InEngineSettings.Make();

            return(new QueueLifeCycleBuilder(command)
            {
                QueueSettings = settings.Queue,
                MailSettings = settings.Mail,
            });
        }
Example #2
0
        public static IQueueLifeCycleBuilder Command(Expression <Action> expressionAction)
        {
            var settings = InEngineSettings.Make();

            return(new QueueLifeCycleBuilder(new Lambda(expressionAction.ToExpressionNode()))
            {
                QueueSettings = settings.Queue,
                MailSettings = settings.Mail,
            });
        }
Example #3
0
        public static IQueueLifeCycleBuilder Commands(IList <AbstractCommand> commands)
        {
            var settings = InEngineSettings.Make();

            return(new QueueLifeCycleBuilder(new Chain()
            {
                Commands = commands
            })
            {
                QueueSettings = settings.Queue,
                MailSettings = settings.Mail,
            });
        }
Example #4
0
        public static void Main(string[] args)
        {
            Console.WriteLine("------------------------------------------------------------");
            Console.WriteLine("Queue Integration Tests");
            Console.WriteLine("------------------------------------------------------------");
            new QueuingTest().Run();

            Console.WriteLine("------------------------------------------------------------");
            Console.WriteLine("Start Server...");
            Console.WriteLine("------------------------------------------------------------");
            var settings   = InEngineSettings.Make();
            var serverHost = new ServerHost()
            {
                MailSettings  = settings.Mail,
                QueueSettings = settings.Queue,
            };

            serverHost.Start();
            Console.ReadLine();
            serverHost.Dispose();
        }
Example #5
0
        public override void Run()
        {
            if (ExecWhitelist == null)
            {
                ExecWhitelist = InEngineSettings.Make().ExecWhitelist;
            }
            if (!ExecWhitelist.ContainsKey(Executable))
            {
                throw new CommandFailedException("Executable is not whitelisted.");
            }
            var fileName = ExecWhitelist[Executable];

            if (!File.Exists(fileName))
            {
                throw new CommandFailedException($"Cannot run {fileName}. It either does not exist or is inaccessible. Exiting...");
            }
            var process = new Process()
            {
                StartInfo = new ProcessStartInfo(fileName, Arguments)
                {
                    UseShellExecute        = false,
                    ErrorDialog            = false,
                    RedirectStandardError  = false,
                    RedirectStandardInput  = false,
                    RedirectStandardOutput = false,
                }
            };
            var commandWithArguments = $"{fileName} {Arguments}";

            process.Start();
            if (process.WaitForExit(Timeout * 1000))
            {
                return;
            }
            Error($"The command ({commandWithArguments}) has timed out and is about to be killed...");
            process.Kill();
            Error($"The command ({commandWithArguments}) has been killed.");
            throw new CommandFailedException($"The command ({commandWithArguments}) timed out after {Timeout} second(s).");
        }
        public void InterpretPluginArguments(string[] pluginArgs, AbstractPlugin abstractPlugin)
        {
            var isSuccessful = Parser.Default.ParseArguments(pluginArgs, abstractPlugin, (verb, subOptions) => {
                try
                {
                    var settings = InEngineSettings.Make();
                    if (subOptions == null && (pluginArgs.Contains("-h") || pluginArgs.Contains("--help")))
                    {
                        ExitWithSuccess();
                    }
                    else if (subOptions == null)
                    {
                        ExitWithFailure("");
                    }
                    var command = subOptions as AbstractCommand;
                    if (command is AbstractCommand)
                    {
                        (command as AbstractCommand).Name = verb.Normalize();
                    }
                    if (command is IHasQueueSettings)
                    {
                        (command as IHasQueueSettings).QueueSettings = settings.Queue;
                    }
                    command.MailSettings = settings.Mail;
                    command.Run();
                    ExitWithSuccess();
                }
                catch (Exception exception)
                {
                    ExitWithFailure(exception);
                }
            });

            if (!isSuccessful)
            {
                ExitWithFailure(new CommandFailedException("Could not parse plugin arguments. Use -h, --help for usage."));
            }
        }
Example #7
0
        /// <summary>
        /// Start the server as a service or as a CLI program in the foreground.
        /// </summary>
        public static void RunServer()
        {
            var settings = InEngineSettings.Make();

            ServerHost = new ServerHost()
            {
                MailSettings  = settings.Mail,
                QueueSettings = settings.Queue,
            };

            if (!Environment.UserInteractive && Type.GetType("Mono.Runtime") == null)
            {
                using (var service = new Service())
                    ServiceBase.Run(service);
            }
            else
            {
                ServerHost.Start();
                Console.WriteLine("Press any key to exit...");
                Console.ReadLine();
                ServerHost.Dispose();
            }
        }
Example #8
0
        public override void Run()
        {
            var settings = InEngineSettings.Make();
            var queue    = QueueAdapter.Make(true, settings.Queue, settings.Mail);

            queue.ClearPendingQueue();
            queue.Publish(new Echo()
            {
                VerbatimText = "Core echo command."
            });
            new Length {
                QueueSettings = settings.Queue,
                MailSettings  = settings.Mail,
            }.Run();
            new Peek {
                PendingQueue  = true,
                QueueSettings = settings.Queue,
                MailSettings  = settings.Mail,
            }.Run();


            Enqueue.Command(() => Console.WriteLine("Core lambda command."))
            .Dispatch();
            Enqueue.Command(() => new Echo {
                VerbatimText = "Core echo command in a lambda command."
            }.Run())
            .Dispatch();
            Enqueue.Command(new AlwaysFail())
            .WriteOutputTo("queueWriteTest-TheFileShouldNotExist.txt")
            .WithRetries(4)
            .Dispatch();

            Enqueue.Commands(new[] {
                new Echo {
                    VerbatimText = "Chain Link 1",
                    MailSettings = settings.Mail,
                },
                new Echo {
                    VerbatimText = "Chain Link 2",
                    MailSettings = settings.Mail,
                },
            }).Dispatch();

            Enqueue.Commands(new List <AbstractCommand> {
                new Echo {
                    VerbatimText = "Chain Link A",
                    MailSettings = settings.Mail,
                },
                new AlwaysFail(),
                new Echo {
                    VerbatimText = "Chain Link C",
                    MailSettings = settings.Mail,
                },
            }).Dispatch();

            Enqueue.Commands(new List <AbstractCommand> {
                new Echo {
                    VerbatimText = "Chain Link A",
                    MailSettings = settings.Mail,
                },
                new AlwaysFail(),
                new Echo {
                    VerbatimText = "Chain Link C",
                    MailSettings = settings.Mail,
                },
            }).Dispatch();

            Enqueue.Commands(Enumerable.Range(0, 10).Select(x => new AlwaysSucceed() as AbstractCommand).ToList())
            .Dispatch();

            var queueWriteIntegrationTest  = "queueWriteIntegrationTest.txt";
            var queueAppendIntegrationTest = "queueAppendIntegrationTest.txt";

            File.Delete(queueWriteIntegrationTest);
            File.Delete(queueAppendIntegrationTest);
            Enqueue.Command(new Echo {
                VerbatimText = "Core echo command.",
                MailSettings = settings.Mail,
            })
            .PingAfter("http://www.google.com")
            .PingBefore("http://www.google.com")
            .EmailOutputTo("*****@*****.**")
            .WriteOutputTo(queueWriteIntegrationTest)
            .AppendOutputTo(queueAppendIntegrationTest)
            .Dispatch();
        }