public static void FinalizeThroughHttpContext()
        {
            if (_threadDataManagerData != null)
            {
                _threadDataManagerData = null;
                Log.LogError(LogTitle, "Thread data hasn't been disposed after request execution. Resource leaks are possible.");
            }


            var httpContext = HttpContext.Current;

            // Checking if ThreadData was initialized though HttpContext
            var currentData = httpContext.Items[c_HttpContextItemsId] as IDisposable;

            if (currentData != null)
            {
                httpContext.Items[c_HttpContextItemsId] = null;
                try
                {
                    currentData.Dispose();
                }
                catch (Exception e)
                {
                    Log.LogError(LogTitle, e);
                }
            }
        }
Esempio n. 2
0
        public static IDisposable Initialize(ThreadDataManagerData parentThreadData)
        {
            if (parentThreadData != null)
            {
                parentThreadData.CheckNotDisposed();
            }

            return(new ThreadDataManagerScope(new ThreadDataManagerData(parentThreadData), true));
        }
        public static void StartThread(Thread thread)
        {
            ThreadDataManagerData data = ThreadDataManager.Current;

            StartThreadData startThreadData = new StartThreadData
            {
                Data = data,
            };

            thread.Start(startThreadData);
        }
        public static void StartThread(Thread thread, object parameter)
        {
            ThreadDataManagerData data = ThreadDataManager.Current;

            StartThreadData startThreadData = new StartThreadData
            {
                Data      = data,
                Parameter = parameter
            };

            thread.Start(startThreadData);
        }
            public ThreadDataManagerScope(ThreadDataManagerData newCurrentData, bool disposeData)
            {
                Verify.ArgumentNotNull(newCurrentData, "newCurrentData");
                newCurrentData.CheckNotDisposed();

                _threadData = newCurrentData;

                // NOTE: We shouldn't take value from 'Current' property, since it may return it from HttpContext
                _threadDataValueToBeRestored = _threadDataManagerData;
                _threadDataManagerData       = newCurrentData;

                _disposeData = disposeData;
            }
        public static ThreadDataManagerData GetCurrentNotNull()
        {
            ThreadDataManagerData current = Current;

            Verify.That(current != null,
                        @"ThreadDataManager hasn't been initialized in the current thread. You probably have forgotten to use Composite.Core.Threading.ThreadDataManager.EnsureInitialize() call on a custom created thread.
Example of usage:
using(Composite.Core.Threading.ThreadDataManager.EnsureInitialize())
{
  // Code that works with C1 data layer goes here
  .....
}");
            current.CheckNotDisposed();

            return(current);
        }
        public static void InitializeThroughHttpContext()
        {
            var httpContext = HttpContext.Current;

            Verify.IsNotNull(httpContext, "This can only be called from a thread started with a current http context");

            if (httpContext.Items[c_HttpContextItemsId] == null)
            {
                if (_threadDataManagerData != null)
                {
                    Log.LogCritical(LogTitle, "ThreadData has already been initialized in the current thread. It's been reset to NULL value, resource leaks are possible.");
                    _threadDataManagerData = null;
                }

                var threadData = new ThreadDataManagerData();
                httpContext.Items[c_HttpContextItemsId] = threadData;
            }
        }
        /// <summary>
        /// This method will find the first one that contains the key and return the value
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool TryGetParentValue(object key, out object value)
        {
            CheckNotDisposed();

            ThreadDataManagerData current = this;

            while ((current != null) && (current.Data.ContainsKey(key) == false))
            {
                current = current.Parent;
            }

            if (current == null)
            {
                value = null;
                return(false);
            }

            value = current.Data[key];
            return(true);
        }
Esempio n. 9
0
        public static void InitializeThroughHttpContext(bool forceUserValidation)
        {
            var httpContext = HttpContext.Current;

            Verify.IsNotNull(httpContext, "This can only be called from a thread started with a current http context");

            if (httpContext.Items[c_HttpContextItemsId] == null)
            {
                if (_threadDataManagerData != null)
                {
                    Log.LogCritical(LogTitle, "ThreadData has already been initialized in the current thread. It's been reset to NULL value, resource leaks are possible.");
                    _threadDataManagerData = null;
                }

                var threadData = new ThreadDataManagerData();
                httpContext.Items[c_HttpContextItemsId] = threadData;
            }

            if (forceUserValidation)
            {
                string username = LoginSessionStorePluginFacade.StoredUsername;
            }
        }
 /// <exclude />
 public ThreadDataManagerData(ThreadDataManagerData parentThreadData)
 {
     this.Parent = parentThreadData;
     this.Data   = new Hashtable <object, object>();
 }
Esempio n. 11
0
 /// <exclude />
 public ThreadDataManagerData(ThreadDataManagerData parentThreadData)
 {
     this.Parent = parentThreadData;
     this.Data = new Hashtable<object, object>();
 }
Esempio n. 12
0
            public ThreadDataManagerScope(ThreadDataManagerData newCurrentData, bool disposeData)
            {
                Verify.ArgumentNotNull(newCurrentData, "newCurrentData");
                newCurrentData.CheckNotDisposed();

                _threadData = newCurrentData;

                // NOTE: We shouldn't take value from 'Current' property, since it may return it from HttpContext
                _threadDataValueToBeRestored = _threadDataManagerData;
                _threadDataManagerData = newCurrentData;

                _disposeData = disposeData;
            }
Esempio n. 13
0
        public static void FinalizeThroughHttpContext()
        {
            if(_threadDataManagerData != null)
            {
                _threadDataManagerData = null;
                Log.LogError(LogTitle, "Thread data hasn't been disposed after request execution. Resource leaks are possible.");
            }


            var httpContext = HttpContext.Current;

            // Checking if ThreadData was initialized though HttpContext
            var currentData = httpContext.Items[c_HttpContextItemsId] as IDisposable;
            if (currentData != null)
            {
                httpContext.Items[c_HttpContextItemsId] = null;
                try
                {
                    currentData.Dispose();
                }
                catch(Exception e)
                {
                    Log.LogError(LogTitle, e);
                }
            }
        }
Esempio n. 14
0
        public static void InitializeThroughHttpContext(bool forceUserValidation)
        {
            var httpContext = HttpContext.Current;
            Verify.IsNotNull(httpContext, "This can only be called from a thread started with a current http context");

            if (httpContext.Items[c_HttpContextItemsId] == null)
            {
                if (_threadDataManagerData != null)
                {
                    Log.LogCritical(LogTitle, "ThreadData has already been initialized in the current thread. It's been reset to NULL value, resource leaks are possible.");
                    _threadDataManagerData = null;
                }

                var threadData = new ThreadDataManagerData();
                httpContext.Items[c_HttpContextItemsId] = threadData;
            }

            if (forceUserValidation)
            {
                string username = LoginSessionStorePluginFacade.StoredUsername;
            }
        }
Esempio n. 15
0
        public static IDisposable Initialize(ThreadDataManagerData parentThreadData)
        {
            if(parentThreadData != null)
            {
                parentThreadData.CheckNotDisposed();
            }

            return new ThreadDataManagerScope(new ThreadDataManagerData(parentThreadData), true);
        }
Esempio n. 16
0
        public static void InitializeThroughHttpContext()
        {
            var httpContext = HttpContext.Current;
            Verify.IsNotNull(httpContext, "This can only be called from a thread started with a current http context");

            if (httpContext.Items[c_HttpContextItemsId] == null)
            {
                if (_threadDataManagerData != null)
                {
                    Log.LogCritical(LogTitle, "ThreadData has already been initialized in the current thread. It's been reset to NULL value, resource leaks are possible.");
                    _threadDataManagerData = null;
                }

                var threadData = new ThreadDataManagerData();
                httpContext.Items[c_HttpContextItemsId] = threadData;
            }
        }