make common project portable

pull/702/head
Luke Pulverenti 8 years ago
parent abc5a2eabd
commit 2af3ec43d5

@ -205,14 +205,14 @@ namespace MediaBrowser.Common.Implementations
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BaseApplicationHost{TApplicationPathsType}"/> class. /// Initializes a new instance of the <see cref="BaseApplicationHost{TApplicationPathsType}"/> class.
/// </summary> /// </summary>
protected BaseApplicationHost(TApplicationPathsType applicationPaths, protected BaseApplicationHost(TApplicationPathsType applicationPaths,
ILogManager logManager, ILogManager logManager,
IFileSystem fileSystem) IFileSystem fileSystem)
{ {
// hack alert, until common can target .net core // hack alert, until common can target .net core
BaseExtensions.CryptographyProvider = CryptographyProvider; BaseExtensions.CryptographyProvider = CryptographyProvider;
XmlSerializer = new XmlSerializer (fileSystem, logManager.GetLogger("XmlSerializer")); XmlSerializer = new XmlSerializer(fileSystem, logManager.GetLogger("XmlSerializer"));
FailedAssemblies = new List<string>(); FailedAssemblies = new List<string>();
ApplicationPaths = applicationPaths; ApplicationPaths = applicationPaths;
@ -396,13 +396,13 @@ namespace MediaBrowser.Common.Implementations
/// <returns>Task.</returns> /// <returns>Task.</returns>
public virtual Task RunStartupTasks() public virtual Task RunStartupTasks()
{ {
Resolve<ITaskManager>().AddTasks(GetExports<IScheduledTask>(false)); Resolve<ITaskManager>().AddTasks(GetExports<IScheduledTask>(false));
ConfigureAutorun (); ConfigureAutorun();
ConfigurationManager.ConfigurationUpdated += OnConfigurationUpdated; ConfigurationManager.ConfigurationUpdated += OnConfigurationUpdated;
return Task.FromResult (true); return Task.FromResult(true);
} }
/// <summary> /// <summary>
@ -438,7 +438,7 @@ namespace MediaBrowser.Common.Implementations
protected virtual void FindParts() protected virtual void FindParts()
{ {
RegisterModules(); RegisterModules();
ConfigurationManager.AddParts(GetExports<IConfigurationFactory>()); ConfigurationManager.AddParts(GetExports<IConfigurationFactory>());
Plugins = GetExports<IPlugin>().Select(LoadPlugin).Where(i => i != null).ToArray(); Plugins = GetExports<IPlugin>().Select(LoadPlugin).Where(i => i != null).ToArray();
} }
@ -462,6 +462,10 @@ namespace MediaBrowser.Common.Implementations
assemblyPlugin.SetAttributes(assemblyFilePath, assemblyFileName, assemblyName.Version, assemblyId); assemblyPlugin.SetAttributes(assemblyFilePath, assemblyFileName, assemblyName.Version, assemblyId);
} }
var isFirstRun = !File.Exists(plugin.ConfigurationFilePath);
plugin.SetStartupInfo(isFirstRun, File.GetLastWriteTimeUtc, s => Directory.CreateDirectory(s));
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -498,43 +502,43 @@ namespace MediaBrowser.Common.Implementations
/// <returns>Task.</returns> /// <returns>Task.</returns>
protected virtual Task RegisterResources(IProgress<double> progress) protected virtual Task RegisterResources(IProgress<double> progress)
{ {
RegisterSingleInstance(ConfigurationManager); RegisterSingleInstance(ConfigurationManager);
RegisterSingleInstance<IApplicationHost>(this); RegisterSingleInstance<IApplicationHost>(this);
RegisterSingleInstance<IApplicationPaths>(ApplicationPaths); RegisterSingleInstance<IApplicationPaths>(ApplicationPaths);
TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, LogManager.GetLogger("TaskManager"), FileSystemManager); TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, LogManager.GetLogger("TaskManager"), FileSystemManager);
RegisterSingleInstance(JsonSerializer); RegisterSingleInstance(JsonSerializer);
RegisterSingleInstance(XmlSerializer); RegisterSingleInstance(XmlSerializer);
RegisterSingleInstance(MemoryStreamProvider); RegisterSingleInstance(MemoryStreamProvider);
RegisterSingleInstance(LogManager); RegisterSingleInstance(LogManager);
RegisterSingleInstance(Logger); RegisterSingleInstance(Logger);
RegisterSingleInstance(TaskManager); RegisterSingleInstance(TaskManager);
RegisterSingleInstance(FileSystemManager); RegisterSingleInstance(FileSystemManager);
HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, LogManager.GetLogger("HttpClient"), FileSystemManager, MemoryStreamProvider); HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, LogManager.GetLogger("HttpClient"), FileSystemManager, MemoryStreamProvider);
RegisterSingleInstance(HttpClient); RegisterSingleInstance(HttpClient);
NetworkManager = CreateNetworkManager(LogManager.GetLogger("NetworkManager")); NetworkManager = CreateNetworkManager(LogManager.GetLogger("NetworkManager"));
RegisterSingleInstance(NetworkManager); RegisterSingleInstance(NetworkManager);
SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, LogManager); SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, LogManager);
RegisterSingleInstance(SecurityManager); RegisterSingleInstance(SecurityManager);
InstallationManager = new InstallationManager(LogManager.GetLogger("InstallationManager"), this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, ConfigurationManager, FileSystemManager); InstallationManager = new InstallationManager(LogManager.GetLogger("InstallationManager"), this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, ConfigurationManager, FileSystemManager);
RegisterSingleInstance(InstallationManager); RegisterSingleInstance(InstallationManager);
ZipClient = new ZipClient(FileSystemManager); ZipClient = new ZipClient(FileSystemManager);
RegisterSingleInstance(ZipClient); RegisterSingleInstance(ZipClient);
IsoManager = new IsoManager(); IsoManager = new IsoManager();
RegisterSingleInstance(IsoManager); RegisterSingleInstance(IsoManager);
return Task.FromResult (true); return Task.FromResult(true);
} }
private void RegisterModules() private void RegisterModules()
@ -583,7 +587,7 @@ namespace MediaBrowser.Common.Implementations
Logger.Error("LoaderException: " + loaderException.Message); Logger.Error("LoaderException: " + loaderException.Message);
} }
} }
// If it fails we can still get a list of the Types it was able to resolve // If it fails we can still get a list of the Types it was able to resolve
return ex.Types.Where(t => t != null); return ex.Types.Where(t => t != null);
} }

