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, }; }
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, }); }
public void InitService( CompanyFile companyFile, SDK.CompanyFileCredentials credentials, SDK.ApiConfiguration myConfiguration, OAuthKeyService myOAuthKeyService) { myCompanyFile = companyFile; myCredentials = credentials; myService = new ItemBillService(myConfiguration, null, myOAuthKeyService); }
public void InitService( CompanyFile companyFile, CompanyFileCredentials credentials, ApiConfiguration myConfiguration, OAuthKeyService myOAuthKeyService) { myCompanyFile = companyFile; myCredentials = credentials; myService = new ItemOrderService(myConfiguration, null, myOAuthKeyService); myCustomerService = new CustomerService(myConfiguration, null, myOAuthKeyService); }
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; }
public async t.Task <int> SyncTable( MYOBTypeEnum type, ApiConfiguration myConfiguration, CompanyFile myCompanyFile, CompanyFileCredentials myCredentials, OAuthKeyService myOAuthKeyService, CancellationToken ct, IProgress <int> progress) { var _currentPage = 1; const double PageSize = 400; var myMYOBhandler = MakeServiceHandler(type, myConfiguration, myOAuthKeyService); try { var totalPages = 0; var numAdded = 0; do { var pageFilter = $"$top={PageSize}&$skip={PageSize * (_currentPage - 1)}&$orderby={myMYOBhandler.OrderBy}"; numAdded = await myMYOBhandler.Addtems(myCompanyFile, pageFilter, myCredentials, ct); if (totalPages == 0) { totalPages = (int)Math.Ceiling(myMYOBhandler.ItemCount / PageSize); } _currentPage++; } while (numAdded > 0); //(_currentPage <= totalPages); myMYOBhandler.SynchroniseItems(progress); return(myMYOBhandler.ItemCount); } catch (ApiCommunicationException ex) { HandyFunctions.Log(ex.ToString()); throw; } catch (Exception ex) { HandyFunctions.Log(ex.ToString()); throw; } }
//public MyobPost MakePostServiceHandler( // MYOBTypeEnum type, // ApiConfiguration myConfiguration, // OAuthKeyService myOAuthKeyService, // CancellationToken ct) //{ // switch (type) // { // case MYOBTypeEnum.SalesInvoice: // var syncinv = new SyncInvoices(); // syncinv.InitService(_companyFile, _credentials, myConfiguration, myOAuthKeyService); // return syncinv; // case MYOBTypeEnum.SalesOrder: // var o = new SyncSalesOrders(); // o.InitService(_companyFile, _credentials, myConfiguration, myOAuthKeyService); // return o; // default: // throw new ArgumentOutOfRangeException("type"); // } //} public IMyobHandler MakeServiceHandler( MYOBTypeEnum type, ApiConfiguration myConfiguration, OAuthKeyService myOAuthKeyService) { IMyobHandler o = null; switch (type) { case MYOBTypeEnum.TaxRate: o = new SyncTaxCodes(); break; case MYOBTypeEnum.GeneralLedgerAccount: o = new SyncAccounts(); break; case MYOBTypeEnum.Inventory: o = new SyncInventory(); break; case MYOBTypeEnum.Customer: o = new SyncCustomers(); break; case MYOBTypeEnum.Supplier: o = new SyncSuppliers(); break; //case MYOBTypeEnum.NotApplicable: // break; default: throw new ArgumentOutOfRangeException("type", type, null); } o.InitService(myConfiguration, myOAuthKeyService); return(o); }
public void InitService(ApiConfiguration myConfiguration, OAuthKeyService myOAuthKeyService) { _myService = new ItemService(myConfiguration, null, myOAuthKeyService); items = new List <Item>(); }
public void InitService(ApiConfiguration myConfiguration, OAuthKeyService myOAuthKeyService) { _myService = new CustomerService(myConfiguration, null, myOAuthKeyService); items = new List <Customer>(); }