You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2013/12/06 08:37:11 UTC

git commit: CB-802 WP8 ConsoleHelper outputs all console.log calls to isolated storage file for watching with CordovaDeploy tool

Updated Branches:
  refs/heads/master 910699644 -> 2171cd6a4


CB-802 WP8 ConsoleHelper outputs all console.log calls to isolated storage file for watching with CordovaDeploy tool


Project: http://git-wip-us.apache.org/repos/asf/cordova-wp8/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp8/commit/2171cd6a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp8/tree/2171cd6a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp8/diff/2171cd6a

Branch: refs/heads/master
Commit: 2171cd6a41c5d8fe4554e52e197552ed3a84ca94
Parents: 9106996
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Thu Dec 5 23:36:54 2013 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Thu Dec 5 23:36:54 2013 -0800

----------------------------------------------------------------------
 wp8/template/cordovalib/ConsoleHelper.cs | 47 +++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/2171cd6a/wp8/template/cordovalib/ConsoleHelper.cs
----------------------------------------------------------------------
diff --git a/wp8/template/cordovalib/ConsoleHelper.cs b/wp8/template/cordovalib/ConsoleHelper.cs
index c7bc8df..92cf0c9 100644
--- a/wp8/template/cordovalib/ConsoleHelper.cs
+++ b/wp8/template/cordovalib/ConsoleHelper.cs
@@ -1,7 +1,10 @@
 using Microsoft.Phone.Controls;
+using Microsoft.Phone.Shell;
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
+using System.IO;
+using System.IO.IsolatedStorage;
 using System.Linq;
 using System.Text;
 
@@ -12,8 +15,23 @@ namespace WPCordovaClassLib.CordovaLib
 
         public WebBrowser Browser { get; set; }
 
-        public void InjectScript() 
+        protected bool hasListener = false;
+
+
+
+        public void InjectScript()
         {
+            using(IsolatedStorageFileStream file = new IsolatedStorageFileStream("debugOutput.txt", FileMode.Create, FileAccess.Write, IsolatedStorageFile.GetUserStoreForApplication()))
+            {
+            }
+
+            if (!hasListener)
+            {
+                PhoneApplicationService.Current.Closing += OnServiceClosing;
+                hasListener = true;
+            }
+
+
             string script = @"(function(win) {
         function exec(msg) { window.external.Notify('ConsoleLog/' + msg); }
         var cons = win.console = win.console || {};
@@ -24,12 +42,35 @@ namespace WPCordovaClassLib.CordovaLib
         cons.error = cons.error || function(msg) { exec('ERROR:' + msg ); };
     })(window);";
 
-           Browser.InvokeScript("execScript", new string[] { script });
+            Browser.InvokeScript("execScript", new string[] { script });
+        }
+
+        void OnServiceClosing(object sender, ClosingEventArgs e)
+        {
+            using (IsolatedStorageFileStream file = new IsolatedStorageFileStream("debugOutput.txt", FileMode.Append, FileAccess.Write, IsolatedStorageFile.GetUserStoreForApplication()))
+            {
+                using (StreamWriter writeFile = new StreamWriter(file))
+                {
+                    writeFile.WriteLine("EXIT");
+                    writeFile.Close();
+                }
+                file.Close();
+            }
         }
 
         public bool HandleCommand(string commandStr)
         {
-            Debug.WriteLine(commandStr.Substring("ConsoleLog/".Length));
+            string output = commandStr.Substring("ConsoleLog/".Length);
+            Debug.WriteLine(output);
+            using (IsolatedStorageFileStream file = new IsolatedStorageFileStream("debugOutput.txt", FileMode.Append, FileAccess.Write, IsolatedStorageFile.GetUserStoreForApplication()))
+            {
+                using (StreamWriter writeFile = new StreamWriter(file))
+                {
+                    writeFile.WriteLine(output);
+                    writeFile.Close();
+                }
+                file.Close();
+            }
             return true;
         }