Esempio n. 1
0
        public static async Task <ResponseList <AccessToken> > getFromSocial(string SocialID, string SocialLastAccessToken, UserData.SocialProvider SocialProvider)
        {
            //TODO: controlla che restituisca solo gli utenti con SocialProvider<>0
            if (Constants.IsDownloadingToken)
            {
                return(new Gateway <PersonalizedData, AccessToken> .ResponseList <AccessToken>());
            }
            else
            {
                Constants.IsDownloadingToken = true;
            }

            var parameters = new GetTokenQuery
            {
                SocialID = SocialID,
                SocialLastAccessToken = SocialLastAccessToken,
                SocialProvider        = SocialProvider,
            };
            string url   = Constants.GatewayUrl + "?action=getUserToken&AppToken=" + Constants.RandomAppToken;
            var    pairs = new List <KeyValuePair <string, string> >();

            pairs.Add(new KeyValuePair <string, string>("parameters", JsonConvert.SerializeObject(parameters)));

            WebServiceV2 webRequest = new WebServiceV2();
            var          result     = await webRequest.UrlToString(url, pairs, false, Constants.HTTPTimeoutMini);

            Constants.IsDownloadingToken = false;
            if (result == null || result.Length < 1)
            {
                return(new ResponseList <AccessToken> {
                    errorMessage = "no response", state = WebServiceV2.WebRequestState.TimeOut
                });
            }
            ResponseList <AccessToken> obj = new ResponseList <AccessToken>();

            try
            {
                obj = JsonConvert.DeserializeObject <ResponseList <AccessToken> >(result);
                if (obj.errorMessage != null)
                {
                    Debug.WriteLine(obj.errorMessage + Environment.NewLine);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return(new ResponseList <AccessToken> {
                    state = WebServiceV2.WebRequestState.GenericError
                });
            }
            return(obj);
        }
Esempio n. 2
0
        public async Task <AccessTokenExistsResponse> esisteUserFromSocialToken(string SocialToken, UserData.SocialProvider SocialProvider)
        {
            var parameters = new GetTokenQuery
            {
                SocialLastAccessToken = SocialToken,
                SocialProvider        = SocialProvider,
            };
            string url   = Constants.GatewayUrl + "?action=esisteUserFromSocialToken&AppToken=" + Constants.RandomAppToken;
            var    pairs = new List <KeyValuePair <string, string> >();

            pairs.Add(new KeyValuePair <string, string>("parameters", JsonConvert.SerializeObject(parameters)));

            WebServiceV2 webRequest = new WebServiceV2();
            var          result     = await webRequest.UrlToString(url, pairs, false, Constants.HTTPTimeoutMini);

            Constants.IsDownloadingToken = false;
            if (result == null || result.Length < 1)
            {
                return(new AccessTokenExistsResponse {
                    errorMessage = "no response", state = WebServiceV2.WebRequestState.TimeOut
                });
            }
            AccessTokenExistsResponse obj = new AccessTokenExistsResponse();

            try
            {
                obj = JsonConvert.DeserializeObject <AccessTokenExistsResponse>(result);
                if (obj.errorMessage != null)
                {
                    Debug.WriteLine(obj.errorMessage + Environment.NewLine);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return(new AccessTokenExistsResponse {
                    state = WebServiceV2.WebRequestState.GenericError
                });
            }
            return(obj);
        }