private SessionManager(SessionManager.SessionData ownerSession)
 {
     this.PrimarySession = ownerSession;
     this.cache          = new Dictionary <ADObjectId, SessionManager.SessionData>(100);
     this.cache.Add(ownerSession.Id, ownerSession);
     this.disposeQueue = new Queue <SessionManager.SessionData>(100);
 }
 private SessionManager.SessionData NewSession(ExchangePrincipal principal)
 {
     if (this.disposeQueue.Count >= 100)
     {
         Globals.ValidatorTracer.TraceDebug <int>((long)this.GetHashCode(), "Session manager exceeded the cache limit of {0}", 100);
         SessionManager.SessionData sessionData = this.disposeQueue.Dequeue();
         this.cache.Remove(sessionData.Id);
         sessionData.Dispose();
     }
     SessionManager.SessionData sessionData2 = SessionManager.OpenSession(principal, this.PrimarySession.ExTimeZone, this.PrimarySession.ClientInfoString);
     this.disposeQueue.Enqueue(sessionData2);
     this.cache.Add(principal.ObjectId, sessionData2);
     return(sessionData2);
 }
        internal override void ValidateMeetings(ref Dictionary <GlobalObjectId, List <Attendee> > organizerRumsSent, Action <long> onItemRepaired)
        {
            bool shouldProcessMailbox = CalendarParticipant.InternalShouldProcessMailbox(this.ExchangePrincipal);

            SessionManager.SessionData sessionData = this.sessionManager[this.ExchangePrincipal];
            foreach (CalendarInstanceContext calendarInstanceContext in base.ItemList.Values)
            {
                string            empty             = string.Empty;
                CalendarLocalItem calendarLocalItem = new CalendarLocalItem(this.ExchangePrincipal, sessionData.Session);
                calendarInstanceContext.ValidationContext.CalendarInstance = calendarLocalItem;
                calendarInstanceContext.ValidationContext.CalendarInstance.ShouldProcessMailbox = shouldProcessMailbox;
                try
                {
                    using (CalendarFolder calendarFolder = CalendarFolder.Bind(sessionData.Session, DefaultFolderType.Calendar, null))
                    {
                        calendarLocalItem.CalendarFolderId = calendarFolder.Id.ObjectId.ProviderLevelItemId;
                        CalendarItemBase calendarItemBase = CalendarQuery.FindMatchingItem(sessionData.Session, calendarFolder, calendarInstanceContext.ValidationContext.BaseItem.CalendarItemType, calendarInstanceContext.ValidationContext.BaseItem.GlobalObjectId.Bytes, ref empty);
                        if (calendarInstanceContext.ValidationContext.OppositeRole == RoleType.Organizer)
                        {
                            if (calendarItemBase != null)
                            {
                                calendarInstanceContext.ValidationContext.OppositeRoleOrganizerIsValid = calendarItemBase.IsOrganizer();
                            }
                            else
                            {
                                calendarInstanceContext.ValidationContext.OppositeRoleOrganizerIsValid = this.IsOrganizerValid(sessionData.Session, calendarInstanceContext);
                            }
                            calendarInstanceContext.ValidationContext.OppositeItem = (calendarInstanceContext.ValidationContext.OppositeRoleOrganizerIsValid ? calendarItemBase : null);
                        }
                        else
                        {
                            calendarInstanceContext.ValidationContext.OppositeItem = calendarItemBase;
                        }
                        calendarInstanceContext.ValidationContext.ErrorString = empty;
                    }
                }
                catch (StorageTransientException ex)
                {
                    string text = string.Format("Could not open item store session or calendar, exception = {0}", ex.GetType());
                    Globals.ConsistencyChecksTracer.TraceError((long)this.GetHashCode(), text);
                    calendarInstanceContext.ValidationContext.CalendarInstance.LoadInconsistency = Inconsistency.CreateInstance(calendarInstanceContext.ValidationContext.OppositeRole, text, CalendarInconsistencyFlag.StorageException, calendarInstanceContext.ValidationContext);
                }
                catch (RecurrenceFormatException ex2)
                {
                    string text2 = string.Format("Could not open item store session or calendar due recurrence format error, exception = {0}", ex2.GetType());
                    Globals.ConsistencyChecksTracer.TraceError((long)this.GetHashCode(), text2);
                    calendarInstanceContext.ValidationContext.CalendarInstance.LoadInconsistency = ((calendarInstanceContext.ValidationContext.OppositeRole == RoleType.Attendee) ? Inconsistency.CreateInstance(calendarInstanceContext.ValidationContext.OppositeRole, text2, CalendarInconsistencyFlag.RecurrenceBlob, calendarInstanceContext.ValidationContext) : null);
                }
                catch (StoragePermanentException ex3)
                {
                    string text3 = string.Format("Could not open item store session or calendar, exception = {0}", ex3.GetType());
                    Globals.ConsistencyChecksTracer.TraceError((long)this.GetHashCode(), text3);
                    calendarInstanceContext.ValidationContext.CalendarInstance.LoadInconsistency = Inconsistency.CreateInstance(calendarInstanceContext.ValidationContext.OppositeRole, text3, CalendarInconsistencyFlag.StorageException, calendarInstanceContext.ValidationContext);
                }
                catch (ArgumentException arg)
                {
                    Globals.ConsistencyChecksTracer.TraceError <RoleType, ArgumentException>((long)this.GetHashCode(), "Could not open item store session or calendar for {0}, exception = {1}", calendarInstanceContext.ValidationContext.OppositeRole, arg);
                }
                finally
                {
                    base.ValidateInstance(calendarInstanceContext, organizerRumsSent, onItemRepaired);
                    if (calendarInstanceContext.ValidationContext.OppositeItem != null)
                    {
                        calendarInstanceContext.ValidationContext.OppositeItem.Dispose();
                        calendarInstanceContext.ValidationContext.OppositeItem = null;
                    }
                }
            }
        }