mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Prepared Azure projects for .NET 4.0
Changed Azure references to SDK 1.2 Added a hack for the ASP.NET 4 bug in HttpEncoder Converted projects to VS10 --HG-- branch : dev
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Yaml.Serialization;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.WindowsAzure.ServiceRuntime;
|
||||
using Microsoft.WindowsAzure.StorageClient;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Environment.Configuration;
|
||||
@@ -23,7 +25,7 @@ namespace Orchard.Azure.Environment.Configuration {
|
||||
set; }
|
||||
|
||||
public AzureShellSettingsManager(IShellSettingsManagerEventHandler events)
|
||||
: this(CloudStorageAccount.FromConfigurationSetting("DataConnectionString"), events)
|
||||
: this(CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DataConnectionString")), events)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -33,15 +35,23 @@ namespace Orchard.Azure.Environment.Configuration {
|
||||
_storageAccount = storageAccount;
|
||||
_events = events;
|
||||
|
||||
BlobClient = _storageAccount.CreateCloudBlobClient();
|
||||
AzureHelper.InjectHttpContext(() =>
|
||||
{
|
||||
BlobClient = _storageAccount.CreateCloudBlobClient();
|
||||
|
||||
// Get and create the container if it does not exist
|
||||
// The container is named with DNS naming restrictions (i.e. all lower case)
|
||||
Container = new CloudBlobContainer(ContainerName, BlobClient);
|
||||
Container.CreateIfNotExist();
|
||||
// Get and create the container if it does not exist
|
||||
// The container is named with DNS naming restrictions (i.e. all lower case)
|
||||
Container = new CloudBlobContainer(ContainerName, BlobClient);
|
||||
Container.CreateIfNotExist();
|
||||
|
||||
// Tenant settings are protected by default
|
||||
Container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Off });
|
||||
// Tenant settings are protected by default
|
||||
Container.SetPermissions(new BlobContainerPermissions
|
||||
{
|
||||
PublicAccess =
|
||||
BlobContainerPublicAccessType.Off
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
IEnumerable<ShellSettings> IShellSettingsManager.LoadSettings() {
|
||||
@@ -51,25 +61,41 @@ namespace Orchard.Azure.Environment.Configuration {
|
||||
void IShellSettingsManager.SaveSettings(ShellSettings 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 =String.Concat(settings.Name, "/", "Settings.txt");
|
||||
var blob = Container.GetBlockBlobReference(filePath);
|
||||
blob.UploadText(ComposeSettings(settings));
|
||||
AzureHelper.InjectHttpContext(
|
||||
() =>
|
||||
{
|
||||
var filePath = String.Concat(settings.Name, "/", "Settings.txt");
|
||||
var blob = Container.GetBlockBlobReference(filePath);
|
||||
blob.UploadText(ComposeSettings(settings));
|
||||
});
|
||||
|
||||
_events.Saved(settings);
|
||||
}
|
||||
|
||||
IEnumerable<ShellSettings> LoadSettings() {
|
||||
var settingsBlobs =
|
||||
BlobClient.ListBlobsWithPrefix(Container.Name + "/" ).OfType<CloudBlobDirectory>()
|
||||
.SelectMany(directory => directory.ListBlobs()).OfType<CloudBlockBlob>()
|
||||
.Where(blob => string.Equals(Path.GetFileName(blob.Uri.ToString()), "Settings.txt", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
foreach ( var settingsBlob in settingsBlobs ) {
|
||||
yield return ParseSettings(settingsBlob.DownloadText());
|
||||
}
|
||||
var result = new List<ShellSettings>();
|
||||
|
||||
AzureHelper.InjectHttpContext(
|
||||
() =>
|
||||
{
|
||||
var settingsBlobs =
|
||||
BlobClient.ListBlobsWithPrefix(Container.Name + "/").OfType<CloudBlobDirectory>()
|
||||
.SelectMany(directory => directory.ListBlobs()).OfType<CloudBlockBlob>()
|
||||
.Where(
|
||||
blob =>
|
||||
string.Equals(Path.GetFileName(blob.Uri.ToString()),
|
||||
"Settings.txt",
|
||||
StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
result.AddRange(settingsBlobs.Select(settingsBlob => ParseSettings(settingsBlob.DownloadText())));
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
class Content {
|
||||
|
Reference in New Issue
Block a user