Esempio n. 1
0
        private static string DivClick(String text, IE ie)
        {
            List <HControl> controls = new List <HControl>();

            string[] a = text.Trim().Split('|');
            string   g = a[0].Trim();

            string[] h           = g.Split('[');
            string[] j           = h[1].Trim(']').Split(':');
            HControl hcontroldiv = new HControl();

            hcontroldiv.Control   = h[0].Trim();
            hcontroldiv.Attribute = j[0].Trim();
            hcontroldiv.Value     = j[1].Trim();
            Div div = MyWatiN.GetDiv(ie, hcontroldiv);

            if (div != null)
            {
                string[] k = text.Split(',');
                foreach (string l in k)
                {
                    string[] m        = l.Trim().Split('[');
                    string   n        = m[1].Trim(']');
                    string[] o        = n.Split(':');
                    HControl hcontrol = new HControl();
                    hcontrol.Control   = m[0].Trim();
                    hcontrol.Attribute = o[0].Trim();
                    hcontrol.Value     = o[1].Trim();
                    controls.Add(hcontrol);
                }
                return(RunControl(controls, div, ie));
            }
            return("Error");
        }
Esempio n. 2
0
        string RunControl(List <HControl> controls, string data)
        {
            string status = string.Empty;

            foreach (HControl ctr in controls)
            {
                if (MyWatiN.IsExist(ie, ctr))
                {
                    status = MyWatiN.FillData(ie, ctr, data);
                    break;
                }
            }
            return(status);
        }
Esempio n. 3
0
        private static string ClickMode(String text, IE ie)
        {
            List <HControl> controls = new List <HControl>();

            string[] a = text.Trim().Split('|');
            string   g = a[1].Trim();

            string[] h           = g.Split('[');
            string[] j           = h[1].Trim(']').Split(':');
            HControl hcontroldiv = new HControl();

            hcontroldiv.Control   = h[0].Trim();
            hcontroldiv.Attribute = j[0].Trim();
            hcontroldiv.Value     = j[1].Trim();
            TextField div     = MyWatiN.GetTextField(ie, hcontroldiv);
            string    style   = div.GetAttributeValue("style");
            string    display = Filter.GetTextByRegex(FilterPattern.Display, style, true, 0, 1);

            if (!string.IsNullOrEmpty(display))
            {
                string[] k = a[0].Split(',');
                foreach (string l in k)
                {
                    string[] m        = l.Trim().Split('[');
                    string   n        = m[1].Trim(']');
                    string[] o        = n.Split(':');
                    HControl hcontrol = new HControl();
                    hcontrol.Control   = m[0].Trim();
                    hcontrol.Attribute = o[0].Trim();
                    hcontrol.Value     = o[1].Trim();
                    controls.Add(hcontrol);
                }
                return(RunControl(controls, "", ie));
            }
            return(String.Empty);
        }
