Tags: CSharp,ProtectedUserControl,UserControl,LicenseFile,LicenseValidationRequestInfo,EventArgs,SecureLicenseManager, Created At: 10/24/2016 8:26:15 PM, Views:
HTML view: Copy Source | Copy HTML- // Adding the following attribute enables Visual Studio.NET designer license embedding support
- [LicenseProvider(typeof(SecureLicenseManager))]
- public class ProtectedUserControl : UserControl
- {
- ///Компонент защиты
- private SecureLicense _license;
-
- /// <summary>
- /// Ð‘Ð°Ð·Ð¾Ð²Ð°Ñ Ñ„ÑƒÐ½ÐºÑ†Ð¸Ñ, нужна ли защита?
- /// ЕÑли не наш Ñервер, то нужна!
- /// </summary>
- protected virtual Boolean NeedProtection
- {
- get
- {
- return !Request.Url.Host.Contains("localhost");
- }
- }
-
- /// <summary>
- /// Поехала инициализациÑ
- /// </summary>
- /// <param name="e"></param>
- protected override void OnInit(EventArgs e)
- {
- base.OnInit(e);
- if (NeedProtection)
- {
- try
- {
- string keys_dir = Global.LicensePath;
- if(String.IsNullOrEmpty(keys_dir))
- {
- keys_dir = @"C:\Keys";
- }
- Exception e0 = null;
- foreach(string filename in Directory.GetFiles(keys_dir, "*.lic", SearchOption.TopDirectoryOnly))
- {
- LicenseFile file = new LicenseFile();
- file.Load(filename);
- if(file.Id != null)
- {
- LicenseValidationRequestInfo info = new LicenseValidationRequestInfo
- {
- LicenseFile = file,
- SerialNumbers =
- new[] {"DLXLENT-3TX1-2UQ8-87YR-647Y-16WS"}
- };
- try
- {
- _license = SecureLicenseManager.Validate(this, typeof (Components_Campaign), info);
- //нашли рабочую лицензию
- e0 = null;
- break;
- }catch(NoLicenseException nle)
- {
- //еÑли ÑоединилиÑÑŒ, но что-то на Ñтороне лицензиара пошло не так, то плюем на Ñто дело
- //if(nle.Message.Contains("Cannot validate license at server."))
- if(nle.Message.Contains("The license is still encrypted and the internal properties cannot be accessed"))
- {
- break;
- }
- e0 = nle;
- }
- catch(Exception e1)
- {
- e0 = e1;
- }
- }
- }
- if(e0!=null)
- {
- throw e0;
- }
- }
- catch (Exception e1)
- {
- Global.Logger.Error("licence", e1);
- State.GlobalError = e1.Message;
- Response.Redirect("~/PurchaseLicense.aspx");
- }
- }
- }
-
- public override void Dispose()
- {
- if (_license != null)
- _license.Dispose();
-
- base.Dispose();
- }
-
- }
|