UnsignedPublishLicense 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 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
當 (String) 建構函式建立 UnsignedPublishLicense 時 UnsignedPublishLicense ,會忽略 XrML <RANGETIME>
或 <INTERVALTIME>
元素。 若要指定發行授權的這些值, ContentGrant 必須明確設定 和 ValidUntil 的屬性 ValidFrom 。 下列範例示範如何明確設定 ValidFrom 和 ValidUntil 屬性。
// 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