Orchard控制台

Orchard提供了一组控制台命令,来替代Orchard后台管理站点。

进入控制台:

  1. 进入cmd
  2. 进入Orchard站点的bin目录
  3. 输入Orchard.exe,回车。

使用命令

输入help commands可,以查看可用命令

如后你的站在还未安装,那么,只有Setup命令可以执行。Setup命令相当于在安装页面执行站点安装,但是它还能通过附加参数,决定哪些特性启用。

安装完成以后,再次执行help commands命令,你会发现多了很多的命令

orchard> help commands

List of available commands:

---------------------------

 

blog create /Slug:<slug> /Title:<title> /Owner:<username> [/MenuText:<menu text>]

Creates a new Blog

 

blog import /Slug:<slug> /FeedUrl:<feed url> /Owner:<username>

Import all items from <feed url> into the blog at the specified <slug>

 

cultures get site culture

Get culture for the site

 

cultures list

List site cultures

 

cultures set site culture <culture-name>

Set culture for the site

 

feature disable <feature-name-1> ... <feature-name-n>

Disable one or more features

 

feature enable <feature-name-1> ... <feature-name-n>

Enable one or more features

 

feature list [/Summary:true|false]

Display list of available features

 

help <command>

Display help text for <command>

 

help commands

Display help text for all available commands

 

package create <extensionName> <path>

Create a package for the extension <extensionName>

(an extension being a module or a theme).

The package will be output at the <path> specified.

The default filename is Orchard.[Module|Theme].<extensionName>.<extensionVersion>.nupkg.

For example, "package create SampleModule c:\temp" will create the package

"c:\temp\Orchard.Module.SampleModule.1.0.0.nupkg".

 

package install <packageId> <location> /Version:<version>

Install a module or a theme from a package file.

 

package uninstall <packageId>

Uninstall a module or a theme.

The <packageId> should take the format Orchard.[Module|Theme].<extensionName>.

For example, "package uninstall Orchard.Module.SampleModule" will uninstall the Module under the "~/Modules/SampleModule" directory and

"package uninstall Orchard.Theme.SampleTheme" will uninstall the Theme under the "~/Themes/SampleTheme" directory.

 

user create /UserName:<username> /Password:<password> /Email:<email>

Creates a new User

可用的命令取决于站点启用的特性。你可以通过"feature list" 或者 "feature list /Summary:true"查看所有特性,也可以通过feature enable <feature-name> 命令启用特性

orchard> feature list /Summary:true

Common, Enabled

Containers, Enabled

Contents, Enabled

Dashboard, Enabled

DatabaseUpdate, Disabled

Feeds, Enabled

Gallery, Enabled

HomePage, Enabled

Lucene, Disabled

Navigation, Enabled

Orchard.ArchiveLater, Disabled

Orchard.Blogs, Enabled

Orchard.Blogs.RemotePublishing, Disabled

Orchard.CodeGeneration, Enabled

Orchard.Comments, Enabled

Orchard.ContentTypes, Enabled

Orchard.Email, Disabled

Orchard.Experimental, Disabled

Orchard.Experimental.TestingLists, Disabled

Orchard.Experimental.WebCommandLine, Disabled

Orchard.Indexing, Disabled

Orchard.jQuery, Enabled

Orchard.Lists, Enabled

Orchard.Localization, Disabled

Orchard.Media, Enabled

Orchard.Messaging, Disabled

Orchard.Migrations, Disabled

Orchard.Modules, Enabled

Orchard.MultiTenancy, Disabled

Orchard.Packaging, Enabled

Orchard.Pages, Enabled

Orchard.PublishLater, Enabled

Orchard.Roles, Enabled

Orchard.Scripting, Enabled

Orchard.Scripting.Dlr, Disabled

Orchard.Scripting.Lightweight, Enabled

Orchard.Search, Disabled

Orchard.Setup, Disabled

Orchard.Tags, Enabled

Orchard.Themes, Enabled

Orchard.Users, Enabled

Orchard.Widgets, Enabled

PackagingServices, Enabled

Profiling, Disabled

Reports, Enabled

Routable, Enabled

SafeMode, Disabled

Scheduling, Enabled

Settings, Enabled

Shapes, Enabled

TheAdmin, Disabled

TheThemeMachine, Enabled

TinyMce, Enabled

XmlRpc, Disabled

批量或者单条执行脚本

这里有两种"Non-interactive" 模式:单行命令和响应文件。

单行命令

单行命令会立即执行,而且执行完成以后,Orchard.exe会自动退出。

首先进入站点的bin目录,然后执行下面的命令:

orchard package create "Orchard.Blogs" "c:\\temp\\"

响应文件

响应文件包含了多条命令,一条命令一行。这样能够批量的执行命令。

我们创建一个响应文件 myfile.txt,内容如下:

package create "Orchard.Blogs" "c:\\temp\\"

package create "Orchard.Users" "c:\\temp\\"

下面的命令执行响应文件:

orchard @myfile.txt

新增命令

你可以通过继承Orchard.Commands.DefaultOrchardCommandHandler类来创建自己的命令。命令是一个简单的方法,具有CommanName特性,能执行你设定的逻辑。下面的代码创建了一个"hello world"命令,具有一个名称为name的参数和名称为YouRock的可选参数。

[CommandName("hello world")]

[CommandHelp(@"hello world <name> [/YouRock:true|false]

Says hello and whether you rock or not.")]

[OrchardSwitches("YouRock")]

public void HelloWorld(string name) {

Context.Output.WriteLine(T("Hello {0}.", name ?? "world"));

Context.Output.WriteLine(YouRock ? "You rock." : "You do not rock.");

}

可选参数的声明方式和属性一致

[OrchardSwitch]

public bool YouRock { get; set; }

命令在整个Orchard站点都可以执行(不区分程序集,作用域),它能访问数据库,使用依赖注入等等代码可以执行的操纵,它都能执行。

命令执行时的错误

不建议的命令执行的时候抛出错误,但是,在任何时候,命令都应该有返回值,如果要抛出错误,请抛出OrchardException类型错误。

posted @ 2015-08-25 14:43  争世不悔  阅读(234)  评论(0编辑  收藏  举报