removed calls to resolve DNS because they take 30 seconds when no network is 
available and prevent deviceready


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/commit/817124ce
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/tree/817124ce
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/diff/817124ce

Branch: refs/heads/master
Commit: 817124ceb556d565e8ef6fd46d4ff18aa4fd36dc
Parents: e87a258
Author: Jesse MacFadyen <purplecabb...@gmail.com>
Authored: Thu May 24 12:14:21 2012 -0700
Committer: Jesse MacFadyen <purplecabb...@gmail.com>
Committed: Thu May 24 12:14:21 2012 -0700

----------------------------------------------------------------------
 framework/Cordova/Commands/NetworkStatus.cs |   53 +++++++++------------
 1 files changed, 23 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/817124ce/framework/Cordova/Commands/NetworkStatus.cs
----------------------------------------------------------------------
diff --git a/framework/Cordova/Commands/NetworkStatus.cs 
b/framework/Cordova/Commands/NetworkStatus.cs
index 851e227..ba56724 100644
--- a/framework/Cordova/Commands/NetworkStatus.cs
+++ b/framework/Cordova/Commands/NetworkStatus.cs
@@ -43,43 +43,33 @@ namespace WP7CordovaClassLib.Cordova.Commands
         const string NONE = "none";
         const string CELL = "cellular";
 
+        private bool HasCallback = false;
 
         public NetworkStatus()
-            : base()
         {
-
             DeviceNetworkInformation.NetworkAvailabilityChanged += new 
EventHandler<NetworkNotificationEventArgs>(ChangeDetected);
         }
 
         public void getConnectionInfo(string empty)
         {
-            // Use the GetIsNetworkAvailable method to quickly determine if we 
have a connection or not
-            // Otherwise, resolving a DNS name with no connection takes a 
while.
-            if 
(System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
-            {
-                // We have to try to resolve a host name to get the specific 
subtype of network available.
-                // Kind of a shitty API here MSFT
-                DeviceNetworkInformation.ResolveHostNameAsync(
-                    new DnsEndPoint("microsoft.com", 80),
-                    new NameResolutionCallback(nrr =>
-                        {
-                            if (nrr.NetworkErrorCode == NetworkError.Success)
-                            {
-                                
updateConnectionType(checkConnectionType(nrr.NetworkInterface.InterfaceSubtype));
-                            }
-                            else
-                            {
-                                updateConnectionType(NONE);
-                            }
-                        }
-                    ),
-                    null
-                );
-            }
-            else
+            HasCallback = true;
+            updateConnectionType(checkConnectionType());
+        }
+
+        private string checkConnectionType()
+        {
+            if (DeviceNetworkInformation.IsNetworkAvailable)
             {
-                updateConnectionType(NONE);
+                if (DeviceNetworkInformation.IsWiFiEnabled)
+                {
+                    return WIFI;
+                }
+                else
+                {
+                    return DeviceNetworkInformation.IsCellularDataEnabled ? 
CELL : UNKNOWN;
+                }
             }
+            return NONE;
         }
 
         private string checkConnectionType(NetworkInterfaceSubType type)
@@ -123,9 +113,12 @@ namespace WP7CordovaClassLib.Cordova.Commands
         private void updateConnectionType(string type)
         {
             // This should also implicitly fire offline/online events as that 
is handled on the JS side
-            PluginResult result = new PluginResult(PluginResult.Status.OK, 
type);
-            result.KeepCallback = true;
-            DispatchCommandResult(result);
+            if (this.HasCallback)
+            {
+                PluginResult result = new PluginResult(PluginResult.Status.OK, 
type);
+                result.KeepCallback = true;
+                DispatchCommandResult(result);
+            }
         }
     }
 }

Reply via email to