Beispiel #1
0
 private void GetTokenForMYOB(Credentials crendetials)
 {
     try
     {
         _configurationCloud            = new ApiConfiguration(crendetials.ConsumerKey, crendetials.ConsumerSecret, "http://desktop");
         _oAuthKeyService               = new MYOBOAuthKeyService();
         _oAuthKeyService.OAuthResponse = null;
         if (_oAuthKeyService.OAuthResponse == null)
         {
             var    oauthService = new OAuthService(_configurationCloud);
             string _accessCode  = OAuthLogin.GetAuthorizationCode(_configurationCloud);
             _oAuthKeyService.OAuthResponse =
                 oauthService.GetTokens(_accessCode);
             var frmLogin = new CompanyFileLogin();
             frmLogin.ShowDialog(this);
             if (frmLogin.Username.Length > 0)
             {
                 AccountingIntegrationConfigManager.Instance.SaveCompanyFileCredentials(frmLogin.Username, frmLogin.Password);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #2
0
        private void TryGetTokens()
        {
            _oAuthKeyService = new OAuthKeyService();
            if (_oAuthKeyService.OAuthResponse != null)
            {
                return;
            }
            var oauthService = new OAuthService(_configurationCloud);
            var code         = OAuthLogin.GetAuthorizationCode(_configurationCloud);
            var tokens       = oauthService.GetTokens(code);

            _oAuthKeyService.OAuthResponse = tokens;
        }
Beispiel #3
0
        private t.Task <OAuthTokens> GetOAuthTokens()
        {
            var tcs = new t.TaskCompletionSource <OAuthTokens>();

            t.Task.Run(
                async() =>
            {
                var oauthService = new OAuthService(_configurationCloud);
                var code         = OAuthLogin.GetAuthorizationCode(_configurationCloud);
                var response     = await oauthService.GetTokensAsync(code);
                tcs.SetResult(response);
            });
            return(tcs.Task);
        }
Beispiel #4
0
        /// <summary>
        /// Event that is called when the form loads
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks></remarks>
        private void CompanyFilesLoad(object sender, EventArgs e)
        {
            try
            {
                ShowSpinner();

                //If developer key  enable (see above) and set useCVloud to true the following section manages OAuth token and accessing cloud service
                if (UseCloud)
                {
                    _configurationCloud = new ApiConfiguration(DeveloperKey, DeveloperSecret, "http://desktop");
                    _oAuthKeyService    = new OAuthKeyService();

                    //Get tokens if not stored
                    if (_oAuthKeyService.OAuthResponse == null)
                    {
                        var oauthService = new OAuthService(_configurationCloud);
                        _oAuthKeyService.OAuthResponse =
                            oauthService.GetTokens(OAuthLogin.GetAuthorizationCode(_configurationCloud));
                    }

                    // Load all files from cloud and local simultaneously
                    var cfsCloud = new CompanyFileService(_configurationCloud, null, _oAuthKeyService);
                    cfsCloud.GetRange(OnComplete, OnError);
                }

                _configurationLocal = new ApiConfiguration(LocalApiUrl);
                var cfsLocal = new CompanyFileService(_configurationLocal);
                cfsLocal.GetRange(OnComplete, OnError);

                //' The following two lines can be called to run synchronously rather than async
                //_companyFiles = cfs.GetRange()
                //dgvCompanyFiles.DataSource = _companyFiles
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }