Esempio n. 1
0
        private static bool ExecuteSubStep(string subStepName, ITaskContext taskContext, ITask task, Func <ITaskContext, ITask, bool> substep, Func <ITaskContext, ITask, Exception, Exception> createException, bool throwOnFalse)
        {
            bool       flag = false;
            Exception  ex   = null;
            ExDateTime now  = ExDateTime.Now;

            try
            {
                taskContext.Logger.LogInformation(HybridStrings.HybridInfoTaskSubStepStart(task.Name, subStepName));
                flag = substep(taskContext, task);
                if (taskContext.Warnings.Count > 0)
                {
                    foreach (LocalizedString localizedString in taskContext.Warnings)
                    {
                        taskContext.Logger.LogWarning(localizedString);
                        taskContext.UI.WriteWarning(localizedString);
                    }
                    taskContext.Warnings.Clear();
                }
                if (throwOnFalse && !flag)
                {
                    ex = createException(taskContext, task, null);
                }
            }
            catch (Exception arg)
            {
                ex = createException(taskContext, task, arg);
            }
            finally
            {
                if (ex != null)
                {
                    taskContext.Logger.LogError(ex.ToString());
                }
                double totalMilliseconds = ExDateTime.Now.Subtract(now).TotalMilliseconds;
                taskContext.Logger.LogInformation(HybridStrings.HybridInfoTaskSubStepFinish(task.Name, subStepName, flag, totalMilliseconds));
                taskContext.Logger.LogInformation(new string('-', 128));
                if (ex != null)
                {
                    throw ex;
                }
            }
            return(flag);
        }