mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-19 01:57:55 +08:00
Create module packaging command handlers
--HG-- branch : dev rename : src/Orchard.Web/Modules/Orchard.Modules/Commands/FeatureCommand.cs => src/Orchard.Web/Modules/Orchard.Modules/Commands/FeatureCommands.cs
This commit is contained in:
@@ -5,11 +5,11 @@ using Orchard.UI.Notify;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.Modules.Commands {
|
||||
public class FeatureCommand : DefaultOrchardCommandHandler {
|
||||
public class FeatureCommands : DefaultOrchardCommandHandler {
|
||||
private readonly IModuleService _moduleService;
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public FeatureCommand(IModuleService moduleService, INotifier notifier) {
|
||||
public FeatureCommands(IModuleService moduleService, INotifier notifier) {
|
||||
_moduleService = moduleService;
|
||||
_notifier = notifier;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ namespace Orchard.Modules.Commands {
|
||||
}
|
||||
if (featuresToEnable.Count != 0) {
|
||||
_moduleService.EnableFeatures(featuresToEnable, true);
|
||||
foreach(var entry in _notifier.List()) {
|
||||
foreach (var entry in _notifier.List()) {
|
||||
Context.Output.WriteLine(entry.Message);
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
using System.IO;
|
||||
using Orchard.Commands;
|
||||
using Orchard.Packaging;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Modules.Commands {
|
||||
public class PackagingCommands : DefaultOrchardCommandHandler {
|
||||
private readonly IModuleService _moduleService;
|
||||
private readonly INotifier _notifier;
|
||||
private readonly IPackageManager _packageManager;
|
||||
|
||||
public PackagingCommands(IModuleService moduleService, INotifier notifier, IPackageManager packageManager) {
|
||||
_moduleService = moduleService;
|
||||
_notifier = notifier;
|
||||
_packageManager = packageManager;
|
||||
}
|
||||
|
||||
[OrchardSwitch]
|
||||
public string Filename { get; set; }
|
||||
|
||||
[CommandHelp("module create package <moduleName> [/Filename:filename.zip]\r\n\t" + "Create a package for the module <moduleName>. The default filename is <moduleName>-<moduleVersion>.zip.")]
|
||||
[CommandName("module create package")]
|
||||
[OrchardSwitches("Filename")]
|
||||
public void CreatePackage(string moduleName) {
|
||||
var packageData = _packageManager.Harvest(moduleName);
|
||||
if (packageData == null) {
|
||||
Context.Output.WriteLine(T("Module \"{0}\" does not exist in this Orchard installation.", moduleName));
|
||||
return;
|
||||
}
|
||||
|
||||
var filename = Filename;
|
||||
if(string.IsNullOrEmpty(filename)) {
|
||||
filename = string.Format("{0}-{1}.zip", packageData.ExtensionName, packageData.ExtensionVersion);
|
||||
}
|
||||
|
||||
using(var stream = File.Create(filename)) {
|
||||
packageData.PackageStream.CopyTo(stream);
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
var fileInfo = new FileInfo(filename);
|
||||
Context.Output.WriteLine(T("Package \"{0}\" successfully created", fileInfo.FullName));
|
||||
}
|
||||
|
||||
[CommandHelp("module install package <filename>\r\n\t" + "Install a module from a package <filename>.")]
|
||||
[CommandName("module install package")]
|
||||
public void InstallPackage(string filename) {
|
||||
if (!File.Exists(filename)) {
|
||||
Context.Output.WriteLine(T("File \"{0}\" does not exist.", filename));
|
||||
}
|
||||
|
||||
using (var stream = File.Open(filename, FileMode.Open, FileAccess.Read)) {
|
||||
var packageInfo = _packageManager.Install(stream);
|
||||
Context.Output.WriteLine(T("Package \"{0}\" successfully installed at \"{1}\"", packageInfo.ExtensionName, packageInfo.ExtensionPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -66,7 +66,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Commands\FeatureCommand.cs" />
|
||||
<Compile Include="Commands\PackagingCommands.cs" />
|
||||
<Compile Include="Commands\FeatureCommands.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Extensions\StringExtensions.cs" />
|
||||
<Compile Include="Models\ModuleFeature.cs" />
|
||||
|
@@ -48,6 +48,9 @@ namespace Orchard.Packaging {
|
||||
EndPackage(context);
|
||||
}
|
||||
|
||||
if (context.Stream.CanSeek)
|
||||
context.Stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
return context.Stream;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user