Abstracted part of local providers data directory management.
This commit is contained in:
parent
42f4344501
commit
2aabe4d6c6
7 changed files with 80 additions and 33 deletions
|
@ -16,5 +16,5 @@ using System.Reflection;
|
||||||
//
|
//
|
||||||
// You can specify all the values or you can default the Revision and Build Numbers
|
// You can specify all the values or you can default the Revision and Build Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
[assembly: AssemblyVersion("3.0.4.568")]
|
[assembly: AssemblyVersion("3.0.4.569")]
|
||||||
[assembly: AssemblyFileVersion("3.0.4.568")]
|
[assembly: AssemblyFileVersion("3.0.4.569")]
|
|
@ -111,6 +111,7 @@
|
||||||
<Compile Include="AuthReader.cs" />
|
<Compile Include="AuthReader.cs" />
|
||||||
<Compile Include="Preferences.cs" />
|
<Compile Include="Preferences.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="ProviderBase.cs" />
|
||||||
<Compile Include="ProviderCollector.cs" />
|
<Compile Include="ProviderCollector.cs" />
|
||||||
<Compile Include="ProviderLoader.cs" />
|
<Compile Include="ProviderLoader.cs" />
|
||||||
<Compile Include="ProviderUpdater.cs" />
|
<Compile Include="ProviderUpdater.cs" />
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace ScrewTurn.Wiki {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implements a Local Files Storage Provider.
|
/// Implements a Local Files Storage Provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class FilesStorageProvider : IFilesStorageProviderV30 {
|
public class FilesStorageProvider : ProviderBase, IFilesStorageProviderV30 {
|
||||||
|
|
||||||
private readonly ComponentInformation info = new ComponentInformation("Local Files Provider",
|
private readonly ComponentInformation info = new ComponentInformation("Local Files Provider",
|
||||||
"Threeplicate Srl", Settings.WikiVersion, "http://www.screwturn.eu", null);
|
"Threeplicate Srl", Settings.WikiVersion, "http://www.screwturn.eu", null);
|
||||||
|
@ -30,7 +30,7 @@ namespace ScrewTurn.Wiki {
|
||||||
private IHostV30 host;
|
private IHostV30 host;
|
||||||
|
|
||||||
private string GetFullPath(string finalChunk) {
|
private string GetFullPath(string finalChunk) {
|
||||||
return Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), finalChunk);
|
return Path.Combine(GetDataDirectory(host), finalChunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -46,7 +46,7 @@ namespace ScrewTurn.Wiki {
|
||||||
|
|
||||||
this.host = host;
|
this.host = host;
|
||||||
|
|
||||||
if(!LocalProvidersTools.CheckWritePermissions(host.GetSettingValue(SettingName.PublicDirectory))) {
|
if(!LocalProvidersTools.CheckWritePermissions(GetDataDirectory(host))) {
|
||||||
throw new InvalidConfigurationException("Cannot write into the public directory - check permissions");
|
throw new InvalidConfigurationException("Cannot write into the public directory - check permissions");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ namespace ScrewTurn.Wiki {
|
||||||
private string BuildFullPath(string partialPath) {
|
private string BuildFullPath(string partialPath) {
|
||||||
if(partialPath == null) partialPath = "";
|
if(partialPath == null) partialPath = "";
|
||||||
partialPath = partialPath.Replace("/", Path.DirectorySeparatorChar.ToString()).TrimStart(Path.DirectorySeparatorChar);
|
partialPath = partialPath.Replace("/", Path.DirectorySeparatorChar.ToString()).TrimStart(Path.DirectorySeparatorChar);
|
||||||
string up = Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), UploadDirectory);
|
string up = Path.Combine(GetDataDirectory(host), UploadDirectory);
|
||||||
return CheckPath(Path.Combine(up, partialPath), up); // partialPath CANNOT start with "\" -> Path.Combine does not work
|
return CheckPath(Path.Combine(up, partialPath), up); // partialPath CANNOT start with "\" -> Path.Combine does not work
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ namespace ScrewTurn.Wiki {
|
||||||
private string BuildFullPathForAttachments(string partialPath) {
|
private string BuildFullPathForAttachments(string partialPath) {
|
||||||
if(partialPath == null) partialPath = "";
|
if(partialPath == null) partialPath = "";
|
||||||
partialPath = partialPath.Replace("/", Path.DirectorySeparatorChar.ToString()).TrimStart(Path.DirectorySeparatorChar);
|
partialPath = partialPath.Replace("/", Path.DirectorySeparatorChar.ToString()).TrimStart(Path.DirectorySeparatorChar);
|
||||||
string up = Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), AttachmentsDirectory);
|
string up = Path.Combine(GetDataDirectory(host), AttachmentsDirectory);
|
||||||
return CheckPath(Path.Combine(up, partialPath), up); // partialPath CANNOT start with "\" -> Path.Combine does not work
|
return CheckPath(Path.Combine(up, partialPath), up); // partialPath CANNOT start with "\" -> Path.Combine does not work
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace ScrewTurn.Wiki {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implements a Pages Storage Provider.
|
/// Implements a Pages Storage Provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PagesStorageProvider : IPagesStorageProviderV30 {
|
public class PagesStorageProvider : ProviderBase, IPagesStorageProviderV30 {
|
||||||
|
|
||||||
private const string NamespacesFile = "Namespaces.cs";
|
private const string NamespacesFile = "Namespaces.cs";
|
||||||
private const string PagesFile = "Pages.cs";
|
private const string PagesFile = "Pages.cs";
|
||||||
|
@ -40,15 +40,15 @@ namespace ScrewTurn.Wiki {
|
||||||
private IndexStorerBase indexStorer;
|
private IndexStorerBase indexStorer;
|
||||||
|
|
||||||
private string GetFullPath(string filename) {
|
private string GetFullPath(string filename) {
|
||||||
return Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), filename);
|
return Path.Combine(GetDataDirectory(host), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetFullPathForPageContent(string filename) {
|
private string GetFullPathForPageContent(string filename) {
|
||||||
return Path.Combine(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), PagesDirectory), filename);
|
return Path.Combine(Path.Combine(GetDataDirectory(host), PagesDirectory), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetFullPathForPageDrafts(string filename) {
|
private string GetFullPathForPageDrafts(string filename) {
|
||||||
return Path.Combine(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), DraftsDirectory), filename);
|
return Path.Combine(Path.Combine(GetDataDirectory(host), DraftsDirectory), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetDraftFullPath(LocalPageInfo page) {
|
private string GetDraftFullPath(LocalPageInfo page) {
|
||||||
|
@ -58,15 +58,15 @@ namespace ScrewTurn.Wiki {
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetFullPathForMessages(string filename) {
|
private string GetFullPathForMessages(string filename) {
|
||||||
return Path.Combine(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), MessagesDirectory), filename);
|
return Path.Combine(Path.Combine(GetDataDirectory(host), MessagesDirectory), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetFullPathForSnippets(string filename) {
|
private string GetFullPathForSnippets(string filename) {
|
||||||
return Path.Combine(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), SnippetsDirectory), filename);
|
return Path.Combine(Path.Combine(GetDataDirectory(host), SnippetsDirectory), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetFullPathForContentTemplate(string filename) {
|
private string GetFullPathForContentTemplate(string filename) {
|
||||||
return Path.Combine(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), ContentTemplatesDirectory), filename);
|
return Path.Combine(Path.Combine(GetDataDirectory(host), ContentTemplatesDirectory), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -92,24 +92,24 @@ namespace ScrewTurn.Wiki {
|
||||||
|
|
||||||
this.host = host;
|
this.host = host;
|
||||||
|
|
||||||
if(!LocalProvidersTools.CheckWritePermissions(host.GetSettingValue(SettingName.PublicDirectory))) {
|
if(!LocalProvidersTools.CheckWritePermissions(GetDataDirectory(host))) {
|
||||||
throw new InvalidConfigurationException("Cannot write into the public directory - check permissions");
|
throw new InvalidConfigurationException("Cannot write into the public directory - check permissions");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Directory.Exists(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), PagesDirectory))) {
|
if(!Directory.Exists(Path.Combine(GetDataDirectory(host), PagesDirectory))) {
|
||||||
Directory.CreateDirectory(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), PagesDirectory));
|
Directory.CreateDirectory(Path.Combine(GetDataDirectory(host), PagesDirectory));
|
||||||
}
|
}
|
||||||
if(!Directory.Exists(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), MessagesDirectory))) {
|
if(!Directory.Exists(Path.Combine(GetDataDirectory(host), MessagesDirectory))) {
|
||||||
Directory.CreateDirectory(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), MessagesDirectory));
|
Directory.CreateDirectory(Path.Combine(GetDataDirectory(host), MessagesDirectory));
|
||||||
}
|
}
|
||||||
if(!Directory.Exists(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), SnippetsDirectory))) {
|
if(!Directory.Exists(Path.Combine(GetDataDirectory(host), SnippetsDirectory))) {
|
||||||
Directory.CreateDirectory(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), SnippetsDirectory));
|
Directory.CreateDirectory(Path.Combine(GetDataDirectory(host), SnippetsDirectory));
|
||||||
}
|
}
|
||||||
if(!Directory.Exists(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), ContentTemplatesDirectory))) {
|
if(!Directory.Exists(Path.Combine(GetDataDirectory(host), ContentTemplatesDirectory))) {
|
||||||
Directory.CreateDirectory(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), ContentTemplatesDirectory));
|
Directory.CreateDirectory(Path.Combine(GetDataDirectory(host), ContentTemplatesDirectory));
|
||||||
}
|
}
|
||||||
if(!Directory.Exists(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), DraftsDirectory))) {
|
if(!Directory.Exists(Path.Combine(GetDataDirectory(host), DraftsDirectory))) {
|
||||||
Directory.CreateDirectory(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), DraftsDirectory));
|
Directory.CreateDirectory(Path.Combine(GetDataDirectory(host), DraftsDirectory));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool upgradeNeeded = false;
|
bool upgradeNeeded = false;
|
||||||
|
|
46
Core/ProviderBase.cs
Normal file
46
Core/ProviderBase.cs
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using ScrewTurn.Wiki.PluginFramework;
|
||||||
|
|
||||||
|
namespace ScrewTurn.Wiki {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Implements a base class for local file-based data providers.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class ProviderBase {
|
||||||
|
|
||||||
|
private object _syncLock = new object();
|
||||||
|
|
||||||
|
private bool _dataDirectoryAlreadyRead = false;
|
||||||
|
private string _dataDirectory = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the data directory.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dataDirectory">The data directory.</param>
|
||||||
|
protected void SetDataDirectory(string dataDirectory) {
|
||||||
|
lock(_syncLock) {
|
||||||
|
if(_dataDirectoryAlreadyRead) throw new InvalidOperationException("Cannot set data directory when it's already been read");
|
||||||
|
_dataDirectory = dataDirectory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the data directory.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="host">The host object.</param>
|
||||||
|
/// <returns>The data directory.</returns>
|
||||||
|
protected string GetDataDirectory(IHostV30 host) {
|
||||||
|
lock(_syncLock) {
|
||||||
|
_dataDirectoryAlreadyRead = true;
|
||||||
|
if(string.IsNullOrEmpty(_dataDirectory)) return host.GetSettingValue(SettingName.PublicDirectory);
|
||||||
|
else return _dataDirectory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -11,7 +11,7 @@ namespace ScrewTurn.Wiki {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implements a Settings Storage Provider against local text pluginAssemblies.
|
/// Implements a Settings Storage Provider against local text pluginAssemblies.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SettingsStorageProvider : ISettingsStorageProviderV30 {
|
public class SettingsStorageProvider : ProviderBase, ISettingsStorageProviderV30 {
|
||||||
|
|
||||||
// Filenames: Settings, Log, RecentChanges, MetaData
|
// Filenames: Settings, Log, RecentChanges, MetaData
|
||||||
private const string ConfigFile = "Config.cs";
|
private const string ConfigFile = "Config.cs";
|
||||||
|
@ -62,15 +62,15 @@ namespace ScrewTurn.Wiki {
|
||||||
private bool isFirstStart = false;
|
private bool isFirstStart = false;
|
||||||
|
|
||||||
private string GetFullPath(string name) {
|
private string GetFullPath(string name) {
|
||||||
return Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), name);
|
return Path.Combine(GetDataDirectory(host), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetFullPathForPlugin(string name) {
|
private string GetFullPathForPlugin(string name) {
|
||||||
return Path.Combine(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), PluginsDirectory), name);
|
return Path.Combine(Path.Combine(GetDataDirectory(host), PluginsDirectory), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetFullPathForPluginConfig(string name) {
|
private string GetFullPathForPluginConfig(string name) {
|
||||||
return Path.Combine(Path.Combine(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), PluginsDirectory), PluginsConfigDirectory), name);
|
return Path.Combine(Path.Combine(Path.Combine(GetDataDirectory(host), PluginsDirectory), PluginsConfigDirectory), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -86,7 +86,7 @@ namespace ScrewTurn.Wiki {
|
||||||
|
|
||||||
this.host = host;
|
this.host = host;
|
||||||
|
|
||||||
if(!LocalProvidersTools.CheckWritePermissions(host.GetSettingValue(SettingName.PublicDirectory))) {
|
if(!LocalProvidersTools.CheckWritePermissions(GetDataDirectory(host))) {
|
||||||
throw new InvalidConfigurationException("Cannot write into the public directory - check permissions");
|
throw new InvalidConfigurationException("Cannot write into the public directory - check permissions");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace ScrewTurn.Wiki {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implements a Users Storage Provider.
|
/// Implements a Users Storage Provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UsersStorageProvider : IUsersStorageProviderV30 {
|
public class UsersStorageProvider : ProviderBase, IUsersStorageProviderV30 {
|
||||||
|
|
||||||
private const string UsersFile = "Users.cs";
|
private const string UsersFile = "Users.cs";
|
||||||
private const string UsersDataFile = "UsersData.cs";
|
private const string UsersDataFile = "UsersData.cs";
|
||||||
|
@ -25,7 +25,7 @@ namespace ScrewTurn.Wiki {
|
||||||
private UserInfo[] usersCache = null;
|
private UserInfo[] usersCache = null;
|
||||||
|
|
||||||
private string GetFullPath(string filename) {
|
private string GetFullPath(string filename) {
|
||||||
return Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), filename);
|
return Path.Combine(GetDataDirectory(host), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -41,7 +41,7 @@ namespace ScrewTurn.Wiki {
|
||||||
|
|
||||||
this.host = host;
|
this.host = host;
|
||||||
|
|
||||||
if(!LocalProvidersTools.CheckWritePermissions(host.GetSettingValue(SettingName.PublicDirectory))) {
|
if(!LocalProvidersTools.CheckWritePermissions(GetDataDirectory(host))) {
|
||||||
throw new InvalidConfigurationException("Cannot write into the public directory - check permissions");
|
throw new InvalidConfigurationException("Cannot write into the public directory - check permissions");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue