Ejemplo n.º 1
0
        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,
            });
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _configurationCloud = new ApiConfiguration(SessionManager.DeveloperKey, SessionManager.DeveloperSecret, SessionManager.CallBackUrl);
            _oAuthKeyService    = new OAuthKeyService();
            if (_oAuthKeyService.OAuthResponse == null)
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(Server.MapPath("~/info.xml"));

                XmlNode nodeObj = doc.SelectSingleNode("/user/code");
                //string id = nodeObj["Project"].InnerText; // For inner text


                var oauthService = new MYOB.AccountRight.SDK.Services.OAuthService(_configurationCloud);
                _oAuthKeyService.OAuthResponse = oauthService.GetTokens(nodeObj.Attributes["value"].Value);
            }

            SessionManager.MyOAuthKeyServiceAutoBackup = _oAuthKeyService;
            SessionManager.MyConfigurationAutoBackup   = _configurationCloud;

            var cfsCloud = new MYOB.AccountRight.SDK.Services.CompanyFileService(_configurationCloud, null, _oAuthKeyService);

            CompanyFile[] companyFiles = cfsCloud.GetRange();
            CompanyFile   companyFile  = companyFiles.FirstOrDefault(a => a.Id == Guid.Parse(SessionManager.CompanyId));

            SessionManager.SelectedCompanyFileAutoBackup = companyFile;
            ICompanyFileCredentials credentials = new CompanyFileCredentials(SessionManager.CompanyUserId, SessionManager.CompanyPassword);

            SessionManager.MyCredentialsAutoBackup = credentials;
            HandleSales();
            HandlePurchase();
        }
Ejemplo n.º 3
0
        private void DgvCompanyFilesCellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            //Get the selected company file
            CompanyFile companyFile = ((CompanyFile[])dgvCompanyFiles.DataSource)[e.RowIndex];

            //Get configuration that matches server where file is
            IApiConfiguration config = companyFile.Uri.GetLeftPart(UriPartial.Path).ToLower().Contains(LocalApiUrl)
                                           ? _configurationLocal
                                           : _configurationCloud;

            //Get the credentials for the database
            var frmLogin = new LoginForm();

            frmLogin.ShowDialog(this);
            if (frmLogin.Username.Length <= 0)
            {
                return;
            }
            ICompanyFileCredentials credentials = new CompanyFileCredentials(frmLogin.Username, frmLogin.Password);

            ////load the Invoice List
            //var frmInvoiceList = new InvoiceListForm();
            //frmInvoiceList.Initialise(config, companyFile, credentials, _oAuthKeyService);
            //frmInvoiceList.Show();
        }
Ejemplo n.º 4
0
        // <summary>
        /// This public method may be very long running, so it returns a Task which allows calling
        /// application to 'await' the asynchronous return of a future result (or an exception).
        /// </summary>
        /// <remarks>
        ///     This is an example of a public library method that may run for a long time
        ///     By passing a CancellationToken we can test if the caller wants us to cancel.
        ///     By passing an IProgress we can pass information back to the caller (conveniently it
        ///     happens on the original thread if the caller is a Forms or WPF app).
        /// </remarks>
        public void PrepareToCommunicateWithMyob(string MYOBLogin)
        {
            //http://stackoverflow.com/questions/11879967/best-way-to-convert-callback-based-async-method-to-awaitable-task


            var developerKey = ConfigurationManager.AppSettings["MyobDeveloperKey"];


            var developerSecret = ConfigurationManager.AppSettings["MyobDeveloperSecret"];

            _configurationCloud = new ApiConfiguration(developerKey, developerSecret, "http://desktop");

            // you many get a benign error here on the fist time - if the tokens have not been stored
            try
            {
                TryGetTokens();
            }
            catch (Exception)
            {
                try
                {
                    TryGetTokens();
                }
                catch (Exception)
                {
                    throw;
                }
            }

            var task2        = GetCompanyFiles(_configurationCloud, _oAuthKeyService);
            var companyFiles = task2.Result; // waits for the files

            _companyFile = companyFiles.First();
            _credentials = AskForCredentials(_companyFile, MYOBLogin);
        }
Ejemplo n.º 5
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            CompanyFile companyFile = (CompanyFile)CompanyFiles.FirstOrDefault(a => a.Id == Guid.Parse(lblID.Text));//[e.RowIndex];

            ICompanyFileCredentials credentials = new CompanyFileCredentials(txtUserName.Text, txtPassword.Text);

            SessionManager.SelectedCompanyFile = companyFile;
            SessionManager.MyCredentials       = credentials;
            Response.Redirect("SearchPage.aspx");
        }
