public PublishResponse Publish(lr_Envelope docs) { string rawData = LRUtils.HttpPostRequest(_baseUri, LRUtils.Routes.Publish, docs.Serialize(), "application/json", this.Username, this.Password); return _serializer.Deserialize<PublishResponse>(rawData); }
public PublishResponse Publish(lr_Envelope docs) { string rawData = LRUtils.HttpPostRequest(_baseUri, LRUtils.Routes.Publish, docs.Serialize(), "application/json", this.Username, this.Password); return(_serializer.Deserialize <PublishResponse>(rawData)); }
public static lr_Envelope buildParadataTestEnvelope(int numDocs = 1) { //create a document and an envelop lr_Envelope env = new lr_Envelope(); for(int i = 0; i < numDocs; i++) { lr_document doc = new lr_document(); //Add the keys from the contentobject to the keys for the document doc.keys.Add("3DR"); 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"; //Submitted by the ADL3DR agent doc.identity.submitter = "austin montoya";//LearningRegistry.Settings.LearningRegistry_Integration_SubmitterName(); doc.identity.signer = "austin montoya";//LearningRegistry.Settings.LearningRegistry_Integration_SignerName(); doc.identity.submitter_type = "agent"; //The data is paradata doc.resource_data_type = "paradata"; //Set ActivityStream as the paradata schema doc.payload_schema.Add("LearningRegistry_Paradata_1_0"); LearningRegistry.Paradata.lr_Activity activity = new lr_Activity(); //Create a paradata object LearningRegistry.Paradata.lr_Paradata pd = activity.activity; //Create a complex actor type, set to 3dr user lr_Actor.lr_Actor_complex mActor = new lr_Actor.lr_Actor_complex(); mActor.description.Add("AnonymousUser"); mActor.objectType = "3DR User"; //Set the paradata actor pd.actor = mActor; //Create a complex verb type lr_Verb.lr_Verb_complex verb = new lr_Verb.lr_Verb_complex(); verb.action = "Published"; verb.context.id = ""; verb.date = DateTime.Now; verb.measure = null; //Set the paradata verb pd.verb = verb; //Create a complex object type lr_Object.lr_Object_complex _object = new lr_Object.lr_Object_complex(); _object.id = "an object id"; //Set the paradata object pd._object = _object; //A human readable description for the paradata pd.content = "The a user uploaded a new model which was assigned the PID ..."; //The resource_data of this Resource_data_description_document is the inline paradata doc.resource_data = activity; env.documents.Add(doc); } //sign the envelope //env.Sign(LearningRegistry.Settings.LearningRegistry_Integration_KeyPassPhrase(), LearningRegistry.Settings.LearningRegistry_Integration_KeyID(), LearningRegistry.Settings.LearningRegistry_Integration_PublicKeyURL()); return env; }
private lr_Envelope buildEnvelopeFromMapping() { var sigInfo = this.SignatureInformationWidget; PgpSigner signer = null; bool needToSign = false; if(sigInfo.SignatureType == PublishGUI.SignatureType.LR_PGP) { signer = new PgpSigner(sigInfo.PgpPublicKeyLocations, sigInfo.PgpKeyringLocation, sigInfo.PgpSecretKeyPassphrase); needToSign = true; } Dictionary<string, string> map = new Dictionary<string, string>(); FieldInfo[] infos = typeof(lr_document).GetFields(); int j = 0; for (int i = 0; i < MapRowsContainer.Children.Length; i++) { var info = infos[j]; var mapRow = (CsvToLrMapRow)MapRowsContainer.Children[i]; var customAttributes = info.GetCustomAttributes(typeof(RequiredField), false); if (customAttributes.Length > 0) { RequiredField attr = (RequiredField)customAttributes[0]; if (attr.Immutable) { i--; //It was never added to the RowContainer, so we need to examine mapRow again with the next property j++; //We examined the property, increment this index continue; } } if (nestedTypes.Contains(info.FieldType)) { //Never added to RowContainer, decrement i and increment j if (info.FieldType == typeof(lr_digital_signature)) { i--; j++; continue; } foreach (var subInfo in info.FieldType.GetFields()) { mapRow = (CsvToLrMapRow)MapRowsContainer.Children[i++]; string key = String.Join(".", info.Name, subInfo.Name); map[key] = mapRow.DropDownValue; } if(info.FieldType.GetFields().Length > 0) i--; //avoid double incrementing from loop iterator statment j++; } else map[infos[j++].Name] = mapRow.DropDownValue; } //Create the docs from the map and the dataDict lr_Envelope envelope = new lr_Envelope(); for (int i = 0; i < _rawRowDataList.Count; i++) { lr_document doc = new lr_document(); int rowIndex = 0; foreach (var info in infos) { CsvToLrMapRow currentRow = (CsvToLrMapRow)MapRowsContainer.Children[rowIndex++]; var customAttributes = info.GetCustomAttributes(typeof(RequiredField), false); if(customAttributes.Length > 0 ) { RequiredField attr = (RequiredField)customAttributes[0]; if (attr.Immutable) { rowIndex--; continue; } } if (!nestedTypes.Contains(info.FieldType)) { string val; if (currentRow.IsConstant) val = currentRow.ConstantValue; else if (currentRow.IsSerializeToRow) val = _rawRowDataList[i]; else if (currentRow.DropDownValue == null) continue; //Nothing to map to or assign if they did not choose a value from the dropdown else val = _rowData[map[info.Name]][i]; if (info.FieldType == typeof(List<string>)) { List<string> vals = val.Split(',').ToList<string>(); info.SetValue(doc, vals); } else info.SetValue(doc, Convert.ChangeType(val, info.FieldType)); } else //This is a nested object property { var subFields = info.FieldType.GetFields(); object currentObj = info.GetValue(doc); if (currentObj == null) currentObj = new object(); rowIndex--; if (typeof(lr_digital_signature).Equals(info.FieldType)) continue; foreach (var subField in subFields) { var rowToAdd = MapRowsContainer.Children.Cast<CsvToLrMapRow>() .Where(x => x.Key.Replace("*", "").Split('.')[0] == info.Name && x.Key.Replace("*", "").Split('.')[1] == subField.Name) .ToList()[0]; rowIndex++; //Used another row from subInfo, need to update the index string val; if (rowToAdd.IsConstant) val = rowToAdd.ConstantValue; else if (rowToAdd.IsSerializeToRow) val = _rawRowDataList[i]; else if (rowToAdd.DropDownValue == null) continue; else val = _rowData[map[String.Join(".", info.Name, subField.Name)]][i]; if (subField.FieldType == typeof(List<string>)) { List<string> vals = val.Split(',').ToList<string>(); subField.SetValue(currentObj, vals); } else subField.SetValue(currentObj, val); } } } if(needToSign) doc = signer.Sign(doc); envelope.documents.Add(doc); } return envelope; }
public static String ModelDownloadedInternal(ContentObject co) { lr_Envelope env = new lr_Envelope(); lr_document doc = new lr_document(); //Add the keys from the contentobject to the keys for the document doc.keys.Add("3DR"); string[] keywords = co.Keywords.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string key in keywords) doc.keys.Add(key); //This is the URI of the resource this data describes doc.resource_locator = LR_Integration_APIBaseURL() + co.PID + "/Format/dae?ID=00-00-00"; //Submitted by the ADL3DR agent doc.identity.submitter = LR_Integration_SubmitterName(); doc.identity.signer = LR_Integration_SignerName(); doc.identity.submitter_type = new lr_submitter_type.agent(); //The data is paradata doc.resource_data_type = new lr_resource_data_type.paradata(); //Set ActivityStream as the paradata schema doc.payload_schema.Add(new lr_schema_value.paradata.LR_Paradata_1_0()); Paradata.lr_Activity activity = new lr_Activity(); //Create a paradata object Paradata.lr_Paradata pd = activity.activity; //Set the paradata actor pd.actor = null; //Create a complex verb type lr_Verb.lr_Verb_complex verb = new lr_Verb.lr_Verb_complex(); verb.action = "Downloaded"; verb.context.id = ""; verb.date = DateTime.Now; lr_Measure measure = new lr_Measure(); measure.measureType = "count"; measure.value = co.Downloads.ToString(); verb.measure = measure; //Set the paradata verb pd.verb = verb; //Create a complex object type lr_Object.lr_Object_complex _object = new lr_Object.lr_Object_complex(); _object.id = co.PID; //Set the paradata object pd._object = _object; //A human readable description for the paradata pd.content = "The a user downloaded this model from the ADL 3DR."; //The resource_data of this Resource_data_description_document is the inline paradata doc.resource_data = activity; env.documents.Add(doc); //sign the envelope env.Sign(LR_Integration_KeyPassPhrase(), LR_Integration_KeyID(), LR_Integration_PublicKeyURL()); //Serialize and publish return env.Publish(); }
public static String ModelUploadedInternal(ContentObject co) { //create a document and an envelop lr_Envelope env = new lr_Envelope(); lr_document doc = new lr_document(); //Add the keys from the contentobject to the keys for the document doc.keys.Add("3DR"); string[] keywords = co.Keywords.Split(new char[]{','},StringSplitOptions.RemoveEmptyEntries); foreach (string key in keywords) doc.keys.Add(key); //This is the URI of the resource this data describes doc.resource_locator = LR_Integration_APIBaseURL() + co.PID + "/Format/dae?ID=00-00-00"; //Submitted by the ADL3DR agent doc.identity.submitter = LR_Integration_SubmitterName(); doc.identity.signer = LR_Integration_SignerName() ; doc.identity.submitter_type = new lr_submitter_type.agent(); //The data is paradata doc.resource_data_type = new lr_resource_data_type.paradata(); //Set ActivityStream as the paradata schema doc.payload_schema.Add(new lr_schema_value.paradata.LR_Paradata_1_0()); Paradata.lr_Activity activity = new lr_Activity(); //Create a paradata object Paradata.lr_Paradata pd = activity.activity; //Create a complex actor type, set to 3dr user lr_Actor.lr_Actor_complex mActor = new lr_Actor.lr_Actor_complex(); mActor.description.Add("AnonymousUser"); mActor.objectType = "3DR User"; //Set the paradata actor pd.actor = mActor; //Create a complex verb type lr_Verb.lr_Verb_complex verb = new lr_Verb.lr_Verb_complex(); verb.action = "Published"; verb.context.id = ""; verb.date = DateTime.Now; verb.measure = null; //Set the paradata verb pd.verb = verb; //Create a complex object type lr_Object.lr_Object_complex _object = new lr_Object.lr_Object_complex(); _object.id = co.PID; //Set the paradata object pd._object = _object; //A human readable description for the paradata pd.content = "The a user uploaded a new model which was assigned the PID " + co.PID; //The resource_data of this Resource_data_description_document is the inline paradata doc.resource_data = activity; env.documents.Add(doc); //Create a second document doc = new lr_document(); //Submitted by the ADL3DR agent doc.identity.submitter = LR_Integration_SubmitterName(); doc.identity.signer = LR_Integration_SignerName(); doc.identity.submitter_type = new lr_submitter_type.agent(); //Add the keys from the content object to the document foreach (string key in keywords) doc.keys.Add(key); //the metadata will be inline doc.payload_placement = new lr_payload_placement.inline(); //This is the resource the data describes doc.resource_locator = LR_Integration_APIBaseURL() + co.PID + "/Format/dae?ID=00-00-00"; //The inline resource data is the contentobject var backupdata = co.JSONMetadata; co.JSONMetadata = null; doc.resource_data = co; //Set the scema to dublin core doc.payload_schema.Add(new lr_schema_value.metadata.DublinCore1_1()); //this is metadata doc.resource_data_type = new lr_resource_data_type.metadata(); //Add the doc to the envelope env.documents.Add(doc); //sign the envelope env.Sign(LR_Integration_KeyPassPhrase(),LR_Integration_KeyID(),LR_Integration_PublicKeyURL()); co.JSONMetadata = backupdata; //Serialize and publish return env.Publish(); }
static public String ModelUploadedInternal(ContentObject co) { //create a document and an envelop lr_Envelope env = new lr_Envelope(); lr_document doc = new lr_document(); //Add the keys from the contentobject to the keys for the document doc.keys.Add("3DR"); string[] keywords = co.Keywords.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string key in keywords) { doc.keys.Add(key); } //This is the URI of the resource this data describes doc.resource_locator = LR_Integration_APIBaseURL() + co.PID + "/Format/dae?ID=00-00-00"; //Submitted by the ADL3DR agent doc.identity.submitter = LR_Integration_SubmitterName(); doc.identity.signer = LR_Integration_SignerName(); doc.identity.submitter_type = new lr_submitter_type.agent(); //The data is paradata doc.resource_data_type = new lr_resource_data_type.paradata(); //Set ActivityStream as the paradata schema doc.payload_schema.Add(new lr_schema_value.paradata.LR_Paradata_1_0()); Paradata.lr_Activity activity = new lr_Activity(); //Create a paradata object Paradata.lr_Paradata pd = activity.activity; //Create a complex actor type, set to 3dr user lr_Actor.lr_Actor_complex mActor = new lr_Actor.lr_Actor_complex(); mActor.description.Add("AnonymousUser"); mActor.objectType = "3DR User"; //Set the paradata actor pd.actor = mActor; //Create a complex verb type lr_Verb.lr_Verb_complex verb = new lr_Verb.lr_Verb_complex(); verb.action = "Published"; verb.context.id = ""; verb.date = DateTime.Now; verb.measure = null; //Set the paradata verb pd.verb = verb; //Create a complex object type lr_Object.lr_Object_complex _object = new lr_Object.lr_Object_complex(); _object.id = co.PID; //Set the paradata object pd._object = _object; //A human readable description for the paradata pd.content = "The a user uploaded a new model which was assigned the PID " + co.PID; //The resource_data of this Resource_data_description_document is the inline paradata doc.resource_data = activity; env.documents.Add(doc); //Create a second document doc = new lr_document(); //Submitted by the ADL3DR agent doc.identity.submitter = LR_Integration_SubmitterName(); doc.identity.signer = LR_Integration_SignerName(); doc.identity.submitter_type = new lr_submitter_type.agent(); //Add the keys from the content object to the document foreach (string key in keywords) { doc.keys.Add(key); } //the metadata will be inline doc.payload_placement = new lr_payload_placement.inline(); //This is the resource the data describes doc.resource_locator = LR_Integration_APIBaseURL() + co.PID + "/Format/dae?ID=00-00-00"; //The inline resource data is the contentobject doc.resource_data = co; //Set the scema to dublin core doc.payload_schema.Add(new lr_schema_value.metadata.DublinCore1_1()); //this is metadata doc.resource_data_type = new lr_resource_data_type.metadata(); //Add the doc to the envelope env.documents.Add(doc); //sign the envelope env.Sign(LR_Integration_KeyPassPhrase(), LR_Integration_KeyID(), LR_Integration_PublicKeyURL()); //Serialize and publish return(env.Publish()); }
static public String ModelRatedInternal(ContentObject co) { lr_Envelope env = new lr_Envelope(); lr_document doc = new lr_document(); //Add the keys from the contentobject to the keys for the document doc.keys.Add("3DR"); string[] keywords = co.Keywords.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string key in keywords) { doc.keys.Add(key); } //This is the URI of the resource this data describes doc.resource_locator = LR_Integration_APIBaseURL() + co.PID + "/Format/dae?ID=00-00-00"; //Submitted by the ADL3DR agent doc.identity.submitter = LR_Integration_SubmitterName(); doc.identity.signer = LR_Integration_SignerName(); doc.identity.submitter_type = new lr_submitter_type.agent(); //The data is paradata doc.resource_data_type = new lr_resource_data_type.paradata(); //Set ActivityStream as the paradata schema doc.payload_schema.Add(new lr_schema_value.paradata.LR_Paradata_1_0()); Paradata.lr_Activity activity = new lr_Activity(); //Create a paradata object Paradata.lr_Paradata pd = activity.activity; //Set the paradata actor pd.actor = null; //Create a complex verb type lr_Verb.lr_Verb_complex verb = new lr_Verb.lr_Verb_complex(); verb.action = "Rated"; verb.context.id = ""; verb.date = DateTime.Now; lr_Measure measure = new lr_Measure(); measure.measureType = "value"; float reviewtotal = 0; foreach (Review r in co.Reviews) { reviewtotal += r.Rating; } measure.value = (reviewtotal / co.Reviews.Count).ToString(); verb.measure = measure; if (measure.value == "NaN") { return(""); } //Set the paradata verb pd.verb = verb; //Create a complex object type lr_Object.lr_Object_complex _object = new lr_Object.lr_Object_complex(); _object.id = co.PID; //Set the paradata object pd._object = _object; //A human readable description for the paradata pd.content = "Users on the ADL 3DR rated this model with this average rating."; //The resource_data of this Resource_data_description_document is the inline paradata doc.resource_data = activity; env.documents.Add(doc); //sign the envelope env.Sign(LR_Integration_KeyPassPhrase(), LR_Integration_KeyID(), LR_Integration_PublicKeyURL()); //Serialize and publish return(env.Publish()); }
static void Main(string[] args) { //create a document and an envelop lr_Envelope env = new lr_Envelope(); lr_document doc = new lr_document(); //Add the keys from the contentobject to the keys for the document doc.keys.Add("3DR"); 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/LRTest.html"; //Submitted by the ADL3DR agent doc.identity.submitter = LR.Settings.LR_Integration_SubmitterName(); doc.identity.signer = LR.Settings.LR_Integration_SignerName(); doc.identity.submitter_type = new lr_submitter_type.agent(); //The data is paradata doc.resource_data_type = new lr_resource_data_type.paradata(); //Set ActivityStream as the paradata schema doc.payload_schema.Add(new lr_schema_value.paradata.LR_Paradata_1_0()); LR.Paradata.lr_Activity activity = new lr_Activity(); //Create a paradata object LR.Paradata.lr_Paradata pd = activity.activity; //Create a complex actor type, set to 3dr user lr_Actor.lr_Actor_complex mActor = new lr_Actor.lr_Actor_complex(); mActor.description.Add("AnonymousUser"); mActor.objectType = "3DR User"; //Set the paradata actor pd.actor = mActor; //Create a complex verb type lr_Verb.lr_Verb_complex verb = new lr_Verb.lr_Verb_complex(); verb.action = "Published"; verb.context.id = ""; verb.date = DateTime.Now; verb.measure = null; //Set the paradata verb pd.verb = verb; //Create a complex object type lr_Object.lr_Object_complex _object = new lr_Object.lr_Object_complex(); _object.id = "an object id"; //Set the paradata object pd._object = _object; //A human readable description for the paradata pd.content = "The a user uploaded a new model which was assigned the PID ..."; //The resource_data of this Resource_data_description_document is the inline paradata doc.resource_data = activity; env.documents.Add(doc); //sign the envelope env.Sign(LR.Settings.LR_Integration_KeyPassPhrase(), LR.Settings.LR_Integration_KeyID(), LR.Settings.LR_Integration_PublicKeyURL()); //Serialize and publish env.Publish(); }