private async Task <BuildContentOutput> DoBuildContentForBuildRequestAsync(BuildRequest buildRequest)
        {
            Message message = buildRequest.SharedObject.GetValue <Message>(Constants.BuildMessage);

            // add message priority into AmbientContext
            SetMessagePriorityInAmbientContext(message);

            TraceEx.TraceInformation(
                string.Format(
                    "Build content for request Action: {0}, EntityIdentifier: {1}, Message: {2}",
                    buildRequest.ActionName,
                    buildRequest.EntityIdentifier,
                    Utility.ToJsonString(message)));

            string pipelineName = BuildActionMapper.GetPipelineName(buildRequest.ActionName);

            if (string.IsNullOrEmpty(pipelineName))
            {
                string errorMessage = LogMessage.FormatMessage(LogCode.PipelineForActionNotFound, buildRequest.ActionName);
                TraceEx.TraceError(errorMessage);
                throw new ArgumentException(errorMessage);
            }

            BuildEngine  engine;
            BuildContext context;

            using (new PerformanceScopeWrapper(
                       "Setup Context",
                       PerformanceCategory.Pipeline))
            {
                string reportPipelineName = GetReportPipelineName(buildRequest.ActionName, message.MessageType);
                engine  = BuildEngineFactory.CreateEngineByPipelineName(reportPipelineName);
                context = engine.Context;

                context.XmlContext.AddVariable(Constants.ContextData.PipelineName, pipelineName);
                await SetupContextAsync(context, buildRequest);

                context.SetSharedObject(Constants.ContextData.PipelineStartTime, DateTime.UtcNow);
            }

            PipelineResult result = PipelineResult.Break;

            using (new PerformanceScopeWrapper(
                       string.Format("Setup Pipeline: {0}", buildRequest.ActionName),
                       PerformanceCategory.Pipeline))
            {
                engine.Pipeline.Setup(context);
            }

            XmlDocument document = new XmlDocument();

            result = await engine.Pipeline.ApplyAsync(document, context);

            return(new BuildContentOutput
            {
                BuildContentResult = result == PipelineResult.NeedRerun ? BuildContentResult.NeedRerun : BuildContentResult.Succeeded,
                Outputs = context.Outputs
            });
        }
Esempio n. 2
0
        public static async void RunTaskSilentlyNoWait(Task task, [CallerMemberName] string taskDescription = null)
        {
            Guard.ArgumentNotNull(task, nameof(task));

            try
            {
                await task;
                TraceEx.TraceInformation($"{taskDescription} succeeded.");
            }
            catch (Exception ex)
            {
                TraceEx.TraceError($"{taskDescription} failed: {ex}");
            }
        }
Esempio n. 3
0
        private void Refresh(IReadOnlyDictionary <string, object> config, bool silent)
        {
            object value;

            if (config.TryGetValue(_key, out value))
            {
                try
                {
                    T typedValue = _converter != null?_converter(value) : (T)value;

                    if (!object.Equals(Value, typedValue))
                    {
                        TraceEx.TraceInformation(string.Format("Configuration '{0}' is changed from '{1}' to '{2}'.", _key, Value, typedValue));
                        Value = typedValue;
                        if (OnChanged != null)
                        {
                            OnChanged();
                        }
                    }
                }
                catch (InvalidCastException)
                {
                    TraceEx.TraceWarning(string.Format("Cannot cast value '{0}' to type '{1}', original value is kept.", value, typeof(T)));
                    if (!silent)
                    {
                        throw;
                    }
                }
            }
            else
            {
                TraceEx.TraceWarning(string.Format("Cannot find configuration '{0}', original value is kept.", _key));
                if (!silent)
                {
                    throw new KeyNotFoundException(string.Format("Cannot find configuration '{0}'", _key));
                }
            }
        }