프로젝트

일반

사용자정보

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

markus / License / LicenseService.svc.cs @ master

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

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