Exemplo n.º 1
0
        public static ExecutionMetadata GenerateExecutionMetadata(IList <string> files)
        {
            var executionMetadata = new ExecutionMetadata()
            {
                StartCommand     = "",
                StartCommandArgs = new string[] { },
            };
            var procfiles   = files.Where(x => Path.GetFileName(x).ToLower() == "procfile").ToList();
            var executables = files.Where(x => x.EndsWith(".exe")).ToList();

            if (procfiles.Any())
            {
                var file    = File.ReadAllLines(procfiles.First());
                var webline = file.Where(x => x.StartsWith("web:"));
                if (webline.Any())
                {
                    var contents = webline.First().Substring(4).Trim().Split(new[] { ' ' });
                    executionMetadata.StartCommand     = contents[0];
                    executionMetadata.StartCommandArgs = contents.Skip(1).ToArray();
                }
                else
                {
                    throw new Exception("Procfile didn't contain a web line");
                }
            }
            else if (files.Any(x => Path.GetFileName(x).ToLower() == "web.config"))
            {
                executionMetadata.StartCommand = @"..\tmp\lifecycle\WebAppServer.exe";
            }
            else if (executables.Any())
            {
                if (executables.Count() > 1)
                {
                    throw new Exception("Directory contained more than 1 executable file.");
                }
                executionMetadata.StartCommand     = Path.GetFileName(executables.First());
                executionMetadata.StartCommandArgs = new string[] { };
            }
            else
            {
                Console.Error.WriteLine("No start command detected");
            }

            return(executionMetadata);
        }
Exemplo n.º 2
0
        public static ExecutionMetadata GenerateExecutionMetadata(IList<string> files)
        {
            var executionMetadata = new ExecutionMetadata()
            {
                StartCommand = "",
                StartCommandArgs = new string[] { },
            };
            var procfiles = files.Where(x => Path.GetFileName(x).ToLower() == "procfile").ToList();
            var executables = files.Where(x => x.EndsWith(".exe")).ToList();
            if (procfiles.Any())
            {
                var file = File.ReadAllLines(procfiles.First());
                var webline = file.Where(x => x.StartsWith("web:"));
                if (webline.Any())
                {
                    var contents = webline.First().Substring(4).Trim().Split(new[] { ' ' });
                    executionMetadata.StartCommand = contents[0];
                    executionMetadata.StartCommandArgs = contents.Skip(1).ToArray();
                }
                else
                {
                    throw new Exception("Procfile didn't contain a web line");
                }
            }
            else if (files.Any(x => Path.GetFileName(x).ToLower() == "web.config"))
            {
                executionMetadata.StartCommand = @"..\tmp\lifecycle\WebAppServer.exe";
            }
            else if (executables.Any())
            {
                if (executables.Count() > 1)
                    throw new Exception("Directory contained more than 1 executable file.");
                executionMetadata.StartCommand = Path.GetFileName(executables.First());
                executionMetadata.StartCommandArgs = new string[] { };
            }
            else
            {
                Console.Error.WriteLine("No start command detected");
            }

            return executionMetadata;
        }