Table of Contents

Class ROCrate

Namespace
ROCrates
Assembly
ROCrates.Net.dll

A class representing an RO-Crate.

Use this class to read and write RO-Crates.

public class ROCrate
Inheritance
ROCrate
Inherited Members

Constructors

ROCrate()

Initialise a new empty ROCrate object.

public ROCrate()

Fields

Entities

A Dictionary<TKey, TValue> containing all the entities in the ROCrate.

The keys are the same as the @id tags in the ro-crate-metadata.json @graph.

public Dictionary<string, Entity> Entities

Field Value

Dictionary<string, Entity>

Metadata

A reference to the Metadata object of the ROCrate.

public Metadata Metadata

Field Value

Metadata

Preview

A reference to the Preview object of the ROCrate.

public Preview Preview

Field Value

Preview

RootDataset

A reference to the RootDataset object of the ROCrate.

public RootDataset RootDataset

Field Value

RootDataset

Methods

Add(params Entity[])

Add entities to an ROCrate.

public void Add(params Entity[] entities)

Parameters

entities Entity[]

The entities to add the RO-Crate.

Examples

var roCrate = new ROCrate();
var textFile = new File(roCrate, source: "my-file.txt");
var imageFile = new File(roCrate, source: "my-image.png");
var person = new Person(roCrate);
roCrate.Add(textFile, imageFile, person);

AddDataset(string?, JsonObject?, string?, string?, bool, bool)

Add a dataset to the ROCrate and return the created Dataset object.

public Dataset AddDataset(string? identifier = null, JsonObject? properties = null, string? source = null, string? destPath = null, bool fetchRemote = false, bool validateUrl = false)

Parameters

identifier string

The unique identifier.

properties JsonObject

Additional properties of the dataset.

source string

The path to the dataset.

destPath string

The path to where dataset will be saved.

fetchRemote bool

Fetch the dataset from remote location?

validateUrl bool

Check the URL?

Returns

Dataset

A new Dataset with the given parameters.

Examples

var roCrate = new ROCrate();
var dataset = roCrate.AddDataset();

AddFile(string?, JsonObject?, string?, string?, bool, bool)

Add a file to the ROCrate and return the created File object.

public File AddFile(string? identifier = null, JsonObject? properties = null, string? source = null, string? destPath = null, bool fetchRemote = false, bool validateUrl = false)

Parameters

identifier string

The unique identifier.

properties JsonObject

Additional properties of the file.

source string

The path to the file.

destPath string

The path to where file will be saved.

fetchRemote bool

Fetch the file from remote location?

validateUrl bool

Check the URL?

Returns

File

A new File with the given parameters.

Examples

var roCrate = new ROCrate();
var file = roCrate.AddFile();

AddPerson(string?, JsonObject?)

Add a person to the ROCrate and return the created Person object.

public Person AddPerson(string? identifier = null, JsonObject? properties = null)

Parameters

identifier string

The unique identifier of the person.

properties JsonObject

Additional properties of the person.

Returns

Person

Examples

var roCrate = new ROCrate();
var person = roCrate.AddPerson();

Remarks

A new Person with the given parameters.

AddTestDefinition(string?, JsonObject?, string?, string?, bool, bool)

Add a test definition to the ROCrate and return the created TestDefinition object.

public TestDefinition AddTestDefinition(string? identifier = null, JsonObject? properties = null, string? source = null, string? destPath = null, bool fetchRemote = false, bool validateUrl = false)

Parameters

identifier string

The unique identifier.

properties JsonObject

Additional properties of the test definition.

source string

The path to the test definition file.

destPath string

The path to where test definition file will be saved.

fetchRemote bool

Fetch the test definition from remote location?

validateUrl bool

Check the URL?

Returns

TestDefinition

A new TestDefinition with the given parameters.

Examples

var roCrate = new ROCrate();
var testDefinition = roCrate.AddTestDefinition();

AddTestInstance(TestSuite, string, string, TestService?, string?)

Add a test instance to the ROCrate and return the TestInstance object.

public TestInstance AddTestInstance(TestSuite testSuite, string url, string resource = "", TestService? testService = null, string? name = null)

Parameters

testSuite TestSuite

The suite the test instance is run in.

url string

The URL to the test instance.

resource string

The resource of the test instance.

testService TestService

The service used to run the test instance.

name string

The name of the test instance.

Returns

TestInstance

The TestInstance with the given parameters.

Examples

var roCrate = new ROCrate();
var testInstance = roCrate.AddTestInstance();

AddTestSuite(string?, string?, Entity?)

Add a test suite to the ROCrate and return the created TestSuite object.

public TestSuite AddTestSuite(string? identifier = null, string? name = null, Entity? mainEntity = null)

Parameters

identifier string

The identifier of the test suite.

name string

The name of the test suite.

mainEntity Entity

The main entity of the test suite.

Returns

TestSuite

The TestSuite object with the given parameters.

Examples

var roCrate = new ROCrate();
var testSuite = roCrate.AddTestSuite();

AddWorkflow(string?, JsonObject?, string?, string?, bool, bool)

Add a workflow to the ROCrate and return the created ComputationalWorkflow object.

public ComputationalWorkflow AddWorkflow(string? identifier = null, JsonObject? properties = null, string? source = null, string? destPath = null, bool fetchRemote = false, bool validateUrl = false)

Parameters

identifier string

The unique identifier.

properties JsonObject

Additional properties of the workflow.

source string

The path to the workflow file.

destPath string

The path to where workflow file will be saved.

fetchRemote bool

Fetch the workflow from remote location?

validateUrl bool

Check the URL?

Returns

ComputationalWorkflow

A new ComputationalWorkflow with the given parameters.

Examples

var roCrate = new ROCrate();
var workflow = roCrate.AddWorkflow();

Convert(string)

Convert a directory into an RO-Crate.

This method iterates over the files and directories contained inside source and populates an ROCrate object with entities representing the contents of the RO-Crate. The ro-crate-metadata.json and ro-crate-preview.html files are then saved into source

public void Convert(string source)

Parameters

source string

The path to the directory to be converted to an RO-Crate.

Examples

var roCrate = new ROCrate();
roCrate.Convert("convertMe");

Initialise(string)

Initialise an ROCrate object from the contents of a directory that is a valid RO-Crate.

This method assumes that all files and directories described by the metadata exist on disk. It will not fetch them from remote locations.

public void Initialise(string source)

Parameters

source string

The path to the directory containing the RO-Crate to initialise an ROCrate from.

Exceptions

CrateReadException

Thrown when there is an issue reading the RO-Crate.

MetadataException

Thrown when there is an issue with the RO-Crate's metadata.

ResolveId(string)

Resolves URI for a given ID.

[Obsolete("ResolveId is deprecated")]
public string ResolveId(string id)

Parameters

id string

The ID to be resolved.

Returns

string

The resolved URI for the given ID.

Save(string?, bool)

Save the ROCrate to disk.

public void Save(string? location = null, bool zip = false)

Parameters

location string

The directory where the data entities will be written. This will become a .zip file with the name {location}.zip if zip is true. If location is null, the current working directory will be used.

zip bool

If true, save the RO-Crate as a .zip file, else save to a directory. Default: false