blob: e1fa581d7b8a67625f577cd5a2a3150ef135b48d (
plain)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
using MediaBrowser.Model.Connect;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.System;
using System;
using System.Collections.Generic;
namespace MediaBrowser.Model.ApiClient
{
public class ServerInfo
{
public List<ServerUserInfo> Users { get; set; }
public String Name { get; set; }
public String Id { get; set; }
public String LocalAddress { get; set; }
public String RemoteAddress { get; set; }
public String ManualAddress { get; set; }
public String UserId { get; set; }
public String AccessToken { get; set; }
public List<WakeOnLanInfo> WakeOnLanInfos { get; set; }
public DateTime DateLastAccessed { get; set; }
public String ExchangeToken { get; set; }
public UserLinkType? UserLinkType { get; set; }
public ConnectionMode? LastConnectionMode { get; set; }
public ServerInfo()
{
WakeOnLanInfos = new List<WakeOnLanInfo>();
Users = new List<ServerUserInfo>();
}
public void ImportInfo(PublicSystemInfo systemInfo)
{
Name = systemInfo.ServerName;
Id = systemInfo.Id;
if (!string.IsNullOrEmpty(systemInfo.LocalAddress))
{
LocalAddress = systemInfo.LocalAddress;
}
if (!string.IsNullOrEmpty(systemInfo.WanAddress))
{
RemoteAddress = systemInfo.WanAddress;
}
var fullSystemInfo = systemInfo as SystemInfo;
if (fullSystemInfo != null)
{
WakeOnLanInfos = new List<WakeOnLanInfo>();
if (!string.IsNullOrEmpty(fullSystemInfo.MacAddress))
{
WakeOnLanInfos.Add(new WakeOnLanInfo
{
MacAddress = fullSystemInfo.MacAddress
});
}
}
}
public string GetAddress(ConnectionMode mode)
{
switch (mode)
{
case ConnectionMode.Local:
return LocalAddress;
case ConnectionMode.Manual:
return ManualAddress;
case ConnectionMode.Remote:
return RemoteAddress;
default:
throw new ArgumentException("Unexpected ConnectionMode");
}
}
public void AddOrUpdate(ServerUserInfo user)
{
if (user == null)
{
throw new ArgumentNullException("user");
}
// Clone the existing list of users
var list = new List<ServerUserInfo>();
foreach (ServerUserInfo serverUserInfo in Users)
{
list.Add(serverUserInfo);
}
var index = FindIndex(list, user.Id);
if (index != -1)
{
var existing = list[index];
// Merge the data
existing.IsSignedInOffline = user.IsSignedInOffline;
}
else
{
list.Add(user);
}
Users = list;
}
private int FindIndex(List<ServerUserInfo> users, string id)
{
var index = 0;
foreach (var user in users)
{
if (StringHelper.EqualsIgnoreCase(id, user.Id))
{
return index;
}
index++;
}
return -1;
}
}
}
|