/// <summary>
 /// Constructs a TCAPI object with no asynchronous support.
 /// </summary>
 /// <param name="endpoint">The endpoint for the TCAPI</param>
 /// <param name="authentification">The authentification object</param>
 public TCAPI(Uri endpoint, IAuthenticationConfiguration authentification)
 {
     this.endpoint = endpoint;
     this.Authentification = authentification;
     this.tcapiCallback = null;
     this.offlineStorage = null;
     this.version = DetermineVersioning();
 }
        /// <summary>
        /// Transforms the Query object into a NameValueCollection, which will be transformed into a query string.
        /// </summary>
        /// <param name="version">The TCAPI Version to serialize the statement as.</param>
        /// <returns></returns>
        public NameValueCollection ToNameValueCollection(TCAPIVersion version)
        {
            NameValueCollection nvc       = new NameValueCollection();
            TinCanJsonConverter converter = new TinCanJsonConverter();

            if (!string.IsNullOrEmpty(verb))
            {
                nvc["verb"] = verb.ToLower();
            }
            if (targetObject != null)
            {
                nvc["object"] = converter.SerializeToJSON(targetObject);
            }
            if (!string.IsNullOrEmpty(registration))
            {
                nvc["registration"] = registration;
            }
            nvc["context"] = context.ToString();
            if (actor != null)
            {
                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();
            }
            if (until != null)
            {
                nvc["until"] = until.Value.ToString();
            }
            nvc["limit"]         = limit.ToString();
            nvc["authoritative"] = authoritative.ToString();
            nvc["sparse"]        = sparse.ToString();
            if (instructor != null)
            {
                nvc["instructor"] = converter.SerializeToJSON(instructor);
            }
            nvc["ascending"] = ascending.ToString();
            if (!string.IsNullOrEmpty(continueToken))
            {
                nvc["continueToken"] = continueToken;
            }
            nvc["historical"] = historical.ToString();


            return(nvc);
        }
示例#3
0
        public String ToJSON(TCAPIVersion version, Boolean pretty = false)
        {
            Formatting formatting = Formatting.None;
            if (pretty)
            {
                formatting = Formatting.Indented;
            }

            return JsonConvert.SerializeObject(ToJObject(version), formatting);
        }
示例#4
0
        /// <summary>
        /// To the json.
        /// </summary>
        /// <param name="version">The version.</param>
        /// <param name="pretty">if set to <c>true</c> [pretty].</param>
        /// <returns>System.String.</returns>
        public string ToJSON(TCAPIVersion version, bool pretty = false)
        {
            var formatting = Formatting.None;

            if (pretty)
            {
                formatting = Formatting.Indented;
            }

            return(JsonConvert.SerializeObject(ToJObject(version), formatting));
        }
示例#5
0
        public RemoteLRSAsync(string endpoint, string username, string password)
        {
            this.endpoint = endpoint;

            // endpoint should have trailing /
            if (this.endpoint[this.endpoint.Length - 1] != '/')
            {
                this.endpoint += "/";
            }

            this.version = TCAPIVersion.latest();
            this.auth    = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(username + ":" + password));

            ClearState();
        }
示例#6
0
        /// <summary>
        /// Sends the statement.
        /// </summary>
        /// <param name="agent">The agent.</param>
        /// <param name="verb">The verb.</param>
        /// <param name="target">The target.</param>
        /// <returns>Task&lt;LRSResponse&gt;.</returns>
        public async Task <LRSResponse> SendStatement(Agent agent, Verb verb, IStatementTarget target)
        {
            var authority = new Agent
            {
                Mbox    = "mailto:[email protected]",
                Account = new AgentAccount {
                    Name = "ADL Administrator"
                },
                Name = "Admin"
            };

            var statement = new Statement
            {
                Version   = TCAPIVersion.Latest(),
                Actor     = agent,
                Target    = target,
                Authority = authority,
                Verb      = verb
            };

            return(await _lrs.SaveStatementAsync(statement));
        }
示例#7
0
 /// <summary>
 /// To the j object.
 /// </summary>
 /// <returns>JObject.</returns>
 public JObject ToJObject()
 {
     return(ToJObject(TCAPIVersion.Latest()));
 }
示例#8
0
 // TODO: rename methods to ToJObject and ToJSON
 /// <summary>
 /// To the j object.
 /// </summary>
 /// <param name="version">The version.</param>
 /// <returns>JObject.</returns>
 public abstract JObject ToJObject(TCAPIVersion version);
 /// <summary>
 /// Constructs a TCAPI Object, forcibly setting the version.
 /// </summary>
 /// <param name="endpoint"></param>
 /// <param name="authentification"></param>
 /// <param name="version"></param>
 /// <remarks>Forcing the version is not recommended and should only be used if an issue with the LRS
 /// </remarks>
 public TCAPI(Uri endpoint, IAuthenticationConfiguration authentification, TCAPIVersion version)
     : this(endpoint, authentification)
 {
     this.version = version;
 }
示例#10
0
 public TCAPI(Uri endpoint, IAuthenticationConfiguration authentification, ITCAPICallback tcapiCallback, IOfflineStorage offlineStorage, int statementPostInterval, int maxBatchSize, TCAPIVersion version)
     : this(endpoint, authentification, tcapiCallback, offlineStorage, statementPostInterval, maxBatchSize)
 {
     this.version = version;
 }
