-
Notifications
You must be signed in to change notification settings - Fork 7
Publishing Data
One of the main draws of the Learning Registry service is the breadth and flexibility in which information about learning resources can be described through its data model. In dynamically-typed languages, where JSON serialization/deserialization is often trivial, expressing the data in the proper format for publishing is quite easy to accomplish. Unfortunately, in statically-typed languages, such as C# and Java, data structures are usually defined at compile-time, causing an issue with type-resolution and access modifiers that cannot usually be inferred from raw JSON data. This can somewhat be circumvented in C# using generic data structures such as ArrayLists
and Dictionaries
to hold non-primitives; however, this disadvantages coders in the way that they must understand much more of the framework they are manipulating, as Intellisense and other productivity-boosting tools will be useless on a structure such as Dictionary<string, object>
where the available fields are not obvious to the developer.
Thus, the majority of the LR Resource Description Data Model has been recreated for the simplification of creation, population, publication, and consumption of JSON documents stored in the Learning Registry. Here, we will provide an example of how to properly create and publish an LR document through LR.Net.
Important Classes:
- lr_document - The Resource Data Description Document that stores metadata or paradata about a learning resource.
- lr_Envelope - The envelope that contains one or more lr_documents, as well as an optional digital signature.
- LRClient - The main LR.Net interface to a Learning Registry Node.
lr_document doc = new lr_document();
//Add one or more keys describing the resource
string[] keywords = new string[] { "keyword1", "keyword2" };
foreach (string key in keywords)
doc.keys.Add(key);
//This is the URI of the resource this data describes
doc.resource_locator = "http://www.example.com/LearningRegistryTest.html";
//Submitter information (i.e. who published this and verified it as a learning resource)
doc.identity.submitter = "John Doe";
doc.identity.signer = "John Doe";
doc.identity.submitter_type = "agent";
//The data is paradata
doc.resource_data_type = "paradata";
//Fill in info about the format of this paradata
doc.payload_schema.Add("LearningRegistry_Paradata_1_0");
//Provide the resource data. Must be a serializable object to publish.
doc.resource_data = "<whatever you want>";
//Create the envelope to send this document
lr_Envelope envelope = new lr_Envelope();
envelope.docs.Add(doc);
//Instantiate the LRClient to publish the data
LRClient client = new LRClient("http://localhost");
PublishResponse response = client.Publish(env);
//Make sure the publish went ok
if(response.error != "" || response.document_results[0].error != "")
throw new Exception("Something went wrong");