Ejemplo n.º 1
0
        void ScheduledRun()
        {
            //contract = new Turbine.Consumer.Data.Contract.ConsumerRegistrationContract();
            contract        = Turbine.Consumer.AppUtility.GetConsumerRegistrationContract();
            consumerRun     = Turbine.Consumer.AppUtility.GetConsumerRunContract();
            consumerMonitor = Turbine.Consumer.AppUtility.GetConsumerMonitorContract();

            consumerMonitor.setConsumerRun(consumerRun);

            try
            {
                contract.Register(consumerRun);
            }
            catch (System.Data.UpdateException ex)
            {
                // TODO: Ask to be shutdown
                Debug.WriteLine("Failed Register UpdateException: " + ex, "AspenSinter");
                Debug.WriteLine("InnerException:  " + ex.InnerException, "AspenSinter");
                Environment.Exit(1);
            }
            catch (Exception ex)
            {
                // TODO: Ask to be shutdown
                Debug.WriteLine("Failed to Register: " + ex.Message, "AspenSinter");
                Debug.WriteLine(ex.StackTrace);
                Environment.Exit(1);
            }

            // Run KeepAlive task
            var ktask = new Task <bool>(() => KeepAlive());

            ktask.Start();

            try
            {
                _ScheduledRun();
            }
            catch (System.Data.UpdateException ex)
            {
                // TODO: Ask to be shutdown
                Debug.WriteLine("Failed ScheduledRun UpdateException: " + ex, "AspenSinter");
                Debug.WriteLine("InnerException:  " + ex.InnerException);
                throw;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed ScheduledRun: " + ex.Message, "AspenSinter");
                Debug.WriteLine(ex.StackTrace);
                contract.Error();
                Debug.WriteLine("SERVICE GOING TO EXIT", "AspenSinter");
                Environment.Exit(1);
            }

            try
            {
                contract.UnRegister();
            }
            catch (System.Data.UpdateException ex)
            {
                // TODO: Ask to be shutdown
                Debug.WriteLine("Failed UnRegister UpdateException: " + ex.Message, "AspenSinter");
                Debug.WriteLine("InnerException:  " + ex.InnerException, "AspenSinter");
            }
            catch (Exception ex)
            {
                // TODO: Ask to be shutdown
                Debug.WriteLine("Failed UnRegister: " + ex.Message, "AspenSinter");
                Debug.WriteLine(ex.StackTrace, "AspenSinter");
            }

            if (shutdown)
            {
                Debug.WriteLine("CONTRACT SHUTDOWN", "AspenSinter");
                shutdownProcess = System.Diagnostics.Process.Start("shutdown", "/s /t 10");
            }
            else if (!stop)
            {
                Debug.WriteLine("SERVICE GOING TO EXIT", "AspenSinter");
                Environment.Exit(1);
            }
        }