Beispiel #1
0
        ///<summary>
        ///Get a value from the javascript API
        ///</summary>
        ///<remarks>
        ///Implements the interface in ScormWrapper, and looks syncronous to the caller.
        ///does the 2004/1.2 conversion.
        ///</remarks>
        ///<returns>
        ///A scormget structure with the identifier and the return value of the get command
        ///</returns>
        ///<param name="identifier">
        ///the dot notation identifier of the data model element to get
        ///</param>
        public ScormGet Get(string identifier, System.Type EDT)
        {
            ScormGet get = new ScormGet(identifier, "", EDT);


            int key = SetupCallback();

            Log("Get " + get.GetIdentifier());
            UnityEngine.Application.ExternalCall("doGetValue", new object[] { get.GetIdentifier(), CallbackObjectName, CallbackFunctionName, key });

            APICallResult returnval = WaitForReturn(key);

            get.SetValue(returnval.Result);


            if (returnval.ErrorCode == "")
            {
                Log("Got  " + get.GetValue());
            }
            else
            {
                Log("Error:" + returnval.ErrorCode.ToString() + " " + returnval.ErrorDescription);
            }


            return(get);
        }
Beispiel #2
0
        ///<summary>
        ///Wait until the ScormManager calls the object and inserts the results of a javascript message
        ///</summary>
        ///<remarks>
        ///the key is used to associate a javascript command with the message that responds to it. This key is
        ///sent into the javascript layer, and sent back to the scormmanager as part of the response. The
        ///Scorm manager inserts the message value into the queue. After this thread sleeps a bit, it checks
        ///the queue to see if it got an answer to this request. If so, you get back the value of that message.
        ///This all happens to allow the ScormSerializer to pretend that the set functions it calls on the Bridge
        ///are synchronous.
        ///</remarks>
        ///<returns>
        ///The return of the javascript commands associated with this key.
        ///</returns>
        APICallResult WaitForReturn(int key)
        {
            int  timeout = 0;
            bool wait    = true;

            lock (CallbackValues)
            {
                wait = CallbackValues[key] == null && timeout < TimeToWaitForReply;
            }
            while (wait)
            {
                processQueue();
                lock (CallbackValues)
                {
                    wait = CallbackValues[key] == null && timeout < TimeToWaitForReply;
                }
                if (wait)
                {
                    System.Threading.Thread.Sleep(TimePerPoll);
                }
                timeout += TimePerPoll;
            }
            if (timeout >= TimeToWaitForReply)
            {
                Log("timeout");
            }
            lock (CallbackValues)
            {
                APICallResult ret = CallbackValues[key];
                //if(CallbackValues[key].ErrorCode != "")
                //	Log(CallbackValues[key].ErrorDescription);
                CallbackValues.Remove(key);
                return(ret);
            }
        }
Beispiel #3
0
    /// <summary>
    /// Wait until the ScormManager calls the object and inserts the results of a javascript message
    /// </summary>
    /// <remarks>
    /// the key is used to associate a javascript command with the message that responds to it. This key is
    /// sent into the javascript layer, and sent back to the ScormManager as part of the response. The
    /// ScormManager inserts the message value into the queue. After this, the thread sleeps a bit (the TimePerPoll value), it checks
    /// the queue to see if it got an answer to this request. If so, you get back the value of that message.
    /// This all happens to allow the ScormManager to pretend that the set functions it calls on the Scorm API Wrapper
    /// are synchronous.
    /// </remarks>
    /// <returns>
    /// The return of the javascript commands associated with this key.
    /// </returns>
    APICallResult WaitForReturn(int key)
    {
        int  timeout = 0;
        bool wait    = true;

        lock (CallbackValues) {
            wait = CallbackValues[key] == null && timeout < TimeToWaitForReply;                         //Wait = true if the CallbackValues for this call is empty (not yet processed or timeout is reached
        }

        while (wait)
        {
            processQueue();                                                                                                                             //Look for any queued results that match this call's key
            lock (CallbackValues) {
                wait = CallbackValues[key] == null && timeout < TimeToWaitForReply;
            }
            if (wait)
            {
                System.Threading.Thread.Sleep(TimePerPoll);                                                                     //Sleep for the poll period (so we don't check obsesively)
            }
            timeout += TimePerPoll;
        }

        if (timeout >= TimeToWaitForReply)                                                                                              //On timeout send log call too
        {
            Log("timeout");
        }

        lock (CallbackValues) {
            APICallResult ret = CallbackValues[key];                                                                            //Fetch the callback values for this call (key)
            CallbackValues.Remove(key);                                                                                         //Remove this callback from the list (don't need to process it as we now have the value)
            return(ret);                                                                                                        //Return the APICallResult for this call
        }
    }
