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
entitiesEntity[]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
identifierstringThe unique identifier.
propertiesJsonObjectAdditional properties of the dataset.
sourcestringThe path to the dataset.
destPathstringThe path to where dataset will be saved.
fetchRemoteboolFetch the dataset from remote location?
validateUrlboolCheck 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
identifierstringThe unique identifier.
propertiesJsonObjectAdditional properties of the file.
sourcestringThe path to the file.
destPathstringThe path to where file will be saved.
fetchRemoteboolFetch the file from remote location?
validateUrlboolCheck 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
identifierstringThe unique identifier of the person.
propertiesJsonObjectAdditional 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
identifierstringThe unique identifier.
propertiesJsonObjectAdditional properties of the test definition.
sourcestringThe path to the test definition file.
destPathstringThe path to where test definition file will be saved.
fetchRemoteboolFetch the test definition from remote location?
validateUrlboolCheck 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
testSuiteTestSuiteThe suite the test instance is run in.
urlstringThe URL to the test instance.
resourcestringThe resource of the test instance.
testServiceTestServiceThe service used to run the test instance.
namestringThe 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
identifierstringThe identifier of the test suite.
namestringThe name of the test suite.
mainEntityEntityThe 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
identifierstringThe unique identifier.
propertiesJsonObjectAdditional properties of the workflow.
sourcestringThe path to the workflow file.
destPathstringThe path to where workflow file will be saved.
fetchRemoteboolFetch the workflow from remote location?
validateUrlboolCheck 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
sourcestringThe 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
idstringThe 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
locationstringThe directory where the data entities will be written. This will become a .zip file with the name {location}.zip if
zipistrue. Iflocationisnull, the current working directory will be used.zipboolIf
true, save the RO-Crate as a .zip file, else save to a directory. Default:false