示例#11
0
        /// <summary>
        /// Construct a TCAPI object with asynchronous support.
        /// </summary>
        /// <param name="endpoint">The LRS endpoint</param>
        /// <param name="authentification">Authentification object</param>
        /// <param name="tcapiCallback">Asynchornous callback object</param>
        /// <param name="offlineStorage">Offline Storage object</param>
        /// <param name="statementPostInterval">Interval for asynchronous operations to take place, in milliseconds</param>
        public TCAPI(Uri endpoint, IAuthenticationConfiguration authentification, ITCAPICallback tcapiCallback, IOfflineStorage offlineStorage, int statementPostInterval, int maxBatchSize)
        {
            this.endpoint = endpoint;
            this.authentification = authentification;
            this.tcapiCallback = tcapiCallback;
            this.offlineStorage = offlineStorage;
            this.statementPostInterval = statementPostInterval;
            this.maxBatchSize = maxBatchSize;

            this.asyncPostCallback = new AsyncPostCallback(this.PostSuccess, this.PostFailed, this.PostConnectionFailed);
            this.isAsyncFlushing = false;

            asyncPostTimer = new Timer();
            asyncPostTimer.Elapsed += new ElapsedEventHandler(AsyncPostTimerElapsed);
            asyncPostTimer.Interval = this.statementPostInterval;
            asyncPostTimer.Enabled = this.statementPostInterval > 0;
            asyncPostTimer.AutoReset = true;
            this.version = DetermineVersioning();
        }
示例#12
0
 // TODO: rename methods to ToJObject and ToJSON
 public abstract JObject ToJObject(TCAPIVersion version);
        /// <summary>
        /// Transforms the Query object into a NameValueCollection, which will be transformed into a query string.
        /// </summary>
        /// <param name="version">The TCAPI Version to serialize the statement as.</param>
        /// <returns></returns>
        public NameValueCollection ToNameValueCollection(TCAPIVersion version)
        {
            NameValueCollection nvc = new NameValueCollection();
            TinCanJsonConverter converter = new TinCanJsonConverter();

            if (!string.IsNullOrEmpty(verb))
                nvc["verb"] = verb.ToLower();
            if (targetObject != null)
                nvc["object"] = converter.SerializeToJSON(targetObject);
            if (!string.IsNullOrEmpty(registration))
                nvc["registration"] = registration;
            nvc["context"] = context.ToString();
            if (actor != null)
                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();
            if (until != null)
                nvc["until"] = until.Value.ToString();
            nvc["limit"] = limit.ToString();
            nvc["authoritative"] = authoritative.ToString();
            nvc["sparse"] = sparse.ToString();
            if (instructor != null)
                nvc["instructor"] = converter.SerializeToJSON(instructor);
            nvc["ascending"] = ascending.ToString();
            if (!string.IsNullOrEmpty(continueToken))
                nvc["continueToken"] = continueToken;
            nvc["historical"] = historical.ToString();

            return nvc;
        }
 private static WebHeaderCollection GetWebHeaders(Uri endPoint, IAuthenticationConfiguration authentication, TCAPIVersion version)
 {
     WebHeaderCollection whc;
     var qo = new StatementQueryObject { Limit = 1 };
     NameValueCollection nvc = qo.ToNameValueCollection(version);
     HttpMethods.GetRequest(nvc, endPoint + STATEMENTS, authentication, out whc, "0.95");
     return whc;
 }
 /// <summary>
 /// This method determines which version of the X-EXPERIENCE-API is being used by requesting a single statement
 /// and reading the versioning header.  This allows proper serialization when communicating with the server.
 /// </summary>
 /// <returns></returns>
 private static TCAPIVersion DetermineVersioning(Uri endPoint, IAuthenticationConfiguration authentication, TCAPIVersion version)
 {
     WebHeaderCollection whc = GetWebHeaders(endPoint, authentication, version);
     string versionString = null;
     versionString = whc["X-Experience-API-Version"];
     if (string.IsNullOrEmpty(versionString))
     {
     }
     else if (versionString.Equals("0.95") || versionString.Equals(".95"))
     {
         return TCAPIVersion.TinCan095;
     }
     return TCAPIVersion.TinCan090;
 }
示例#16
0
 /// <summary>
 /// This method determines which version of the X-EXPERIENCE-API is being used by requesting a single statement
 /// and reading the versioning header.  This allows proper serialization when communicating with the server.
 /// </summary>
 /// <returns></returns>
 private TCAPIVersion DetermineVersioning()
 {
     WebHeaderCollection whc = GetWebHeaders();
     string version = null;
     version = whc["X-Experience-API-Version"];
     if (string.IsNullOrEmpty(version))
     {
     }
     else if (version.Equals("0.95") || version.Equals(".95"))
     {
         return TCAPIVersion.TinCan095;
     }
     return TCAPIVersion.TinCan090;
 }
示例#17
0
 /// <summary>
 /// To the json.
 /// </summary>
 /// <param name="pretty">if set to <c>true</c> [pretty].</param>
 /// <returns>System.String.</returns>
 public string ToJSON(bool pretty = false)
 {
     return(ToJSON(TCAPIVersion.Latest(), pretty));
 }
 public String ToJSON(Boolean pretty = false)
 {
     return(ToJSON(TCAPIVersion.latest(), pretty));
 }