private static bool HandleAssemblyUpdaterErrors(IEnumerable <AssemblyUpdaterUpdateTask> allTasks)
        {
            var tasksWithErrors = allTasks.Where(t => APIUpdaterAssemblyHelper.IsError(t.Result) || t.Exception != null);

            if (!tasksWithErrors.Any())
            {
                return(false);
            }

            var sb = new StringBuilder(L10n.Tr("Unable to update following assemblies:"));

            foreach (var updaterTask in tasksWithErrors)
            {
                sb.AppendFormat("{1} (Name = {2}, Error = {3}) (Output: {4}){0}{5}{0}{6}{0}", Environment.NewLine, updaterTask.Candidate.Path, updaterTask.Candidate.Name, updaterTask.Result, updaterTask.OutputPath, updaterTask.StdOut, updaterTask.StdErr);
                if (updaterTask.Exception != null)
                {
                    sb.AppendFormat("\tException: {0}{1}", updaterTask.Exception, Environment.NewLine);
                }
            }

            ReportIgnoredAssembliesDueToPreviousErrors(sb, allTasks.Except(tasksWithErrors));

            APIUpdaterLogger.WriteErrorToConsole(sb.ToString());
            return(true);
        }
        private static bool HandleCheckAssemblyPublishUpdaterConfigErrors(AssemblyUpdaterCheckAssemblyPublishConfigsTask[] nonTimedOutTasks)
        {
            var withErrors = nonTimedOutTasks.Where(t => APIUpdaterAssemblyHelper.IsError(t.Result) || t.Exception != null);

            if (!withErrors.Any())
            {
                return(false);
            }

            var sb = new StringBuilder(L10n.Tr("Failed to check following assemblies for updater configurations:\r\n"));

            foreach (var failledAssemblyInfo in withErrors)
            {
                sb.AppendFormat(L10n.Tr("{0} (ret = {1}):\r\n{2}\r\n{3}\r\n"), failledAssemblyInfo.Candidate.Path, failledAssemblyInfo.Result, failledAssemblyInfo.StdOut, failledAssemblyInfo.StdErr);
            }
            sb.Append("\r\n--------------");

            APIUpdaterLogger.WriteErrorToConsole(sb.ToString());

            return(true);
        }
        private static bool HandleAssemblyUpdaterErrors(IEnumerable <AssemblyUpdaterUpdateTask> allTasks)
        {
            var tasksWithErrors = allTasks.Where(t => APIUpdaterAssemblyHelper.IsError(t.Result) || APIUpdaterAssemblyHelper.IsUnknown(t.Result) || t.Exception != null);

            if (!tasksWithErrors.Any())
            {
                return(false);
            }

            var sb = new StringBuilder(L10n.Tr("Unable to update following assemblies:"));

            foreach (var updaterTask in tasksWithErrors)
            {
                sb.Append(FormatErrorFromTask(updaterTask));
            }

            ReportIgnoredAssembliesDueToPreviousErrors(sb, allTasks.Except(tasksWithErrors));

            APIUpdaterLogger.WriteErrorToConsole(sb.ToString());
            return(true);
        }
        private static void RunAssemblyUpdaterTask(object o)
        {
            var task = (AssemblyUpdaterTask)o;

            string stdOut = string.Empty;
            string stdErr = string.Empty;

            try
            {
                task.Result = APIUpdaterAssemblyHelper.Run(task.Arguments, AssemblyUpdaterTask.WorkingDirectory, out stdOut, out stdErr);
            }
            catch (Exception ex)
            {
                task.Exception = ex;
            }
            finally
            {
                task.StdErr = stdErr;
                task.StdOut = stdOut;

                task.Event.Set();
            }
        }
        static string FormatErrorFromTask(AssemblyUpdaterUpdateTask updaterTask)
        {
            // this may happen if mono.exe (which we use to run AssemblyUpdater.exe) cannot run the executable
            // and reports an error (for example, *file not found*)
            var unknownStatusMessage = APIUpdaterAssemblyHelper.IsUnknown(updaterTask.Result)
                ? " does not match any return code from AssemblyUpdater.exe"
                : string.Empty;

            var exceptionMessage = updaterTask.Exception != null
                ? $"{Environment.NewLine}\tException: {updaterTask.Exception}"
                : string.Empty;

            return(string.Format("{1} (Name = {2}, Error = {3}{7}) (Output: {4}){0}{5}{0}{6}{0}{8}",
                                 Environment.NewLine,
                                 updaterTask.Candidate.Path,
                                 updaterTask.Candidate.Name,
                                 updaterTask.Result,
                                 updaterTask.OutputPath,
                                 updaterTask.StdOut,
                                 updaterTask.StdErr,
                                 unknownStatusMessage,
                                 exceptionMessage));
        }
 public AssemblyUpdaterCheckAssemblyPublishConfigsTask(AssemblyUpdateCandidate a) : base(a)
 {
     Arguments = APIUpdaterAssemblyHelper.ArgumentsForCheckingForUpdaterConfigsOn(a.Path);
 }
 public AssemblyUpdaterUpdateTask(AssemblyUpdateCandidate a) : base(a)
 {
     OutputPath = Path.GetTempFileName();
     Arguments  = APIUpdaterAssemblyHelper.ArgumentsForUpdateAssembly(a.Path, OutputPath, a.UpdateConfigSources);
 }