mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 12:03:51 +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;
|
using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
namespace Orchard.Modules.Commands {
|
namespace Orchard.Modules.Commands {
|
||||||
public class FeatureCommand : DefaultOrchardCommandHandler {
|
public class FeatureCommands : DefaultOrchardCommandHandler {
|
||||||
private readonly IModuleService _moduleService;
|
private readonly IModuleService _moduleService;
|
||||||
private readonly INotifier _notifier;
|
private readonly INotifier _notifier;
|
||||||
|
|
||||||
public FeatureCommand(IModuleService moduleService, INotifier notifier) {
|
public FeatureCommands(IModuleService moduleService, INotifier notifier) {
|
||||||
_moduleService = moduleService;
|
_moduleService = moduleService;
|
||||||
_notifier = notifier;
|
_notifier = notifier;
|
||||||
}
|
}
|
||||||
@@ -63,8 +63,8 @@ namespace Orchard.Modules.Commands {
|
|||||||
}
|
}
|
||||||
if (featuresToEnable.Count != 0) {
|
if (featuresToEnable.Count != 0) {
|
||||||
_moduleService.EnableFeatures(featuresToEnable, true);
|
_moduleService.EnableFeatures(featuresToEnable, true);
|
||||||
foreach(var entry in _notifier.List()) {
|
foreach (var entry in _notifier.List()) {
|
||||||
Context.Output.WriteLine(entry.Message);
|
Context.Output.WriteLine(entry.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -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>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AdminMenu.cs" />
|
<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="Controllers\AdminController.cs" />
|
||||||
<Compile Include="Extensions\StringExtensions.cs" />
|
<Compile Include="Extensions\StringExtensions.cs" />
|
||||||
<Compile Include="Models\ModuleFeature.cs" />
|
<Compile Include="Models\ModuleFeature.cs" />
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ namespace Orchard.Packaging {
|
|||||||
EndPackage(context);
|
EndPackage(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (context.Stream.CanSeek)
|
||||||
|
context.Stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
return context.Stream;
|
return context.Stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user