Пример #1
0
        /// <summary>
        /// Executes the compilation process.
        /// </summary>
        /// <param name="compilation">The compilation object.</param>
        /// <param name="outputStream">The output stream to write to.</param>
        /// <returns>The compilation result.</returns>
        public CompilationResult Execute(CompilationRequest input, Stream outputStream)
        {
            var context = new CompilationContext
            {
                Input        = input,
                OutputStream = outputStream,
                Result       = new CompilationResult()
            };

            // TODO: move model registry into
            // compilation context instance

            // this locks the current scope
            ModelRegistry.BeginRegistration();
            CompilationContext.Current = context;
            var profiler = new ProcessProfiler();

            try
            {
                foreach (var proc in _processes)
                {
                    profiler.Execute(proc, context);
                    if (context.Result.HasErrors)
                    {
                        break;
                    }
                }
            }
            catch (CompilationException compEx)
            {
                context.Result.AddError(compEx.ToErrorMessage());
            }
            catch (Exception ex)
            {
                context.Result.AddError("Unexpected Error: " + ex.Message);
            }
            finally
            {
                // release lock
                ModelRegistry.EndRegistration();
                CompilationContext.Current = null;
                profiler.End();
            }

            return(context.Result);
        }