private bool TryGetRacAndClc()
 {
     this.result.SetTask(Strings.InfoGetCertificationUri);
     try
     {
         this.certificationUri = RmsClientManager.GetRMSServiceLocation(this.organizationId, ServiceType.Certification);
         this.certificationUri = RmsoProxyUtil.GetCertificationServerRedirectUrl(this.certificationUri);
     }
     catch (RightsManagementException ex)
     {
         this.result.SetFailureResult(Strings.ErrorFailedToGetCertificationUri, ex, this.encryptionEnabled);
         return(false);
     }
     catch (ExchangeConfigurationException ex2)
     {
         this.result.SetFailureResult(Strings.ErrorFailedToGetCertificationUri, ex2, this.encryptionEnabled);
         return(false);
     }
     if (this.certificationUri == null)
     {
         this.result.SetFailureResult(Strings.ErrorFailedToGetCertificationUri, null, this.encryptionEnabled);
         return(false);
     }
     this.result.SetSuccessResult(Strings.InfoCertificationUri(this.certificationUri));
     this.result.SetTask(Strings.InfoCheckRmsVersion(this.certificationUri));
     try
     {
         if (this.ValidateRmsVersion(this.certificationUri, ServiceType.CertificationService))
         {
             this.result.SetSuccessResult(Strings.InfoRmsVersionChecked);
         }
         else
         {
             this.result.SetFailureResult(Strings.ErrorFailedRmsVersionCheck, null, this.encryptionEnabled);
         }
     }
     catch (RightsManagementException ex3)
     {
         this.result.SetFailureResult(Strings.ErrorFailedRmsVersionCheck, ex3, this.encryptionEnabled);
         return(false);
     }
     catch (ExchangeConfigurationException ex4)
     {
         this.result.SetFailureResult(Strings.ErrorFailedRmsVersionCheckInitialization, ex4, this.encryptionEnabled);
         return(false);
     }
     this.result.SetTask(Strings.InfoGetPublishingUri);
     try
     {
         this.publishingUri = RmsClientManager.GetRMSServiceLocation(this.organizationId, ServiceType.Publishing);
         this.publishingUri = RmsoProxyUtil.GetLicenseServerRedirectUrl(this.publishingUri);
     }
     catch (RightsManagementException ex5)
     {
         this.result.SetFailureResult(Strings.ErrorFailedToGetPublishingUri, ex5, this.encryptionEnabled);
         return(false);
     }
     catch (ExchangeConfigurationException ex6)
     {
         this.result.SetFailureResult(Strings.ErrorFailedToGetPublishingUri, ex6, this.encryptionEnabled);
         return(false);
     }
     if (this.publishingUri == null)
     {
         this.result.SetFailureResult(Strings.ErrorFailedToGetPublishingUri, null, this.encryptionEnabled);
         return(false);
     }
     this.result.SetSuccessResult(Strings.InfoPublishingUri(this.publishingUri));
     this.result.SetTask(Strings.InfoGetRacAndClc);
     try
     {
         this.tenantLicenses = RmsClientManager.AcquireTenantLicenses(this.context, this.publishingUri);
         this.result.SetSuccessResult(Strings.InfoRacAndClc);
     }
     catch (ExchangeConfigurationException ex7)
     {
         this.result.SetFailureResult(this.datacenter ? Strings.ErrorFailedToGetRacAndClcTenant : Strings.ErrorFailedToGetRacAndClcEnterprise, ex7, this.encryptionEnabled);
         return(false);
     }
     catch (RightsManagementException ex8)
     {
         this.result.SetFailureResult(this.datacenter ? Strings.ErrorFailedToGetRacAndClcTenant : Strings.ErrorFailedToGetRacAndClcEnterprise, ex8, this.encryptionEnabled);
         return(false);
     }
     return(true);
 }
        private bool TryCalculateIrmBodyTag(StoreDriverDeliveryEventArgsImpl argsImpl)
        {
            MessageItem messageItem = null;
            bool        result;

            try
            {
                OrganizationId organizationId = argsImpl.ADRecipientCache.OrganizationId;
                MessageItem    replayItem     = argsImpl.ReplayItem;
                using (Attachment attachment = this.TryOpenFirstAttachment(replayItem))
                {
                    StreamAttachmentBase streamAttachmentBase = attachment as StreamAttachmentBase;
                    if (streamAttachmentBase == null)
                    {
                        ConversationsProcessingAgent.tracer.TraceError((long)this.GetHashCode(), "message.rpmsg attachment is not of the correct type");
                        return(false);
                    }
                    using (Stream contentStream = streamAttachmentBase.GetContentStream(PropertyOpenMode.ReadOnly))
                    {
                        if (contentStream == null)
                        {
                            ConversationsProcessingAgent.tracer.TraceError((long)this.GetHashCode(), "The rights protected message is not properly formatted");
                            return(false);
                        }
                        using (DrmEmailMessageContainer drmEmailMessageContainer = new DrmEmailMessageContainer())
                        {
                            try
                            {
                                drmEmailMessageContainer.Load(contentStream, (object param0) => Streams.CreateTemporaryStorageStream());
                            }
                            catch (InvalidRpmsgFormatException)
                            {
                                ConversationsProcessingAgent.tracer.TraceError((long)this.GetHashCode(), "The rights protected message is not properly formatted");
                                return(false);
                            }
                            string text = null;
                            if (!argsImpl.MailItemDeliver.MbxTransportMailItem.ExtendedProperties.TryGetValue <string>("Microsoft.Exchange.RightsManagement.TransportDecryptionUL", out text) || string.IsNullOrEmpty(text))
                            {
                                ConversationsProcessingAgent.tracer.TraceError((long)this.GetHashCode(), "Failed to load the useLicense");
                                return(false);
                            }
                            try
                            {
                                Uri       licenseUri;
                                XmlNode[] array;
                                bool      flag;
                                RmsClientManager.GetLicensingUri(organizationId, drmEmailMessageContainer.PublishLicense, out licenseUri, out array, out flag);
                                RpMsgToMsgConverter     rpMsgToMsgConverter = new RpMsgToMsgConverter(drmEmailMessageContainer, organizationId, false);
                                RmsClientManagerContext context             = new RmsClientManagerContext(organizationId, RmsClientManagerContext.ContextId.MessageId, replayItem.InternetMessageId, argsImpl.ADRecipientCache, new RmsLatencyTracker(argsImpl.MailItemDeliver.MbxTransportMailItem.LatencyTracker), drmEmailMessageContainer.PublishLicense);
                                using (DisposableTenantLicensePair disposableTenantLicensePair = RmsClientManager.AcquireTenantLicenses(context, licenseUri))
                                {
                                    messageItem = rpMsgToMsgConverter.ConvertRpmsgToMsg(replayItem, text, disposableTenantLicensePair.EnablingPrincipalRac);
                                }
                            }
                            catch (RightsManagementException arg)
                            {
                                ConversationsProcessingAgent.tracer.TraceError <RightsManagementException>((long)this.GetHashCode(), "Conversion failed: {0}", arg);
                                return(false);
                            }
                            catch (InvalidRpmsgFormatException arg2)
                            {
                                ConversationsProcessingAgent.tracer.TraceError <InvalidRpmsgFormatException>((long)this.GetHashCode(), "Conversion failed: {0}", arg2);
                                return(false);
                            }
                            catch (ExchangeConfigurationException arg3)
                            {
                                ConversationsProcessingAgent.tracer.TraceError <ExchangeConfigurationException>((long)this.GetHashCode(), "Conversion failed: {0}", arg3);
                                return(false);
                            }
                            catch (AttachmentProtectionException arg4)
                            {
                                ConversationsProcessingAgent.tracer.TraceError <AttachmentProtectionException>((long)this.GetHashCode(), "Conversion failed: {0}", arg4);
                                return(false);
                            }
                        }
                    }
                }
                this.bodyTag = messageItem.Body.CalculateBodyTag(out this.latestMessageWordCount);
                if (messageItem.AttachmentCollection.Count == 0)
                {
                    this.forceAllAttachmentsHidden = true;
                }
                else
                {
                    foreach (AttachmentHandle attachmentHandle in messageItem.AttachmentCollection)
                    {
                        if (!attachmentHandle.IsInline)
                        {
                            break;
                        }
                        this.forceAllAttachmentsHidden = true;
                    }
                }
                result = true;
            }
            finally
            {
                if (messageItem != null)
                {
                    messageItem.Dispose();
                }
            }
            return(result);
        }