Exemple #1
0
        public void StopCallForwarding()
        {
            Task task = CallForwardingTask;

            if (task == null)
            {
                Status = TwoChatsHandlerStatus.Stopped;
                return;
            }

            Status = TwoChatsHandlerStatus.Finishing;
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            {
                //По идее, этот код не будет вызван никогда.
                SynchronizationHelper.WaitFor(
                    () => { return(!(task.IsCanceled || task.IsCompleted || task.IsFaulted)); },
                    15000
                    );
            }
            else
            {
                task.Wait(15000);
            }
            BotScenario?.FinishExecution(15000);
            if (!(task.IsCanceled || task.IsCompleted || task.IsFaulted))
            {
                task.Dispose();
                Status = TwoChatsHandlerStatus.Aborted;
            }
            else
            {
                Status = TwoChatsHandlerStatus.Stopped;
            }
        }
 /// <summary>
 /// Whait for all dialogs finish and don`t start new.
 /// </summary>
 public void СarefullyStopWork()
 {
     carefullyStop = true;
     SynchronizationHelper.WaitFor(
         () => { return(RealWorkUnitsCount > 0); },
         25000
         );
     AbortWork();
 }
Exemple #3
0
        void FindCompanion(int countOfTryes)
        {
            if (countOfTryes <= 0)
            {
                throw new Exception("Out of tryes to find companion.");
            }
            chatMessagesList = new List <ChatMessage>();

            /*companionSearchSettings != null && previousCompanionSearchSettings == companionSearchSettings &&*/
            if (RestartConversationIfCan())
            {
                return;
            }

            CustomBrowser.LoadPage(chatStartUrl);
            InitJs();
            try
            {
                GetWithUpdate_IsStillTalking();
            }
            catch
            {
                throw new Exception("Page load exception!");
            }

            //SynchronizationHelper.Pause(500);
            //string scriptToSetSettings = JsFor_SetSearchSettings(companionSearchSettings);
            //CustomBrowser.ExJs(scriptToSetSettings);
            SynchronizationHelper.Pause(200);
            CustomBrowser.ExJs(JsFor_ClickSearchButtononStartUrl);
            InitJs();

            //SynchronizationHelper.WaitFor(
            //    GetWithUpdate_IsSearchingCompanion, 20000);
            SynchronizationHelper.WaitFor(
                () => {
                if (GetWithUpdate_IsStillTalking())
                {
                    return(true);
                }
                SynchronizationHelper.Pause(250);
                return(false);
            },
                10000);

            //previousCompanionSearchSettings = companionSearchSettings;
            if (!GetWithUpdate_IsStillTalking())
            {
                FindCompanion(countOfTryes - 1);
            }
            CheckCaptchaAndWait();
        }
Exemple #4
0
        /// <summary>
        /// Return true if conversation restarted.
        /// </summary>
        /// <returns></returns>
        bool RestartConversationIfCan()
        {
            bool res = false;

            try
            {
                CustomBrowser.ExJs(JsFor_ClickSearchNewCompanionButton);
                SynchronizationHelper.Pause(200);

                SynchronizationHelper.WaitFor(
                    GetWithUpdate_IsSearchingCompanion, 20000);
                SynchronizationHelper.WaitFor(
                    () => { return(!GetWithUpdate_IsStillTalking()); }, 15000);
                res = GetWithUpdate_IsStillTalking();
            }
            catch { }
            return(res);
        }
Exemple #5
0
 public void Free()
 {
     if (IsFree)
     {
         return;
     }
     IsFree     = true;
     WriteToLog = delegate { };
     Invoker(() =>
     {
         if (BrowsersTabItem != null)
         {
             WindowedBrowsersPresenter.RemoveTabItem(BrowsersTabItem);
         }
         BrowsersTabItem           = null;
         WindowedBrowsersPresenter = null;
         WebView?.Dispose();
         WebView = null;
         WebViewHost?.Dispose();
         WebViewHost = null;
         //Приостанавливает текущий поток до того как все WebView, использующие сессию завершатся, с таймаутом в 10 сек.
         SynchronizationHelper.WaitFor(() =>
         {
             bool stillWait = true;
             Invoker(() => { stillWait = WebSession.HasViews; });
             return(stillWait);
         }, 15000);
         if (!WebSession.HasViews)
         {
             WebSession.Dispose();
         }
         WebSession = null;
         WebCore.ReleaseMemory();
     });
     //Invoker = null;
     GC.Collect();
 }
        /// <summary>
        /// Abort all dialogs.
        /// </summary>
        public void AbortWork()
        {
            Task task = mainWorkTask;

            if (task == null)
            {
                return;
            }

            carefullyStop = true;
            abortWork     = true;

            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            {
                SynchronizationHelper.WaitFor(
                    () => { return(!(task.IsCanceled || task.IsCompleted || task.IsFaulted)); },
                    25000
                    );
            }
            else
            {
                task.Wait(25000);
            }
        }