Example #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Name">Event name</param>
 /// <param name="StartTime">Time of the event</param>
 /// <param name="FinishTime">Finish time for the event. May be null.</param>
 public Event(string Name, TimeSpan StartTime, TimeSpan?FinishTime)
 {
     this.Name       = Name;
     this.StartTime  = StartTime;
     this.FinishTime = FinishTime;
     this.Span       = TraceSpan.Create(Name);
 }
Example #2
0
        /// <summary>
        /// Build all the tasks for this node
        /// </summary>
        /// <param name="Job">Information about the current job</param>
        /// <param name="TagNameToFileSet">Mapping from tag names to the set of files they include. Should be set to contain the node inputs on entry.</param>
        /// <returns>Whether the task succeeded or not. Exiting with an exception will be caught and treated as a failure.</returns>
        public bool Build(JobContext Job, Dictionary <string, HashSet <FileReference> > TagNameToFileSet)
        {
            // Run each of the tasks in order
            HashSet <FileReference> BuildProducts = TagNameToFileSet[DefaultOutput.TagName];

            for (int Idx = 0; Idx < Tasks.Count; Idx++)
            {
                using (ITraceSpan Span = TraceSpan.Create("Task", Tasks[Idx].GetTraceName()))
                {
                    ITaskExecutor Executor = Tasks[Idx].GetExecutor();
                    if (Executor == null)
                    {
                        // Execute this task directly
                        try
                        {
                            Tasks[Idx].GetTraceMetadata(Span, "");
                            Tasks[Idx].Execute(Job, BuildProducts, TagNameToFileSet);
                        }
                        catch (Exception Ex)
                        {
                            ExceptionUtils.AddContext(Ex, "while executing task {0}", Tasks[Idx].GetTraceString());
                            if (Tasks[Idx].SourceLocation != null)
                            {
                                ExceptionUtils.AddContext(Ex, "at {0}({1})", GetReadablePathForDiagnostics(Tasks[Idx].SourceLocation.Item1), Tasks[Idx].SourceLocation.Item2);
                            }
                            throw;
                        }
                    }
                    else
                    {
                        Tasks[Idx].GetTraceMetadata(Span, "1.");

                        // The task has a custom executor, which may be able to execute several tasks simultaneously. Try to add the following tasks.
                        int FirstIdx = Idx;
                        while (Idx + 1 < Tasks.Count && Executor.Add(Tasks[Idx + 1]))
                        {
                            Idx++;
                            Tasks[Idx].GetTraceMetadata(Span, string.Format("{0}.", 1 + Idx - FirstIdx));
                        }
                        try
                        {
                            Executor.Execute(Job, BuildProducts, TagNameToFileSet);
                        }
                        catch (Exception Ex)
                        {
                            for (int TaskIdx = FirstIdx; TaskIdx <= Idx; TaskIdx++)
                            {
                                ExceptionUtils.AddContext(Ex, "while executing {0}", Tasks[TaskIdx].GetTraceString());
                            }
                            if (Tasks[FirstIdx].SourceLocation != null)
                            {
                                ExceptionUtils.AddContext(Ex, "at {0}({1})", GetReadablePathForDiagnostics(Tasks[FirstIdx].SourceLocation.Item1), Tasks[FirstIdx].SourceLocation.Item2);
                            }
                            throw;
                        }
                    }
                }
            }

            // Remove anything that doesn't exist, since these files weren't explicitly tagged
            BuildProducts.RemoveWhere(x => !FileReference.Exists(x));
            return(true);
        }