Exemplo n.º 1
0
        public override int Run(string[] remainingArguments)
        {
            var satpath = Path.Combine(AssemblyDirectory, "platforms.yml");

            var foundError = false;

            if (File.Exists(satpath))
            {
                var inputText = Substitute(File.ReadAllText(satpath));
                using (var input = new StringReader(inputText))
                {
                    var des = new Deserializer(namingConvention: new CamelCaseNamingConvention());
                    _satellites = des.Deserialize<IList<Satellite>>(input).ToDictionary(k => k.Id, v => v);
                    foreach (var satellite in _satellites)
                    {
                        satellite.Value.Path = Path.Combine(Path.GetDirectoryName(satpath),
                                                            PlatformFixPath(satellite.Value.Path));
                    }
                }
            }
            else //if no platforms.yml included, use a nested directory of exes.
            {
                _satellites = new Dictionary<string, Satellite>();
                var exeDir = Path.Combine(AssemblyDirectory, "Platforms");
                var exes = Directory.GetFiles(exeDir, "*.exe");
                foreach (var exe in exes)
                {
                    var sat = new Satellite {Id = Path.GetFileName(exe), Path = Path.Combine(exeDir, exe)};
                    _satellites.Add(sat.Id, sat);
                }
            }

            if (!_satellites.Any())
            {
                Console.WriteLine("Platform Runners not found!");
                Environment.Exit(1);
            }

            string sharedpath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            string configPath = remainingArguments.First();
            var inputText2 = Substitute(File.ReadAllText(configPath));
            using (var input = new StringReader(inputText2))
            {
                var des = new Deserializer(namingConvention: new CamelCaseNamingConvention());
                var setting = des.Deserialize<YamlSettings>(input);

                var fullConfigPath = Path.GetDirectoryName(Path.GetFullPath(configPath));

                _port = _port ?? GetUnusedPort();

                string url = string.Format("http://localhost:{0}", _port);
                //Create Temp shared path
                Directory.CreateDirectory(sharedpath);

                using (var host = new NancyHost(new HostConfiguration{RewriteLocalhost = false},new Uri(url)))
                {
                    var results = PlatformResults.Instance;
                    results.ResharePath = sharedpath;
                    results.Includes.AddRange(_includes);
                    results.Excludes.AddRange(_excludes);

                    host.Start();
                    Console.WriteLine("Server running on {0}", url);

                    var assemblies = setting.Config.Assemblies.ToDictionary(Path.GetFileName, v => v);

                    var threadList = new List<Thread>();

                        lock (results.WaitingForPlatforms)
                        {
                            //lock is not necessary but underscores that fact
                            //that the WaitingForPlatforms needs to be complete before the end of
                            //this block.
                            foreach (var set in setting.Config.Platforms)
                            {
                                var sat = _satellites[set.Id];
                                var pgr = Path.Combine(Path.GetDirectoryName(satpath), PlatformFixPath(sat.Path));
                                var progexists = File.Exists(pgr);
                                results.WaitingForPlatforms.Add(set.Id);

                                Func<string, string> expandPath =
                                it => string.Format("\"{0}\"", Path.Combine(fullConfigPath, PlatformFixPath(it)));

                                var currentAssemblies = CurrentAssemblies(assemblies, set);

                                var asmpaths = currentAssemblies
                                                      .Values
                                                      .Select(expandPath)
                                                      .Aggregate(String.Empty,
                                                                 (seed, item) => string.Format("{0} {1}", seed, item));

                                var processArgs = String.Format("sat {4} {0} {1} {2} {3}",
                                    sat.Id, url, sharedpath, asmpaths, !_showsats ? "hidden" : "show");
                                var process = new Process()
                                                  {
                                                      StartInfo =
                                                              new ProcessStartInfo(pgr, processArgs)
                                                              {
                                                                  CreateNoWindow = !_showsats,
                                                                  UseShellExecute = _showsats,
                                                                  RedirectStandardOutput = !_showsats
                                                              }
                                                  };

                                threadList.Add(new Thread(() =>
                                                              {
                                                                  using (process)
                                                                  {
                                                                      if (progexists)
                                                                      {
                                                                          process.Start();
                                                                          process.WaitForExit();
                                                                      }
                                                                      results.Exited(sat.Id);
                                                                  }
                                                              }));

                            }
                        }

                        foreach (var thread in threadList)
                        {
                            thread.Start();
                        }
                        foreach (var thread in threadList)
                        {
                            thread.Join();
                        }

                        WriteResults.ToFiles(results.File, _outputs);
                        PrintResults.PrintEnd(results);
                        foundError = (results.Errors.Any() || results.Failures.Any());
                }
            }

            try
            {
                //Try Delete Temp shared path
                Directory.Delete(sharedpath);
            }catch{}

            if (!_noerrorcode && foundError)
                return 1;
            return 0;
        }
Exemplo n.º 2
0
        public override int Run(string[] remainingArguments)
        {
            var satpath = Path.Combine(AssemblyDirectory, "platforms.yml");

            var foundError = false;

            if (File.Exists(satpath))
            {
                var inputText = Substitute(File.ReadAllText(satpath));
                using (var input = new StringReader(inputText))
                {
                    var des = new Deserializer(namingConvention: new CamelCaseNamingConvention());
                    _satellites = des.Deserialize <IList <Satellite> >(input).ToDictionary(k => k.Id, v => v);
                    foreach (var satellite in _satellites)
                    {
                        satellite.Value.Path = Path.Combine(Path.GetDirectoryName(satpath),
                                                            PlatformFixPath(satellite.Value.Path));
                    }
                }
            }
            else //if no platforms.yml included, use a nested directory of exes.
            {
                _satellites = new Dictionary <string, Satellite>();
                var exeDir = Path.Combine(AssemblyDirectory, "Platforms");
                var exes   = Directory.GetFiles(exeDir, "*.exe");
                foreach (var exe in exes)
                {
                    var sat = new Satellite {
                        Id = Path.GetFileName(exe), Path = Path.Combine(exeDir, exe)
                    };
                    _satellites.Add(sat.Id, sat);
                }
            }

            if (!_satellites.Any())
            {
                Console.WriteLine("Platform Runners not found!");
                Environment.Exit(1);
            }

            string sharedpath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            string configPath = remainingArguments.First();
            var    inputText2 = Substitute(File.ReadAllText(configPath));

            using (var input = new StringReader(inputText2))
            {
                var des     = new Deserializer(namingConvention: new CamelCaseNamingConvention());
                var setting = des.Deserialize <YamlSettings>(input);

                var fullConfigPath = Path.GetDirectoryName(Path.GetFullPath(configPath));

                _port = _port ?? GetUnusedPort();

                string url = string.Format("http://localhost:{0}", _port);
                //Create Temp shared path
                Directory.CreateDirectory(sharedpath);

                using (var host = new NancyHost(new HostConfiguration {
                    RewriteLocalhost = false
                }, new Uri(url)))
                {
                    var results = PlatformResults.Instance;
                    results.ResharePath = sharedpath;
                    results.Includes.AddRange(_includes);
                    results.Excludes.AddRange(_excludes);

                    host.Start();
                    Console.WriteLine("Server running on {0}", url);

                    var assemblies = setting.Config.Assemblies.ToDictionary(Path.GetFileName, v => v);

                    var threadList = new List <Thread>();

                    lock (results.WaitingForPlatforms)
                    {
                        //lock is not necessary but underscores that fact
                        //that the WaitingForPlatforms needs to be complete before the end of
                        //this block.
                        foreach (var set in setting.Config.Platforms)
                        {
                            var sat        = _satellites[set.Id];
                            var pgr        = Path.Combine(Path.GetDirectoryName(satpath), PlatformFixPath(sat.Path));
                            var progexists = File.Exists(pgr);
                            results.WaitingForPlatforms.Add(set.Id);

                            Func <string, string> expandPath =
                                it => string.Format("\"{0}\"", Path.Combine(fullConfigPath, PlatformFixPath(it)));

                            var currentAssemblies = CurrentAssemblies(assemblies, set);

                            var asmpaths = currentAssemblies
                                           .Values
                                           .Select(expandPath)
                                           .Aggregate(String.Empty,
                                                      (seed, item) => string.Format("{0} {1}", seed, item));

                            var processArgs = String.Format("sat {4} {0} {1} {2} {3}",
                                                            sat.Id, url, sharedpath, asmpaths, !_showsats ? "hidden" : "show");
                            var process = new Process()
                            {
                                StartInfo =
                                    new ProcessStartInfo(pgr, processArgs)
                                {
                                    CreateNoWindow         = !_showsats,
                                    UseShellExecute        = _showsats,
                                    RedirectStandardOutput = !_showsats
                                }
                            };

                            threadList.Add(new Thread(() =>
                            {
                                using (process)
                                {
                                    if (progexists)
                                    {
                                        process.Start();
                                        process.WaitForExit();
                                    }
                                    results.Exited(sat.Id);
                                }
                            }));
                        }
                    }

                    foreach (var thread in threadList)
                    {
                        thread.Start();
                    }
                    foreach (var thread in threadList)
                    {
                        thread.Join();
                    }

                    WriteResults.ToFiles(results.File, _outputs);
                    PrintResults.PrintEnd(results);
                    foundError = (results.Errors.Any() || results.Failures.Any());
                }
            }

            try
            {
                //Try Delete Temp shared path
                Directory.Delete(sharedpath);
            }catch {}

            if (!_noerrorcode && foundError)
            {
                return(1);
            }
            return(0);
        }