コード例 #1
0
ファイル: Adm.cs プロジェクト: pauldotknopf/Noodle
 public AdmAuthentication(string clientId, string clientSecret)
 {
     this.clientId = clientId;
     //If clientid or client secret has special characters, encode before sending request
     this.request = string.Format("grant_type=client_credentials&client_id={0}&client_secret={1}&scope=http://api.microsofttranslator.com", HttpUtility.UrlEncode(clientId), HttpUtility.UrlEncode(clientSecret));
     this.token = HttpPost(DatamarketAccessUri, this.request);
     //renew the token every specfied minutes
     accessTokenRenewer = new Timer(OnTokenExpiredCallback, this, TimeSpan.FromMinutes(RefreshTokenDuration), TimeSpan.FromMilliseconds(-1));
 }
コード例 #2
0
ファイル: Adm.cs プロジェクト: pauldotknopf/Noodle
 private void RenewAccessToken()
 {
     AdmAccessToken newAccessToken = HttpPost(DatamarketAccessUri, this.request);
     //swap the new token with old one
     //Note: the swap is thread unsafe
     this.token = newAccessToken;
     Console.WriteLine(string.Format("Renewed token for user: {0} is: {1}", this.clientId, this.token.access_token));
 }