예제 #1
0
        public static AttributeConstraint GetControl(IE ie, HControl control)
        {
            //Regex regex = new Regex(FilterPattern.GetToPattern(control.Value));
            String regex = control.Value;

            switch (control.Attribute.ToLower())
            {
            case AttributeType.Id:
                return(Find.ById(regex));

            case AttributeType.Name:
                return(Find.ByName(regex));

            case AttributeType.Class:
                return(Find.ByClass(regex));

            case AttributeType.Text:
            {
                Regex regexs = new Regex(FilterPattern.GetToPattern(control.Value));
                return(Find.ByText(regexs));
            }

            case AttributeType.Value:
            {
                Regex regexs = new Regex(FilterPattern.GetToPattern(control.Value));
                return(Find.ByValue(regexs));
            }

            default:
                return(Find.ByName(regex));
            }
        }
예제 #2
0
 public static AttributeConstraint GetControl(IE ie, HControl control)
 {
     //Regex regex = new Regex(FilterPattern.GetToPattern(control.Value));
     String regex = control.Value;
     switch (control.Attribute.ToLower())
     {
         case AttributeType.Id:
             return Find.ById(regex);
         case AttributeType.Name:
             return Find.ByName(regex);
         case AttributeType.Class:
             return Find.ByClass(regex);
         case AttributeType.Text:
             {
                 Regex regexs = new Regex(FilterPattern.GetToPattern(control.Value));
                 return Find.ByText(regexs);
             }
         case AttributeType.Value:
             {
                 Regex regexs = new Regex(FilterPattern.GetToPattern(control.Value));
                 return Find.ByValue(regexs);
             }
         default:
             return Find.ByName(regex);
     }
 }
