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