licensemanager.cs
来自「该源代码用 C# 写成」· CS 代码 · 共 103 行
CS
103 行
using System;
namespace Org.InteliIM.Configurations
{
/// <summary>
/// Description of LicenseManager.
/// </summary>
public class LicenseManager
{
public LicenseManager()
{
}
public LicenseManager(Preference preference)
{
this.Preference = preference;
}
private Preference preference;
public Preference Preference
{
get { return this.preference; }
set { this.preference = value; }
}
private LicenseState licenseState = LicenseState.Tryout;
public LicenseState LicenseState
{
get
{
this.Verify();
return this.licenseState;
}
set
{
if (this.licenseState != value)
{
this.licenseState = value;
this.OnLicenseStateChanged();
}
}
}
public bool Pass(string userName, string registrationCode)
{
this.Preference["License.UserName"] = userName;
this.Preference["License.RegistrationCode"] = registrationCode;
return true;
}
public string UserName
{
get { return this.Preference["License.UserName"]; }
}
public string RegistrationCode
{
get { return this.Preference["License.RegistrationCode"]; }
}
public void Verify()
{
this.Preference.Load();
string userName = this.Preference["License.UserName"];
string registrationCode = this.Preference["License.RegistrationCode"];
if (userName != null && userName != ""
&& registrationCode != null && registrationCode != ""
&& userName == registrationCode)
{
this.LicenseState = LicenseState.HasBought;
this.Preference.Save();
return;
}
if ((DateTime.Now.Subtract(DateTime.Parse("1-30-2005"))).Days > 0)
{
this.LicenseState = LicenseState.Expired;
}
}
public void OnLicenseStateChanged()
{
if (this.LicenseStateChanged != null)
this.LicenseStateChanged(null, null);
}
public event EventHandler LicenseStateChanged;
}
public enum LicenseState
{
HasBought,
Tryout,
Expired
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?