프로젝트

일반

사용자정보

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

markus / License / LicenseService.svc.cs @ master

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

1
using log4net;
2
using Rhino.Licensing;
3
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
        ILog log = log4net.LogManager.GetLogger(typeof(LicenseService));
19
        protected License.DB.DataBase database = new DB.DataBase();
20

    
21
        public LicenseService()
22
        {
23
            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
            //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
            string result = null;
49

    
50
            try
51
            {
52
                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
               
57
                    var identifier = machine + @"\" + user + ": " + Process;
58
                    var license = generator.Generate(identifier, guid, DateTime.MaxValue, LicenseType.Standard);
59

    
60
                    database.Active(machine, Process, user, license);
61

    
62
                    result = license;
63

    
64
                    log.Info("GetLicense : " + license);
65
                }
66
            }
67
            catch (Exception ex)
68
            {
69
                log.Error(ex);
70
            }
71

    
72
            return result;
73
        }
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
            catch (Exception ex)
85
            {
86
                log.Error(ex);
87
                throw new FaultException("License Validate Error");
88
            }
89
        }
90

    
91
        public bool Upload()
92
        {
93
            var uri = ConfigurationManager.AppSettings["UploadUri"];
94
            var siteName = ConfigurationManager.AppSettings["Site"];
95

    
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

    
106
            return true;
107
        }
108
    }
109
}
클립보드 이미지 추가 (최대 크기: 500 MB)