示例#1
0
        /// <summary>
        ///     Sets the context data within the logical thread.
        /// </summary>
        /// <param name="contextData">The context data.</param>
        /// <remarks></remarks>
        public static void SetContext(RequestContextData contextData)
        {
            long tenantId   = -1;
            var  tenantName = string.Empty;

            if (contextData != null &&
                contextData.Tenant != null)
            {
                var tenant = contextData.Tenant;
                tenantId   = tenant.Id;
                tenantName = tenant.HaveName ? tenant.Name : TenantHelper.GetTenantName(tenantId);                  // don't trigger a name fetch
            }

            var userName = string.Empty;

            if (contextData != null &&
                contextData.Identity != null)
            {
                userName = contextData.Identity.Name;
            }

            // Set the diagnostics context for logging purposes
            DiagnosticsRequestContext.SetContext(tenantId, tenantName, userName);

            // Set the default request context data in the logical context
            CallContext.SetData(ContextKey, contextData);

            ActualUserRequestContext.SetContext(contextData);
        }
示例#2
0
        /// <summary>
        ///     Frees the request data from the logical thread.
        /// </summary>
        public static void FreeContext( )
        {
            DiagnosticsRequestContext.FreeContext( );

            // Free the request context data from the logical context
            CallContext.FreeNamedDataSlot(ContextKey);

            ActualUserRequestContext.FreeContext();
        }