예제 #1
0
        private static void ReduceTargetToDelta(PluginExecutionContext _, Entity target, Entity preImage)
        {
            _.Trace("Reducing 'Target' Entity to delta, based on attribute values in the PreEntityImage.");
            IEnumerable <string> keysRemoved = target.ReduceToDelta(preImage);

            _.Trace("Removed attributes: {0}", string.Join(",", keysRemoved));
        }
예제 #2
0
        public override void ExecutePlugin(PluginExecutionContext _)
        {
            var target = _.GetTarget <Entity>();

            _.Trace("Target: ",
                    (target == null ? "(null)" : target.ToTraceable()));
        }
예제 #3
0
        /// <summary>
        /// Trace information about the SdkMessage that triggered the plugin
        /// </summary>
        /// <param name="_"></param>
        /// <param name="config"></param>
        private static void TraceTrigger(PluginExecutionContext _, PluginConfiguration config)
        {
            bool blnTraceMessageStack;

            bool.TryParse(config.UnsecureDictionary["TraceMessageStack"], out blnTraceMessageStack);

            if (blnTraceMessageStack)
            {
                StringBuilder messageStack = new StringBuilder();

                IPluginExecutionContext adam = _;
                do
                {
                    messageStack.AppendLine(adam.ToTraceableMessage());
                    adam = adam.ParentContext;
                } while (adam.ParentContext != null);
                adam = null;

                _.Trace(
                    "Plugin message stack: {0}{1}",
                    Environment.NewLine,
                    messageStack.ToString());
            }
            else
            {
                _.Trace(
                    "Plugin triggered by {0}",
                    _.ToTraceableMessage());
            }
        }
예제 #4
0
 private static void TraceExitPointWithDuration(PluginExecutionContext _, string pluginTypeName, TimeSpan duration)
 {
     _.Trace("Exiting {0}.Execute(), Correlation Id: {1}, Duration: {2:N2}ms.",
             pluginTypeName,
             _.CorrelationId.ToString(),
             duration.TotalMilliseconds);
 }
예제 #5
0
 private static void ValidatePluginRegistration(PluginExecutionContext _)
 {
     if (string.Compare(_.MessageName, "Update", ignoreCase: true) != 0 || !(_.Stage == PluginStage.PreValidation || _.Stage == PluginStage.PreOperation))
     {
         _.Trace("This plugin only supports the Update message in Pre-Validation or Pre-Operation stages.");
         throw new InvalidPluginExecutionException("Invalid SdkMessageStep registration.");
     }
 }
        public override void ExecutePlugin(PluginExecutionContext _)
        {
            Entity target = _.GetTarget <Entity>();

            _.Trace("Updating {0}. Modified fields: {1}.",
                    target.ToEntityReference().ToTraceable(),
                    string.Join(",", target.Attributes.Keys.ToList()));
        }
예제 #7
0
 private static void TraceEntryPoint(PluginExecutionContext _, string pluginTypeName)
 {
     _.Trace("Entering {0}.Execute(), Depth: {1}, Request Id: {2}, Correlation Id: {3}, Running as: {4}.",
             pluginTypeName,
             _.Depth.ToString(),
             _.RequestId.ToString(),
             _.CorrelationId.ToString(),
             _.InitiatingUserId.ToString());
 }
예제 #8
0
        private static void GetPreImage(PluginExecutionContext _, out Entity preImage)
        {
            _.Trace("Getting PreEntityImage.");

            preImage = _.GetPreImage <Entity>();
            if (preImage == null)
            {
                throw new InvalidPluginExecutionException("PreEntityImage is null. Register a single PreEntityImage on the message processing step, including all attributes that are to be compared.");
            }
        }
예제 #9
0
        private static void GetTarget(PluginExecutionContext _, out Entity target)
        {
            _.Trace("Getting InputParameter['Target'].");

            target = _.GetTarget <Entity>();
            if (target == null)
            {
                throw new InvalidPluginExecutionException("Target is null.");
            }
        }
예제 #10
0
        public override void ExecutePlugin(PluginExecutionContext _)
        {
            Entity target   = null;
            Entity preImage = null;

            OptimizedUpdate.ValidatePluginRegistration(_);
            OptimizedUpdate.GetTarget(_, out target);
            OptimizedUpdate.GetPreImage(_, out preImage);
            OptimizedUpdate.ReduceTargetToDelta(_, target, preImage);
        }
예제 #11
0
        private void ExecutePluginWithTracesOnEntryAndExit(PluginExecutionContext _)
        {
            TraceEntryPoint(_, this.PluginTypeName);
            TraceTrigger(_, this.Configuration);

            TimeSpan duration = Metrics.TimeAction(() => {
                ExecutePlugin(_);
            });

            TraceExitPointWithDuration(_, this.PluginTypeName, duration);
        }
예제 #12
0
        void IPlugin.Execute(IServiceProvider serviceProvider)
        {
            PluginExecutionContext _ = new PluginExecutionContext(serviceProvider);

            try {
                this.ExecutePluginWithTracesOnEntryAndExit(_);
            }
            catch (InvalidPluginExecutionException) {
                throw;
            }
            catch (Exception ex) {
                _.Trace("!! Exception caught, plugin aborting.");

                throw new InvalidPluginExecutionException(
                          string.Format(
                              "Plugin '{0}' failed to execute, returning the error: {1}",
                              PluginTypeName,
                              ex.Message
                              ),
                          ex);
            }
        }
예제 #13
0
 public abstract void ExecutePlugin(PluginExecutionContext _);