private void AddExecutionContextDetails(
            IOrganizationService service,
            IExecutionContext executionContext,
            int?pluginStage,
            int?workflowCategory)
        {
            this.EventProperties.ImpersonatingUserId = executionContext.UserId.ToString();
            this.EventProperties.CorrelationId       = executionContext.CorrelationId.ToString();
            this.EventProperties.Message             = executionContext.MessageName;
            this.EventProperties.Mode               = AiProperties.GetModeName(executionContext.Mode);
            this.EventProperties.Depth              = executionContext.Depth;
            this.EventProperties.InputParameters    = this.TraceParameters(true, service, executionContext);
            this.EventProperties.OutputParameters   = this.TraceParameters(false, service, executionContext);
            this.EventProperties.OperationId        = executionContext.OperationId.ToString();
            this.EventProperties.OperationCreatedOn = executionContext.OperationCreatedOn.ToUniversalTime()
                                                      .ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
            this.EventProperties.OrganizationId = executionContext.OrganizationId.ToString();

            if (pluginStage != null)
            {
                var stage = pluginStage.Value;
                this.AddPluginExecutionContextDetails(stage, executionContext as IPluginExecutionContext);
            }

            if (workflowCategory != null)
            {
                var category = workflowCategory.Value;
                this.AddWorkflowExecutionContextDetails(category);
            }
        }
        private void AddPluginExecutionHistory(IPluginExecutionContext executionContext)
        {
            // This doesn't work... need to figure out something that can work here.
            DateTime?end = null;

            if (!executionContext.SharedVariables.ContainsKey("StartedOn"))
            {
                executionContext.SharedVariables.Add("StartedOn", DateTime.UtcNow);
            }
            else
            {
                end = (DateTime?)executionContext.SharedVariables["StartedOn"];
            }
            var past = new Stack <AiPluginProperties>();

            if (this.EventProperties.Depth > 1)
            {
                var currentContext = executionContext;
                var last           = currentContext;
                while (currentContext != null)
                {
                    past.Push(
                        new AiPluginProperties
                    {
                        OperationId         = currentContext.OperationId.ToString(),
                        ImpersonatingUserId = currentContext.UserId.ToString(),
                        CorrelationId       = currentContext.CorrelationId.ToString(),
                        Message             = currentContext.MessageName,
                        Mode                = AiProperties.GetModeName(currentContext.Mode),
                        Depth               = currentContext.Depth,
                        EntityId            = currentContext.PrimaryEntityId.ToString(),
                        EntityName          = currentContext.PrimaryEntityName,
                        Stage               = AiProperties.GetStageName(currentContext.Stage),
                        ParentCorrelationId = currentContext.ParentContext?.CorrelationId.ToString(),
                        OperationCreatedOn  = currentContext.OperationCreatedOn.ToUniversalTime()
                                              .ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'")
                    });
                    last           = currentContext;
                    currentContext = currentContext.ParentContext;
                }

                var span = DateTime.UtcNow - (end ?? last.OperationCreatedOn.ToUniversalTime());

                this.WriteMetric("BackendDuration", span.TotalMilliseconds);

                this.EventProperties.History  = past.ToArray();
                this.EventProperties.Duration = span.TotalMilliseconds.ToString();
            }
        }
Beispiel #3
0
        private void AddExecutionContextDetails(IExecutionContext executionContext, int?pluginStage, int?workflowCategory)
        {
            _eventProperties.ImpersonatingUserId = executionContext.UserId.ToString();
            _eventProperties.CorrelationId       = executionContext.CorrelationId.ToString();
            _eventProperties.Message             = executionContext.MessageName;
            _eventProperties.Mode             = AiProperties.GetModeName(executionContext.Mode);
            _eventProperties.Depth            = executionContext.Depth;
            _eventProperties.InputParameters  = TraceParameters(true, executionContext);
            _eventProperties.OutputParameters = TraceParameters(false, executionContext);

            if (pluginStage != null)
            {
                int stage = pluginStage.Value;
                AddPluginExecutionContextDetails(stage);
            }

            if (workflowCategory != null)
            {
                int category = workflowCategory.Value;
                AddWorkflowExecutionContextDetails(category);
            }
        }