/// <summary>
        /// Gather important information of the currently running program.
        /// Also determine which systems we can connect to correctly
        /// </summary>
        /// <returns></returns>
        private RobotDiagnostics PerformDiagnostics()
        {
            var results = new RobotDiagnostics();

            // gather data about the current hosting machine
            results.ServerName = Dns.GetHostName();
            results.ServerPath = System.Reflection.Assembly.GetEntryAssembly().Location;
            var host = Dns.GetHostEntry(results.ServerName);

            results.ServerIPAddress = host.AddressList.FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetwork);

            // ping the connectivity of the remote services and providers
            results.TaskServerHealth    = _taskServer.TestHealth();
            results.StagingServerHealth = _stagingServer.TestHealth();
            if (_entity1Provider != null)
            {
                results.Entity1ProviderHealth = _entity1Provider.TestHealth();
            }
            if (_entity2Provider != null)
            {
                results.Entity2ProviderHealth = _entity2Provider.TestHealth();
            }

            return(results);
        }
        /// <summary>
        /// Begin processing the robot
        /// </summary>
        /// <returns></returns>
        public bool Start()
        {
            VerboseOutput(" * Verbose mode selected.");

            if (StagingDisabled)
            {
                VerboseOutput(" * Pretend mode selected (no data will be staged).");
            }

            if (HealthCheckOnly)
            {
                VerboseOutput(" * Health check only.");
            }


            // Test connectivity of all providers and staging server
            _robotDiagnostics = PerformDiagnostics();
            if (Verbose || HealthCheckOnly)
            {
                Console.WriteLine(FormatDiagnosticsMessage(_robotDiagnostics));
            }

            if (HealthCheckOnly)
            {
                VerboseOutput("Health check completed.  Exiting.");
                return(true);
            }

            // Connect to task server and :
            //   - report systems connectivity
            //   - ask server if a new run is required (along with parameters for run)
            // (on error, send error notification and abort)
            ActionResponse actionResponse = _taskServer.ReportRobotHealth(_robotDiagnostics);

            if (!actionResponse.Success)
            {
                // We failed connecting to the task server!!!!!  Need to fall back to manually alerting someone...
                SendErrorEmail("Error", "Failed reporting Robot health to task server! " + actionResponse.Message);
                return(false);
            }

            ActionResponse <NewTaskRunResult> requestNewTaskRunResult = _taskServer.RequestNewTaskRun();

            if (!requestNewTaskRunResult.Success)
            {
                // We failed connecting to the task server!!!!!  Need to fall back to manually alerting someone...
                SendErrorEmail("Error", "Failed requesting new task run with task server! " + requestNewTaskRunResult.Message);
                return(false);
            }

            if (!requestNewTaskRunResult.Response.RunRequired)
            {
                // The task server has told us we don't need to run.  Nothing left to do.
                return(true);
            }

            return(PerformTask(requestNewTaskRunResult.Response));
        }
        private string FormatDiagnosticsMessage(RobotDiagnostics diagnostics)
        {
            var sb = new StringBuilder();

            sb.AppendFormat("======================================================================").AppendLine();
            sb.AppendFormat("Robot Diagnostics :").AppendLine();
            sb.AppendFormat("======================================================================").AppendLine();
            sb.AppendFormat("   Robot Id       : {0}", _robotId).AppendLine();
            sb.AppendFormat("   Server Name    : {0}", diagnostics.ServerName).AppendLine();
            sb.AppendFormat("   Server IP      : {0}", diagnostics.ServerIPAddress).AppendLine();
            sb.AppendFormat("   Server Path    : {0}", diagnostics.ServerPath).AppendLine();
            sb.AppendFormat("   Remote Health  : {0}", diagnostics.AllProvidersHealthy ? "All Ok" : "Fail").AppendLine();
            sb.AppendFormat("                  : {0} -> {1}", "Task Server", diagnostics.TaskServerHealth.Success ? "Ok" : "Fail").AppendLine();
            sb.AppendFormat("                  : {0} -> {1}", "Staging Server", diagnostics.StagingServerHealth.Success ? "Ok" : "Fail").AppendLine();
            sb.AppendFormat("                  : {0} -> {1}", _entity1Provider.DataType.Name, diagnostics.Entity1ProviderHealth.Success ? "Ok" : "Fail").AppendLine();
            sb.AppendFormat("                  : {0} -> {1}", _entity2Provider.DataType.Name, diagnostics.Entity1ProviderHealth.Success ? "Ok" : "Fail").AppendLine();
            sb.AppendFormat("======================================================================").AppendLine();
            return(sb.ToString());
        }
 public ActionResponse ReportRobotHealth(RobotDiagnostics robotDiagnostics)
 {
     return(new ActionResponse {
         Success = true
     });
 }