Esempio n. 1
0
 internal object ResolveService(Type t)
 {
     return(DataServiceScopeManager.GetService(t));
 }
Esempio n. 2
0
            public void WrapperAction(TSource source)
            {
                var originalHttpContext = HttpContext.Current;

                bool dataScopePushed     = false;
                bool languageScopePushed = false;

                var currentThread = System.Threading.Thread.CurrentThread;

                CultureInfo originalCulture   = currentThread.CurrentCulture;
                CultureInfo originalUiCulture = currentThread.CurrentUICulture;
                var         originalPrincipal = Thread.CurrentPrincipal;

                using (ThreadDataManager.Initialize(_parentData))
                {
                    try
                    {
                        DataScopeManager.EnterThreadLocal();

                        if (DataScopeManager.CurrentDataScope != _parentThreadDataScope)
                        {
                            DataScopeManager.PushDataScope(_parentThreadDataScope);
                            dataScopePushed = true;
                        }

                        LocalizationScopeManager.EnterThreadLocal();

                        if (LocalizationScopeManager.CurrentLocalizationScope != _parentThreadLocale)
                        {
                            LocalizationScopeManager.PushLocalizationScope(_parentThreadLocale);
                            languageScopePushed = true;
                        }

                        DataServiceScopeManager.EnterThreadLocal();

                        HttpContext.Current = _parentThreadHttpContext;

                        currentThread.CurrentCulture   = _parentThreadCulture;
                        currentThread.CurrentUICulture = _parentThreadUiCulture;
                        Thread.CurrentPrincipal        = _parentThreadPrincipal;

                        try
                        {
                            _body(source);
                        }
                        catch (ThreadAbortException threadAbort)
                        {
                            object state = threadAbort.ExceptionState;

                            if (state != null)
                            {
                                Thread.ResetAbort();

                                // Throwing another exception because Thread.ResetAbort clears ThreadAbortException.ExceptionState
                                throw new RethrowableThreadAbortException(state);
                            }
                        }
                    }
                    finally
                    {
                        currentThread.CurrentCulture   = originalCulture;
                        currentThread.CurrentUICulture = originalUiCulture;
                        Thread.CurrentPrincipal        = originalPrincipal;

                        HttpContext.Current = originalHttpContext;

                        if (dataScopePushed)
                        {
                            DataScopeManager.PopDataScope();
                        }
                        if (languageScopePushed)
                        {
                            LocalizationScopeManager.PopLocalizationScope();
                        }

                        DataScopeManager.ExitThreadLocal();
                        LocalizationScopeManager.ExitThreadLocal();
                        DataServiceScopeManager.ExitThreadLocal();
                    }
                }
            }