예제 #3
0
        public static List <HControl> GetByField(string Field, string Type)
        {
            try
            {
                List <HControl> fields = new List <HControl>();
                string          sql    = @"select * from QLCV_FieldSetting where Field='" + Field + "' and Type='" + Type + "'";
                DataTable       table  = ServerProvider.ExecuteToDataTable(sql);
                if (table != null && table.Rows.Count > 0)
                {
                    foreach (DataRow row in table.Rows)
                    {
                        HControl ctr = new HControl();
                        ctr.Control   = row["Control"].ToString();
                        ctr.Attribute = row["Attribute"].ToString();
                        ctr.Value     = row["Value"].ToString();

                        fields.Add(ctr);
                    }
                }

                return(fields);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
예제 #4
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");
        }
예제 #5
0
        public static WatiN.Core.Div GetDiv(IE ie, HControl control)
        {
            switch (control.Attribute.ToLower())
            {
            case AttributeType.Id:
            {
                Div div = ie.Div(Find.ById(control.Value));
                if (div.Exists)
                {
                    return(div);
                }
                return(null);
            }

            case AttributeType.Name:
            {
                Div div = ie.Div(Find.ByName(control.Value));
                if (div.Exists)
                {
                    return(div);
                }
                return(null);
            }

            case AttributeType.Class:
            {
                Div div = ie.Div(Find.ByClass(control.Value));
                if (div.Exists)
                {
                    return(div);
                }
                return(null);
            }

            case AttributeType.Text:
            {
                foreach (WatiN.Core.Div bt in ie.Divs)
                {
                    if (bt.Text == control.Value)
                    {
                        return(bt);
                    }
                }
                return(null);
            }

            default:
            {
                foreach (WatiN.Core.Div bt in ie.Divs)
                {
                    if (bt.Name == control.Value)
                    {
                        return(bt);
                    }
                }
                return(null);
            }
            }
        }
예제 #6
0
        public static WatiN.Core.Link GetLink(Div div, HControl control)
        {
            switch (control.Attribute.ToLower())
            {
            case AttributeType.Id:
            {
                Link link = div.Link(Find.ById(control.Value));
                if (link.Exists)
                {
                    return(link);
                }
                return(null);
            }

            case AttributeType.Name:
            {
                Link link = div.Link(Find.ByName(control.Value));
                if (link.Exists)
                {
                    return(link);
                }
                return(null);
            }

            case AttributeType.Class:
            {
                Link link = div.Link(Find.ByClass(control.Value));
                if (link.Exists)
                {
                    return(link);
                }
                return(null);
            }

            case AttributeType.Text:
            {
                Link link = div.Link(Find.ByText(control.Value));
                if (link.Exists)
                {
                    return(link);
                }
                return(null);
            }

            default:
            {
                Link link = div.Link(Find.ByText(control.Value));
                if (link.Exists)
                {
                    return(link);
                }
                return(null);
            }
            }
        }
예제 #7
0
        public static string FillData(IE ie, HControl control, string data)
        {
            int i = 0;

            while (i < Loop)
            {
                i++;
                try
                {
                    switch (control.Control.ToLower())
                    {
                    case ControlType.AHref:
                        ie.Link(GetControl(ie, control)).Click();
                        break;

                    case ControlType.AHrefNoText:
                        ie.GoTo(control.Value);
                        break;

                    case ControlType.Button:
                        ie.Button(GetControl(ie, control)).Click();
                        break;

                    case ControlType.Div:
                        ie.Div(GetControl(ie, control)).Click();
                        break;

                    case ControlType.TextArea:
                        ie.TextField(GetControl(ie, control)).Value = data;
                        break;

                    case ControlType.TextBox:
                        ie.TextField(GetControl(ie, control)).Value = data;
                        break;
                    }
                    ie.WaitForComplete();

                    return(string.Empty);
                }
                catch (Exception ex)
                {
                    if (i == Loop)
                    {
                        return(ex.Message);
                    }
                    Thread.Sleep(60000);
                }
            }
            return(string.Empty);
        }
예제 #8
0
        public static bool IsExist(IE ie, HControl control)
        {
            try
            {
                bool  existed = true;
                Regex regex   = new Regex(FilterPattern.GetToPattern(control.Value));
                switch (control.Control.ToLower())
                {
                case ControlType.AHref:
                    existed = ie.Link(Find.ByText(regex)).Exists;
                    break;

                case ControlType.AHrefNoText:
                    try
                    {
                    }
                    catch (Exception ex)
                    {
                        existed = false;
                    }
                    break;

                case ControlType.Button:
                    existed = ie.Button(GetControl(ie, control)).Exists;
                    break;

                case ControlType.Div:
                    existed = ie.Div(GetControl(ie, control)).Exists;
                    break;

                case ControlType.TextArea:
                    existed = ie.TextField(GetControl(ie, control)).Exists;
                    break;

                case ControlType.TextBox:
                    existed = ie.TextField(GetControl(ie, control)).Exists;
                    break;
                }
                return(existed);//
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
예제 #9
0
        private static string ClickConfirm(String text, IE ie)
        {
            List <HControl> controls = new List <HControl>();

            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(RunControlConfirm(controls, ie));
        }
예제 #10
0
        public static bool IsExist(IE ie, HControl control)
        {
            try
            {
                bool existed = true;
                Regex regex = new Regex(FilterPattern.GetToPattern(control.Value));
                switch (control.Control.ToLower())
                {
                    case ControlType.AHref:
                        existed = ie.Link(Find.ByText(regex)).Exists;
                        break;
                    case ControlType.AHrefNoText:
                        try
                        {

                        }
                        catch (Exception ex)
                        {
                            existed = false;
                        }
                        break;
                    case ControlType.Button:
                        existed = ie.Button(GetControl(ie, control)).Exists;
                        break;
                    case ControlType.Div:
                        existed = ie.Div(GetControl(ie, control)).Exists;
                        break;
                    case ControlType.TextArea:
                        existed = ie.TextField(GetControl(ie, control)).Exists;
                        break;
                    case ControlType.TextBox:
                        existed = ie.TextField(GetControl(ie, control)).Exists;
                        break;
                }
                return existed;// 
            }
            catch (Exception ex)
            {
                return false;
            }
        }
예제 #11
0
        private static string Submit(String text, IE ie)
        {
            List <HControl> controls = new List <HControl>();

            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);
            }
            foreach (WatiN.Core.Form frm in ie.Forms)
            {
                foreach (HControl ctr in controls)
                {
                    if (frm.GetAttributeValue(ctr.Attribute).IndexOf(ctr.Value) >= 0)
                    {
                        int timeout = Settings.WaitForCompleteTimeOut;
                        Settings.WaitForCompleteTimeOut = 1;
                        try
                        {
                            frm.Submit();
                        }
                        catch
                        {
                        }
                        ie.WaitForComplete();
                        Settings.WaitForCompleteTimeOut = timeout;
                        return(String.Empty);
                    }
                }
            }

            return("Error");
        }
예제 #12
0
 public static bool Exist(String text, IE ie)
 {
     try
     {
         List <HControl> controls = new List <HControl>();
         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(CheckExist(controls, ie));
     }
     catch
     {
         return(false);
     }
 }
예제 #13
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);
        }
