/// <summary> /// Invoked to acquire the PlayReady License /// </summary> async void LicenseAcquisitionRequest(PlayReadyLicenseAcquisitionServiceRequest licenseRequest, MediaProtectionServiceCompletion completionNotifier, string url, string challengeCustomData) { bool bResult = false; string ExceptionMessage = string.Empty; try { if (!string.IsNullOrEmpty(url)) { Log("ProtectionManager PlayReady Manual License Acquisition Service Request in progress - URL: " + url); if (!string.IsNullOrEmpty(challengeCustomData)) { var encoding = new UTF8Encoding(); byte[] b = encoding.GetBytes(challengeCustomData); licenseRequest.ChallengeCustomData = Convert.ToBase64String(b, 0, b.Length); } PlayReadySoapMessage soapMessage = licenseRequest.GenerateManualEnablingChallenge(); byte[] messageBytes = soapMessage.GetMessageBody(); HttpContent httpContent = new ByteArrayContent(messageBytes); IPropertySet propertySetHeaders = soapMessage.MessageHeaders; foreach (string strHeaderName in propertySetHeaders.Keys) { string strHeaderValue = propertySetHeaders[strHeaderName].ToString(); // The Add method throws an ArgumentException try to set protected headers like "Content-Type" // so set it via "ContentType" property if (strHeaderName.Equals("Content-Type", StringComparison.OrdinalIgnoreCase)) { httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse(strHeaderValue); } else { httpContent.Headers.Add(strHeaderName.ToString(), strHeaderValue); } } var licenseAcquision = new CommonLicenseRequest(); HttpContent responseHttpContent = await licenseAcquision.AcquireLicenseAsync(new Uri(url), httpContent); if (responseHttpContent != null) { Exception exResult = licenseRequest.ProcessManualEnablingResponse(await responseHttpContent.ReadAsByteArrayAsync()); if (exResult != null) { throw exResult; } bResult = true; } else { ExceptionMessage = licenseAcquision.GetLastErrorMessage(); } } else { Log("ProtectionManager PlayReady License Acquisition Service Request in progress - URL: " + licenseRequest.Uri.ToString()); await licenseRequest.BeginServiceRequest(); bResult = true; } } catch (Exception e) { ExceptionMessage = e.Message; } if (bResult == true) { Log(!string.IsNullOrEmpty(url) ? "ProtectionManager Manual PlayReady License Acquisition Service Request successful" : "ProtectionManager PlayReady License Acquisition Service Request successful"); } else { Log(!string.IsNullOrEmpty(url) ? "ProtectionManager Manual PlayReady License Acquisition Service Request failed: " + ExceptionMessage : "ProtectionManager PlayReady License Acquisition Service Request failed: " + ExceptionMessage); } completionNotifier.Complete(bResult); }
/// <summary> /// Invoked to acquire the PlayReady License /// </summary> async void LicenseAcquisitionRequest(PlayReadyLicenseAcquisitionServiceRequest licenseRequest, MediaProtectionServiceCompletion completionNotifier, string url, string challengeCustomData) { bool bResult = false; string ExceptionMessage = string.Empty; try { if (!string.IsNullOrEmpty(url)) { Log("ProtectionManager PlayReady Manual License Acquisition Service Request in progress - URL: " + url); if (!string.IsNullOrEmpty(challengeCustomData)) { var encoding = new UTF8Encoding(); byte[] b = encoding.GetBytes(challengeCustomData); licenseRequest.ChallengeCustomData = Convert.ToBase64String(b, 0, b.Length); } PlayReadySoapMessage soapMessage = licenseRequest.GenerateManualEnablingChallenge(); byte[] messageBytes = soapMessage.GetMessageBody(); HttpContent httpContent = new ByteArrayContent(messageBytes); IPropertySet propertySetHeaders = soapMessage.MessageHeaders; foreach (string strHeaderName in propertySetHeaders.Keys) { string strHeaderValue = propertySetHeaders[strHeaderName].ToString(); // The Add method throws an ArgumentException try to set protected headers like "Content-Type" // so set it via "ContentType" property if (strHeaderName.Equals("Content-Type", StringComparison.OrdinalIgnoreCase)) httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse(strHeaderValue); else httpContent.Headers.Add(strHeaderName.ToString(), strHeaderValue); } var licenseAcquision = new CommonLicenseRequest(); HttpContent responseHttpContent = await licenseAcquision.AcquireLicenseAsync(new Uri(url), httpContent); if (responseHttpContent != null) { Exception exResult = licenseRequest.ProcessManualEnablingResponse(await responseHttpContent.ReadAsByteArrayAsync()); if (exResult != null) { throw exResult; } bResult = true; } else ExceptionMessage = licenseAcquision.GetLastErrorMessage(); } else { Log("ProtectionManager PlayReady License Acquisition Service Request in progress - URL: " + licenseRequest.Uri.ToString()); await licenseRequest.BeginServiceRequest(); bResult = true; } } catch (Exception e) { ExceptionMessage = e.Message; } if (bResult == true) Log(!string.IsNullOrEmpty(url) ? "ProtectionManager Manual PlayReady License Acquisition Service Request successful" : "ProtectionManager PlayReady License Acquisition Service Request successful"); else Log(!string.IsNullOrEmpty(url) ? "ProtectionManager Manual PlayReady License Acquisition Service Request failed: " + ExceptionMessage : "ProtectionManager PlayReady License Acquisition Service Request failed: " + ExceptionMessage); completionNotifier.Complete(bResult); }