Ejemplo n.º 1
0
        public static void registerUser(string userId, IDictionary <string, object> userProperties, TuningUpdater tuningUpdater, Callback cb)
        {
            Error ret = Error.Success;

            if (!Initialized)
            {
                Util.logError("Cannot registerUser before calling init()");
                ret = Error.NotInitialized;
            }
            else if (!isValidId(DeviceId))
            {
                Util.logError("No device Id set.  Check for prior errors");
                ret = Error.MissingId;
            }

            if (Error.Success == ret)
            {
                string deviceId = DeviceId;

                string        url          = Host + "/isos-personalization/ws/interface/application_updateuser" + getQueryParms();
                List <object> allArgs      = new List <object>(4);
                double        curTimeStamp = Util.Timestamp();
                allArgs.Add(curTimeStamp);
                allArgs.Add(curTimeStamp);
                allArgs.Add(userId);
                allArgs.Add(deviceId);

                // TODO: It's not a good idea to go around the event depot (out of order issue)
                allArgs.Add(userProperties);

                try
                {
                    // Create an (async) request to add the user. The callback will be triggered when the request is completed
                    HttpRequest.executeAsync(new Uri(url), ReqTimeout, Json.Serialize(allArgs), new InitRequestListener(tuningUpdater, userProperties, null, 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;
                }
            }

            // 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);
            }
        }
Ejemplo n.º 2
0
        /**
         * Store an event in the depot.
         *
         * @param event The event we wish to store
         */
        internal static Error store(IDictionary <string, object> eventData)
        {
            // Build up the batch
            List <object> allArgs = new List <object>(2);

            allArgs.Add(Util.Timestamp());
            allArgs.Add(new List <object> {
                eventData
            });

            // Create a new request to send the data "asynchronously", but we're going to fire and forget in this implementation
            HttpRequest.executeAsync(sUri, sReqTimeout, Json.Serialize(allArgs), sRequestListener);

            return(Error.Success);
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        public static void init(string customerId, TuningUpdater tuningUpdater, string userId, Dictionary <string, object> userProperties, string deviceId, Dictionary <string, object> deviceProperties, int reqTimeout, string host, bool logEnabled, string sdkNamePre, string sdkVersion, Callback cb, string hubObjName, bool isWebPlayer)
        {
            Error ret = Error.Success;

            // Have we already initialized CognitiveVR?
            if (Initialized)
            {
                Util.logError("CognitiveVR has already been initialized, no need to re-initialize");
                ret = Error.AlreadyInitialized;
            }
            else if (null == cb)
            {
                Util.logError("Please provide a valid callback");
                ret = Error.InvalidArgs;
            }

            if (Error.Success == ret)
            {
                sCustomerId = customerId;
                ReqTimeout  = reqTimeout;
                Host        = host;
                sSDKName    = Util.getSDKName(sdkNamePre);
                sSDKVersion = sdkVersion;

                Util.cacheDeviceAndAppInfo();

                // First see if we have a deviceId stored off locally that we can use
                string savedDeviceId;
                if (!isValidId(deviceId) && Prefs.TryGetValue(DEVICEID_KEY_NAME, out savedDeviceId))
                {
                    if (isValidId(savedDeviceId))
                    {
                        deviceId = savedDeviceId;
                    }
                }

                // set up device id & user id now, in case initial server call doesn't make it back (offline usage, etc)
                if (isValidId(deviceId))
                {
                    DeviceId = deviceId;
                }
                if (isValidId(userId))
                {
                    UserId = userId;
                }

                // add any auto-scraped device state
                IDictionary <string, object> deviceAndAppInfo = Util.getDeviceAndAppInfo();
                if (null == deviceProperties)
                {
                    deviceProperties = deviceAndAppInfo as Dictionary <string, object>;
                }
                else
                {
                    try
                    {
                        foreach (var info in deviceAndAppInfo)
                        {
                            if (!deviceProperties.ContainsKey(info.Key))
                            {
                                deviceProperties.Add(info.Key, info.Value);
                            }
                        }
                    }
                    catch (ArgumentException)
                    {
                        Util.logError("device properties passed in have a duplicate key to the auto-scraped properties!");
                    }
                }

                HttpRequest.init(hubObjName, isWebPlayer);

                // No device Id, so let's retrieve one and save it off
                string url          = Host + "/isos-personalization/ws/interface/application_init" + getQueryParms();
                IList  allArgs      = new List <object>(6);
                double curTimeStamp = Util.Timestamp();
                allArgs.Add(curTimeStamp);
                allArgs.Add(curTimeStamp);
                allArgs.Add(userId);
                allArgs.Add(deviceId);
                allArgs.Add(userProperties);
                allArgs.Add(deviceProperties);

                try
                {
                    HttpRequest.executeAsync(new Uri(url), ReqTimeout, Json.Serialize(allArgs), new InitRequestListener(tuningUpdater, userProperties, deviceProperties, cb));
                }
                catch (WebException e)
                {
                    reset();

                    Util.logError("WebException during the HttpRequest.  Check your host and customerId values: " + e.Message);
                    ret = Error.InvalidArgs;
                }
                catch (Exception e)
                {
                    reset();

                    Util.logError("Error during HttpRequest: " + e.Message);
                    ret = Error.Generic;
                }
            }

            if ((Error.Success != ret) && (null != cb))
            {
                cb(ret);
            }
        }