예제 #14
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();
                    }
                }
            }
        }
예제 #15
0
        public static WatiN.Core.Button GetButton(Div ie, HControl control)
        {

            switch (control.Attribute.ToLower())
            {
                case AttributeType.Id:
                    {
                        Button bt = ie.Button(Find.ById(control.Value));
                        if (bt.Exists)
                            return bt;
                        return null;
                    }
                case AttributeType.Name:
                    {
                        Button bt = ie.Button(Find.ByName(control.Value));
                        if (bt.Exists)
                            return bt;
                        return null;
                    }
                case AttributeType.Class:
                    {
                        Button bt = ie.Button(Find.ByClass(control.Value));
                        if (bt.Exists)
                            return bt;
                        return null;
                    }
                case AttributeType.Text:
                    {
                        foreach (WatiN.Core.Button bt in ie.Buttons)
                        {
                            string s = bt.Text.ToLowerInvariant();
                            s = s.Replace("ð", "đ");
                            if (s == control.Value.ToLower())
                                return bt;
                        }
                        return null;
                    }
                case AttributeType.Value:
                    {
                        foreach (WatiN.Core.Button bt in ie.Buttons)
                        {
                            string s = bt.Value.ToLowerInvariant();
                            s = s.Replace("ð", "đ");
                            if (s == control.Value.ToLower())
                                return bt;
                        }
                        return null;
                    }
                default:
                    {
                        foreach (WatiN.Core.Button bt in ie.Buttons)
                        {
                            if (bt.Name == control.Value)
                                return bt;
                        }
                        return null;
                    }
            }
        }
예제 #16
0
 public static WatiN.Core.Div GetDiv(IE ie, HControl control)
 {
     switch (control.Attribute.ToLower())
     {
         case AttributeType.Id:
             {
                 Div div = ie.Div(Find.ById(control.Value));
                 if (div.Exists)
                     return div;
                 return null;
             }
         case AttributeType.Name:
             {
                 Div div = ie.Div(Find.ByName(control.Value));
                 if (div.Exists)
                     return div;
                 return null;
             }
         case AttributeType.Class:
             {
                 Div div = ie.Div(Find.ByClass(control.Value));
                 if (div.Exists)
                     return div;
                 return null;
             }
         case AttributeType.Text:
             {
                 foreach (WatiN.Core.Div bt in ie.Divs)
                 {
                     if (bt.Text == control.Value)
                         return bt;
                 }
                 return null;
             }
         
         default:
             {
                 foreach (WatiN.Core.Div bt in ie.Divs)
                 {
                     if (bt.Name == control.Value)
                         return bt;
                 }
                 return null;
             }
     }
 }
