Beispiel #1
0
        public static void refresh(Callback cb)
        {
            Error ret = Error.Success;

            if (CoreSubsystem.Initialized)
            {
                String url = CoreSubsystem.Host + "/isos-personalization/ws/interface/tuner_refresh" + CoreSubsystem.getQueryParms();

                IList  allArgs      = new List <object>(4);
                double curTimeStamp = Util.Timestamp();
                allArgs.Add(curTimeStamp);
                allArgs.Add(curTimeStamp);
                allArgs.Add(CoreSubsystem.DeviceId);
                allArgs.Add(CoreSubsystem.getRegisteredUsers());

                try
                {
                    // Create an (async) request to retrieve the tuning variables.  The callback will be triggered when the request is completed
                    HttpRequest.executeAsync(new Uri(url), CoreSubsystem.ReqTimeout, Json.Serialize(allArgs), new RefreshRequestListener(cb));
                }
                catch (WebException e)
                {
                    Util.logError("WebException during the HttpRequest.  Check your host and customerId values: " + e.Message);
                    ret = Error.InvalidArgs;
                }
                catch (Exception e)
                {
                    Util.logError("Error during HttpRequest: " + e.Message);
                    ret = Error.Generic;
                }
            }
            else
            {
                Util.logError("Cannot refresh tuning because CognitiveVR is not initialized");
                ret = Error.NotInitialized;
            }

            // if we have an error at this point, then the callback will not get called through the HttpRequest, so call it now
            if (Error.Success != ret && null != cb)
            {
                cb(ret);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Register a user with CognitiveVR and make them the currently active user.  This can be done at any point when a new user is interacted with by
        /// the application. Note that if the active user is known at startup, it is generally ideal to provide their info directly to CognitiveVR.Core.init instead
        /// </summary>
        /// <param name="userInfo">An EntityInfo created with InitParams.createUserInfo</param>
        /// <param name="cb">Application defined callback which will occur on completion</param>
        public static void registerUser(EntityInfo userInfo, Callback cb)
        {
            Error error = Error.Success;

            if (null == cb)
            {
                Util.logError("Please provide a valid CognitiveVR.Callback");
                error = Error.InvalidArgs;
            }
            else if (Constants.ENTITY_TYPE_USER != userInfo.type)
            {
                Util.logError("To provide user settings, be sure to use createUserInfo");
                error = Error.InvalidArgs;
            }

            if (Error.Success == error)
            {
                //#if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR
                //string userProperties = Json.Serialize(userInfo.properties);

                //				registerCallback("onCognitiveVRRegisterUserComplete", cb);
                //#endif

                //#if UNITY_IPHONE && !UNITY_EDITOR
                //cognitivevr_core_registeruser(userInfo.entityId, userProperties, HUB_OBJECT);
                //#elif UNITY_ANDROID && !UNITY_EDITOR
                //callNativeAsync("cognitivevr_core_registeruser", new object[] {userInfo.entityId, userProperties, HUB_OBJECT});
                //				#else
                CoreSubsystem.registerUser(userInfo.entityId, userInfo.properties, new TuningSubsystem.Updater(), cb);
                //#endif
            }
            else if (null != cb)
            {
                // Some argument error, just call the callback immediately
                cb(error);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Initializes CognitiveVR Framework for use, including instrumentation and tuning.
        /// </summary>
        /// <param name="initParams">Initialization parameters</param>
        /// <param name="cb">Application defined callback which will occur on completion</param>
        public static void init(InitParams initParams, Callback cb)
        {
            Debug.Log("Core.init()");
            // this should only be enabled during android development!!!
            //AndroidJNIHelper.debug = true;

            Error error = Error.Success;

            // Enable/disable logging
            Util.setLogEnabled(initParams.logEnabled);

            if (null == initParams)
            {
                Util.logError("No init parameters provided");
                error = Error.InvalidArgs;
            }
            else if (null == cb)
            {
                Util.logError("Please provide a valid CognitiveVR.Callback");
                error = Error.InvalidArgs;
            }
            else if (Constants.ENTITY_TYPE_USER != initParams.userInfo.type)
            {
                Util.logError("To provide intitial user settings, be sure to use createUserInfo");
                error = Error.InvalidArgs;
            }
            else if (Constants.ENTITY_TYPE_DEVICE != initParams.deviceInfo.type)
            {
                Util.logError("To provide intitial device settings, be sure to use createDeviceInfo");
                error = Error.InvalidArgs;
            }

            GameObject go = GameObject.Find(HUB_OBJECT);

            if (null == go)
            {
                go = new GameObject(HUB_OBJECT);
            }
            GameObject.DontDestroyOnLoad(go);

            if (Error.Success == error)
            {
                InstrumentationSubsystem.init();

                // Builds targeting the web player need to be handled specially due to the security model
                // Unfortunately, there is no good way to determine that at run time within the plugin.
                #if UNITY_WEBPLAYER
                const bool isWebPlayer = true;
                #else
                const bool isWebPlayer = false;
                #endif

                TuningSubsystem.init(delegate(Error err)
                {
                    CoreSubsystem.init(initParams.customerId, new TuningSubsystem.Updater(), initParams.userInfo.entityId, initParams.userInfo.properties, initParams.deviceInfo.entityId, initParams.deviceInfo.properties, initParams.requestTimeout, initParams.host, initParams.logEnabled, SDK_NAME_PREFIX, SDK_VERSION, cb, HUB_OBJECT, isWebPlayer);
                });
            }
            else if (null != cb)
            {
                // Some argument error, just call the callback immediately
                cb(error);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Resume CognitiveVR.  This causes CognitiveVR read its last known state from Internal Storage and restart polling for events to send.
 /// One would typically call this whenever the application is brought to the foreground.
 /// </summary>
 public static void resume()
 {
     CoreSubsystem.resume();
 }
Beispiel #5
0
 /// <summary>
 /// Pause CognitiveVR.  This causes CognitiveVR to save off its state to Internal Storage and stop checking for events to send.
 /// One would typically call this whenever the application is sent to the background.
 ///
 /// <b>Note:</b> On some platforms, one can still make calls to CognitiveVR functions even when it's paused, but doing so will trigger
 /// reads and writes to Internal Storage, so it should be done judiciously
 /// </summary>
 public static void pause()
 {
     CoreSubsystem.pause();
 }
Beispiel #6
0
 /// <summary>
 /// Useful when the logged in user logs out of the application.  Clearing the active user allows CognitiveVR to provide non user-specific
 /// tuning values and report telemetry which is not linked to a user
 /// </summary>
 /// <returns>An error code</returns>
 public static Error clearActiveUser()
 {
     return(CoreSubsystem.setActiveUser(null));
 }
Beispiel #7
0
 /// <summary>
 /// Explicitly sets the active user id. Generally only required when multiple concurrent users are required/supported, since
 /// init() and registerUser() both activate the provided user by default.
 /// </summary>
 /// <returns>An error code</returns>
 /// <param name="userId">The user id, which had been previously registered with CognitiveVR.Core.registerUser</param>
 public static Error setActiveUser(string userId)
 {
     return(CoreSubsystem.setActiveUser(userId));
 }