You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/MediaBrowser.Model/ApiClient/ServerInfo.cs

123 lines
3.4 KiB

using MediaBrowser.Model.Connect;
10 years ago
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.System;
10 years ago
using System;
using System.Collections.Generic;
10 years ago
using System.Linq;
namespace MediaBrowser.Model.ApiClient
{
public class ServerInfo
{
10 years ago
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; }
10 years ago
public String ManualAddress { get; set; }
public String UserId { get; set; }
public String AccessToken { get; set; }
public List<WakeOnLanInfo> WakeOnLanInfos { get; set; }
10 years ago
public DateTime DateLastAccessed { get; set; }
10 years ago
public String ExchangeToken { get; set; }
public UserLinkType? UserLinkType { get; set; }
10 years ago
public ConnectionMode? LastConnectionMode { get; set; }
public ServerInfo()
{
WakeOnLanInfos = new List<WakeOnLanInfo>();
10 years ago
Users = new List<ServerUserInfo>();
}
10 years ago
public void ImportInfo(PublicSystemInfo systemInfo)
{
Name = systemInfo.ServerName;
Id = systemInfo.Id;
10 years ago
if (!string.IsNullOrEmpty(systemInfo.LocalAddress))
10 years ago
{
LocalAddress = systemInfo.LocalAddress;
}
10 years ago
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
});
}
}
}
10 years ago
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");
}
}
10 years ago
public void AddOrUpdate(ServerUserInfo user)
{
if (user == null)
{
throw new ArgumentNullException("user");
}
var list = Users.ToList();
var index = FindIndex(list, user.Id);
if (index != -1)
{
var existing = list[index];
// Merge the data
existing.IsSignedInOffline = user.IsSignedInOffline;
10 years ago
}
else
{
list.Add(user);
}
Users = list;
}
private int FindIndex(List<ServerUserInfo> users, string id)
{
var index = 0;
foreach (var user in users)
{
if (StringHelper.Equals(id, user.Id))
{
return index;
}
index++;
}
return -1;
}
}
}