Esempio n. 1
0
 public static void TaskExecuted(this ILogger logger, IStartupTask task, TimeSpan elapsed)
 {
     _taskExecuted(
         logger,
         task.GetType().GetDisplayName(),
         (long)elapsed.TotalMilliseconds);
 }
Esempio n. 2
0
 public static void TaskFailed(this ILogger logger, IStartupTask task, TimeSpan elapsed, Exception exception)
 {
     _taskFailed(
         logger,
         task.GetType().GetDisplayName(),
         (long)elapsed.TotalMilliseconds,
         exception: exception);
 }
        private int?GetFluentlyDeclaredPosition(IStartupTask task, ICollection tasks)
        {
            var group = Options.Groups.FirstOrDefault(g => g.Sequence.Any(t => t.TaskType == task.GetType()));

            if (group == null)
            {
                return(null);
            }
            var sequence = group.Sequence.Select(s => s.TaskType).ToList();

            if (!sequence.Contains(typeof(IStartupTask)))
            {
                return(sequence.IndexOf(task.GetType()) + 1);
            }
            if (sequence.IndexOf(typeof(IStartupTask)) > sequence.IndexOf(task.GetType()))
            {
                return(sequence.IndexOf(task.GetType()) + 1);
            }
            return(tasks.Count + sequence.IndexOf(task.GetType()) - sequence.IndexOf(typeof(IStartupTask)));
        }
        private static int?GetAttributeGroup(IStartupTask task)
        {
            var attribute = task.GetType().GetCustomAttributes(false).FirstOrDefault(a => a is TaskAttribute) as TaskAttribute;

            if (attribute == null)
            {
                return(null);
            }
            if (attribute.Group == 0)
            {
                return(null);
            }
            return(attribute.Group);
        }
        private static int?GetAttributePosition(IStartupTask task)
        {
            var attribute = task.GetType().GetCustomAttributes(false).FirstOrDefault(a => a is TaskAttribute) as TaskAttribute;

            if (attribute == null)
            {
                return(null);
            }
            if (attribute.PositionInSequence == int.MaxValue)
            {
                return(null);
            }
            return(attribute.PositionInSequence);
        }
        private int?GetFluentlyDeclaredDelay(IStartupTask task)
        {
            var group = Options.Groups.FirstOrDefault(g => g.Sequence.Any(t => t.TaskType == task.GetType()));

            if (group == null)
            {
                return(null);
            }
            var match = group.Sequence.FirstOrDefault(t => t.TaskType == task.GetType());

            if (match == null || match.Delay == 0)
            {
                return(null);
            }
            return(match.Delay);
        }
		private static void ExecuteTaskRecursively(
			IStartupTask task, ISet<Type> executedTasks, BootstrapSettings settings)
		{
			var dependencies =
				from dependencyType in task.Dependencies
				where !executedTasks.Contains(dependencyType)
				select (IStartupTask) Activator.CreateInstance(dependencyType);

			foreach (var dependencyTask in dependencies)
				ExecuteTaskRecursively(dependencyTask, executedTasks, settings);

			Log.InfoFormat("Executing {0} startup task", task.Name);
			task.Invoke(settings);
			Log.InfoFormat("{0} startup task have executed successfully", task.Name);
			executedTasks.Add(task.GetType());
		}
        private int?GetFluentlyDeclaredGroup(IStartupTask task)
        {
            var group = Options.Groups.FirstOrDefault(g => g.Sequence.Any(t => t.TaskType == task.GetType()));

            if (group == null)
            {
                return(null);
            }
            return(Options.Groups.IndexOf(group));
        }
Esempio n. 9
0
 /// <summary>
 /// Initializes a new <see cref="StartupTaskDescriptor"/>
 /// </summary>
 /// <param name="task">The <see cref="IStartupTask"/> to describe</param>
 public StartupTaskDescriptor(IStartupTask task)
 {
     this.Task      = task;
     this.Name      = task.GetType().Name.Replace("StartupTask", "").Replace("Task", "");
     this.StartedAt = DateTime.UtcNow;
 }
Esempio n. 10
0
 public static void TaskExecuting(this ILogger logger, IStartupTask task)
 {
     _taskExecuting(
         logger,
         task.GetType().GetDisplayName());
 }