diff --git a/WindowsAdvancedFirewallApi/ApiConstants.cs b/WindowsAdvancedFirewallApi/ApiConstants.cs index f34659b..490cf99 100644 --- a/WindowsAdvancedFirewallApi/ApiConstants.cs +++ b/WindowsAdvancedFirewallApi/ApiConstants.cs @@ -15,17 +15,5 @@ internal class ApiConstants public const string REGISTRY_KEY_EVENTLOG = @"SYSTEM\CurrentControlSet\Services\EventLog\"; public const string REGISTRY_KEY_FIREWALL_LOG = REGISTRY_KEY_EVENTLOG + FIREWALL_EVENT_PROTOCOL; - - internal enum EventID - { - FIREWALL_SETTING_GENERAL = WFEvents.WFGlobalConfigurationChangedEvent, - FIREWALL_SETTING_PROFILE = WFEvents.WFProfileConfigurationChangedEvent, - - FIREWALL_RULE_ADDED = WFEvents.WFRuleAddEvent, - FIREWALL_RULE_MODIFIED = WFEvents.WFRuleChangeEvent, - FIREWALL_RULE_DELETED = WFEvents.WFRuleDeleteEvent, - - FIREWALL_NETWORKINTERFACE_CHANGED = WFEvents.WFInterfaceProfileChangedEvent - } } } diff --git a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallBaseEventArgs.cs b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallBaseEventArgs.cs index 1e317b3..371c45e 100644 --- a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallBaseEventArgs.cs +++ b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallBaseEventArgs.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using WindowsAdvancedFirewallApi.Events.Objects; namespace WindowsAdvancedFirewallApi.Events.Arguments { @@ -13,6 +14,7 @@ public abstract class FirewallBaseEventArgs : EventArgs protected static Logger LOG = LogManager.GetCurrentClassLogger(); protected EventLogEntry FirewallLogEvent { get; set; } + public long LogId { get; protected set; } public long EventId { get; protected set; } public DateTime ModifyingTime { get; protected set; } @@ -26,8 +28,20 @@ internal FirewallBaseEventArgs(EventLogEntry eventArgs) } FirewallLogEvent = eventArgs; + LogId = FirewallLogEvent.Index; EventId = FirewallLogEvent.InstanceId; ModifyingTime = FirewallLogEvent.TimeGenerated; } } + + public abstract class FirewallBaseEventArgs : FirewallBaseEventArgs + where TData : FirewallBaseObject, new() + { + protected TData Data { get; set; } + + internal FirewallBaseEventArgs(EventLogEntry @event) : base(@event) + { + Data = new TData(); + } + } } diff --git a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallDataEventArgs.cs b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallDataEventArgs.cs deleted file mode 100644 index 09c413a..0000000 --- a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallDataEventArgs.cs +++ /dev/null @@ -1,23 +0,0 @@ -using NLog; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using WindowsAdvancedFirewallApi.Events.Objects; -using WindowsAdvancedFirewallApi.Utils; - -namespace WindowsAdvancedFirewallApi.Events.Arguments -{ - public abstract class FirewallDataEventArgs : FirewallBaseEventArgs - where TData : FirewallBaseObject, new() - { - protected TData Data { get; set; } - - internal FirewallDataEventArgs(EventLogEntry @event) : base (@event) - { - Data = new TData(); - } - } -} diff --git a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallEventArgs.cs b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallEventArgs.cs index f844327..f49258c 100644 --- a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallEventArgs.cs +++ b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallEventArgs.cs @@ -10,23 +10,19 @@ namespace WindowsAdvancedFirewallApi.Events.Arguments { - public abstract class FirewallEventArgs : FirewallDataEventArgs where TData : FirewallBaseObject, new() + public abstract class FirewallEventArgs : FirewallBaseEventArgs where TData : FirewallBaseObject, new() { - public int Origin { get; protected set; } public string ModifyingUser { get; protected set; } - public string ModifyingApplication { get; protected set; } internal FirewallEventArgs(EventLogEntry @event) : base(@event) { } - protected void SetAttributes(int iOrigin, int iModifiyingUser, int iModifyingApplication) + protected void SetAttributes(int iModifiyingUser) { LOG.Debug("ReplacementStrings: {0}", string.Join(",", FirewallLogEvent.ReplacementStrings)); - Origin = PrimitiveUtils.ParseInteger(FirewallLogEvent.ReplacementStrings[iOrigin], 0); ModifyingUser = FirewallLogEvent.ReplacementStrings[iModifiyingUser]; - ModifyingApplication = FirewallLogEvent.ReplacementStrings[iModifyingApplication]; } } } diff --git a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallExtendedApplicationEventArgs.cs b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallExtendedApplicationEventArgs.cs new file mode 100644 index 0000000..0a54b20 --- /dev/null +++ b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallExtendedApplicationEventArgs.cs @@ -0,0 +1,28 @@ +using NLog; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WindowsAdvancedFirewallApi.Events.Objects; +using WindowsAdvancedFirewallApi.Utils; + +namespace WindowsAdvancedFirewallApi.Events.Arguments +{ + public abstract class FirewallExtendedApplicationEventArgs : FirewallEventArgs where TData : FirewallBaseObject, new() + { + public string ModifyingApplication { get; protected set; } + + internal FirewallExtendedApplicationEventArgs(EventLogEntry @event) : base(@event) + { + } + + protected void SetAttributes(int iModifiyingUser, int iModifyingApplication) + { + SetAttributes(iModifiyingUser); + + ModifyingApplication = FirewallLogEvent.ReplacementStrings[iModifyingApplication]; + } + } +} diff --git a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallExtendedOriginEventArgs.cs b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallExtendedOriginEventArgs.cs new file mode 100644 index 0000000..fa5409d --- /dev/null +++ b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallExtendedOriginEventArgs.cs @@ -0,0 +1,28 @@ +using NLog; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WindowsAdvancedFirewallApi.Events.Objects; +using WindowsAdvancedFirewallApi.Utils; + +namespace WindowsAdvancedFirewallApi.Events.Arguments +{ + public abstract class FirewallExtendedOriginEventArgs : FirewallExtendedApplicationEventArgs where TData : FirewallBaseObject, new() + { + public int Origin { get; protected set; } + + internal FirewallExtendedOriginEventArgs(EventLogEntry @event) : base(@event) + { + } + + protected void SetAttributes(int iOrigin, int iModifiyingUser, int iModifyingApplication) + { + SetAttributes(iModifiyingUser, iModifyingApplication); + + Origin = PrimitiveUtils.ParseInteger(FirewallLogEvent.ReplacementStrings[iOrigin], 0); + } + } +} diff --git a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallHistoryLoadingStatusChangedEventArgs.cs b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallHistoryLoadingStatusChangedEventArgs.cs new file mode 100644 index 0000000..2bc6c33 --- /dev/null +++ b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallHistoryLoadingStatusChangedEventArgs.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WindowsAdvancedFirewallApi.Events.Arguments +{ + public class FirewallHistoryLoadingStatusChangedEventArgs + { + public int LoadedCount { get; internal set; } + public int MaxCount { get; internal set; } + public FirewallBaseEventArgs CurrentLoadedEvent { get; internal set; } + } +} diff --git a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallNetworkInterfaceProfileChanged.cs b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallNetworkInterfaceProfileChangedEventArgs.cs similarity index 81% rename from WindowsAdvancedFirewallApi/Events/Arguments/FirewallNetworkInterfaceProfileChanged.cs rename to WindowsAdvancedFirewallApi/Events/Arguments/FirewallNetworkInterfaceProfileChangedEventArgs.cs index 7b8bfbd..7431e91 100644 --- a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallNetworkInterfaceProfileChanged.cs +++ b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallNetworkInterfaceProfileChangedEventArgs.cs @@ -9,7 +9,7 @@ namespace WindowsAdvancedFirewallApi.Events.Arguments { - public class FirewallNetworkInterfaceProfileChanged : FirewallDataEventArgs + public class FirewallNetworkInterfaceProfileChangedEventArgs : FirewallBaseEventArgs { public FirewallNetworkInterfaceProfile NetworkInterface { @@ -17,7 +17,7 @@ public FirewallNetworkInterfaceProfile NetworkInterface protected set { Data = value; } } - public FirewallNetworkInterfaceProfileChanged(EventLogEntry @event) : base(@event) + public FirewallNetworkInterfaceProfileChangedEventArgs(EventLogEntry @event) : base(@event) { SetAttributes(); } diff --git a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallProfileSettingEventArgs.cs b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallProfileSettingEventArgs.cs index 50bbe25..b3e318c 100644 --- a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallProfileSettingEventArgs.cs +++ b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallProfileSettingEventArgs.cs @@ -10,17 +10,17 @@ namespace WindowsAdvancedFirewallApi.Events.Arguments { - public class FirewallProfileSettingEventArgs : FirewallSettingEventArgs + public class FirewallProfileSettingEventArgs : FirewallSettingEventArgs { internal FirewallProfileSettingEventArgs(EventLogEntry @event) : base(@event) { SetAttributes(); } - protected new void SetAttributes() + protected void SetAttributes() { SetAttributes(5, 6, 7); - SetSettingAttributes(1, 2, 3, 4); + SetSettingAttributes(1, 3, 2, 4); Setting.Profiles = EnumUtils.ParseStringValue(FirewallLogEvent.ReplacementStrings[0], FirewallBaseObject.Profile.Unkown); } diff --git a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallRuleAddedEventArgs.cs b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallRuleAddedEventArgs.cs index 1ea2712..46fb117 100644 --- a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallRuleAddedEventArgs.cs +++ b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallRuleAddedEventArgs.cs @@ -18,38 +18,29 @@ public FirewallRuleAddedEventArgs(EventLogEntry @event) : base(@event) protected void SetAttributes() { SetAttributes(2, 21, 22); + SetRuleAttributes(0, 1); - try - { - Rule.Id = FirewallLogEvent.ReplacementStrings[0]; - Rule.Name = FirewallLogEvent.ReplacementStrings[1]; - Rule.ApplicationPath = FirewallLogEvent.ReplacementStrings[3]; - Rule.ServiceName = FirewallLogEvent.ReplacementStrings[4]; - Rule.Direction = int.Parse(FirewallLogEvent.ReplacementStrings[5]); - Rule.Protocol = int.Parse(FirewallLogEvent.ReplacementStrings[6]); - Rule.LocalPorts = FirewallLogEvent.ReplacementStrings[7]; - Rule.RemotePorts = FirewallLogEvent.ReplacementStrings[8]; - Rule.Action = FirewallLogEvent.ReplacementStrings[9]; - Rule.Profiles = EnumUtils.ParseStringValue(FirewallLogEvent.ReplacementStrings[10], FirewallBaseObject.Profile.Unkown); - Rule.LocalAddresses = FirewallLogEvent.ReplacementStrings[11]; - Rule.RemoteAddresses = FirewallLogEvent.ReplacementStrings[12]; - Rule.RemoteMachineAuthorizationList = FirewallLogEvent.ReplacementStrings[13]; - Rule.RemoteUserAuthorizationList = FirewallLogEvent.ReplacementStrings[14]; - Rule.EmbeddedContext = FirewallLogEvent.ReplacementStrings[15]; - Rule.Flags = int.Parse(FirewallLogEvent.ReplacementStrings[16]); - Rule.Active = Convert.ToBoolean(int.Parse(FirewallLogEvent.ReplacementStrings[17])); - Rule.EdgeTraversal = int.Parse(FirewallLogEvent.ReplacementStrings[18]); - Rule.LooseSourceMapped = int.Parse(FirewallLogEvent.ReplacementStrings[19]); - Rule.SecurityOptions = int.Parse(FirewallLogEvent.ReplacementStrings[20]); - Rule.SchemaVersion = int.Parse(FirewallLogEvent.ReplacementStrings[23]); - Rule.Status = long.Parse(FirewallLogEvent.ReplacementStrings[24]); - Rule.LocalOnlyMapped = int.Parse(FirewallLogEvent.ReplacementStrings[25]); - } - catch (Exception ex) when (ex is ArgumentNullException || ex is FormatException || ex is OverflowException) - { - LOG.Info(string.Format("Primitive parse error: {0}", string.Join(",", FirewallLogEvent.ReplacementStrings))); - LOG.Debug(ex); - } + Rule.ApplicationPath = FirewallLogEvent.ReplacementStrings[3]; + Rule.ServiceName = FirewallLogEvent.ReplacementStrings[4]; + Rule.Direction = FirewallLogEvent.ReplacementStrings[5].ParseInteger(0); + Rule.Protocol = FirewallLogEvent.ReplacementStrings[6].ParseInteger(); + Rule.LocalPorts = FirewallLogEvent.ReplacementStrings[7]; + Rule.RemotePorts = FirewallLogEvent.ReplacementStrings[8]; + Rule.Action = FirewallLogEvent.ReplacementStrings[9]; + Rule.Profiles = EnumUtils.ParseStringValue(FirewallLogEvent.ReplacementStrings[10], FirewallBaseObject.Profile.Unkown); + Rule.LocalAddresses = FirewallLogEvent.ReplacementStrings[11]; + Rule.RemoteAddresses = FirewallLogEvent.ReplacementStrings[12]; + Rule.RemoteMachineAuthorizationList = FirewallLogEvent.ReplacementStrings[13]; + Rule.RemoteUserAuthorizationList = FirewallLogEvent.ReplacementStrings[14]; + Rule.EmbeddedContext = FirewallLogEvent.ReplacementStrings[15]; + Rule.Flags = FirewallLogEvent.ReplacementStrings[16].ParseInteger(); + Rule.Active = Convert.ToBoolean(FirewallLogEvent.ReplacementStrings[17].ParseInteger(0)); + Rule.EdgeTraversal = FirewallLogEvent.ReplacementStrings[18].ParseInteger(0); + Rule.LooseSourceMapped = FirewallLogEvent.ReplacementStrings[19].ParseInteger(0); + Rule.SecurityOptions = FirewallLogEvent.ReplacementStrings[20].ParseInteger(0); + Rule.SchemaVersion = FirewallLogEvent.ReplacementStrings[23].ParseInteger(0); + Rule.Status = FirewallLogEvent.ReplacementStrings[24].ParseLong(0); + Rule.LocalOnlyMapped = FirewallLogEvent.ReplacementStrings[25].ParseInteger(0); } } } diff --git a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallRuleBaseEventArgs.cs b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallRuleBaseEventArgs.cs index 26c0991..3cd9321 100644 --- a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallRuleBaseEventArgs.cs +++ b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallRuleBaseEventArgs.cs @@ -9,7 +9,7 @@ namespace WindowsAdvancedFirewallApi.Events.Arguments { - public abstract class FirewallRuleBaseEventArgs : FirewallEventArgs + public abstract class FirewallRuleBaseEventArgs : FirewallExtendedOriginEventArgs { public FirewallRule Rule { @@ -20,5 +20,11 @@ public FirewallRule Rule internal FirewallRuleBaseEventArgs(EventLogEntry @event) : base(@event) { } + + protected void SetRuleAttributes(int iRuleId, int iRuleName) + { + Rule.Id = FirewallLogEvent.ReplacementStrings[iRuleId]; + Rule.Name = FirewallLogEvent.ReplacementStrings[iRuleName]; + } } } diff --git a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallRuleDeletedEventArgs.cs b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallRuleDeletedEventArgs.cs index 4edc3a1..49af995 100644 --- a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallRuleDeletedEventArgs.cs +++ b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallRuleDeletedEventArgs.cs @@ -11,7 +11,13 @@ public class FirewallRuleDeletedEventArgs : FirewallRuleBaseEventArgs { public FirewallRuleDeletedEventArgs(EventLogEntry @event) : base(@event) { + SetAttributes(); + } + public void SetAttributes() + { + SetAttributes(2, 3); + SetRuleAttributes(0, 1); } } } diff --git a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallSettingEventArgs.cs b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallSettingEventArgs.cs index 170b16e..dee9d0e 100644 --- a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallSettingEventArgs.cs +++ b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallSettingEventArgs.cs @@ -9,9 +9,9 @@ namespace WindowsAdvancedFirewallApi.Events.Arguments { - public class FirewallSettingEventArgs : FirewallEventArgs + public class FirewallSettingEventArgs : FirewallExtendedOriginEventArgs where TSetting : FirewallSetting, new() { - public FirewallSetting Setting + public TSetting Setting { get { return Data; } protected set { Data = value; } @@ -19,31 +19,46 @@ public FirewallSetting Setting internal FirewallSettingEventArgs(EventLogEntry @event) : base(@event) { - SetAttributes(); - } - - protected void SetAttributes() - { - SetAttributes(4, 5, 6); - SetSettingAttributes(0, 1, 2, 3); } protected void SetSettingAttributes(int iSettingType, int iSettingValue, int iSettingValueSize, int iSettingValueDisplay) { Setting.Type = EnumUtils.ParseStringValue(FirewallLogEvent.ReplacementStrings[iSettingType], FirewallSetting.SettingType.Unkown); - Setting.ValueSize = FirewallLogEvent.ReplacementStrings[iSettingValueSize].ParseInteger(0); var settingValue = FirewallLogEvent.ReplacementStrings[iSettingValue]; if (settingValue == string.Empty) { - Setting.Value = FirewallSetting.SettingValue.Empty; + Setting.Value = FirewallSetting.ValueTypes.Common.Empty; } else { - Setting.Value = EnumUtils.ParseStringValue(settingValue, FirewallSetting.SettingValue.Unkown); + if (Setting.Type == FirewallSetting.SettingType.IncomingStandardAction + || Setting.Type == FirewallSetting.SettingType.OutgoingStandardAction) + { + Setting.Value = EnumUtils.ParseStringValue(settingValue, FirewallSetting.ValueTypes.StandardAction.Unkown); + } + else + { + Setting.Value = EnumUtils.ParseStringValue(settingValue, FirewallSetting.ValueTypes.Common.Unkown); + } } + Setting.ValueSize = FirewallLogEvent.ReplacementStrings[iSettingValueSize].ParseInteger(0); Setting.ValueString = FirewallLogEvent.ReplacementStrings[iSettingValueDisplay]; } } + + public class FirewallSettingEventArgs : FirewallSettingEventArgs + { + internal FirewallSettingEventArgs(EventLogEntry @event) : base(@event) + { + SetAttributes(); + } + + protected void SetAttributes() + { + SetAttributes(4, 5, 6); + SetSettingAttributes(0, 2, 1, 3); + } + } } diff --git a/WindowsAdvancedFirewallApi/Events/Arguments/FirewallUserNotificationFailedEventArgs.cs b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallUserNotificationFailedEventArgs.cs new file mode 100644 index 0000000..8eb6490 --- /dev/null +++ b/WindowsAdvancedFirewallApi/Events/Arguments/FirewallUserNotificationFailedEventArgs.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WindowsAdvancedFirewallApi.Events.Objects; +using WindowsAdvancedFirewallApi.Utils; + +namespace WindowsAdvancedFirewallApi.Events.Arguments +{ + public class FirewallUserNotificationFailedEventArgs : FirewallEventArgs + { + public FirewallUserNotificationEvent Notification + { + get { return Data; } + protected set { Data = value; } + } + + internal FirewallUserNotificationFailedEventArgs(EventLogEntry @event) : base(@event) + { + SetAttributes(); + } + + private void SetAttributes() + { + SetAttributes(6); + + Notification.ReasonCode = FirewallLogEvent.ReplacementStrings[0].ParseInteger(-1); + Notification.ApplicationPath = FirewallLogEvent.ReplacementStrings[1]; + Notification.IpVersion = FirewallLogEvent.ReplacementStrings[2].ParseInteger(-1); + Notification.Protocol = FirewallLogEvent.ReplacementStrings[2].ParseInteger(-1); + Notification.Port = FirewallLogEvent.ReplacementStrings[2].ParseInteger(-1); + Notification.ProcessId = FirewallLogEvent.ReplacementStrings[2].ParseInteger(-1); + } + } +} diff --git a/WindowsAdvancedFirewallApi/Events/FirewallEventFactory.cs b/WindowsAdvancedFirewallApi/Events/FirewallEventFactory.cs new file mode 100644 index 0000000..e65fbc9 --- /dev/null +++ b/WindowsAdvancedFirewallApi/Events/FirewallEventFactory.cs @@ -0,0 +1,43 @@ +using NLog; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WindowsAdvancedFirewallApi.Events.Arguments; + +namespace WindowsAdvancedFirewallApi.Events +{ + class FirewallEventFactory + { + private static Logger LOG = LogManager.GetCurrentClassLogger(); + + public static FirewallBaseEventArgs GenerateFirewallEventArgs(EventLogEntry e) + { + var eventId = e?.InstanceId; + + switch ((WFEvents)eventId) + { + case WFEvents.WFGlobalConfigurationChangedEvent: + return new FirewallSettingEventArgs(e); + case WFEvents.WFProfileConfigurationChangedEvent: + return new FirewallProfileSettingEventArgs(e); + case WFEvents.WFRuleAddEvent: + case WFEvents.WFRuleChangeEvent: + return new FirewallRuleAddedEventArgs(e); + case WFEvents.WFRuleDeleteEvent: + return new FirewallRuleDeletedEventArgs(e); + case WFEvents.WFInterfaceProfileChangedEvent: + return new FirewallNetworkInterfaceProfileChangedEventArgs(e); + case WFEvents.WFUnableToShowQueryUserNotificationEvent: + return new FirewallUserNotificationFailedEventArgs(e); + case WFEvents.WFRestoreDefaultsEvent: + case WFEvents.WFAllFirewallRulesDeletedEvent: + default: + LOG.Info(string.Format("The event id '{0}' is not handled by this API.", eventId)); + return null; + } + } + } +} diff --git a/WindowsAdvancedFirewallApi/Events/FirewallEventManager.cs b/WindowsAdvancedFirewallApi/Events/FirewallEventManager.cs index ab47b94..78ffb7d 100644 --- a/WindowsAdvancedFirewallApi/Events/FirewallEventManager.cs +++ b/WindowsAdvancedFirewallApi/Events/FirewallEventManager.cs @@ -21,40 +21,44 @@ public enum InstallationStatus Installed, NotInstalled, Unknown } - const string FIREWALL_EVENT_SOURCE = ApiConstants.FIREWALL_EVENT_SOURCE; - const string FIREWALL_EVENT_PROTOCOL = ApiConstants.FIREWALL_EVENT_PROTOCOL; - const string FIREWALL_EVENT_LOGNAME = ApiConstants.FIREWALL_EVENT_LOGNAME; - - const string REGISTRY_KEY_EVENTLOG = ApiConstants.REGISTRY_KEY_EVENTLOG; - const string REGISTRY_KEY_FIREWALL_LOG = ApiConstants.REGISTRY_KEY_FIREWALL_LOG; - - private static FirewallEventManager instance; - - public static FirewallEventManager Instance + private static FirewallEventManager _singleton; + private static FirewallEventManager Singleton { get { - if (instance == null) + if (_singleton == null) { - instance = new FirewallEventManager(); + _singleton = new FirewallEventManager(); } - return instance; + return _singleton; } } - public static FirewallEventManager Get => Instance; + public static FirewallEventManager Instance => Singleton; + public static FirewallEventManager Get => Singleton; private EventLog _eventLog { get; set; } + #region EventHander + + public event EventHandler HistoryLoadingStatusChanged; + public event EventHandler> HistoryLoaded; + + public event EventHandler DefaultsRestored; public event EventHandler SettingsChanged; public event EventHandler ProfileSettingsChanged; + public event EventHandler AllRulesDeleted; public event EventHandler RulesChanged; public event EventHandler RuleAdded; public event EventHandler RuleModified; public event EventHandler RuleDeleted; - public event EventHandler NetworkInterfaceProfileChanged; + public event EventHandler NetworkInterfaceProfileChanged; + + public event EventHandler UserNotificationFailedForBlockedOperation; + + #endregion private FirewallEventManager() { @@ -65,7 +69,7 @@ public bool IsInstalled() { ApiHelper.RaiseExceptionOnUnauthorizedAccess("to check installation status.", true); - using (var key = Registry.LocalMachine.OpenSubKey(REGISTRY_KEY_FIREWALL_LOG)) + using (var key = Registry.LocalMachine.OpenSubKey(ApiConstants.REGISTRY_KEY_FIREWALL_LOG)) { if (key == null) { @@ -100,7 +104,7 @@ public void Install() if(!IsInstalled()) { - Registry.LocalMachine.CreateSubKey(REGISTRY_KEY_FIREWALL_LOG); + Registry.LocalMachine.CreateSubKey(ApiConstants.REGISTRY_KEY_FIREWALL_LOG); } //if (!EventLog.SourceExists(FIREWALL_EVENT_SOURCE)) @@ -115,7 +119,7 @@ public void Deinstall() if(IsInstalled()) { - Registry.LocalMachine.DeleteSubKey(REGISTRY_KEY_FIREWALL_LOG); + Registry.LocalMachine.DeleteSubKey(ApiConstants.REGISTRY_KEY_FIREWALL_LOG); } //if(EventLog.SourceExists(FIREWALL_EVENT_SOURCE)) @@ -129,7 +133,7 @@ public bool CanListenFirewall() { try { - var temp = new EventLog(FIREWALL_EVENT_LOGNAME) + var temp = new EventLog(ApiConstants.FIREWALL_EVENT_LOGNAME) { EnableRaisingEvents = true }; @@ -151,7 +155,7 @@ public bool StartListingFirewall() { if (_eventLog == null) { - _eventLog = new EventLog(FIREWALL_EVENT_LOGNAME) + _eventLog = new EventLog(ApiConstants.FIREWALL_EVENT_LOGNAME) { EnableRaisingEvents = true, }; @@ -179,68 +183,63 @@ public bool StopListingFirewall() private void EventLog_EntryWritten(object sender, EntryWrittenEventArgs e) { - var @event = GenerateFirewallEventArgs(e.Entry); + var @event = FirewallEventFactory.GenerateFirewallEventArgs(e.Entry); RaiseFirewallEvent(@event); } - private void InvokeEventHandler(EventHandler handler, FirewallBaseEventArgs e) where TData : FirewallBaseEventArgs - { - if (e is TData) - { - handler?.Invoke(this, (TData)e); - } - } - private void RaiseFirewallEvent(FirewallBaseEventArgs e) { + InvokeEventHandler(DefaultsRestored, e); InvokeEventHandler(SettingsChanged, e); InvokeEventHandler(ProfileSettingsChanged, e); + InvokeEventHandler(AllRulesDeleted, e); InvokeEventHandler(RulesChanged, e); InvokeEventHandler(RuleAdded, e); InvokeEventHandler(RuleModified, e); InvokeEventHandler(RuleDeleted, e); InvokeEventHandler(NetworkInterfaceProfileChanged, e); + + InvokeEventHandler(UserNotificationFailedForBlockedOperation, e); } - public List GetEventHistory() + private void InvokeEventHandler(EventHandler handler, FirewallBaseEventArgs e) where TData : FirewallBaseEventArgs { - var events = new List(); - - foreach (EventLogEntry item in _eventLog.Entries) + if (e is TData) { - var @event = GenerateFirewallEventArgs(item); - if(@event != null) - { - events.Add(@event); - } + handler?.Invoke(this, (TData)e); } - - return events; } - private FirewallBaseEventArgs GenerateFirewallEventArgs(EventLogEntry e) + public void LoadEventHistory() { - var eventId = e?.InstanceId; - - switch ((ApiConstants.EventID)eventId) + Task.Run(() => { - case ApiConstants.EventID.FIREWALL_SETTING_GENERAL: - return new FirewallSettingEventArgs(e); - case ApiConstants.EventID.FIREWALL_SETTING_PROFILE: - return new FirewallProfileSettingEventArgs(e); - case ApiConstants.EventID.FIREWALL_RULE_ADDED: - case ApiConstants.EventID.FIREWALL_RULE_MODIFIED: - return new FirewallRuleAddedEventArgs(e); - case ApiConstants.EventID.FIREWALL_RULE_DELETED: - return new FirewallRuleDeletedEventArgs(e); - case ApiConstants.EventID.FIREWALL_NETWORKINTERFACE_CHANGED: - return new FirewallNetworkInterfaceProfileChanged(e); - default: - LOG.Info(string.Format("The event id '{0}' is not handled by this API.", eventId)); - return null; - } + var events = new List(); + var index = 1; + + foreach (EventLogEntry item in _eventLog.Entries) + { + var @event = FirewallEventFactory.GenerateFirewallEventArgs(item); + if (@event != null) + { + events.Add(@event); + + var loadedEvent = new FirewallHistoryLoadingStatusChangedEventArgs() + { + MaxCount = _eventLog.Entries.Count, + LoadedCount = index, + CurrentLoadedEvent = @event + }; + HistoryLoadingStatusChanged.Invoke(this, null); + } + + index++; + } + + HistoryLoaded.Invoke(this, events); + }); } ~FirewallEventManager() diff --git a/WindowsAdvancedFirewallApi/Events/Objects/FirewallProfileSetting.cs b/WindowsAdvancedFirewallApi/Events/Objects/FirewallProfileSetting.cs new file mode 100644 index 0000000..4ffe2c4 --- /dev/null +++ b/WindowsAdvancedFirewallApi/Events/Objects/FirewallProfileSetting.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WindowsAdvancedFirewallApi.Events.Objects +{ + public class FirewallProfileSetting : FirewallSetting + { + public Profile Profiles { get; set; } + } +} diff --git a/WindowsAdvancedFirewallApi/Events/Objects/FirewallSetting.cs b/WindowsAdvancedFirewallApi/Events/Objects/FirewallSetting.cs index c3f80fd..f724985 100644 --- a/WindowsAdvancedFirewallApi/Events/Objects/FirewallSetting.cs +++ b/WindowsAdvancedFirewallApi/Events/Objects/FirewallSetting.cs @@ -12,26 +12,56 @@ public enum SettingType { Unkown = -1, WindowsFirewallActivating = 1, + WindowsFirewallCurrentProfile = 2, WindowsFirewallShieldMode = 3, // Blocks all incoming connections (inclusive the allowed apps) DeactivateIncomingNotification = 10, - DeactivatedInterfaces = 15 + DeactivatedInterfaces = 15, + OutgoingStandardAction = 16, + IncomingStandardAction = 17 } - public enum SettingValue + public class ValueTypes { - Unkown = -2, - Empty = -1, - No = 00000000, - Yes = 01000000, - Private = 02000000, - Public = 04000000 - } + public static List Collection = new List { typeof(Common), typeof(StandardAction) }; + + public enum Common + { + Empty = -2, + Unkown = -1, + No = 00000000, + Yes = 01000000, + Private = 02000000, + Public = 04000000 + } - public Profile Profiles { get; set; } + public enum StandardAction + { + Unkown = -1, + Allowing = 00000000, + Blocking = 01000000, + } + } public SettingType Type { get; set; } + + private Enum _value; + public Enum Value + { + get { return _value; } + set + { + if (!ValueTypes.Collection.Contains(value.GetType())) + { + throw new ArgumentOutOfRangeException(nameof(ValueType), string.Format("Only enumeration types from class {0} are allowed.", nameof(ValueTypes))); + } + + _value = value; + ValueType = value.GetType(); + } + } + public Type ValueType { get; private set; } + public int ValueSize { get; set; } - public SettingValue Value { get; set; } public string ValueString { get; set; } } } diff --git a/WindowsAdvancedFirewallApi/Events/Objects/FirewallUserNotificationEvent.cs b/WindowsAdvancedFirewallApi/Events/Objects/FirewallUserNotificationEvent.cs new file mode 100644 index 0000000..6358be4 --- /dev/null +++ b/WindowsAdvancedFirewallApi/Events/Objects/FirewallUserNotificationEvent.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WindowsAdvancedFirewallApi.Events.Objects +{ + public class FirewallUserNotificationEvent : FirewallBaseObject + { + public int ReasonCode { get; set; } + public string ApplicationPath { get; set; } + public int IpVersion { get; set; } + public int Protocol { get; set; } + public int Port { get; set; } + public int ProcessId { get; set; } + } +} diff --git a/WindowsAdvancedFirewallApi/Events/WFEvents.cs b/WindowsAdvancedFirewallApi/Events/WFEvents.cs index dcffef0..7fef35a 100644 --- a/WindowsAdvancedFirewallApi/Events/WFEvents.cs +++ b/WindowsAdvancedFirewallApi/Events/WFEvents.cs @@ -11,8 +11,8 @@ internal enum WFEvents WFStartupConfigurationInfo = 2000, WFStartupProfileConfigurationInfo = 2001, WFGlobalConfigurationChangedEvent = 2002, - WFProfileConfigurationChangedEvent = 2003, + WFRuleAddEvent = 2004, WFRuleChangeEvent = 2005, WFRuleDeleteEvent = 2006, @@ -22,6 +22,7 @@ internal enum WFEvents WFGroupPolicyErrorEvent = 2009, WFInterfaceProfileChangedEvent = 2010, WFUnableToShowQueryUserNotificationEvent = 2011, + WFRestoreDefaultsEvent = 2032, WFAllFirewallRulesDeletedEvent = 2033, diff --git a/WindowsAdvancedFirewallApi/NLog.config b/WindowsAdvancedFirewallApi/NLog.config index 854c6ae..e1376b9 100644 --- a/WindowsAdvancedFirewallApi/NLog.config +++ b/WindowsAdvancedFirewallApi/NLog.config @@ -33,11 +33,7 @@ diff --git a/WindowsAdvancedFirewallApi/Utils/EnumUtils.cs b/WindowsAdvancedFirewallApi/Utils/EnumUtils.cs index de71f74..decbf16 100644 --- a/WindowsAdvancedFirewallApi/Utils/EnumUtils.cs +++ b/WindowsAdvancedFirewallApi/Utils/EnumUtils.cs @@ -17,7 +17,9 @@ private static void CheckForEnum() where TEnum : struct, IConvertible, IC } } - public static TEnum ParseEnum(this int value, TEnum defaultValue = default(TEnum)) where TEnum : struct, IConvertible => ParseEnum(value, defaultValue); + public static TEnum ParseEnum(this short value, TEnum defaultValue = default(TEnum)) where TEnum : struct, IConvertible, IComparable, IFormattable => Parse(value, defaultValue); + public static TEnum ParseEnum(this int value, TEnum defaultValue = default(TEnum)) where TEnum : struct, IConvertible, IComparable, IFormattable => Parse(value, defaultValue); + public static TEnum ParseEnum(this long value, TEnum defaultValue = default(TEnum)) where TEnum : struct, IConvertible, IComparable, IFormattable => Parse((int)value, defaultValue); public static TEnum Parse(int value, TEnum defaultValue = default(TEnum)) where TEnum : struct, IConvertible, IComparable, IFormattable { diff --git a/WindowsAdvancedFirewallApi/Utils/PrimitiveUtils.cs b/WindowsAdvancedFirewallApi/Utils/PrimitiveUtils.cs index 19becbe..c89afff 100644 --- a/WindowsAdvancedFirewallApi/Utils/PrimitiveUtils.cs +++ b/WindowsAdvancedFirewallApi/Utils/PrimitiveUtils.cs @@ -7,36 +7,61 @@ namespace WindowsAdvancedFirewallApi.Utils { - public static class PrimitiveUtils - { - private static Logger LOG = LogManager.GetCurrentClassLogger(); + public static class PrimitiveUtils + { + private static Logger LOG = LogManager.GetCurrentClassLogger(); - public static int ParseInteger(this string value) - { - try - { - return int.Parse(value); - } - catch (Exception ex) when (ex is ArgumentNullException || ex is FormatException || ex is OverflowException) - { - LOG.Info(string.Format("Primitive parse error: {0}", value)); - LOG.Debug(ex); + public static int ParseInteger(this string value) + { + try + { + return int.Parse(value); + } + catch (Exception ex) when (ex is ArgumentNullException || ex is FormatException || ex is OverflowException) + { + LOG.Info(string.Format("Primitive parse error: {0}", value)); + LOG.Debug(ex); + throw; + } + } - throw; - } - } + public static int ParseInteger(this string value, int defaultValue) + { + try + { + return int.Parse(value); + } + catch (Exception ex) when (ex is ArgumentNullException || ex is FormatException || ex is OverflowException) + { + LOG.Info(string.Format("Return default value: {0}", defaultValue)); + return defaultValue; + } + } + public static long ParseLong(this string value) + { + try + { + return long.Parse(value); + } + catch (Exception ex) when (ex is ArgumentNullException || ex is FormatException || ex is OverflowException) + { + LOG.Info(string.Format("Primitive parse error: {0}", value)); + LOG.Debug(ex); + throw; + } + } - public static int ParseInteger(this string value, int defaultValue) - { - try - { - return int.Parse(value); - } - catch (Exception ex) when (ex is ArgumentNullException || ex is FormatException || ex is OverflowException) - { - LOG.Info(string.Format("Return default value: {0}", defaultValue)); - return defaultValue; - } - } - } + public static long ParseLong(this string value, long defaultValue) + { + try + { + return long.Parse(value); + } + catch (Exception ex) when (ex is ArgumentNullException || ex is FormatException || ex is OverflowException) + { + LOG.Info(string.Format("Return default value: {0}", defaultValue)); + return defaultValue; + } + } + } } diff --git a/WindowsAdvancedFirewallApi/WindowsAdvancedFirewallApi.csproj b/WindowsAdvancedFirewallApi/WindowsAdvancedFirewallApi.csproj index c677326..0842b3f 100644 --- a/WindowsAdvancedFirewallApi/WindowsAdvancedFirewallApi.csproj +++ b/WindowsAdvancedFirewallApi/WindowsAdvancedFirewallApi.csproj @@ -101,7 +101,7 @@ True - ..\packages\NLog.4.2.2\lib\net45\NLog.dll + ..\packages\NLog.4.2.3\lib\net45\NLog.dll True @@ -180,19 +180,25 @@ - + + - + + + + + + diff --git a/WindowsAdvancedFirewallApi/packages.config b/WindowsAdvancedFirewallApi/packages.config index bb6e97a..78018a8 100644 --- a/WindowsAdvancedFirewallApi/packages.config +++ b/WindowsAdvancedFirewallApi/packages.config @@ -1,7 +1,6 @@  - - + \ No newline at end of file diff --git a/WindowsFirewallDashboard/Library/ApplicationSystem/ApplicationInformation.cs b/WindowsFirewallDashboard/Library/ApplicationSystem/ApplicationInformation.cs index 9b94de5..370e354 100644 --- a/WindowsFirewallDashboard/Library/ApplicationSystem/ApplicationInformation.cs +++ b/WindowsFirewallDashboard/Library/ApplicationSystem/ApplicationInformation.cs @@ -7,7 +7,7 @@ namespace WindowsFirewallDashboard.Library.ApplicationSystem { - public class ApplicationInformation + class ApplicationInformation { public static Assembly GetExecutingAssembly() { diff --git a/WindowsFirewallDashboard/Library/ApplicationSystem/ApplicationManager.cs b/WindowsFirewallDashboard/Library/ApplicationSystem/ApplicationManager.cs index 0d06581..b6a0440 100644 --- a/WindowsFirewallDashboard/Library/ApplicationSystem/ApplicationManager.cs +++ b/WindowsFirewallDashboard/Library/ApplicationSystem/ApplicationManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; @@ -7,25 +8,29 @@ using System.Windows; using WindowsAdvancedFirewallApi.Events; using WindowsAdvancedFirewallApi.Events.Arguments; +using WindowsFirewallDashboard.Library.Utils; +using WindowsFirewallDashboard.Resources.Localization; namespace WindowsFirewallDashboard.Library.ApplicationSystem { - public class ApplicationManager + #pragma warning disable CC0091 + class ApplicationManager { - private static ApplicationManager _instance; - - public static ApplicationManager Instance + private static ApplicationManager _singleton; + protected static ApplicationManager Singleton { get { - if(_instance == null) + if (_singleton == null) { - _instance = new ApplicationManager(); + _singleton = new ApplicationManager(); } - return _instance; + return _singleton; } } + public static ApplicationManager Instance => Singleton; + public FirewallManager Firewall { get; private set; } public NotificationManager Notifications { get; private set; } public TrayManager Tray { get; private set; } @@ -37,6 +42,8 @@ private ApplicationManager() Firewall = new FirewallManager(Notifications); Tray.Icon = new Icon(Application.GetResourceStream(ApplicationResource.NotifyIconWhite).Stream); + + LocalizationTool.Initialize(); } public void Start() @@ -46,8 +53,6 @@ public void Start() Tray.ShowIcon(); ApplicationUpdater.Instance.CheckForUpdates(); - - Firewall.EventManager.GetEventHistory(); } public void Activate() @@ -62,6 +67,8 @@ public void Deactivate() public void Exit() { + Tray.HideIcon(); + Firewall.StopEventListening(); } diff --git a/WindowsFirewallDashboard/Library/ApplicationSystem/ApplicationResource.cs b/WindowsFirewallDashboard/Library/ApplicationSystem/ApplicationResource.cs index fbae29a..1694343 100644 --- a/WindowsFirewallDashboard/Library/ApplicationSystem/ApplicationResource.cs +++ b/WindowsFirewallDashboard/Library/ApplicationSystem/ApplicationResource.cs @@ -6,7 +6,7 @@ namespace WindowsFirewallDashboard.Library.ApplicationSystem { - public class ApplicationResource + class ApplicationResource { public static Uri NotifyIconBlack = new Uri(@"/Resources/Images/NotifyIcon-black.ico", UriKind.Relative); public static Uri NotifyIconWhite = new Uri(@"/Resources/Images/NotifyIcon-white.ico", UriKind.Relative); diff --git a/WindowsFirewallDashboard/Library/ApplicationSystem/FirewallManager.cs b/WindowsFirewallDashboard/Library/ApplicationSystem/FirewallManager.cs index e51a33e..eb51a41 100644 --- a/WindowsFirewallDashboard/Library/ApplicationSystem/FirewallManager.cs +++ b/WindowsFirewallDashboard/Library/ApplicationSystem/FirewallManager.cs @@ -8,7 +8,7 @@ namespace WindowsFirewallDashboard.Library.ApplicationSystem { - public class FirewallManager + class FirewallManager { public FirewallEventManager EventManager { diff --git a/WindowsFirewallDashboard/Library/ApplicationSystem/NotificationManager.cs b/WindowsFirewallDashboard/Library/ApplicationSystem/NotificationManager.cs index ad63452..b456d67 100644 --- a/WindowsFirewallDashboard/Library/ApplicationSystem/NotificationManager.cs +++ b/WindowsFirewallDashboard/Library/ApplicationSystem/NotificationManager.cs @@ -8,7 +8,7 @@ namespace WindowsFirewallDashboard.Library.ApplicationSystem { - public class NotificationManager + class NotificationManager { private FirewallEventNotificationWindow notificationWindow; @@ -23,7 +23,10 @@ public void ShowEventNotification() { if(notificationWindow == null) { - notificationWindow = new FirewallEventNotificationWindow(); + notificationWindow = new FirewallEventNotificationWindow + { + Topmost = true + }; notificationWindow.AddEvent(); notificationWindow.Show(); diff --git a/WindowsFirewallDashboard/Library/ApplicationSystem/TrayManager.cs b/WindowsFirewallDashboard/Library/ApplicationSystem/TrayManager.cs index 70d4f98..584998e 100644 --- a/WindowsFirewallDashboard/Library/ApplicationSystem/TrayManager.cs +++ b/WindowsFirewallDashboard/Library/ApplicationSystem/TrayManager.cs @@ -11,7 +11,7 @@ namespace WindowsFirewallDashboard.Library.ApplicationSystem { - public class TrayManager + class TrayManager { private Window _rootWindow; public Window RootWindow diff --git a/WindowsFirewallDashboard/Library/Utils/GeneralUtils.cs b/WindowsFirewallDashboard/Library/Utils/GeneralUtils.cs index 45e5305..df94d6f 100644 --- a/WindowsFirewallDashboard/Library/Utils/GeneralUtils.cs +++ b/WindowsFirewallDashboard/Library/Utils/GeneralUtils.cs @@ -8,7 +8,7 @@ namespace WindowsFirewallDashboard.Library.Utils { - public static class GeneralUtils + static class GeneralUtils { public static void ShowContextMenu(this NotifyIcon notifyIcon) { diff --git a/WindowsFirewallDashboard/Library/Utils/LocalizationTool.cs b/WindowsFirewallDashboard/Library/Utils/LocalizationTool.cs new file mode 100644 index 0000000..839155a --- /dev/null +++ b/WindowsFirewallDashboard/Library/Utils/LocalizationTool.cs @@ -0,0 +1,48 @@ +using NLog; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Reflection; +using System.Resources; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using WindowsFirewallDashboard.Resources.Localization; + +namespace WindowsFirewallDashboard.Library.Utils +{ + sealed class LocalizationTool + { + private static Logger LOG = LogManager.GetCurrentClassLogger(); + + private static ResourceManager _ressourceManager; + + static LocalizationTool() + { + } + + public static void Initialize() + { + _ressourceManager = new ResourceManager(nameof(Language), Assembly.GetExecutingAssembly()); + } + + public static void UpdateLanguage(string langID) + { + try + { + //Set Language + Thread.CurrentThread.CurrentUICulture = new CultureInfo(langID); + LOG.Info("Changed language to {0}", langID); + } + catch (Exception) + { + LOG.Info("Can't change language to {0}", langID); + } + } + public static string Translate(string key) + { + return _ressourceManager.GetString(key); + } + } +} diff --git a/WindowsFirewallDashboard/Locator/ViewModelLocator.cs b/WindowsFirewallDashboard/Locator/ViewModelLocator.cs index 8beb84f..d69ee71 100644 --- a/WindowsFirewallDashboard/Locator/ViewModelLocator.cs +++ b/WindowsFirewallDashboard/Locator/ViewModelLocator.cs @@ -8,7 +8,7 @@ namespace WindowsFirewallDashboard.Locator { - public class ViewModelLocator + class ViewModelLocator { private static ControlViewModel _controlVM; diff --git a/WindowsFirewallDashboard/Model/FWProfile.cs b/WindowsFirewallDashboard/Model/FWProfile.cs index 559b9d6..f6389ae 100644 --- a/WindowsFirewallDashboard/Model/FWProfile.cs +++ b/WindowsFirewallDashboard/Model/FWProfile.cs @@ -6,7 +6,7 @@ namespace WindowsFirewallDashboard.Model { - public class FWProfile + class FWProfile { } } diff --git a/WindowsFirewallDashboard/Model/FWRule.cs b/WindowsFirewallDashboard/Model/FWRule.cs index a09557f..64d1018 100644 --- a/WindowsFirewallDashboard/Model/FWRule.cs +++ b/WindowsFirewallDashboard/Model/FWRule.cs @@ -6,7 +6,7 @@ namespace WindowsFirewallDashboard.Model { - public class FWRule + class FWRule { } } diff --git a/WindowsFirewallDashboard/NLog.config b/WindowsFirewallDashboard/NLog.config new file mode 100644 index 0000000..e1376b9 --- /dev/null +++ b/WindowsFirewallDashboard/NLog.config @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WindowsFirewallDashboard/Resources/Localization/Language.Designer.cs b/WindowsFirewallDashboard/Resources/Localization/Language.Designer.cs new file mode 100644 index 0000000..2b38840 --- /dev/null +++ b/WindowsFirewallDashboard/Resources/Localization/Language.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace WindowsFirewallDashboard.Resources.Localization { + using System; + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Language { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Language() { + } + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WindowsFirewallDashboard.Resources.Localization.Language", typeof(Language).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/WindowsFirewallDashboard/Resources/Localization/Language.de.resx b/WindowsFirewallDashboard/Resources/Localization/Language.de.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/WindowsFirewallDashboard/Resources/Localization/Language.de.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WindowsFirewallDashboard/Resources/Localization/Language.resx b/WindowsFirewallDashboard/Resources/Localization/Language.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/WindowsFirewallDashboard/Resources/Localization/Language.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WindowsFirewallDashboard/View/FirewallEventNotificationWindow.xaml b/WindowsFirewallDashboard/View/FirewallEventNotificationWindow.xaml index fd0fece..d545a96 100644 --- a/WindowsFirewallDashboard/View/FirewallEventNotificationWindow.xaml +++ b/WindowsFirewallDashboard/View/FirewallEventNotificationWindow.xaml @@ -13,11 +13,9 @@ GlowBrush="{DynamicResource AccentColorBrush}" ResizeMode="NoResize" WindowTransitionsEnabled="true"> - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WindowsFirewallDashboard/View/MainWindow.xaml.cs b/WindowsFirewallDashboard/View/MainWindow.xaml.cs index bf2f647..3fd0141 100644 --- a/WindowsFirewallDashboard/View/MainWindow.xaml.cs +++ b/WindowsFirewallDashboard/View/MainWindow.xaml.cs @@ -17,21 +17,20 @@ using WindowsAdvancedFirewallApi; using WindowsAdvancedFirewallApi.Events; using WindowsFirewallDashboard.Library.ApplicationSystem; +using System.Diagnostics; namespace WindowsFirewallDashboard { /// /// Interaktionslogik für MainWindow.xaml /// - public partial class MainWindow : MetroWindow + partial class MainWindow : MetroWindow { public MainWindow() { InitializeComponent(); InitializeCustomComponents(); InitializeEvents(); - - StartListening(); } private void InitializeCustomComponents() @@ -39,21 +38,29 @@ private void InitializeCustomComponents() ApplicationManager.Instance.Tray.RootWindow = this; } + private void InitializeEvents() { + tabEvents.GotFocus += TabEvents_GotFocus; + ApplicationManager.Instance.Firewall.EventManager.HistoryLoaded += EventManager_HistoryLoaded; + } + private void TabEvents_GotFocus(object sender, RoutedEventArgs e) + { + ApplicationManager.Instance.Firewall.EventManager.LoadEventHistory(); + } + + private void EventManager_HistoryLoaded(object sender, List events) + { + eventHistory.ItemsSource = events; } - private void StartListening() + private void EnableFirewall_Click(object sender, RoutedEventArgs e) { - //if(FirewallEventManager.Instance.StartListingFirewall()) - //this.TbNofitications.Text = "Benachrichtigungen aktiv."; } - private void StopListening() + private void DisableFirewall_Click(object sender, RoutedEventArgs e) { - //if(FirewallEventManager.Instance.StopListingFirewall()) - //this.TbNofitications.Text = "Benachrichtigungen inaktiv."; } } } diff --git a/WindowsFirewallDashboard/ViewModel/Base/BaseViewModel.cs b/WindowsFirewallDashboard/ViewModel/Base/BaseViewModel.cs index 0e9999e..ffba20b 100644 --- a/WindowsFirewallDashboard/ViewModel/Base/BaseViewModel.cs +++ b/WindowsFirewallDashboard/ViewModel/Base/BaseViewModel.cs @@ -9,7 +9,7 @@ namespace WindowsFirewallDashboard.ViewModel.Base { [Serializable] - public abstract class BaseViewModel : IViewModel + abstract class BaseViewModel : IViewModel { protected BaseViewModel() { diff --git a/WindowsFirewallDashboard/ViewModel/Base/BaseViewModelGeneric.cs b/WindowsFirewallDashboard/ViewModel/Base/BaseViewModelGeneric.cs index 875ca39..2439dd0 100644 --- a/WindowsFirewallDashboard/ViewModel/Base/BaseViewModelGeneric.cs +++ b/WindowsFirewallDashboard/ViewModel/Base/BaseViewModelGeneric.cs @@ -9,7 +9,7 @@ namespace WindowsFirewallDashboard.ViewModel.Base { [Serializable] - public abstract class BaseViewModel : BaseViewModel, IViewModel where TModel : class + abstract class BaseViewModel : BaseViewModel, IViewModel where TModel : class { private TModel model; diff --git a/WindowsFirewallDashboard/ViewModel/Base/IViewModel.cs b/WindowsFirewallDashboard/ViewModel/Base/IViewModel.cs index 8596539..6a0ab78 100644 --- a/WindowsFirewallDashboard/ViewModel/Base/IViewModel.cs +++ b/WindowsFirewallDashboard/ViewModel/Base/IViewModel.cs @@ -7,8 +7,8 @@ namespace WindowsFirewallDashboard.ViewModel.Base { - public interface IViewModel : INotifyPropertyChanged { } - public interface IViewModel : IViewModel + interface IViewModel : INotifyPropertyChanged { } + interface IViewModel : IViewModel { [Browsable(false)] [Bindable(false)] diff --git a/WindowsFirewallDashboard/ViewModel/Base/RelayCommand.cs b/WindowsFirewallDashboard/ViewModel/Base/RelayCommand.cs index 54d2109..6e0ba6a 100644 --- a/WindowsFirewallDashboard/ViewModel/Base/RelayCommand.cs +++ b/WindowsFirewallDashboard/ViewModel/Base/RelayCommand.cs @@ -9,7 +9,7 @@ namespace WindowsFirewallDashboard.ViewModel.Base { [Serializable] - public class RelayCommand : ICommand + class RelayCommand : ICommand { #region Fields private readonly Action execute; diff --git a/WindowsFirewallDashboard/ViewModel/ControlViewModel.cs b/WindowsFirewallDashboard/ViewModel/ControlViewModel.cs index c323234..2cd5e7c 100644 --- a/WindowsFirewallDashboard/ViewModel/ControlViewModel.cs +++ b/WindowsFirewallDashboard/ViewModel/ControlViewModel.cs @@ -11,40 +11,8 @@ namespace WindowsFirewallDashboard.ViewModel { - public class ControlViewModel : BaseViewModel + class ControlViewModel : BaseViewModel { - private Grid currentInformationGrid; - - private ICommand showInformationGridCommand; - public ICommand ShowInformationGridCommand - { - get - { - if (showInformationGridCommand == null) - { - showInformationGridCommand = new RelayCommand(param => ShowInformationGrid(param)); - } - return showInformationGridCommand; - } - } - - private void changeCurrentInformationGrid(Grid newGrid) - { - if(currentInformationGrid != null) - { - currentInformationGrid.Visibility = Visibility.Collapsed; - } - - currentInformationGrid = newGrid; - currentInformationGrid.Visibility = Visibility.Visible; - } - - private void ShowInformationGrid(object @object) - { - if (@object is Grid) - { - changeCurrentInformationGrid(@object as Grid); - } - } + } } diff --git a/WindowsFirewallDashboard/WindowsFirewallDashboard.csproj b/WindowsFirewallDashboard/WindowsFirewallDashboard.csproj index 3a1bce9..aab58be 100644 --- a/WindowsFirewallDashboard/WindowsFirewallDashboard.csproj +++ b/WindowsFirewallDashboard/WindowsFirewallDashboard.csproj @@ -140,6 +140,10 @@ ..\packages\MahApps.Metro.1.1.2.0\lib\net45\MahApps.Metro.dll True + + ..\packages\NLog.4.2.3\lib\net45\NLog.dll + True + ..\packages\Octokit.0.17.0\lib\net45\Octokit.dll True @@ -188,10 +192,16 @@ + + + True + True + Language.resx + @@ -225,7 +235,15 @@ ResXFileCodeGenerator Resources.Designer.cs + + + ResXFileCodeGenerator + Language.Designer.cs + + + PreserveNewest + SettingsSingleFileGenerator diff --git a/WindowsFirewallDashboard/packages.config b/WindowsFirewallDashboard/packages.config index 1bf9cdd..df2d5fe 100644 --- a/WindowsFirewallDashboard/packages.config +++ b/WindowsFirewallDashboard/packages.config @@ -1,5 +1,6 @@  + \ No newline at end of file