-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaxtonClient.cs
More file actions
76 lines (60 loc) · 2.52 KB
/
Copy pathPaxtonClient.cs
File metadata and controls
76 lines (60 loc) · 2.52 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using Paxton.Net2.OemClientLibrary;
using PaxtonSync.Properties;
namespace PaxtonSync
{
internal class PaxtonClient : IDisposable
{
private const int _remotePort = 8025;
private const string _remoteHost = "localhost";
private readonly OemClient _net2Client;
public PaxtonClient()
{
_net2Client = _CreateClient();
_Login();
}
private void _Login()
{
var users = _net2Client
.GetListOfOperators()
.UsersDictionary()
.Where(pair => pair.Value == Settings.Default.PaxtonUser)
.ToArray();
if (!users.Any())
throw new Exception("Paxton user not found.");
var userId = users.Single().Key;
var methodList = _net2Client.AuthenticateUser(userId, Settings.Default.PaxtonPass);
if (methodList == null)
throw new Exception("Can't log onto Paxton.");
}
private static OemClient _CreateClient()
{
var net2Client = new OemClient(_remoteHost, _remotePort);
if (net2Client.LastErrorMessage != null)
throw new Exception(net2Client.LastErrorMessage);
return net2Client;
}
public void Dispose()
{
_net2Client.Dispose();
}
public IUsers ViewUserRecords()
{
return _net2Client.ViewUserRecords();
}
public void UpdateUserRecord(int userId, int accessLevelId, int departmentId, bool antiPassbackInd, bool alarmUserInd, string firstName, string middleName, string surname, string telephoneNo, string telephoneExtension, string pinCode, string pictureFileName, DateTime activationDate, bool activeInd, string faxNo, DateTime expiryDate, string[] customFields)
{
var result = _net2Client.UpdateUserRecord(userId, accessLevelId, departmentId, antiPassbackInd, alarmUserInd, firstName, middleName, surname, telephoneNo, telephoneExtension, pinCode, pictureFileName, activationDate, activeInd, faxNo, expiryDate, customFields);
if (!result)
throw new Exception(_net2Client.LastErrorMessage);
}
public void AddUserRecord(int accessLevelId, int departmentId, string firstName, string surname, string[] customFields)
{
var result = _net2Client.AddUserRecord(accessLevelId, departmentId, antiPassbackInd: false, alarmUserInd: false, firstName: firstName, middleName: null, surname: surname, telephoneNo: null, telephoneExtension: null, pinCode: null, pictureFileName: null, activationDate: DateTime.UtcNow, cardNumber: 0, cardTypeId: 0, active: true, faxNo: null, expiryDate: DateTime.MinValue, customFields: customFields);
if (!result)
throw new Exception(_net2Client.LastErrorMessage);
}
}
}