protected override void OnBeforeSend()
        {
            base.CoreItem.SaveRecipients();
            CheckRecipientsResults checkRecipientsResults = this.CheckRecipients();

            if (checkRecipientsResults.InvalidRecipients != null && checkRecipientsResults.InvalidRecipients.Length > 0)
            {
                throw new InvalidSharingRecipientsException(checkRecipientsResults.InvalidRecipients, new RecipientNotSupportedByAnyProviderException());
            }
            this.PerformInvitation();
            this.SharingContext.SerializeToMessage(this);
            this.AddBodyPrefix(this.CreateBodyPrefix());
            this.isSending = true;
            if (this.SharingMessageType.IsResponseToRequest)
            {
                SharingMessageItem sharingMessageItem = this.TryGetOriginalMessage();
                if (sharingMessageItem != null)
                {
                    try
                    {
                        SharingResponseType responseTypeFromMessageType = SharingMessageItem.GetResponseTypeFromMessageType(this.SharingMessageType);
                        sharingMessageItem.PostResponded(responseTypeFromMessageType);
                    }
                    finally
                    {
                        sharingMessageItem.Dispose();
                    }
                }
            }
            this[MessageItemSchema.RecipientReassignmentProhibited] = !this.IsPublishing;
            base.OnBeforeSend();
        }
 internal SharingProvider GetTargetSharingProvider(ADRecipient mailboxOwner)
 {
     Util.ThrowOnNullArgument(mailboxOwner, "mailboxOwner");
     if (this.AvailableSharingProviders.Keys.Count == 1)
     {
         using (Dictionary <SharingProvider, CheckRecipientsResults> .KeyCollection.Enumerator enumerator = this.AvailableSharingProviders.Keys.GetEnumerator())
         {
             if (enumerator.MoveNext())
             {
                 SharingProvider sharingProvider = enumerator.Current;
                 ExTraceGlobals.SharingTracer.TraceDebug <ADRecipient, SharingProvider>((long)this.GetHashCode(), "{0}: Found target provider {1} for current user.", mailboxOwner, sharingProvider);
                 return(sharingProvider);
             }
         }
     }
     foreach (KeyValuePair <SharingProvider, CheckRecipientsResults> keyValuePair in this.AvailableSharingProviders)
     {
         SharingProvider        key   = keyValuePair.Key;
         CheckRecipientsResults value = keyValuePair.Value;
         if (value != null && mailboxOwner.IsAnyAddressMatched(ValidRecipient.ConvertToStringArray(value.ValidRecipients)))
         {
             ExTraceGlobals.SharingTracer.TraceDebug <ADRecipient, SharingProvider>((long)this.GetHashCode(), "{0}: Found target provider {1} for current user.", mailboxOwner, key);
             return(key);
         }
     }
     ExTraceGlobals.SharingTracer.TraceError <ADRecipient>((long)this.GetHashCode(), "{0}: No available provider is found for this user.", mailboxOwner);
     return(null);
 }
Beispiel #3
0
        internal CheckRecipientsResults CheckRecipients(ADRecipient mailboxOwner, SharingContext context, string[] recipients)
        {
            Util.ThrowOnNullArgument(context, "context");
            CheckRecipientsResults checkRecipientsResults = this.sharingProviderHandler.CheckRecipients(mailboxOwner, recipients);

            context.AvailableSharingProviders[this] = checkRecipientsResults;
            return(checkRecipientsResults);
        }
        private bool IsProviderEffective(SharingProvider provider)
        {
            if (!this.AvailableSharingProviders.ContainsKey(provider))
            {
                return(false);
            }
            CheckRecipientsResults checkRecipientsResults = this.AvailableSharingProviders[provider];

            return(checkRecipientsResults != null && checkRecipientsResults.ValidRecipients != null && checkRecipientsResults.ValidRecipients.Length != 0);
        }
        private CheckRecipientsResults CheckRecipients()
        {
            List <string> list  = new List <string>(base.Recipients.Count);
            List <string> list2 = new List <string>(base.Recipients.Count);

            foreach (Recipient recipient in base.Recipients)
            {
                string valueOrDefault = recipient.GetValueOrDefault <string>(ParticipantSchema.SmtpAddress, string.Empty);
                if (!string.IsNullOrEmpty(valueOrDefault))
                {
                    list2.Add(valueOrDefault);
                }
                else
                {
                    list.Add(recipient.Participant.EmailAddress);
                }
            }
            List <ValidRecipient> list3 = new List <ValidRecipient>(list2.Count);

            string[] array = list2.ToArray();
            List <SharingProvider> list4 = new List <SharingProvider>(this.SharingContext.AvailableSharingProviders.Keys);

            foreach (SharingProvider sharingProvider in list4)
            {
                if (array == null || array.Length == 0)
                {
                    break;
                }
                CheckRecipientsResults checkRecipientsResults;
                if (this.ForceSharingProvider != null)
                {
                    if (sharingProvider == this.ForceSharingProvider)
                    {
                        checkRecipientsResults = new CheckRecipientsResults(ValidRecipient.ConvertFromStringArray(array));
                    }
                    else
                    {
                        checkRecipientsResults = new CheckRecipientsResults(array);
                    }
                    this.SharingContext.AvailableSharingProviders[sharingProvider] = checkRecipientsResults;
                }
                else
                {
                    checkRecipientsResults = sharingProvider.CheckRecipients(this.MailboxOwner, this.SharingContext, array);
                }
                list3.AddRange(checkRecipientsResults.ValidRecipients);
                array = checkRecipientsResults.InvalidRecipients;
            }
            list.AddRange(array);
            return(new CheckRecipientsResults(list3.ToArray(), list.ToArray()));
        }
Beispiel #6
0
        private SharingMessageAction CreateRequestAction()
        {
            List <SharingMessageProvider> list = new List <SharingMessageProvider>(this.context.AvailableSharingProviders.Count);

            foreach (KeyValuePair <SharingProvider, CheckRecipientsResults> keyValuePair in this.context.AvailableSharingProviders)
            {
                SharingProvider        key   = keyValuePair.Key;
                CheckRecipientsResults value = keyValuePair.Value;
                if (key != SharingProvider.SharingProviderPublish && value != null && value.ValidRecipients != null && value.ValidRecipients.Length > 0)
                {
                    SharingMessageProvider sharingMessageProvider = key.CreateSharingMessageProvider();
                    sharingMessageProvider.TargetRecipients = value.TargetRecipients;
                    list.Add(sharingMessageProvider);
                }
            }
            return(new SharingMessageAction
            {
                Providers = list.ToArray()
            });
        }
