/// <summary> /// Gets the license expiry date timestamp. /// </summary> /// <returns>Returns the timestamp.</returns> public static uint GetLicenseExpiryDate() { uint expiryDate = 0; int status = IntPtr.Size == 4 ? LexActivatorNative.GetLicenseExpiryDate_x86(ref expiryDate) : LexActivatorNative.GetLicenseExpiryDate(ref expiryDate); switch (status) { case LexStatusCodes.LA_OK: return(expiryDate); case LexStatusCodes.LA_FAIL: return(0); default: throw new LexActivatorException(status); } }
/// <summary> /// Sets the network proxy to be used when contacting Cryptlex servers. /// /// The proxy format should be: [protocol://][username:password@]machine[:port] /// /// NOTE: Proxy settings of the computer are automatically detected. So, in most of the /// cases you don't need to care whether your user is behind a proxy server or not. /// </summary> /// <param name="proxy"></param> public static void SetNetworkProxy(string proxy) { int status; if (LexActivatorNative.IsWindows()) { status = IntPtr.Size == 4 ? LexActivatorNative.SetNetworkProxy_x86(proxy) : LexActivatorNative.SetNetworkProxy(proxy); } else { status = LexActivatorNative.SetNetworkProxyA(proxy); } if (LexStatusCodes.LA_OK != status) { throw new LexActivatorException(status); } }
/// <summary> /// Gets the license meter attribute allowed uses and total uses. /// </summary> /// <param name="name">name of the meter attribute</param> /// <returns>Returns the values of meter attribute allowed and total uses.</returns> public static LicenseMeterAttribute GetLicenseMeterAttribute(string name) { uint allowedUses = 0, totalUses = 0; int status; if (LexActivatorNative.IsWindows()) { status = IntPtr.Size == 4 ? LexActivatorNative.GetLicenseMeterAttribute_x86(name, ref allowedUses, ref totalUses) : LexActivatorNative.GetLicenseMeterAttribute(name, ref allowedUses, ref totalUses); } else { status = LexActivatorNative.GetLicenseMeterAttributeA(name, ref allowedUses, ref totalUses); } if (LexStatusCodes.LA_OK == status) { return(new LicenseMeterAttribute(name, allowedUses, totalUses)); } throw new LexActivatorException(status); }
/// <summary> /// Sets the meter attribute uses for the offline activation request. /// /// This function should only be called before GenerateOfflineActivationRequest() /// function to set the meter attributes in case of offline activation. /// </summary> /// <param name="name">name of the meter attribute</param> /// <param name="uses">the uses value</param> public static void SetOfflineActivationRequestMeterAttributeUses(string name, uint uses) { int status; if (LexActivatorNative.IsWindows()) { status = IntPtr.Size == 4 ? LexActivatorNative.SetOfflineActivationRequestMeterAttributeUses_x86(name, uses) : LexActivatorNative.SetOfflineActivationRequestMeterAttributeUses(name, uses); } else { status = LexActivatorNative.SetOfflineActivationRequestMeterAttributeUsesA(name, uses); } if (LexStatusCodes.LA_OK != status) { throw new LexActivatorException(status); } }
/// <summary> /// Sets the absolute path of the Product.dat file. /// /// This function must be called on every start of your program /// before any other functions are called. /// </summary> /// <param name="filePath">absolute path of the product file (Product.dat)</param> public static void SetProductFile(string filePath) { int status; if (LexActivatorNative.IsWindows()) { status = IntPtr.Size == 4 ? LexActivatorNative.SetProductFile_x86(filePath) : LexActivatorNative.SetProductFile(filePath); } else { status = LexActivatorNative.SetProductFileA(filePath); } if (LexStatusCodes.LA_OK != status) { throw new LexActivatorException(status); } }
/// <summary> /// Embeds the Product.dat file in the application. /// /// It can be used instead of SetProductFile() in case you want /// to embed the Product.dat file in your application. /// /// This function must be called on every start of your program /// before any other functions are called. /// </summary> /// <param name="productData">content of the Product.dat file</param> public static void SetProductData(string productData) { int status; if (LexActivatorNative.IsWindows()) { status = IntPtr.Size == 4 ? LexActivatorNative.SetProductData_x86(productData) : LexActivatorNative.SetProductData(productData); } else { status = LexActivatorNative.SetProductDataA(productData); } if (LexStatusCodes.LA_OK != status) { throw new LexActivatorException(status); } }
/// <summary> /// Generates the offline trial activation request needed for generating /// offline trial activation response in the dashboard. /// </summary> /// <param name="filePath">path of the file for the offline request</param> public static void GenerateOfflineTrialActivationRequest(string filePath) { int status; if (LexActivatorNative.IsWindows()) { status = IntPtr.Size == 4 ? LexActivatorNative.GenerateOfflineTrialActivationRequest_x86(filePath) : LexActivatorNative.GenerateOfflineTrialActivationRequest(filePath); } else { status = LexActivatorNative.GenerateOfflineTrialActivationRequestA(filePath); } if (LexStatusCodes.LA_OK != status) { throw new LexActivatorException(status); } }
/// <summary> /// Sets the license user email and password for authentication. /// /// This function must be called before ActivateLicense() or IsLicenseGenuine() /// function if 'requireAuthentication' property of the license is set to true. /// </summary> /// <param name="email">user email address</param> /// <param name="password">user password</param> public static void SetLicenseUserCredential(string email, string password) { int status; if (LexActivatorNative.IsWindows()) { status = IntPtr.Size == 4 ? LexActivatorNative.SetLicenseUserCredential_x86(email, password) : LexActivatorNative.SetLicenseUserCredential(email, password); } else { status = LexActivatorNative.SetLicenseUserCredentialA(email, password); } if (LexStatusCodes.LA_OK != status) { throw new LexActivatorException(status); } }
/// <summary> /// Sets server sync callback function. /// /// Whenever the server sync occurs in a separate thread, and server returns the response, /// license callback function gets invoked with the following status codes: /// LA_OK, LA_EXPIRED, LA_SUSPENDED, LA_E_REVOKED, LA_E_ACTIVATION_NOT_FOUND, /// LA_E_MACHINE_FINGERPRINT, LA_E_AUTHENTICATION_FAILED, LA_E_COUNTRY, LA_E_INET, /// LA_E_SERVER, LA_E_RATE_LIMIT, LA_E_IP /// </summary> /// <param name="callback"></param> public static void SetLicenseCallback(CallbackType callback) { var wrappedCallback = callback; #if NETFRAMEWORK var syncTarget = callback.Target as System.Windows.Forms.Control; if (syncTarget != null) { wrappedCallback = (v) => syncTarget.Invoke(callback, new object[] { v }); } #endif callbackList.Add(wrappedCallback); int status = IntPtr.Size == 4 ? LexActivatorNative.SetLicenseCallback_x86(wrappedCallback) : LexActivatorNative.SetLicenseCallback(wrappedCallback); if (LexStatusCodes.LA_OK != status) { throw new LexActivatorException(status); } }
/// <summary> /// Extends the local trial. /// /// NOTE: The function is only meant for local (unverified) trials. /// </summary> /// <param name="trialExtensionLength">number of days to extend the trial</param> /// <returns>LA_OK, LA_FAIL</returns> public static int ExtendLocalTrial(uint trialExtensionLength) { int status = IntPtr.Size == 4 ? LexActivatorNative.ExtendLocalTrial_x86(trialExtensionLength) : LexActivatorNative.ExtendLocalTrial(trialExtensionLength); switch (status) { case LexStatusCodes.LA_OK: return(LexStatusCodes.LA_OK); case LexStatusCodes.LA_FAIL: return(LexStatusCodes.LA_FAIL); default: throw new LexActivatorException(status); } }
/// <summary> /// Resets the meter attribute uses consumed by the activation. /// </summary> /// <param name="name">name of the meter attribute</param> public static void ResetActivationMeterAttributeUses(string name) { int status; if (LexActivatorNative.IsWindows()) { status = IntPtr.Size == 4 ? LexActivatorNative.ResetActivationMeterAttributeUses_x86(name) : LexActivatorNative.ResetActivationMeterAttributeUses(name); } else { status = LexActivatorNative.ResetActivationMeterAttributeUsesA(name); } if (LexStatusCodes.LA_OK != status) { throw new LexActivatorException(status); } }
/// <summary> /// It verifies whether trial has started and is genuine or not. The /// verification is done locally. /// /// This function must be called on every start of your program during the trial period. /// /// NOTE: The function is only meant for local (unverified) trials. /// </summary> /// <returns>LA_OK, LA_LOCAL_TRIAL_EXPIRED, LA_FAIL</returns> public static int IsLocalTrialGenuine() { int status = IntPtr.Size == 4 ? LexActivatorNative.IsLocalTrialGenuine_x86() : LexActivatorNative.IsLocalTrialGenuine(); switch (status) { case LexStatusCodes.LA_OK: return(LexStatusCodes.LA_OK); case LexStatusCodes.LA_LOCAL_TRIAL_EXPIRED: return(LexStatusCodes.LA_LOCAL_TRIAL_EXPIRED); case LexStatusCodes.LA_FAIL: return(LexStatusCodes.LA_FAIL); default: throw new LexActivatorException(status); } }
/// <summary> /// Starts the local (unverified) trial. /// /// This function should be executed when your application starts first time on /// the user's computer. /// </summary> /// <param name="trialLength">trial length in days</param> /// <returns>LA_OK, LA_LOCAL_TRIAL_EXPIRED, LA_FAIL</returns> public static int ActivateLocalTrial(uint trialLength) { int status = IntPtr.Size == 4 ? LexActivatorNative.ActivateLocalTrial_x86(trialLength) : LexActivatorNative.ActivateLocalTrial(trialLength); switch (status) { case LexStatusCodes.LA_OK: return(LexStatusCodes.LA_OK); case LexStatusCodes.LA_LOCAL_TRIAL_EXPIRED: return(LexStatusCodes.LA_LOCAL_TRIAL_EXPIRED); case LexStatusCodes.LA_FAIL: return(LexStatusCodes.LA_FAIL); default: throw new LexActivatorException(status); } }
/// <summary> /// Sets the license key required to activate the license. /// </summary> /// <param name="licenseKey">a valid license key</param> public static void SetLicenseKey(string licenseKey) { int status; if (LexActivatorNative.IsWindows()) { status = IntPtr.Size == 4 ? LexActivatorNative.SetLicenseKey_x86(licenseKey) : LexActivatorNative.SetLicenseKey(licenseKey); } else { status = LexActivatorNative.SetLicenseKeyA(licenseKey); } if (LexStatusCodes.LA_OK != status) { throw new LexActivatorException(status); } }
/// <summary> /// Gets the company associated with the license user. /// </summary> /// <returns>Returns the license user company.</returns> public static string GetLicenseUserCompany() { var builder = new StringBuilder(256); int status; if (LexActivatorNative.IsWindows()) { status = IntPtr.Size == 4 ? LexActivatorNative.GetLicenseUserCompany_x86(builder, builder.Capacity) : LexActivatorNative.GetLicenseUserCompany(builder, builder.Capacity); } else { status = LexActivatorNative.GetLicenseUserCompanyA(builder, builder.Capacity); } if (LexStatusCodes.LA_OK == status) { return(builder.ToString()); } throw new LexActivatorException(status); }
/// <summary> /// Sets the trial activation metadata. /// /// The metadata appears along with the trial activation details of the product /// in dashboard. /// </summary> /// <param name="key">string of maximum length 256 characters with utf-8 encoding</param> /// <param name="value">string of maximum length 256 characters with utf-8 encoding</param> public static void SetTrialActivationMetadata(string key, string value) { int status; if (LexActivatorNative.IsWindows()) { status = IntPtr.Size == 4 ? LexActivatorNative.SetTrialActivationMetadata_x86(key, value) : LexActivatorNative.SetTrialActivationMetadata(key, value); } else { status = LexActivatorNative.SetTrialActivationMetadataA(key, value); } if (LexStatusCodes.LA_OK != status) { throw new LexActivatorException(status); } }
/// <summary> /// Gets the activation metadata. /// </summary> /// <param name="key">key to retrieve the value</param> /// <returns>Returns the value of metadata for the key.</returns> public static string GetActivationMetadata(string key) { var builder = new StringBuilder(256); int status; if (LexActivatorNative.IsWindows()) { status = IntPtr.Size == 4 ? LexActivatorNative.GetActivationMetadata_x86(key, builder, builder.Capacity) : LexActivatorNative.GetActivationMetadata(key, builder, builder.Capacity); } else { status = LexActivatorNative.GetActivationMetadataA(key, builder, builder.Capacity); } if (LexStatusCodes.LA_OK == status) { return(builder.ToString()); } throw new LexActivatorException(status); }
/// <summary> /// Sets the current app version of your application. /// /// The app version appears along with the activation details in dashboard. It /// is also used to generate app analytics. /// </summary> /// <param name="appVersion"></param> public static void SetAppVersion(string appVersion) { int status; if (LexActivatorNative.IsWindows()) { status = IntPtr.Size == 4 ? LexActivatorNative.SetAppVersion_x86(appVersion) : LexActivatorNative.SetAppVersion(appVersion); } else { status = LexActivatorNative.SetAppVersionA(appVersion); } if (LexStatusCodes.LA_OK != status) { throw new LexActivatorException(status); } }
/// <summary> /// Gets the meter attribute uses consumed by the activation. /// </summary> /// <param name="name"></param> /// <returns>Returns the value of meter attribute uses by the activation.</returns> public static uint GetActivationMeterAttributeUses(string name) { uint uses = 0; int status; if (LexActivatorNative.IsWindows()) { status = IntPtr.Size == 4 ? LexActivatorNative.GetActivationMeterAttributeUses_x86(name, ref uses) : LexActivatorNative.GetActivationMeterAttributeUses(name, ref uses); } else { status = LexActivatorNative.GetActivationMeterAttributeUsesA(name, ref uses); } if (LexStatusCodes.LA_OK == status) { return(uses); } throw new LexActivatorException(status); }
/// <summary> /// Activates your trial using the offline activation response file. /// </summary> /// <param name="filePath">path of the offline activation response file.</param> /// <returns>LA_OK, LA_TRIAL_EXPIRED, LA_FAIL</returns> public static int ActivateTrialOffline(string filePath) { int status; if (LexActivatorNative.IsWindows()) { status = IntPtr.Size == 4 ? LexActivatorNative.ActivateTrialOffline_x86(filePath) : LexActivatorNative.ActivateTrialOffline(filePath); } else { status = LexActivatorNative.ActivateTrialOfflineA(filePath); } switch (status) { case LexStatusCodes.LA_OK: return(LexStatusCodes.LA_OK); case LexStatusCodes.LA_TRIAL_EXPIRED: return(LexStatusCodes.LA_TRIAL_EXPIRED); case LexStatusCodes.LA_FAIL: return(LexStatusCodes.LA_FAIL); default: throw new LexActivatorException(status); } }