Example #1
0
        static void Main(string[] args)
        {
            //args = new string[] { "3456", @"C:\Users\ack\src\Autotest.Net\AutoTest.Net.sln", Guid.NewGuid().ToString(), "debug", "0", "global" };
            LaunchArguments arguments = null;
            try
            {
                arguments = parseArguments(args);
                Logger.SetDebugMode(arguments.Debug);
                Logger.WriteInfo("Starting application");

                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                _feedback = new ServerFeedback();
                _feedback.ClientDisconnected += _feedback_ClientDisconnected;
                _feedback.ClientConnect += _feedback_ClientConnect;
                server = new TcpServer(_feedback);

                server.MessageReceived += OnRecieve;
                server.StartServer("127.0.0.1", arguments.Port);
                var writeLocator = new DefaultConfigFileLocator(server.Port.ToString(), arguments.IsGlobal);
                initializeConfiguration(writeLocator.GetConfigurationFile());
                if (arguments.IsGlobal)
                    _license = new RhinoValidator(Environment.SpecialFolder.CommonApplicationData);
                else
                    _license = new RhinoValidator(Environment.SpecialFolder.LocalApplicationData);

                _engine = new ATEngine(server, writeLocator, arguments.WatchPath, _license);
                _engine.Start();

                Logger.WriteInfo(string.Format("VM listening on 127.0.0.1:{0}", server.Port));
                startExitTimer();
                SendVmInitializedMessage(arguments.CorrelationId, server, arguments.OwnerPort);
                int clientsConnected = 0;
                while (!_shouldExit)
                {
                    if (clientsConnected == 0 && server.ClientCount > 0)
                        _engine.ValidateConfiguration();
                    clientsConnected = server.ClientCount;
                    Thread.Sleep(1000);
                    if (isMasterDead(arguments.MasterProcessId))
                        shutdown();
                }
                Logger.WriteDebug("We were told to shut down so now we'll send off a vm terminating message and die");
                if (server.ClientCount > 0)
                    SendVmTerminatingMessage(server, arguments.OwnerPort);
            }
            catch (Exception ex)
            {
                if (arguments != null)
                    Logger.Write(ex);
                else
                    Console.WriteLine(ex.ToString());
            }
            finally
            {
                AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException;
            }
            Logger.WriteDebug("Screw you guys I'm going home!");
        }
Example #2
0
        static void Main(string[] args)
        {
            //args = new string[] { "3456", @"C:\Users\ack\src\Autotest.Net\AutoTest.Net.sln", Guid.NewGuid().ToString(), "debug", "0", "global" };
            LaunchArguments arguments = null;

            try
            {
                arguments = parseArguments(args);
                Logger.SetDebugMode(arguments.Debug);
                Logger.WriteInfo("Starting application");

                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                _feedback = new ServerFeedback();
                _feedback.ClientDisconnected += _feedback_ClientDisconnected;
                _feedback.ClientConnect      += _feedback_ClientConnect;
                server = new TcpServer(_feedback);

                server.MessageReceived += OnRecieve;
                server.StartServer("127.0.0.1", arguments.Port);
                var writeLocator = new DefaultConfigFileLocator(server.Port.ToString(), arguments.IsGlobal);
                initializeConfiguration(writeLocator.GetConfigurationFile());
                if (arguments.IsGlobal)
                {
                    _license = new RhinoValidator(Environment.SpecialFolder.CommonApplicationData);
                }
                else
                {
                    _license = new RhinoValidator(Environment.SpecialFolder.LocalApplicationData);
                }

                _engine = new ATEngine(server, writeLocator, arguments.WatchPath, _license);
                _engine.Start();

                Logger.WriteInfo(string.Format("VM listening on 127.0.0.1:{0}", server.Port));
                startExitTimer();
                SendVmInitializedMessage(arguments.CorrelationId, server, arguments.OwnerPort);
                int clientsConnected = 0;
                while (!_shouldExit)
                {
                    if (clientsConnected == 0 && server.ClientCount > 0)
                    {
                        _engine.ValidateConfiguration();
                    }
                    clientsConnected = server.ClientCount;
                    Thread.Sleep(1000);
                    if (isMasterDead(arguments.MasterProcessId))
                    {
                        shutdown();
                    }
                }
                Logger.WriteDebug("We were told to shut down so now we'll send off a vm terminating message and die");
                if (server.ClientCount > 0)
                {
                    SendVmTerminatingMessage(server, arguments.OwnerPort);
                }
            }
            catch (Exception ex)
            {
                if (arguments != null)
                {
                    Logger.Write(ex);
                }
                else
                {
                    Console.WriteLine(ex.ToString());
                }
            }
            finally
            {
                AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException;
            }
            Logger.WriteDebug("Screw you guys I'm going home!");
        }