Example #1
0
 public void AgentInvokeResumed(MExSession session)
 {
     if (this.OnAgentInvokeResumed != null)
     {
         this.OnAgentInvokeResumed(this, session);
     }
 }
Example #2
0
 private void AgentAsyncCompletionCallback(AgentAsyncContext context)
 {
     if (this.resumeAgentCallback != null && this.resumeAgentCallback())
     {
         MExDiagnostics.EventLog.LogEvent(EdgeExtensibilityEventLogConstants.Tuple_MExAgentDidNotCallResume, this.lastAgentName, new object[]
         {
             this.lastAgentName,
             this.eventTopic
         });
     }
     ExTraceGlobals.DispatchTracer.TraceDebug <string, string>((long)this.GetHashCode(), this.InstanceNameFormatted + "async completed, async result {0}, exception {1}", this.isSyncInvoke ? "n/a" : this.pendingResult.GetHashCode().ToString(CultureInfo.InvariantCulture), (context.AsyncException == null) ? "n/a" : context.AsyncException.GetType().FullName);
     if (this.isSyncInvoke)
     {
         if (context.AsyncException != null)
         {
             MExAsyncResult.WrapAndRethrowException(context.AsyncException, new LocalizedString(MExRuntimeStrings.AgentFault(this.currentAgent.Name, this.eventTopic)));
         }
         this.syncWaitHandle.Set();
         return;
     }
     if (context.AsyncException != null)
     {
         this.pendingResult.AsyncException = context.AsyncException;
         this.HaltExecution();
         MExSession.LogMexAgentFaultEvent(MExDiagnostics.EventLog, context.AsyncException, this.currentAgent.Name, this.eventTopic);
     }
     if (this.completeAsyncAgentCallback != null)
     {
         this.completeAsyncAgentCallback();
     }
     this.Dispatcher.AgentInvokeCompleted(this);
     this.ResumeExecution();
 }
Example #3
0
 public void AgentInvokeCompleted(MExSession session)
 {
     if (this.OnAgentInvokeEnd != null)
     {
         this.OnAgentInvokeEnd(this, session);
     }
 }
Example #4
0
 private void HandleLeakedException(Exception e)
 {
     this.pendingResult.EventTopic      = this.eventTopic;
     this.pendingResult.FaultyAgentName = this.currentAgent.Name;
     this.pendingResult.AsyncException  = e;
     ExTraceGlobals.DispatchTracer.TraceError((long)this.GetHashCode(), this.InstanceNameFormatted + e);
     MExSession.LogMexAgentFaultEvent(MExDiagnostics.EventLog, e, this.currentAgent.Name, this.eventTopic);
 }
        internal void AgentInvokeEndHandler(object dispatcher, MExSession context)
        {
            MExCountersInstance instance = MExCounters.GetInstance(context.CurrentAgent.Name);
            long timestamp = Stopwatch.GetTimestamp();

            instance.AverageAgentDelay.IncrementBy(timestamp - context.BeginInvokeTicks);
            instance.AverageAgentDelayBase.Increment();
            instance.TotalAgentInvocations.Increment();
        }
Example #6
0
        internal void AgentInvokeStartEventHandler(object source, MExSession context)
        {
            this.agentName  = context.ExecutingAgentName;
            this.eventTopic = context.OutstandingEventTopic;
            MailItem mailItem = context.CurrentAgent.Instance.MailItem;

            if (mailItem != null)
            {
                this.internetMessageId = mailItem.InternetMessageId;
            }
            this.agentInvocationTime = DateTime.UtcNow;
        }
Example #7
0
        public IMExSession CreateSession(ICloneableInternal state, string name, Action startAsyncAgentCallback, Action completeAsyncAgentCallback, Func <bool> resumeAgentCallback)
        {
            if (this.runtimeState != 1)
            {
                ExTraceGlobals.InitializeTracer.TraceError <int>((long)this.GetHashCode(), this.InstanceNameFormatted + "invalid state for initialization: {0}", this.runtimeState);
                throw new InvalidOperationException(MExRuntimeStrings.InvalidState);
            }
            MExSession mexSession = new MExSession(this.settings, state, name, this.GetHashCode().ToString(), startAsyncAgentCallback, completeAsyncAgentCallback, resumeAgentCallback);

            this.perfCounters.Subscribe(mexSession.Dispatcher);
            return(mexSession);
        }
