using System;
using System.Collections.Generic;
using TGS.Interface.Components;
namespace TGS.Interface
{
///
sealed class Server : IServer
{
///
public Version Version => serverInterface.ServerVersion;
///
public IEnumerable Instances { get
{
lock (this)
if (knownInstances == null)
knownInstances = serverInterface.GetComponent(null).ListInstances();
foreach (var I in knownInstances)
{
IInstance nextInstance;
try
{
nextInstance = new Instance(serverInterface, I);
}
catch
{
continue;
}
yield return nextInstance;
}
}
}
///
public ITGInstanceManager InstanceManager => UserIsAdministrator ? serverInterface.GetComponent(null) : null;
///
public ITGSService Management => UserIsAdministrator ? serverInterface.GetComponent(null) : null;
///
/// If the connected user is an administrator of the
///
bool UserIsAdministrator
{
get
{
lock (this)
{
if (isAdministrator)
return true;
try
{
serverInterface.GetComponent(null).Version();
isAdministrator = true;
return true;
}
catch
{
return false;
}
}
}
}
///
/// The backing
///
readonly Client serverInterface;
///
/// Result of a call to
///
IList knownInstances;
///
/// Backing field for
///
bool isAdministrator;
///
/// Construct an
///
/// The to use
public Server(Client _serverInterface)
{
serverInterface = _serverInterface;
}
///
public IInstance GetInstance(string name)
{
return new Instance(serverInterface, new InstanceMetadata { Name = name, Enabled = false });
}
}
}