Esempio n. 4
0
        private static string RunControlConfirm(List <HControl> controls, IE ie)
        {
            int    i      = 0;
            string status = "Error";

            while (i < Loop)
            {
                i++;
                foreach (HControl control in controls)
                {
                    switch (control.Control.ToLower())
                    {
                    case ControlType.AHref:
                    {
                        WatiN.Core.Link obj = MyWatiN.GetLink(ie, control);
                        if (obj != null)
                        {
                            ConfirmDialogHandler approveConfirmDialog = new ConfirmDialogHandler();
                            using (new UseDialogOnce(ie.DialogWatcher, approveConfirmDialog))
                            {
                                obj.ClickNoWait();
                                approveConfirmDialog.WaitUntilExists();
                                approveConfirmDialog.OKButton.Click();
                                ie.WaitForComplete();
                                return(String.Empty);
                            }
                        }
                        break;
                    }

                    case ControlType.Link:
                    {
                        WatiN.Core.Link obj = MyWatiN.GetLink(ie, control);
                        if (obj != null)
                        {
                            ConfirmDialogHandler approveConfirmDialog = new ConfirmDialogHandler();
                            using (new UseDialogOnce(ie.DialogWatcher, approveConfirmDialog))
                            {
                                obj.ClickNoWait();
                                approveConfirmDialog.WaitUntilExists();
                                approveConfirmDialog.OKButton.Click();
                                ie.WaitForComplete();
                                return(String.Empty);
                            }
                        }
                        break;
                    }

                    case ControlType.Button:
                    {
                        WatiN.Core.Button obj = MyWatiN.GetButton(ie, control);
                        if (obj != null)
                        {
                            ConfirmDialogHandler approveConfirmDialog = new ConfirmDialogHandler();
                            using (new UseDialogOnce(ie.DialogWatcher, approveConfirmDialog))
                            {
                                obj.ClickNoWait();
                                approveConfirmDialog.WaitUntilExists();
                                approveConfirmDialog.OKButton.Click();
                                ie.WaitForComplete();
                                return(String.Empty);
                            }
                        }
                        break;
                    }

                    case ControlType.Div:
                    {
                        WatiN.Core.Div obj = MyWatiN.GetDiv(ie, control);
                        if (obj != null)
                        {
                            ConfirmDialogHandler approveConfirmDialog = new ConfirmDialogHandler();

                            using (new UseDialogOnce(ie.DialogWatcher, approveConfirmDialog))
                            {
                                obj.ClickNoWait();
                                approveConfirmDialog.WaitUntilExists();
                                approveConfirmDialog.OKButton.Click();
                                ie.WaitForComplete();
                                return(String.Empty);
                            }
                        }
                        break;
                    }
                    }
                }
                Thread.Sleep(1000);
            }
            return(status);
        }
