Refactoring some packaging code

--HG--
branch : dev
This commit is contained in:
Louis DeJardin
2010-07-07 15:06:33 -07:00
parent 882b1f6df5
commit 62e9c69713
6 changed files with 33 additions and 22 deletions

View File

@@ -24,6 +24,7 @@ namespace Orchard.Modules.Packaging.Services {
void Install(PackageData packageData);
}
[OrchardFeature("Orchard.Modules.Packaging")]
public class PackageManager : IPackageManager {
private readonly IExtensionManager _extensionManager;
private readonly IPackageSourceManager _packageSourceManager;

View File

@@ -0,0 +1,19 @@
using System.IO;
using System.Web.Mvc;
namespace PackageIndexReferenceImplementation.Controllers {
public class StreamResult : ActionResult {
public string ContentType { get; set; }
public Stream Stream { get; set; }
public StreamResult(string contentType, Stream stream) {
ContentType = contentType;
Stream = stream;
}
public override void ExecuteResult(ControllerContext context) {
context.HttpContext.Response.ContentType = ContentType;
Stream.CopyTo(context.HttpContext.Response.OutputStream);
}
}
}

View File

@@ -50,6 +50,16 @@ namespace PackageIndexReferenceImplementation.Controllers {
}
var mediaIdentifier = UpdateSyndicationItem(packageProperties, item);
_mediaStorage.StoreMedia(mediaIdentifier + ":application/x-package", Request.InputStream);
_feedStorage.StoreFeed(feed);
return new AtomItemResult("201 Created", null, item);
}
private string UpdateSyndicationItem(PackageProperties packageProperties, SyndicationItem item) {
if (!string.IsNullOrEmpty(packageProperties.Category)) {
item.Authors.Clear();
//parse package.PackageProperties.Creator into email-style authors
@@ -82,12 +92,7 @@ namespace PackageIndexReferenceImplementation.Controllers {
var mediaUrl = Url.Action("Resource", "Media", new RouteValueDictionary { { "Id", mediaIdentifier }, { "ContentType", "application/x-package" } });
item.Links.Clear();
item.Links.Add(new SyndicationLink(new Uri(HostBaseUri(), new Uri(mediaUrl, UriKind.Relative))));
Request.InputStream.Seek(0, SeekOrigin.Begin);
_mediaStorage.StoreMedia(mediaIdentifier+":application/x-package", Request.InputStream);
_feedStorage.StoreFeed(feed);
return new AtomItemResult("201 Created", null, item);
return mediaIdentifier;
}
private Uri HostBaseUri() {

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
@@ -21,19 +20,4 @@ namespace PackageIndexReferenceImplementation.Controllers
return new StreamResult(contentType, _mediaStorage.GetMedia(id + ":" + contentType));
}
}
public class StreamResult : ActionResult {
public string ContentType { get; set; }
public Stream Stream { get; set; }
public StreamResult(string contentType, Stream stream) {
ContentType = contentType;
Stream = stream;
}
public override void ExecuteResult(ControllerContext context) {
context.HttpContext.Response.ContentType = ContentType;
Stream.CopyTo(context.HttpContext.Response.OutputStream);
}
}
}

View File

@@ -75,6 +75,7 @@
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\MediaController.cs" />
<Compile Include="Controllers\Artifacts\XmlBodyAttribute.cs" />
<Compile Include="Controllers\Artifacts\StreamResult.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>

View File

@@ -11,6 +11,7 @@ namespace PackageIndexReferenceImplementation.Services {
var safeIdentifier = GetSafeIdentifier(identifier);
var filePath = HostingEnvironment.MapPath("~/App_Data/Media/" + safeIdentifier);
using (var destination = new FileStream(filePath, FileMode.Create, FileAccess.Write)) {
data.Seek(0, SeekOrigin.Begin);
data.CopyTo(destination);
}
}