Пример #1
0
        void IServiceContext.CreateContext(List <ContextMessage> messageContext)
        {
            this.Messages = new Dictionary <ServiceContextKey, object>();
            messageContext.ForEach(i => this.Messages.Add(i.Key, i.Instance));

            if (this.Messages.ContainsKey(ServiceContextKey.UserLogin))
            {
                this.UserLogin = this.Messages[ServiceContextKey.UserLogin].ToString();
                System.Security.Principal.IPrincipal principal =
                    new System.Security.Principal.GenericPrincipal(new System.Security.Principal.GenericIdentity(this.UserLogin), new string[0]);
                System.Threading.Thread.CurrentPrincipal = principal;

                ServiceCache.SetCache(
                    string.Format("{0}@{1}", System.ServiceModel.OperationContext.Current.SessionId,
                                  ServiceContextKey.UserLogin.GetName()), this.UserLogin);
            }

            lock (_servicesOpen)
            {
                if (System.ServiceModel.OperationContext.Current != null)
                {
                    if (!_servicesOpen.ContainsKey(System.ServiceModel.OperationContext.Current.SessionId))
                    {
                        _servicesOpen.Add(System.ServiceModel.OperationContext.Current.SessionId, this);
                    }
                }
            }
        }
Пример #2
0
        void IServiceContext.DisposeContext()
        {
            this.Messages = null;
            lock (_servicesOpen)
            {
                if (_servicesOpen.ContainsKey(System.ServiceModel.OperationContext.Current.SessionId))
                {
                    _servicesOpen.Remove(System.ServiceModel.OperationContext.Current.SessionId);
                }

                ServiceCache.RemoveCacheCurrentSession();
            }
        }