Esempio n. 5
0
        public static string RunControl(List <HControl> controls, string data, IE ie)
        {
            int    i      = 0;
            string status = "Error";

            while (i < Loop)
            {
                i++;
                foreach (HControl control in controls)
                {
                    switch (control.Control.ToLower())
                    {
                    case ControlType.AHref:
                    {
                        WatiN.Core.Link obj = MyWatiN.GetLink(ie, control);
                        if (obj != null)
                        {
                            obj.Click();
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.AHrefNoText:
                    {
                        ie.GoTo(control.Value);
                        ie.WaitForComplete();
                        return(String.Empty);

                        break;
                    }

                    case ControlType.Link:
                    {
                        WatiN.Core.Link obj = MyWatiN.GetLink(ie, control);
                        if (obj != null)
                        {
                            obj.Click();
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.Button:
                    {
                        WatiN.Core.Button obj = MyWatiN.GetButton(ie, control);
                        if (obj != null)
                        {
                            obj.Click();
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.Div:
                    {
                        WatiN.Core.Div obj = MyWatiN.GetDiv(ie, control);
                        if (obj != null)
                        {
                            obj.Click();
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.Image:
                    {
                        WatiN.Core.Image obj = MyWatiN.GetImage(ie, control);
                        if (obj != null)
                        {
                            obj.Click();
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.TextArea:
                    {
                        WatiN.Core.TextField obj = MyWatiN.GetTextField(ie, control);
                        if (obj != null)
                        {
                            obj.Value = data;
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.TextBox:
                    {
                        WatiN.Core.TextField obj = MyWatiN.GetTextField(ie, control);
                        if (obj != null)
                        {
                            obj.Value = data;
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.CheckBox:
                    {
                        WatiN.Core.CheckBox obj = MyWatiN.GetCheckBox(ie, control);
                        if (obj != null)
                        {
                            obj.Checked = bool.Parse(data);
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }
                    }
                }
                Thread.Sleep(1000);
            }
            return(status);
        }
Esempio n. 6
0
        public static string RunControl(List <HControl> controls, string data, Div div, IE ie)
        {
            int    i      = 0;
            string status = "Error";

            while (i < Loop)
            {
                i++;
                foreach (HControl control in controls)
                {
                    switch (control.Control.ToLower())
                    {
                    case ControlType.Link:
                    {
                        WatiN.Core.Link obj = MyWatiN.GetLink(div, control);
                        if (obj != null)
                        {
                            obj.Click();
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.Button:
                    {
                        WatiN.Core.Button obj = MyWatiN.GetButton(div, control);
                        if (obj != null)
                        {
                            obj.Click();
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.Image:
                    {
                        WatiN.Core.Image obj = MyWatiN.GetImage(div, control);
                        if (obj != null)
                        {
                            obj.Click();
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.TextArea:
                    {
                        WatiN.Core.TextField obj = MyWatiN.GetTextField(div, control);
                        if (obj != null)
                        {
                            obj.Value = data;
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.TextBox:
                    {
                        WatiN.Core.TextField obj = MyWatiN.GetTextField(div, control);
                        if (obj != null)
                        {
                            obj.Value = data;
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.CheckBox:
                    {
                        WatiN.Core.CheckBox obj = MyWatiN.GetCheckBox(div, control);
                        if (obj != null)
                        {
                            obj.Checked = true;
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }
                    }
                }
                if (i < Loop - 1)
                {
                    Thread.Sleep(1000);
                }
            }
            return(status);
        }
Esempio n. 7
0
        public static bool CheckExist(List <HControl> controls, IE ie)
        {
            int  i      = 0;
            bool status = false;

            while (i < 2)
            {
                i++;
                foreach (HControl control in controls)
                {
                    switch (control.Control.ToLower())
                    {
                    case ControlType.AHref:
                    {
                        WatiN.Core.Link obj = MyWatiN.GetLink(ie, control);
                        if (obj != null)
                        {
                            return(true);
                        }
                        break;
                    }

                    case ControlType.Link:
                    {
                        WatiN.Core.Link obj = MyWatiN.GetLink(ie, control);
                        if (obj != null)
                        {
                            return(true);
                        }
                        break;
                    }

                    case ControlType.Button:
                    {
                        WatiN.Core.Button obj = MyWatiN.GetButton(ie, control);
                        if (obj != null)
                        {
                            return(true);
                        }
                        break;
                    }

                    case ControlType.Div:
                    {
                        WatiN.Core.Div obj = MyWatiN.GetDiv(ie, control);
                        if (obj != null)
                        {
                            return(true);
                        }
                        break;
                    }

                    case ControlType.Image:
                    {
                        WatiN.Core.Image obj = MyWatiN.GetImage(ie, control);
                        if (obj != null)
                        {
                            return(true);
                        }
                        break;
                    }

                    case ControlType.TextArea:
                    {
                        WatiN.Core.TextField obj = MyWatiN.GetTextField(ie, control);
                        if (obj != null)
                        {
                            return(true);
                        }
                        break;
                    }

                    case ControlType.TextBox:
                    {
                        WatiN.Core.TextField obj = MyWatiN.GetTextField(ie, control);
                        if (obj != null)
                        {
                            return(true);
                        }
                        break;
                    }

                    case ControlType.CheckBox:
                    {
                        WatiN.Core.CheckBox obj = MyWatiN.GetCheckBox(ie, control);
                        if (obj != null)
                        {
                            return(true);
                        }
                        break;
                    }
                    }
                }
                if (i < 1)
                {
                    Thread.Sleep(1000);
                }
            }
            return(status);
        }
Esempio n. 8
0
        public void Run()
        {
            if (listforum == null)
            {
                return;
            }
            string error = "";

            while (listforum.Count != 0)
            {
                error = "";
                try
                {
                    WebLink forum = new WebLink();
                    lock (listforum)
                    {
                        if (listforum.Count > 0)
                        {
                            forum = listforum[0];
                            listforum.RemoveAt(0);
                        }
                    }
                    if (string.IsNullOrEmpty(forum.UrlPost))
                    {
                        break;
                    }
                    // Start WatiN
                    Open();

                    // Start Forum
                    error = MyWatiN.Goto(forum.UrlPost, ie);
                    if (!string.IsNullOrEmpty(error))
                    {
                        AddStatus(forum.UrlPost, RunStatus.ErrTimeOut, error);
                        Close();
                        continue;
                    }

                    // === Step 1 === //
                    //NextStep();

                    // Control User name
                    error = "";
                    if ((error = RunControl(multiforum.UserName, forum.UserName)) != string.Empty)
                    {
                        AddStatus(forum.UrlPost, RunStatus.ErrUserName, error);
                        Close();
                        continue;
                    }

                    // Control Pass word
                    error = "";
                    if ((error = RunControl(multiforum.PassWord, forum.Password)) != string.Empty)
                    {
                        AddStatus(forum.UrlPost, RunStatus.ErrPassword, error);
                        Close();
                        continue;
                    }

                    // Control Login
                    error = "";
                    if ((error = RunControl(multiforum.Login)) != string.Empty)
                    {
                        AddStatus(forum.UrlPost, RunStatus.ErrLogin, error);
                        Close();
                        continue;
                    }

                    error = MyWatiN.Goto(forum.UrlPost, ie);
                    if (!string.IsNullOrEmpty(error))
                    {
                        AddStatus(forum.UrlPost, RunStatus.ErrTimeOut, error);
                        Close();
                        continue;
                    }

                    //Wait(10000);

                    // === Step 2 === //
                    //NextStep();

                    // Filter topic
                    bool   isTopic    = false;
                    bool   isNewTopic = false;
                    string href       = "";

                    error = "";
                    string tmp = "";

                    HControl link = new HControl();
                    link.Control   = ControlType.AHref;
                    link.Attribute = AttributeType.Text;

                    for (int j = 0; j < multiforum.NewThread.Count; j++)
                    {
                        href = GetLink(ie.Links, multiforum.NewThread[j].Value);
                        //forum.NewThread.Field = FilterUrl.AbsoluteUrl(ie.Url, href);
                        if (!string.IsNullOrEmpty(href))
                        {
                            // New Thread
                            multiforum.NewThread[j].Value = href;
                            error = MyWatiN.FillData(ie, multiforum.NewThread[j]);
                            //Wait(3000);

                            isNewTopic = true;
                            isTopic    = true;
                            break;
                        }
                    }
                    // === Step 3 === //
                    //NextStep();
                    if (!isNewTopic)
                    {
                        AddStatus(forum.UrlPost, RunStatus.ErrNewThread, error);
                        Close();
                        continue;
                    }

                    // Fill entry
                    // Control Subject
                    error = "";
                    if ((error = RunControl(multiforum.Subject, entry.Subject)) != string.Empty)
                    {
                        AddStatus(forum.UrlPost, RunStatus.ErrSubject, error);
                        Close();
                        continue;
                    }

                    // Control Mode
                    error = "";
                    bool b = false;
                    for (int i = 0; i < multiforum.Mode.Count; i++)
                    {
                        if (MyWatiN.IsExist(ie, multiforum.Mode[i]))
                        {
                            for (int j = 0; j < multiforum.Message.Count; j++)
                            {
                                string style   = ie.TextField(MyWatiN.GetControl(ie, multiforum.Message[j])).GetAttributeValue("style");
                                string display = Filter.GetTextByRegex(FilterPattern.Display, style, true, 0, 1);
                                if (!string.IsNullOrEmpty(display))
                                {
                                    MyWatiN.FillData(ie, multiforum.Mode[i]);
                                    b = true;
                                    break;
                                }
                            }
                            if (b == true)
                            {
                                break;
                            }
                        }
                    }

                    // Control Message
                    error = "";
                    if ((error = RunControl(multiforum.Message, entry.Message)) != string.Empty)
                    {
                        AddStatus(forum.UrlPost, RunStatus.ErrMessage, error);
                        Close();
                        continue;
                    }
                    // === Step 4 === //
                    //NextStep();
                    // Control Tag
                    RunControl(multiforum.Tags, entry.Tags);


                    AddStatus(forum.UrlPost, RunStatus.Success);

                    // === Step 5 === //
                    error = "";
                    if ((error = RunControl(multiforum.Submit)) != string.Empty)
                    {
                        AddStatus(forum.UrlPost, RunStatus.ErrSubmit, error);
                        Close();
                        continue;
                    }

                    // NextStep();

                    // End WatiN
                    Close();
                    Wait(6000);
                }
                catch (Exception ex)
                {
                    if (ie != null)
                    {
                        AddStatus("", RunStatus.Error, ex.Message);
                        Close();
                    }
                }
            }
        }