264 lines
11 KiB
C#
264 lines
11 KiB
C#
using System;
|
|
using System.ComponentModel.Design;
|
|
using System.Reflection;
|
|
|
|
namespace System.ComponentModel
|
|
{
|
|
/// <summary>Provides properties and methods to add a license to a component and to manage a <see cref="T:System.ComponentModel.LicenseProvider" />. This class cannot be inherited.</summary>
|
|
// Token: 0x020000A0 RID: 160
|
|
public sealed class LicenseManager
|
|
{
|
|
// Token: 0x06000538 RID: 1336 RVA: 0x0000DD6C File Offset: 0x0000BF6C
|
|
private LicenseManager()
|
|
{
|
|
}
|
|
|
|
/// <summary>Gets or sets the current <see cref="T:System.ComponentModel.LicenseContext" />, which specifies when you can use the licensed object.</summary>
|
|
/// <returns>A <see cref="T:System.ComponentModel.LicenseContext" /> that specifies when you can use the licensed object.</returns>
|
|
/// <exception cref="T:System.InvalidOperationException">The <see cref="P:System.ComponentModel.LicenseManager.CurrentContext" /> property is currently locked and cannot be changed.</exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
|
/// </PermissionSet>
|
|
// Token: 0x1700015C RID: 348
|
|
// (get) Token: 0x0600053A RID: 1338 RVA: 0x0000DD80 File Offset: 0x0000BF80
|
|
// (set) Token: 0x0600053B RID: 1339 RVA: 0x0000DDE4 File Offset: 0x0000BFE4
|
|
public static LicenseContext CurrentContext
|
|
{
|
|
get
|
|
{
|
|
object obj = LicenseManager.lockObject;
|
|
LicenseContext licenseContext;
|
|
lock (obj)
|
|
{
|
|
if (LicenseManager.mycontext == null)
|
|
{
|
|
LicenseManager.mycontext = new global::System.ComponentModel.Design.RuntimeLicenseContext();
|
|
}
|
|
licenseContext = LicenseManager.mycontext;
|
|
}
|
|
return licenseContext;
|
|
}
|
|
set
|
|
{
|
|
object obj = LicenseManager.lockObject;
|
|
lock (obj)
|
|
{
|
|
if (LicenseManager.contextLockUser != null)
|
|
{
|
|
throw new InvalidOperationException("The CurrentContext property of the LicenseManager is currently locked and cannot be changed.");
|
|
}
|
|
LicenseManager.mycontext = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets the <see cref="T:System.ComponentModel.LicenseUsageMode" /> which specifies when you can use the licensed object for the <see cref="P:System.ComponentModel.LicenseManager.CurrentContext" />.</summary>
|
|
/// <returns>One of the <see cref="T:System.ComponentModel.LicenseUsageMode" /> values, as specified in the <see cref="P:System.ComponentModel.LicenseManager.CurrentContext" /> property.</returns>
|
|
// Token: 0x1700015D RID: 349
|
|
// (get) Token: 0x0600053C RID: 1340 RVA: 0x0000DE48 File Offset: 0x0000C048
|
|
public static LicenseUsageMode UsageMode
|
|
{
|
|
get
|
|
{
|
|
return LicenseManager.CurrentContext.UsageMode;
|
|
}
|
|
}
|
|
|
|
/// <summary>Creates an instance of the specified type, given a context in which you can use the licensed instance.</summary>
|
|
/// <returns>An instance of the specified type.</returns>
|
|
/// <param name="type">A <see cref="T:System.Type" /> that represents the type to create. </param>
|
|
/// <param name="creationContext">A <see cref="T:System.ComponentModel.LicenseContext" /> that specifies when you can use the licensed instance. </param>
|
|
// Token: 0x0600053D RID: 1341 RVA: 0x0000DE54 File Offset: 0x0000C054
|
|
public static object CreateWithContext(Type type, LicenseContext creationContext)
|
|
{
|
|
return LicenseManager.CreateWithContext(type, creationContext, new object[0]);
|
|
}
|
|
|
|
/// <summary>Creates an instance of the specified type with the specified arguments, given a context in which you can use the licensed instance.</summary>
|
|
/// <returns>An instance of the specified type with the given array of arguments.</returns>
|
|
/// <param name="type">A <see cref="T:System.Type" /> that represents the type to create. </param>
|
|
/// <param name="creationContext">A <see cref="T:System.ComponentModel.LicenseContext" /> that specifies when you can use the licensed instance. </param>
|
|
/// <param name="args">An array of type <see cref="T:System.Object" /> that represents the arguments for the type. </param>
|
|
// Token: 0x0600053E RID: 1342 RVA: 0x0000DE64 File Offset: 0x0000C064
|
|
public static object CreateWithContext(Type type, LicenseContext creationContext, object[] args)
|
|
{
|
|
object obj = null;
|
|
object obj2 = LicenseManager.lockObject;
|
|
lock (obj2)
|
|
{
|
|
object obj3 = new object();
|
|
LicenseContext currentContext = LicenseManager.CurrentContext;
|
|
LicenseManager.CurrentContext = creationContext;
|
|
LicenseManager.LockContext(obj3);
|
|
try
|
|
{
|
|
obj = Activator.CreateInstance(type, args);
|
|
}
|
|
catch (TargetInvocationException ex)
|
|
{
|
|
throw ex.InnerException;
|
|
}
|
|
finally
|
|
{
|
|
LicenseManager.UnlockContext(obj3);
|
|
LicenseManager.CurrentContext = currentContext;
|
|
}
|
|
}
|
|
return obj;
|
|
}
|
|
|
|
/// <summary>Returns whether the given type has a valid license.</summary>
|
|
/// <returns>true if the given type is licensed; otherwise, false.</returns>
|
|
/// <param name="type">The <see cref="T:System.Type" /> to find a valid license for. </param>
|
|
// Token: 0x0600053F RID: 1343 RVA: 0x0000DF1C File Offset: 0x0000C11C
|
|
public static bool IsLicensed(Type type)
|
|
{
|
|
License license = null;
|
|
if (!LicenseManager.privateGetLicense(type, null, false, out license))
|
|
{
|
|
return false;
|
|
}
|
|
if (license != null)
|
|
{
|
|
license.Dispose();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>Determines whether a valid license can be granted for the specified type.</summary>
|
|
/// <returns>true if a valid license can be granted; otherwise, false.</returns>
|
|
/// <param name="type">A <see cref="T:System.Type" /> that represents the type of object that requests the <see cref="T:System.ComponentModel.License" />. </param>
|
|
// Token: 0x06000540 RID: 1344 RVA: 0x0000DF4C File Offset: 0x0000C14C
|
|
public static bool IsValid(Type type)
|
|
{
|
|
License license = null;
|
|
if (!LicenseManager.privateGetLicense(type, null, false, out license))
|
|
{
|
|
return false;
|
|
}
|
|
if (license != null)
|
|
{
|
|
license.Dispose();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>Determines whether a valid license can be granted for the specified instance of the type. This method creates a valid <see cref="T:System.ComponentModel.License" />.</summary>
|
|
/// <returns>true if a valid <see cref="T:System.ComponentModel.License" /> can be granted; otherwise, false.</returns>
|
|
/// <param name="type">A <see cref="T:System.Type" /> that represents the type of object that requests the license. </param>
|
|
/// <param name="instance">An object of the specified type or a type derived from the specified type. </param>
|
|
/// <param name="license">A <see cref="T:System.ComponentModel.License" /> that is a valid license, or null if a valid license cannot be granted. </param>
|
|
// Token: 0x06000541 RID: 1345 RVA: 0x0000DF7C File Offset: 0x0000C17C
|
|
public static bool IsValid(Type type, object instance, out License license)
|
|
{
|
|
return LicenseManager.privateGetLicense(type, null, false, out license);
|
|
}
|
|
|
|
/// <summary>Prevents changes being made to the current <see cref="T:System.ComponentModel.LicenseContext" /> of the given object.</summary>
|
|
/// <param name="contextUser">The object whose current context you want to lock. </param>
|
|
/// <exception cref="T:System.InvalidOperationException">The context is already locked.</exception>
|
|
// Token: 0x06000542 RID: 1346 RVA: 0x0000DF88 File Offset: 0x0000C188
|
|
public static void LockContext(object contextUser)
|
|
{
|
|
object obj = LicenseManager.lockObject;
|
|
lock (obj)
|
|
{
|
|
LicenseManager.contextLockUser = contextUser;
|
|
}
|
|
}
|
|
|
|
/// <summary>Allows changes to be made to the current <see cref="T:System.ComponentModel.LicenseContext" /> of the given object.</summary>
|
|
/// <param name="contextUser">The object whose current context you want to unlock. </param>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="contextUser" /> represents a different user than the one specified in a previous call to <see cref="M:System.ComponentModel.LicenseManager.LockContext(System.Object)" />. </exception>
|
|
// Token: 0x06000543 RID: 1347 RVA: 0x0000DFD0 File Offset: 0x0000C1D0
|
|
public static void UnlockContext(object contextUser)
|
|
{
|
|
object obj = LicenseManager.lockObject;
|
|
lock (obj)
|
|
{
|
|
if (LicenseManager.contextLockUser != null)
|
|
{
|
|
if (LicenseManager.contextLockUser != contextUser)
|
|
{
|
|
throw new ArgumentException("The CurrentContext property of the LicenseManager can only be unlocked with the same contextUser.");
|
|
}
|
|
LicenseManager.contextLockUser = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>Determines whether a license can be granted for the specified type.</summary>
|
|
/// <param name="type">A <see cref="T:System.Type" /> that represents the type of object that requests the license. </param>
|
|
/// <exception cref="T:System.ComponentModel.LicenseException">A <see cref="T:System.ComponentModel.License" /> cannot be granted. </exception>
|
|
// Token: 0x06000544 RID: 1348 RVA: 0x0000E03C File Offset: 0x0000C23C
|
|
public static void Validate(Type type)
|
|
{
|
|
License license = null;
|
|
if (!LicenseManager.privateGetLicense(type, null, true, out license))
|
|
{
|
|
throw new LicenseException(type, null);
|
|
}
|
|
if (license != null)
|
|
{
|
|
license.Dispose();
|
|
}
|
|
}
|
|
|
|
/// <summary>Determines whether a license can be granted for the instance of the specified type.</summary>
|
|
/// <returns>A valid <see cref="T:System.ComponentModel.License" />.</returns>
|
|
/// <param name="type">A <see cref="T:System.Type" /> that represents the type of object that requests the license. </param>
|
|
/// <param name="instance">An <see cref="T:System.Object" /> of the specified type or a type derived from the specified type. </param>
|
|
/// <exception cref="T:System.ComponentModel.LicenseException">The type is licensed, but a <see cref="T:System.ComponentModel.License" /> cannot be granted. </exception>
|
|
// Token: 0x06000545 RID: 1349 RVA: 0x0000E070 File Offset: 0x0000C270
|
|
public static License Validate(Type type, object instance)
|
|
{
|
|
License license = null;
|
|
if (!LicenseManager.privateGetLicense(type, instance, true, out license))
|
|
{
|
|
throw new LicenseException(type, instance);
|
|
}
|
|
return license;
|
|
}
|
|
|
|
// Token: 0x06000546 RID: 1350 RVA: 0x0000E098 File Offset: 0x0000C298
|
|
private static bool privateGetLicense(Type type, object instance, bool allowExceptions, out License license)
|
|
{
|
|
bool flag = false;
|
|
License license2 = null;
|
|
LicenseProviderAttribute licenseProviderAttribute = (LicenseProviderAttribute)Attribute.GetCustomAttribute(type, typeof(LicenseProviderAttribute), true);
|
|
if (licenseProviderAttribute != null)
|
|
{
|
|
Type licenseProvider = licenseProviderAttribute.LicenseProvider;
|
|
if (licenseProvider != null)
|
|
{
|
|
LicenseProvider licenseProvider2 = (LicenseProvider)Activator.CreateInstance(licenseProvider);
|
|
if (licenseProvider2 != null)
|
|
{
|
|
license2 = licenseProvider2.GetLicense(LicenseManager.CurrentContext, type, instance, allowExceptions);
|
|
if (license2 != null)
|
|
{
|
|
flag = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
flag = true;
|
|
}
|
|
license = license2;
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x04000182 RID: 386
|
|
private static LicenseContext mycontext;
|
|
|
|
// Token: 0x04000183 RID: 387
|
|
private static object contextLockUser;
|
|
|
|
// Token: 0x04000184 RID: 388
|
|
private static object lockObject = new object();
|
|
}
|
|
}
|