Ejemplo n.º 1
0
        /// <summary>
        /// Не рекомендуется использовать извне.
        /// </summary>
        public ChatMessage ReadMessageAt(int msgNum)
        {
            InitJs();
            string jsResText = CustomBrowser.ExJsWithResult(
                JsFor_GetMessageAt(msgNum)
                ).Trim();

            if (string.IsNullOrWhiteSpace(jsResText) || CustomBrowser.CheckJsResult_IsUndefined(jsResText) || jsResText == "msgError")
            {
                ThrowInvalidJsResultExeption("JsFor_GetMessageAt", jsResText);
            }

            string jsResBool = CustomBrowser.ExJsWithResult(
                JsFor_CheckIfCompanionsMessageAt(msgNum)
                ).Trim();

            if (!CustomBrowser.CheckJsResult_WhiteList(jsResBool, new string[] { "1", "0" }))
            {
                ThrowInvalidJsResultExeption("JsFor_CheckIfCompanionsMessageAt", jsResBool);
            }
            jsResText = jsResText.Replace("<br>", "\n");

            ChatMessage res = new ChatMessage(
                jsResText,
                jsResBool == "1"
                );

            return(res);
        }
Ejemplo n.º 2
0
        private async void Enter()
        {
            Request.IsEntered = false;
            Browser           = CustomBrowser.Create();
            try
            {
                var locale = await Browser.RequestAsync(Request);

                Response.Headers    = locale.Headers;
                Response.Response   = locale.Response;
                Response.StatusCode = locale.StatusCode;
                Request.IsEntered   = true;
            }
            catch (ArgumentNullException ex)
            {
                WindowsManager.Message("ApiDog", ex.Message);
            }
            catch (Exception ex)
            {
                WindowsManager.Message("ApiDog", ex.Message);
            }
            finally
            {
                Browser.Abort();
            }
        }
Ejemplo n.º 3
0
 public void SendMessage(string text)
 {
     InitJs();
     CustomBrowser.ExJs(JsFor_ClearTextArea);
     CustomBrowser.ExJs(JsFor_SetMessageBoxText(text));
     CustomBrowser.ExJs(JsFor_ClickSendMessageButton);
 }
Ejemplo n.º 4
0
 public CustomBrowserSettingWindow(CustomBrowser browser)
 {
     InitializeComponent();
     currentCustomBrowser = browser;
     DataContext          = new CustomBrowser
     {
         Name = browser.Name, DataDirectoryPath = browser.DataDirectoryPath
     };
 }
Ejemplo n.º 5
0
        public bool GetWithUpdate_IsBotFuncsInitialized()
        {
            string jsRes = Convert.ToString(CustomBrowser.ExJsWithResult(JsFor_GetIsBotFuncsInitialized)).Trim();

            if (!CustomBrowser.CheckJsResult_WhiteList(jsRes, new string[] { "1", "0" }))
            {
                ThrowInvalidJsResultExeption("JsFor_GetIsBotFuncsInitialized", jsRes);
            }
            return(jsRes == "1");
        }
Ejemplo n.º 6
0
        public bool GetWithUpdate_CheckCaptcha()
        {
            InitJs();
            string jsRes = Convert.ToString(CustomBrowser.ExJsWithResult(JsFor_CheckCaptcha)).Trim();

            if (!CustomBrowser.CheckJsResult_WhiteList(jsRes, new string[] { "1", "0" }))
            {
                ThrowInvalidJsResultExeption("JsFor_CheckCaptcha", jsRes);
            }
            return(jsRes == "1");
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Не используется и, возможно, никогда не будет.
        /// </summary>
        public void SimulateWriting(int timeMS)
        {
            int waiInOneLoop = 200;

            while (timeMS > 0)
            {
                CustomBrowser.ExJs(JsFor_SimulateWriting);
                SynchronizationHelper.Pause(waiInOneLoop);
                timeMS -= waiInOneLoop;
            }
            CustomBrowser.ExJs(JsFor_ClearTextArea);
            SynchronizationHelper.Pause(50);
        }
Ejemplo n.º 9
0
        public bool GetWithUpdate_IsStillTalking()
        {
            InitJs();
            string jsRes = Convert.ToString(CustomBrowser.ExJsWithResult(JsFor_CheckIfStillTalking)).Trim();

            if (!CustomBrowser.CheckJsResult_WhiteList(jsRes, new string[] { "1", "0" }))
            {
                ThrowInvalidJsResultExeption("JsFor_CheckIfStillTalking", jsRes);
            }

            isStillTalking = jsRes == "1";
            return(isStillTalking);
        }
Ejemplo n.º 10
0
 void InitJs()
 {
     if (GetWithUpdate_IsBotFuncsInitialized())
     {
         return;
     }
     CustomBrowser.ExJs(ResourcesAndConsts.Instance().JsLib_JqueryKeypressSimulator);
     CustomBrowser.ExJs(JsFor_InitCheckIfStillTalking);
     CustomBrowser.ExJs(JsFor_InitGetCountOfMessages);
     CustomBrowser.ExJs(JsFor_InitCheckIfCompanionsMessageAt);
     CustomBrowser.ExJs(JsFor_InitCheckCaptcha);
     CustomBrowser.ExJs(JsFor_InitClickSearchNewCompanionButton);
     CustomBrowser.ExJs(JsFor_SetIsBotFuncsInitialized);
 }
Ejemplo n.º 11
0
        public bool GetWithUpdate_IsSearchingCompanion()
        {
            isSearchingCompanion = false;
            return(isSearchingCompanion);

            string jsRes = CustomBrowser.ExJsWithResult(JsFor_CheckIfSearchingCompanion).Trim();

            if (!CustomBrowser.CheckJsResult_WhiteList(jsRes, new string[] { "1", "0" }))
            {
                ThrowInvalidJsResultExeption("JsFor_CheckIfSearchingCompanion", jsRes);
            }

            isSearchingCompanion = jsRes == "1";
            return(isSearchingCompanion);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Не рекомендуется использовать извне.
        /// </summary>
        public int ReadMessagesCount()
        {
            InitJs();
            int?jsRes = null;

            try
            {
                jsRes = Convert.ToInt32(CustomBrowser.ExJsWithResult(
                                            JsFor_GetCountOfMessages
                                            ));
                return((int)jsRes);
            }
            catch
            {
                ThrowInvalidJsResultExeption("JsFor_GetCountOfMessages", "null");
                return(-9999);
            }
        }
 public CustomChromiumBookmarkLoader(CustomBrowser browser)
 {
     BrowserName = browser.Name;
     BrowserDataPath = browser.DataDirectoryPath;
 }
Ejemplo n.º 15
0
 public void WriteToBrowserLog(string text)
 {
     CustomBrowser.WriteToLog(text);
 }
Ejemplo n.º 16
0
 public void FinishConversation()
 {
     InitJs();
     CustomBrowser.ExJs(JsFor_FinishConversation);
     SynchronizationHelper.Pause(300);
 }