Beispiel #7
0
        private SharingMessageAction CreateInvitationAction()
        {
            List <SharingMessageProvider> list = new List <SharingMessageProvider>(this.context.AvailableSharingProviders.Count);

            foreach (KeyValuePair <SharingProvider, CheckRecipientsResults> keyValuePair in this.context.AvailableSharingProviders)
            {
                SharingProvider        key   = keyValuePair.Key;
                CheckRecipientsResults value = keyValuePair.Value;
                if (value != null && value.ValidRecipients != null && value.ValidRecipients.Length > 0)
                {
                    SharingMessageProvider sharingMessageProvider = key.CreateSharingMessageProvider(this.context);
                    sharingMessageProvider.TargetRecipients = value.TargetRecipients;
                    list.Add(sharingMessageProvider);
                }
            }
            return(new SharingMessageAction
            {
                Title = (this.context.IsPrimary ? null : this.context.FolderName),
                Providers = list.ToArray()
            });
        }
        private void PerformInvitation()
        {
            Dictionary <SharingProvider, ValidRecipient[]> dictionary = new Dictionary <SharingProvider, ValidRecipient[]>();
            List <ValidRecipient> list = new List <ValidRecipient>();
            SharingProvider       fallbackSharingProvider = this.SharingContext.FallbackSharingProvider;

            using (FolderPermissionContext current = FolderPermissionContext.GetCurrent(this.MailboxSession, this.SharingContext))
            {
                bool flag = false;
                try
                {
                    foreach (KeyValuePair <SharingProvider, CheckRecipientsResults> keyValuePair in this.SharingContext.AvailableSharingProviders)
                    {
                        SharingProvider        key   = keyValuePair.Key;
                        CheckRecipientsResults value = keyValuePair.Value;
                        if (this.FallbackEnabled && key == fallbackSharingProvider)
                        {
                            if (value != null)
                            {
                                list.AddRange(value.ValidRecipients);
                            }
                        }
                        else if (value != null)
                        {
                            PerformInvitationResults performInvitationResults = key.PerformInvitation(this.MailboxSession, this.SharingContext, value.ValidRecipients, this.FrontEndLocator);
                            ExTraceGlobals.SharingTracer.TraceDebug <IExchangePrincipal, SharingProvider, PerformInvitationResults>((long)this.GetHashCode(), "{0}: Performed invitation by provider {1}. Result = {2}", this.MailboxSession.MailboxOwner, key, performInvitationResults);
                            if (performInvitationResults.Result == PerformInvitationResultType.Failed || performInvitationResults.Result == PerformInvitationResultType.PartiallySuccess)
                            {
                                if (!this.FallbackEnabled)
                                {
                                    StoreObjectId folderId = this.SharingContext.FolderId;
                                    InvalidSharingRecipientsResolution invalidSharingRecipientsResolution;
                                    if (!this.CanUseFallback)
                                    {
                                        invalidSharingRecipientsResolution = new InvalidSharingRecipientsResolution(folderId);
                                    }
                                    else
                                    {
                                        using (Folder folder = Folder.Bind(this.MailboxSession, folderId))
                                        {
                                            this.SharingContext.PopulateUrls(folder);
                                        }
                                        invalidSharingRecipientsResolution = new InvalidSharingRecipientsResolution(this.BrowseUrl, this.ICalUrl);
                                    }
                                    ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, InvalidSharingRecipientsResolution>((long)this.GetHashCode(), "{0}: No fall back for these invalid recipients. Resolution = {1}", this.MailboxSession.MailboxOwner, invalidSharingRecipientsResolution);
                                    throw new InvalidSharingRecipientsException(performInvitationResults.FailedRecipients, invalidSharingRecipientsResolution);
                                }
                                ValidRecipient[] array = Array.ConvertAll <InvalidRecipient, ValidRecipient>(performInvitationResults.FailedRecipients, (InvalidRecipient invalidRecipient) => new ValidRecipient(invalidRecipient.SmtpAddress, null));
                                ExTraceGlobals.SharingTracer.TraceDebug <IExchangePrincipal, SharingProvider, int>((long)this.GetHashCode(), "{0}: Fall back on provider {1} for these {2} failed recipients.", this.MailboxSession.MailboxOwner, fallbackSharingProvider, array.Length);
                                list.AddRange(array);
                                dictionary.Add(key, performInvitationResults.SucceededRecipients);
                            }
                        }
                    }
                    if (this.FallbackEnabled)
                    {
                        foreach (KeyValuePair <SharingProvider, ValidRecipient[]> keyValuePair2 in dictionary)
                        {
                            SharingProvider  key2   = keyValuePair2.Key;
                            ValidRecipient[] value2 = keyValuePair2.Value;
                            this.SharingContext.AvailableSharingProviders[key2] = new CheckRecipientsResults(value2);
                        }
                        this.SharingContext.AvailableSharingProviders[fallbackSharingProvider] = new CheckRecipientsResults(list.ToArray());
                        PerformInvitationResults performInvitationResults2 = fallbackSharingProvider.PerformInvitation(this.MailboxSession, this.SharingContext, list.ToArray(), this.FrontEndLocator);
                        ExTraceGlobals.SharingTracer.TraceDebug <IExchangePrincipal, SharingProvider, PerformInvitationResults>((long)this.GetHashCode(), "{0}: Performed invitation by fallback provider {1}. Result = {2}", this.MailboxSession.MailboxOwner, fallbackSharingProvider, performInvitationResults2);
                        if (performInvitationResults2.Result == PerformInvitationResultType.Failed || performInvitationResults2.Result == PerformInvitationResultType.PartiallySuccess)
                        {
                            throw new InvalidOperationException("The fallback provider should never fail.");
                        }
                    }
                    flag = true;
                }
                finally
                {
                    if (!flag)
                    {
                        current.Disable();
                    }
                }
            }
        }