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); }