예제 #17
0
 public static WatiN.Core.Link GetLink(Div div, HControl control)
 {
     switch (control.Attribute.ToLower())
     {
         case AttributeType.Id:
             {
                 Link link = div.Link(Find.ById(control.Value));
                 if (link.Exists)
                     return link;
                 return null;
             }
         case AttributeType.Name:
             {
                 Link link = div.Link(Find.ByName(control.Value));
                 if (link.Exists)
                     return link;
                 return null;
             }
         case AttributeType.Class:
             {
                 Link link = div.Link(Find.ByClass(control.Value));
                 if (link.Exists)
                     return link;
                 return null;
             }
         case AttributeType.Text:
             {
                 Link link = div.Link(Find.ByText(control.Value));
                 if (link.Exists)
                     return link;
                 return null;
             }
         default:
             {
                 Link link = div.Link(Find.ByText(control.Value));
                 if (link.Exists)
                     return link;
                 return null;
             }
     }
 }
예제 #18
0
 public static string FillData(IE ie, HControl control)
 {
     return(FillData(ie, control, ""));
 }
예제 #19
0
 public static WatiN.Core.Image GetImage(Div ie, HControl control)
 {
     switch (control.Attribute.ToLower())
     {
         case AttributeType.Id:
             {
                 Image txt = ie.Image(Find.ById(control.Value));
                 if (txt.Exists)
                     return txt;
                 return null;
             }
         case AttributeType.Name:
             {
                 Image txt = ie.Image(Find.ByName(control.Value));
                 if (txt.Exists)
                     return txt;
                 return null;
             }
         case AttributeType.Class:
             {
                 Image txt = ie.Image(Find.ByClass(control.Value));
                 if (txt.Exists)
                     return txt;
                 return null;
             }
         case AttributeType.Text:
             {
                 Image txt = ie.Image(Find.ByText(control.Value));
                 if (txt.Exists)
                     return txt;
                 return null;
             }
         case AttributeType.Value:
             {
                 Image txt = ie.Image(Find.ByValue(control.Value));
                 if (txt.Exists)
                     return txt;
                 return null;
             }
         default:
             {
                 Image txt = ie.Image(Find.ByName(control.Value));
                 if (txt.Exists)
                     return txt;
                 return null;
             }
     }
 }
예제 #20
0
 public static string FillData(IE ie, HControl control)
 {
     return FillData(ie, control, "");
 }
예제 #21
0
        public static WatiN.Core.Image GetImage(Div ie, HControl control)
        {
            switch (control.Attribute.ToLower())
            {
            case AttributeType.Id:
            {
                Image txt = ie.Image(Find.ById(control.Value));
                if (txt.Exists)
                {
                    return(txt);
                }
                return(null);
            }

            case AttributeType.Name:
            {
                Image txt = ie.Image(Find.ByName(control.Value));
                if (txt.Exists)
                {
                    return(txt);
                }
                return(null);
            }

            case AttributeType.Class:
            {
                Image txt = ie.Image(Find.ByClass(control.Value));
                if (txt.Exists)
                {
                    return(txt);
                }
                return(null);
            }

            case AttributeType.Text:
            {
                Image txt = ie.Image(Find.ByText(control.Value));
                if (txt.Exists)
                {
                    return(txt);
                }
                return(null);
            }

            case AttributeType.Value:
            {
                Image txt = ie.Image(Find.ByValue(control.Value));
                if (txt.Exists)
                {
                    return(txt);
                }
                return(null);
            }

            default:
            {
                Image txt = ie.Image(Find.ByName(control.Value));
                if (txt.Exists)
                {
                    return(txt);
                }
                return(null);
            }
            }
        }
예제 #22
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;
           
        }
예제 #23
0
        public static string FillData(IE ie, HControl control, string data)
        {
            int i = 0;
            while (i < Loop)
            {
                i++;
                try
                {
                    switch (control.Control.ToLower())
                    {
                        case ControlType.AHref:
                            ie.Link(GetControl(ie, control)).Click();
                            break;
                        case ControlType.AHrefNoText:
                            ie.GoTo(control.Value);
                            break;
                        case ControlType.Button:
                            ie.Button(GetControl(ie, control)).Click();
                            break;
                        case ControlType.Div:
                            ie.Div(GetControl(ie, control)).Click();
                            break;
                        case ControlType.TextArea:
                            ie.TextField(GetControl(ie, control)).Value = data;
                            break;
                        case ControlType.TextBox:
                            ie.TextField(GetControl(ie, control)).Value = data;
                            break;
                    }
                    ie.WaitForComplete();

                    return string.Empty;
                }
                catch (Exception ex)
                {
                    if (i == Loop)
                    {
                        return ex.Message;
                    }
                    Thread.Sleep(60000);
                }
            }
            return string.Empty;
        }
