Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Tags: CSharp,ProtectedUserControl,UserControl,LicenseFile,LicenseValidationRequestInfo,EventArgs,SecureLicenseManager, Created At: 10/24/2016 8:26:15 PMViews:

HTML view:
Copy Source | Copy HTML
  1. // Adding the following attribute enables Visual Studio.NET designer license embedding support
  2.     [LicenseProvider(typeof(SecureLicenseManager))]
  3.     public class ProtectedUserControl : UserControl
  4.     {
  5.         ///Компонент Ð·Ð°Ñ‰Ð¸Ñ‚Ñ‹
  6.         private SecureLicense _license;
  7.  
  8.         /// <summary>
  9.         /// Ð‘азовая Ñ„ункция, Ð½ÑƒÐ¶Ð½Ð° Ð»Ð¸ Ð·Ð°Ñ‰Ð¸Ñ‚а?
  10.         /// Ð•ÑÐ»Ð¸ Ð½Ðµ Ð½Ð°Ñˆ ÑÐµÑ€Ð²ÐµÑ€, Ñ‚о Ð½ÑƒÐ¶Ð½Ð°!
  11.         /// </summary>
  12.         protected virtual Boolean NeedProtection
  13.         {
  14.             get
  15.             {
  16.                 return !Request.Url.Host.Contains("localhost");
  17.             }
  18.         }
  19.  
  20.         /// <summary>
  21.         /// ÐŸÐ¾ÐµÑ…ала Ð¸Ð½Ð¸Ñ†Ð¸Ð°Ð»Ð¸Ð·Ð°Ñ†Ð¸Ñ
  22.         /// </summary>
  23.         /// <param name="e"></param>
  24.         protected override void OnInit(EventArgs e)
  25.         {
  26.             base.OnInit(e);
  27.             if (NeedProtection)
  28.             {
  29.                 try
  30.                 {
  31.                     string keys_dir = Global.LicensePath;
  32.                     if(String.IsNullOrEmpty(keys_dir))
  33.                     {
  34.                         keys_dir = @"C:\Keys";
  35.                     }
  36.                     Exception e0 = null;
  37.                     foreach(string filename in Directory.GetFiles(keys_dir, "*.lic", SearchOption.TopDirectoryOnly))
  38.                     {
  39.                         LicenseFile file = new LicenseFile();
  40.                         file.Load(filename);
  41.                         if(file.Id != null)
  42.                         {
  43.                             LicenseValidationRequestInfo info = new LicenseValidationRequestInfo
  44.                                                                     {
  45.                                                                         LicenseFile = file,
  46.                                                                         SerialNumbers =
  47.                                                                             new[] {"DLXLENT-3TX1-2UQ8-87YR-647Y-16WS"}
  48.                                                                     };
  49.                             try
  50.                             {
  51.                                 _license = SecureLicenseManager.Validate(this, typeof (Components_Campaign), info);
  52.                                 //нашли Ñ€Ð°Ð±Ð¾Ñ‡ÑƒÑŽ Ð»Ð¸Ñ†ÐµÐ½Ð·Ð¸ÑŽ
  53.                                 e0 = null;
  54.                                 break;
  55.                             }catch(NoLicenseException nle)
  56.                             {
  57.                                 //если ÑÐ¾ÐµÐ´Ð¸Ð½Ð¸Ð»Ð¸ÑÑŒ, Ð½Ð¾ Ñ‡Ñ‚о-то Ð½Ð° ÑÑ‚ороне Ð»Ð¸Ñ†ÐµÐ½Ð·Ð¸Ð°Ñ€Ð° Ð¿Ð¾ÑˆÐ»Ð¾ Ð½Ðµ Ñ‚ак, Ñ‚о Ð¿Ð»ÑŽÐµÐ¼ Ð½Ð° ÑÑ‚о Ð´ÐµÐ»Ð¾
  58.                                 //if(nle.Message.Contains("Cannot validate license at server."))
  59.                                 if(nle.Message.Contains("The license is still encrypted and the internal properties cannot be accessed"))
  60.                                 {
  61.                                     break;
  62.                                 }
  63.                                 e0 = nle;
  64.                             }
  65.                             catch(Exception e1)
  66.                             {
  67.                                 e0 = e1;
  68.                             }
  69.                         }
  70.                     }
  71.                     if(e0!=null)
  72.                     {
  73.                         throw e0;
  74.                     }
  75.                 }
  76.                 catch (Exception e1)
  77.                 {
  78.                     Global.Logger.Error("licence", e1);
  79.                     State.GlobalError = e1.Message;
  80.                     Response.Redirect("~/PurchaseLicense.aspx");
  81.                 }
  82.             }
  83.         }
  84.  
  85.         public override void Dispose()
  86.         {
  87.             if (_license != null)
  88.                 _license.Dispose();
  89.  
  90.             base.Dispose();
  91.         }
  92.  
  93.     }

Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2017