private IDictionary <string, BrowserContextManager> CreateManagers()
        {
            var managers = new Dictionary <string, BrowserContextManager>();

            if (File.Exists(Path.Combine(AppContext.BaseDirectory, "state.tmp")))
            {
                using (var fileStream = File.Open(Path.Combine(AppContext.BaseDirectory, "state.tmp"), FileMode.Open))
                {
                    var states = ProtoSerialize.Deserialize <IDictionary <string, PageState> >(fileStream);
                    foreach (var state in states)
                    {
                        var browserContextManager = new BrowserContextManager(browser, state.Value);
                        managers.Add(state.Key, browserContextManager);
                    }
                }
            }
            return(managers);
        }
예제 #2
0
        static void Main(string[] args)
        {
            using (var manager = new HeadlessBrowserManager())
            {
                BrowserContextManager contextManager = null;
                if (!manager.TryGetManager(TOKEN, out contextManager))
                {
                    contextManager = manager.CreateManager(TOKEN);
                }

                contextManager.Screenshot(Path.Combine(AppContext.BaseDirectory, "before login.png"));
                contextManager.Logon();
                Thread.Sleep(1000);
                contextManager.Screenshot(Path.Combine(AppContext.BaseDirectory, "after login.png"));
                //contextManager.Logoff();
                //Thread.Sleep(1000);
                contextManager.Screenshot(Path.Combine(AppContext.BaseDirectory, "after logout.png"));
                Console.ReadKey();
            }
        }
 public bool TryGetManager(string token, out BrowserContextManager browserContextManager)
 => managers.TryGetValue(token, out browserContextManager);