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

@@ -168,6 +168,7 @@ namespace MediaBrowser.Common.Kernel
if (!File.Exists(ApplicationPaths.SystemConfigurationFilePath))
{
Configuration = new TConfigurationType();
XmlSerializer.SerializeToFile(Configuration, ApplicationPaths.SystemConfigurationFilePath);
}
else
{

View File

@@ -24,7 +24,7 @@ namespace MediaBrowser.Common.Plugins
}
}
protected override Type ConfigurationType
public override Type ConfigurationType
{
get { return typeof(TConfigurationType); }
}
@@ -35,12 +35,12 @@ namespace MediaBrowser.Common.Plugins
/// </summary>
public abstract class BasePlugin : IDisposable
{
private IKernel Kernel { get; set; }
public IKernel IKernel { get; set; }
/// <summary>
/// Gets or sets the plugin's current context
/// </summary>
protected KernelContext Context { get { return Kernel.KernelContext; } }
protected KernelContext Context { get { return IKernel.KernelContext; } }
/// <summary>
/// Gets the name of the plugin
@@ -50,7 +50,7 @@ namespace MediaBrowser.Common.Plugins
/// <summary>
/// Gets the type of configuration this plugin uses
/// </summary>
protected abstract Type ConfigurationType { get; }
public abstract Type ConfigurationType { get; }
/// <summary>
/// Gets the plugin version
@@ -74,6 +74,8 @@ namespace MediaBrowser.Common.Plugins
}
}
public DateTime ConfigurationDateLastModified { get; private set; }
/// <summary>
/// Gets the path to the assembly file
/// </summary>
@@ -81,7 +83,7 @@ namespace MediaBrowser.Common.Plugins
{
get
{
return Path.Combine(Kernel.ApplicationPaths.PluginsPath, AssemblyFileName);
return Path.Combine(IKernel.ApplicationPaths.PluginsPath, AssemblyFileName);
}
}
@@ -102,7 +104,7 @@ namespace MediaBrowser.Common.Plugins
{
get
{
return Path.Combine(Kernel.ApplicationPaths.PluginConfigurationsPath, ConfigurationFileName);
return Path.Combine(IKernel.ApplicationPaths.PluginConfigurationsPath, ConfigurationFileName);
}
}
@@ -118,7 +120,7 @@ namespace MediaBrowser.Common.Plugins
{
// Give the folder name the same name as the config file name
// We can always make this configurable if/when needed
_DataFolderPath = Path.Combine(Kernel.ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(ConfigurationFileName));
_DataFolderPath = Path.Combine(IKernel.ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(ConfigurationFileName));
if (!Directory.Exists(_DataFolderPath))
{
@@ -154,7 +156,7 @@ namespace MediaBrowser.Common.Plugins
/// </summary>
public void Initialize(IKernel kernel)
{
Kernel = kernel;
IKernel = kernel;
ReloadConfiguration();
@@ -183,12 +185,14 @@ namespace MediaBrowser.Common.Plugins
if (!File.Exists(ConfigurationFilePath))
{
Configuration = Activator.CreateInstance(ConfigurationType) as BasePluginConfiguration;
XmlSerializer.SerializeToFile(Configuration, ConfigurationFilePath);
}
else
{
Configuration = XmlSerializer.DeserializeFromFile(ConfigurationType, ConfigurationFilePath) as BasePluginConfiguration;
Configuration.DateLastModified = File.GetLastWriteTime(ConfigurationFilePath);
}
ConfigurationDateLastModified = File.GetLastWriteTime(ConfigurationFilePath);
}
}
}

View File

@@ -52,6 +52,13 @@ namespace MediaBrowser.Common.Serialization
return ServiceStack.Text.JsonSerializer.DeserializeFromStream<T>(stream);
}
public static object DeserializeFromStream(Stream stream, Type type)
{
Configure();
return ServiceStack.Text.JsonSerializer.DeserializeFromStream(type, stream);
}
private static bool IsConfigured = false;
private static void Configure()
{

View File

@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
namespace MediaBrowser.Common.Serialization
{
@@ -19,11 +20,16 @@ namespace MediaBrowser.Common.Serialization
return ServiceStack.Text.TypeSerializer.DeserializeFromStream<T>(stream);
}
public static object DeserializeFromStream(Stream stream, Type type)
{
return ServiceStack.Text.TypeSerializer.DeserializeFromStream(type, stream);
}
public static void SerializeToFile<T>(T obj, string file)
{
using (Stream stream = File.Open(file, FileMode.Create))
{
ServiceStack.Text.TypeSerializer.SerializeToStream<T>(obj, stream);
SerializeToStream<T>(obj, stream);
}
}
@@ -31,7 +37,7 @@ namespace MediaBrowser.Common.Serialization
{
using (Stream stream = File.OpenRead(file))
{
return ServiceStack.Text.TypeSerializer.DeserializeFromStream<T>(stream);
return DeserializeFromStream<T>(stream);
}
}
}

View File

@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
namespace MediaBrowser.Common.Serialization
{
@@ -18,6 +19,11 @@ namespace MediaBrowser.Common.Serialization
return ProtoBuf.Serializer.Deserialize<T>(stream);
}
public static object DeserializeFromStream(Stream stream, Type type)
{
throw new NotImplementedException();
}
public static void SerializeToFile<T>(T obj, string file)
{
using (Stream stream = File.Open(file, FileMode.Create))

View File

@@ -39,6 +39,14 @@ namespace MediaBrowser.Common.Serialization
}
}
public static void SerializeToFile(object obj, string file)
{
using (FileStream stream = new FileStream(file, FileMode.Create))
{
ServiceStack.Text.XmlSerializer.SerializeToStream(obj, stream);
}
}
public static object DeserializeFromFile(Type type, string file)
{
using (Stream stream = File.OpenRead(file))