如何为Neo4j服务经理编程?
How to program a Neo4j Service Manager?
- Caslon Melior 问题:
- I am trying to write a Neo4j service manager program in C# that can start and stop local graph databases using the current Neo4j version, 3.3.5. The program should replicate the functionality of the discontinued
Neo4j-ce.exe
program. The program will call the same PowerShell commands that are in theNeo4j.bat
file. This is the first PowerShell script I have tried to write. - 到目前为止,程序在启动时会出现许多异常错误,这些错误以“无法找到或打开PDB文件”结束当我运行PowerShell实例代码时,会引发安全异常。。。
Exception thrown: 'System.DllNotFoundException' in System.Management.Automation.dllException thrown: 'System.Security.SecurityException' in mscorlib.dll
- ... Yet the
PowerShellInstance.Streams.Error.Count
is zero. Neo4j.bat
contains this call to PowerShell:PowerShell -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -Command "try { Unblock-File -Path '%~dp0Neo4j-Management\*.*' -ErrorAction 'SilentlyContinue' } catch {};Import-Module '%~dp0Neo4j-Management.psd1'; Exit (Invoke-Neo4j %*)"
Neo4jServiceManager.exe
contains this button event:private void btnNeo4jStart_Click(object sender, EventArgs e){ // Create runspace to be used by PowerShell instance. Runspace myRunspace = RunspaceFactory.CreateRunspace(); myRunspace.Open(); // Start PowerShell instance. using (PowerShell PowerShellInstance = PowerShell.Create()) { // Add runspace to PowerShell instance. PowerShellInstance.Runspace = myRunspace; // Add command to pipeline. // Import module: Neo4j-Management.psd1 and execute Invoke-Neo4j cmdlet. PowerShellInstance.AddScript(@"C:\; cd C:\neo4j-community-3.3.5; SETLOCAL; try { Unblock-File -Path 'C:\neo4j-community-3.3.5\bin\Neo4j-Management\*.*' -ErrorAction 'SilentlyContinue' } catch {}; Exit ('C:\neo4j-community-3.3.5\bin\Neo4j-Management\Invoke-Neo4j.psd1 install-service')"); // Invoke execution on the pipeline (and collect output). Collection<PSObject> PSOutput = PowerShellInstance.Invoke(); // Loop through each output object item. foreach (PSObject outputItem in PSOutput) { // if null object was dumped to the pipeline during the script then a null // object may be present here. check for null to prevent potential NRE. if (outputItem != null) { //TODO: do something with the output item // outputItem.BaseOBject } } // Check the other output streams (for example, the error stream). // If PowerShellInstance.Streams.Error.Count = 1, then // PowerShellInstance.Streams.Error[0].CategoryInfo returns information. if (PowerShellInstance.Streams.Error.Count > 0) { // error records were written to the error stream. // do something with the items found. } }}
- I am trying to write a Neo4j service manager program in C# that can start and stop local graph databases using the current Neo4j version, 3.3.5. The program should replicate the functionality of the discontinued
- 回答: