UnsignedPublishLicense 构造函数

定义

初始化 UnsignedPublishLicense 类的新实例。

重载

UnsignedPublishLicense()

初始化 UnsignedPublishLicense 类的新实例。

UnsignedPublishLicense(String)

从指定的 XrML 发布许可证模板初始化 类的新实例 UnsignedPublishLicense

UnsignedPublishLicense()

初始化 UnsignedPublishLicense 类的新实例。

public:
 UnsignedPublishLicense();
public UnsignedPublishLicense ();
Public Sub New ()

注解

UnsignedPublishLicense 创建一个空且未签名的发布许可证。

适用于

UnsignedPublishLicense(String)

从指定的 XrML 发布许可证模板初始化 类的新实例 UnsignedPublishLicense

public:
 UnsignedPublishLicense(System::String ^ publishLicenseTemplate);
public UnsignedPublishLicense (string publishLicenseTemplate);
new System.Security.RightsManagement.UnsignedPublishLicense : string -> System.Security.RightsManagement.UnsignedPublishLicense
Public Sub New (publishLicenseTemplate As String)

参数

publishLicenseTemplate
String

可扩展权限标记语言 (XrML) 用于创建此许可证的发布许可证模板。

示例

下面的示例演示如何使用此构造函数。

WriteStatus("   Reading '" + xrmlFilename + "' permissions.");
try
{
    StreamReader sr = File.OpenText(xrmlFile);
    xrmlString = sr.ReadToEnd();
}
catch (Exception ex)
{
    MessageBox.Show("ERROR: '"+xrmlFilename+"' open failed.\n"+
        "Exception: " + ex.Message, "XrML File Error",
        MessageBoxButton.OK, MessageBoxImage.Error);
    return false;
}

WriteStatus("   Building UnsignedPublishLicense");
WriteStatus("       from '" + xrmlFilename + "'.");
UnsignedPublishLicense unsignedLicense =
    new UnsignedPublishLicense(xrmlString);
ContentUser author = unsignedLicense.Owner;
WriteStatus("   Reading '" & xrmlFilename & "' permissions.")
Try
    Dim sr As StreamReader = File.OpenText(xrmlFile)
    xrmlString = sr.ReadToEnd()
Catch ex As Exception
    MessageBox.Show("ERROR: '" & xrmlFilename &"' open failed." & vbLf & "Exception: " & ex.Message, "XrML File Error", MessageBoxButton.OK, MessageBoxImage.Error)
    Return False
End Try

WriteStatus("   Building UnsignedPublishLicense")
WriteStatus("       from '" & xrmlFilename & "'.")
Dim unsignedLicense As New UnsignedPublishLicense(xrmlString)
Dim author As ContentUser = unsignedLicense.Owner

注解

publishLicenseTemplate (UnsignedPublishLicense String) 构造函数创建 时UnsignedPublishLicense,将忽略 XrML <RANGETIME><INTERVALTIME> 元素。 若要为发布许可证指定这些值, ContentGrant 必须显式设置 和 ValidFromValidUntil 的属性。 以下示例演示如何显式设置 ValidFromValidUntil 属性。

// The XRML template <RANGETIME> and <INTERVALTIME> elements are
// ignored by the UnsignedPublishLicense(xrmlString) constructor.
// To specify these values for the license, the ContentGrant
// ValidFrom and ValidUntil properties must be explicitly set.
// The following code sample demonstrates how to set the
// ContentGrant properties for ValidFrom and ValidUntil.

// Create a copy of the original XRML template ContentGrants
// set by the UnsignedPublishLicense(xrmlString) constructor.
ICollection<ContentGrant> tmpGrants = new List<ContentGrant>();
foreach (ContentGrant grant in unsignedLicense.Grants)
    tmpGrants.Add(grant);

// Erase all original UnsignedPublishLicense ContentGrants.
unsignedLicense.Grants.Clear();

// Add each original grant back to the UnsignedPublishLicense
// with appropriate ValidFrom and ValidUntil date/time values.
foreach (ContentGrant grant in tmpGrants)
{
    unsignedLicense.Grants.Add( new ContentGrant(
        grant.User, grant.Right,
        DateTime.MinValue,    // set ValidFrom as appropriate
        DateTime.MaxValue));  // set ValidUntil as appropriate
}
' The XRML template <RANGETIME> and <INTERVALTIME> elements are
' ignored by the UnsignedPublishLicense(xrmlString) constructor.
' To specify these values for the license, the ContentGrant
' ValidFrom and ValidUntil properties must be explicitly set.
' The following code sample demonstrates how to set the
' ContentGrant properties for ValidFrom and ValidUntil.

' Create a copy of the original XRML template ContentGrants
' set by the UnsignedPublishLicense(xrmlString) constructor.
Dim tmpGrants As ICollection(Of ContentGrant) = New List(Of ContentGrant)()
For Each grant As ContentGrant In unsignedLicense.Grants
    tmpGrants.Add(grant)
Next grant

' Erase all original UnsignedPublishLicense ContentGrants.
unsignedLicense.Grants.Clear()

' Add each original grant back to the UnsignedPublishLicense
' with appropriate ValidFrom and ValidUntil date/time values.
For Each grant As ContentGrant In tmpGrants
    unsignedLicense.Grants.Add(New ContentGrant(grant.User, grant.Right, Date.MinValue, Date.MaxValue)) ' set ValidUntil as appropriate -  set ValidFrom as appropriate
Next grant

适用于