This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DbProviderFactoryRepository | |
{ | |
/// <summary> | |
/// The table containing all the data. | |
/// </summary> | |
private DataTable dbProviderFactoryTable; | |
/// <summary> | |
/// Name of the configuration element. | |
/// </summary> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize the repository. | |
var repository = new DbProviderFactoryRepository(); | |
// Create a description manually and add it to the repository. | |
var manualDescription = new DbProviderFactoryDescription(); | |
manualDescription.Description = ".NET Framework Data Provider for Microsoft SQL Server Compact"; | |
manualDescription.Invariant = "System.Data.SqlServerCe.3.5"; | |
manualDescription.Name = "Microsoft SQL Server Compact Data Provider"; | |
manualDescription.Type = "System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe"; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Create the firewall manager object. | |
Dim fwMgr | |
Set fwMgr = CreateObject("HNetCfg.FwMgr") | |
' Get the current profile for the local firewall policy. | |
Dim profile | |
Set profile = fwMgr.LocalPolicy.CurrentProfile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HRESULT hr = S_OK; | |
INetFwMgr* fwMgr = NULL; | |
INetFwPolicy* fwPolicy = NULL; | |
_ASSERT(fwProfile != NULL); | |
*fwProfile = NULL; | |
// Create an instance of the firewall settings manager. | |
hr = CoCreateInstance( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ComImport, ComVisible(false), Guid("F7898AF5-CAC4-4632-A2EC-DA06E5111AF2"), System.Runtime.InteropServices.InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] | |
public interface INetFwMgr | |
{ | |
INetFwPolicy LocalPolicy { get; } | |
FirewallProfileType CurrentProfileType { get; } | |
void RestoreDefaults(); | |
void IsPortAllowed(string imageFileName, IPVersion ipVersion, long portNumber, string localAddress, IPProtocol ipProtocol, [Out] out bool allowed, [Out] out bool restricted); | |
void IsIcmpTypeAllowed(IPVersion ipVersion, string localAddress, byte type, [Out] out bool allowed, [Out] out bool restricted); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Type fwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr"); | |
dynamic fwMgr = Activator.CreateInstance(fwMgrType); | |
bool isFwEnabled = fwMgr.LocalPolicy.CurrentProfile.FirewallEnabled; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Msdn reference: http://msdn.microsoft.com/en-us/library/aa366282(v=VS.85).aspx | |
/// </summary> | |
public enum NetFwAction | |
{ | |
Block = 0, | |
Allow = 1, | |
Max = 2 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Msdn reference: http://msdn.microsoft.com/en-us/library/aa365100(v=VS.85).aspx | |
/// </summary> | |
public class NetFwAuthorizedApplication | |
{ | |
... | |
/// <summary> | |
/// Initialize the application object. | |
/// </summary> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DynamicComMapper | |
{ | |
/// <summary> | |
/// Map all the properties of the object to the properties of the COM object. | |
/// </summary> | |
/// <param name="comObj"></param> | |
protected void Map(dynamic comObj) | |
{ | |
foreach (PropertyInfo property in this.GetType().GetProperties()) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Release a COM object so that it can be cleaned up. | |
/// </summary> | |
/// <param name="comObj"></param> | |
protected void ReleaseCom(dynamic comObj) | |
{ | |
Marshal.ReleaseComObject(comObj); | |
} | |