예제 #1
0
 public ProductManager()
 {
     bot        = new WebBot();
     productDal = new ProductDal();
     mailSender = new MailSender();
     handle     = new HandleException();
 }
예제 #2
0
 public void Stop(bool web)
 {
     TrimBot.Abort();
     ManageBot.Abort();
     if (web)
     {
         WebBot.Abort();
     }
 }
예제 #3
0
        //[STAThread]
        static void Main(string[] args)
        {
#if DEBUG
            System.Diagnostics.Debug.WriteLine("[*] Initializing WebBot ");
#endif
            string HtmlFilePath = String.Format(@"file:///{0}App_Data\{1}", AppDomain.CurrentDomain.BaseDirectory, "IndeedApplicationForm1.html");

            WebBot bot = new WebBot(HtmlFilePath);

            //bot.HiddenInstance();
            bot.Start();

            Console.ReadLine();
        }
예제 #4
0
 public void httplisten()
 {
     try
     {
         while (true)
         {
             listener.Start();
             HttpListenerContext context = listener.GetContext();
             HttpListenerRequest request = context.Request;
             StreamReader        input   = new StreamReader(request.InputStream, request.ContentEncoding);
             string kvpair = input.ReadToEnd();
             if (kvpair.Contains("="))
             {
                 string action = kvpair.Split('=')[0];
                 if (action == "stop")
                 {
                     StopAtNext = true;
                     MyConsole.WriteLine("#" + CurrentFile + ": Stopping Bot after dataset.");
                 }
                 else if (action == "start")
                 {
                     StopAtNext = false;
                     if (!TrimBot.IsAlive)
                     {
                         MyConsole.WriteLine("#" + CurrentFile + ": Restarting Bot.");
                         Start();
                     }
                     else
                     {
                         MyConsole.WriteLine("#" + (CurrentFile + 1) + ": Restarting Bot at dataset.");
                     }
                 }
                 else if (action == "refresh")
                 {
                     int curLine = int.Parse(kvpair.Split('=')[1]);
                     HttpListenerResponse response = context.Response;
                     byte[] buffer = Encoding.UTF8.GetBytes("{ \"text\" : \"" + MyConsole.GetHTML(curLine) + "\", \"curLine\" : " + MyConsole.Lines.Count + ", \"curSet\" : " + CurrentFile + ", \"numcrash\" : " + Crashes + ", \"time\" : \"" + calcRestTime() + "\"}");
                     response.ContentLength64 = buffer.Length;
                     Stream output = response.OutputStream;
                     output.Write(buffer, 0, buffer.Length);
                     output.Close();
                     listener.Stop();
                 }
             }
             else
             {
                 HttpListenerResponse response = context.Response;
                 XmlDocument          html     = new XmlDocument();
                 html.LoadXml(Properties.Resources.template);
                 XmlNode curLineSpan = html.SelectSingleNode("//span[@id='curLineSpan']");
                 XmlNode dataset     = html.SelectSingleNode("//p[@id='dataset']");
                 XmlNode crashes     = html.SelectSingleNode("//p[@id='crashes']");
                 XmlNode console     = html.SelectSingleNode("//div[@id='console']");
                 XmlNode button      = html.SelectSingleNode("//div[@id='button']");
                 XmlNode time        = html.SelectSingleNode("//p[@id='time']");
                 XmlNode script      = html.SelectSingleNode("//script[@type='text/javascript']");
                 curLineSpan.InnerText = MyConsole.Lines.Count.ToString();
                 dataset.InnerText     = "Current dataset: #" + Properties.Settings.Default.progress;
                 crashes.InnerText     = "Number of crashes: " + Crashes;
                 console.InnerXml      = MyConsole.GetHTML(0);
                 time.InnerText        = calcRestTime();
                 XmlAttribute btnAttr1 = html.CreateAttribute("class");
                 XmlAttribute btnAttr2 = html.CreateAttribute("onclick");
                 if (StopAtNext)
                 {
                     btnAttr1.Value = "start";
                     btnAttr2.Value = "start();";
                 }
                 else
                 {
                     btnAttr1.Value = "stop";
                     btnAttr2.Value = "stop();";
                 }
                 button.Attributes.Append(btnAttr1);
                 button.Attributes.Append(btnAttr2);
                 script.InnerText = Properties.Resources.script;
                 byte[] buffer = Encoding.UTF8.GetBytes(html.OuterXml);
                 response.ContentLength64 = buffer.Length;
                 Stream output = response.OutputStream;
                 output.Write(buffer, 0, buffer.Length);
                 output.Close();
                 listener.Stop();
             }
         }
     }
     catch (Exception exc)
     {
         listener.Stop();
         WebBot.Abort();
     }
 }