mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 03:25:23 +08:00
Refactoring some packaging code
--HG-- branch : dev
This commit is contained in:
@@ -24,6 +24,7 @@ namespace Orchard.Modules.Packaging.Services {
|
|||||||
void Install(PackageData packageData);
|
void Install(PackageData packageData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[OrchardFeature("Orchard.Modules.Packaging")]
|
||||||
public class PackageManager : IPackageManager {
|
public class PackageManager : IPackageManager {
|
||||||
private readonly IExtensionManager _extensionManager;
|
private readonly IExtensionManager _extensionManager;
|
||||||
private readonly IPackageSourceManager _packageSourceManager;
|
private readonly IPackageSourceManager _packageSourceManager;
|
||||||
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -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)) {
|
if (!string.IsNullOrEmpty(packageProperties.Category)) {
|
||||||
item.Authors.Clear();
|
item.Authors.Clear();
|
||||||
//parse package.PackageProperties.Creator into email-style authors
|
//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" } });
|
var mediaUrl = Url.Action("Resource", "Media", new RouteValueDictionary { { "Id", mediaIdentifier }, { "ContentType", "application/x-package" } });
|
||||||
item.Links.Clear();
|
item.Links.Clear();
|
||||||
item.Links.Add(new SyndicationLink(new Uri(HostBaseUri(), new Uri(mediaUrl, UriKind.Relative))));
|
item.Links.Add(new SyndicationLink(new Uri(HostBaseUri(), new Uri(mediaUrl, UriKind.Relative))));
|
||||||
|
return mediaIdentifier;
|
||||||
Request.InputStream.Seek(0, SeekOrigin.Begin);
|
|
||||||
_mediaStorage.StoreMedia(mediaIdentifier+":application/x-package", Request.InputStream);
|
|
||||||
_feedStorage.StoreFeed(feed);
|
|
||||||
|
|
||||||
return new AtomItemResult("201 Created", null, item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Uri HostBaseUri() {
|
private Uri HostBaseUri() {
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
@@ -21,19 +20,4 @@ namespace PackageIndexReferenceImplementation.Controllers
|
|||||||
return new StreamResult(contentType, _mediaStorage.GetMedia(id + ":" + contentType));
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -75,6 +75,7 @@
|
|||||||
<Compile Include="Controllers\HomeController.cs" />
|
<Compile Include="Controllers\HomeController.cs" />
|
||||||
<Compile Include="Controllers\MediaController.cs" />
|
<Compile Include="Controllers\MediaController.cs" />
|
||||||
<Compile Include="Controllers\Artifacts\XmlBodyAttribute.cs" />
|
<Compile Include="Controllers\Artifacts\XmlBodyAttribute.cs" />
|
||||||
|
<Compile Include="Controllers\Artifacts\StreamResult.cs" />
|
||||||
<Compile Include="Global.asax.cs">
|
<Compile Include="Global.asax.cs">
|
||||||
<DependentUpon>Global.asax</DependentUpon>
|
<DependentUpon>Global.asax</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@@ -11,6 +11,7 @@ namespace PackageIndexReferenceImplementation.Services {
|
|||||||
var safeIdentifier = GetSafeIdentifier(identifier);
|
var safeIdentifier = GetSafeIdentifier(identifier);
|
||||||
var filePath = HostingEnvironment.MapPath("~/App_Data/Media/" + safeIdentifier);
|
var filePath = HostingEnvironment.MapPath("~/App_Data/Media/" + safeIdentifier);
|
||||||
using (var destination = new FileStream(filePath, FileMode.Create, FileAccess.Write)) {
|
using (var destination = new FileStream(filePath, FileMode.Create, FileAccess.Write)) {
|
||||||
|
data.Seek(0, SeekOrigin.Begin);
|
||||||
data.CopyTo(destination);
|
data.CopyTo(destination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user