private void RenewAccessToken()
		{
			MstfAzureMarketplaceAccessToken newAccessToken = HttpPost(DATAMARKET_ACCESS_URI, _request);
			//swap the new token with old one
			//Note: the swap is thread unsafe
			_token = newAccessToken;
		}
Exemplo n.º 2
0
        private void RenewAccessToken()
        {
            MstfAzureMarketplaceAccessToken newAccessToken = HttpPost(DATAMARKET_ACCESS_URI, _request);

            //swap the new token with old one
            //Note: the swap is thread unsafe
            _token = newAccessToken;
        }
Exemplo n.º 3
0
        private MstfAzureMarketplaceAccessToken HttpPost(string datamarketAccessUri, string requestDetails)
        {
            var webRequest = Request(datamarketAccessUri, requestDetails);

            using (WebResponse webResponse = webRequest.GetResponse())
            {
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(MstfAzureMarketplaceAccessToken));
                //Get deserialized object from JSON stream
                MstfAzureMarketplaceAccessToken token = (MstfAzureMarketplaceAccessToken)serializer.ReadObject(webResponse.GetResponseStream());
                return(token);
            }
        }
Exemplo n.º 4
0
        public MstfAzureMarketplaceAuthentication(string clientId, string clientSecret)
        {
            ClientId     = clientId;
            ClientSecret = clientSecret;

            //If clientid or client secret has special characters, encode before sending request
            _request = string.Format(
                "grant_type=client_credentials&client_id={0}&client_secret={1}&scope=http://api.microsofttranslator.com",
                HttpUtility.UrlEncode(clientId), HttpUtility.UrlEncode(ClientSecret));
            _token = HttpPost(DATAMARKET_ACCESS_URI, _request);
            //renew the token every specified minutes

            _accessTokenRenewer = new Timer(OnTokenExpiredCallback, this,
                                            TimeSpan.FromMinutes(REFRESH_TOKEN_DURATION), TimeSpan.FromMilliseconds(-1));
        }
		public MstfAzureMarketplaceAuthentication(string clientId, string clientSecret)
		{
			ClientId = clientId;
			ClientSecret = clientSecret;
			
			//If clientid or client secret has special characters, encode before sending request
			_request = string.Format(
				"grant_type=client_credentials&client_id={0}&client_secret={1}&scope=http://api.microsofttranslator.com", 
				HttpUtility.UrlEncode(clientId), HttpUtility.UrlEncode(ClientSecret));
			_token = HttpPost(DATAMARKET_ACCESS_URI, _request);
			//renew the token every specified minutes

			_accessTokenRenewer = new Timer(OnTokenExpiredCallback, this, 
				TimeSpan.FromMinutes(REFRESH_TOKEN_DURATION), TimeSpan.FromMilliseconds(-1));
		}