Пример #1
0
 /// <summary>
 /// Indicates whether a LicenseData object is not null and valid.
 /// </summary>
 public static bool IsValid(LicenseData data)
 {
   if (null != data && data.IsValid())
     return true;
   return false;
 }
Пример #2
0
      /// <summary>
      /// Passed as a delegate to LicenseUtils.GetLicense(), will call the C++
      /// ValidateProductKey() method then and copy CRhinoLicenseValidator C++
      /// data to the LicenseData output object.
      /// </summary>
      /// <param name="productKey"></param>
      /// <param name="licenseData">
      /// Key information is coppied to this object
      /// </param>
      /// <returns></returns>
      public ValidateResult ValidateProductKey(string productKey, out LicenseData licenseData)
      {
        // Create an empty LicenseData
        licenseData = new LicenseData();
        var rc = 0;
        // Call back into the C++ unmanaged function pointer
        if (IntPtr.Zero != _validator)
          rc = UnsafeNativeMethods.RHC_ValidateProductKey(productKey, _validator);
        if (rc != 1)
          return (-1 == rc ? ValidateResult.ErrorHideMessage : ValidateResult.ErrorShowMessage);
        // Copy unmanaged C++ validate data to the managed LicenseData
        var year = 0;
        var month = 0;
        var day = 0;
        var hour = 0;
        var minute = 0;
        var second = 0;
        var licenseCount = 0;
        var buildType = 0;
        IntPtr hIcon;
        // String placeholders
        using (var shSerailNumber = new StringHolder())
        using (var shLicenseTitle = new StringHolder())
        using (var shProductLicense = new StringHolder())
        {
          // Get ON_wString pointers
          var pSerialNumber = shSerailNumber.NonConstPointer();
          var pLicenseTitle = shLicenseTitle.NonConstPointer();
          var pProductLicense = shProductLicense.NonConstPointer();
          hIcon = UnsafeNativeMethods.RHC_ExtractLicenseData(_validator,
                                                             ref year,
                                                             ref month,
                                                             ref day,
                                                             ref hour,
                                                             ref minute,
                                                             ref second,
                                                             pSerialNumber,
                                                             ref licenseCount,
                                                             pLicenseTitle,
                                                             pProductLicense,
                                                             ref buildType);
          // Copy ON_wString values to C# strings
          licenseData.SerialNumber = shSerailNumber.ToString();
          licenseData.LicenseTitle = shLicenseTitle.ToString();
          licenseData.ProductLicense = shProductLicense.ToString();
        }
        // Set the expiration date using the C++ date data
        if (year >= 2010)
          licenseData.DateToExpire = new DateTime(year, month, day, hour, minute, second);
        licenseData.LicenseCount = licenseCount;
        licenseData.BuildType = (LicenseBuildType)buildType;
        // Icon associated with the specified license type
        if (hIcon != IntPtr.Zero)
        {
          // Create a new icon from the handle.
          var newIcon = System.Drawing.Icon.FromHandle(hIcon);

          // Set the LicenseData icon. Note, LicenseData creates it's own copy of the icon.
          licenseData.ProductIcon = newIcon;

          // When using Icon::FromHandle, you must dispose of the original icon by using the
          // DestroyIcon method in the Win32 API to ensure that the resources are released.
          DestroyIcon(newIcon.Handle);
        }

        return ValidateResult.Success;
      }