Changing system.io.packaging to nupack for packaging

PackageBuilder changed to produce opc binary through nupack
Affected code in PackageManager and PackageExpander disabled by #if REFACTORING

--HG--
branch : nuget
extra : transplant_source : %16%B0%AA%E7%24H/%D3%08%FBz%3D%83%94%26s%3F%99%B5%C8
This commit is contained in:
Louis DeJardin
2010-10-27 11:19:17 -07:00
parent 21837215d5
commit 7b8deeb33c
7 changed files with 87 additions and 43 deletions

View File

@@ -1 +1 @@
0000000000000000000000000000000000000000 external/nupack 230ef1360257ef0ac622f6e85a94323ef2e49cae external/nupack

View File

@@ -67,9 +67,6 @@
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Web.Services" /> <Reference Include="System.Web.Services" />
<Reference Include="System.EnterpriseServices" /> <Reference Include="System.EnterpriseServices" />
<Reference Include="WindowsBase">
<Private>True</Private>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AdminMenu.cs" /> <Compile Include="AdminMenu.cs" />
@@ -113,6 +110,10 @@
<Folder Include="Scripts\" /> <Folder Include="Scripts\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\..\external\nupack\NuPack.Core\NuPack.Core.csproj">
<Project>{F879F274-EFA0-4157-8404-33A19B4E6AEC}</Project>
<Name>NuPack.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Orchard\Orchard.Framework.csproj"> <ProjectReference Include="..\..\..\Orchard\Orchard.Framework.csproj">
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project> <Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
<Name>Orchard.Framework</Name> <Name>Orchard.Framework</Name>

View File

