从CLI工具访问Sitecore的API [英] Accessing Sitecore API from a CLI tool
问题描述
我想从一个命令行工具访问Sitecore的API(与出口有关数据库中的用户的一些信息的目的),但我一直没能得到连一个简单的命令行程序。
I would like to access the Sitecore API from within a command line tool (with a goal of exporting some information about users in the database), however I haven't been able to get a simple CLI program connected.
要举一个简单的例子
using Sitecore;
using Sitecore.Configuration;
using Sitecore.Data;
using Sitecore.Data.Items;
...
static void Main(string[] args)
{
Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
Console.WriteLine(master.Items.ToString());
}
由于这个目前为,我得到下面的异常
As this currently stands, I get the following exception
Unhandled Exception: System.InvalidOperationException: Could not read Sitecore configuration.
at Sitecore.Configuration.Factory.GetConfiguration()
at Sitecore.Configuration.Factory.GetConfigNode(String xpath, Boolean assert)
at Sitecore.Configuration.Factory.CreateObject(String configPath, String[] parameters, Boolean assert)
at Sitecore.Configuration.Factory.CreateObject(String configPath, Boolean assert)
at Sitecore.Configuration.Factory.GetDatabase(String name, Boolean assert)
at Sitecore.Configuration.Factory.GetDatabase(String name)
at Example.Program.Main(String[] args)
我认为这关系到系统无法找到合适的web.config文件(令人吃惊,因为我从来没有告诉它所在的位置),但我看不出有什么办法配置此告诉它在哪里看的。
I assume this related to the inability of the system to find the appropriate web.config file (unsurprising since I never told it where it was), however I see no way of configuring this to tell it where to look.
那么,我该怎么配置Sitecore的找到它的Web.config文件中,或者,我应该如何进行不同处理这个问题,以得到一个命令行工具访问Sitecore的API?
So, how can I configure Sitecore to find it's web.config file, or, how should I be approaching this problem differently to get access to the Sitecore API from a command line tool?
推荐答案
这是可能使用的app.config(我无法证实或否认),但你将有一个更容易的时间Web服务这样做。可能最简单的办法是创建一个你所需要的逻辑的自定义Web服务,并使用CLI来调用/触发服务。
This may be possible using App.Config (I cannot confirm or deny) but you will have a much easier time doing this by web service. Likely easiest would be to create a custom web service with the logic you need, and use a CLI to call/trigger the service.
这篇关于从CLI工具访问Sitecore的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!