Exemplo n.º 1
0
        /// <summary>
        ///     If you decide to use own choice of HTTP client and want to use the built-in analytics function of FeedHenry cloud,
        ///     you need to add the returnd object as part of the request body with the key "__fh".
        /// </summary>
        /// <returns>The default request parameters</returns>
        public static IDictionary <string, object> GetDefaultParams()
        {
            var defaults  = new Dictionary <string, object>();
            var appConfig = FHConfig.GetInstance();

            defaults["appid"]       = appConfig.GetAppId();
            defaults["appkey"]      = appConfig.GetAppKey();
            defaults["cuid"]        = appConfig.GetDeviceId();
            defaults["destination"] = appConfig.GetDestination();
            defaults["sdk_version"] = "FH_SDK/" + SdkVersion;
            if (null != appConfig.GetProjectId())
            {
                defaults["projectid"] = appConfig.GetProjectId();
            }
            if (null != appConfig.GetConnectionTag())
            {
                defaults["connectiontag"] = appConfig.GetConnectionTag();
            }
            var initInfo = GetInitInfo();

            if (null != initInfo)
            {
                defaults["init"] = initInfo;
            }
            var sessionToken = FHAuthSession.GetInstance.GetToken();

            if (null != sessionToken)
            {
                defaults["sessionToken"] = sessionToken;
            }
            return(defaults);
        }
        private PokerService()
        {
            _socket = IO.Socket(FHConfig.GetInstance().GetHost());
            _socket.On("sessions", data =>
            {
                var session = JsonConvert.DeserializeObject <Session>((string)data);
                SessionEvent?.Invoke(this, new SessionEventArgs {
                    Session = session
                });
            });

            _socket.On("sessionUpdated", data =>
            {
                var user = JsonConvert.DeserializeObject <User>((string)data);
                SessionUpdatedEvent?.Invoke(this, new UserEventArgs {
                    User = user
                });
            });

            _socket.On("voteUpdated", data =>
            {
                var user = JsonConvert.DeserializeObject <User>((string)data);
                SessionVoteEvent?.Invoke(this, new UserEventArgs {
                    User = user
                });
            });

            _socket.On("finish", data =>
            {
                SessionFinishEvent?.Invoke(this, (string)data);
            });
        }
        private static JObject GetRequestParams()
        {
            var data = new JObject();

            data.Add("token", FHConfig.GetInstance().GetDeviceId());
            return(data);
        }
Exemplo n.º 4
0
 /// <summary>
 ///     Return the cloud host info as URL
 /// </summary>
 /// <returns>the cloud host url</returns>
 public string GetCloudHost()
 {
     if (null != _hostUrl)
     {
         return(_hostUrl);
     }
     if (null != _cloudPropsJson["url"])
     {
         _hostUrl = (string)_cloudPropsJson["url"];
     }
     else
     {
         var hosts = (JObject)_cloudPropsJson["hosts"];
         if (null != hosts["url"])
         {
             _hostUrl = (string)hosts["url"];
         }
         else
         {
             var appMode = FHConfig.GetInstance().GetMode();
             if ("dev" == appMode)
             {
                 _hostUrl = (string)hosts["debugCloudUrl"];
             }
             else
             {
                 _hostUrl = (string)hosts["releaseCloudUrl"];
             }
         }
     }
     _hostUrl = _hostUrl.EndsWith("/") ? _hostUrl.Substring(0, _hostUrl.Length - 1) : _hostUrl;
     return(_hostUrl);
 }
Exemplo n.º 5
0
        private async Task <PushConfig> ReadConfig(Registration registration)
        {
            string configName;

            configName = FHConfig.GetInstance().IsLocalDevelopment ? Constants.LocalConfigFileName : Constants.ConfigFileName;

            return(await registration.LoadConfigJson(configName));
        }
Exemplo n.º 6
0
        private async Task <FHResponse> CallRemote(string path, string sessionToken)
        {
            var uri  = new Uri(string.Format("{0}/{1}", FHConfig.GetInstance().GetHost(), path));
            var data = new Dictionary <string, object> {
                { SessionTokenKey, sessionToken }
            };
            var fhres = await FHHttpClient.FHHttpClient.SendAsync(uri, "POST", null, data, _timeout);

            return(fhres);
        }
Exemplo n.º 7
0
        public async Task TestReadConfig()
        {
            // given
            await FHClient.Init();

            // when
            var config = FHConfig.GetInstance();

            // then
            Assert.AreEqual("http://192.168.28.34:8001", config.GetHost());
            Assert.AreEqual("project_id_for_test", config.GetProjectId());
            Assert.AreEqual("app_key_for_test", config.GetAppKey());
            Assert.AreEqual("appid_for_test", config.GetAppId());
            Assert.AreEqual("connection_tag_for_test", config.GetConnectionTag());
        }
Exemplo n.º 8
0
        /// <summary>
        ///     If you decide to use own choice of HTTP client and want to use the built-in analytics function of FeedHenry cloud,
        ///     you need to add the returned object as HTTP headers to each cloud request.
        /// </summary>
        /// <returns>The default HTTP request headers</returns>
        public static IDictionary <string, string> GetDefaultParamsAsHeaders()
        {
            var defaultParams = GetDefaultParams();
            IDictionary <string, string> headers = new Dictionary <string, string>();

            foreach (var item in defaultParams)
            {
                var headername = "X-FH-" + item.Key;
                if (null != item.Value)
                {
                    headers.Add(headername, JsonConvert.SerializeObject(item.Value));
                }
            }
            if (null != FHConfig.GetInstance().GetAppKey())
            {
                headers.Add("X-FH-AUTH-APP", FHConfig.GetInstance().GetAppKey());
            }

            return(headers);
        }
Exemplo n.º 9
0
        /// <summary>
        ///     The actual implementation of initialising the FeedHenry SDK. It is called when the Init method of each platform's
        ///     FHClient class called in.
        ///     This way it will guarantee the platform's specific assembly will be loaded so that the ServiceFinder can find the
        ///     correct implmenetation for some of the services.
        ///     (The Adaptation approach used here works for wp and xamarain android without the FHClient reference. However, due
        ///     to Xamarain IOS is using AOT compiler, we have to reference the FHClient class of the IOS SDK to make sure it will
        ///     be loaded during compile.)
        /// </summary>
        /// <returns>If Init is success or not</returns>
        /// <exception cref="FHException"></exception>
        protected static async Task <bool> Init()
        {
            var fhconfig = FHConfig.GetInstance();

            if (AppReady)
            {
                return(true);
            }
            if (fhconfig.IsLocalDevelopment)
            {
                AppReady = true;
                var cloudJson = new JObject();
                cloudJson["url"] = fhconfig.GetHost();
                CloudProps       = new CloudProps(cloudJson);
                return(true);
            }
            var initRequest = new FHInitRequest {
                TimeOut = TimeOut
            };
            var initRes = await initRequest.ExecAsync();

            if (null != initRes.Error)
            {
                throw initRes.Error;
            }
            var resJson = initRes.GetResponseAsJObject();

            CloudProps = new CloudProps(resJson);
            AppReady   = true;
            var initValue = resJson["init"];

            if (null != initValue)
            {
                SaveInitInfo(initValue.ToString());
            }
            return(true);
        }
Exemplo n.º 10
0
        public PushConfig ReadPushConfig()
        {
            var configName = FHConfig.GetInstance().IsLocalDevelopment
                ? Constants.LocalConfigFileName
                : Constants.ConfigFileName;

            var appProps       = ReadAppProps();
            var configLocation = Path.Combine(GetPackageDir(), configName);
            var json           = ServiceFinder.Resolve <IIOService>().ReadFile(configLocation);
            var config         = (JObject)JsonConvert.DeserializeObject(json);
            var configWindows  = config["windows"];

            var pushConfig = new PushConfig
            {
                Alias          = (string)config["Alias"],
                Categories     = config["Categories"]?.ToObject <List <string> >(),
                UnifiedPushUri = new Uri(appProps.host + "/api/v2/ag-push"),
                VariantId      = (string)(configWindows != null ? configWindows["variantID"] : config["variantID"]),
                VariantSecret  =
                    (string)(configWindows != null ? configWindows["variantSecret"] : config["variantSecret"])
            };

            return(pushConfig);
        }
Exemplo n.º 11
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="props">The json format of the cloud host info</param>
 public CloudProps(JObject props)
 {
     _cloudPropsJson = props;
     _config         = FHConfig.GetInstance();
 }