public ApiContext GetAuthorizedContext(PelicanContext pelicanContext,
                                               Guid companyFileId)
        {
            var keyService = new OAuthKeyService(this);

            var configuration = new ApiConfiguration(pelicanContext.ClientKey,
                                                     pelicanContext.ClientSecret,
                                                     pelicanContext.RedirectUrl);

            // get companyfiles
            var cfService = new CompanyFileService(configuration,
                                                   null,
                                                   keyService);
            var companyFiles = cfService.GetRange();

            // select
            var companyFile = companyFiles.FirstOrDefault(_ => _.Id == companyFileId);

            // fetch accounts
            var credentials = new CompanyFileCredentials("Administrator",
                                                         "");

            return(new ApiContext
            {
                ApiConfiguration = configuration,
                CompanyFileCredentials = credentials,
                KeyService = keyService,
                CompanyFile = companyFile,
            });
        }
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Load all files from cloud and local simultaneously
            lblCode.Text = SessionManager.Code;
            var cfsCloud = new CompanyFileService(SessionManager.MyConfiguration, null, SessionManager.MyOAuthKeyService);

            CompanyFile[] a = cfsCloud.GetRange();
            CompanyFiles         = a;
            GridView1.DataSource = a;
            GridView1.DataBind();
        }
Example #3
0
        public static void ListFiles()
        {
            var configuration = new ApiConfiguration("http://localhost:8080/accountright");
            var cfService     = new CompanyFileService(configuration);
            var companyFiles  = cfService.GetRange();
            var companyFile   =
                companyFiles.FirstOrDefault(x => new Version(x.ProductVersion) >= new Version("2015.3"));
            var credentials    = new CompanyFileCredentials("Administrator", "");
            var accountService = new AccountService(configuration);
            var accounts       = accountService.GetRange(companyFile, null, credentials);

            MessageBox.Show($"{accounts.Count} accounts");
        }
Example #4
0
 public void FetchFile(IApiConfiguration configurationCloud, IWebRequestFactory webRequestFactory, IOAuthKeyService keyService, string inFilename)
 {
     try
     {
         ServiceLogger.Log("In fetch File");
         FileName           = inFilename;
         ConfigurationCloud = configurationCloud;
         MyOAuthKeyService  = keyService;
         var cfsCloud = new CompanyFileService(configurationCloud, null, keyService);
         cfsCloud.GetRange(OnComplete, OnError);
     }
     catch (Exception ex)
     {
         ServiceLogger.LogException("Exception in FetchFile", ex);
     }
 }
Example #5
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);
            }
        }