프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / License / LicenseService.svc.cs @ cf1cc862

이력 | 보기 | 이력해설 | 다운로드 (2.61 KB)

1 1305c420 taeseongkim
using Rhino.Licensing;
2
using System;
3
using System.Collections.Generic;
4
using System.Configuration;
5
using System.IO;
6
using System.Linq;
7
using System.Runtime.Serialization;
8
using System.ServiceModel;
9
using System.ServiceModel.Activation;
10
using System.ServiceModel.Web;
11
using System.Text;
12
13
namespace License
14
{
15
    public partial class LicenseService : license.iLicenseService
16
    {
17
        protected License.DB.DataBase database = new DB.DataBase();
18
19
        public LicenseService()
20
        {
21
            LicensingService.LicenseServerPrivateKey = Key.Data;
22
            LicensingService.SoftwarePublicKey = Key2.Data;
23
            Upload();
24
            //new StreamReader(typeof(LicenseService)
25
            //                                   .Assembly
26
            //                                   .GetManifestResourceStream("License.key.xml")).ReadToEnd();
27
28
            //LicensingService.SoftwarePublicKey = new StreamReader(typeof(LicenseService)
29
            //                                   .Assembly
30
            //                                   .GetManifestResourceStream("License.key.xml")).ReadToEnd();
31
        }
32
33
        public string GetLicense(string key, string machine, string Process, string user)
34
        {
35
            if (LicensingService.SoftwarePublicKey.Replace(System.Environment.NewLine, " ").Replace(" ", "") == key.Replace(System.Environment.NewLine, " ").Replace(" ", ""))
36
            {
37
                var guid = Guid.NewGuid();
38
                var generator = new LicenseGenerator(LicensingService.LicenseServerPrivateKey);
39
               
40
                var identifier = machine + @"\" + user + ": " + Process;
41
                var license = generator.Generate(identifier, guid, DateTime.MaxValue, LicenseType.Standard);
42
43
                database.Active(machine, Process, user, license);
44
45
                return license;
46
            }
47
            else
48
            {
49
                return null;
50
            }
51
        }
52
53
        public bool Validate(string key, string license)
54
        {
55
            try
56
            {
57
                var validator = new StringLicenseValidator(key, license);
58
         
59
                validator.AssertValidLicense();
60
                return true;
61
            }
62
            catch (Exception)
63
            {
64
                throw new FaultException("License Validate Error");
65
            }
66
        }
67
68
        public bool Upload()
69
        {
70
            var uri =  ConfigurationManager.AppSettings["UploadUri"];
71 cf1cc862 taeseongkim
            var siteName = ConfigurationManager.AppSettings["Site"];
72
           database.UploadAsync(new Uri(uri), siteName).ConfigureAwait(false);
73 1305c420 taeseongkim
74
            return true;
75
        }
76
    }
77
}
클립보드 이미지 추가 (최대 크기: 500 MB)