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
Metadata
public Metadata Metadata
Field Value
Preview
public Preview Preview
Field Value
RootDataset
A reference to the RootDataset object of the ROCrate.
public RootDataset RootDataset
Field Value
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)
public Dataset AddDataset(string? identifier = null, JsonObject? properties = null, string? source = null, string? destPath = null, bool fetchRemote = false, bool validateUrl = false)
Parameters
identifier
stringThe unique identifier.
properties
JsonObjectAdditional properties of the dataset.
source
stringThe path to the dataset.
destPath
stringThe path to where dataset will be saved.
fetchRemote
boolFetch the dataset from remote location?
validateUrl
boolCheck the URL?
Returns
Examples
var roCrate = new ROCrate();
var dataset = roCrate.AddDataset();
AddFile(string?, JsonObject?, string?, string?, bool, bool)
public File AddFile(string? identifier = null, JsonObject? properties = null, string? source = null, string? destPath = null, bool fetchRemote = false, bool validateUrl = false)
Parameters
identifier
stringThe unique identifier.
properties
JsonObjectAdditional properties of the file.
source
stringThe path to the file.
destPath
stringThe path to where file will be saved.
fetchRemote
boolFetch the file from remote location?
validateUrl
boolCheck the URL?
Returns
Examples
var roCrate = new ROCrate();
var file = roCrate.AddFile();
AddPerson(string?, JsonObject?)
public Person AddPerson(string? identifier = null, JsonObject? properties = null)
Parameters
identifier
stringThe unique identifier of the person.
properties
JsonObjectAdditional properties of the person.
Returns
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
stringThe unique identifier.
properties
JsonObjectAdditional properties of the test definition.
source
stringThe path to the test definition file.
destPath
stringThe path to where test definition file will be saved.
fetchRemote
boolFetch the test definition from remote location?
validateUrl
boolCheck 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
TestSuiteThe suite the test instance is run in.
url
stringThe URL to the test instance.
resource
stringThe resource of the test instance.
testService
TestServiceThe service used to run the test instance.
name
stringThe 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?)
public TestSuite AddTestSuite(string? identifier = null, string? name = null, Entity? mainEntity = null)
Parameters
identifier
stringThe identifier of the test suite.
name
stringThe name of the test suite.
mainEntity
EntityThe main entity of the test suite.
Returns
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
stringThe unique identifier.
properties
JsonObjectAdditional properties of the workflow.
source
stringThe path to the workflow file.
destPath
stringThe path to where workflow file will be saved.
fetchRemote
boolFetch the workflow from remote location?
validateUrl
boolCheck 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
stringThe 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
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
stringThe 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
stringThe directory where the data entities will be written. This will become a .zip file with the name {location}.zip if
zip
istrue
. Iflocation
isnull
, the current working directory will be used.zip
boolIf
true
, save the RO-Crate as a .zip file, else save to a directory. Default:false