private static void AcquireServerLicensingMexCallback(ICancelableAsyncResult asyncResult) { RmsServerInfoManager.Tracer.TraceDebug(0L, "AcquireServerLicensingMexCallback invoked"); ArgumentValidator.ThrowIfNull("asyncResult", asyncResult); ArgumentValidator.ThrowIfNull("asyncResult.AsyncState", asyncResult.AsyncState); AcquireServerInfoAsyncResult acquireServerInfoAsyncResult = asyncResult.AsyncState as AcquireServerInfoAsyncResult; if (acquireServerInfoAsyncResult == null) { throw new InvalidOperationException("asyncResult.AsyncState has to be type of AcquireServerInfoAsyncResult."); } acquireServerInfoAsyncResult.AddBreadCrumb(Constants.State.AcquireServerLicensingMexCallback); Exception ex = null; try { DownloadResult downloadResult = acquireServerInfoAsyncResult.HttpClient.EndDownload(asyncResult); acquireServerInfoAsyncResult.LatencyTracker.EndTrackRmsLatency(RmsOperationType.AcquireServerLicensingMexData); if (downloadResult.IsSucceeded) { Uri targetUriFromResponse = RmsClientManagerUtils.GetTargetUriFromResponse(downloadResult.ResponseStream); if (targetUriFromResponse == null) { ex = new RightsManagementException(RightsManagementFailureCode.FailedToExtractTargetUriFromMex, ServerStrings.FailedToFindTargetUriFromMExData(acquireServerInfoAsyncResult.ServerLicensingMExUri), acquireServerInfoAsyncResult.LicenseUri.ToString()); } else { acquireServerInfoAsyncResult.ServerInfo.ServerLicensingWSTargetUri = TokenTarget.Fix(targetUriFromResponse); RmsServerInfoManager.serverInfoMap.Add(acquireServerInfoAsyncResult.ServerInfo); } } else { RmsClientManager.TraceFail(null, acquireServerInfoAsyncResult.Context.SystemProbeId, "Failed to download data from server licensing MEx {0}. Exception is {1}", new object[] { acquireServerInfoAsyncResult.ServerLicensingMExUri, downloadResult.Exception }); ex = new RightsManagementException(RightsManagementFailureCode.FailedToDownloadMexData, ServerStrings.FailedToDownloadServerLicensingMExData(downloadResult.ResponseUri), downloadResult.Exception, acquireServerInfoAsyncResult.LicenseUri.ToString()); ((RightsManagementException)ex).IsPermanent = !downloadResult.IsRetryable; } } finally { acquireServerInfoAsyncResult.Release(); } RmsServerInfoManager.Tracer.TraceDebug(0L, "AcquireServiceLocationCallback: Invoking find service location callbacks"); RmsServerInfoManager.outstandingFindServiceLocationCalls.InvokeCallbacks(acquireServerInfoAsyncResult.LicenseUri, ex); }
private static void AcquireCertificationMexCallback(ICancelableAsyncResult asyncResult) { RmsServerInfoManager.Tracer.TraceDebug(0L, "AcquireCertificationMexCallback invoked"); ArgumentValidator.ThrowIfNull("asyncResult", asyncResult); ArgumentValidator.ThrowIfNull("asyncResult.AsyncState", asyncResult.AsyncState); AcquireServerInfoAsyncResult acquireServerInfoAsyncResult = asyncResult.AsyncState as AcquireServerInfoAsyncResult; if (acquireServerInfoAsyncResult == null) { throw new InvalidOperationException("asyncResult.AsyncState has to be type of AcquireServerInfoAsyncResult."); } acquireServerInfoAsyncResult.AddBreadCrumb(Constants.State.AcquireCertificationMexCallback); Exception ex = null; try { DownloadResult downloadResult = acquireServerInfoAsyncResult.HttpClient.EndDownload(asyncResult); acquireServerInfoAsyncResult.LatencyTracker.EndTrackRmsLatency(RmsOperationType.AcquireCertificationMexData); if (downloadResult.IsSucceeded) { Uri targetUriFromResponse = RmsClientManagerUtils.GetTargetUriFromResponse(downloadResult.ResponseStream); if (targetUriFromResponse == null) { ex = new RightsManagementException(RightsManagementFailureCode.FailedToExtractTargetUriFromMex, ServerStrings.FailedToFindTargetUriFromMExData(acquireServerInfoAsyncResult.CertificationMExUri), acquireServerInfoAsyncResult.LicenseUri.ToString()); } else { acquireServerInfoAsyncResult.ServerInfo.CertificationWSTargetUri = TokenTarget.Fix(targetUriFromResponse); acquireServerInfoAsyncResult.AddBreadCrumb(Constants.State.BeginDownloadServerLicensingMexData); WebProxy localServerProxy; try { localServerProxy = RmsClientManagerUtils.GetLocalServerProxy(true); } catch (ExchangeConfigurationException ex2) { ex = ex2; return; } HttpSessionConfig httpSessionConfig = new HttpSessionConfig(); if (localServerProxy != null) { httpSessionConfig.Proxy = localServerProxy; } acquireServerInfoAsyncResult.LatencyTracker.BeginTrackRmsLatency(RmsOperationType.AcquireServerLicensingMexData); acquireServerInfoAsyncResult.HttpClient.BeginDownload(acquireServerInfoAsyncResult.ServerLicensingMExUri, httpSessionConfig, RmsClientManagerUtils.WrapCancellableCallbackWithUnhandledExceptionHandlerAndUpdatePoisonContext(new CancelableAsyncCallback(RmsServerInfoManager.AcquireServerLicensingMexCallback)), acquireServerInfoAsyncResult); } } else { RmsClientManager.TraceFail(null, acquireServerInfoAsyncResult.Context.SystemProbeId, "Failed to download data from certification MEx {0}. Exception is {1}", new object[] { acquireServerInfoAsyncResult.CertificationMExUri, downloadResult.Exception }); ex = new RightsManagementException(RightsManagementFailureCode.FailedToDownloadMexData, ServerStrings.FailedToDownloadCertificationMExData(downloadResult.ResponseUri), downloadResult.Exception, acquireServerInfoAsyncResult.LicenseUri.ToString()); ((RightsManagementException)ex).IsPermanent = !downloadResult.IsRetryable; } } finally { if (ex != null) { acquireServerInfoAsyncResult.Release(); RmsServerInfoManager.Tracer.TraceDebug(0L, "AcquireServiceLocationCallback: Invoking find service location callbacks"); RmsServerInfoManager.outstandingFindServiceLocationCalls.InvokeCallbacks(acquireServerInfoAsyncResult.LicenseUri, ex); } } }