Adding CreateFile on IStorageFile

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2011-04-08 14:53:26 -07:00
parent 6bf32dbbfb
commit 7353fe5f58
6 changed files with 68 additions and 19 deletions
+12 -6
View File
@@ -8,8 +8,7 @@ using Microsoft.WindowsAzure.StorageClient;
using Orchard.FileSystems.Media;
namespace Orchard.Azure {
public class AzureFileSystem
{
public class AzureFileSystem {
private const string FolderEntry = "$$$ORCHARD$$$.$$$";
public string ContainerName { get; protected set; }
@@ -71,15 +70,13 @@ namespace Orchard.Azure {
return path2;
}
if ( path2.StartsWith("http://") || path2.StartsWith("https://") )
{
if ( path2.StartsWith("http://") || path2.StartsWith("https://") ) {
return path2;
}
var ch = path1[path1.Length - 1];
if (ch != '/')
{
if (ch != '/') {
return (path1.TrimEnd('/') + '/' + path2.TrimStart('/'));
}
@@ -158,6 +155,9 @@ namespace Orchard.Azure {
try {
if (!Container.DirectoryExists(String.Concat(_root, path))) {
CreateFolder(path);
// return false to be consistent with FileSystemProvider's implementation
return false;
}
return true;
}
@@ -302,6 +302,12 @@ namespace Orchard.Azure {
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 {
@@ -1,4 +1,5 @@
using Microsoft.WindowsAzure;
using System.IO;
using Microsoft.WindowsAzure;
using Orchard.Environment.Configuration;
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 bool TrySaveStream(string path, System.IO.Stream inputStream) {
throw new System.NotImplementedException();
public bool TrySaveStream(string path, Stream inputStream) {
try {
SaveStream(path, inputStream);
}
catch {
return false;
}
return true;
}
public void SaveStream(string path, System.IO.Stream inputStream) {
throw new System.NotImplementedException();
public void SaveStream(string path, Stream inputStream) {
// 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);
}
}
}
}
}