private Dictionary <string, object> GetAvailableSessions(List <string> coins)
        {
            List <RemoteSession> sessions      = Chrome.GetAvailableSessions("http://localhost:9222"); // connected sessions
            List <RemoteSession> upbitSessions = new List <RemoteSession>();                           // upbit pages
            List <RemoteSession> rawSessions   = new List <RemoteSession>();                           // specified pages in config
            //string chromeStartUrl = Properties.Settings.Default.ChromeStartUrl;//
            string chromeStartUrl = "a";                                                               //
            string upbitUrl       = "upbit.com/exchange";

            foreach (RemoteSession session in sessions)
            {
                string url = session.url;

                if (url.IndexOf(upbitUrl) != -1)
                {
                    upbitSessions.Add(session);
                }

                else if (url.IndexOf(chromeStartUrl) != -1)
                {
                    rawSessions.Add(session);
                }
            }

            Dictionary <string, object> availableSessions = new Dictionary <string, object>();

            availableSessions["upbit"] = upbitSessions;
            availableSessions["raw"]   = rawSessions;
            availableSessions["count"] = upbitSessions.Count + rawSessions.Count;

            return(availableSessions);
        }
示例#2
0
        static void Main(string[] args)
        {
            var chrome = new Chrome("http://localhost:9222");

            var sessions = chrome.GetAvailableSessions();

            Console.WriteLine("Available debugging sessions");
            foreach (var s in sessions)
            {
                Console.WriteLine(s.url);
            }

            if (sessions.Count == 0)
            {
                throw new Exception("All debugging sessions are taken.");
            }

            // Will drive first tab session
            var sessionWSEndpoint =
                sessions[0].webSocketDebuggerUrl;

            chrome.SetActiveSession(sessionWSEndpoint);

            chrome.NavigateTo("http://www.google.com");

            var result = chrome.Eval("document.getElementById('lst-ib').value='Hello World'");

            result = chrome.Eval("document.forms[0].submit()");

            Console.ReadLine();
        }
示例#3
0
        private void AttachThread()
        {
            // 리모트 주소 리스트
            string[] remoteAddresses = Properties.Settings.Default.RemoteAddresses.Split(',');

            List <string> keys = new List <string>();

            foreach (KeyValuePair <string, Chrome> browser in this.Browsers)
            {
                keys.Add(browser.Key);
            }


            foreach (string key in keys)
            {
                string   pair         = key;
                string[] pairUriArray = key.Split('/');
                string   pairUri      = String.Format("{1}-{0}", pairUriArray[0], pairUriArray[1]);

                // 순서대로 리모트에 접속해서 접속할 페이지가 있나 찾고 있으면 연결
                bool found = false;
                foreach (string remoteDebuggingUrl in remoteAddresses)
                {
                    if (!found)
                    {
                        List <RemoteSession> sessions = Chrome.GetAvailableSessions(remoteDebuggingUrl);
                        foreach (RemoteSession session in sessions)
                        {
                            if (!found)
                            {
                                if (session.url.IndexOf(pairUri) != -1) // Found
                                {
                                    this.Browsers[pair] = new Chrome();
                                    found = true;

                                    if (session.url.IndexOf("upbit.com/exchange") != -1) // just connect
                                    {
                                        StartConnectSession(this.Browsers[pair], session.webSocketDebuggerUrl);
                                    }
                                    else /// connect and go to page
                                    {
                                        StartConnectSessionAndGotoPage(this.Browsers[pair], session.webSocketDebuggerUrl, pairUri);
                                        Thread.Sleep(7000);
                                    }
                                }
                            }
                        }
                    }
                }

                if (!found)
                {
                    throw new Exception(String.Format("Couldn't found a browser with {0} in url.", pairUri));
                }
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            //chrome.exe --remote-debugging-port=9222 --user-data-dir=C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data
            //chrome.exe --remote-debugging-port=9222 --user-data-dir=C:\myChromeUser

            var chrome = new Chrome("http://localhost:9222");

            var sessions = chrome.GetAvailableSessions();

            Console.WriteLine("Available debugging sessions");
            foreach (var s in sessions)
            {
                Console.WriteLine(s.url);
            }

            if (sessions.Count == 0)
            {
                throw new Exception("All debugging sessions are taken.");
            }

            var sessionWSEndpoint = sessions[0].webSocketDebuggerUrl;

            chrome.SetActiveSession(sessionWSEndpoint);

            //var result = chrome.Eval("alert(window.getSelection().toString())");
            var result = chrome.Eval("window.getSelection().toString()");

            //var result = chrome.Eval("window.getSelection()");
            Console.WriteLine(result);

            //////// Will drive first tab session
            //////var sessionWSEndpoint = sessions[0].webSocketDebuggerUrl;

            //////chrome.SetActiveSession(sessionWSEndpoint);

            //////chrome.NavigateTo("http://www.google.com");

            //////var result = chrome.Eval("document.getElementById('lst-ib').value='Hello World'");

            //////result = chrome.Eval("document.forms[0].submit()");

            Console.ReadLine();
        }