示例#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>
        ///     Sets the context data within the logical thread.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <remarks></remarks>
        public static void SetContext(RequestContext context)
        {
            // Set the default request context data in the logical context
            var contextData = new RequestContextData(context.Identity, context.Tenant, context.Culture, context.SecondaryIdentity);

            SetContext(contextData);
        }
示例#3
0
        /// <summary>
        ///		Sets the context.
        /// </summary>
        /// <param name="identity">The identity.</param>
        /// <param name="tenant">The tenant.</param>
        /// <param name="culture">The culture.</param>
        /// <param name="timeZone">The time zone.</param>
        /// <param name="secondaryIdentity">The secondary identity.</param>
        public static void SetContext(IdentityInfo identity, TenantInfo tenant, string culture, string timeZone, IdentityInfo secondaryIdentity = null)
        {
            // Set the default request context data in the logical context
            var contextData = new RequestContextData(identity, tenant, culture, timeZone, secondaryIdentity);

            SetContext(contextData);
        }
示例#4
0
        /// <summary>
        ///     Sets the context data within the logical thread.
        /// </summary>
        /// <param name="identity">The identity.</param>
        /// <param name="tenant">The tenant.</param>
        /// <param name="culture">The culture.</param>
        public static void SetContext(IdentityInfo identity, TenantInfo tenant, string culture)
        {
            // Set the default request context data in the logical context
            var contextData = new RequestContextData(identity, tenant, culture);

            SetContext(contextData);
        }
示例#5
0
 /// <summary>
 ///     Sets the context only if it refers to an actual user.
 /// </summary>
 /// <param name="contextData">The context data.</param>
 internal static void SetContext(RequestContextData contextData)
 {
     if (contextData != null &&
         contextData.Identity != null &&
         contextData.Identity.Id > 0)
     {
         // Set the context if it refers to an actual user
         CallContext.SetData(ActualUserContextKey, contextData);
     }
 }
示例#6
0
        /// <summary>
        ///     Sets the tenant administrator context data within the logical thread.
        /// </summary>
        /// <param name="tenantId">
        ///     An ID identifying the tenant.
        /// </param>
        /// <param name="culture">
        ///     A string containing the culture.
        /// </param>
        private static void SetTenantAdministratorContext(long tenantId, string culture)
        {
            var tenant   = new TenantInfo(tenantId);
            var identity = new IdentityInfo(0, SpecialStrings.TenantAdministratorUser);

            /////
            // Set the default request context data in the logical context
            /////
            var contextData = new RequestContextData(identity, tenant, String.IsNullOrEmpty(culture) ? CultureHelper.GetUiThreadCulture(CultureType.Neutral) : culture);

            /////
            // Set the request context data
            /////
            SetContext(contextData);
        }
示例#7
0
        /// <summary>
        ///     Sets the system administrator context data within the logical thread.
        /// </summary>
        /// <param name="culture">
        ///     A string containing the culture.
        /// </param>
        internal static void SetSystemAdministratorContext(string culture)
        {
            var tenantInfo = new TenantInfo(0)
            {
                Name = SpecialStrings.GlobalTenant
            };
            var identityInfo = new IdentityInfo(0, SpecialStrings.SystemAdministratorUser);

            // Note that trigger depth is not propagated into the admin context. It will have it's own trigger depth.
            var contextData = new RequestContextData(identityInfo, tenantInfo, String.IsNullOrEmpty(culture) ? CultureHelper.GetUiThreadCulture(CultureType.Neutral) : culture);

            /////
            // Set the request context data
            /////
            SetContext(contextData);
        }
示例#8
0
 /// <summary>
 ///     Initializes a new instance of the CustomContext class.
 /// </summary>
 /// <param name="contextData">
 ///     Context data.
 /// </param>
 public static CustomContext SetContext(RequestContextData contextData)
 {
     return(new CustomContext(contextData));
 }
示例#9
0
 /// <summary>
 ///     Initializes a new instance of the CustomContext class.
 /// </summary>
 /// <param name="contextData">
 ///     Context data.
 /// </param>
 public CustomContext(RequestContextData contextData)
     : base(() => RequestContext.SetContext(contextData))
 {
 }
示例#10
0
 /// <summary>
 ///     Initializes a new instance of the RequestContext class.
 /// </summary>
 public RequestContext(RequestContextData contextData)
 {
     _contextData = contextData;
 }