コード例 #1
0
ファイル: StartOptionsTests.cs プロジェクト: loudej/coral
 public void SetConcurrencyShouldParseNameAndInteger()
 {
     var options = new StartOptions();
     options.SetConcurrency("alpha=5");
     options.SetConcurrency("beta=3,gamma=6");
     options.Concurrency.ShouldContainKeyAndValue("alpha", 5);
     options.Concurrency.ShouldContainKeyAndValue("beta", 3);
     options.Concurrency.ShouldContainKeyAndValue("gamma", 6);
     options.Concurrency.Count.ShouldBe(3);
 }
コード例 #2
0
ファイル: Main.cs プロジェクト: loudej/coral
        static int DoStart(string[] args)
        {
            // Parse options
            var options = new StartOptions();
            options.Parse(args);

            // Show help if needed
            if (options.ShowHelp)
            {
                Console.WriteLine(
            @"Usage: Coral start [options] [process [process [...]]]
            Execute multiple console applications

            Options:"
            );
                options.WriteOptionDescriptions(Console.Out);
                return 0;
            }

            // Determine process file
            var procfile = options.Procfile ?? "Coral.txt";

            // Split process file contents into "name:command" pairs
            var lines = File.ReadAllText(procfile)
                .Split(new[] { "\n" }, StringSplitOptions.None)
                .Select(line => line.Trim('\r', ' ', '\t'))
                .Select(line => line.Split(new[] { ":" }, 2, StringSplitOptions.None));

            // Switch to provided directory, or use procfile location as default
            var directory = options.Directory ?? Path.GetDirectoryName(Path.Combine(Directory.GetCurrentDirectory(), procfile));
            Directory.SetCurrentDirectory(directory);

            // Create components and add process definitions
            var engine = Starter.CreateEngine();
            engine.Start();
            engine.Scheduler.Post("Init", () =>
            {
                foreach (var line in lines.Where(x => x.Length == 2))
                {
                    engine.ProcessTender.AddProcess(
                        new ProcessDefinition
                            {
                                Name = line[0] + ".1",
                                Command = line[1],
                                WorkingDirectory = options.Directory,
                            });
                }
            });
            Console.ReadLine();

            engine.Stop().Wait();
            return 0;
        }