Skip to content

Commit

Permalink
Handle exceptions. GetProperties() and GetConfiguration() can throw e…
Browse files Browse the repository at this point in the history
…xceptions

on some tunnel interfaces.  Ignore the exceptions, as sharing them doesn't make sense anyways.
  • Loading branch information
karlhiramoto committed Feb 7, 2014
1 parent 627393d commit e21f16b
Showing 1 changed file with 39 additions and 17 deletions.
56 changes: 39 additions & 17 deletions IcsManagerLibrary/IcsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,28 @@ where nic.Supports(NetworkInterfaceComponent.IPv4)

public static NetShare GetCurrentlySharedConnections()
{
INetConnection sharedConnection = (
from INetConnection c in SharingManager.EnumEveryConnection
where GetConfiguration(c).SharingEnabled
where GetConfiguration(c).SharingConnectionType ==
tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PUBLIC
select c).DefaultIfEmpty(null).First();
INetConnection homeConnection = (
from INetConnection c in SharingManager.EnumEveryConnection
where GetConfiguration(c).SharingEnabled
where GetConfiguration(c).SharingConnectionType ==
tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PRIVATE
select c).DefaultIfEmpty(null).First();
INetConnection sharedConnection = null;
INetConnection homeConnection = null;
INetSharingEveryConnectionCollection connections = SharingManager.EnumEveryConnection;
foreach (INetConnection c in connections)
{
try
{

INetSharingConfiguration config = GetConfiguration(c);
if (config.SharingEnabled)
{
if (config.SharingConnectionType == tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PUBLIC)
sharedConnection = c;
else if (config.SharingConnectionType == tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PRIVATE)
homeConnection = c;
}
}
catch (System.Runtime.InteropServices.ExternalException)
{
}
}

return new NetShare(sharedConnection, homeConnection);
}

Expand Down Expand Up @@ -91,8 +101,8 @@ public static INetConnection GetConnectionById(string guid)
if (props.Guid == guid)
return c;
}
catch
{
catch (System.Runtime.InteropServices.ExternalException)
{
// Ignore these It'ts known that Tunnel adapter isatap causes getProperties to fail.
}
}
Expand All @@ -101,9 +111,21 @@ public static INetConnection GetConnectionById(string guid)

public static INetConnection GetConnectionByName(string name)
{
return (from INetConnection c in GetAllConnections()
where GetProperties(c).Name == name
select c).DefaultIfEmpty(null).First();
INetSharingEveryConnectionCollection connections = GetAllConnections();
foreach (INetConnection c in connections)
{
try
{
INetConnectionProps props = GetProperties(c);
if (props.Name == name)
return c;
}
catch (System.Runtime.InteropServices.ExternalException)
{
// Ignore these It'ts known that Tunnel adapter isatap causes getProperties to fail.
}
}
return null;
}

}
Expand Down

0 comments on commit e21f16b

Please sign in to comment.