Tweaked plugin downloading a bit

This commit is contained in:
LukePulverenti Luke Pulverenti luke pulverenti
2012-09-03 17:56:30 -04:00
parent 7f8a477278
commit fc735e9187
11 changed files with 91 additions and 23 deletions

View File

@@ -590,15 +590,34 @@ namespace MediaBrowser.ApiInteraction
}
/// <summary>
/// Gets weather information for the default location as set in configuration
/// Gets the current server configuration
/// </summary>
public async Task<ServerConfiguration> GetServerConfigurationAsync()
{
string url = ApiUrl + "/ServerConfiguration";
using (Stream stream = await GetSerializedStreamAsync(url, ApiInteraction.SerializationFormat.Json).ConfigureAwait(false))
// At the moment this can't be retrieved in protobuf format
SerializationFormat format = DataSerializer.CanDeserializeJsv ? SerializationFormat.Jsv : ApiInteraction.SerializationFormat.Json;
using (Stream stream = await GetSerializedStreamAsync(url, format).ConfigureAwait(false))
{
return DeserializeFromStream<ServerConfiguration>(stream, ApiInteraction.SerializationFormat.Json);
return DeserializeFromStream<ServerConfiguration>(stream, format);
}
}
/// <summary>
/// Gets weather information for the default location as set in configuration
/// </summary>
public async Task<object> GetPluginConfigurationAsync(PluginInfo plugin, Type configurationType)
{
string url = ApiUrl + "/PluginConfiguration?assemblyfilename=" + plugin.AssemblyFileName;
// At the moment this can't be retrieved in protobuf format
SerializationFormat format = DataSerializer.CanDeserializeJsv ? SerializationFormat.Jsv : ApiInteraction.SerializationFormat.Json;
using (Stream stream = await GetSerializedStreamAsync(url, format).ConfigureAwait(false))
{
return DeserializeFromStream(stream, format, configurationType);
}
}
@@ -685,6 +704,20 @@ namespace MediaBrowser.ApiInteraction
return DataSerializer.DeserializeJsonFromStream<T>(stream);
}
private object DeserializeFromStream(Stream stream, SerializationFormat format, Type type)
{
if (format == ApiInteraction.SerializationFormat.Protobuf)
{
return DataSerializer.DeserializeProtobufFromStream(stream, type);
}
if (format == ApiInteraction.SerializationFormat.Jsv)
{
return DataSerializer.DeserializeJsvFromStream(stream, type);
}
return DataSerializer.DeserializeJsonFromStream(stream, type);
}
/// <summary>
/// This is just a helper around HttpClient
/// </summary>

View File

@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
namespace MediaBrowser.ApiInteraction
{
@@ -11,6 +12,10 @@ namespace MediaBrowser.ApiInteraction
T DeserializeJsvFromStream<T>(Stream stream);
T DeserializeProtobufFromStream<T>(Stream stream);
object DeserializeJsonFromStream(Stream stream, Type type);
object DeserializeJsvFromStream(Stream stream, Type type);
object DeserializeProtobufFromStream(Stream stream, Type type);
bool CanDeserializeJsv { get; }
bool CanDeserializeProtobuf { get; }
}