Ejemplo n.º 6
0
 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);
 }
Ejemplo n.º 7
0
        public async Task <int> Addtems(
            CompanyFile myCompanyFile,
            string pageFilter,
            CompanyFileCredentials myCredentials,
            CancellationToken ct)
        {
            var tpc      = _myService.GetRangeAsync(myCompanyFile, pageFilter, myCredentials, ct, null);
            var newItems = await tpc;

            items.AddRange(newItems.Items);
            return(newItems.Items.Count());
        }
Ejemplo n.º 8
0
        internal CompanyFileWithResources Login(CompanyFile companyFile, string userId, string password)
        {
            var _login = new LoginContext {
                Username = userId, Password = password
            };

            var _service = new CompanyFileService(APIConfiguration, null, KeyService);

            CompanyFileResource = _service.Get(companyFile, _login);
            CompanyCredential   = new CompanyFileCredentials(userId, password);
            return(CompanyFileResource);
        }
Ejemplo n.º 9
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");
        }
Ejemplo n.º 10
0
        private static CompanyFileCredentials AskForCredentials(CompanyFile companyFile, string MYOBLogin)
        {
            //var prompt = string.Format( "Password for login {0} " ,& MYOBLogin
            var o = new MYOBLogin {
                Login = MYOBLogin
            };
            CompanyFileCredentials credentials = null;
            var dlg = o.ShowDialog();

            if (dlg == DialogResult.OK)
            {
                var login    = o.Login;
                var password = o.Password();
                credentials = new CompanyFileCredentials(login, password);
            }

            return(credentials);
        }
Ejemplo n.º 11
0
        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;
            }
        }
Ejemplo n.º 12
0
        public async void AddItemToMyob(
            AMSDbContext connect,
            MYOBCustomer jtMyobCustomer,
            CompanyFile myCompanyFile,
            CompanyFileCredentials myCredentials,
            CancellationToken ct)
        {
            var item = new Customer
            {
                IsActive    = jtMyobCustomer.IsActive,
                CompanyName = jtMyobCustomer.CompanyName,
                FirstName   = jtMyobCustomer.FirstName,
                LastName    = jtMyobCustomer.LastName
            };

            HandyFunctions.Log(item.ToJson2());
            var   task = _myService.InsertAsync(myCompanyFile, item, myCredentials, ct, ErrorLevel.WarningsAsErrors);
            await task;

            jtMyobCustomer.Uid = item.UID;
            connect.SaveChanges();
        }
        protected override void OnStart(string[] args)
        {
            // Update the service state to Start Pending.
            ServiceStatus serviceStatus = new ServiceStatus();

            serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING;
            serviceStatus.dwWaitHint     = 300000;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);
            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Interval = 60000 * 60 * SessionManager.TimerInHours; // 60 seconds
            timer.Elapsed += new System.Timers.ElapsedEventHandler(this.OnTimer);
            timer.Start();
            _configurationCloud = new ApiConfiguration(SessionManager.DeveloperKey, SessionManager.DeveloperSecret, "http://localhost:60669/Default");
            _oAuthKeyService    = new OAuthKeyService();
            //if (_oAuthKeyService.OAuthResponse == null)
            //{
            var oauthService = new MYOB.AccountRight.SDK.Services.OAuthService(_configurationCloud);

            _oAuthKeyService.OAuthResponse = oauthService.GetTokens(SessionManager.Code);
            //  }

            SessionManager.MyOAuthKeyService = _oAuthKeyService;
            SessionManager.MyConfiguration   = _configurationCloud;

            var cfsCloud = new MYOB.AccountRight.SDK.Services.CompanyFileService(SessionManager.MyConfiguration, null, SessionManager.MyOAuthKeyService);

            CompanyFile[] companyFiles = cfsCloud.GetRange();
            CompanyFile   companyFile  = companyFiles.FirstOrDefault(a => a.Id == Guid.Parse(SessionManager.CompanyId));

            SessionManager.SelectedCompanyFile = companyFile;
            ICompanyFileCredentials credentials = new CompanyFileCredentials(SessionManager.CompanyUserId, SessionManager.CompanyPassword);

            SessionManager.MyCredentials = credentials;
            // OnTimer();
            // Update the service state to Running.
            serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);
            OnTimer(null, null);
        }