示例#1
0
        public void CallWebApiGetAndBackup(string infoName, string uriBase, string requestPath, List <object> queryParams)
        {
            var ret = this.accessWebApi.GetApiCall(requestPath, queryParams);

            if (ret != null) //success
            {
                //Do backup
                var mydatabase = new LiteDBDatabase.LiteDBHandle();
                mydatabase.UpdateBackupInfo(infoName, ret);
            }
        }
示例#2
0
        //Create new web api with back up item service
        public void newWebApiBackup(string infoName, string uriBase, string requestPath, List <object> queryParams, int interval)
        {
            //Check if Offline database already contain entity with name strInfoName
            var mydatabase = new LiteDBDatabase.LiteDBHandle();

            if (mydatabase.isBackupInfoExist(infoName) == false) //Not Exist. Need to create new
            {
                mydatabase.CreateBackupInfo(infoName, null);
            }
            //
            var subscription = Observable.Interval(TimeSpan.FromMilliseconds(interval))
                               .Subscribe(x =>
            {
                //Call GET() method & do back up
                this.CallWebApiGetAndBackup(infoName, uriBase, requestPath, queryParams);
            });

            this.lstWebApiBackupSubscription.Add(subscription);
        }
示例#3
0
        /// <summary>
        /// This function is the "entry point" of all applicaton. When we override it, we can add our desired activities to control application start-up sequence
        /// </summary>
        /// <param name="e"></param>
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            //Testing area


            //******************INI REDUX APP STORE***********************************************************************
            clsAppStore.IniStore(); //Create new App Store

            //******************INI FOR BACKUP OFFLINE DATABASE***********************************
            var myDatabase = new LiteDBDatabase.LiteDBHandle();

            myDatabase.IniDatabase();

            //******************************************************************************************************
            //Showing Splash
            clsSplash clsNewSplash = new clsSplash();

            clsNewSplash.thrSplash = new System.Threading.Thread(clsNewSplash.ShowSplash);
            clsNewSplash.thrSplash.SetApartmentState(System.Threading.ApartmentState.STA);
            clsNewSplash.thrSplash.Start();

            // CFP Ini Loading component
            LoadingComponent.IniLoadComponent iniLoading = new LoadingComponent.IniLoadComponent();
            iniLoading.IniComponent();

            //Prevent 2 instances of program running together
            string strThisProcess = Process.GetCurrentProcess().ProcessName;

            if (Process.GetProcesses().Count(p => p.ProcessName == strThisProcess) > 1)
            {
                //If there is an instance already running, we will try to wait 4 second for that instance terminated.
                //After that, if that instance still running, push message out and terminated

                int intStartTick = MyLibrary.clsApiFunc.GetTickCount();
                while ((MyLibrary.clsApiFunc.GetTickCount() - intStartTick) < 4000)
                {
                    if (Process.GetProcesses().Count(p => p.ProcessName == strThisProcess) <= 1)
                    {
                        break;
                    }
                }

                if (Process.GetProcesses().Count(p => p.ProcessName == strThisProcess) > 1)
                {
                    //MessageBox.Show("Warning: This program already opened! Please check!", "Multi-Instance of program opened Error");
                    var testError = new wdError();
                    testError.ShowDialog();
                    //clsEventLog.WriteLogData("Start Failed", "Another Instance Exist", "");
                    Environment.Exit(0);
                    return;
                }
            }

            //**************************************************************************************************************************************************
            //Change application startup to Boots Trapper
            clsCFPBootstrapper clsBootstrapper = new clsCFPBootstrapper();

            try
            {
                clsBootstrapper.Run();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unexpected Error happen. Error message: " + ex.Message, "CFP clsBootstrapper.Run() fail!");
                Environment.Exit(0);
            }
        }