Skip to content

Commit

Permalink
Added SampleCsWithLicense project
Browse files Browse the repository at this point in the history
  • Loading branch information
dalefugier committed Jan 29, 2018
1 parent a6db31c commit 7b58ef8
Show file tree
Hide file tree
Showing 7 changed files with 351 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cpp/SampleWithLicensing/SampleWithLicensingValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ CRhinoLicenseValidator::result CSampleWithLicensingValidator::VerifyLicenseKey(
license_key = L"SAMPLE-EVALUATION";
bEvaluation = true;
}
else if (license_key.Left(8).CompareNoCase(L"EVALUATION") == 0)
else if (license_key.Right(10).CompareNoCase(L"EVALUATION") == 0)
{
bEvaluation = true;
}
Expand Down
52 changes: 52 additions & 0 deletions rhinocommon/cs/SampleCsWithLicense/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Reflection;
using System.Runtime.InteropServices;
using Rhino.PlugIns;

// Plug-in Description Attributes - all of these are optional.
// These will show in Rhino's option dialog, in the tab Plug-ins.
[assembly: PlugInDescription(DescriptionType.Address, "3670 Woodland Park Avenue North\r\nSeattle, WA 98103")]
[assembly: PlugInDescription(DescriptionType.Country, "United States")]
[assembly: PlugInDescription(DescriptionType.Email, "[email protected]")]
[assembly: PlugInDescription(DescriptionType.Phone, "206-545-6877")]
[assembly: PlugInDescription(DescriptionType.Fax, "206-545-7321")]
[assembly: PlugInDescription(DescriptionType.Organization, "Robert McNeel & Associates")]
[assembly: PlugInDescription(DescriptionType.UpdateUrl, "https://github.com/mcneel/rhino-developer-samples")]
[assembly: PlugInDescription(DescriptionType.WebSite, "http://www.rhino3d.com/")]
[assembly: PlugInDescription(DescriptionType.Icon, "SampleCsWithLicense.Resources.SampleCs.ico")]


// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SampleCsWithLicense")]
[assembly: AssemblyDescription("RhinoCommon Sample - SampleCsWithLicense")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Robert McNeel & Associates")]
[assembly: AssemblyProduct("SampleCsCommands")]
[assembly: AssemblyCopyright("Copyright © 2018, Robert McNeel & Associates")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5deff610-a9c2-4922-92bc-ff6d3deb8d5e")] // This will also be the Guid of the Rhino plug-in

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("6.0.0.0")]
[assembly: AssemblyFileVersion("6.0.0.0")]

// Make compatible with Rhino Installer Engine
[assembly: AssemblyInformationalVersion("2")]
Binary file not shown.
88 changes: 88 additions & 0 deletions rhinocommon/cs/SampleCsWithLicense/SampleCsWithLicense.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{5DEFF610-A9C2-4922-92BC-FF6D3DEB8D5E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SampleCsWithLicense</RootNamespace>
<AssemblyName>SampleCsWithLicense</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<IsWebBootstrapper>false</IsWebBootstrapper>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="RhinoWindows">
<HintPath>C:\Program Files\Rhino 6\System\RhinoWindows.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="RhinoCommon">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files\Rhino 6\System\rhinocommon.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Eto">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files\Rhino 6\System\Eto.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Rhino.UI">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files\Rhino 6\System\Rhino.UI.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="SampleCsWithLicenseCommand.cs" />
<Compile Include="SampleCsWithLicensePlugIn.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\SampleCs.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<PostBuildEvent>Copy "$(TargetPath)" "$(TargetDir)$(ProjectName).rhp"
Erase "$(TargetPath)"</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<FallbackCulture>en-US</FallbackCulture>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartProgram>C:\Program Files\Rhino 6\System\Rhino.exe</StartProgram>
<StartArguments>
</StartArguments>
<StartAction>Program</StartAction>
</PropertyGroup>
</Project>
16 changes: 16 additions & 0 deletions rhinocommon/cs/SampleCsWithLicense/SampleCsWithLicenseCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Rhino;
using Rhino.Commands;

namespace SampleCsWithLicense
{
public class SampleCsWithLicenseCommand : Command
{
public override string EnglishName => "SampleCsWithLicense";

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
RhinoApp.WriteLine($"{0} plug-in loaded.", SampleCsWithLicensePlugIn.Instance.Name);
return Result.Success;
}
}
}
187 changes: 187 additions & 0 deletions rhinocommon/cs/SampleCsWithLicense/SampleCsWithLicensePlugIn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
using System;
using Rhino.PlugIns;
using Rhino.UI;

namespace SampleCsWithLicense
{
///<summary>
/// <para>Every RhinoCommon .rhp assembly must have one and only one PlugIn-derived
/// class. DO NOT create instances of this class yourself. It is the
/// responsibility of Rhino to create an instance of this class.</para>
/// <para>To complete plug-in information, please also see all PlugInDescription
/// attributes in AssemblyInfo.cs (you might need to click "Project" ->
/// "Show All Files" to see it in the "Solution Explorer" window).</para>
///</summary>
public class SampleCsWithLicensePlugIn : PlugIn
{
/// <summary>
/// Public constructor
/// </summary>
public SampleCsWithLicensePlugIn()
{
Instance = this;
}

/// <summary>
/// Gets the only instance of the SampleCsWithLicensePlugIn plug-in.
/// </summary>
public static SampleCsWithLicensePlugIn Instance
{
get; private set;
}

// You can override methods here to change the plug-in behavior on
// loading and shut down, add options pages to the Rhino _Option command
// and maintain plug-in wide options in a document.

/// <summary>
/// OnLoad override
/// </summary>
protected override LoadReturnCode OnLoad(ref string errorMessage)
{
var rc = GetLicense(Capabilities, TextMask, OnValidateProductKey, OnLeaseChanged);
if (!rc)
return LoadReturnCode.ErrorNoDialog;

return LoadReturnCode.Success;
}

#region Licensing Info

/// <summary>
/// Returns an icon to show in the License page in Options.
/// </summary>
private static System.Drawing.Icon ProductIcon
{
get
{
var size = RhinoWindows.Forms.Dpi.ScaleInt(32);
return DrawingUtilities.LoadIconWithScaleDown("SampleCsWithLicense.Resources.SampleCs.ico", size);
}
}

/// <summary>
/// In the event that the user needs to be asked for a license, then you can
/// provide a text mask, which helps the user to distinguish between proper
/// and improper user input of your license code. Note, if you do not want
/// to use a text mask, then pass in a null value for this parameter.
/// </summary>
private static string TextMask => ">S\\AMP\\LE-AAAAAAAAAA";

/// <summary>
/// Our hard-code evaluation license key.
/// </summary>
private static string EvalLicenseKey => "SAMPLE-EVALUATION";

/// <summary>
/// Controls the buttons that will appear on the license notification window that
// is displayed if a license for the requesting product is not found. Note, the
// "Close" button will always be displayed.
/// </summary>
private static LicenseCapabilities Capabilities => LicenseCapabilities.CanBeEvaluated |
LicenseCapabilities.CanBePurchased |
LicenseCapabilities.CanBeSpecified;

#endregion

#region Licensing delegates

/// <summary>
/// Validates a product key or license.
/// </summary>
/// <param name="licenseKey">The license key as input by the user.</param>
/// <param name="licenseData">The license data extracted by validating the license key.</param>
/// <returns>The results of the license validation.</returns>
private static ValidateResult OnValidateProductKey(string licenseKey, out LicenseData licenseData)
{
// Initialize output data
licenseData = new LicenseData
{
BuildType = LicenseBuildType.Release,
LicenseCount = 1,
ProductIcon = ProductIcon,
IsUpgradeFromPreviousVersion = false,
RequiresOnlineValidation = false // This sample current does not support Rhino accounts.
};

var evaluation = false;
if (string.IsNullOrEmpty(licenseKey))
{
licenseKey = EvalLicenseKey;
evaluation = true;
}
else if (licenseKey.IndexOf("EVALUATION", StringComparison.OrdinalIgnoreCase) > 0)
{
evaluation = true;
}

// Fill in the class members based on the license key and validation code.
// This value will never be display in any user interface.
// When your plugin's VerifyLicenseKey function is called, it is
// passed a a product, or CD, key that was entered into the Zoo
// administrator console. Your VerifyLicenseKey function will validate
// the product key and decode it into a product license. This is
// where you can store this license. This value will be passed
// to your application at runtime when it requests a license.
licenseData.ProductLicense = licenseKey;

// This value will display in user interface items, such as in
// the Zoo console and in About dialog boxes. Also, this value
// is used to uniquely identify this license. Thus, it is
// critical that this value be unique per product key, entered
// by the administrator. No other license of this product, as
// validated by this plugin, should return this value.
// TODO: provide an obfuscated license string here.
licenseData.SerialNumber = licenseKey;

// This value will display in user interface items, such as in
// the Zoo console and in About dialog boxes.
// (e.g. "Rhinoceros 6", "Rhinoceros 6 Commercial", etc.)
// TODO: provide a license title string here.
licenseData.LicenseTitle = Instance.Name;

// The Zoo supports licenses that expire. If your licensing scheme
// is sophisticated enough to support this, then specify the
// expiration date here. Note, this value must be specified in
// Coordinated Universal Time (UTC). If your license does not expire,
// then just this value to null.
if (evaluation)
{
var today = DateTime.UtcNow;
var expire = today.AddDays(90);
licenseData.DateToExpire = expire;
}

return ValidateResult.Success;
}

/// <summary>
/// Called by Rhino to signal that a lease from Rhino Accounts has changed.
/// If LicenseLeaseChangedEventArgs.Lease is null, then the server has signaled
/// that this product is no longer licensed. Your plug-in must change behavior
/// to behave appropriately.
/// </summary>
/// <param name="args">Data passed by Rhino when the lease changes</param>
/// <param name="icon">Icon to be displayed in Tools > Options > Licenses for this lease.</param>
private static void OnLeaseChanged(LicenseLeaseChangedEventArgs args, out System.Drawing.Icon icon)
{
icon = ProductIcon;

// This sample does not support Rhino accounts.

if (null == args.Lease)
{
// Lease has been voided; this product should behave as if it has no
// license. It is up to the plug-in to determine what that looks like.
}

// Verify that args.Lease.ProductId is correct
// Verify that args.Lease.ProductEdition is correct
// Verify that args.Lease.ProductVersion is correct
// Verify thatargs.Lease.IsExpired() is false
}

#endregion

}
}
8 changes: 7 additions & 1 deletion rhinocommon/cs/SamplesCs.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2008
VisualStudioVersion = 15.0.27130.2020
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleCsCommands", "SampleCsCommands\SampleCsCommands.csproj", "{C1498326-89AB-48B0-A148-290C169CAA68}"
EndProject
Expand Down Expand Up @@ -63,6 +63,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleCsWizardPanel", "Samp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleCsDockBar", "SampleCsDockBar\SampleCsDockBar.csproj", "{9C84103D-7C1B-4685-8763-129503FEE6B6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleCsWithLicense", "SampleCsWithLicense\SampleCsWithLicense.csproj", "{5DEFF610-A9C2-4922-92BC-FF6D3DEB8D5E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -177,6 +179,10 @@ Global
{9C84103D-7C1B-4685-8763-129503FEE6B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C84103D-7C1B-4685-8763-129503FEE6B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C84103D-7C1B-4685-8763-129503FEE6B6}.Release|Any CPU.Build.0 = Release|Any CPU
{5DEFF610-A9C2-4922-92BC-FF6D3DEB8D5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5DEFF610-A9C2-4922-92BC-FF6D3DEB8D5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5DEFF610-A9C2-4922-92BC-FF6D3DEB8D5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5DEFF610-A9C2-4922-92BC-FF6D3DEB8D5E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 7b58ef8

Please sign in to comment.