|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace QuickPlay
|
|
|
|
|
{
|
|
|
|
|
#pragma warning disable CS0659 // This is basically an almost-singleton, which will never be put in any hash table.
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Application (global) configuration data class
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Serializable]
|
|
|
|
|
sealed class AppConfiguration
|
|
|
|
|
{
|
|
|
|
|
// XXX: All the fields need to be checked in overriden Equals method
|
|
|
|
|
public readonly string playerConfigUrl;
|
|
|
|
|
|
|
|
|
|
public static AppConfiguration loadSavedConfiguration()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void saveConfiguration()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure that the configuration is same
|
|
|
|
|
var newConfig = AppConfiguration.loadSavedConfiguration();
|
|
|
|
|
if (this != newConfig) throw new InvalidDataException("Saved configuration is different from the supplied one.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PlayerConfiguration GetPlayerConfig()
|
|
|
|
|
{
|
|
|
|
|
// TODO: decide sensibly
|
|
|
|
|
var cfgProvider = new CurlConfigurationProvider(playerConfigUrl);
|
|
|
|
|
return cfgProvider.GetConfiguration();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We want to compare by values.
|
|
|
|
|
// It might actually be a bit more sensible to compare serialized
|
|
|
|
|
// versions of the objects, but that seems unneccessarily hard.
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
|
|
|
|
var other = (AppConfiguration)obj;
|
|
|
|
|
// These fields have to match...
|
|
|
|
|
if (this.playerConfigUrl != other.playerConfigUrl) return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#pragma warning restore CS0659
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Configuration of the player.
|
|
|
|
|
///
|
|
|
|
|
/// Contains details about connection, configured songs &c.
|
|
|
|
|
/// </summary>
|
|
|
|
|
class PlayerConfiguration
|
|
|
|
|
{
|
|
|
|
|
public static PlayerConfiguration FromFile(StreamReader reader)
|
|
|
|
|
{
|
|
|
|
|
return null; // FIXME: Implement
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IPlayer GetPlayer()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IPlayerConfigurationProvider
|
|
|
|
|
{
|
|
|
|
|
PlayerConfiguration GetConfiguration();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sealed class CurlConfigurationProvider : IPlayerConfigurationProvider
|
|
|
|
|
{
|
|
|
|
|
readonly string configUrl;
|
|
|
|
|
public CurlConfigurationProvider(string url)
|
|
|
|
|
{
|
|
|
|
|
configUrl = url;
|
|
|
|
|
}
|
|
|
|
|
public PlayerConfiguration GetConfiguration()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sealed class FileConfigurationProvider : IPlayerConfigurationProvider
|
|
|
|
|
{
|
|
|
|
|
StreamReader reader;
|
|
|
|
|
public FileConfigurationProvider(StreamReader reader)
|
|
|
|
|
{
|
|
|
|
|
this.reader = reader;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FileConfigurationProvider(string filename)
|
|
|
|
|
{
|
|
|
|
|
this.reader = new StreamReader(filename);
|
|
|
|
|
}
|
|
|
|
|
public PlayerConfiguration GetConfiguration()
|
|
|
|
|
{
|
|
|
|
|
return PlayerConfiguration.FromFile(reader);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sealed class DummyConfigurationProvider : IPlayerConfigurationProvider
|
|
|
|
|
{
|
|
|
|
|
public PlayerConfiguration GetConfiguration() => null;
|
|
|
|
|
}
|
|
|
|
|
}
|