jellyfin/MediaBrowser.Model/ApiClient/ServerInfo.cs

127 lines
3.5 KiB
C#
Raw Normal View History

2014-10-29 18:17:31 -07:00
using MediaBrowser.Model.Connect;
2015-01-29 22:18:32 -07:00
using MediaBrowser.Model.Extensions;
2014-10-29 18:17:31 -07:00
using MediaBrowser.Model.System;
2014-10-26 20:06:01 -07:00
using System;
2014-10-02 20:48:59 -07:00
using System.Collections.Generic;
namespace MediaBrowser.Model.ApiClient
{
public class ServerInfo
{
2015-01-29 22:18:32 -07:00
public List<ServerUserInfo> Users { get; set; }
2014-10-02 20:48:59 -07:00
public String Name { get; set; }
public String Id { get; set; }
public String LocalAddress { get; set; }
public String RemoteAddress { get; set; }
2014-12-02 20:13:03 -07:00
public String ManualAddress { get; set; }
2014-10-02 20:48:59 -07:00
public String UserId { get; set; }
public String AccessToken { get; set; }
2014-10-03 18:42:38 -07:00
public List<WakeOnLanInfo> WakeOnLanInfos { get; set; }
2014-10-13 13:14:53 -07:00
public DateTime DateLastAccessed { get; set; }
2014-10-18 14:25:04 -07:00
public String ExchangeToken { get; set; }
2014-10-29 18:17:31 -07:00
public UserLinkType? UserLinkType { get; set; }
2014-12-02 20:13:03 -07:00
public ConnectionMode? LastConnectionMode { get; set; }
2014-11-13 23:27:10 -07:00
2014-10-02 20:48:59 -07:00
public ServerInfo()
{
2014-10-03 18:42:38 -07:00
WakeOnLanInfos = new List<WakeOnLanInfo>();
2015-01-29 22:18:32 -07:00
Users = new List<ServerUserInfo>();
2014-10-02 20:48:59 -07:00
}
2014-10-26 20:06:01 -07:00
public void ImportInfo(PublicSystemInfo systemInfo)
{
Name = systemInfo.ServerName;
Id = systemInfo.Id;
2014-12-02 20:13:03 -07:00
if (!string.IsNullOrEmpty(systemInfo.LocalAddress))
2014-10-26 20:06:01 -07:00
{
LocalAddress = systemInfo.LocalAddress;
}
2014-11-13 23:27:10 -07:00
2014-10-26 20:06:01 -07:00
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
});
}
}
}
2014-12-02 20:13:03 -07:00
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");
}
}
2015-01-29 22:18:32 -07:00
public void AddOrUpdate(ServerUserInfo user)
{
if (user == null)
{
throw new ArgumentNullException("user");
}
2015-03-27 13:55:31 -07:00
// Clone the existing list of users
var list = new List<ServerUserInfo>();
foreach (ServerUserInfo serverUserInfo in Users)
{
list.Add(serverUserInfo);
}
2015-01-29 22:18:32 -07:00
var index = FindIndex(list, user.Id);
if (index != -1)
{
var existing = list[index];
// Merge the data
existing.IsSignedInOffline = user.IsSignedInOffline;
2015-01-29 22:18:32 -07:00
}
else
{
list.Add(user);
}
Users = list;
}
private int FindIndex(List<ServerUserInfo> users, string id)
{
var index = 0;
foreach (var user in users)
{
2015-02-06 08:01:17 -07:00
if (StringHelper.EqualsIgnoreCase(id, user.Id))
2015-01-29 22:18:32 -07:00
{
return index;
}
index++;
}
return -1;
}
2014-10-02 20:48:59 -07:00
}
}