From 00f37935f50a97b573e5926bbcd2792cc6f2abf4 Mon Sep 17 00:00:00 2001
From: brewdente <brewdente@gmail.com>
Date: Wed, 6 May 2015 21:59:10 -0400
Subject: [PATCH] Adding comments to the sample Program.cs

---
 source/Sample/Program.cs | 35 +++++++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/source/Sample/Program.cs b/source/Sample/Program.cs
index 041d1af..9e4b2c3 100644
--- a/source/Sample/Program.cs
+++ b/source/Sample/Program.cs
@@ -17,28 +17,47 @@ namespace MasterDevs.ChromeDevTools.Sample
     {
         static void Main(string[] args)
         {
-
+            // STEP 1 - Run Chrome
             var chromeProcessFactory = new ChromeProcessFactory();
             using (var chromeProcess = chromeProcessFactory.Create(9222))
             {
+                // STEP 2 - Create a debugging session
                 var endpointUrl = chromeProcess.GetSessions().Result.LastOrDefault();
                 var chromeSessionFactory = new ChromeSessionFactory();
-
                 var chromeSession = chromeSessionFactory.Create(endpointUrl);
-                var pageEnableResult = chromeSession.SendAsync<ChromeDevTools.Protocol.Network.EnableCommand>().Result;
-                chromeSession.Subscribe<ChromeDevTools.Protocol.Network.ResponseReceivedEvent>((o, e) =>
+
+                // STEP 3 - Send a command
+                // 
+                // Here we are sending a command to tell chrome to navigate to
+                // the specified URL
+                var navigateResponse = chromeSession.SendAsync(new NavigateCommand
+                    {
+                        Url = "http://www.google.com"
+                    })
+                    .Result;
+                Console.WriteLine("NavigateResponse: " + navigateResponse.Id);
+
+                // STEP 4 - Register for events (in this case, "Page" domain events)
+                // send an event to tell chrome to send us all Page events
+                // but we only subscribe to certain events in this session
+                var pageEnableResult = chromeSession.SendAsync<ChromeDevTools.Protocol.Page.EnableCommand>().Result;
+                Console.WriteLine("PageEnable: " + pageEnableResult.Id);
+                chromeSession.Subscribe<Protocol.Page.DomContentEventFiredEvent>((o, e) =>
                     {
-                        Console.WriteLine("Response Received");
+                        var domContentEvent = (Event<DomContentEventFiredEvent>)e;
+                        Console.WriteLine("DomContentEvent: " + domContentEvent.Params.Timestamp);
                     });
-                chromeSession.SendAsync(new NavigateCommand
+                // you might never see this, but that's what an event is ... right?
+                chromeSession.Subscribe<Protocol.Page.FrameStartedLoadingEvent>((o, e) =>
                     {
-                        Url = "http://www.google.com"
+                        var frameStartedLoadingEvent = (Event<FrameStartedLoadingEvent>)e;
+                        Console.WriteLine("FrameStartedLoading: " + frameStartedLoadingEvent.Params.FrameId);
                     });
 
                 Console.ReadLine();
             }
 
         }
-        
+
     }
 }
-- 
GitLab