Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hibernating-rhinos/rhino-licensing
Browse files Browse the repository at this point in the history
  • Loading branch information
HEskandari committed Aug 15, 2010
2 parents 6b78c3c + 504845f commit cc63229
Show file tree
Hide file tree
Showing 14 changed files with 788 additions and 463 deletions.
941 changes: 503 additions & 438 deletions Rhino.Licensing/AbstractLicenseValidator.cs

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions Rhino.Licensing/FloatingLicenseNotAvialableException.cs
Expand Up @@ -3,22 +3,42 @@

namespace Rhino.Licensing
{
/// <summary>
///
/// </summary>
public class FloatingLicenseNotAvialableException : RhinoLicensingException
{
/// <summary>
/// Creates a new instance of <seealso cref="FloatingLicenseNotAvialableException"/>.
/// </summary>
public FloatingLicenseNotAvialableException()
{
}

/// <summary>
/// Creates a new instance of <seealso cref="FloatingLicenseNotAvialableException"/>.
/// </summary>
/// <param name="message">error message</param>
public FloatingLicenseNotAvialableException(string message)
: base(message)
{
}

/// <summary>
/// Creates a new instance of <seealso cref="FloatingLicenseNotAvialableException"/>.
/// </summary>
/// <param name="message">error message</param>
/// <param name="inner">inner exception</param>
public FloatingLicenseNotAvialableException(string message, Exception inner)
: base(message, inner)
{
}

/// <summary>
/// Creates a new instance of <seealso cref="FloatingLicenseNotAvialableException"/>.
/// </summary>
/// <param name="info">serialization information</param>
/// <param name="context">streaming context</param>
protected FloatingLicenseNotAvialableException(
SerializationInfo info,
StreamingContext context)
Expand Down
31 changes: 21 additions & 10 deletions Rhino.Licensing/ILicensingService.cs
@@ -1,11 +1,22 @@
using System;
using System.ServiceModel;
namespace Rhino.Licensing
{
[ServiceContract(SessionMode = SessionMode.NotAllowed)]
public interface ILicensingService
{
[OperationContract]
string LeaseLicense(string machine, string user, Guid id);
}
using System;
using System.ServiceModel;

namespace Rhino.Licensing
{
/// <summary>
/// Service contract of the licensing server.
/// </summary>
[ServiceContract(SessionMode = SessionMode.NotAllowed)]
public interface ILicensingService
{
/// <summary>
/// Issues a float license for the user.
/// </summary>
/// <param name="machine">machine name</param>
/// <param name="user">user name</param>
/// <param name="id">Id of the license holder</param>
/// <returns></returns>
[OperationContract]
string LeaseLicense(string machine, string user, Guid id);
}
}
28 changes: 18 additions & 10 deletions Rhino.Licensing/ISubscriptionLicensingService.cs
@@ -1,11 +1,19 @@
using System.ServiceModel;

namespace Rhino.Licensing
{
[ServiceContract]
public interface ISubscriptionLicensingService
{
[OperationContract]
string LeaseLicense(string previousLicense);
}
using System.ServiceModel;

namespace Rhino.Licensing
{
/// <summary>
/// Service contract of subscription server.
/// </summary>
[ServiceContract]
public interface ISubscriptionLicensingService
{
/// <summary>
/// Issues a leased license
/// </summary>
/// <param name="previousLicense"></param>
/// <returns></returns>
[OperationContract]
string LeaseLicense(string previousLicense);
}
}
10 changes: 10 additions & 0 deletions Rhino.Licensing/InvalidationType.cs
@@ -1,8 +1,18 @@
namespace Rhino.Licensing
{
/// <summary>
/// InvalidationType
/// </summary>
public enum InvalidationType
{
/// <summary>
/// Can not create a new license
/// </summary>
CannotGetNewLicense,

/// <summary>
/// License is expired
/// </summary>
TimeExpired
}
}
21 changes: 21 additions & 0 deletions Rhino.Licensing/LicenseFileNotFoundException.cs
Expand Up @@ -3,23 +3,44 @@

namespace Rhino.Licensing
{
/// <summary>
/// Thrown when a valid license file can not be
/// found on the client machine.
/// </summary>
[Serializable]
public class LicenseFileNotFoundException : RhinoLicensingException
{
/// <summary>
/// Creates a new instance of <seealso cref="LicenseFileNotFoundException"/>
/// </summary>
public LicenseFileNotFoundException()
{
}

/// <summary>
/// Creates a new instance of <seealso cref="LicenseFileNotFoundException"/>
/// </summary>
/// <param name="message">error message</param>
public LicenseFileNotFoundException(string message)
: base(message)
{
}

/// <summary>
/// Creates a new instance of <seealso cref="LicenseFileNotFoundException"/>
/// </summary>
/// <param name="message">error message</param>
/// <param name="inner">inner exception</param>
public LicenseFileNotFoundException(string message, Exception inner)
: base(message, inner)
{
}

/// <summary>
/// Creates a new instance of <seealso cref="LicenseFileNotFoundException"/>
/// </summary>
/// <param name="info">serialization information</param>
/// <param name="context">streaming context</param>
protected LicenseFileNotFoundException(
SerializationInfo info,
StreamingContext context) : base(info, context)
Expand Down
31 changes: 31 additions & 0 deletions Rhino.Licensing/LicenseGenerator.cs
Expand Up @@ -9,15 +9,28 @@

namespace Rhino.Licensing
{
/// <summary>
/// LicenseGenerator generates and signs license.
/// </summary>
public class LicenseGenerator
{
private readonly string privateKey;

/// <summary>
/// Creates a new instance of <seealso cref="LicenseGenerator"/>.
/// </summary>
/// <param name="privateKey">private key of the product</param>
public LicenseGenerator(string privateKey)
{
this.privateKey = privateKey;
}

/// <summary>
/// Generates a new floating license.
/// </summary>
/// <param name="name">Name of the license holder</param>
/// <param name="publicKey">public key of the license server</param>
/// <returns>license content</returns>
public string GenerateFloatingLicense(string name, string publicKey)
{
using (var rsa = new RSACryptoServiceProvider())
Expand Down Expand Up @@ -49,11 +62,29 @@ public string GenerateFloatingLicense(string name, string publicKey)
return new StreamReader(ms).ReadToEnd();
}
}

/// <summary>
/// Generates a new license
/// </summary>
/// <param name="name">name of the license holder</param>
/// <param name="id">Id of the license holder</param>
/// <param name="expirationDate">expiry date</param>
/// <param name="licenseType">type of the license</param>
/// <returns></returns>
public string Generate(string name, Guid id, DateTime expirationDate, LicenseType licenseType)
{
return Generate(name, id, expirationDate, new Dictionary<string, string>(), licenseType);
}

/// <summary>
/// Generates a new license
/// </summary>
/// <param name="name">name of the license holder</param>
/// <param name="id">Id of the license holder</param>
/// <param name="expirationDate">expiry date</param>
/// <param name="licenseType">type of the license</param>
/// <param name="attributes">extra information stored as key/valye in the license file</param>
/// <returns></returns>
public string Generate(string name, Guid id, DateTime expirationDate, IDictionary<string, string> attributes, LicenseType licenseType)
{
using (var rsa = new RSACryptoServiceProvider())
Expand Down
26 changes: 24 additions & 2 deletions Rhino.Licensing/LicenseNotFoundException.cs
Expand Up @@ -3,21 +3,43 @@

namespace Rhino.Licensing
{
/// <summary>
/// Thrown when suitable license is not found.
/// </summary>
[Serializable]
public class LicenseNotFoundException : RhinoLicensingException
{
/// <summary>
/// Creates a new instance of <seealso cref="LicenseNotFoundException"/>.
/// </summary>
public LicenseNotFoundException()
{
}

public LicenseNotFoundException(string message) : base(message)
/// <summary>
/// Creates a new instance of <seealso cref="LicenseNotFoundException"/>.
/// </summary>
/// <param name="message">error message</param>
public LicenseNotFoundException(string message)
: base(message)
{
}

public LicenseNotFoundException(string message, Exception inner) : base(message, inner)
/// <summary>
/// Creates a new instance of <seealso cref="LicenseNotFoundException"/>.
/// </summary>
/// <param name="message">error message</param>
/// <param name="inner">inner exception</param>
public LicenseNotFoundException(string message, Exception inner)
: base(message, inner)
{
}

/// <summary>
/// Creates a new instance of <seealso cref="LicenseNotFoundException"/>.
/// </summary>
/// <param name="info">serialization information</param>
/// <param name="context">steaming context</param>
protected LicenseNotFoundException(
SerializationInfo info,
StreamingContext context) : base(info, context)
Expand Down
26 changes: 26 additions & 0 deletions Rhino.Licensing/LicenseType.cs
@@ -1,12 +1,38 @@
namespace Rhino.Licensing
{
/// <summary>
/// License Type
/// </summary>
public enum LicenseType
{
/// <summary>
/// No type specified
/// </summary>
None,

/// <summary>
/// For trial use
/// </summary>
Trial,

/// <summary>
/// Standard license
/// </summary>
Standard,

/// <summary>
/// For personal use
/// </summary>
Personal,

/// <summary>
/// Floating license
/// </summary>
Floating,

/// <summary>
/// Subscription based license
/// </summary>
Subscription
}
}
25 changes: 25 additions & 0 deletions Rhino.Licensing/LicenseValidator.cs
Expand Up @@ -3,23 +3,42 @@

namespace Rhino.Licensing
{
/// <summary>
/// License validator validates a license file
/// that can be located on disk.
/// </summary>
public class LicenseValidator : AbstractLicenseValidator
{
private readonly string licensePath;
private string inMemoryLicense;

/// <summary>
/// Creates a new instance of <seealso cref="LicenseValidator"/>.
/// </summary>
/// <param name="publicKey">public key</param>
/// <param name="licensePath">path to license file</param>
public LicenseValidator(string publicKey, string licensePath)
: base(publicKey)
{
this.licensePath = licensePath;
}

/// <summary>
/// Creates a new instance of <seealso cref="LicenseValidator"/>.
/// </summary>
/// <param name="publicKey">public key</param>
/// <param name="licensePath">path to license file</param>
/// <param name="licenseServerUrl">license server endpoint address</param>
/// <param name="clientId">Id of the license holder</param>
public LicenseValidator(string publicKey, string licensePath, string licenseServerUrl, Guid clientId)
: base(publicKey, licenseServerUrl, clientId)
{
this.licensePath = licensePath;
}

/// <summary>
/// Gets or Sets the license content
/// </summary>
protected override string License
{
get
Expand All @@ -40,6 +59,9 @@ protected override string License
}
}

/// <summary>
/// Validates loaded license
/// </summary>
public override void AssertValidLicense()
{
if (File.Exists(licensePath) == false)
Expand All @@ -51,6 +73,9 @@ public override void AssertValidLicense()
base.AssertValidLicense();
}

/// <summary>
/// Removes existing license from the machine.
/// </summary>
public override void RemoveExistingLicense()
{
File.Delete(licensePath);
Expand Down

0 comments on commit cc63229

Please sign in to comment.