Getting setup to save real info for site settings and changing the default settings name to "default"

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-02-09 14:25:38 -08:00
parent 837f5a444e
commit d976e75a09
5 changed files with 58 additions and 28 deletions

View File

@@ -58,9 +58,8 @@ namespace Orchard.Tests.Environment {
return _shellSettings.AsEnumerable();
}
public bool SaveSettings(IShellSettings settings) {
public void SaveSettings(IShellSettings settings) {
_shellSettings.Add(settings);
return true;
}
}

View File

@@ -45,18 +45,22 @@ namespace Orchard.Setup.Controllers {
return Index(model);
}
var shellSettings = new ShellSettings {
Name = "default",
DataProvider = model.DatabaseOptions ? "SQLite" : "SqlServer",
DataFolder = Server.MapPath("~/App_Data"),
DataConnectionString = model.DatabaseConnectionString
};
// initialize the database:
// provider: SqlServer or SQLite
// dataFolder: physical path (map before calling). Builtin database will be created in this location
// connectionString: optional - if provided the dataFolder is essentially ignored, but should still be passed in
_databaseMigrationManager.CreateCoordinator(model.DatabaseOptions ? "SQLite" : "SqlServer", Server.MapPath("~/App_Data"), model.DatabaseConnectionString);
_databaseMigrationManager.CreateCoordinator(shellSettings.DataProvider, shellSettings.DataFolder, shellSettings.DataConnectionString);
// creating a standalone environment.
// in theory this environment can be used to resolve any normal components by interface, and those
// components will exist entirely in isolation - no crossover between the safemode container currently in effect
var shellSettings = new ShellSettings { Name = "temp" };
using (var finiteEnvironment = _orchardHost.CreateStandaloneEnvironment(shellSettings)) {
var contentManager = finiteEnvironment.Resolve<IContentManager>();
@@ -83,13 +87,9 @@ namespace Orchard.Setup.Controllers {
var authenticationService = finiteEnvironment.Resolve<IAuthenticationService>();
authenticationService.SignIn(user, true);
}
if (!_shellSettingsLoader.SaveSettings(shellSettings)) {
_notifier.Error(T("Site settings could not be saved. (Name = \"{0}\")", shellSettings.Name));
return Index(model);
}
_shellSettingsLoader.SaveSettings(shellSettings);
_orchardHost.Reinitialize();

View File

@@ -22,7 +22,7 @@ using (Html.BeginFormAntiForgeryPost()) { %>
</fieldset>
<fieldset>
<%=Html.LabelFor(svm => svm.AdminPassword) %>
<%=Html.EditorFor(svm => svm.AdminPassword) %>
<%=Html.PasswordFor(svm => svm.AdminPassword) %>
<%=Html.ValidationMessage("AdminPassword", "*") %>
</fieldset>
<fieldset>

View File

@@ -1,9 +1,15 @@
namespace Orchard.Environment.Configuration {
public interface IShellSettings {
string Name { get; set; }
string DataProvider { get; set; }
string DataFolder { get; set; }
string DataConnectionString { get; set; }
}
public class ShellSettings : IShellSettings {
public string Name { get; set; }
public string DataProvider { get; set; }
public string DataFolder { get; set; }
public string DataConnectionString { get; set; }
}
}

View File

@@ -1,35 +1,45 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.Hosting;
using Orchard.Localization;
using Yaml.Grammar;
namespace Orchard.Environment.Configuration {
public interface IShellSettingsLoader {
IEnumerable<IShellSettings> LoadSettings();
bool SaveSettings(IShellSettings settings);
void SaveSettings(IShellSettings settings);
}
public class ShellSettingsLoader : IShellSettingsLoader {
Localizer T { get; set; }
public ShellSettingsLoader() {
T = NullLocalizer.Instance;
}
IEnumerable<IShellSettings> IShellSettingsLoader.LoadSettings() {
return LoadSettings().ToArray();
}
public bool SaveSettings(IShellSettings settings) {
if (settings != null && !string.IsNullOrEmpty(settings.Name)) {
var sitesPath = HostingEnvironment.MapPath("~/App_Data/Sites");
if (sitesPath != null) {
if (!Directory.Exists(sitesPath))
Directory.CreateDirectory(sitesPath);
public void SaveSettings(IShellSettings settings) {
if (settings == null)
throw new ArgumentException(T("There are no settings to save.").ToString());
if (string.IsNullOrEmpty(settings.Name))
throw new ArgumentException(T("Settings \"Name\" is not set.").ToString());
var filePath = Path.Combine(sitesPath, string.Format("{0}.txt", settings.Name));
File.WriteAllText(filePath, ComposeSettings(settings));
return true;
}
}
var sitesPath = HostingEnvironment.MapPath("~/App_Data/Sites");
return false;
if (string.IsNullOrEmpty(sitesPath))
throw new ArgumentException(T("Can't determine the path on the server to save settings. Looking for something like \"~/App_Data/Sites\".").ToString());
if (!Directory.Exists(sitesPath))
Directory.CreateDirectory(sitesPath);
var filePath = Path.Combine(sitesPath, string.Format("{0}.txt", settings.Name));
File.WriteAllText(filePath, ComposeSettings(settings));
}
static IEnumerable<IShellSettings> LoadSettings() {
@@ -54,7 +64,12 @@ namespace Orchard.Environment.Configuration {
.Where(x => x.Key is Scalar)
.ToDictionary(x => ((Scalar)x.Key).Text, x => x.Value);
return new ShellSettings { Name = GetValue(fields, "Name") };
return new ShellSettings {
Name = GetValue(fields, "Name"),
DataProvider = GetValue(fields, "DataProvider"),
DataFolder = GetValue(fields, "DataFolder"),
DataConnectionString = GetValue(fields, "DataConnectionString")
};
}
static string GetValue(
@@ -66,7 +81,17 @@ namespace Orchard.Environment.Configuration {
}
static string ComposeSettings(IShellSettings shellSettings) {
return shellSettings == null ? "" : string.Format("Name: {0}", shellSettings.Name);
if (shellSettings == null)
return "";
var settingsBuilder = new StringBuilder();
settingsBuilder.AppendLine(string.Format("Name: {0}", shellSettings.Name));
settingsBuilder.AppendLine(string.Format("DataProvider: {0}", shellSettings.DataProvider));
settingsBuilder.AppendLine(string.Format("DataFolder: {0}", shellSettings.DataFolder));
settingsBuilder.AppendLine(string.Format("DataConnectionString: {0}", shellSettings.DataConnectionString));
return settingsBuilder.ToString();
}
}
}