@ -13,8 +13,11 @@
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<ProductVersion>10.0.0</ProductVersion> <ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkProfile /> <TargetFrameworkProfile>
</TargetFrameworkProfile>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@ -42,11 +45,6 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="..\SharedVersion.cs"> <Compile Include="..\SharedVersion.cs">
<Link>Properties\SharedVersion.cs</Link> <Link>Properties\SharedVersion.cs</Link>
@ -83,8 +81,10 @@
<Name>MediaBrowser.Model</Name> <Name>MediaBrowser.Model</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <None Include="project.json" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent /> <PostBuildEvent />
</PropertyGroup> </PropertyGroup>

@ -61,8 +61,17 @@ namespace MediaBrowser.Common.Plugins
AssemblyFileName = assemblyFileName; AssemblyFileName = assemblyFileName;
Version = assemblyVersion; Version = assemblyVersion;
Id = assemblyId; Id = assemblyId;
}
private Func<string, DateTime> _dateModifiedFn;
private Action<string> _directoryCreateFn;
public void SetStartupInfo(bool isFirstRun, Func<string, DateTime> dateModifiedFn, Action<string> directoryCreateFn)
{
IsFirstRun = isFirstRun;
IsFirstRun = !File.Exists(ConfigurationFilePath); // hack alert, until the .net core transition is complete
_dateModifiedFn = dateModifiedFn;
_directoryCreateFn = directoryCreateFn;
} }
/// <summary> /// <summary>
@ -94,7 +103,7 @@ namespace MediaBrowser.Common.Plugins
// Ensure it's been lazy loaded // Ensure it's been lazy loaded
var config = Configuration; var config = Configuration;
return File.GetLastWriteTimeUtc(ConfigurationFilePath); return _dateModifiedFn(ConfigurationFilePath);
} }
} }
@ -147,14 +156,6 @@ namespace MediaBrowser.Common.Plugins
{ {
return (TConfigurationType)XmlSerializer.DeserializeFromFile(typeof(TConfigurationType), path); return (TConfigurationType)XmlSerializer.DeserializeFromFile(typeof(TConfigurationType), path);
} }
catch (DirectoryNotFoundException)
{
return (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType));
}
catch (FileNotFoundException)
{
return (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType));
}
catch catch
{ {
return (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType)); return (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType));
@ -182,10 +183,6 @@ namespace MediaBrowser.Common.Plugins
} }
} }
/// <summary>
/// The _data folder path
/// </summary>
private string _dataFolderPath;
/// <summary> /// <summary>
/// Gets the full path to the data folder, where the plugin can store any miscellaneous files needed /// Gets the full path to the data folder, where the plugin can store any miscellaneous files needed
/// </summary> /// </summary>
@ -194,16 +191,9 @@ namespace MediaBrowser.Common.Plugins
{ {
get get
{ {
if (_dataFolderPath == null) // Give the folder name the same name as the config file name
{ // We can always make this configurable if/when needed
// Give the folder name the same name as the config file name return Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(ConfigurationFileName));
// We can always make this configurable if/when needed
_dataFolderPath = Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(ConfigurationFileName));
Directory.CreateDirectory(_dataFolderPath);
}
return _dataFolderPath;
} }
} }
@ -230,7 +220,7 @@ namespace MediaBrowser.Common.Plugins
{ {
lock (_configurationSaveLock) lock (_configurationSaveLock)
{ {
Directory.CreateDirectory(Path.GetDirectoryName(ConfigurationFilePath)); _directoryCreateFn(Path.GetDirectoryName(ConfigurationFilePath));
XmlSerializer.SerializeToFile(Configuration, ConfigurationFilePath); XmlSerializer.SerializeToFile(Configuration, ConfigurationFilePath);
} }

@ -104,5 +104,7 @@ namespace MediaBrowser.Common.Plugins
/// Called when just before the plugin is uninstalled from the server. /// Called when just before the plugin is uninstalled from the server.
/// </summary> /// </summary>
void OnUninstalling(); void OnUninstalling();
void SetStartupInfo(bool isFirstRun, Func<string, DateTime> dateModifiedFn, Action<string> directoryCreateFn);
} }
} }

@ -0,0 +1,16 @@
{
"supports": {
"net46.app": {},
"uwp.10.0.app": {},
"dnxcore50.app": {}
},
"dependencies": {
"Microsoft.NETCore": "5.0.0",
"Microsoft.NETCore.Portable.Compatibility": "1.0.0"
},
"frameworks": {
"dotnet": {
"imports": "portable-net452+win81"
}
}
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save