Exemplo n.º 1
0
        internal static CalendarParticipant Create(UserObject userObject, ExDateTime validateFrom, ExDateTime validateUntil, SessionManager sessionManager)
        {
            ExchangePrincipal exchangePrincipal = userObject.ExchangePrincipal;

            if (exchangePrincipal == null)
            {
                return(new CalendarExternalParticipant(userObject, validateFrom, validateUntil));
            }
            try
            {
                if (exchangePrincipal.MailboxInfo.Location.ServerVersion < Globals.E15Version)
                {
                    Globals.ConsistencyChecksTracer.TraceDebug(0L, "Remote mailbox is on a pre-E15 server, using XSO to access it.");
                    return(new CalendarLocalParticipant(userObject, validateFrom, validateUntil, sessionManager));
                }
                bool flag = StringComparer.OrdinalIgnoreCase.Equals(LocalServerCache.LocalServerFqdn, exchangePrincipal.MailboxInfo.Location.ServerFqdn);
                if (flag && !Configuration.CalendarRepairForceEwsUsage)
                {
                    Globals.ConsistencyChecksTracer.TraceDebug(0L, "Local server is a best fit to service the remote mailbox.");
                    return(new CalendarLocalParticipant(userObject, validateFrom, validateUntil, sessionManager));
                }
                if (Configuration.CalendarRepairOppositeMailboxEwsEnabled)
                {
                    Uri backEndWebServicesUrl = CalendarParticipant.GetBackEndWebServicesUrl(exchangePrincipal.MailboxInfo);
                    if (backEndWebServicesUrl != null)
                    {
                        Globals.ConsistencyChecksTracer.TraceDebug <Uri>(0L, "Using {0} to access the remote mailbox.", backEndWebServicesUrl);
                        if (CalendarItemBase.IsTenantToBeFixed(sessionManager.PrimarySession.Session))
                        {
                            return(new CalendarRemoteParticipant2(userObject, validateFrom, validateUntil, sessionManager.PrimarySession.Session, backEndWebServicesUrl));
                        }
                        return(new CalendarRemoteParticipant(userObject, validateFrom, validateUntil, sessionManager.PrimarySession.Session, backEndWebServicesUrl));
                    }
                }
                else
                {
                    Globals.ConsistencyChecksTracer.TraceDebug <ExchangePrincipal>(0L, "Unable to access the remote mailbox {0}.", exchangePrincipal);
                }
            }
            catch (WrongServerException exception)
            {
                CalendarParticipant.HandleException(exception, exchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString());
            }
            return(null);
        }
        internal override void ValidateMeetings(ref Dictionary <GlobalObjectId, List <Attendee> > organizerRumsSent, Action <long> onItemRepaired)
        {
            bool shouldProcessMailbox = CalendarParticipant.InternalShouldProcessMailbox(this.ExchangePrincipal);

            try
            {
                List <SearchExpressionType> list = new List <SearchExpressionType>();
                foreach (CalendarInstanceContext calendarInstanceContext in base.ItemList.Values)
                {
                    calendarInstanceContext.ValidationContext.CalendarInstance = new CalendarRemoteItem(this.ExchangePrincipal, this.binding);
                    calendarInstanceContext.ValidationContext.CalendarInstance.ShouldProcessMailbox = shouldProcessMailbox;
                    GlobalObjectId       globalObjectId = calendarInstanceContext.ValidationContext.BaseItem.GlobalObjectId;
                    string               value          = Convert.ToBase64String(globalObjectId.CleanGlobalObjectIdBytes);
                    SearchExpressionType item           = new IsEqualToType
                    {
                        Item = CalendarItemFields.CleanGlobalObjectIdProp,
                        FieldURIOrConstant = new FieldURIOrConstantType
                        {
                            Item = new ConstantValueType
                            {
                                Value = value
                            }
                        }
                    };
                    list.Add(item);
                }
                ItemType[] remoteCalendarItems = this.GetRemoteCalendarItems(list);
                if (remoteCalendarItems != null)
                {
                    Dictionary <GlobalObjectId, CalendarItemType> dictionary = new Dictionary <GlobalObjectId, CalendarItemType>();
                    foreach (ItemType itemType in remoteCalendarItems)
                    {
                        CalendarItemType calendarItemType = itemType as CalendarItemType;
                        GlobalObjectId   globalObjectId2  = CalendarItemFields.GetGlobalObjectId(calendarItemType);
                        dictionary.Add(globalObjectId2, calendarItemType);
                    }
                    foreach (KeyValuePair <GlobalObjectId, CalendarInstanceContext> keyValuePair in base.ItemList)
                    {
                        if (dictionary.ContainsKey(keyValuePair.Key))
                        {
                            CalendarItemType        remoteItem = dictionary[keyValuePair.Key];
                            CalendarInstanceContext value2     = keyValuePair.Value;
                            try
                            {
                                try
                                {
                                    CalendarItemBase calendarItemBase = CalendarItem.Create(this.localSession, this.localSession.GetDefaultFolderId(DefaultFolderType.Calendar));
                                    Globals.ConsistencyChecksTracer.TraceDebug((long)this.GetHashCode(), "Converting the EWS item to XSO.");
                                    this.calendarConverter.ConvertItem(calendarItemBase, remoteItem);
                                    value2.ValidationContext.OppositeItem = calendarItemBase;
                                }
                                catch (FormatException ex)
                                {
                                    string text = string.Format("Could not convert the remote item, exception = {0}", ex.GetType());
                                    Globals.ConsistencyChecksTracer.TraceError((long)this.GetHashCode(), text);
                                    value2.ValidationContext.CalendarInstance.LoadInconsistency = Inconsistency.CreateInstance(value2.ValidationContext.OppositeRole, text, CalendarInconsistencyFlag.StorageException, value2.ValidationContext);
                                }
                                catch (CorruptDataException ex2)
                                {
                                    string text2 = string.Format("Could not convert the remote item, exception = {0}", ex2.GetType());
                                    Globals.ConsistencyChecksTracer.TraceError((long)this.GetHashCode(), text2);
                                    value2.ValidationContext.CalendarInstance.LoadInconsistency = Inconsistency.CreateInstance(value2.ValidationContext.OppositeRole, text2, CalendarInconsistencyFlag.StorageException, value2.ValidationContext);
                                }
                                catch (StorageTransientException ex3)
                                {
                                    string text3 = string.Format("Could not convert the remote item, exception = {0}", ex3.GetType());
                                    Globals.ConsistencyChecksTracer.TraceError((long)this.GetHashCode(), text3);
                                    value2.ValidationContext.CalendarInstance.LoadInconsistency = Inconsistency.CreateInstance(value2.ValidationContext.OppositeRole, text3, CalendarInconsistencyFlag.StorageException, value2.ValidationContext);
                                }
                                continue;
                            }
                            finally
                            {
                                base.ValidateInstance(value2, organizerRumsSent, onItemRepaired);
                                if (value2.ValidationContext.OppositeItem != null)
                                {
                                    value2.ValidationContext.OppositeItem.Dispose();
                                    value2.ValidationContext.OppositeItem = null;
                                }
                            }
                        }
                        Globals.ConsistencyChecksTracer.TraceDebug((long)this.GetHashCode(), "GetItem didn't return an expected GlobalObjectId.");
                    }
                }
                foreach (CalendarInstanceContext calendarInstanceContext2 in base.ItemList.Values)
                {
                    if (!calendarInstanceContext2.IsValidationDone)
                    {
                        if (calendarInstanceContext2.ValidationContext.OppositeRole == RoleType.Organizer && calendarInstanceContext2.ValidationContext.OppositeItem == null)
                        {
                            calendarInstanceContext2.ValidationContext.OppositeRoleOrganizerIsValid = true;
                        }
                        base.ValidateInstance(calendarInstanceContext2, organizerRumsSent, onItemRepaired);
                    }
                }
            }
            catch (ProtocolViolationException exception)
            {
                this.HandleRemoteException(exception);
            }
            catch (SecurityException exception2)
            {
                this.HandleRemoteException(exception2);
            }
            catch (ArgumentException exception3)
            {
                this.HandleRemoteException(exception3);
            }
            catch (InvalidOperationException exception4)
            {
                this.HandleRemoteException(exception4);
            }
            catch (NotSupportedException exception5)
            {
                this.HandleRemoteException(exception5);
            }
            catch (XmlException exception6)
            {
                this.HandleRemoteException(exception6);
            }
            catch (XPathException exception7)
            {
                this.HandleRemoteException(exception7);
            }
            catch (SoapException exception8)
            {
                this.HandleRemoteException(exception8);
            }
            catch (IOException exception9)
            {
                this.HandleRemoteException(exception9);
            }
        }
        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;
                    }
                }
            }
        }