public bool Render(string xmlfilePattern, Dictionary <string, Entity> dicScraper, Dictionary <string, Entity> dicProxy) { /* get input xml file and parse it to Sinter object */ Sinter sinterIn = conn.GetSinterFromFile(resultDir, xmlfilePattern); Console.WriteLine(@"Input filename: {0}\*{1}", resultDir, xmlfilePattern); Assert.IsTrue(sinterIn != null); /* execute the sinter, in this case: ls_l_res */ bool ret = cmdhlr.CommandExecSinter(sinterIn); Assert.IsTrue(ret); /* screenshot the render window, save to output folder */ Bitmap bmp = new Bitmap(proxy.Form.Width, proxy.Form.Height); proxy.Form.DrawToBitmap(bmp, new Rectangle(0, 0, proxy.Form.Width, proxy.Form.Height)); string pngfile = string.Format(@"{0}\{1}.png", TestContext.DeploymentDirectory, TestContext.TestName); bmp.Save(pngfile, ImageFormat.Png); Console.WriteLine("Output png saved to {0}", pngfile); /* create a dummy scraper to scraper our proxy window */ WindowsScraper.WindowsScraper dummyScraper = new WindowsScraper.WindowsScraper(); AutomationElement renderedElement = SinterUtil.GetAutomationElementFromId(Process.GetCurrentProcess().Id.ToString(), IdType.ProcessId); Assert.IsNotNull(renderedElement); Entity entityOut = dummyScraper.UIAElement2EntityRecursive(renderedElement); /* parse to two dictionay and compare */ ParseXML(sinterIn.EntityNode, dicScraper, 0); ParseXML(entityOut, dicProxy, 0); /* * foreach (KeyValuePair<string, Entity> kvp in dicScraper) * { * Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value.States); * } * Console.WriteLine("=================================="); * foreach (KeyValuePair<string, Entity> kvp in dicProxy) * { * Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value.States); * } */ proxy.dictFormCtrlButtons.Clear(); // this avoid user prompt proxy.Form.Close(); return(true); }
public static void StartServer() { string logfilepath, xmlfilepath, logfolder; using (XmlReader reader = new XmlTextReader("Server_config.xml")) { reader.MoveToContent(); port = Int32.Parse(reader.GetAttribute("port")); //read log settings logfolder = Environment.ExpandEnvironmentVariables(reader.GetAttribute("logfolder")); logfilepath = Path.Combine(logfolder, reader.GetAttribute("logfile")); //log file path xmlfilepath = Path.Combine(logfolder, reader.GetAttribute("xml_logfile")); //xml log file path log4net.GlobalContext.Properties["LogFileName"] = logfilepath; log4net.GlobalContext.Properties["XMLFileName"] = xmlfilepath; certfile = reader.GetAttribute("cert"); } serverCertificate = new X509Certificate2(certfile, ServerConfiguration.DEFAULT_PASSCODE, X509KeyStorageFlags.MachineKeySet); MsgUtil.StartLogger(); log.Info("port = " + port); log.InfoFormat("logfile: {0}", logfilepath); log.InfoFormat("xmlfile: {0}", xmlfilepath); SslStream sslStream = null; serverSocket = new TcpListener(IPAddress.Any, port); TcpClient clientSocket = default(TcpClient); int counter = 0; WindowsScraper.WindowsScraper scraper = null; #if !DEBUG Random rnd = new Random(); string passcode = rnd.Next(1, 999999).ToString(); #else string passcode = ServerConfiguration.DEFAULT_PASSCODE; #endif serverSocket.Start(); log.Info("Sinter Scrapper Started"); log.InfoFormat("Passcode = {0}", passcode); Console.WriteLine("\nLet the Sinter proxy client know this passcode : {0}", passcode); try { while (true) { counter += 1; clientSocket = serverSocket.AcceptTcpClient(); sslStream = ProcessClient(clientSocket); if (sslStream == null) { log.Info("Client No:" + counter + " rejected!"); clientSocket.Close(); } else { log.Info("Client No:" + counter + " connected!"); if (scraper == null) { scraper = new WindowsScraper.WindowsScraper(passcode); } else { scraper.execute_stop_scraping(); //restart scraper } ClientHandler client = new ClientHandler(scraper, clientSocket, "" + counter, sslStream); clients.Add(client); } } } catch (SocketException e) { log.Error("SocketException: {0}", e); } catch (ArgumentException e) { log.Error("ArgumentException: {0}", e); } }