/// <summary> ///A test for GetActivity ///</summary> //[TestMethod()] public void GetActivityTest() { TinCanJsonConverter converter = new TinCanJsonConverter(); TCAPI target = new TCAPI("http://cloud.scorm.com/ScormEngineInterface/TCAPI/public", new BasicHTTPAuth("test", "password")); string activityId = "example.com"; // TODO: Initialize to an appropriate value Activity actual; actual = target.GetActivity(activityId); Console.Write(converter.SerializeToJSON(actual)); Assert.Inconclusive(INCONCLUSIVE_CONSOLE); }
/// <summary> ///A test for GetActivityProfileIds ///</summary> //[TestMethod()] public void GetActivityProfileIdsTest() { TinCanJsonConverter converter = new TinCanJsonConverter(); TCAPI target = new TCAPI("http://cloud.scorm.com/ScormEngineInterface/TCAPI/public", new BasicHTTPAuth("test", "password")); string activityId = "example.com"; NullableDateTime since = null; string[] actual; actual = target.GetActivityProfileIds(activityId, since); Console.Write(converter.SerializeToJSON(actual)); Assert.Inconclusive(INCONCLUSIVE_CONSOLE); }
/// <summary> ///A test for GetActivityState ///</summary> //[TestMethod()] public void GetActivityStateTest() { TinCanJsonConverter converter = new TinCanJsonConverter(); TCAPI target = new TCAPI("http://cloud.scorm.com/ScormEngineInterface/TCAPI/public", new BasicHTTPAuth("test", "password")); Actor actor = new Actor("Example", "mailto:[email protected]"); string activityId = "example.com"; string registrationId = null; string stateId = "Bananas"; ActivityState actual; actual = target.GetActivityState(activityId, actor, stateId, registrationId); Console.Write(converter.SerializeToJSON(actual)); Assert.Inconclusive(INCONCLUSIVE_CONSOLE); }
/// <summary> /// Retreives a statement with a given ID /// </summary> /// <param name="statementId">Statement to retreive</param> /// <returns>The statement with this ID</returns> public Statement GetStatement(string statementId) { Statement statement = new Statement(); statement.Id = statementId; TinCanJsonConverter converter = new TinCanJsonConverter(); string statementToGet = converter.SerializeToJSON(statement); NameValueCollection nvc = new NameValueCollection(); nvc["statementId"] = statementId; string result = HttpMethods.GetRequest(nvc, endpoint + STATEMENTS, authentification, versionString); Statement statementResult = null; switch (version) { case TCAPIVersion.TinCan090: statementResult = (Statement)((Model.TinCan090.Statement)converter.DeserializeJSON(result, typeof(Model.TinCan090.Statement))); break; case TCAPIVersion.TinCan095: statementResult = (Statement)converter.DeserializeJSON(result, typeof(Statement)); break; } return statementResult; }
/// <summary> /// Saves an actor profile /// </summary> /// <param name="actorProfile">The actor profile instance</param> /// <param name="previousProfile">The last instance of the actor profile</param> /// <param name="overwrite">Flag to force overwrite of the previous profile</param> public void SaveActorProfile(ActorProfile actorProfile, ActorProfile previousProfile, bool overwrite) { TinCanJsonConverter converter = new TinCanJsonConverter(); NameValueCollection nvc = new NameValueCollection(); string putData = actorProfile.Body; nvc["profileId"] = actorProfile.ProfileId; switch (version) { case TCAPIVersion.TinCan090: nvc["actor"] = converter.SerializeToJSON((Model.TinCan090.Actor)previousProfile.Actor); break; default: nvc["actor"] = converter.SerializeToJSON(previousProfile.Actor); break; } nvc["overwrite"] = overwrite.ToString(); string previousSha1 = string.Empty; if (previousProfile != null) previousSha1 = BitConverter.ToString(Encryption.GetSha1Hash(Encoding.UTF8.GetBytes(previousProfile.Body))).Replace("-", ""); string contentType = actorProfile.ContentType; HttpMethods.PutRequest(putData, nvc, endpoint + ACTOR_PROFILE, authentification, contentType, previousSha1, versionString); }
/// <summary> ///A test for GetStatements ///</summary> //[TestMethod()] public void GetStatementsTest() { TinCanJsonConverter converter = new TinCanJsonConverter(); TCAPI target = new TCAPI("http://cloud.scorm.com/ScormEngineInterface/TCAPI/public", new BasicHTTPAuth("test", "password"), TCAPIVersion.TinCan090); StatementQueryObject queryObject = new StatementQueryObject(); queryObject.Actor = new Actor("Example", "mailto:[email protected]"); StatementResult actual; actual = target.GetStatements(queryObject); Console.Write(converter.SerializeToJSON(actual)); while (!String.IsNullOrEmpty(actual.More)) { actual = target.GetStatements(actual.More); Console.Write(converter.SerializeToJSON(actual)); //break; } Assert.Inconclusive(INCONCLUSIVE_CONSOLE); }
public void GetActorProfileIdsTest() { TinCanJsonConverter converter = new TinCanJsonConverter(); TCAPI target = new TCAPI(new Uri("http://cloud.scorm.com/tc/public"), new BasicHTTPAuth("test", "password")); Actor actor = new Actor("Example", "mailto:[email protected]"); NullableDateTime since = null; string[] actual; actual = target.GetActorProfileIds(actor, since); Console.Write(converter.SerializeToJSON(actual)); Assert.Inconclusive(INCONCLUSIVE_CONSOLE); }
/// <summary> /// Gets all the activity states for an activity /// </summary> /// <param name="activityId">The activity ID</param> /// <param name="actor">The actor</param> /// <param name="registrationId">The registration ID</param> /// <param name="since">Exclusive start date</param> /// <returns>An array of activity state document keys</returns> public string[] GetActivityStateIds(string activityId, Actor actor, string registrationId, NullableDateTime since) { string[] stateIds; string getResult; TinCanJsonConverter converter = new TinCanJsonConverter(); NameValueCollection nvc = new NameValueCollection(); nvc["activityId"] = activityId; switch (version) { case TCAPIVersion.TinCan090: nvc["actor"] = converter.SerializeToJSON((Model.TinCan090.Actor)actor); break; default: nvc["actor"] = converter.SerializeToJSON(actor); break; } if (!string.IsNullOrEmpty(registrationId)) nvc["registrationId"] = registrationId; if (since != null) nvc["since"] = since.Value.ToString(Constants.ISO8601_DATE_FORMAT); getResult = HttpMethods.GetRequest(nvc, endpoint + ACTIVITY_STATE, authentification, versionString); stateIds = (string[])converter.DeserializeJSON(getResult, typeof(string[])); return stateIds; }
/// <summary> /// Retreives a complete actor given a partial actor /// </summary> /// <param name="partialActor">An actor containing at least one inverse functional property</param> /// <returns></returns> public Actor GetActor(Actor partialActor) { TinCanJsonConverter converter = new TinCanJsonConverter(); NameValueCollection nvc = new NameValueCollection(); string getResult; Actor result = null; switch (version) { case TCAPIVersion.TinCan090: nvc["actor"] = converter.SerializeToJSON((Model.TinCan090.Actor)partialActor); break; default: nvc["actor"] = converter.SerializeToJSON(partialActor); break; } getResult = HttpMethods.GetRequest(nvc, endpoint + ACTORS, authentification, versionString); switch (version) { case TCAPIVersion.TinCan095: result = (Actor)converter.DeserializeJSON(getResult, typeof(Actor)); break; case TCAPIVersion.TinCan090: result = (Actor)((Model.TinCan090.Actor)converter.DeserializeJSON(getResult, typeof(Model.TinCan090.Actor))); break; } return result; }
/// <summary> /// Deletes all the actor profiles for a given actor /// </summary> /// <param name="actor">The actor to delete profiles from</param> public void DeleteAllActorProfile(Actor actor) { TinCanJsonConverter converter = new TinCanJsonConverter(); NameValueCollection nvc = new NameValueCollection(); switch (version) { case TCAPIVersion.TinCan090: nvc["actor"] = converter.SerializeToJSON((Model.TinCan090.Actor)actor); break; default: nvc["actor"] = converter.SerializeToJSON(actor); break; } HttpMethods.DeleteRequest(nvc, endpoint + ACTOR_PROFILE, authentification, versionString); }
/// <summary> /// Retrieves a specific activity state /// </summary> /// <param name="activityId">The activity ID</param> /// <param name="actor">The actor associated with the state</param> /// <param name="stateId">The state document id</param> /// <param name="registrationId">Optional registration ID</param> /// <returns>The activity state</returns> public ActivityState GetActivityState(string activityId, Actor actor, string stateId, string registrationId) { TinCanJsonConverter converter = new TinCanJsonConverter(); NameValueCollection nvc = new NameValueCollection(); string getResult; ActivityState result = new ActivityState(); nvc["activityId"] = activityId; switch (version) { case TCAPIVersion.TinCan090: nvc["actor"] = converter.SerializeToJSON((Model.TinCan090.Actor)actor); break; default: nvc["actor"] = converter.SerializeToJSON(actor); break; } nvc["stateId"] = stateId; if (!string.IsNullOrEmpty(registrationId)) nvc["registrationId"] = registrationId; WebHeaderCollection whc; getResult = HttpMethods.GetRequest(nvc, endpoint + ACTIVITY_STATE, authentification, out whc, versionString); if (whc != null) result.ContentType = whc["Content-Type"]; result.Body = getResult; result.ActivityId = activityId; result.Actor = actor; result.RegistrationId = registrationId; result.StateId = stateId; return result; }
/// <summary> /// Deletes the activity state /// </summary> /// <param name="activityId">The activity ID</param> /// <param name="actor">The associated actor</param> /// <param name="stateId">The state document key</param> /// <param name="registrationId">Optional registration ID</param> public void DeleteActivityState(string activityId, Actor actor, string stateId, string registrationId) { TinCanJsonConverter converter = new TinCanJsonConverter(); NameValueCollection nvc = new NameValueCollection(); nvc["activityId"] = activityId; switch (version) { case TCAPIVersion.TinCan090: nvc["actor"] = converter.SerializeToJSON((Model.TinCan090.Actor)actor); break; default: nvc["actor"] = converter.SerializeToJSON(actor); break; } nvc["stateId"] = stateId; if (!string.IsNullOrEmpty(registrationId)) nvc["registrationId"] = registrationId; HttpMethods.DeleteRequest(nvc, endpoint + ACTIVITY_STATE, authentification, versionString); }
/// <summary> /// Stores statements synchronously, must be called from a separate thread /// </summary> /// <param name="statements">Statements to store</param> /// <param name="callback">Callback to signal upon completion</param> private void StoreStatements(Statement[] statements, AsyncPostCallback callback) { // Break the statement into a 2D array. First index is the number of batches, second is the number of // statements in that batch, which is either maxBatchSize or statements.Length % maxBatchSize Statement[][] batches = new Statement[(statements.Length - 1) / maxBatchSize + 1][]; for (int i = 0; i < batches.Length; i++) { batches[i] = new Statement[statements.Length - (maxBatchSize * (i + 1)) >= 0 ? maxBatchSize : statements.Length % maxBatchSize]; Array.Copy(statements, i * maxBatchSize, batches[i], 0, batches[i].Length); } for (int round = 0; round < batches.Length; round++) { foreach (Statement s in batches[round]) { var failures = new List<ValidationFailure>(s.Validate(earlyReturnOnFailure: true)); if (failures.Count > 0) { throw new ArgumentException(failures[0].Error, "statements"); } } TinCanJsonConverter converter = new TinCanJsonConverter(); string postData; switch (version) { case TCAPIVersion.TinCan090: Model.TinCan090.Statement[] currentBatch = new RusticiSoftware.TinCanAPILibrary.Model.TinCan090.Statement[batches[round].Length]; for (int i = 0; i < currentBatch.Length; i++) currentBatch[i] = (Model.TinCan090.Statement)batches[round][i]; postData = converter.SerializeToJSON(currentBatch); break; default: postData = converter.SerializeToJSON(batches[round]); break; } HttpMethods.PostRequest(postData, endpoint + STATEMENTS, authentification, callback, versionString); } }
public void GetStatementsTest() { TinCanJsonConverter converter = new TinCanJsonConverter(); TCAPI target = new TCAPI(new Uri("http://cloud.scorm.com/tc/public"), new BasicHTTPAuth("test", "password"), TCAPIVersion.TinCan095); StatementQueryObject queryObject = new StatementQueryObject(); queryObject.Actor = new Actor("Example", "mailto:[email protected]"); queryObject.Since = new DateTime(2013, 6, 1); queryObject.Limit = 50; int limit = 0; StatementResult actual; actual = target.GetStatements(queryObject); limit = actual.Statements.Length; Console.Write(converter.SerializeToJSON(actual)); while (limit <= 50 && !string.IsNullOrEmpty(actual.More)) { actual = target.GetStatements(actual.More); Console.Write(converter.SerializeToJSON(actual)); limit += actual.Statements.Length; //break; } Assert.Inconclusive(INCONCLUSIVE_CONSOLE); }
/// <summary> ///A test for GetActorProfile ///</summary> //[TestMethod()] public void GetActorProfileTest() { TinCanJsonConverter converter = new TinCanJsonConverter(); TCAPI target = new TCAPI("http://cloud.scorm.com/ScormEngineInterface/TCAPI/public", new BasicHTTPAuth("test", "password")); Actor actor = new Actor("Example", "mailto:[email protected]"); string profileId = "Example"; ActorProfile actual; actual = target.GetActorProfile(actor, profileId); Console.Write(converter.SerializeToJSON(actual)); Assert.Inconclusive(INCONCLUSIVE_CONSOLE); }
/// <summary> /// Retrieves an Actor profile /// </summary> /// <param name="actor">The actor that owns the profile</param> /// <param name="profileId">The profile document key</param> /// <returns></returns> public ActorProfile GetActorProfile(Actor actor, string profileId) { ActorProfile result = new ActorProfile(); string getResult; TinCanJsonConverter converter = new TinCanJsonConverter(); NameValueCollection nvc = new NameValueCollection(); switch (version) { case TCAPIVersion.TinCan090: nvc["actor"] = converter.SerializeToJSON((Model.TinCan090.Actor)actor); break; default: nvc["actor"] = converter.SerializeToJSON(actor); break; } nvc["profileId"] = profileId; WebHeaderCollection whc; getResult = HttpMethods.GetRequest(nvc, endpoint + ACTOR_PROFILE, authentification, out whc, versionString); if (whc != null) result.ContentType = whc["Content-Type"]; result.ProfileId = profileId; result.Actor = actor; result.Body = getResult; return result; }
/// <summary> ///A test for GetActor ///</summary> //[TestMethod()] public void GetActorTest() { TinCanJsonConverter converter = new TinCanJsonConverter(); TCAPI target = new TCAPI("http://cloud.scorm.com/ScormEngineInterface/TCAPI/public", new BasicHTTPAuth("test", "password")); Actor partialActor = new Actor(); partialActor.Mbox = "mailto:[email protected]"; Actor fullActor = target.GetActor(partialActor); Console.Write(converter.SerializeToJSON(fullActor)); Assert.Inconclusive(INCONCLUSIVE_CONSOLE); }
/// <summary> /// Retrieves a list of all actor profile document keys /// </summary> /// <param name="actor">The actor that owns the document keys</param> /// <param name="since">Optional start date</param> /// <returns>An array of profile document keys</returns> public string[] GetActorProfileIds(Actor actor, NullableDateTime since) { TinCanJsonConverter converter = new TinCanJsonConverter(); NameValueCollection nvc = new NameValueCollection(); string[] getResult; switch (version) { case TCAPIVersion.TinCan090: nvc["actor"] = converter.SerializeToJSON((Model.TinCan090.Actor)actor); break; default: nvc["actor"] = converter.SerializeToJSON(actor); break; } if (since != null) nvc["since"] = since.Value.ToString(Constants.ISO8601_DATE_FORMAT); getResult = (string[])converter.DeserializeJSON(HttpMethods.GetRequest(nvc, endpoint + ACTOR_PROFILE, authentification, versionString), typeof(string[])); return getResult; }
/// <summary> ///A test for GetStatement ///</summary> //[TestMethod()] public void GetStatementTest() { TinCanJsonConverter converter = new TinCanJsonConverter(); TCAPI target = new TCAPI("http://cloud.scorm.com/ScormEngineInterface/TCAPI/public", new BasicHTTPAuth("test", "password")); Statement actual; actual = target.GetStatement("c17c9b10-95d4-4579-90d2-d2d4683fb88b"); Console.Write(converter.SerializeToJSON(actual)); Assert.Inconclusive(INCONCLUSIVE_CONSOLE); }
public void GetActivityProfileTest() { TinCanJsonConverter converter = new TinCanJsonConverter(); TCAPI target = new TCAPI(new Uri("http://cloud.scorm.com/tc/public"), new BasicHTTPAuth("test", "password")); string activityId = "example.com"; string profileId = "Bananas"; ActivityProfile actual; actual = target.GetActivityProfile(activityId, profileId); Console.Write(converter.SerializeToJSON(actual)); Assert.Inconclusive(INCONCLUSIVE_CONSOLE); }