@@ -1,17 +1,20 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.IO.Packaging;
using System.Linq; using System.Linq;
using System.Net.Mime; using System.Net.Mime;
using System.Reflection; using System.Reflection;
using System.Web; using System.Web;
using System.Web.Hosting; using System.Web.Hosting;
using System.Xml.Linq; using System.Xml.Linq;
using NuPack;
using Orchard.Environment.Extensions; using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models; using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.WebSite; using Orchard.FileSystems.WebSite;
using NuPack_PackageBuilder = NuPack.PackageBuilder;
using NuPack_IPackageBuilder = NuPack.IPackageBuilder;
namespace Orchard.Packaging.Services { namespace Orchard.Packaging.Services {
[OrchardFeature("PackagingServices")] [OrchardFeature("PackagingServices")]
public class PackageBuilder : IPackageBuilder { public class PackageBuilder : IPackageBuilder {
@@ -36,7 +39,6 @@ namespace Orchard.Packaging.Services {
_webSiteFolder = webSiteFolder; _webSiteFolder = webSiteFolder;
} }
#region IPackageBuilder Members
public Stream BuildPackage(ExtensionDescriptor extensionDescriptor) { public Stream BuildPackage(ExtensionDescriptor extensionDescriptor) {
var context = new CreateContext(); var context = new CreateContext();
@@ -67,26 +69,14 @@ namespace Orchard.Packaging.Services {
return context.Stream; return context.Stream;
} }
#endregion
private void SetCoreProperties(CreateContext context, ExtensionDescriptor extensionDescriptor) { private void SetCoreProperties(CreateContext context, ExtensionDescriptor extensionDescriptor) {
PackageProperties properties = context.Package.PackageProperties; context.Builder.Id = extensionDescriptor.Name;
properties.Title = extensionDescriptor.DisplayName ?? extensionDescriptor.Name; context.Builder.Version = new Version(extensionDescriptor.Version);
//properties.Subject = ""; context.Builder.Title = extensionDescriptor.DisplayName ?? extensionDescriptor.Name;
properties.Creator = extensionDescriptor.Author; context.Builder.Description = extensionDescriptor.Description;
properties.Keywords = extensionDescriptor.Tags; context.Builder.Authors.Add(extensionDescriptor.Author);
properties.Description = extensionDescriptor.Description;
//properties.LastModifiedBy = "";
//properties.Revision = "";
//properties.LastPrinted = "";
//properties.Created = "";
//properties.Modified = "";
properties.Category = extensionDescriptor.Features.Where(f => f.Name == extensionDescriptor.Name).Select(f => f.Category).FirstOrDefault();
properties.Identifier = extensionDescriptor.Name;
properties.ContentType = "Orchard " + extensionDescriptor.ExtensionType;
//properties.Language = "";
properties.Version = extensionDescriptor.Version;
properties.ContentStatus = "";
} }
@@ -125,7 +115,7 @@ namespace Orchard.Packaging.Services {
if (context.SourceFolder.FileExists(context.SourcePath + virtualPath)) { if (context.SourceFolder.FileExists(context.SourcePath + virtualPath)) {
EmbedVirtualFile(context, virtualPath, MediaTypeNames.Application.Octet); EmbedVirtualFile(context, virtualPath, MediaTypeNames.Application.Octet);
} }
else if (hintPath != null) {} else if (hintPath != null) { }
} }
} }
@@ -150,8 +140,7 @@ namespace Orchard.Packaging.Services {
private static void BeginPackage(CreateContext context) { private static void BeginPackage(CreateContext context) {
context.Stream = new MemoryStream(); context.Builder = new NuPack_PackageBuilder();
context.Package = Package.Open(context.Stream, FileMode.Create, FileAccess.ReadWrite);
} }
private static void EstablishPaths(CreateContext context, IWebSiteFolder webSiteFolder, string locationPath, string moduleName, string moduleType) { private static void EstablishPaths(CreateContext context, IWebSiteFolder webSiteFolder, string locationPath, string moduleName, string moduleType) {
@@ -174,24 +163,24 @@ namespace Orchard.Packaging.Services {
return false; return false;
} }
private static Uri EmbedVirtualFile(CreateContext context, string relativePath, string contentType) { private static void EmbedVirtualFile(CreateContext context, string relativePath, string contentType) {
Uri partUri = PackUriHelper.CreatePartUri(new Uri(context.TargetPath + relativePath, UriKind.Relative)); var file = new VirtualPackageFile(context.SourceFolder, context.SourcePath + relativePath);
PackagePart packagePart = context.Package.CreatePart(partUri, contentType); context.Builder.Files.Add(file);
using (Stream stream = packagePart.GetStream(FileMode.Create, FileAccess.Write)) {
context.SourceFolder.CopyFileTo(context.SourcePath + relativePath, stream, true /*actualContent*/);
}
return partUri;
} }
private static void EndPackage(CreateContext context) { private static void EndPackage(CreateContext context) {
context.Package.Close(); context.Stream = new MemoryStream();
context.Builder.Save(context.Stream);
} }
#region Nested type: CreateContext #region Nested type: CreateContext
private class CreateContext { private class CreateContext {
public Stream Stream { get; set; } public Stream Stream { get; set; }
public Package Package { get; set; } //public Package Package { get; set; }
//public Manifest Manifest { get; set; }
public NuPack_PackageBuilder Builder { get; set; }
public IWebSiteFolder SourceFolder { get; set; } public IWebSiteFolder SourceFolder { get; set; }
public string SourcePath { get; set; } public string SourcePath { get; set; }
@@ -201,5 +190,29 @@ namespace Orchard.Packaging.Services {
} }
#endregion #endregion
#region Nested type: CreateContext
private class VirtualPackageFile : IPackageFile {
private readonly IWebSiteFolder _sourceFolder;
public VirtualPackageFile(IWebSiteFolder sourceFolder, string path) {
Path = path;
_sourceFolder = sourceFolder;
}
public string Path { get; private set; }
public Stream GetStream() {
var stream = new MemoryStream();
_sourceFolder.CopyFileTo(Path, stream);
stream.Seek(0, SeekOrigin.Begin);
return stream;
}
}
#endregion
} }
} }

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.IO.Packaging;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Xml.Linq; using System.Xml.Linq;
@@ -23,7 +22,6 @@ namespace Orchard.Packaging.Services {
public Localizer T { get; set; } public Localizer T { get; set; }
#region IPackageExpander Members
public PackageInfo ExpandPackage(Stream packageStream) { public PackageInfo ExpandPackage(Stream packageStream) {
var context = new ExpandContext(); var context = new ExpandContext();
@@ -55,9 +53,8 @@ namespace Orchard.Packaging.Services {
}; };
} }
#endregion
private void ExtractFile(ExpandContext context, string relativePath) { private void ExtractFile(ExpandContext context, string relativePath) {
#if REFACTORING
Uri partUri = PackUriHelper.CreatePartUri(new Uri(context.SourcePath + relativePath, UriKind.Relative)); Uri partUri = PackUriHelper.CreatePartUri(new Uri(context.SourcePath + relativePath, UriKind.Relative));
PackagePart packagePart = context.Package.GetPart(partUri); PackagePart packagePart = context.Package.GetPart(partUri);
using (Stream packageStream = packagePart.GetStream(FileMode.Open, FileAccess.Read)) { using (Stream packageStream = packagePart.GetStream(FileMode.Open, FileAccess.Read)) {
@@ -71,6 +68,7 @@ namespace Orchard.Packaging.Services {
packageStream.CopyTo(fileStream); packageStream.CopyTo(fileStream);
} }
} }
#endif
} }
private void ExtractProjectFiles(ExpandContext context, params string[] itemGroupTypes) { private void ExtractProjectFiles(ExpandContext context, params string[] itemGroupTypes) {
@@ -113,16 +111,22 @@ namespace Orchard.Packaging.Services {
} }
private void ExtractThemeFiles(ExpandContext context) { private void ExtractThemeFiles(ExpandContext context) {
#if REFACTORING
foreach (var relativePath in from p in context.Package.GetParts() foreach (var relativePath in from p in context.Package.GetParts()
where p.Uri.ToString().StartsWith("/" + context.ExtensionName + "/", StringComparison.OrdinalIgnoreCase) where p.Uri.ToString().StartsWith("/" + context.ExtensionName + "/", StringComparison.OrdinalIgnoreCase)
select p.Uri.ToString().Substring(("/" + context.ExtensionName + "/").Length)) { select p.Uri.ToString().Substring(("/" + context.ExtensionName + "/").Length)) {
ExtractFile(context, relativePath); ExtractFile(context, relativePath);
} }
#endif
} }
private bool PartExists(ExpandContext context, string relativePath) { private bool PartExists(ExpandContext context, string relativePath) {
#if REFACTORING
Uri projectUri = PackUriHelper.CreatePartUri(new Uri(context.SourcePath + relativePath, UriKind.Relative)); Uri projectUri = PackUriHelper.CreatePartUri(new Uri(context.SourcePath + relativePath, UriKind.Relative));
return context.Package.PartExists(projectUri); return context.Package.PartExists(projectUri);
#else
return false;
#endif
} }
@@ -131,6 +135,7 @@ namespace Orchard.Packaging.Services {
} }
private static bool LoadProject(ExpandContext context, string relativePath) { private static bool LoadProject(ExpandContext context, string relativePath) {
#if REFACTORING
Uri projectUri = PackUriHelper.CreatePartUri(new Uri(context.SourcePath + relativePath, UriKind.Relative)); Uri projectUri = PackUriHelper.CreatePartUri(new Uri(context.SourcePath + relativePath, UriKind.Relative));
if (!context.Package.PartExists(projectUri)) { if (!context.Package.PartExists(projectUri)) {
return false; return false;
@@ -139,6 +144,7 @@ namespace Orchard.Packaging.Services {
using (Stream stream = part.GetStream(FileMode.Open, FileAccess.Read)) { using (Stream stream = part.GetStream(FileMode.Open, FileAccess.Read)) {
context.Project = XDocument.Load(stream); context.Project = XDocument.Load(stream);
} }
#endif
return true; return true;
} }
@@ -150,14 +156,19 @@ namespace Orchard.Packaging.Services {
context.Stream = new MemoryStream(); context.Stream = new MemoryStream();
packageStream.CopyTo(context.Stream); packageStream.CopyTo(context.Stream);
} }
#if REFACTORING
context.Package = Package.Open(context.Stream, FileMode.Open, FileAccess.Read); context.Package = Package.Open(context.Stream, FileMode.Open, FileAccess.Read);
#endif
} }
private void EndPackage(ExpandContext context) { private void EndPackage(ExpandContext context) {
#if REFACTORING
context.Package.Close(); context.Package.Close();
#endif
} }
private void GetCoreProperties(ExpandContext context) { private void GetCoreProperties(ExpandContext context) {
#if REFACTORING
context.ExtensionName = context.Package.PackageProperties.Identifier; context.ExtensionName = context.Package.PackageProperties.Identifier;
context.ExtensionVersion = context.Package.PackageProperties.Version; context.ExtensionVersion = context.Package.PackageProperties.Version;
@@ -165,6 +176,7 @@ namespace Orchard.Packaging.Services {
if (contentType.StartsWith(ContentTypePrefix)) { if (contentType.StartsWith(ContentTypePrefix)) {
context.ExtensionType = contentType.Substring(ContentTypePrefix.Length); context.ExtensionType = contentType.Substring(ContentTypePrefix.Length);
} }
#endif
} }
private void EstablishPaths(ExpandContext context, IVirtualPathProvider virtualPathProvider) { private void EstablishPaths(ExpandContext context, IVirtualPathProvider virtualPathProvider) {
@@ -185,7 +197,7 @@ namespace Orchard.Packaging.Services {
private class ExpandContext { private class ExpandContext {
public Stream Stream { get; set; } public Stream Stream { get; set; }
public Package Package { get; set; } //public Package Package { get; set; }
public string ExtensionName { get; set; } public string ExtensionName { get; set; }
public string ExtensionVersion { get; set; } public string ExtensionVersion { get; set; }

View File

@@ -1,6 +1,5 @@
using System; using System;
using System.IO; using System.IO;
using System.IO.Packaging;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Text; using System.Text;
@@ -57,6 +56,7 @@ namespace Orchard.Packaging.Services {
} }
public PackageData Download(string feedItemId) { public PackageData Download(string feedItemId) {
#if REFACTORING
PackagingEntry entry = _packagingSourceManager.GetModuleList().Single(x => x.SyndicationItem.Id == feedItemId); PackagingEntry entry = _packagingSourceManager.GetModuleList().Single(x => x.SyndicationItem.Id == feedItemId);
WebRequest request = WebRequest.Create(entry.PackageStreamUri); WebRequest request = WebRequest.Create(entry.PackageStreamUri);
using (WebResponse response = request.GetResponse()) { using (WebResponse response = request.GetResponse()) {
@@ -76,6 +76,9 @@ namespace Orchard.Packaging.Services {
} }
} }
} }
#else
throw new NotImplementedException();
#endif
} }
public PackageInfo Install(Stream packageStream) { public PackageInfo Install(Stream packageStream) {

View File

@@ -23,7 +23,7 @@
} }
<fieldset> <fieldset>
@Html.LabelFor(m => m.FeedUrl, T("Feed Url")) @Html.LabelFor(m => m.FeedUrl, T("Feed Url"))
@Html.DropDownListFor(m => m.FeedUrl, new[]{new SelectListItem{Text=T("Download").ToString(),Value="Download"}}.Concat( Model.Sources.Select(x => new SelectListItem { Text = T("Push to {0}", x.FeedUrl).ToString(), Value = x.FeedUrl }))) @Html.DropDownListFor(m => m.FeedUrl, new[]{new SelectListItem{Text=T("Download").ToString(),Value=""}}.Concat( Model.Sources.Select(x => new SelectListItem { Text = T("Push to {0}", x.FeedUrl).ToString(), Value = x.FeedUrl })))
@Html.ValidationMessageFor(m=>m.FeedUrl) @Html.ValidationMessageFor(m=>m.FeedUrl)
</fieldset> </fieldset>
<input type="submit" value="Harvest" /> <input type="submit" value="Harvest" />

View File

@@ -93,6 +93,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Themes", "Orchard.Web\Theme
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.PublishLater", "Orchard.Web\Modules\Orchard.PublishLater\Orchard.PublishLater.csproj", "{C889167C-E52C-4A65-A419-224B3D1B957D}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.PublishLater", "Orchard.Web\Modules\Orchard.PublishLater\Orchard.PublishLater.csproj", "{C889167C-E52C-4A65-A419-224B3D1B957D}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "External", "External", "{104288A3-382E-4032-AF50-FBB5FDAB9EBB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuPack.Core", "..\external\nupack\NuPack.Core\NuPack.Core.csproj", "{F879F274-EFA0-4157-8404-33A19B4E6AEC}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
CodeCoverage|Any CPU = CodeCoverage|Any CPU CodeCoverage|Any CPU = CodeCoverage|Any CPU
@@ -492,6 +496,16 @@ Global
{C889167C-E52C-4A65-A419-224B3D1B957D}.FxCop|Any CPU.Build.0 = Release|Any CPU {C889167C-E52C-4A65-A419-224B3D1B957D}.FxCop|Any CPU.Build.0 = Release|Any CPU
{C889167C-E52C-4A65-A419-224B3D1B957D}.Release|Any CPU.ActiveCfg = Release|Any CPU {C889167C-E52C-4A65-A419-224B3D1B957D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C889167C-E52C-4A65-A419-224B3D1B957D}.Release|Any CPU.Build.0 = Release|Any CPU {C889167C-E52C-4A65-A419-224B3D1B957D}.Release|Any CPU.Build.0 = Release|Any CPU
{F879F274-EFA0-4157-8404-33A19B4E6AEC}.CodeCoverage|Any CPU.ActiveCfg = Coverage|Any CPU
{F879F274-EFA0-4157-8404-33A19B4E6AEC}.CodeCoverage|Any CPU.Build.0 = Coverage|Any CPU
{F879F274-EFA0-4157-8404-33A19B4E6AEC}.Coverage|Any CPU.ActiveCfg = Coverage|Any CPU
{F879F274-EFA0-4157-8404-33A19B4E6AEC}.Coverage|Any CPU.Build.0 = Coverage|Any CPU
{F879F274-EFA0-4157-8404-33A19B4E6AEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F879F274-EFA0-4157-8404-33A19B4E6AEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F879F274-EFA0-4157-8404-33A19B4E6AEC}.FxCop|Any CPU.ActiveCfg = Coverage|Any CPU
{F879F274-EFA0-4157-8404-33A19B4E6AEC}.FxCop|Any CPU.Build.0 = Coverage|Any CPU
{F879F274-EFA0-4157-8404-33A19B4E6AEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F879F274-EFA0-4157-8404-33A19B4E6AEC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@@ -533,5 +547,6 @@ Global
{8A4E42CE-79F8-4BE2-8B1E-A6B83432123B} = {383DBA32-4A3E-48D1-AAC3-75377A694452} {8A4E42CE-79F8-4BE2-8B1E-A6B83432123B} = {383DBA32-4A3E-48D1-AAC3-75377A694452}
{0DFA2E10-96C8-4E05-BC10-B710B97ECCDE} = {383DBA32-4A3E-48D1-AAC3-75377A694452} {0DFA2E10-96C8-4E05-BC10-B710B97ECCDE} = {383DBA32-4A3E-48D1-AAC3-75377A694452}
{CB70A642-8CEC-4DDE-8C9F-AD08900EC98D} = {74492CBC-7201-417E-BC29-28B4C25A58B0} {CB70A642-8CEC-4DDE-8C9F-AD08900EC98D} = {74492CBC-7201-417E-BC29-28B4C25A58B0}
{F879F274-EFA0-4157-8404-33A19B4E6AEC} = {104288A3-382E-4032-AF50-FBB5FDAB9EBB}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal