Esempio n. 1
0
        public void Start(Server server)
        {
            lock (_proccesses)
            {
                if (_proccesses.ContainsKey(server.Id))
                {
                    try
                    {
                        _proccesses[server.Id].Kill();
                    }
                    catch
                    {
                    }

                    _proccesses.Remove(server.Id);
                }

                var command = ServerUtils.BuildCommand(server);

                var process = new Process();
                process.StartInfo.FileName  = command.Item1;
                process.StartInfo.Arguments = command.Item2;
                process.EnableRaisingEvents = true;
                process.Exited += new EventHandler((sender, e) =>
                {
                    log.InfoFormat("Unexpectedly closing server #{0}.", server.Id);
                    _context.Servers.Single(p => p.Id == server.Id).IsActivated = false;
                    _context.SubmitChanges();
                });

                _proccesses.Add(server.Id, process);
                process.Start();
            }
        }