Beispiel #1
0
 internal InitRequestListener(TuningUpdater tuningUpdater, IDictionary <string, object> userProperties, IDictionary <string, object> deviceProperties, Callback cb)
 {
     mTuningUpdater    = tuningUpdater;
     mUserProperties   = userProperties;
     mDeviceProperties = deviceProperties;
     mCallback         = cb;
 }
        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 Splyt?
            if (Initialized)
            {
                Util.logError("Splyt 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)
                        {
                            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);
            }
        }
 internal InitRequestListener(TuningUpdater tuningUpdater, IDictionary<string, object> userProperties, IDictionary<string, object> deviceProperties, Callback cb)
 {
     mTuningUpdater = tuningUpdater;
     mUserProperties = userProperties;
     mDeviceProperties = deviceProperties;
     mCallback = cb;
 }
        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);
            }
        }
Beispiel #5
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);
            }
        }
Beispiel #6
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);
            }
        }