Ejemplo n.º 1
0
        protected override void ExecuteCrmPlugin(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException(nameof(localContext));
            }

            try
            {
                AiLogger aiLogger = new AiLogger(_unsecureConfig, localContext.OrganizationService, localContext.TracingService,
                                                 localContext.PluginExecutionContext, localContext.PluginExecutionContext.Stage, null);

                string message  = ActionHelpers.GetInputValue <string>("message", localContext.PluginExecutionContext, localContext.TracingService);
                string severity = ActionHelpers.GetInputValue <string>("severity", localContext.PluginExecutionContext, localContext.TracingService);

                string severityValidationResult = AiTrace.ValidateSeverityValue(severity);
                if (!string.IsNullOrEmpty(severityValidationResult))
                {
                    localContext.TracingService.Trace(severityValidationResult);
                    return;
                }

                bool isValid = Enum.TryParse(severity, out AiTraceSeverity traceSeverity);

                aiLogger.WriteTrace(message, isValid
                    ? traceSeverity
                    : AiTraceSeverity.Information);
            }
            catch (Exception e)
            {
                localContext.TracingService.Trace($"Unhandled Exception: {e.Message}");
            }
        }
Ejemplo n.º 2
0
        protected override void ExecuteCrmWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext localContext)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (localContext == null)
            {
                throw new ArgumentNullException(nameof(localContext));
            }

            string   aiSetupJson = AiSetupJson.Get(context);
            AiLogger aiLogger    = new AiLogger(aiSetupJson, localContext.OrganizationService, localContext.TracingService,
                                                localContext.WorkflowExecutionContext, null, localContext.WorkflowExecutionContext.WorkflowCategory);

            string message  = Message.Get(context);
            string severity = Severity.Get(context);

            string severityValidationResult = AiTrace.ValidateSeverityValue(severity);

            if (!string.IsNullOrEmpty(severityValidationResult))
            {
                localContext.TracingService.Trace(severityValidationResult);
                LogSuccess.Set(context, false);
                return;
            }

            Enum.TryParse(severity, out AiTraceSeverity traceSeverity);

            bool logSuccess = aiLogger.WriteTrace(message, traceSeverity);

            LogSuccess.Set(context, logSuccess);
        }