private void InitializeFormCefsharpDummy()
        {
            Globals.log.Debug("AmivoiceWatcher:> InitializeFormCefsharpDummy()");

            myFormCefsharpDummy = new FormCefsharpDummy();
            myFormCefsharpDummy.Show(formDummy);
        }
Example #2
0
        //private static void GetConfigurationFileByCefsharpDummyThread()
        //{
        //    //while (!AmivoiceWatcher.myFormCefsharpDummy.isFinishLoadDefault)
        //    //{
        //    //    Thread.Sleep(500);
        //    //}

        //    var i = 0;

        //    while ((myState != ConfigurationSetupState.downloadedSuccess) && (myState != ConfigurationSetupState.downloadedFail))
        //    {
        //        Thread.Sleep(1000);
        //        if (myState == ConfigurationSetupState.downloading)
        //        {
        //            i++;
        //            Thread.Sleep(1000);

        //            Globals.log.Debug(String.Format("Check if downloading configuration finish => {0} sec.", i));

        //            if (i > 20)
        //            {
        //                Globals.log.Warn("Can not load config file from server! The recorded one(if exists) will be used.");
        //                //isLoadingFile = false;
        //                myState = ConfigurationSetupState.downloadedFail;
        //                return;
        //            }
        //        }

        //    }

        //    myState = ConfigurationSetupState.setting_var;

        //    //isLoadingFile = false;

        //    //AmivoiceWatcher.myFormCefsharpDummy.DownloadFile(configurationURL);
        //    //AmivoiceWatcher.myFormCefsharpDummy.DownloadConfigFile();
        //}


        private static void SetConfiguration_Thread()
        {
            var waiting_counter = 0;

            while (!Globals.isProgramExit)
            {
                try
                {
                    switch (myState)
                    {
                    case State.zero:
                    {
                        myState = State.getting_configUrl;
                        break;
                    }

                    case State.getting_configUrl:
                    {
                        GetConfigurationUrl();

                        myState = State.getting_configUrl_completed;

                        break;
                    }

                    case State.getting_configUrl_completed:
                    {
                        if (configUrl == "")
                        {
                            Globals.log.Debug("Configuration:> Finish getting ConfigurationURL=Sting.Empty");
                            myState = State.setting_var;
                        }
                        else
                        {
                            Globals.log.Debug("Configuration:> Finish getting ConfigurationURL and start waiting for dowloading url = " + configUrl);
                            //GetConfigurationFileByCefsharpDummy();
                            myState = State.downloading;
                            Thread.Sleep(1000);
                        }

                        break;
                    }

                    case State.setting_var:
                    {
                        SetGlobalVariable();

                        //isSetConfigurationSuccess = true;
                        myState = myState = State.completed;
                        //AmivoiceWatcher.myFormCefsharpDummy.SendComputerLog_startup();

                        break;
                    }

                    case State.downloading:
                    {
                        Thread.Sleep(1000);

                        Globals.log.Debug(String.Format("Configuration:> Check if downloading configuration finish => {0} sec.", waiting_counter));
                        waiting_counter++;

                        if (AmivoiceWatcher.myFormCefsharpDummy.myState < FormCefsharpDummy.State.browser_initialized)
                        {
                            Globals.log.Warn("AmivoiceWatcher.myFormCefsharpDummy.myState < FormCefsharpDummy.State.browser_initialized");
                            if (waiting_counter > 15)
                            {
                                Globals.log.Warn("Configuration:> Give up waiting. Try to exit the program now");
                                //AmivoiceWatcher.ForceExit();
                            }
                        }
                        else if (AmivoiceWatcher.myFormCefsharpDummy.myState > FormCefsharpDummy.State.downloading_config)
                        {
                            Globals.log.Warn("Configuration.State change to State.setting_var");
                            //isLoadingFile = false;
                            myState = State.setting_var;
                        }
                        else
                        {
                            if (waiting_counter > 20)
                            {
                                Globals.log.Warn("Can not load config file from server! The recorded one(if exists) will be used.");
                                //isLoadingFile = false;
                                myState = State.downloadedFail;

                                if (AmivoiceWatcher.myFormCefsharpDummy.myState == FormCefsharpDummy.State.downloading_config)
                                {
                                    Globals.log.Warn("Configuration:> force myFormCefsharpDummy to stop downloading");
                                    FormCefsharpDummy.StopLoading();
                                    AmivoiceWatcher.myFormCefsharpDummy.Load_ReloadPage();
                                }
                            }
                        }

                        break;
                    }

                    case State.downloadedFail:
                    case State.downloadedSuccess:
                    {
                        myState = State.setting_var;
                        break;
                    }

                    case State.completed:
                    {
                        Globals.log.Debug("Set configuration....OK");
                        Globals.log.Warn("Configuration:> fininish SetConfiguration_Thread()");
                        return;
                    }

                    default:
                    {
                        Thread.Sleep(500);
                        break;
                    }
                    }
                }
                catch (Exception e)
                {
                    Globals.log.Debug(e.ToString());
                }
            }

            Globals.log.Debug("Exit Configuration.SetConfiguration_Thread() Successfully");
        }