예제 #24
0
        public static WatiN.Core.Button GetButton(Div ie, HControl control)
        {
            switch (control.Attribute.ToLower())
            {
            case AttributeType.Id:
            {
                Button bt = ie.Button(Find.ById(control.Value));
                if (bt.Exists)
                {
                    return(bt);
                }
                return(null);
            }

            case AttributeType.Name:
            {
                Button bt = ie.Button(Find.ByName(control.Value));
                if (bt.Exists)
                {
                    return(bt);
                }
                return(null);
            }

            case AttributeType.Class:
            {
                Button bt = ie.Button(Find.ByClass(control.Value));
                if (bt.Exists)
                {
                    return(bt);
                }
                return(null);
            }

            case AttributeType.Text:
            {
                foreach (WatiN.Core.Button bt in ie.Buttons)
                {
                    string s = bt.Text.ToLowerInvariant();
                    s = s.Replace("ð", "đ");
                    if (s == control.Value.ToLower())
                    {
                        return(bt);
                    }
                }
                return(null);
            }

            case AttributeType.Value:
            {
                foreach (WatiN.Core.Button bt in ie.Buttons)
                {
                    string s = bt.Value.ToLowerInvariant();
                    s = s.Replace("ð", "đ");
                    if (s == control.Value.ToLower())
                    {
                        return(bt);
                    }
                }
                return(null);
            }

            default:
            {
                foreach (WatiN.Core.Button bt in ie.Buttons)
                {
                    if (bt.Name == control.Value)
                    {
                        return(bt);
                    }
                }
                return(null);
            }
            }
        }
예제 #25
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";
        }
예제 #26
0
 private static string Submit(String text, IE ie)
 {
     List<HControl> controls = new List<HControl>();
     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);
     }
     foreach (WatiN.Core.Form frm in ie.Forms)
     {
         foreach (HControl ctr in controls)
         {
             if (frm.GetAttributeValue(ctr.Attribute).IndexOf(ctr.Value) >= 0)
             {
                 int timeout = Settings.WaitForCompleteTimeOut;
                 Settings.WaitForCompleteTimeOut = 1;
                 try
                 {
                     frm.Submit();
                 }
                 catch
                 {
                 }
                 ie.WaitForComplete();
                 Settings.WaitForCompleteTimeOut = timeout;
                 return String.Empty;
             }
         }
     }
   
     return "Error";
 }
예제 #27
0
 private static string ClickConfirm(String text, IE ie)
 {
     List<HControl> controls = new List<HControl>();
     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 RunControlConfirm(controls, ie);
 }
예제 #28
0
 public static bool Exist(String text, IE ie)
 {
     try
     {
         List<HControl> controls = new List<HControl>();
         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 CheckExist(controls, ie);
     }
     catch
     {
         return false;
     }
 }
예제 #29
0
        public static List<HControl> GetByField(string Field,string Type)
        {
            try
            {
                List<HControl> fields = new List<HControl>();
                string sql = @"select * from QLCV_FieldSetting where Field='" + Field + "' and Type='" + Type + "'";
                DataTable table = ServerProvider.ExecuteToDataTable(sql);
                if (table != null && table.Rows.Count > 0)
                {
                    foreach (DataRow row in table.Rows)
                    {
                        HControl ctr = new HControl();
                        ctr.Control = row["Control"].ToString();
                        ctr.Attribute = row["Attribute"].ToString();
                        ctr.Value = row["Value"].ToString();

                        fields.Add(ctr);
                    }
                }

                return fields;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
예제 #30
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();
                    }
                }
            }
        }