Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            var verb = new Verb(x => x.Experienced);

            var stmt = new Statement();

            stmt.Actor(x => x.Agent(name: "", mbox: ""));
            stmt.Verb(x => x.Experienced);

            stmt.Actor   = new Agent(name: "Test User", mbox: "mailto:[email protected]");
            stmt.Verb    = new Verb(x => x.Experienced);
            stmt.Context = new Context {
                Registration = Guid.NewGuid(),
            };

            stmt.Context.ContextActivities.Grouping.Add(new Activity {
                Id = "http://id.tincanapi.com/activity/tincan-prototypes",
            });

            stmt.Context.ContextActivities.Category.Add(new Activity {
                Id         = "http://id.tincanapi.com/recipe/tincan-prototypes/launcher/1",
                Definition = new Definition {
                    Type = "http://id.tincanapi.com/activitytype/recipe"
                }
            });

            stmt.Context.ContextActivities.Category.Add(new Activity {
                Id         = "http://id.tincanapi.com/activity/tincan-prototypes/launcher-template",
                Definition = new Definition {
                    Name = "Tin Can Launcher Template",
                    Type = "http://id.tincanapi.com/activitytype/source"
                },
            });

            stmt.Object = new Activity {
                Id         = "http://id.tincanapi.com/activity/tincan-prototypes/launcher",
                Definition = new Definition {
                    Name        = "Tin Can Prototypes Launcher",
                    Description = "A tool for launching the Tin Can prototypes. Simulates the role of an LMS in launching experiences.",
                    Type        = "http://id.tincanapi.com/activitytype/lms"
                },
            };

            stmt.Stored    = DateTimeOffset.UtcNow;
            stmt.Timestamp = DateTimeOffset.UtcNow;

            var settings = new JsonSerializerSettings();

            settings.Formatting        = Formatting.Indented;
            settings.ContractResolver  = new ExperienceCamelCasePropertyNamesContractResolver();
            settings.NullValueHandling = NullValueHandling.Ignore;

            var json = JsonConvert.SerializeObject(stmt, settings);

            System.Console.WriteLine(json);

            var ci = CultureInfo.GetCultureInfo("en-US");

            //var authority = "{\"authority\":{\"account\":{\"homePage\":\"http://cloud.scorm.com/\",\"name\":\"anonymous\"},\"objectType\":\"Agent\"}}";
            //var a = Newtonsoft.Json.JsonConvert.DeserializeObject<Authority>(authority);

            //var json = "{\"id\":\"dac6f1e4-d670-45e0-9bf8-288289748d02\",\"actor\":{\"name\":\"Mr Coyle\",\"mbox\":\"mailto:[email protected]\",\"objectType\":\"Agent\"},\"verb\":{\"id\":\"http://adlnet.gov/expapi/verbs/attempted\",\"display\":{\"en-US\":\"attempted\"}},\"context\":{\"contextActivities\":{\"grouping\":[{\"id\":\"http://tincanapi.com/GolfExample_TCAPI\",\"objectType\":\"Activity\"}]}},\"timestamp\":\"2014-06-23T23:34:11.265Z\",\"stored\":\"2014-06-23T23:34:11.882Z\",\"authority\":{\"account\":{\"homePage\":\"http://cloud.scorm.com/\",\"name\":\"anonymous\"},\"objectType\":\"Agent\"},\"version\":\"1.0.0\",\"object\":{\"id\":\"http://tincanapi.com/GolfExample_TCAPI\",\"definition\":{\"name\":{\"en-US\":\"Golf Example - Tin Can Course\"},\"description\":{\"en-US\":\"An overview of how to play the great game of golf.\"},\"type\":\"http://adlnet.gov/expapi/activities/course\"},\"objectType\":\"Activity\"}}";



            //statement.Context.ContextActivities.Category = new Activity();



            var client = new HttpClient();

            client.BaseAddress = new Uri("http://cloud.scorm.com/ScormEngineInterface/TCAPI/public/");
            client.DefaultRequestHeaders.Authorization("test", "test");
            client.DefaultRequestHeaders.Add("X-Experience-API-Version", "1.0.1");
            ////http://cloud.scorm.com/ScormEngineInterface/TCAPI/public/statement"	string
            ////http://cloud.scorm.com/ScormEngineInterface/TCAPI/public/statements?limit=10}	System.Uri
            ////http://cloud.scorm.com/ScormEngineInterface/TCAPI/public/statements?limit=25&related_activities=false&related_agents=false
            //var result = default(Task<HttpResponseMessage>);

            //var sr = client.PostAsync(statement: s => s
            //    .Actor(stmt.Actor)
            //    .Verb(stmt.Verb)
            //    .Object()
            //);

            client.PostAsync(() => new ObjectContent <Statement>(stmt, new JsonMediaTypeFormatter {
                SerializerSettings = settings
            }));

            //var pr = client.PostAsync(statement: s => s
            //  .Actor("*****@*****.**")
            //  .Verb(verb => verb.Completed)
            //  .Object()
            //).Result;

            //result.Wait();

            //var content = result.Result.Content.ReadAsStringAsync().Result;

            //var got = client.GetAsync(statement: s => s
            //		   .Verb(x => x.Answered)
            //		   .Limit(10));

            var response  = client.GetAsync("http://cloud.scorm.com/ScormEngineInterface/TCAPI/public/statements?limit=250&related_activities=false&related_agents=false");
            var result    = response.Result.Content.ReadAsStringAsync().Result;
            var statement = (Statement)null;

            var jobj       = (JObject)JsonConvert.DeserializeObject(result);
            var statements = jobj["statements"].OfType <JObject>().Select(x => x.ToObject <Statement>());

            //foreach(var item in jobj["statements"]) {
            //    json = JsonConvert.SerializeObject(item);
            //    //json = json.Replace("und", "en-US");
            //    try {
            //        statement = Newtonsoft.Json.JsonConvert.DeserializeObject<Statement>(json);
            //        Console.WriteLine(statement);
            //    }catch(Exception ex) {
            //        Console.WriteLine(ex.Message);
            //    }
            //}


            Console.WriteLine(result);

            Console.ReadLine();
        }