diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..3777b8a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,271 @@ +# Remove the line below if you want to inherit .editorconfig settings from higher directories +root = true + +# All files +[*] +indent_style = space +indent_size = 4 +tab_width = 4 +charset = utf-8 + +# XML-like files +[*.{xml,config,proj,csproj,wxi,wxs,props,targets}] + +indent_style = space +indent_size = 2 +tab_width = 2 +end_of_line = crlf + +# Json files +[*.json] + +indent_style = space +indent_size = 2 +tab_width = 2 +end_of_line = crlf + +# Powershell +[*.{ps1,psm1,psd1,psrc,pssc}] +indent_style = space +indent_size = 4 +tab_width = 4 +end_of_line = crlf + +# C# files +[*.cs] + +#### Core EditorConfig Options #### + +# Indentation and spacing +indent_style = space +indent_size = 4 +tab_width = 4 + +# New line preferences +end_of_line = crlf +insert_final_newline = false + +#### .NET Coding Conventions #### + +# Organize usings +dotnet_separate_import_directive_groups = false +dotnet_sort_system_directives_first = true +file_header_template = unset + +# this. and Me. preferences +dotnet_style_qualification_for_event = false:suggestion +dotnet_style_qualification_for_field = false +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_property = false:suggestion + +# Language keywords vs BCL types preferences +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion + +# Parentheses preferences +dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:suggestion +dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:suggestion +dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion +dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:suggestion + +# Modifier preferences +dotnet_style_require_accessibility_modifiers = for_non_interface_members + +# Expression-level preferences +dotnet_style_coalesce_expression = true +dotnet_style_collection_initializer = true +dotnet_style_explicit_tuple_names = true +dotnet_style_namespace_match_folder = true +dotnet_style_null_propagation = true +dotnet_style_object_initializer = true +dotnet_style_operator_placement_when_wrapping = beginning_of_line +dotnet_style_prefer_auto_properties = true:suggestion +dotnet_style_prefer_compound_assignment = true +dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion +dotnet_style_prefer_conditional_expression_over_return = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true +dotnet_style_prefer_inferred_tuple_names = true +dotnet_style_prefer_is_null_check_over_reference_equality_method = true +dotnet_style_prefer_simplified_boolean_expressions = true +dotnet_style_prefer_simplified_interpolation = true + +# Field preferences +dotnet_style_readonly_field = true:warning + +# Parameter preferences +dotnet_code_quality_unused_parameters = all + +# Suppression preferences +dotnet_remove_unnecessary_suppression_exclusions = none + +# New line preferences +dotnet_style_allow_multiple_blank_lines_experimental = false:suggestion +dotnet_style_allow_statement_immediately_after_block_experimental = false:suggestion + +#### C# Coding Conventions #### + +# var preferences +csharp_style_var_elsewhere = true:suggestion +csharp_style_var_for_built_in_types = true:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion + +# Expression-bodied members +csharp_style_expression_bodied_accessors = true:suggestion +csharp_style_expression_bodied_constructors = true:suggestion +csharp_style_expression_bodied_indexers = true:suggestion +csharp_style_expression_bodied_lambdas = true:suggestion +csharp_style_expression_bodied_local_functions = true:suggestion +csharp_style_expression_bodied_methods = true:suggestion +csharp_style_expression_bodied_operators = true:suggestion +csharp_style_expression_bodied_properties = true:suggestion + +# Pattern matching preferences +csharp_style_pattern_matching_over_as_with_null_check = true +csharp_style_pattern_matching_over_is_with_cast_check = true +csharp_style_prefer_not_pattern = true +csharp_style_prefer_pattern_matching = true:suggestion +csharp_style_prefer_switch_expression = true + +# Null-checking preferences +csharp_style_conditional_delegate_call = true + +# Modifier preferences +csharp_prefer_static_local_function = true +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async + +# Code-block preferences +csharp_prefer_braces = false:suggestion +csharp_prefer_simple_using_statement = true:suggestion + +# Expression-level preferences +csharp_prefer_simple_default_expression = true:suggestion +csharp_style_deconstructed_variable_declaration = true +csharp_style_implicit_object_creation_when_type_is_apparent = true +csharp_style_inlined_variable_declaration = true +csharp_style_pattern_local_over_anonymous_function = true +csharp_style_prefer_index_operator = true:suggestion +csharp_style_prefer_range_operator = true +csharp_style_throw_expression = true:suggestion +csharp_style_unused_value_assignment_preference = discard_variable +csharp_style_unused_value_expression_statement_preference = discard_variable:suggestion + +# 'using' directive preferences +csharp_using_directive_placement = outside_namespace:suggestion +dotnet_diagnostic.IDE0065.severity = none + +# New line preferences +csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true +csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:suggestion +csharp_style_allow_embedded_statements_on_same_line_experimental = true + +#### C# Formatting Rules #### + +# New line preferences +csharp_new_line_before_catch = true +csharp_new_line_before_else = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_open_brace = all +csharp_new_line_between_query_expression_clauses = true + +# Indentation preferences +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = false +csharp_indent_labels = no_change +csharp_indent_switch_labels = true + +# Space preferences +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +# Wrapping preferences +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = true + +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case +csharp_style_namespace_declarations = block_scoped:silent +csharp_style_prefer_null_check_over_type_check = true:suggestion +csharp_style_prefer_local_over_anonymous_function = true:suggestion +csharp_style_prefer_method_group_conversion = true:silent +csharp_style_prefer_top_level_statements = true:silent + +[*.{cs,vb}] +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_auto_properties = true:suggestion +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion +dotnet_style_prefer_conditional_expression_over_return = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_compound_assignment = true:suggestion +dotnet_style_prefer_simplified_interpolation = true:suggestion +dotnet_style_namespace_match_folder = true:suggestion +dotnet_style_operator_placement_when_wrapping = beginning_of_line \ No newline at end of file diff --git a/src/Delta.CapiNet/Delta.CapiNet.csproj b/src/Delta.CapiNet/Delta.CapiNet.csproj index 4f0df22..8036946 100644 --- a/src/Delta.CapiNet/Delta.CapiNet.csproj +++ b/src/Delta.CapiNet/Delta.CapiNet.csproj @@ -1,9 +1,8 @@ - net48 + net8.0 true - 9.0 false diff --git a/src/Delta.CertXplorer.Common/Delta.CertXplorer.Common.csproj b/src/Delta.CertXplorer.Common/Delta.CertXplorer.Common.csproj index e934636..2323053 100644 --- a/src/Delta.CertXplorer.Common/Delta.CertXplorer.Common.csproj +++ b/src/Delta.CertXplorer.Common/Delta.CertXplorer.Common.csproj @@ -1,12 +1,11 @@ - net48 + net8.0-windows Delta.CertXplorer.Common Delta.CertXplorer true true - 9.0 false @@ -45,10 +44,4 @@ - - - - - - \ No newline at end of file diff --git a/src/Delta.CertXplorer.Core/Delta.CertXplorer.Core.csproj b/src/Delta.CertXplorer.Core/Delta.CertXplorer.Core.csproj index 3be3b81..7e41717 100644 --- a/src/Delta.CertXplorer.Core/Delta.CertXplorer.Core.csproj +++ b/src/Delta.CertXplorer.Core/Delta.CertXplorer.Core.csproj @@ -1,12 +1,11 @@ - net48 + net8.0-windows Delta.CertXplorer.Core Delta.CertXplorer true true - 9.0 false @@ -162,10 +161,6 @@ - - - - TextTemplatingFileGenerator diff --git a/src/Delta.CertXplorer.Core/Logging/CertXplorerLogService.cs b/src/Delta.CertXplorer.Core/Logging/CertXplorerLogService.cs index beaba0c..4ae7309 100644 --- a/src/Delta.CertXplorer.Core/Logging/CertXplorerLogService.cs +++ b/src/Delta.CertXplorer.Core/Logging/CertXplorerLogService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Linq; using System.Reflection; @@ -261,7 +261,7 @@ private void StoreLogEntry(LogLevel level, string message, Exception exception) /// /// Initializes a new instance of the class. /// - public CertXplorerLogService() + public CertXplorerLogService() { if (!classIsInitialized) InitializeLogger(); } @@ -287,16 +287,16 @@ private void InitializeLogger() configuration.EventLogName, configuration.EventLogMachine, configuration.EventSourceName); - Debug.Listeners.Add(new EventLogTraceListener(eventLog)); + _ = Trace.Listeners.Add(new EventLogTraceListener(eventLog)); } catch (Exception ex) { string error = string.Format(SR.InitializationError, ex.Message); - storedLogEntries.Add(new LogEntry - { - Level = LogLevel.Error, - Message = error, - Exception = ex + storedLogEntries.Add(new LogEntry + { + Level = LogLevel.Error, + Message = error, + Exception = ex }); } } @@ -326,11 +326,11 @@ private void InitializeLogger() catch (Exception ex) { string error = string.Format(SR.InitializationError, ex.Message); - storedLogEntries.Add(new LogEntry - { - Level = LogLevel.Error, - Message = error, - Exception = ex + storedLogEntries.Add(new LogEntry + { + Level = LogLevel.Error, + Message = error, + Exception = ex }); } } @@ -370,7 +370,7 @@ private void LogEntry(LogEntry entry) // File logging try { - if (entry.Level <= configuration.TracingLogLevel) LogToTraceFile(entry); + if (entry.Level <= configuration.TracingLogLevel) LogToTraceFile(entry); } catch (Exception ex) { @@ -416,7 +416,7 @@ private void LogToEventLog(LogEntry entry) private void LogToTraceFile(LogEntry entry) { - using (FileStream stream = new FileStream(traceFilename, + using (FileStream stream = new FileStream(traceFilename, FileMode.Append, FileAccess.Write, FileShare.ReadWrite)) { using (TextWriter writer = new StreamWriter(stream)) @@ -424,7 +424,7 @@ private void LogToTraceFile(LogEntry entry) LogToWriter(writer, entry); writer.Flush(); } - + stream.Close(); } } @@ -478,13 +478,13 @@ private string GetCallingMethod() MethodBase method = null; Type declaringType = MethodBase.GetCurrentMethod().DeclaringType; // TODO: remove from original code -//#pragma warning disable 618 -// Type traceHandlerType = typeof(Delta.CertXplorer.Diagnostics.TraceHandler); -//#pragma warning restore + //#pragma warning disable 618 + // Type traceHandlerType = typeof(Delta.CertXplorer.Diagnostics.TraceHandler); + //#pragma warning restore for (int i = 0; i < stackTrace.FrameCount; i++) { MethodBase current = stackTrace.GetFrame(i).GetMethod(); - if ((current.DeclaringType != declaringType) && + if ((current.DeclaringType != declaringType) && (!current.DeclaringType.FullName.Contains("Delta.CertXplorer.Logging")) && (!current.DeclaringType.FullName.Contains("Delta.CertXplorer.Diagnostics")) && (!current.DeclaringType.FullName.Contains("Delta.CertXplorer.Extensions.LoggingExtensions"))) @@ -495,7 +495,7 @@ private string GetCallingMethod() } return (method != null ? - string.Format("{0}.{1}", method.DeclaringType.FullName, method.Name) : + string.Format("{0}.{1}", method.DeclaringType.FullName, method.Name) : "?"); } } diff --git a/src/Delta.CertXplorer.Core/Logging/log4net/Log4NetService.cs b/src/Delta.CertXplorer.Core/Logging/log4net/Log4NetService.cs index ae9f069..3ef730b 100644 --- a/src/Delta.CertXplorer.Core/Logging/log4net/Log4NetService.cs +++ b/src/Delta.CertXplorer.Core/Logging/log4net/Log4NetService.cs @@ -17,15 +17,10 @@ public sealed partial class Log4NetService : BaseLogService, ITextBoxAppendable private static readonly Type thisServiceType = typeof(Log4NetService); private readonly FileInfo configurationFileInfo; - public Log4NetService() : this(null, true) { } public Log4NetService(FileInfo configurationFile) : this(configurationFile, true) { } private Log4NetService(FileInfo configurationFile, bool configure) { - if (configurationFile == null) configurationFile = new FileInfo( - AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); - configurationFileInfo = configurationFile; - if (configure) _ = XmlConfigurator.ConfigureAndWatch(configurationFileInfo); } diff --git a/src/Delta.CertXplorer.Core/Logging/log4net/Log4NetServiceFactory.cs b/src/Delta.CertXplorer.Core/Logging/log4net/Log4NetServiceFactory.cs index 936aaa0..ff06fbf 100644 --- a/src/Delta.CertXplorer.Core/Logging/log4net/Log4NetServiceFactory.cs +++ b/src/Delta.CertXplorer.Core/Logging/log4net/Log4NetServiceFactory.cs @@ -1,29 +1,14 @@ -using System; using System.IO; -namespace Delta.CertXplorer.Logging.log4net +namespace Delta.CertXplorer.Logging.log4net; + +public static class Log4NetServiceFactory { - public static class Log4NetServiceFactory + public static ILogService CreateService(string configurationFile) { - public static ILogService CreateService() => new Log4NetService(); - - public static ILogService CreateService(string configurationFile) - { - FileInfo fileInfo; - if (File.Exists(configurationFile)) fileInfo = new FileInfo(configurationFile); - else - { - // If we couldn't find the file, we try to search for it in the application's configuration - // file directory. - var appConfig = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; - var path = Path.GetDirectoryName(appConfig); - var configFile = Path.Combine(path, configurationFile); - fileInfo = File.Exists(configFile) ? - new FileInfo(configFile) : - throw new FileNotFoundException("Log4Net configuration file was not found", configurationFile); - } - - return new Log4NetService(fileInfo); - } + var fileInfo = File.Exists(configurationFile) + ? new FileInfo(configurationFile) + : throw new FileNotFoundException("Log4Net configuration file was not found", configurationFile); + return new Log4NetService(fileInfo); } } diff --git a/src/Delta.CertXplorer.Core/UI/Actions/UIAction.cs b/src/Delta.CertXplorer.Core/UI/Actions/UIAction.cs index 3265517..235a2d5 100644 --- a/src/Delta.CertXplorer.Core/UI/Actions/UIAction.cs +++ b/src/Delta.CertXplorer.Core/UI/Actions/UIAction.cs @@ -13,248 +13,231 @@ using System.Drawing; using System.Windows.Forms; -namespace Delta.CertXplorer.UI.Actions +namespace Delta.CertXplorer.UI.Actions; + +[ToolboxBitmap(typeof(UIAction), "UIAction.bmp"), DefaultEvent("Run"), StandardAction] +[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Winforms conventions")] +public class UIAction : Component { - [ToolboxBitmap(typeof(UIAction), "UIAction.bmp"), DefaultEvent("Run"), StandardAction] - [SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Winforms conventions")] - public class UIAction : Component + protected enum ActionWorkingState { - protected enum ActionWorkingState - { - Listening, - Driving - } + Listening, + Driving + } - private readonly List targets = new List(); - private readonly EventHandler clickEventHandler; - private readonly EventHandler checkStateChangedEventHandler; - private UIActionsManager actionList = null; - private CheckState checkState = CheckState.Unchecked; - private bool enabled = true; - private bool checkOnClick = false; - private Keys shortcutKeys = Keys.None; - private bool visible = true; - - public UIAction() - { - WorkingState = ActionWorkingState.Listening; - clickEventHandler = new EventHandler(target_Click); - checkStateChangedEventHandler = new EventHandler(target_CheckStateChanged); - } + private readonly List targets = []; + private readonly EventHandler clickEventHandler; + private readonly EventHandler checkStateChangedEventHandler; + private UIActionsManager actionList = null; + private CheckState checkState = CheckState.Unchecked; + private bool enabled = true; + private bool checkOnClick = false; + private Keys shortcutKeys = Keys.None; + private bool visible = true; + + public UIAction() + { + WorkingState = ActionWorkingState.Listening; + clickEventHandler = new EventHandler(target_Click); + checkStateChangedEventHandler = new EventHandler(target_CheckStateChanged); + } - public event EventHandler CheckStateChanged; - public event CancelEventHandler BeforeRun; - public event EventHandler Run; - public event EventHandler AfterRun; - public event EventHandler Update; + public event EventHandler CheckStateChanged; + public event CancelEventHandler BeforeRun; + public event EventHandler Run; + public event EventHandler AfterRun; + public event EventHandler Update; - [DefaultValue(false)] - public bool Checked - { - get => checkState != CheckState.Unchecked; - set => CheckState = value ? CheckState.Checked : CheckState.Unchecked; - } + [DefaultValue(false)] + public bool Checked + { + get => checkState != CheckState.Unchecked; + set => CheckState = value ? CheckState.Checked : CheckState.Unchecked; + } - [DefaultValue(CheckState.Unchecked), UpdatableProperty] - public CheckState CheckState + [DefaultValue(CheckState.Unchecked), UpdatableProperty] + public CheckState CheckState + { + get => checkState; + set { - get => checkState; - set - { - if (checkState == value) return; - - checkState = value; - UpdateAllTargets(nameof(CheckState), value); - CheckStateChanged?.Invoke(this, EventArgs.Empty); - } + if (checkState == value) return; + + checkState = value; + UpdateAllTargets(nameof(CheckState), value); + CheckStateChanged?.Invoke(this, EventArgs.Empty); } + } - [DefaultValue(true), UpdatableProperty] - public bool Enabled + [DefaultValue(true), UpdatableProperty] + public bool Enabled + { + get => ActionList != null ? enabled && ActionList.Enabled : enabled; + set { - get => ActionList != null ? enabled && ActionList.Enabled : enabled; - set - { - if (enabled == value) return; - enabled = value; - UpdateAllTargets(nameof(Enabled), value); - } + if (enabled == value) return; + enabled = value; + UpdateAllTargets(nameof(Enabled), value); } + } - [DefaultValue(false), UpdatableProperty] - public bool CheckOnClick + [DefaultValue(false), UpdatableProperty] + public bool CheckOnClick + { + get => checkOnClick; + set { - get => checkOnClick; - set - { - if (checkOnClick == value) return; - checkOnClick = value; - UpdateAllTargets(nameof(CheckOnClick), value); - } + if (checkOnClick == value) return; + checkOnClick = value; + UpdateAllTargets(nameof(CheckOnClick), value); } + } - [DefaultValue(Keys.None), UpdatableProperty, Localizable(true)] - public Keys ShortcutKeys + [DefaultValue(Keys.None), UpdatableProperty, Localizable(true)] + public Keys ShortcutKeys + { + get => shortcutKeys; + set { - get => shortcutKeys; - set - { - if (shortcutKeys == value) return; - shortcutKeys = value; - var converter = new KeysConverter(); - var text = (string)converter.ConvertTo(value, typeof(string)); - UpdateAllTargets(nameof(ToolStripMenuItem.ShortcutKeyDisplayString), text); - } + if (shortcutKeys == value) return; + shortcutKeys = value; + var converter = new KeysConverter(); + var text = (string)converter.ConvertTo(value, typeof(string)); + UpdateAllTargets(nameof(ToolStripMenuItem.ShortcutKeyDisplayString), text); } + } - [DefaultValue(true), UpdatableProperty] - public bool Visible + [DefaultValue(true), UpdatableProperty] + public bool Visible + { + get => visible; + set { - get => visible; - set - { - if (visible == value) return; - visible = value; - UpdateAllTargets(nameof(Visible), value); - } + if (visible == value) return; + visible = value; + UpdateAllTargets(nameof(Visible), value); } + } - protected ActionWorkingState WorkingState { get; set; } + protected ActionWorkingState WorkingState { get; set; } - [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] - protected internal UIActionsManager ActionList + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + protected internal UIActionsManager ActionList + { + get => actionList; + set { - get => actionList; - set - { - if (actionList != value) - actionList = value; - } + if (actionList != value) + actionList = value; } + } - public void DoRun() - { - if (!enabled) return; - - CancelEventArgs e = new CancelEventArgs(); - OnBeforeRun(e); - if (e.Cancel) return; - - OnRun(EventArgs.Empty); - OnAfterRun(EventArgs.Empty); - } + public void DoRun() + { + if (!enabled) return; - protected virtual void OnBeforeRun(CancelEventArgs e) => BeforeRun?.Invoke(this, e); - protected virtual void OnRun(EventArgs e) => Run?.Invoke(this, e); - protected virtual void OnAfterRun(EventArgs e) => AfterRun?.Invoke(this, e); - protected virtual void OnUpdate(EventArgs e) => Update?.Invoke(this, e); - protected virtual void OnRemovingTarget(Component extendee) { } - protected virtual void OnAddingTarget(Component extendee) { } + var e = new CancelEventArgs(); + OnBeforeRun(e); + if (e.Cancel) return; - protected virtual void AddHandler(Component extendee) - { - var clickEvent = extendee.GetType().GetEvent("Click"); - if (clickEvent != null) - clickEvent.AddEventHandler(extendee, clickEventHandler); + OnRun(EventArgs.Empty); + OnAfterRun(EventArgs.Empty); + } - var checkStateChangedEvent = extendee.GetType().GetEvent("CheckStateChanged"); - if (checkStateChangedEvent != null) - checkStateChangedEvent.AddEventHandler(extendee, checkStateChangedEventHandler); + protected virtual void OnBeforeRun(CancelEventArgs e) => BeforeRun?.Invoke(this, e); + protected virtual void OnRun(EventArgs e) => Run?.Invoke(this, e); + protected virtual void OnAfterRun(EventArgs e) => AfterRun?.Invoke(this, e); + protected virtual void OnUpdate(EventArgs e) => Update?.Invoke(this, e); + protected virtual void OnRemovingTarget(Component extendee) { } + protected virtual void OnAddingTarget(Component extendee) { } - if (extendee is ToolBarButton button) - button.Parent.ButtonClick += new ToolBarButtonClickEventHandler(toolbar_ButtonClick); - } + protected virtual void AddHandler(Component extendee) + { + var clickEvent = extendee.GetType().GetEvent("Click"); + clickEvent?.AddEventHandler(extendee, clickEventHandler); - protected virtual void RemoveHandler(Component extendee) - { - var clickEvent = extendee.GetType().GetEvent("Click"); - if (clickEvent != null) - clickEvent.RemoveEventHandler(extendee, clickEventHandler); + var checkStateChangedEvent = extendee.GetType().GetEvent("CheckStateChanged"); + checkStateChangedEvent?.AddEventHandler(extendee, checkStateChangedEventHandler); + } - var checkStateChangedEvent = extendee.GetType().GetEvent("CheckStateChanged"); - if (checkStateChangedEvent != null) - checkStateChangedEvent.RemoveEventHandler(extendee, checkStateChangedEventHandler); + protected virtual void RemoveHandler(Component extendee) + { + var clickEvent = extendee.GetType().GetEvent("Click"); + clickEvent?.RemoveEventHandler(extendee, clickEventHandler); - if (extendee is ToolBarButton button) - button.Parent.ButtonClick -= new ToolBarButtonClickEventHandler(toolbar_ButtonClick); - } + var checkStateChangedEvent = extendee.GetType().GetEvent("CheckStateChanged"); + checkStateChangedEvent?.RemoveEventHandler(extendee, checkStateChangedEventHandler); + } - internal void DoUpdate() => OnUpdate(EventArgs.Empty); + internal void DoUpdate() => OnUpdate(EventArgs.Empty); - internal void InternalRemoveTarget(Component extendee) - { - _ = targets.Remove(extendee); - RemoveHandler(extendee); - OnRemovingTarget(extendee); - } + internal void InternalRemoveTarget(Component extendee) + { + _ = targets.Remove(extendee); + RemoveHandler(extendee); + OnRemovingTarget(extendee); + } - internal void InternalAddTarget(Component extendee) - { - targets.Add(extendee); - RefreshState(extendee); - AddHandler(extendee); - OnAddingTarget(extendee); - } + internal void InternalAddTarget(Component extendee) + { + targets.Add(extendee); + RefreshState(extendee); + AddHandler(extendee); + OnAddingTarget(extendee); + } - internal void RefreshEnabledCheckState() - { - UpdateAllTargets(nameof(Enabled), Enabled); - UpdateAllTargets(nameof(CheckState), CheckState); - } + internal void RefreshEnabledCheckState() + { + UpdateAllTargets(nameof(Enabled), Enabled); + UpdateAllTargets(nameof(CheckState), CheckState); + } - internal void RunShortcut() - { - if (!Enabled) return; - if (CheckOnClick) Checked = !Checked; - DoRun(); - } + internal void RunShortcut() + { + if (!Enabled) return; + if (CheckOnClick) Checked = !Checked; + DoRun(); + } - protected void UpdateAllTargets(string propertyName, object value) - { - foreach (var component in targets) - UpdateProperty(component, propertyName, value); - } + protected void UpdateAllTargets(string propertyName, object value) + { + foreach (var component in targets) + UpdateProperty(component, propertyName, value); + } - private void UpdateProperty(Component target, string propertyName, object value) + private void UpdateProperty(Component target, string propertyName, object value) + { + WorkingState = ActionWorkingState.Driving; + try { - WorkingState = ActionWorkingState.Driving; - try - { - if (ActionList != null) - ActionList.TypeDescriptions[target.GetType()].SetValue(propertyName, target, value); - } - finally - { - WorkingState = ActionWorkingState.Listening; - } + ActionList?.TypeDescriptions[target.GetType()].SetValue(propertyName, target, value); } - - private void RefreshState(Component target) + finally { - var properties = TypeDescriptor.GetProperties(this, new[] { new UpdatablePropertyAttribute() }); - foreach (PropertyDescriptor property in properties) - UpdateProperty(target, property.Name, property.GetValue(this)); + WorkingState = ActionWorkingState.Listening; } + } - private void HandleClick(object sender, EventArgs e) - { - if (WorkingState != ActionWorkingState.Listening) return; - DoRun(); - } + private void RefreshState(Component target) + { + var properties = TypeDescriptor.GetProperties(this, new[] { new UpdatablePropertyAttribute() }); + foreach (PropertyDescriptor property in properties) + UpdateProperty(target, property.Name, property.GetValue(this)); + } - private void HandleCheckStateChanged(object sender, EventArgs e) - { - if (WorkingState != ActionWorkingState.Listening) return; - CheckState = (CheckState)ActionList.TypeDescriptions[sender.GetType()].GetValue("CheckState", sender); - } + private void HandleClick(object sender, EventArgs e) + { + if (WorkingState != ActionWorkingState.Listening) return; + DoRun(); + } - private void toolbar_ButtonClick(object sender, ToolBarButtonClickEventArgs e) - { - if (targets.Contains(e.Button)) HandleClick(e.Button, e); // called if sender is ToolBarButton - } + private void HandleCheckStateChanged(object sender, EventArgs e) + { + if (WorkingState != ActionWorkingState.Listening) return; + CheckState = (CheckState)ActionList.TypeDescriptions[sender.GetType()].GetValue(nameof(CheckState), sender); + } - private void target_Click(object sender, EventArgs e) => HandleClick(sender, e); // called if sender is Control + private void target_Click(object sender, EventArgs e) => HandleClick(sender, e); // called if sender is Control - private void target_CheckStateChanged(object sender, EventArgs e) => HandleCheckStateChanged(sender, e); - } + private void target_CheckStateChanged(object sender, EventArgs e) => HandleCheckStateChanged(sender, e); } diff --git a/src/Delta.CertXplorer.Core/UI/Actions/UIActionsManager.cs b/src/Delta.CertXplorer.Core/UI/Actions/UIActionsManager.cs index c3130dd..f9fafd6 100644 --- a/src/Delta.CertXplorer.Core/UI/Actions/UIActionsManager.cs +++ b/src/Delta.CertXplorer.Core/UI/Actions/UIActionsManager.cs @@ -14,175 +14,168 @@ using System.Drawing; using System.Diagnostics.CodeAnalysis; -namespace Delta.CertXplorer.UI.Actions +namespace Delta.CertXplorer.UI.Actions; + +[ProvideProperty("Action", typeof(Component))] +[ToolboxItemFilter("System.Windows.Forms")] +[ToolboxBitmap(typeof(UIAction), "UIActionsManager.bmp")] +[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Winforms conventions")] +public class UIActionsManager : Component, IExtenderProvider, ISupportInitialize { - [ProvideProperty("Action", typeof(Component))] - [ToolboxItemFilter("System.Windows.Forms")] - [ToolboxBitmap(typeof(UIAction), "UIActionsManager.bmp")] - [SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Winforms conventions")] - public class UIActionsManager : Component, IExtenderProvider, ISupportInitialize - { - private readonly Dictionary targets; - private ContainerControl containerControl = null; - private bool enabled = true; - private bool initializing = false; + private readonly Dictionary targets; + private ContainerControl containerControl = null; + private bool enabled = true; + private bool initializing = false; - public UIActionsManager() - { - Actions = new UIActionCollection(this); - targets = new Dictionary(); - TypeDescriptions = new Dictionary(); + public UIActionsManager() + { + Actions = new UIActionCollection(this); + targets = []; + TypeDescriptions = []; - if (!DesignMode) Application.Idle += new EventHandler(Application_Idle); - } + if (!DesignMode) Application.Idle += new EventHandler(Application_Idle); + } - public event EventHandler Update; + public event EventHandler Update; - [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] - public UIActionCollection Actions { get; } + [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] + public UIActionCollection Actions { get; } - [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public Dictionary TypeDescriptions { get; } + [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public Dictionary TypeDescriptions { get; } - [DefaultValue(true)] - public bool Enabled + [DefaultValue(true)] + public bool Enabled + { + get => enabled; + set { - get => enabled; - set - { - if (enabled == value) return; - enabled = value; - RefreshActions(); - } + if (enabled == value) return; + enabled = value; + RefreshActions(); } + } - public ContainerControl ContainerControl - { - get => containerControl; - set => SetContainerControl(value); - } + public ContainerControl ContainerControl + { + get => containerControl; + set => SetContainerControl(value); + } - [Browsable(false)] - public Control ActiveControl => GetActiveControl(containerControl); + [Browsable(false)] + public Control ActiveControl => GetActiveControl(containerControl); - public override ISite Site + public override ISite Site + { + get => base.Site; + set { - get => base.Site; - set - { - base.Site = value; - if (value != null && - value.GetService(typeof(IDesignerHost)) is IDesignerHost host && - host.RootComponent is ContainerControl control) - SetContainerControl(control); - } + base.Site = value; + if (value != null && + value.GetService(typeof(IDesignerHost)) is IDesignerHost host && + host.RootComponent is ContainerControl control) + SetContainerControl(control); } + } - [DefaultValue(null)] - public UIAction GetAction(Component extendee) => targets.ContainsKey(extendee) ? targets[extendee] : null; + public void BeginInit() => initializing = true; + public void EndInit() + { + initializing = false; + CheckInternalCollections(); + RefreshActions(); + } - public void SetAction(Component extendee, UIAction action) - { - if (!initializing) - { - if (extendee == null) throw new ArgumentNullException(nameof(extendee)); - if (action != null && action.ActionList != this) - throw new ArgumentException("The Action you selected is owned by another ActionList", nameof(action)); - } - - if (targets.ContainsKey(extendee)) - { - targets[extendee].InternalRemoveTarget(extendee); - _ = targets.Remove(extendee); - } - - if (action != null) - { - if (!TypeDescriptions.ContainsKey(extendee.GetType())) TypeDescriptions.Add( - extendee.GetType(), new UIActionTargetDescriptor(extendee.GetType())); - - targets.Add(extendee, action); - action.InternalAddTarget(extendee); - } - } + [DefaultValue(null)] + public UIAction GetAction(Component extendee) => + targets.TryGetValue(extendee, out var value) ? value : null; - protected virtual void OnUpdate(EventArgs eventArgs) + public void SetAction(Component extendee, UIAction action) + { + if (!initializing) { - Update?.Invoke(this, eventArgs); - foreach (var action in Actions) action.DoUpdate(); + ArgumentNullException.ThrowIfNull(extendee); + if (action != null && action.ActionList != this) + throw new ArgumentException("The Action you selected is owned by another ActionList", nameof(action)); } - protected virtual Type[] GetSupportedTypes() => new Type[] + if (targets.TryGetValue(extendee, out var value)) { - typeof(ButtonBase), - typeof(ToolStripButton), - typeof(ToolStripMenuItem), - typeof(ToolBarButton), - typeof(MenuItem) - }; - - private void RefreshActions() - { - if (DesignMode) return; - foreach (var action in Actions) action.RefreshEnabledCheckState(); + value.InternalRemoveTarget(extendee); + _ = targets.Remove(extendee); } - private void CheckInternalCollections() + if (action != null) { - foreach (var action in targets.Values) - { - if (!Actions.Contains(action) || action.ActionList != this) throw new InvalidOperationException( - "Action owned by another action list or invalid Action.ActionList"); - } + if (!TypeDescriptions.ContainsKey(extendee.GetType())) TypeDescriptions.Add( + extendee.GetType(), new UIActionTargetDescriptor(extendee.GetType())); + + targets.Add(extendee, action); + action.InternalAddTarget(extendee); } + } + + protected virtual void OnUpdate(EventArgs eventArgs) + { + Update?.Invoke(this, eventArgs); + foreach (var action in Actions) action.DoUpdate(); + } + + protected virtual Type[] GetSupportedTypes() => + [typeof(ButtonBase), typeof(ToolStripButton), typeof(ToolStripMenuItem)]; - private Control GetActiveControl(ContainerControl container) + private void RefreshActions() + { + if (DesignMode) return; + foreach (var action in Actions) action.RefreshEnabledCheckState(); + } + + private void CheckInternalCollections() + { + foreach (var action in targets.Values) { - if (container == null) return null; - return container.ActiveControl is ContainerControl cc ? GetActiveControl(cc) : container.ActiveControl; + if (!Actions.Contains(action) || action.ActionList != this) throw new InvalidOperationException( + "Action owned by another action list or invalid Action.ActionList"); } + } + + private void SetContainerControl(ContainerControl container) + { + if (containerControl == container) return; - private void SetContainerControl(ContainerControl container) + containerControl = container; + if (!DesignMode && containerControl is Form f) { - if (containerControl == container) return; - - containerControl = container; - if (!DesignMode && containerControl is Form f) - { - f.KeyPreview = true; - f.KeyDown += new KeyEventHandler(form_KeyDown); - } + f.KeyPreview = true; + f.KeyDown += new KeyEventHandler(form_KeyDown); } + } - private void Application_Idle(object sender, EventArgs e) => OnUpdate(EventArgs.Empty); + private void Application_Idle(object sender, EventArgs e) => OnUpdate(EventArgs.Empty); - private void form_KeyDown(object sender, KeyEventArgs e) + private void form_KeyDown(object sender, KeyEventArgs e) + { + foreach (var action in Actions) { - foreach (var action in Actions) - { - if (action.ShortcutKeys == e.KeyData) - action.RunShortcut(); - } + if (action.ShortcutKeys == e.KeyData) + action.RunShortcut(); } + } - bool IExtenderProvider.CanExtend(object extendee) + bool IExtenderProvider.CanExtend(object extendee) + { + var targetType = extendee.GetType(); + foreach (var type in GetSupportedTypes()) { - var targetType = extendee.GetType(); - foreach (var type in GetSupportedTypes()) - { - if (type.IsAssignableFrom(targetType)) return true; - } - - return false; + if (type.IsAssignableFrom(targetType)) return true; } - public void BeginInit() => initializing = true; + return false; + } - public void EndInit() - { - initializing = false; - CheckInternalCollections(); - RefreshActions(); - } + private static Control GetActiveControl(ContainerControl container) + { + if (container == null) return null; + return container.ActiveControl is ContainerControl cc ? GetActiveControl(cc) : container.ActiveControl; } } diff --git a/src/Delta.CertXplorer.Extensibility/Delta.CertXplorer.Extensibility.csproj b/src/Delta.CertXplorer.Extensibility/Delta.CertXplorer.Extensibility.csproj index da26312..146afaf 100644 --- a/src/Delta.CertXplorer.Extensibility/Delta.CertXplorer.Extensibility.csproj +++ b/src/Delta.CertXplorer.Extensibility/Delta.CertXplorer.Extensibility.csproj @@ -1,9 +1,8 @@ - net48 + net8.0-windows true - 9.0 false @@ -23,6 +22,7 @@ + all @@ -37,9 +37,5 @@ runtime; build; native; contentfiles; analyzers - - - - \ No newline at end of file diff --git a/src/Delta.CertXplorer/Delta.CertXplorer.csproj b/src/Delta.CertXplorer/Delta.CertXplorer.csproj index 245b627..ba31900 100644 --- a/src/Delta.CertXplorer/Delta.CertXplorer.csproj +++ b/src/Delta.CertXplorer/Delta.CertXplorer.csproj @@ -1,12 +1,11 @@ - net48 + net8.0-windows WinExe certx Delta.CertXplorer true - 9.0 safe.ico false @@ -76,11 +75,7 @@ - - - - - + diff --git a/src/Delta.Icao/Delta.Icao.csproj b/src/Delta.Icao/Delta.Icao.csproj index ec47ea1..d70bdf6 100644 --- a/src/Delta.Icao/Delta.Icao.csproj +++ b/src/Delta.Icao/Delta.Icao.csproj @@ -1,8 +1,7 @@ - net48 - 9.0 + net8.0 false diff --git a/src/Delta.SmartCard/Delta.SmartCard.csproj b/src/Delta.SmartCard/Delta.SmartCard.csproj index 38b85f7..bdba281 100644 --- a/src/Delta.SmartCard/Delta.SmartCard.csproj +++ b/src/Delta.SmartCard/Delta.SmartCard.csproj @@ -1,8 +1,7 @@ - net48 - 9.0 + net8.0 False diff --git a/src/Plugins/CertToolsPlugin/CertToolsPlugin.csproj b/src/Plugins/CertToolsPlugin/CertToolsPlugin.csproj index eec3192..2823eeb 100644 --- a/src/Plugins/CertToolsPlugin/CertToolsPlugin.csproj +++ b/src/Plugins/CertToolsPlugin/CertToolsPlugin.csproj @@ -1,9 +1,8 @@ - + - net48 + net8.0-windows true - 9.0 false @@ -21,7 +20,7 @@ Resources.Designer.cs - + True @@ -36,7 +35,7 @@ CertificateMmcTemplates.Designer.cs - + diff --git a/src/Plugins/CryptoHelperPlugin/CryptoHelperPlugin.csproj b/src/Plugins/CryptoHelperPlugin/CryptoHelperPlugin.csproj index 3e805f2..78af231 100644 --- a/src/Plugins/CryptoHelperPlugin/CryptoHelperPlugin.csproj +++ b/src/Plugins/CryptoHelperPlugin/CryptoHelperPlugin.csproj @@ -1,9 +1,8 @@ - + - net48 + net8.0-windows true - 9.0 false @@ -21,7 +20,7 @@ Resources.Designer.cs - + diff --git a/src/Plugins/PemPlugin/PemPlugin.csproj b/src/Plugins/PemPlugin/PemPlugin.csproj index 358819c..f1b7322 100644 --- a/src/Plugins/PemPlugin/PemPlugin.csproj +++ b/src/Plugins/PemPlugin/PemPlugin.csproj @@ -1,9 +1,8 @@ - + - net48 + net8.0-windows true - 9.0 false diff --git a/src/Plugins/PluralSightSelfCertPlugin/PluralSightSelfCertPlugin.csproj b/src/Plugins/PluralSightSelfCertPlugin/PluralSightSelfCertPlugin.csproj index 4104fba..e5a9a13 100644 --- a/src/Plugins/PluralSightSelfCertPlugin/PluralSightSelfCertPlugin.csproj +++ b/src/Plugins/PluralSightSelfCertPlugin/PluralSightSelfCertPlugin.csproj @@ -1,9 +1,8 @@ - + - net48 + net8.0-windows true - 9.0 false diff --git a/src/Plugins/ThirdParty/Pluralsight.Crypto/Pluralsight.Crypto.csproj b/src/Plugins/ThirdParty/Pluralsight.Crypto/Pluralsight.Crypto.csproj index 3d16e1d..e993b2c 100644 --- a/src/Plugins/ThirdParty/Pluralsight.Crypto/Pluralsight.Crypto.csproj +++ b/src/Plugins/ThirdParty/Pluralsight.Crypto/Pluralsight.Crypto.csproj @@ -1,11 +1,9 @@ - net48 + net8.0-windows true - 9.0 false - @@ -24,8 +22,4 @@ - - - - \ No newline at end of file diff --git a/src/Tests/CapiNetTestApp/CapiNetTestApp.csproj b/src/Tests/CapiNetTestApp/CapiNetTestApp.csproj index 1889f72..37c8057 100644 --- a/src/Tests/CapiNetTestApp/CapiNetTestApp.csproj +++ b/src/Tests/CapiNetTestApp/CapiNetTestApp.csproj @@ -2,9 +2,8 @@ WinExe - net48 + net8.0-windows true - 9.0 False diff --git a/src/UnitTests/UnitTests.Delta.CapiNet/UnitTests.Delta.CapiNet.csproj b/src/UnitTests/UnitTests.Delta.CapiNet/UnitTests.Delta.CapiNet.csproj index 3545d01..e6e6b06 100644 --- a/src/UnitTests/UnitTests.Delta.CapiNet/UnitTests.Delta.CapiNet.csproj +++ b/src/UnitTests/UnitTests.Delta.CapiNet/UnitTests.Delta.CapiNet.csproj @@ -1,10 +1,9 @@ - net48 + net8.0 UnitTests.Delta.CapiNet Delta.CapiNet - 9.0 False