The Nuxeo .NET Client is a cross-platform client library developed in C# for the Nuxeo Automation and REST API.
Nuxeo .NET Client targets two platforms: net45
and dnxcore50
. This allows it to be used to develop apps for not only Windows but also Linux and Mac OS. Bellow follows an app/platform compatibility table for the Nuxeo .NET Client library:
1 +------------------------------------+------------+
3 +------------------------------------+------------+
4 | Destkop .NET 4.5+ | Yes |
5 | ASP .NET 4.5+ | Yes |
6 | ASP .NET 5 (Native & CoreCLR) | Yes |
7 | DNX Console App (Native & CoreCLR) | Yes |
8 | Windows 8/8.1 Store APP | No |
9 | Windows Phone 8/8.1 | No |
10 | Windows 10 (UWP) | No |
11 | Xamarin.Android | Yes? |
12 | Xamarin.iOS | Yes? |
13 +------------------------------------+------------+
Setup
In order to run Nuxeo .NET Client, you must have installed the .NET Core DNX SDK, version 1.0.0-beta8 or above, or .NET 4.5 on a Windows setup. Installation instructions follow below:
- Install .NET Core:
Add the following feeds to NuGet config file:
If you do not yet have a config file, create it on:
- For Mac OS & Linux: *~/.config/NuGet/NuGet.config*
- For Windows: *AppData%/NuGet/NuGet.Config*
And paste the following contents:
1 <?
xml version=
"1.0" encoding=
"utf-8"?>
4 <
add key=
"AspNetVNext" value=
"https://www.myget.org/F/aspnetvnext/" />
5 <
add key=
"NuGet" value=
"https://www.nuget.org/api/v2/" />
On Visual Studio 2015
If you are using Visual Studio 2015 on Windows, you will need to download the Microsoft ASP.NET and Web Tools 2015 (Beta8) – Visual Studio. Two setup files must be installed:
- DotNetVersionManager-x64.msi
- WebToolsExtensionsVS14.msi for Visual Studio 2015 or WebToolsExtensionsVWD14.msi for Visual Studio 2015 Express
Usage
Download the NuxeoClient nupkg file and install it by running dnu install NuxeoClient -s <path-to-nupkg-file-parent-folder>
.
Include NuxeClient dependency in your project.json file:
5 "NuxeoClient": "1.0.0-*"
Reference NuxeoClient and NuxeoClient.Wrappers namespaces:
Create a new instance of NuxeoClient:
Client client = new Client();
Create a folder named "Test Folder 1" on the root:
client.Operation("Document.Create")
.SetInput("doc:/")
.SetParameter("type", "Folder")
.SetParameter("name", "TestFolder1")
.SetParameter("properties", new ParamProperties { { "dc:title", "Test Folder 1" } })
.Execute();
If you want to do something with the result, you can either wait for it with a .Execute().Result;
or continue the async call with .Execute().ContinueWith(...);
.
Please check the tests on test/TCK for more usage examples and the tutorial and the end of this document.
Running the Tests
This project includes a Test Compatibility Kit (TCK) covering several tests on the client. In order for the tests to run, there must be an instance of the Nuxeo Server running, loading nuxeo-automation-test-7.10-SNAPSHOT.jar.
Before running the tests, the server's ip address should be updated in the test/TCK/config.json file.
Then, on the solution folder, run:
dnu restore
to download all dependencies
cd test/TCK
to move to the TCK folder
dnx test
to run all tests
On Visual Studio 2015
- Open the solution on Visual Studio
- Show the Test Explorer, if not displayed already: go to
Test > Window > Test Explorer
- Build solution, which will automatically discover all tests
- On Test Explorer, hit Run All to run all tests
If any errors are displayed regarding missing dependencies:
- Open the Package Manager Console:
Tools > NuGet Package Manager > Package Manager Console
- Run
dnu restore
Known Issues
There is currently a bug where DELETE requests are sent as GET on Linux and Mac OS only, which prevents operations such as deleting documents and drop batches from working. This issue was reported here. This bug causes 5 out of 9 tests of the TCK to fail, on the last stage where all temporary files are deleted.
Tutorial
Let's make a quick DNX Console App that creates a folder on the server's root and a child document. This quit tutorial assumes that you have an instance of Nuxeo Server running on your local machine.
- Create a new directory for your project named TestNuxeoApp and
cd
there
- Download the NuxeoClient nupkg file and install it by running
dnu install NuxeoClient -s <path-to-nupkg-file-parent-folder>
- Create a new project.json with dependencies to "System.Console" and "NuxeoClient". It should look something like this:
3 "description": "Nuxeo Test App",
13 "System.Console": "4.0.0-beta-23409",
14 "NuxeoClient": "1.0.0-*"
- Inside the project directory, create a new file named Program.cs. Make it create a new Nuxeo Client, create a folder in the server's root directory named "My Folder", and then a file inside My Folder named "My File". It should look something like this:
namespace TestNuxeoApp
{
public class Program
{
public static void Main(string[] args)
{
using(var client = new Client())
{
client.Operation("Document.Create")
.SetInput("doc:/")
.SetParameter("type", "Folder")
.SetParameter("name", "MyFolder")
.SetParameter("properties", new ParamProperties { { "dc:title", "My Folder" } })
.Execute().ContinueWith((folderResponse) => {
Document folder = folderResponse.Result as Document;
Console.WriteLine(folder == null ? "Failed to create folder." : "Created " + folder.Path);
folder.Create(new Document {
Type = "File",
Name = "MyFile",
Properties = new Properties { { "dc:title", "My File" } }
}).ContinueWith((fileResponse) => {
Document file = fileResponse.Result as Document;
Console.WriteLine(file == null ? "Failed to create file." : "Created " + file.Path);
}).Wait();
}).Wait();
}
}
}
}
- Restore dependencies by running
dnu restore
- Run the app by running
dnx run
- Check the server and verify that the documents were created