mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 12:03:51 +08:00
Merge
--HG-- branch : 1.x
This commit is contained in:
@@ -190,9 +190,9 @@ namespace Orchard.Azure.Tests.FileSystems.Media {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void CanCreateAlreadyExistingFolder() {
|
public void TryCreateFolderShouldReturnFalseIfFolderAlreadyExists() {
|
||||||
_azureBlobStorageProvider.CreateFile("folder1/foo.txt");
|
_azureBlobStorageProvider.CreateFile("folder1/foo.txt");
|
||||||
Assert.That(_azureBlobStorageProvider.TryCreateFolder("folder1"), Is.True);
|
Assert.That(_azureBlobStorageProvider.TryCreateFolder("folder1"), Is.False);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ using Microsoft.WindowsAzure.StorageClient;
|
|||||||
using Orchard.FileSystems.Media;
|
using Orchard.FileSystems.Media;
|
||||||
|
|
||||||
namespace Orchard.Azure {
|
namespace Orchard.Azure {
|
||||||
public class AzureFileSystem
|
public class AzureFileSystem {
|
||||||
{
|
|
||||||
private const string FolderEntry = "$$$ORCHARD$$$.$$$";
|
private const string FolderEntry = "$$$ORCHARD$$$.$$$";
|
||||||
|
|
||||||
public string ContainerName { get; protected set; }
|
public string ContainerName { get; protected set; }
|
||||||
@@ -71,15 +70,13 @@ namespace Orchard.Azure {
|
|||||||
return path2;
|
return path2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( path2.StartsWith("http://") || path2.StartsWith("https://") )
|
if ( path2.StartsWith("http://") || path2.StartsWith("https://") ) {
|
||||||
{
|
|
||||||
return path2;
|
return path2;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ch = path1[path1.Length - 1];
|
var ch = path1[path1.Length - 1];
|
||||||
|
|
||||||
if (ch != '/')
|
if (ch != '/') {
|
||||||
{
|
|
||||||
return (path1.TrimEnd('/') + '/' + path2.TrimStart('/'));
|
return (path1.TrimEnd('/') + '/' + path2.TrimStart('/'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +155,9 @@ namespace Orchard.Azure {
|
|||||||
try {
|
try {
|
||||||
if (!Container.DirectoryExists(String.Concat(_root, path))) {
|
if (!Container.DirectoryExists(String.Concat(_root, path))) {
|
||||||
CreateFolder(path);
|
CreateFolder(path);
|
||||||
|
|
||||||
|
// return false to be consistent with FileSystemProvider's implementation
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -302,6 +302,12 @@ namespace Orchard.Azure {
|
|||||||
return _blob.OpenWrite();
|
return _blob.OpenWrite();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Stream CreateFile() {
|
||||||
|
// as opposed to the File System implementation, if nothing is done on the stream
|
||||||
|
// the file will be emptied, because Azure doesn't implement FileMode.Truncate
|
||||||
|
_blob.DeleteIfExists();
|
||||||
|
return OpenWrite();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AzureBlobFolderStorage : IStorageFolder {
|
private class AzureBlobFolderStorage : IStorageFolder {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.WindowsAzure;
|
using System.IO;
|
||||||
|
using Microsoft.WindowsAzure;
|
||||||
using Orchard.Environment.Configuration;
|
using Orchard.Environment.Configuration;
|
||||||
using Orchard.FileSystems.Media;
|
using Orchard.FileSystems.Media;
|
||||||
|
|
||||||
@@ -12,12 +13,31 @@ namespace Orchard.Azure.FileSystems.Media {
|
|||||||
public AzureBlobStorageProvider(ShellSettings shellSettings, CloudStorageAccount storageAccount) : base("media", shellSettings.Name, false, storageAccount) { }
|
public AzureBlobStorageProvider(ShellSettings shellSettings, CloudStorageAccount storageAccount) : base("media", shellSettings.Name, false, storageAccount) { }
|
||||||
|
|
||||||
|
|
||||||
public bool TrySaveStream(string path, System.IO.Stream inputStream) {
|
public bool TrySaveStream(string path, Stream inputStream) {
|
||||||
throw new System.NotImplementedException();
|
try {
|
||||||
|
SaveStream(path, inputStream);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveStream(string path, System.IO.Stream inputStream) {
|
public void SaveStream(string path, Stream inputStream) {
|
||||||
throw new System.NotImplementedException();
|
// Create the file.
|
||||||
|
// The CreateFile method will map the still relative path
|
||||||
|
var file = CreateFile(path);
|
||||||
|
|
||||||
|
using(var outputStream = file.OpenWrite()) {
|
||||||
|
var buffer = new byte[8192];
|
||||||
|
for (;;) {
|
||||||
|
var length = inputStream.Read(buffer, 0, buffer.Length);
|
||||||
|
if (length <= 0)
|
||||||
|
break;
|
||||||
|
outputStream.Write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ using Orchard.Recipes.Models;
|
|||||||
namespace Orchard.Recipes.Services {
|
namespace Orchard.Recipes.Services {
|
||||||
public class RecipeJournalManager : IRecipeJournal {
|
public class RecipeJournalManager : IRecipeJournal {
|
||||||
private readonly IStorageProvider _storageProvider;
|
private readonly IStorageProvider _storageProvider;
|
||||||
private readonly string _recipeJournalFolder = "RecipeJournal" + Path.DirectorySeparatorChar;
|
private const string RecipeJournalFolder = "RecipeJournal";
|
||||||
private const string WebConfig =
|
private const string WebConfig =
|
||||||
@"
|
@"
|
||||||
<configuration>
|
<configuration>
|
||||||
@@ -92,10 +92,10 @@ namespace Orchard.Recipes.Services {
|
|||||||
|
|
||||||
private IStorageFile GetJournalFile(string executionId) {
|
private IStorageFile GetJournalFile(string executionId) {
|
||||||
IStorageFile journalFile;
|
IStorageFile journalFile;
|
||||||
var journalPath = Path.Combine(_recipeJournalFolder, executionId);
|
var journalPath = _storageProvider.Combine(RecipeJournalFolder, executionId);
|
||||||
try {
|
try {
|
||||||
if (_storageProvider.TryCreateFolder(_recipeJournalFolder)) {
|
if (_storageProvider.TryCreateFolder(RecipeJournalFolder)) {
|
||||||
var webConfigPath = Path.Combine(_recipeJournalFolder, "web.config");
|
var webConfigPath = _storageProvider.Combine(RecipeJournalFolder, "web.config");
|
||||||
var webConfigFile = _storageProvider.CreateFile(webConfigPath);
|
var webConfigFile = _storageProvider.CreateFile(webConfigPath);
|
||||||
WriteWebConfig(webConfigFile);
|
WriteWebConfig(webConfigFile);
|
||||||
}
|
}
|
||||||
@@ -121,10 +121,9 @@ namespace Orchard.Recipes.Services {
|
|||||||
|
|
||||||
private static void WriteJournal(IStorageFile journalFile, XElement journal) {
|
private static void WriteJournal(IStorageFile journalFile, XElement journal) {
|
||||||
string content = journal.ToString();
|
string content = journal.ToString();
|
||||||
using (var stream = journalFile.OpenWrite()) {
|
using (var stream = journalFile.CreateFile()) {
|
||||||
using (var tw = new StreamWriter(stream)) {
|
using (var tw = new StreamWriter(stream)) {
|
||||||
tw.Write(content);
|
tw.Write(content);
|
||||||
stream.SetLength(stream.Position);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,8 +135,18 @@ namespace Orchard.FileSystems.Media {
|
|||||||
/// <param name="path">The relative path to the folder to be created.</param>
|
/// <param name="path">The relative path to the folder to be created.</param>
|
||||||
/// <returns>True if success; False otherwise.</returns>
|
/// <returns>True if success; False otherwise.</returns>
|
||||||
public bool TryCreateFolder(string path) {
|
public bool TryCreateFolder(string path) {
|
||||||
try { CreateFolder(path); }
|
try {
|
||||||
catch { return false; }
|
// prevent unnecessary exception
|
||||||
|
DirectoryInfo directoryInfo = new DirectoryInfo(MapStorage(path));
|
||||||
|
if (directoryInfo.Exists) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CreateFolder(path);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -250,8 +260,12 @@ namespace Orchard.FileSystems.Media {
|
|||||||
/// <param name="inputStream">The stream to be saved.</param>
|
/// <param name="inputStream">The stream to be saved.</param>
|
||||||
/// <returns>True if success; False otherwise.</returns>
|
/// <returns>True if success; False otherwise.</returns>
|
||||||
public bool TrySaveStream(string path, Stream inputStream) {
|
public bool TrySaveStream(string path, Stream inputStream) {
|
||||||
try { SaveStream(path, inputStream); }
|
try {
|
||||||
catch { return false; }
|
SaveStream(path, inputStream);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -334,6 +348,10 @@ namespace Orchard.FileSystems.Media {
|
|||||||
return new FileStream(_fileInfo.FullName, FileMode.Open, FileAccess.ReadWrite);
|
return new FileStream(_fileInfo.FullName, FileMode.Open, FileAccess.ReadWrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Stream CreateFile() {
|
||||||
|
return new FileStream(_fileInfo.FullName, FileMode.Truncate, FileAccess.ReadWrite);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,5 +18,11 @@ namespace Orchard.FileSystems.Media {
|
|||||||
/// Creates a stream for writing to the file.
|
/// Creates a stream for writing to the file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Stream OpenWrite();
|
Stream OpenWrite();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a stream for writing to the file, and truncates the existing content.
|
||||||
|
/// </summary>
|
||||||
|
Stream CreateFile();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user