private static ActivityScope AddActivityScope(ActivityContextState activityContextState, object userState, ActivityType activityType, ActivityEventArgs eventArgs, LocalizedString exceptionString)
        {
            bool          flag          = false;
            bool          flag2         = false;
            ActivityScope activityScope = null;

            if (ActivityContext.IsStarted)
            {
                try
                {
                    throw new ActivityContextException(exceptionString);
                }
                catch (ActivityContextException)
                {
                    flag2 = true;
                }
                if (SingleContext.Singleton.CheckId())
                {
                    ActivityScopeImpl activityScopeImpl = (ActivityScopeImpl)ActivityContext.GetCurrentActivityScope();
                    if (activityScopeImpl != null)
                    {
                        return(new ActivityScope(activityScopeImpl));
                    }
                }
            }
            if (SingleContext.Singleton.LocalId != null && !flag2)
            {
                try
                {
                    throw new ActivityContextException(DiagnosticsResources.ExceptionActivityContextMustBeCleared(DebugContext.GetDebugInfo()));
                }
                catch (ActivityContextException)
                {
                }
            }
            ActivityScope result;

            try
            {
                activityScope              = ActivityScopeImpl.AddActivityScope(activityContextState);
                activityScope.UserState    = userState;
                activityScope.ActivityType = activityType;
                ActivityContext.RaiseEvent(activityScope.ActivityScopeImpl, eventArgs);
                ExTraceGlobals.ActivityContextTracer.TraceDebug <Guid, bool>((long)activityScope.LocalId.GetHashCode(), "ActivityContext.AddActivityScope - ActivityId {0}, (activityContextState != null) = {1}", activityScope.ActivityId, activityContextState != null);
                flag   = true;
                result = activityScope;
            }
            finally
            {
                if (!flag)
                {
                    if (activityScope != null)
                    {
                        activityScope.Dispose();
                    }
                    ActivityContext.ClearThreadScope();
                }
            }
            return(result);
        }
 private static void RolloverGlobalScope()
 {
     try
     {
         ActivityScope activityScope = ActivityContext.Start(null, ActivityType.Global);
         activityScope.Action = "GlobalActivity";
         ActivityContext.inactiveGlobalScope = ActivityContext.globalScope;
         ActivityContext.globalScope         = activityScope;
     }
     finally
     {
         ActivityContext.ClearThreadScope();
     }
 }
 private static void LogGlobalInactive()
 {
     try
     {
         ActivityScope activityScope = ActivityContext.inactiveGlobalScope;
         if (activityScope != null && activityScope.Status == ActivityContextStatus.ActivityStarted)
         {
             ActivityContext.SetThreadScope(activityScope);
             ActivityCoverageReport.OnGlobalActivityEnded(activityScope);
             activityScope.ActivityScopeImpl.RemoveInstrInstances();
             activityScope.End();
             ActivityContext.inactiveGlobalScope = null;
         }
     }
     finally
     {
         ActivityContext.ClearThreadScope();
     }
 }