markus / Rhino.Licensing / LicenseValidator.cs @ 42d49521
이력 | 보기 | 이력해설 | 다운로드 (2.71 KB)
1 |
using System; |
---|---|
2 |
using System.IO; |
3 |
|
4 |
namespace Rhino.Licensing |
5 |
{ |
6 |
/// <summary> |
7 |
/// License validator validates a license file |
8 |
/// that can be located on disk. |
9 |
/// </summary> |
10 |
public class LicenseValidator : AbstractLicenseValidator |
11 |
{ |
12 |
private readonly string licensePath; |
13 |
private string inMemoryLicense; |
14 |
|
15 |
/// <summary> |
16 |
/// Creates a new instance of <seealso cref="LicenseValidator"/>. |
17 |
/// </summary> |
18 |
/// <param name="publicKey">public key</param> |
19 |
/// <param name="licensePath">path to license file</param> |
20 |
public LicenseValidator(string publicKey, string licensePath) |
21 |
: base(publicKey) |
22 |
{ |
23 |
this.licensePath = licensePath; |
24 |
} |
25 |
|
26 |
/// <summary> |
27 |
/// Creates a new instance of <seealso cref="LicenseValidator"/>. |
28 |
/// </summary> |
29 |
/// <param name="publicKey">public key</param> |
30 |
/// <param name="licensePath">path to license file</param> |
31 |
/// <param name="licenseServerUrl">license server endpoint address</param> |
32 |
/// <param name="clientId">Id of the license holder</param> |
33 |
public LicenseValidator(string publicKey, string licensePath, string licenseServerUrl, Guid clientId) |
34 |
: base(publicKey, licenseServerUrl, clientId) |
35 |
{ |
36 |
this.licensePath = licensePath; |
37 |
} |
38 |
|
39 |
/// <summary> |
40 |
/// Gets or Sets the license content |
41 |
/// </summary> |
42 |
protected override string License |
43 |
{ |
44 |
get |
45 |
{ |
46 |
|
47 |
return inMemoryLicense ?? File.ReadAllText(licensePath); |
48 |
} |
49 |
set |
50 |
{ |
51 |
try |
52 |
{ |
53 |
File.WriteAllText(licensePath, value); |
54 |
} |
55 |
catch (Exception e) |
56 |
{ |
57 |
inMemoryLicense = value; |
58 |
System.Diagnostics.Debug.WriteLine("Could not write new license value, using in memory model instead", e); |
59 |
//Log.Warn("Could not write new license value, using in memory model instead", e); |
60 |
} |
61 |
} |
62 |
} |
63 |
|
64 |
/// <summary> |
65 |
/// Validates loaded license |
66 |
/// </summary> |
67 |
public override void AssertValidLicense() |
68 |
{ |
69 |
if (File.Exists(licensePath) == false) |
70 |
{ |
71 |
//Log.WarnFormat("Could not find license file: {0}", licensePath); |
72 |
throw new LicenseFileNotFoundException(); |
73 |
} |
74 |
|
75 |
base.AssertValidLicense(); |
76 |
} |
77 |
|
78 |
/// <summary> |
79 |
/// Removes existing license from the machine. |
80 |
/// </summary> |
81 |
public override void RemoveExistingLicense() |
82 |
{ |
83 |
File.Delete(licensePath); |
84 |
} |
85 |
} |
86 |
} |