领胜LDS 键盘AOI检测项目
xcd
2020-07-03 3cba54c4ee8d29d33ed21a2c749a9d2f2d03e22d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using Bro.Common.Helper;
using SuperDog;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
 
namespace AuthorityService
{
    public partial class AuthorityService : ServiceBase
    {
        public AuthorityService()
        {
            InitializeComponent();
        }
 
        Timer authorityCheckTimer = null;
        UdpClient client = null;
        const string OK = "AuthorityOK";
        const string NG = "AuthorityNG";
 
        LoggerHelper logHelper = null;
        protected override void OnStart(string[] args)
        {
            logHelper = new LoggerHelper(AppDomain.CurrentDomain.BaseDirectory, "AuthorityServiceLog");
 
            authorityCheckTimer = new Timer(OnAuthorityCheck, null, 1000 * 60, 1000 * 60);
 
            int port = 11001;
            if (!int.TryParse(ConfigurationManager.AppSettings["Port"], out port))
            {
                port = 11001;
            }
 
            client = new UdpClient(port);
            client.EnableBroadcast = true;
            client.BeginReceive(OnRequestReceived, null);
        }
 
        private void OnRequestReceived(IAsyncResult ar)
        {
            try
            {
                IPEndPoint remoteIP = null;
                var data = client.EndReceive(ar, ref remoteIP);
 
                if (System.Text.Encoding.UTF8.GetString(data) == "AuthorityCheck")
                {
                    var respond = System.Text.Encoding.UTF8.GetBytes(DogStatus == DogStatus.StatusOk ? OK : NG);
                    client.Send(respond, respond.Length, remoteIP);
                }
            }
            catch (Exception ex)
            {
                logHelper.LogAsync(DateTime.Now, "通信异常", ex.Message);
            }
            finally
            {
                client.BeginReceive(OnRequestReceived, null);
            }
        }
 
        DogStatus DogStatus = DogStatus.StatusOk;
        private void OnAuthorityCheck(object state)
        {
            try
            {
                DogFeature feature = new DogFeature(1);
                using (var dog = new Dog(feature))
                {
                    string vendorCodes = "FIgWctNxfC4kOOrFk52ktOm6JBRreMTI2ckQRUwjJmzstXN2awbyKGfjdlWcKFpjMiJRwirzPlJKSThN1nC7axSY4Y9l5+aRzCYI8WoYFmtx4zBx2n1fQ9Rb/CGk99Z9mM5mpZQVH+PGmZGsEjfSBdY12HjIcPVHGmMyecskMlhIGxDqUg8ndCk8/0fqexKbQCffDiGAPbxZgxKlRAnxJFOwd1V2Hmq3Iln1YNhyRRbgudU7kPCY/RsxBKXtL4wym96d2jQNDcKV8A5Anb4UlSLbac7OcrCZEBSUTpMjyDYRvDWFWTmfVKX9/vuI4VvKjr2t/wt01Nu0tQ0a4AVtQZk+l13WZkwkkeOUh6gtvVFJZH61hpwhOOjnN9dNw8WSYBYC/NyaMjiv7yRVHt9K/Bs76T8I0ias55BP1GXe6C+zGJ9KXK+baCLojMTObj3Bs9JFhDwEDgEjRDCxz9POZnE3XPe/2ET4KbRP5cXZsX7rxbnwQ33E/cKcG1hidG3RTLu7d+IRob9vgpeeUYXB8OHSoReJBsjhJEWBCDko9YnTb1FcO0YwPQdxW0BaVf1n6XAXlPUA6cGP552Kp3F0pcIxVKKGpYUeDL7oIFQrtnJ5aW7mB+/c35BDTCueM8wQIJ3b2KOI+lueC+dbhpHffVgtPnrh/atxcZxUoM2/KxjvniCYtUOKbeYh8Gqn1MDk1bAO2B9KNBrbGuWJpgDTfZunE/ZVtd09clExYJ8NW2Lw6pfNB3nbh1MlRUmmhQPIDubOnjiaBVbCQGF6Nm4/M0aIywSPJCMPaXK0sso5v+EDM4frryOPkvBEAbDyIuU+yQkO9vnYggKLAezyxZNxVqQgXcMaS0WyJxZxjFku7/Os8YU5z54DeOu6zDRD4zAjUKT7JIQcJKvtYGVB5lvirKDqISzDjsHcq4NJyQbQzg462y9o90ljUwCCMJrBmOw4NHpYKTNypN8aCsYmiebwag==";
                    DogStatus = dog.Login(vendorCodes, "<dogscope />");
                }
            }
            catch (Exception ex)
            {
                logHelper.LogAsync(DateTime.Now, "加密狗检测异常", ex.Message);
            }
        }
 
        protected override void OnStop()
        {
            authorityCheckTimer.Change(-1, -1);
            authorityCheckTimer.Dispose();
        }
    }
}