Example #8
0
        internal void AgentInvokeEndEventHandler(object source, MExSession context)
        {
            double totalMilliseconds = DateTime.UtcNow.Subtract(this.agentInvocationTime).TotalMilliseconds;

            if (totalMilliseconds > (double)this.executionTimeLimit && this.agentName != null && this.eventTopic != null)
            {
                MExDiagnostics.EventLog.LogEvent(EdgeExtensibilityEventLogConstants.Tuple_MExAgentTooSlow, null, new object[]
                {
                    this.agentName,
                    totalMilliseconds,
                    this.eventTopic,
                    this.internetMessageId ?? "Not Available"
                });
            }
            this.agentName         = null;
            this.eventTopic        = null;
            this.internetMessageId = null;
        }
Example #9
0
        public object Clone()
        {
            int        agentIndex;
            MExSession mexSession;

            lock (this.syncRoot)
            {
                if (this.closed)
                {
                    throw new InvalidOperationException(MExRuntimeStrings.InvalidState);
                }
                agentIndex = this.dispatcher.GetAgentIndex(this.currentAgent);
                mexSession = new MExSession(this.settings, this.hostState, this.name, this.parentName, this.agentsInDefaultOrder, this.publicAgentsInDefaultOrder, this.startAsyncAgentCallback, this.completeAsyncAgentCallback, this.resumeAgentCallback);
                mexSession.SetCloneState(this.eventTopic, agentIndex);
            }
            ExTraceGlobals.DispatchTracer.TraceDebug <string, string, int>((long)this.GetHashCode(), this.InstanceNameFormatted + "{0} cloned on event '{1}' with index {2}", mexSession.GetHashCode().ToString(CultureInfo.InvariantCulture), this.eventTopic, agentIndex);
            return(mexSession);
        }
Example #10
0
        internal void AgentInvokeReturnsHandler(object dispatcher, MExSession context)
        {
            MExCountersInstance instance = MExCounters.GetInstance(context.CurrentAgent.Name);

            if (context.IsAsyncAgent)
            {
                SlidingAverageCounter slidingAverageCounter = this.asynchronousAgentProcessorUsageSlidingCounters[context.CurrentAgent.SequenceNumber];
                slidingAverageCounter.AddValue(context.TotalProcessorTime);
                long rawValue2;
                long rawValue = slidingAverageCounter.CalculateAverageAcrossAllSamples(out rawValue2);
                instance.AverageAgentProcessorUsageAsynchronousInvocations.RawValue = rawValue;
                instance.AsynchronousAgentInvocationSamples.RawValue = rawValue2;
            }
            else
            {
                SlidingAverageCounter slidingAverageCounter2 = this.synchronousAgentProcessorUsageSlidingCounters[context.CurrentAgent.SequenceNumber];
                slidingAverageCounter2.AddValue(context.TotalProcessorTime);
                long rawValue4;
                long rawValue3 = slidingAverageCounter2.CalculateAverageAcrossAllSamples(out rawValue4);
                instance.AverageAgentProcessorUsageSynchronousInvocations.RawValue = rawValue3;
                instance.SynchronousAgentInvocationSamples.RawValue = rawValue4;
            }
            context.CleanupCpuTracker();
        }
Example #11
0
 internal void AgentInvokeStartHandler(object source, MExSession context)
 {
     context.BeginInvokeTicks = Stopwatch.GetTimestamp();
 }
Example #12
0
        public void Invoke(MExSession session)
        {
            string      eventTopic = session.EventTopic;
            AgentRecord agentRecord;

            if (session.CurrentAgent == null)
            {
                agentRecord = this.executionChain;
                if (this.clonedTopic != null && this.clonedExecutionEntry >= 0 && this.clonedTopic == eventTopic)
                {
                    ExTraceGlobals.DispatchTracer.TraceDebug <string, int>((long)this.GetHashCode(), this.InstanceNameFormatted + "restore clone state for '{0}' at index {1}", eventTopic, this.clonedExecutionEntry);
                    for (int i = 0; i < this.clonedExecutionEntry; i++)
                    {
                        if (agentRecord == null)
                        {
                            ExTraceGlobals.DispatchTracer.TraceError <int>((long)this.GetHashCode(), this.InstanceNameFormatted + "restore clone state failed at index {0}", i);
                            break;
                        }
                        agentRecord = agentRecord.Next;
                    }
                }
            }
            else
            {
                agentRecord = session.NextAgent;
            }
            session.IsAsyncAgent = false;
            while (agentRecord != null)
            {
                session.CurrentAgent = agentRecord;
                if (agentRecord.Enabled)
                {
                    Agent instance = agentRecord.Instance;
                    instance.Session     = session;
                    instance.Synchronous = true;
                    instance.EventTopic  = eventTopic;
                    Delegate @delegate = (Delegate)instance.Handlers[eventTopic];
                    if (@delegate != null)
                    {
                        ExTraceGlobals.DispatchTracer.Information <string, string, string>((long)this.GetHashCode(), this.InstanceNameFormatted + "dispatching event '{0}' to {1} ({2})", eventTopic, instance.GetType().FullName, instance.GetHashCode().ToString());
                        session.IsAsyncAgent = false;
                        if (this.OnAgentInvokeStart != null)
                        {
                            this.OnAgentInvokeStart(this, session);
                        }
                        bool flag = true;
                        try
                        {
                            session.StartCpuTracking(instance.Name);
                            instance.Invoke(eventTopic, session.CurrentEventSource, session.CurrentEventArgs);
                            flag = false;
                        }
                        finally
                        {
                            session.StopCpuTracking();
                            if (flag)
                            {
                                session.NextAgent = null;
                                session.ExecutionCompleted();
                                session.CleanupCpuTracker();
                                ExTraceGlobals.DispatchTracer.TraceDebug <string, string>((long)this.GetHashCode(), this.InstanceNameFormatted + "agent {0} crashed during event '{1}'", instance.GetType().FullName, eventTopic);
                            }
                        }
                        ExTraceGlobals.DispatchTracer.TraceDebug <string, string, string>((long)this.GetHashCode(), this.InstanceNameFormatted + "event '{0}' handled by {1} {2}synchronously", eventTopic, instance.GetType().FullName, session.IsAsyncAgent ? "a" : string.Empty);
                        if (this.OnAgentInvokeReturns != null)
                        {
                            this.OnAgentInvokeReturns(this, session);
                        }
                        session.NextAgent = agentRecord.Next;
                        if (session.IsStatusHalt)
                        {
                            this.AgentInvokeCompleted(session);
                            session.NextAgent = null;
                            break;
                        }
                        if (session.IsAsyncAgent)
                        {
                            if (!session.IsSyncInvoke)
                            {
                                ExTraceGlobals.DispatchTracer.Information((long)this.GetHashCode(), this.InstanceNameFormatted + "async agent pending");
                                break;
                            }
                            session.Wait();
                            this.AgentInvokeCompleted(session);
                        }
                        else
                        {
                            this.AgentInvokeCompleted(session);
                        }
                    }
                    else if (this.settings.MonitoringOptions.MessageSnapshotEnabled)
                    {
                        instance.Invoke(eventTopic, session.CurrentEventSource, session.CurrentEventArgs);
                    }
                }
                agentRecord = agentRecord.Next;
            }
            if (agentRecord == null || (session.NextAgent == null && !session.IsAsyncAgent))
            {
                ExTraceGlobals.DispatchTracer.TraceDebug <string>((long)this.GetHashCode(), this.InstanceNameFormatted + "dispatching of event '{0}' completed", eventTopic);
                session.ExecutionCompleted();
            }
        }