private static SanitizedHtmlString GetIrmErrorDetails(UserContext userContext, RightsManagedMessageDecryptionStatus decryptionStatus)
        {
            if (userContext == null)
            {
                throw new ArgumentNullException("userContext");
            }
            SanitizingStringBuilder <OwaHtml> sanitizingStringBuilder = new SanitizingStringBuilder <OwaHtml>();
            RightsManagementFailureCode       failureCode             = decryptionStatus.FailureCode;

            if (failureCode > RightsManagementFailureCode.PreLicenseAcquisitionFailed)
            {
                switch (failureCode)
                {
                case RightsManagementFailureCode.FailedToExtractTargetUriFromMex:
                case RightsManagementFailureCode.FailedToDownloadMexData:
                    sanitizingStringBuilder.Append(LocalizedStrings.GetNonEncoded(-843834599));
                    goto IL_308;

                case RightsManagementFailureCode.GetServerInfoFailed:
                    goto IL_19E;

                case RightsManagementFailureCode.InternalLicensingDisabled:
                    break;

                case RightsManagementFailureCode.ExternalLicensingDisabled:
                    sanitizingStringBuilder.AppendFormat(LocalizedStrings.GetNonEncoded(-641698444), new object[]
                    {
                        WebReadyViewUtilities.GetOfficeDownloadAnchor(userContext.UserCulture)
                    });
                    goto IL_308;

                default:
                    switch (failureCode)
                    {
                    case RightsManagementFailureCode.ServerRightNotGranted:
                        sanitizingStringBuilder.Append(LocalizedStrings.GetNonEncoded(-271360565));
                        goto IL_308;

                    case RightsManagementFailureCode.InvalidLicensee:
                        goto IL_189;

                    case RightsManagementFailureCode.FeatureDisabled:
                        break;

                    case RightsManagementFailureCode.NotSupported:
                        sanitizingStringBuilder.AppendFormat(LocalizedStrings.GetNonEncoded(-1308596751), new object[]
                        {
                            WebReadyViewUtilities.GetOfficeDownloadAnchor(userContext.UserCulture)
                        });
                        goto IL_308;

                    case RightsManagementFailureCode.CorruptData:
                        sanitizingStringBuilder.Append(LocalizedStrings.GetNonEncoded(-987520932));
                        goto IL_308;

                    default:
                        if (failureCode != RightsManagementFailureCode.Success)
                        {
                            goto IL_19E;
                        }
                        goto IL_308;
                    }
                    break;
                }
                sanitizingStringBuilder.AppendFormat(LocalizedStrings.GetNonEncoded(-1308596751), new object[]
                {
                    WebReadyViewUtilities.GetOfficeDownloadAnchor(userContext.UserCulture)
                });
                goto IL_308;
            }
            if (failureCode == RightsManagementFailureCode.UserRightNotGranted)
            {
                sanitizingStringBuilder.AppendFormat(LocalizedStrings.GetNonEncoded(149546568), new object[]
                {
                    WebReadyViewUtilities.GetOfficeDownloadAnchor(userContext.UserCulture)
                });
                goto IL_308;
            }
            if (failureCode != RightsManagementFailureCode.PreLicenseAcquisitionFailed)
            {
                goto IL_19E;
            }
IL_189:
            sanitizingStringBuilder.Append(LocalizedStrings.GetNonEncoded(-492186842));
            goto IL_308;
IL_19E:
            sanitizingStringBuilder.Append(LocalizedStrings.GetNonEncoded(-624237727));
            Exception exception = decryptionStatus.Exception;

            if (Globals.ShowDebugInformation && exception != null && exception.InnerException != null)
            {
                StringBuilder stringBuilder = new StringBuilder();
                userContext.RenderThemeImage(stringBuilder, ThemeFileId.Expand, string.Empty, new object[0]);
                sanitizingStringBuilder.AppendFormat("<div onclick=\"document.getElementById('divDtls').style.display='';this.style.display='none';adjHght();\" style=\"cursor: pointer; color: #3165cd;\">" + stringBuilder.ToString() + "&nbsp;{0}</div><div id=\"divDtls\" style='display:none'>", new object[]
                {
                    LocalizedStrings.GetNonEncoded(-610047827)
                });
                string text = string.Empty;
                RightsManagementFailureCode failureCode2 = decryptionStatus.FailureCode;
                Exception innerException = exception.InnerException;
                if (innerException is RightsManagementException)
                {
                    RightsManagementException ex = (RightsManagementException)innerException;
                    text = ex.RmsUrl;
                }
                int num = 0;
                while (num < 10 && innerException.InnerException != null)
                {
                    innerException = innerException.InnerException;
                    num++;
                }
                sanitizingStringBuilder.AppendFormat(LocalizedStrings.GetHtmlEncoded(1633606253), new object[]
                {
                    innerException.Message
                });
                if (!string.IsNullOrEmpty(text))
                {
                    sanitizingStringBuilder.Append("<br>");
                    sanitizingStringBuilder.AppendFormat(LocalizedStrings.GetHtmlEncoded(2115316283), new object[]
                    {
                        text
                    });
                }
                if (failureCode2 != RightsManagementFailureCode.Success)
                {
                    sanitizingStringBuilder.Append("<br>");
                    sanitizingStringBuilder.AppendFormat(LocalizedStrings.GetHtmlEncoded(970140031), new object[]
                    {
                        failureCode2
                    });
                }
                sanitizingStringBuilder.Append("</div>");
            }
IL_308:
            return(sanitizingStringBuilder.ToSanitizedString <SanitizedHtmlString>());
        }
        public void InvokeTaskManager()
        {
            if (!AppSettings.GetConfiguredValue <bool>("TranscodingServiceEnabled", false))
            {
                this.HandleFault(LocalizedStrings.GetNonEncoded(500694802));
                return;
            }
            AttachmentPolicy attachmentPolicy = this.owaContext.UserContext.AttachmentPolicy;

            using (Stream stream = this.LoadDocument(true, out this.decryptionStatus))
            {
                if (this.decryptionStatus.Failed)
                {
                    SanitizedHtmlString irmErrorDetails = WebReadyViewUtilities.GetIrmErrorDetails(this.owaContext.UserContext, this.decryptionStatus);
                    this.HandleFault(irmErrorDetails.ToString());
                }
                else if (!attachmentPolicy.WebReadyDocumentViewingEnable)
                {
                    this.HandleFault(LocalizedStrings.GetNonEncoded(500694802));
                }
                else if (!AttachmentUtility.IsWebReadyDocument(this.fileExtension, this.mimeType))
                {
                    this.HandleFault(LocalizedStrings.GetNonEncoded(-1584334964));
                }
                else
                {
                    try
                    {
                        byte[] bytes = Encoding.Default.GetBytes(this.documentIdStringBuilder.ToString());
                        byte[] value = null;
                        using (MessageDigestForNonCryptographicPurposes messageDigestForNonCryptographicPurposes = new MessageDigestForNonCryptographicPurposes())
                        {
                            value = messageDigestForNonCryptographicPurposes.ComputeHash(bytes);
                        }
                        WebReadyViewUtilities.InitializeTranscodingService();
                        Utilities.MakePageNoCacheNoStore(this.owaContext.HttpContext.Response);
                        string sourceDocType = string.IsNullOrEmpty(this.fileExtension) ? this.mimeType : this.fileExtension.TrimStart(new char[]
                        {
                            '.'
                        });
                        try
                        {
                            TranscodingTaskManager.Transcode(BitConverter.ToString(value), this.owaContext.UserContext.Key.UserContextId, stream, sourceDocType, this.currentPageNumber, out this.totalPageNumber, this.owaContext.HttpContext.Response);
                        }
                        catch (TranscodingCrashException innerException)
                        {
                            OwaDiagnostics.LogEvent(ClientsEventLogConstants.Tuple_TranscodingWorkerProcessFails, string.Empty, new object[]
                            {
                                this.owaContext.LogonIdentity.GetLogonName(),
                                this.owaContext.LogonIdentity.UserSid.Value,
                                this.messageFrom,
                                this.messageSubject,
                                this.messageId,
                                this.documentPath,
                                this.documentIdStringBuilder.ToString()
                            });
                            throw new TranscodingUnconvertibleFileException("Transcoding service crash when converting the document.", innerException, this);
                        }
                        if (this.currentPageNumber == 0)
                        {
                            this.currentPageNumber = this.totalPageNumber;
                        }
                    }
                    catch (TranscodingException ex)
                    {
                        ExTraceGlobals.TranscodingTracer.TraceDebug <Type, string>(0L, "Exception: Type: {0} Error: {1}.", ex.GetType(), ex.Message);
                        ErrorInformation exceptionHandlingInformation = Utilities.GetExceptionHandlingInformation(ex, this.owaContext.MailboxIdentity);
                        this.HandleFault(exceptionHandlingInformation.Message);
                    }
                }
            }
        }