示例#1
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;
 }
        public async Task ShouldOAuthRequest()
        {
			await FHClient.Init();

            //given
            ServiceFinder.RegisterType<IOAuthClientHandlerService, MockOAuthClient>();

            var json = JObject.Parse(@"{
                ""hosts"": {""host"": ""HOST""}
             }");
            var config = new FHConfig(new MockDeviceService());
            var props = new CloudProps(json, config);
            var authRequest = new FHAuthRequest(props);

            authRequest.SetAuthUser("gmail", "user", "password");

            var mockHttpCLient =
                new MockHttpClient {Content = "{\"status\": \"ok\", \"url\": \"http://oauthurl.url\"}"};
            FHHttpClientFactory.Get = () => mockHttpCLient;

            //when
            var response = await authRequest.ExecAsync();

            //then
            Assert.IsNotNull(response);
            var responseParams = response.GetResponseAsDictionary();
            Assert.IsNotNull(responseParams);
            Assert.AreEqual("token", responseParams["sessionToken"]);
        }
示例#3
0
        public void TestURLFormatting()
        {
            // given
            var json = JObject.Parse(@"{
                'url': 'http://someserver.com/',
                'hosts': {'host': 'HOST',  'environment': 'ENV'}
             }");
            var config = new FHConfig(new MockDeviceService());
            var props = new CloudProps(json, config);

            // when
            var host = props.GetCloudHost();

            // then
            Assert.AreEqual("http://someserver.com", host);
        }
示例#4
0
        public void TestReadCloudPropsWithJsonEmptyValuesForUrlAndHostWithoutUrl()
        {
            // given
            var json = JObject.Parse(@"{
                'hosts': {'host': 'HOST',  'environment': 'ENV', 'releaseCloudUrl': 'RELEASE_CLOUD_URL'}
             }");
            var config = new FHConfig(new MockDeviceService());
            var props = new CloudProps(json, config);

            // when
            var host = props.GetCloudHost();
            var env = props.GetEnv();

            // then
            Assert.AreEqual("RELEASE_CLOUD_URL", host);
            Assert.AreEqual("ENV", env);
        }
示例#5
0
        public void TestReadCloudPropsWithJsonContainingValues()
        {
            // given
            var json = JObject.Parse(@"{
                'url': 'URL',
                'hosts': {'host': 'HOST',  'environment': 'ENV'}
             }");
            var config = new FHConfig(new MockDeviceService());
            var props = new CloudProps(json, config);

            // when
            var host = props.GetCloudHost();
            var env = props.GetEnv();

            // then
            Assert.AreEqual("URL", host);
            Assert.AreEqual("ENV", env);
        }
示例#6
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()
        {
			FHConfig fhconfig = FHConfig.getInstance();
            if (!appReady)
            {
                if(fhconfig.IsLocalDevelopment){
                    appReady = true;
                    JObject cloudJson = new JObject();
                    cloudJson["url"] = fhconfig.GetHost();
                    cloudProps = new CloudProps(cloudJson);
                    return true;
                }
                FHInitRequest initRequest = new FHInitRequest();
                initRequest.TimeOut = timeout;
                FHResponse initRes = await initRequest.execAsync();
                if (null == initRes.Error)
                {
					JObject resJson = initRes.GetResponseAsJObject();
					cloudProps = new CloudProps (resJson);
                    appReady = true;
					JToken initValue = resJson["init"];
                    if (null != initValue)
                    {
                        SaveInitInfo(initValue.ToString());
                    }
                    return true;
                }
                else
                {
                    throw initRes.Error;
                }
            }
            else
            {
                return true;
            }
        }
示例#7
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);
        }
示例#8
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="props">The cloud host info</param>
		public FHCloudRequest (CloudProps props)
			: base()
		{
			this.cloudProps = props;
		}