Beispiel #4
0
 ///<summary>
 ///Set a value on the javascript API
 ///</summary>
 ///<remarks>
 ///Implements the interface in ScormWrapper, and looks syncronous to the caller.
 ///</remarks>
 ///<returns>
 ///A SetResult enum with the return value of the set command
 ///</returns>
 ///<param name="identifier">
 ///the dot notation identifier of the data model element to get
 ///does the 2004/1.2 conversion.
 ///</param>
 public SetResult Set(ScormSet set)
 {
     if (set.GetValue() != "not_set")
     {
         int key = SetupCallback();
         Log("Set  " + set.GetIdentifier() + " to " + set.GetValue());
         UnityEngine.Application.ExternalCall("doSetValue", new object[] { set.GetIdentifier(), set.GetValue(), CallbackObjectName, CallbackFunctionName, key });
         APICallResult returnval = WaitForReturn(key);
         if (returnval.ErrorCode == "")
         {
             Log("Got " + returnval.Result);
             return(SetResult.Ok);
         }
         else
         {
             Log("Error:" + returnval.ErrorCode.ToString() + " " + returnval.ErrorDescription);
             return(SetResult.Error);
         }
     }
     return(SetResult.Ok);
 }
Beispiel #5
0
    /// <summary>
    /// Set a value on the javascript API
    /// </summary>
    /// <remarks>
    /// Implements the interface to the SCORM API, and looks syncronous to the caller.
    /// </remarks>
    /// <returns>
    /// Bool return value of the set command
    /// </returns>
    /// <param name="identifier">The dot notation identifier of the data model element to set.</param>
    /// <param name="value">Value to set</param>
    public bool SetValue(string identifier, string value)
    {
        bool result = false;

        int key = SetupCallback();                                                                                                              //Set the key for this call (identifies the call when processing the returned results in the queue

        Log("Set  " + identifier + " to " + value);

        UnityEngine.Application.ExternalCall("doSetValue", new object[] { identifier, value, CallbackObjectName, CallbackFunctionName, key });          //Call to scorm.js

        APICallResult returnval = WaitForReturn(key);

        if (returnval.ErrorCode == "")
        {
            Log("Result " + returnval.Result);
            result = true;
        }
        else
        {
            Log("Error:" + returnval.ErrorCode.ToString() + " " + returnval.ErrorDescription);
            result = false;
        }
        return(result);
    }
Beispiel #6
0
    /// <summary>
    /// Get a value from the javascript API
    /// </summary>
    /// <remarks>
    /// Implements the interface to the SCORM API, and looks syncronous to the caller.
    /// TODO: (This is where you would implement the 2004/1.2 conversion)
    /// </remarks>
    /// <returns>
    /// A string of the return value of the get command
    /// </returns>
    /// <param name="identifier">
    /// The dot notation identifier of the data model element to get
    /// </param>
    public string GetValue(string identifier)
    {
        string result = "";

        int key = SetupCallback();                                                                                                              //Set the key for this call (identifies the call when processing the returned results in the queue

        Log("Get " + identifier);

        UnityEngine.Application.ExternalCall("doGetValue", new object[] { identifier, CallbackObjectName, CallbackFunctionName, key });           //Call to scorm.js

        APICallResult returnval = WaitForReturn(key);

        result = returnval.Result;

        if (returnval.ErrorCode == "")
        {
            Log("Got  " + result);                                                                                                              //No error, log result
        }
        else
        {
            Log("Error:" + returnval.ErrorCode.ToString() + " " + returnval.ErrorDescription + " Result: " + returnval.Result);                         //Error, log error code and description
        }
        return(result);
    }