[banshee] [Networking] Add support for Windows network status (bgo#630296)



commit da0b982f683c0c0b1b80724604d3bd330caeeb77
Author: Pete Johanson <peter peterjohanson com>
Date:   Tue Sep 21 17:51:01 2010 -0400

    [Networking] Add support for Windows network status (bgo#630296)
    
    Signed-off-by: Gabriel Burt <gabriel burt gmail com>

 .../Banshee.Networking/DotNetNetworking.cs         |   66 ++++++++++++++++++++
 .../Banshee.Services/Banshee.Networking/Network.cs |    2 +
 .../Banshee.Networking/NetworkManager.cs           |    2 +-
 .../Banshee.Services/Banshee.Networking/Wicd.cs    |    2 +-
 src/Core/Banshee.Services/Banshee.Services.csproj  |    4 +-
 src/Core/Banshee.Services/Makefile.am              |    1 +
 6 files changed, 74 insertions(+), 3 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Networking/DotNetNetworking.cs b/src/Core/Banshee.Services/Banshee.Networking/DotNetNetworking.cs
new file mode 100644
index 0000000..fd7c4fc
--- /dev/null
+++ b/src/Core/Banshee.Services/Banshee.Networking/DotNetNetworking.cs
@@ -0,0 +1,66 @@
+//
+// DotNetNetworking.cs
+//
+// Author:
+//   Pete Johanson <peter peterjohanson com>
+//
+// Copyright 2010 Pete Johanson
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.NetworkInformation;
+using System.Text;
+
+namespace Banshee.Networking
+{
+    public class DotNetNetworking : INetworkAvailabilityService
+    {
+        public static bool ManagerPresent { get { try { return Type.GetType ("Mono.Runtime") == null; } catch { return true; } } }
+
+        #region INetworkAvailabilityService Members
+
+        public State State {
+            get { return NetworkInterface.GetIsNetworkAvailable () ? State.Connected : State.Disconnected; }
+        }
+
+        public event StateChangeHandler StateChange;
+
+        #endregion
+
+        public DotNetNetworking ()
+        {
+            if (!ManagerPresent) {
+                throw new ApplicationException (".NET network detection is only supported on Windows.");
+            }
+
+            NetworkChange.NetworkAvailabilityChanged += OnNetworkAvailabilityChanged;
+        }
+
+        void OnNetworkAvailabilityChanged (object o, NetworkAvailabilityEventArgs args)
+        {
+            var handler = StateChange;
+            if (handler != null) {
+                handler (args.IsAvailable ? State.Connected : State.Disconnected);
+            }
+        }
+    }
+}
diff --git a/src/Core/Banshee.Services/Banshee.Networking/Network.cs b/src/Core/Banshee.Services/Banshee.Networking/Network.cs
index 9f8d073..40b5b96 100644
--- a/src/Core/Banshee.Services/Banshee.Networking/Network.cs
+++ b/src/Core/Banshee.Services/Banshee.Networking/Network.cs
@@ -92,6 +92,8 @@ namespace Banshee.Networking
                 manager = new NetworkManager ();
             } else if (Wicd.ManagerPresent) {
                 manager = new Wicd ();
+            } else if (DotNetNetworking.ManagerPresent) {
+                manager = new DotNetNetworking ();
             } else {
                 throw new NetworkUnavailableException ("Neither NetworkManager nor Wicd could be found");
             }
diff --git a/src/Core/Banshee.Services/Banshee.Networking/NetworkManager.cs b/src/Core/Banshee.Services/Banshee.Networking/NetworkManager.cs
index ddeed94..22ddbf9 100644
--- a/src/Core/Banshee.Services/Banshee.Networking/NetworkManager.cs
+++ b/src/Core/Banshee.Services/Banshee.Networking/NetworkManager.cs
@@ -73,7 +73,7 @@ namespace Banshee.Networking
         }
 
         public static bool ManagerPresent {
-            get { return Bus.System.NameHasOwner (BusName); }
+            get { try { return Bus.System.NameHasOwner (BusName); } catch { return false; } }
         }
     }
 }
diff --git a/src/Core/Banshee.Services/Banshee.Networking/Wicd.cs b/src/Core/Banshee.Services/Banshee.Networking/Wicd.cs
index 723e272..e38d436 100644
--- a/src/Core/Banshee.Services/Banshee.Networking/Wicd.cs
+++ b/src/Core/Banshee.Services/Banshee.Networking/Wicd.cs
@@ -89,7 +89,7 @@ namespace Banshee.Networking
         }
 
         public static bool ManagerPresent {
-            get { return Bus.System.NameHasOwner (BusName); }
+            get { try { return Bus.System.NameHasOwner (BusName); } catch { return false; } }
         }
 
         private State GetTranslatedCode (uint wicdCode)
diff --git a/src/Core/Banshee.Services/Banshee.Services.csproj b/src/Core/Banshee.Services/Banshee.Services.csproj
index 9e791e0..821ca80 100644
--- a/src/Core/Banshee.Services/Banshee.Services.csproj
+++ b/src/Core/Banshee.Services/Banshee.Services.csproj
@@ -3,7 +3,7 @@
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProductVersion>8.0.50727</ProductVersion>
+    <ProductVersion>9.0.21022</ProductVersion>
     <ProjectGuid>{B28354F0-BA87-44E8-989F-B864A3C7C09F}</ProjectGuid>
     <OutputType>Library</OutputType>
     <UseParentDirectoryAsNamespace>true</UseParentDirectoryAsNamespace>
@@ -117,6 +117,7 @@
     <Compile Include="Banshee.Collection.Database\RandomByAlbum.cs" />
     <Compile Include="Banshee.Collection.Database\RandomByTrack.cs" />
     <Compile Include="Banshee.Collection.Database\RandomByRating.cs" />
+    <Compile Include="Banshee.Networking\DotNetNetworking.cs" />
     <Compile Include="Banshee.Sources\Source.cs" />
     <Compile Include="Banshee.Sources\SourceManager.cs" />
     <Compile Include="Banshee.Sources\DatabaseSource.cs" />
@@ -350,5 +351,6 @@
         </MonoDevelop.Autotools.MakefileInfo>
       </Properties>
     </MonoDevelop>
+    <VisualStudio />
   </ProjectExtensions>
 </Project>
diff --git a/src/Core/Banshee.Services/Makefile.am b/src/Core/Banshee.Services/Makefile.am
index ba26ebb..66008f5 100644
--- a/src/Core/Banshee.Services/Makefile.am
+++ b/src/Core/Banshee.Services/Makefile.am
@@ -129,6 +129,7 @@ SOURCES =  \
 	Banshee.Metadata/Tests/TaglibReadWriteTests.cs \
 	Banshee.Metrics/BansheeMetrics.cs \
 	Banshee.Metrics/Configuration.cs \
+	Banshee.Networking/DotNetNetworking.cs \
 	Banshee.Networking/INetworkAvailabilityService.cs \
 	Banshee.Networking/Network.cs \
 	Banshee.Networking/NetworkManager.cs \



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]