diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..ba036e609 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,233 @@ +# Remove the line below if you want to inherit .editorconfig settings from higher directories +root = true + +# C# files +[*.cs] + +#### Guidelines #### +guidelines = 120 + +#### Core EditorConfig Options #### + +# Indentation and spacing +indent_size = 4 +indent_style = space +tab_width = 4 + +# New line preferences +insert_final_newline = true + +#### .NET Coding Conventions #### + +# Organize usings +dotnet_separate_import_directive_groups = false +dotnet_sort_system_directives_first = false + +# this. and Me. preferences +dotnet_style_qualification_for_event = false:suggestion +dotnet_style_qualification_for_field = false:suggestion +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 = always_for_clarity:suggestion +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion +dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion + +# Modifier preferences +dotnet_style_require_accessibility_modifiers = always:warning + +# Expression-level preferences +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_object_initializer = false:suggestion +dotnet_style_prefer_auto_properties = true:suggestion +dotnet_style_prefer_compound_assignment = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_simplified_interpolation = true:suggestion + +# Field preferences +dotnet_style_readonly_field = true:suggestion + +# Parameter preferences +dotnet_code_quality_unused_parameters = all:suggestion + +#### C# Coding Conventions #### + +# var preferences +csharp_style_var_elsewhere = false:suggestion +csharp_style_var_for_built_in_types = false:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion + +# Expression-bodied members +csharp_style_expression_bodied_accessors = when_on_single_line:suggestion +csharp_style_expression_bodied_constructors = when_on_single_line:suggestion +csharp_style_expression_bodied_indexers = when_on_single_line:suggestion +csharp_style_expression_bodied_lambdas = when_on_single_line:suggestion +csharp_style_expression_bodied_local_functions = when_on_single_line:suggestion +csharp_style_expression_bodied_methods = when_on_single_line:suggestion +csharp_style_expression_bodied_operators = when_on_single_line:suggestion +csharp_style_expression_bodied_properties = when_on_single_line:suggestion + +# Pattern matching preferences +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_prefer_switch_expression = true:suggestion + +# Null-checking preferences +csharp_style_conditional_delegate_call = true:suggestion + +# Modifier preferences +csharp_prefer_static_local_function = true:suggestion +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion + +# Code-block preferences +csharp_prefer_braces = true:suggestion +csharp_prefer_simple_using_statement = true:suggestion + +# Expression-level preferences +csharp_prefer_simple_default_expression = true:suggestion +csharp_style_deconstructed_variable_declaration = true:suggestion +csharp_style_inlined_variable_declaration = true:suggestion +csharp_style_namespace_declarations = file_scoped:suggestion +csharp_style_pattern_local_over_anonymous_function = false:suggestion +csharp_style_prefer_index_operator = true:suggestion +csharp_style_prefer_range_operator = true:suggestion +csharp_style_throw_expression = true:suggestion +csharp_style_unused_value_assignment_preference = discard_variable:suggestion +csharp_style_unused_value_expression_statement_preference = discard_variable:silent + +# 'using' directive preferences +csharp_using_directive_placement = outside_namespace:suggestion + +#### 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 = one_less_than_current +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.public_protected_or_internal_field_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.public_protected_or_internal_field_should_be_pascal_case.symbols = public_protected_or_internal_field +dotnet_naming_rule.public_protected_or_internal_field_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 + +dotnet_naming_rule.constant_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.constant_should_be_pascal_case.symbols = constant +dotnet_naming_rule.constant_should_be_pascal_case.style = pascal_case + +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.private__field_should_be_begin_with__.severity = suggestion +dotnet_naming_rule.private__field_should_be_begin_with__.symbols = private__field +dotnet_naming_rule.private__field_should_be_begin_with__.style = begin_with__ + +# 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.public_protected_or_internal_field.applicable_kinds = field +dotnet_naming_symbols.public_protected_or_internal_field.applicable_accessibilities = public, internal, protected, protected_internal +dotnet_naming_symbols.public_protected_or_internal_field.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 = + +dotnet_naming_symbols.private__field.applicable_kinds = field +dotnet_naming_symbols.private__field.applicable_accessibilities = private, private_protected +dotnet_naming_symbols.private__field.required_modifiers = + +dotnet_naming_symbols.constant.applicable_kinds = field +dotnet_naming_symbols.constant.applicable_accessibilities = * +dotnet_naming_symbols.constant.required_modifiers = const + +# 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 + +dotnet_naming_style.begin_with__.required_prefix = _ +dotnet_naming_style.begin_with__.required_suffix = +dotnet_naming_style.begin_with__.word_separator = +dotnet_naming_style.begin_with__.capitalization = camel_case + +# License header +file_header_template = Copyright (c) ZeroC, Inc. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fcd79a3d9..35a791cc6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,6 +85,10 @@ jobs: working-directory: ice-demos/csharp run: ${{ runner.os == 'Windows' && 'MSBuild' || 'dotnet msbuild' }} /m msbuild/ice.proj + - name: Run .NET format + run: dotnet format --verify-no-changes "./ice-demos/csharp/C# NET demos.sln" + if: runner.os == 'Linux' + - name: Build Java Demos on ${{ matrix.os }} timeout-minutes: 20 working-directory: ice-demos/java diff --git a/.globalconfig b/.globalconfig new file mode 100644 index 000000000..adbb3215c --- /dev/null +++ b/.globalconfig @@ -0,0 +1,265 @@ +is_global = true + +# CA2007: Consider calling ConfigureAwait on the awaited task +dotnet_diagnostic.CA2007.severity = none + +# CA1416: Validate platform compatibility +# QUIC is nominally supported only on Windows, Linux, and macOS. +dotnet_diagnostic.CA1416.severity = none + +# CA1848: Use the LoggerMessage delegates +dotnet_diagnostic.CA1848.severity = none + +# CA1849: Call async methods when in an async method +dotnet_diagnostic.CA1849.severity = suggestion + +# IDE0130: Namespace does not match folder structure +# We use ExampleName{Client, Server} instead of {Client, Server}. +dotnet_diagnostic.IDE0130.severity = none + +# SA0001: All diagnostics of XML documentation comments has been disabled due to the current project configuration. +dotnet_diagnostic.SA0001.severity = none + +# CA1001: Types that own disposable fields should be disposable +dotnet_diagnostic.CA1001.severity = warning + +# CA1002: Do not expose generic lists +dotnet_diagnostic.CA1002.severity = none + +# CA1008: Enums should have zero value +dotnet_diagnostic.CA1008.severity = none + +# CA1014: Mark assemblies with CLSCompliant +dotnet_diagnostic.CA1014.severity = none + +# CA1028: Enum Storage should be Int32 +dotnet_diagnostic.CA1028.severity = none + +# CA1031: Do not catch general exception types +dotnet_diagnostic.CA1031.severity = none + +# CA1043: Use Integral Or String Argument For Indexers +dotnet_diagnostic.CA1043.severity = none + +# CA1032: Implement standard exception constructors +dotnet_diagnostic.CA1032.severity = none + +# CA1033: Interface methods should be callable by child types +dotnet_diagnostic.CA1033.severity = none + +# CA1034: Nested types should not be visible +dotnet_diagnostic.CA1034.severity = none + +# CA1051: Do not declare visible instance fields +dotnet_diagnostic.CA1051.severity = none + +# CA1062: Validate arguments of public methods +dotnet_diagnostic.CA1062.severity = none + +# CA1303: Do not pass literals as localized parameters +dotnet_diagnostic.CA1303.severity = none + +# CA1308: Normalize strings to uppercase +dotnet_diagnostic.CA1308.severity = none + +# CA1508: Avoid dead conditional code, getting too many false positives +dotnet_diagnostic.CA1508.severity = none + +# CA1711: Identifiers should not have incorrect suffix +dotnet_diagnostic.CA1711.severity = none + +# CA1716: Identifiers should not match keywords +dotnet_diagnostic.CA1716.severity = none + +# CA1717: Only FlagsAttribute enums should have plural names +dotnet_diagnostic.CA1717.severity = warning + +# CA1720: Identifier contains type name +dotnet_diagnostic.CA1720.severity = none + +# CA1724: Type names should not match namespaces +dotnet_diagnostic.CA1724.severity = none + +# CA1819: Properties should not return arrays +dotnet_diagnostic.CA1819.severity = none + +# CA1847: Use char literal for a single character lookup +dotnet_diagnostic.CA1847.severity = warning + +# CA1851: Possible multiple enumerations of 'IEnumerable' collection +dotnet_diagnostic.CA1851.severity = none + +# CA1852: Seal internal types +dotnet_diagnostic.CA1852.severity = none + +# CA2000: Dispose objects before losing scope +dotnet_diagnostic.CA2000.severity = warning + +# CA2008: Do not create tasks without passing a TaskScheduler +dotnet_diagnostic.CA2008.severity = none + +# CA2009: Do not call ToImmutableCollection on an ImmutableCollection value +dotnet_diagnostic.CA2009.severity = warning + +# CA2011: Avoid infinite recursion +dotnet_diagnostic.CA2011.severity = warning + +# CA2012: Use ValueTasks correctly +dotnet_diagnostic.CA2012.severity = warning + +# CA2013: Do not use ReferenceEquals with value types +dotnet_diagnostic.CA2013.severity = warning + +# CA2014: Do not use stackalloc in loops +dotnet_diagnostic.CA2014.severity = warning + +# CA2015: Do not define finalizers for types derived from MemoryManager +dotnet_diagnostic.CA2015.severity = warning + +# CA2016: Forward the 'CancellationToken' parameter to methods +dotnet_diagnostic.CA2016.severity = warning + +# CA2200: Rethrow to preserve stack details +dotnet_diagnostic.CA2200.severity = warning + +# CA2201: Do not raise reserved exception types +dotnet_diagnostic.CA2201.severity = none + +# CA2208: Instantiate argument exceptions correctly +dotnet_diagnostic.CA2208.severity = warning +dotnet_code_quality.CA2208.api_surface = public + +# CA2211: Non-constant fields should not be visible +dotnet_diagnostic.CA2211.severity = none + +# CA2227: Collection properties should be read only +dotnet_diagnostic.CA2227.severity = none + +# CA2241: Provide correct arguments to formatting methods +dotnet_diagnostic.CA2241.severity = warning + +# CA2242: Test for NaN correctly +dotnet_diagnostic.CA2242.severity = warning + +# CA2243: Attribute string literals should parse correctly +dotnet_diagnostic.CA2243.severity = warning + +# CA2244: Do not duplicate indexed element initializations +dotnet_diagnostic.CA2244.severity = warning + +# CA2245: Do not assign a property to itself +dotnet_diagnostic.CA2245.severity = warning + +# CA2246: Assigning symbol and its member in the same statement +dotnet_diagnostic.CA2246.severity = warning + +# CA2247: Argument passed to TaskCompletionSource constructor should be TaskCreationOptions enum instead of TaskContinuationOptions enum +dotnet_diagnostic.CA2247.severity = warning + +# CA2248: Provide correct 'enum' argument to 'Enum.HasFlag' +dotnet_diagnostic.CA2248.severity = warning + +# CA2249: Consider using 'string.Contains' instead of 'string.IndexOf' +dotnet_diagnostic.CA2249.severity = warning + +# CA2250: Use 'ThrowIfCancellationRequested' +dotnet_diagnostic.CA2250.severity = warning + +# CA2251: Use 'string.Equals' +dotnet_diagnostic.CA2251.severity = warning + +# CA5350: Do Not Use Weak Cryptographic Algorithms +dotnet_diagnostic.CA5350.severity = warning + +# CA5351: Do Not Use Broken Cryptographic Algorithms +dotnet_diagnostic.CA5351.severity = warning + +# SA1000: Spacing around keywords +dotnet_diagnostic.SA1000.severity = warning + +# SA1001: Commas should not be preceded by whitespace +dotnet_diagnostic.SA1001.severity = warning + +# SA1010: Opening square brackets should be spaced correctly +dotnet_diagnostic.SA1010.severity = none + +# SA1013: Closing brace should not be preceded by a space +dotnet_diagnostic.SA1013.severity = warning + +# SA1014: Opening generic brackets should not be preceded by a space +dotnet_diagnostic.SA1014.severity = warning + +# SA1101: Prefix local calls with this +dotnet_diagnostic.SA1101.severity = none + +# SA1118: The parameter spans multiple lines +dotnet_diagnostic.SA1118.severity = none + +# SA1122: Use string.Empty for empty strings +dotnet_diagnostic.SA1122.severity = none + +# SA1127: Generic type constraints should be on their own line +dotnet_diagnostic.SA1127.severity = none + +# SA1129: Do not use default value type constructor +dotnet_diagnostic.SA1129.severity = none + +# SA1200: A C# using directive is placed outside of a namespace element +dotnet_diagnostic.SA1200.severity = none + +# SA1201: A field should not follow a property +dotnet_diagnostic.SA1201.severity = none + +# SA1208: Using directives for System should appear before other using directives +dotnet_diagnostic.SA1208.severity = none + +# SA1214: Readonly fields should appear before non-readonly fields +dotnet_diagnostic.SA1214.severity = none + +# SA1309: Field should not begin with an underscore +dotnet_diagnostic.SA1309.severity = none + +# SA1312: Variable should begin with lower-case letter +dotnet_diagnostic.SA1312.severity = none + +# SA1401: Field should be private +dotnet_diagnostic.SA1401.severity = none + +# SA1402: File may only contain a single type +dotnet_diagnostic.SA1402.severity = none + +# SA1405: Debug.Assert should provide message text +dotnet_diagnostic.SA1405.severity = none + +# SA1413: Use trailing comma in multi-line initializers +dotnet_diagnostic.SA1413.severity = none + +# SA1414: Tuple types in signatures should have element names +dotnet_diagnostic.SA1414.severity = none + +# SA1512: Single-line comments should not be followed by blank line +dotnet_diagnostic.SA1512.severity = none + +# SA1513: Closing brace should be followed by blank line +dotnet_diagnostic.SA1513.severity = none + +# SA1515: Single-line comment should be preceded by blank line +dotnet_diagnostic.SA1515.severity = none + +# SA1625: Element documentation should not be copied and pasted +dotnet_diagnostic.SA1625.severity = none + +# SA1642: Element should be documented +dotnet_diagnostic.SA1642.severity = none + +# SA1649: File name should match first type name +dotnet_diagnostic.SA1649.severity = none + +# VSSpell001: VSSpell analyzer produces many false positives +dotnet_diagnostic.VSSpell001.severity = none + +# Use primary constructor +dotnet_diagnostic.IDE0290.severity = none + +# CA1859: use concrete types when possible for improved performance +dotnet_diagnostic.CA1859.severity = none diff --git a/csharp/Directory.Build.props b/csharp/Directory.Build.props index 57601790c..4d0434d79 100644 --- a/csharp/Directory.Build.props +++ b/csharp/Directory.Build.props @@ -1,6 +1,13 @@ - + - net6.0 + net8.0 + true + + + enable + + true diff --git a/csharp/Glacier2/callback/CallbackI.cs b/csharp/Glacier2/callback/CallbackI.cs index aab8bf81f..0ced708ea 100644 --- a/csharp/Glacier2/callback/CallbackI.cs +++ b/csharp/Glacier2/callback/CallbackI.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public sealed class CallbackI : CallbackDisp_ +internal sealed class CallbackI : CallbackDisp_ { public override void initiateCallback(CallbackReceiverPrx proxy, Ice.Current current) { @@ -14,7 +11,7 @@ public override void initiateCallback(CallbackReceiverPrx proxy, Ice.Current cur { proxy.callback(); } - catch(System.Exception ex) + catch (System.Exception ex) { Console.Error.WriteLine(ex); } diff --git a/csharp/Glacier2/callback/CallbackReceiverI.cs b/csharp/Glacier2/callback/CallbackReceiverI.cs index 97302bfbb..389620071 100644 --- a/csharp/Glacier2/callback/CallbackReceiverI.cs +++ b/csharp/Glacier2/callback/CallbackReceiverI.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public sealed class CallbackReceiverI : CallbackReceiverDisp_ +internal sealed class CallbackReceiverI : CallbackReceiverDisp_ { public override void callback(Ice.Current current) { diff --git a/csharp/Glacier2/callback/Client.cs b/csharp/Glacier2/callback/Client.cs index ef57032e0..836c06d0e 100644 --- a/csharp/Glacier2/callback/Client.cs +++ b/csharp/Glacier2/callback/Client.cs @@ -1,13 +1,9 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; using System.Diagnostics; -using System.Collections.Generic; -public class Client +internal class Client { public static int Main(string[] args) { @@ -15,24 +11,18 @@ public static int Main(string[] args) try { - // // The new communicator is automatically destroyed (disposed) at the end of the // using statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // The communicator initialization removes all Ice-related arguments from args + if (args.Length > 0) { - // - // The communicator initialization removes all Ice-related arguments from args - // - if (args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } catch (Exception ex) @@ -44,18 +34,14 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { var router = Glacier2.RouterPrxHelper.checkedCast(communicator.getDefaultRouter()); Glacier2.SessionPrx session; - // // Loop until we have successfully create a session. - // - while(true) + while (true) { - // // Prompt the user for the credentials to create the session. - // Console.WriteLine("This demo accepts any user-id / password combination."); string id; @@ -65,7 +51,7 @@ private static int run(Ice.Communicator communicator) Console.Write("user id: "); Console.Out.Flush(); id = Console.In.ReadLine(); - if(id == null) + if (id == null) { throw new Ice.CommunicatorDestroyedException(); } @@ -74,32 +60,30 @@ private static int run(Ice.Communicator communicator) Console.Write("password: "); Console.Out.Flush(); pw = Console.In.ReadLine(); - if(pw == null) + if (pw == null) { throw new Ice.CommunicatorDestroyedException(); } pw = pw.Trim(); } - catch(System.IO.IOException ex) + catch (System.IO.IOException ex) { Console.WriteLine(ex.StackTrace.ToString()); continue; } - // // Try to create a session and break the loop if succeed, // otherwise try again after printing the error message. - // try { session = router.createSession(id, pw); break; } - catch(Glacier2.PermissionDeniedException ex) + catch (Glacier2.PermissionDeniedException ex) { Console.WriteLine("permission denied:\n" + ex.reason); } - catch(Glacier2.CannotCreateSessionException ex) + catch (Glacier2.CannotCreateSessionException ex) { Console.WriteLine("cannot create session:\n" + ex.reason); } @@ -110,13 +94,11 @@ private static int run(Ice.Communicator communicator) Debug.Assert(connection != null); connection.setCloseCallback(_ => Console.WriteLine("The Glacier2 session has been destroyed.")); - // // The Glacier2 router routes bidirectional calls to objects in the client only // when these objects have the correct Glacier2-issued category. The purpose of // the callbackReceiverFakeIdent is to demonstrate this. // // The Identity name is not checked by the server any value can be used. - // Ice.Identity callbackReceiverIdent = new Ice.Identity(System.Guid.NewGuid().ToString(), router.getCategoryForClient()); Ice.Identity callbackReceiverFakeIdent = @@ -128,9 +110,7 @@ private static int run(Ice.Communicator communicator) CallbackPrx batchOneway = CallbackPrxHelper.uncheckedCast(twoway.ice_batchOneway()); var adapter = communicator.createObjectAdapterWithRouter("", router); - // // Callback will never be called for a fake identity. - // adapter.add(new CallbackReceiverI(), callbackReceiverFakeIdent); CallbackReceiverPrx twowayR = CallbackReceiverPrxHelper.uncheckedCast( @@ -139,11 +119,9 @@ private static int run(Ice.Communicator communicator) adapter.activate(); CallbackReceiverPrx onewayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_oneway()); - menu(); + Menu(); - // // Client REPL - // string line = null; string @override = null; bool fake = false; @@ -152,40 +130,40 @@ private static int run(Ice.Communicator communicator) Console.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); - if(line == null) + if (line == null) { break; } - if(line.Equals("t")) + if (line.Equals("t")) { twoway.initiateCallback(twowayR); } - else if(line.Equals("o")) + else if (line.Equals("o")) { Dictionary context = new Dictionary(); - if(@override != null) + if (@override != null) { context["_ovrd"] = @override; } oneway.initiateCallback(onewayR, context); } - else if(line.Equals("O")) + else if (line.Equals("O")) { Dictionary context = new Dictionary(); context["_fwd"] = "O"; - if(@override != null) + if (@override != null) { context["_ovrd"] = @override; } batchOneway.initiateCallback(onewayR, context); } - else if(line.Equals("f")) + else if (line.Equals("f")) { batchOneway.ice_flushBatchRequests(); } - else if(line.Equals("v")) + else if (line.Equals("v")) { - if(@override == null) + if (@override == null) { @override = "some_value"; Console.WriteLine("override context field is now `" + @override + "'"); @@ -196,11 +174,11 @@ private static int run(Ice.Communicator communicator) Console.WriteLine("override context field is empty"); } } - else if(line.Equals("F")) + else if (line.Equals("F")) { fake = !fake; - if(fake) + if (fake) { twowayR = CallbackReceiverPrxHelper.uncheckedCast( twowayR.ice_identity(callbackReceiverFakeIdent)); @@ -218,30 +196,30 @@ private static int run(Ice.Communicator communicator) Console.WriteLine("callback receiver identity: " + Ice.Util.identityToString(twowayR.ice_getIdentity())); } - else if(line.Equals("s")) + else if (line.Equals("s")) { twoway.shutdown(); } - else if(line.Equals("x")) + else if (line.Equals("x")) { // Nothing to do } - else if(line.Equals("?")) + else if (line.Equals("?")) { - menu(); + Menu(); } else { Console.WriteLine("unknown command `" + line + "'"); - menu(); + Menu(); } } - while(!line.Equals("x")); + while (!line.Equals("x")); return 0; } - private static void menu() + private static void Menu() { Console.WriteLine( "usage:\n" + diff --git a/csharp/Glacier2/callback/Server.cs b/csharp/Glacier2/callback/Server.cs index b2c094a01..01cfbd781 100644 --- a/csharp/Glacier2/callback/Server.cs +++ b/csharp/Glacier2/callback/Server.cs @@ -1,10 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; - -public class Server +internal class Server { public static int Main(string[] args) { @@ -12,32 +8,26 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.server")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.server"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Callback.Server"); - adapter.add(new CallbackI(), Ice.Util.stringToIdentity("callback")); - adapter.activate(); - communicator.waitForShutdown(); - } + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Callback.Server"); + adapter.add(new CallbackI(), Ice.Util.stringToIdentity("callback")); + adapter.activate(); + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/Glacier2/callback/msbuild/client/client.csproj b/csharp/Glacier2/callback/msbuild/client/client.csproj index 189b7eb96..6303b3be1 100644 --- a/csharp/Glacier2/callback/msbuild/client/client.csproj +++ b/csharp/Glacier2/callback/msbuild/client/client.csproj @@ -19,5 +19,14 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/csharp/Glacier2/callback/msbuild/server/server.csproj b/csharp/Glacier2/callback/msbuild/server/server.csproj index 446a06c7d..55f778f8d 100644 --- a/csharp/Glacier2/callback/msbuild/server/server.csproj +++ b/csharp/Glacier2/callback/msbuild/server/server.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/async/Client.cs b/csharp/Ice/async/Client.cs index b85b6580d..d1b341f11 100644 --- a/csharp/Ice/async/Client.cs +++ b/csharp/Ice/async/Client.cs @@ -1,12 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -using System.Threading.Tasks; -public class Client +internal class Client { public static int Main(string[] args) { @@ -14,17 +10,15 @@ public static int Main(string[] args) try { - using (Ice.Communicator communicator = Ice.Util.initialize(ref args, "config.client")) + using Ice.Communicator communicator = Ice.Util.initialize(ref args, "config.client"); + if (args.Length > 0) { - if (args.Length > 0) - { - Console.WriteLine("too many arguments"); - status = 1; - } - else - { - status = Run(communicator); - } + Console.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } catch (Exception exception) diff --git a/csharp/Ice/async/HelloI.cs b/csharp/Ice/async/HelloI.cs index 3dfa8cd45..7c1e190d8 100644 --- a/csharp/Ice/async/HelloI.cs +++ b/csharp/Ice/async/HelloI.cs @@ -1,10 +1,5 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; -using System.Threading; -using System.Threading.Tasks; using Demo; internal class HelloI : HelloDisp_ diff --git a/csharp/Ice/async/Server.cs b/csharp/Ice/async/Server.cs index c18039b9f..4e6f550ec 100644 --- a/csharp/Ice/async/Server.cs +++ b/csharp/Ice/async/Server.cs @@ -1,11 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; -using System.Threading; - -public class Server +internal class Server { public static int Main(string[] args) { @@ -13,37 +8,33 @@ public static int Main(string[] args) try { - using (Ice.Communicator communicator = Ice.Util.initialize(ref args, "config.server")) + using Ice.Communicator communicator = Ice.Util.initialize(ref args, "config.server"); + if (args.Length > 0) { - if (args.Length > 0) - { - Console.WriteLine("too many arguments"); - status = 1; - } - else + Console.WriteLine("too many arguments"); + status = 1; + } + else + { + using var cts = new CancellationTokenSource(); + Console.CancelKeyPress += (sender, eventArgs) => { - using (var cts = new CancellationTokenSource()) - { - Console.CancelKeyPress += (sender, eventArgs) => - { - eventArgs.Cancel = true; - cts.Cancel(); - }; + eventArgs.Cancel = true; + cts.Cancel(); + }; - Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Hello"); - adapter.add(new HelloI(cts), Ice.Util.stringToIdentity("hello")); - adapter.activate(); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Hello"); + adapter.add(new HelloI(cts), Ice.Util.stringToIdentity("hello")); + adapter.activate(); - // cts is canceled by Ctrl+C or a shutdown request. - // With C# 7.1 and up, you should make Main async and call: await Task.Delay(-1, cts.Token) - cts.Token.WaitHandle.WaitOne(); + // cts is canceled by Ctrl+C or a shutdown request. + // With C# 7.1 and up, you should make Main async and call: await Task.Delay(-1, cts.Token) + cts.Token.WaitHandle.WaitOne(); - // Wait for all dispatches to complete before disposing cts since the dispatches use cts or - // cts.Token - communicator.shutdown(); - communicator.waitForShutdown(); - } - } + // Wait for all dispatches to complete before disposing cts since the dispatches use cts or + // cts.Token + communicator.shutdown(); + communicator.waitForShutdown(); } } catch (Exception exception) diff --git a/csharp/Ice/async/msbuild/client/client.csproj b/csharp/Ice/async/msbuild/client/client.csproj index 456e9310f..c3b19fbfd 100644 --- a/csharp/Ice/async/msbuild/client/client.csproj +++ b/csharp/Ice/async/msbuild/client/client.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/async/msbuild/server/server.csproj b/csharp/Ice/async/msbuild/server/server.csproj index ca37d8db5..bf3805177 100644 --- a/csharp/Ice/async/msbuild/server/server.csproj +++ b/csharp/Ice/async/msbuild/server/server.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/asyncInvocation/CalculatorI.cs b/csharp/Ice/asyncInvocation/CalculatorI.cs index 7b634c3d7..609f97872 100644 --- a/csharp/Ice/asyncInvocation/CalculatorI.cs +++ b/csharp/Ice/asyncInvocation/CalculatorI.cs @@ -1,9 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; internal class CalculatorI : CalculatorDisp_ { @@ -43,6 +40,6 @@ public override double squareRoot(int x, Ice.Current current) public override void shutdown(Ice.Current current) { - current.adapter.getCommunicator().shutdown(); + current.adapter.getCommunicator().shutdown(); } } diff --git a/csharp/Ice/asyncInvocation/Client.cs b/csharp/Ice/asyncInvocation/Client.cs index e2001bbcb..711ad5771 100644 --- a/csharp/Ice/asyncInvocation/Client.cs +++ b/csharp/Ice/asyncInvocation/Client.cs @@ -1,12 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -using System.Threading.Tasks; -public class Client +internal class Client { public static int Main(string[] args) { @@ -14,18 +10,16 @@ public static int Main(string[] args) try { - using (Ice.Communicator communicator = Ice.Util.initialize(ref args, "config.client")) + using Ice.Communicator communicator = Ice.Util.initialize(ref args, "config.client"); + if (args.Length > 0) { - if (args.Length > 0) - { - Console.WriteLine("too many arguments"); - status = 1; - } - else - { - // await in modern C# - status = RunAsync(communicator).GetAwaiter().GetResult(); - } + Console.WriteLine("too many arguments"); + status = 1; + } + else + { + // await in modern C# + status = RunAsync(communicator).GetAwaiter().GetResult(); } } catch (Exception exception) @@ -60,10 +54,8 @@ private static async Task RunAsync(Ice.Communicator communicator) Console.WriteLine("You cannot divide by 0"); } - // // Have the calculator find the hypotenuse of a triangle with side lengths of 6 and 8 // using the Pythagorean theorem. - // int[] squares = await Task.WhenAll(calculator.squareAsync(6), calculator.squareAsync(8)); double hypotenuse = await calculator.squareRootAsync(await calculator.addAsync(squares[0], squares[1])); diff --git a/csharp/Ice/asyncInvocation/Server.cs b/csharp/Ice/asyncInvocation/Server.cs index 57ad5987e..c1c32ecbe 100644 --- a/csharp/Ice/asyncInvocation/Server.cs +++ b/csharp/Ice/asyncInvocation/Server.cs @@ -1,10 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; - -public class Server +internal class Server { public static int Main(string[] args) { @@ -12,27 +8,25 @@ public static int Main(string[] args) try { - using (Ice.Communicator communicator = Ice.Util.initialize(ref args, "config.server")) + using Ice.Communicator communicator = Ice.Util.initialize(ref args, "config.server"); + if (args.Length > 0) { - if (args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + Console.CancelKeyPress += (sender, eventArgs) => { - Console.CancelKeyPress += (sender, eventArgs) => - { - eventArgs.Cancel = true; - communicator.shutdown(); - }; + eventArgs.Cancel = true; + communicator.shutdown(); + }; - Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Calculator"); - adapter.add(new CalculatorI(), Ice.Util.stringToIdentity("calculator")); - adapter.activate(); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Calculator"); + adapter.add(new CalculatorI(), Ice.Util.stringToIdentity("calculator")); + adapter.activate(); - communicator.waitForShutdown(); - } + communicator.waitForShutdown(); } } catch (Exception exception) diff --git a/csharp/Ice/asyncInvocation/msbuild/client/client.csproj b/csharp/Ice/asyncInvocation/msbuild/client/client.csproj index fdfcc07c3..0a5ff50bc 100644 --- a/csharp/Ice/asyncInvocation/msbuild/client/client.csproj +++ b/csharp/Ice/asyncInvocation/msbuild/client/client.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/asyncInvocation/msbuild/server/server.csproj b/csharp/Ice/asyncInvocation/msbuild/server/server.csproj index b8d5222ed..a12c24147 100644 --- a/csharp/Ice/asyncInvocation/msbuild/server/server.csproj +++ b/csharp/Ice/asyncInvocation/msbuild/server/server.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/bidir/CallbackReceiverI.cs b/csharp/Ice/bidir/CallbackReceiverI.cs index b8ef57af4..b3f83e35e 100644 --- a/csharp/Ice/bidir/CallbackReceiverI.cs +++ b/csharp/Ice/bidir/CallbackReceiverI.cs @@ -1,13 +1,11 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -public sealed class CallbackReceiverI : CallbackReceiverDisp_ +internal sealed class CallbackReceiverI : CallbackReceiverDisp_ { public override void callback(int num, Ice.Current current) { - System.Console.Out.WriteLine("received callback #" + num); + System.Console.Out.WriteLine("received callback #" + num); } } diff --git a/csharp/Ice/bidir/CallbackSenderI.cs b/csharp/Ice/bidir/CallbackSenderI.cs index f660dd1e7..9480d88c2 100644 --- a/csharp/Ice/bidir/CallbackSenderI.cs +++ b/csharp/Ice/bidir/CallbackSenderI.cs @@ -1,23 +1,12 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -using System.Collections.Generic; -class CallbackSenderI : CallbackSenderDisp_ +internal class CallbackSenderI(Ice.Communicator communicator) : CallbackSenderDisp_ { - public CallbackSenderI(Ice.Communicator communicator) + public void Destroy() { - _communicator = communicator; - _destroy = false; - _clients = new List(); - } - - public void destroy() - { - lock(this) + lock (this) { Console.Out.WriteLine("destroying callback sender"); _destroy = true; @@ -27,7 +16,7 @@ public void destroy() public override void addClient(CallbackReceiverPrx client, Ice.Current current) { - lock(this) + lock (this) { Console.Out.WriteLine("adding client `" + Ice.Util.identityToString(client.ice_getIdentity()) + "'"); _clients.Add((CallbackReceiverPrx)client.ice_fixed(current.con)); @@ -37,41 +26,41 @@ public override void addClient(CallbackReceiverPrx client, Ice.Current current) public void Run() { int num = 0; - lock(this) + lock (this) { - while(!_destroy) + while (!_destroy) { System.Threading.Monitor.Wait(this, 2000); - if(!_destroy && _clients.Count > 0) + if (!_destroy && _clients.Count > 0) { ++num; - // // Invoke callback on all clients; it's safe to do it with _mutex locked // because Ice guarantees these async invocations never block the calling thread. // // The exception callback, if called, is called by an Ice thread, and never the // calling thread. - foreach(var c in _clients) + foreach (var c in _clients) { - c.callbackAsync(num).ContinueWith(t => { - if(t.Exception != null) - { - removeClient(c, t.Exception.InnerException); - } - }); + c.callbackAsync(num).ContinueWith(t => + { + if (t.Exception != null) + { + RemoveClient(c, t.Exception.InnerException); + } + }); } } } } } - private void removeClient(CallbackReceiverPrx c, Exception ex) + private void RemoveClient(CallbackReceiverPrx c, Exception ex) { - lock(this) + lock (this) { - if(_clients.Remove(c)) + if (_clients.Remove(c)) { Console.Error.WriteLine("removing client `" + Ice.Util.identityToString(c.ice_getIdentity()) + "':\n" + ex); @@ -79,7 +68,7 @@ private void removeClient(CallbackReceiverPrx c, Exception ex) } } - private Ice.Communicator _communicator; - private bool _destroy; - private List _clients; + private Ice.Communicator _communicator = communicator; + private bool _destroy = false; + private List _clients = new List(); } diff --git a/csharp/Ice/bidir/Client.cs b/csharp/Ice/bidir/Client.cs index 153dca612..96d17095e 100644 --- a/csharp/Ice/bidir/Client.cs +++ b/csharp/Ice/bidir/Client.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class Client +internal class Client { public static int Main(string[] args) { @@ -13,29 +10,23 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -44,35 +35,27 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { var server = CallbackSenderPrxHelper.checkedCast(communicator.propertyToProxy("CallbackSender.Proxy")); - if(server == null) + if (server == null) { Console.Error.WriteLine("invalid proxy"); return 1; } - // // Create an object adapter with no name and no endpoints for receiving callbacks // over bidirectional connections. - // var adapter = communicator.createObjectAdapter(""); - // // Register the callback receiver servant with the object adapter - // var proxy = CallbackReceiverPrxHelper.uncheckedCast(adapter.addWithUUID(new CallbackReceiverI())); - // // Associate the object adapter with the bidirectional connection. - // server.ice_getConnection().setAdapter(adapter); - // // Provide the proxy of the callback receiver object to the server and wait for // shutdown. - // server.addClient(proxy); communicator.waitForShutdown(); return 0; diff --git a/csharp/Ice/bidir/Server.cs b/csharp/Ice/bidir/Server.cs index 401291cba..bd33cf8e2 100644 --- a/csharp/Ice/bidir/Server.cs +++ b/csharp/Ice/bidir/Server.cs @@ -1,11 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; -using System.Threading; - -public class Server +internal class Server { public static int Main(string[] args) { @@ -13,50 +8,44 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.server")) + using var communicator = Ice.Util.initialize(ref args, "config.server"); + if (args.Length > 0) { - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + // Shutdown the communicator on Ctrl+C or Ctrl+Break + // (shutdown always with Cancel = true) + Console.CancelKeyPress += (eventSender, eventArgs) => { - // - // Shutdown the communicator on Ctrl+C or Ctrl+Break - // (shutdown always with Cancel = true) - // - Console.CancelKeyPress += (eventSender, eventArgs) => - { - eventArgs.Cancel = true; - communicator.shutdown(); - }; + eventArgs.Cancel = true; + communicator.shutdown(); + }; - var adapter = communicator.createObjectAdapter("Callback.Server"); - var sender = new CallbackSenderI(communicator); - adapter.add(sender, Ice.Util.stringToIdentity("sender")); - adapter.activate(); + var adapter = communicator.createObjectAdapter("Callback.Server"); + var sender = new CallbackSenderI(communicator); + adapter.add(sender, Ice.Util.stringToIdentity("sender")); + adapter.activate(); - var t = new Thread(new ThreadStart(sender.Run)); - t.Start(); + var t = new Thread(new ThreadStart(sender.Run)); + t.Start(); - try - { - communicator.waitForShutdown(); - } - finally - { - sender.destroy(); - t.Join(); - } + try + { + communicator.waitForShutdown(); + } + finally + { + sender.Destroy(); + t.Join(); } } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/Ice/bidir/msbuild/client/client.csproj b/csharp/Ice/bidir/msbuild/client/client.csproj index 00d79cdbd..9d5e39125 100644 --- a/csharp/Ice/bidir/msbuild/client/client.csproj +++ b/csharp/Ice/bidir/msbuild/client/client.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/bidir/msbuild/server/server.csproj b/csharp/Ice/bidir/msbuild/server/server.csproj index 3cca75f38..75f69473c 100644 --- a/csharp/Ice/bidir/msbuild/server/server.csproj +++ b/csharp/Ice/bidir/msbuild/server/server.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/callback/CallbackReceiverI.cs b/csharp/Ice/callback/CallbackReceiverI.cs index e9be871d2..f2d9415f4 100644 --- a/csharp/Ice/callback/CallbackReceiverI.cs +++ b/csharp/Ice/callback/CallbackReceiverI.cs @@ -1,10 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -public sealed class CallbackReceiverI : CallbackReceiverDisp_ +internal sealed class CallbackReceiverI : CallbackReceiverDisp_ { public override void callback(Ice.Current current) { diff --git a/csharp/Ice/callback/CallbackSenderI.cs b/csharp/Ice/callback/CallbackSenderI.cs index bb2f74c90..b79bcfd2c 100644 --- a/csharp/Ice/callback/CallbackSenderI.cs +++ b/csharp/Ice/callback/CallbackSenderI.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public sealed class CallbackSenderI : CallbackSenderDisp_ +internal sealed class CallbackSenderI : CallbackSenderDisp_ { public override void initiateCallback(CallbackReceiverPrx proxy, Ice.Current current) { @@ -14,7 +11,7 @@ public override void initiateCallback(CallbackReceiverPrx proxy, Ice.Current cur { proxy.callback(); } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); } @@ -27,7 +24,7 @@ public override void shutdown(Ice.Current current) { current.adapter.getCommunicator().shutdown(); } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); } diff --git a/csharp/Ice/callback/Client.cs b/csharp/Ice/callback/Client.cs index 1c2481399..4bb4f7333 100644 --- a/csharp/Ice/callback/Client.cs +++ b/csharp/Ice/callback/Client.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class Client +internal class Client { public static int Main(string[] args) { @@ -13,24 +10,18 @@ public static int Main(string[] args) try { - // // The new communicator is automatically destroyed (disposed) at the end of the // using statement - // - using (var communicator = Ice.Util.initialize(ref args, "config.client")) + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // The communicator initialization removes all Ice-related arguments from args + if (args.Length > 0) { - // - // The communicator initialization removes all Ice-related arguments from args - // - if (args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } catch (Exception ex) @@ -42,7 +33,7 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { var sender = CallbackSenderPrxHelper.checkedCast(communicator.propertyToProxy("CallbackSender.Proxy"). ice_twoway().ice_secure(false)); @@ -59,7 +50,7 @@ private static int run(Ice.Communicator communicator) var receiver = CallbackReceiverPrxHelper.uncheckedCast( adapter.createProxy(Ice.Util.stringToIdentity("callbackReceiver"))); - menu(); + Menu(); string line = null; do @@ -87,12 +78,12 @@ private static int run(Ice.Communicator communicator) } else if (line.Equals("?")) { - menu(); + Menu(); } else { Console.Out.WriteLine("unknown command `" + line + "'"); - menu(); + Menu(); } } catch (Exception ex) @@ -105,7 +96,7 @@ private static int run(Ice.Communicator communicator) return 0; } - private static void menu() + private static void Menu() { Console.Out.Write("usage:\n" + "t: send callback\n" diff --git a/csharp/Ice/callback/Server.cs b/csharp/Ice/callback/Server.cs index f092fd891..3a0c70928 100644 --- a/csharp/Ice/callback/Server.cs +++ b/csharp/Ice/callback/Server.cs @@ -1,10 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; - -public class Server +internal class Server { public static int Main(string[] args) { @@ -12,32 +8,26 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.server")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.server"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - var adapter = communicator.createObjectAdapter("Callback.Server"); - adapter.add(new CallbackSenderI(), Ice.Util.stringToIdentity("callbackSender")); - adapter.activate(); - communicator.waitForShutdown(); - } + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + var adapter = communicator.createObjectAdapter("Callback.Server"); + adapter.add(new CallbackSenderI(), Ice.Util.stringToIdentity("callbackSender")); + adapter.activate(); + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/Ice/callback/msbuild/client/client.csproj b/csharp/Ice/callback/msbuild/client/client.csproj index 00d79cdbd..9d5e39125 100644 --- a/csharp/Ice/callback/msbuild/client/client.csproj +++ b/csharp/Ice/callback/msbuild/client/client.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/callback/msbuild/server/server.csproj b/csharp/Ice/callback/msbuild/server/server.csproj index 3cca75f38..75f69473c 100644 --- a/csharp/Ice/callback/msbuild/server/server.csproj +++ b/csharp/Ice/callback/msbuild/server/server.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/context/Client.cs b/csharp/Ice/context/Client.cs index 448767cac..0d75f724c 100644 --- a/csharp/Ice/context/Client.cs +++ b/csharp/Ice/context/Client.cs @@ -1,13 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -using System.Collections.Generic; - -public class Client +internal class Client { public static int Main(string[] args) { @@ -15,27 +10,21 @@ public static int Main(string[] args) try { - // // The new communicator is automatically destroyed (disposed) at the end of the // using statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // The communicator initialization removes all Ice-related arguments from args + if (args.Length > 0) { - // - // The communicator initialization removes all Ice-related arguments from args - // - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -44,16 +33,16 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { var proxy = ContextPrxHelper.checkedCast(communicator.propertyToProxy("Context.Proxy")); - if(proxy == null) + if (proxy == null) { Console.Error.WriteLine("invalid proxy"); return 1; } - menu(); + Menu(); string line = null; do @@ -63,25 +52,25 @@ private static int run(Ice.Communicator communicator) Console.Out.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); - if(line == null) + if (line == null) { break; } - if(line.Equals("1")) + if (line.Equals("1")) { proxy.call(); } - else if(line.Equals("2")) + else if (line.Equals("2")) { var ctx = new Dictionary() { { "type", "Explicit" } }; proxy.call(ctx); } - else if(line.Equals("3")) + else if (line.Equals("3")) { var ctx = new Dictionary() { { "type", "Per-Proxy" } }; ContextPrxHelper.uncheckedCast(proxy.ice_context(ctx)).call(); } - else if(line.Equals("4")) + else if (line.Equals("4")) { var ic = communicator.getImplicitContext(); var ctx = new Dictionary() { { "type", "Implicit" } }; @@ -90,25 +79,25 @@ private static int run(Ice.Communicator communicator) ctx = new Dictionary(); ic.setContext(ctx); } - else if(line.Equals("s")) + else if (line.Equals("s")) { proxy.shutdown(); } - else if(line.Equals("x")) + else if (line.Equals("x")) { // Nothing to do } - else if(line.Equals("?")) + else if (line.Equals("?")) { - menu(); + Menu(); } else { Console.WriteLine("unknown command `" + line + "'"); - menu(); + Menu(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); } @@ -118,7 +107,7 @@ private static int run(Ice.Communicator communicator) return 0; } - private static void menu() + private static void Menu() { Console.Write( "usage:\n" + diff --git a/csharp/Ice/context/ContextI.cs b/csharp/Ice/context/ContextI.cs index 0ae6f99dc..8372eca9a 100644 --- a/csharp/Ice/context/ContextI.cs +++ b/csharp/Ice/context/ContextI.cs @@ -1,16 +1,13 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class ContextI : ContextDisp_ +internal class ContextI : ContextDisp_ { public override void call(Ice.Current current) { Console.Out.Write("Type = "); - if(current.ctx.ContainsKey("type")) + if (current.ctx.ContainsKey("type")) { Console.Out.Write(current.ctx["type"]); } diff --git a/csharp/Ice/context/Server.cs b/csharp/Ice/context/Server.cs index c9b4d6c72..e7d5a5168 100644 --- a/csharp/Ice/context/Server.cs +++ b/csharp/Ice/context/Server.cs @@ -1,10 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; - -public class Server +internal class Server { public static int Main(string[] args) { @@ -12,32 +8,26 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.server")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.server"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - var adapter = communicator.createObjectAdapter("Context"); - adapter.add(new ContextI(), Ice.Util.stringToIdentity("context")); - adapter.activate(); - communicator.waitForShutdown(); - } + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + var adapter = communicator.createObjectAdapter("Context"); + adapter.add(new ContextI(), Ice.Util.stringToIdentity("context")); + adapter.activate(); + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/Ice/context/msbuild/client/client.csproj b/csharp/Ice/context/msbuild/client/client.csproj index 6992888c5..0ccc51a8b 100644 --- a/csharp/Ice/context/msbuild/client/client.csproj +++ b/csharp/Ice/context/msbuild/client/client.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/context/msbuild/server/server.csproj b/csharp/Ice/context/msbuild/server/server.csproj index fc501eaff..e89a58dc4 100644 --- a/csharp/Ice/context/msbuild/server/server.csproj +++ b/csharp/Ice/context/msbuild/server/server.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/hello/Client.cs b/csharp/Ice/hello/Client.cs index fbbb173f7..9e87ddd07 100644 --- a/csharp/Ice/hello/Client.cs +++ b/csharp/Ice/hello/Client.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class Client +internal class Client { public static int Main(string[] args) { @@ -13,27 +10,21 @@ public static int Main(string[] args) try { - // // The new communicator is automatically destroyed (disposed) at the end of the // using statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // The communicator initialization removes all Ice-related arguments from args + if (args.Length > 0) { - // - // The communicator initialization removes all Ice-related arguments from args - // - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -42,11 +33,11 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { HelloPrx twoway = HelloPrxHelper.checkedCast( communicator.propertyToProxy("Hello.Proxy").ice_twoway().ice_secure(false)); - if(twoway == null) + if (twoway == null) { Console.Error.WriteLine("invalid proxy"); return 1; @@ -54,13 +45,13 @@ private static int run(Ice.Communicator communicator) HelloPrx oneway = (HelloPrx)twoway.ice_oneway(); HelloPrx batchOneway = (HelloPrx)twoway.ice_batchOneway(); HelloPrx datagram = (HelloPrx)twoway.ice_datagram(); - HelloPrx batchDatagram =(HelloPrx)twoway.ice_batchDatagram(); + HelloPrx batchDatagram = (HelloPrx)twoway.ice_batchDatagram(); bool secure = false; int timeout = -1; int delay = 0; - menu(); + Menu(); string line = null; do @@ -70,25 +61,25 @@ private static int run(Ice.Communicator communicator) Console.Out.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); - if(line == null) + if (line == null) { break; } - if(line.Equals("t")) + if (line.Equals("t")) { twoway.sayHello(delay); } - else if(line.Equals("o")) + else if (line.Equals("o")) { oneway.sayHello(delay); } - else if(line.Equals("O")) + else if (line.Equals("O")) { batchOneway.sayHello(delay); } - else if(line.Equals("d")) + else if (line.Equals("d")) { - if(secure) + if (secure) { Console.WriteLine("secure datagrams are not supported"); } @@ -97,9 +88,9 @@ private static int run(Ice.Communicator communicator) datagram.sayHello(delay); } } - else if(line.Equals("D")) + else if (line.Equals("D")) { - if(secure) + if (secure) { Console.WriteLine("secure datagrams are not supported"); } @@ -108,17 +99,17 @@ private static int run(Ice.Communicator communicator) batchDatagram.sayHello(delay); } } - else if(line.Equals("f")) + else if (line.Equals("f")) { batchOneway.ice_flushBatchRequests(); - if(!secure) + if (!secure) { batchDatagram.ice_flushBatchRequests(); } } - else if(line.Equals("T")) + else if (line.Equals("T")) { - if(timeout == -1) + if (timeout == -1) { timeout = 2000; } @@ -131,7 +122,7 @@ private static int run(Ice.Communicator communicator) oneway = (HelloPrx)oneway.ice_invocationTimeout(timeout); batchOneway = (HelloPrx)batchOneway.ice_invocationTimeout(timeout); - if(timeout == -1) + if (timeout == -1) { Console.WriteLine("timeout is now switched off"); } @@ -140,9 +131,9 @@ private static int run(Ice.Communicator communicator) Console.WriteLine("timeout is now set to 2000ms"); } } - else if(line.Equals("P")) + else if (line.Equals("P")) { - if(delay == 0) + if (delay == 0) { delay = 2500; } @@ -151,7 +142,7 @@ private static int run(Ice.Communicator communicator) delay = 0; } - if(delay == 0) + if (delay == 0) { Console.WriteLine("server delay is now deactivated"); } @@ -160,7 +151,7 @@ private static int run(Ice.Communicator communicator) Console.WriteLine("server delay is now set to 2500ms"); } } - else if(line.Equals("S")) + else if (line.Equals("S")) { secure = !secure; @@ -170,7 +161,7 @@ private static int run(Ice.Communicator communicator) datagram = (HelloPrx)datagram.ice_secure(secure); batchDatagram = (HelloPrx)batchDatagram.ice_secure(secure); - if(secure) + if (secure) { Console.WriteLine("secure mode is now on"); } @@ -179,25 +170,25 @@ private static int run(Ice.Communicator communicator) Console.WriteLine("secure mode is now off"); } } - else if(line.Equals("s")) + else if (line.Equals("s")) { twoway.shutdown(); } - else if(line.Equals("x")) + else if (line.Equals("x")) { // Nothing to do } - else if(line.Equals("?")) + else if (line.Equals("?")) { - menu(); + Menu(); } else { Console.WriteLine("unknown command `" + line + "'"); - menu(); + Menu(); } } - catch(System.Exception ex) + catch (System.Exception ex) { Console.Error.WriteLine(ex); } @@ -207,7 +198,7 @@ private static int run(Ice.Communicator communicator) return 0; } - private static void menu() + private static void Menu() { Console.Write( "usage:\n" + diff --git a/csharp/Ice/hello/HelloI.cs b/csharp/Ice/hello/HelloI.cs index 9f3f493eb..1c2364f06 100644 --- a/csharp/Ice/hello/HelloI.cs +++ b/csharp/Ice/hello/HelloI.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class HelloI : HelloDisp_ +internal class HelloI : HelloDisp_ { public override void sayHello(int delay, Ice.Current current) { - if(delay > 0) + if (delay > 0) { System.Threading.Thread.Sleep(delay); } diff --git a/csharp/Ice/hello/Server.cs b/csharp/Ice/hello/Server.cs index 6809b6367..d9553d13e 100644 --- a/csharp/Ice/hello/Server.cs +++ b/csharp/Ice/hello/Server.cs @@ -1,10 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; - -public class Server +internal class Server { public static int Main(string[] args) { @@ -12,32 +8,26 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.server")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.server"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - var adapter = communicator.createObjectAdapter("Hello"); - adapter.add(new HelloI(), Ice.Util.stringToIdentity("hello")); - adapter.activate(); - communicator.waitForShutdown(); - } + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + var adapter = communicator.createObjectAdapter("Hello"); + adapter.add(new HelloI(), Ice.Util.stringToIdentity("hello")); + adapter.activate(); + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/Ice/hello/msbuild/client/client.csproj b/csharp/Ice/hello/msbuild/client/client.csproj index 456e9310f..c3b19fbfd 100644 --- a/csharp/Ice/hello/msbuild/client/client.csproj +++ b/csharp/Ice/hello/msbuild/client/client.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/hello/msbuild/server/server.csproj b/csharp/Ice/hello/msbuild/server/server.csproj index f21a23c9a..c12295699 100644 --- a/csharp/Ice/hello/msbuild/server/server.csproj +++ b/csharp/Ice/hello/msbuild/server/server.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/interceptor/AuthenticatorI.cs b/csharp/Ice/interceptor/AuthenticatorI.cs index 2c73f6bbe..da4c41220 100644 --- a/csharp/Ice/interceptor/AuthenticatorI.cs +++ b/csharp/Ice/interceptor/AuthenticatorI.cs @@ -1,13 +1,9 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -using System.Collections.Generic; using System.Security.Cryptography; -class AuthenticatorI : AuthenticatorDisp_ +internal class AuthenticatorI : AuthenticatorDisp_ { internal AuthenticatorI() { @@ -17,51 +13,43 @@ internal AuthenticatorI() public override string getToken(Ice.Current current) { - // // Generate a random 32 character long token. - // string chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; char[] tokenValue = new char[32]; byte[] bytes = new byte[tokenValue.Length]; _rand.GetBytes(bytes); - for(var i = 0; i < bytes.Length; ++i) + for (var i = 0; i < bytes.Length; ++i) { tokenValue[i] = chars[bytes[i] % chars.Length]; } string token = new string(tokenValue); - // // By default tokens are valid for 30 seconds after being issued. - // DateTimeOffset expireTime = DateTimeOffset.UtcNow.AddSeconds(30); - lock(_tokenStore) + lock (_tokenStore) { _tokenStore.Add(token, expireTime); } return token; } - internal void validateToken(string tokenValue) + internal void ValidateToken(string tokenValue) { - lock(_tokenStore) + lock (_tokenStore) { - // // Remove any expired tokens. - // - foreach(string token in new List(_tokenStore.Keys)) + foreach (string token in new List(_tokenStore.Keys)) { - if(_tokenStore[token] <= DateTimeOffset.UtcNow) + if (_tokenStore[token] <= DateTimeOffset.UtcNow) { _tokenStore.Remove(token); } } - // // We assume if the client passed a token, but there's no // stored values matching it, that it must of expired. - // - if(!_tokenStore.ContainsKey(tokenValue)) + if (!_tokenStore.ContainsKey(tokenValue)) { throw new TokenExpiredException(); } diff --git a/csharp/Ice/interceptor/Client.cs b/csharp/Ice/interceptor/Client.cs index a6466f71a..d906c5030 100644 --- a/csharp/Ice/interceptor/Client.cs +++ b/csharp/Ice/interceptor/Client.cs @@ -1,39 +1,30 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -class Client +internal class Client { - static int Main(string[] args) + private static int Main(string[] args) { int status = 0; try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // The communicator initialization removes all Ice-related arguments from args. + if (args.Length > 0) { - // - // The communicator intialization removes all Ice-related arguments from args. - // - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -42,22 +33,22 @@ static int Main(string[] args) return status; } - static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { var thermostat = ThermostatPrxHelper.checkedCast(communicator.propertyToProxy("Thermostat.Proxy")); - if(thermostat == null) + if (thermostat == null) { Console.Error.WriteLine("invalid thermostat proxy"); return 1; } var authenticator = AuthenticatorPrxHelper.checkedCast(communicator.propertyToProxy("Authenticator.Proxy")); - if(authenticator == null) + if (authenticator == null) { Console.Error.WriteLine("invalid authenticator proxy"); return 1; } - menu(); + Menu(); try { @@ -68,7 +59,7 @@ static int run(Ice.Communicator communicator) Console.Out.Flush(); line = Console.ReadLine(); - switch(line) + switch (line) { case "1": { @@ -83,15 +74,15 @@ static int run(Ice.Communicator communicator) thermostat.setTemp(float.Parse(Console.ReadLine())); Console.Out.WriteLine("New temperature is " + thermostat.getTemp()); } - catch(FormatException) + catch (FormatException) { Console.Error.WriteLine("Provided temperature is not a parsable float."); } - catch(TokenExpiredException) + catch (TokenExpiredException) { Console.Error.WriteLine("Failed to set temperature. Token expired!"); } - catch(AuthorizationException) + catch (AuthorizationException) { Console.Error.WriteLine("Failed to set temperature. Access denied!"); } @@ -99,22 +90,18 @@ static int run(Ice.Communicator communicator) } case "3": { - // // Request an access token from the server's authentication object. - // string token = authenticator.getToken(); Console.Out.WriteLine("Successfully retrieved access token: \"" + token + "\""); - // // Add the access token to the communicator's context, so it will be // sent along with every request made through it. - // communicator.getImplicitContext().put("accessToken", token); break; } case "4": { var context = communicator.getImplicitContext(); - if(context.containsKey("accessToken")) + if (context.containsKey("accessToken")) { context.remove("accessToken"); } @@ -130,11 +117,11 @@ static int run(Ice.Communicator communicator) { thermostat.shutdown(); } - catch(TokenExpiredException) + catch (TokenExpiredException) { Console.Error.WriteLine("Failed to shutdown thermostat. Token expired!"); } - catch(AuthorizationException) + catch (AuthorizationException) { Console.Error.WriteLine("Failed to shutdown thermostat. Access denied!"); } @@ -147,24 +134,24 @@ static int run(Ice.Communicator communicator) } case "?": { - menu(); + Menu(); break; } default: { Console.Out.WriteLine("Unknown command `" + line + "'"); - menu(); + Menu(); break; } } } - while(!line.Equals("x")); + while (!line.Equals("x")); } - catch(System.IO.IOException ex) + catch (System.IO.IOException ex) { Console.Error.WriteLine(ex); } - catch(Ice.LocalException ex) + catch (Ice.LocalException ex) { Console.Error.WriteLine(ex); } @@ -172,7 +159,7 @@ static int run(Ice.Communicator communicator) return 0; } - private static void menu() + private static void Menu() { Console.Out.Write( "usage:\n" + diff --git a/csharp/Ice/interceptor/InterceptorI.cs b/csharp/Ice/interceptor/InterceptorI.cs index 6fc1b264a..e54f4974b 100644 --- a/csharp/Ice/interceptor/InterceptorI.cs +++ b/csharp/Ice/interceptor/InterceptorI.cs @@ -1,13 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using Ice; -using System.Collections.Generic; -using System.Threading.Tasks; -class InterceptorI : Ice.Object +internal class InterceptorI : Ice.Object { internal InterceptorI(Ice.Object servant, AuthenticatorI authenticator, HashSet securedOperations) { @@ -16,28 +11,22 @@ internal InterceptorI(Ice.Object servant, AuthenticatorI authenticator, HashSet< _securedOperations = securedOperations; } - public ValueTask dispatchAsync(IncomingRequest request) + public ValueTask dispatchAsync(Ice.IncomingRequest request) { var current = request.current; - // // Check if the operation requires authorization to invoke. - // - if(_securedOperations.Contains(current.operation)) + if (_securedOperations.Contains(current.operation)) { - // // Validate the client's access token before dispatching to the servant. // 'validateToken' throws an exception if the token is invalid or expired. - // string tokenValue; - if(current.ctx.TryGetValue("accessToken", out tokenValue)) + if (current.ctx.TryGetValue("accessToken", out tokenValue)) { - _authenticator.validateToken(tokenValue); + _authenticator.ValidateToken(tokenValue); } else { - // // If the client didn't include an accessToken, throw an exception. - // throw new AuthorizationException(); } } diff --git a/csharp/Ice/interceptor/Server.cs b/csharp/Ice/interceptor/Server.cs index 3dbbf831a..d5e46f389 100644 --- a/csharp/Ice/interceptor/Server.cs +++ b/csharp/Ice/interceptor/Server.cs @@ -1,67 +1,51 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; -using System.Collections.Generic; - -class Server +internal class Server { - static int Main(string[] args) + private static int Main(string[] args) { int status = 0; try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.server")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - // We use separate object adapters for the authenticator and the thermostat in - // this demo, so each object has its own endpoints. This way accessibility can - // be fined tuned on each object separately, through firewall rules for example. - // It's implemented this way to illustrate best practices, even if the demo - // doesn't make use of it for simplicity's sake. + using var communicator = Ice.Util.initialize(ref args, "config.server"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - // - // Create an object adapter for the authenticator. - // - var authenticatorAdapter = communicator.createObjectAdapter("Authenticator"); - var authenticator = new AuthenticatorI(); - authenticatorAdapter.add(authenticator, Ice.Util.stringToIdentity("authenticator")); - authenticatorAdapter.activate(); - - // - // Set of all the operations to require authorization for. - // - HashSet securedOperations = new HashSet(new String[] {"setTemp", "shutdown"}); - // - // Create an object adapter for the thermostat. - // - var thermostatAdapter = communicator.createObjectAdapter("Thermostat"); - var interceptor = new InterceptorI(new ThermostatI(), authenticator, securedOperations); - thermostatAdapter.add(interceptor, Ice.Util.stringToIdentity("thermostat")); - thermostatAdapter.activate(); + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + // We use separate object adapters for the authenticator and the thermostat in + // this demo, so each object has its own endpoints. This way accessibility can + // be fined tuned on each object separately, through firewall rules for example. + // It's implemented this way to illustrate best practices, even if the demo + // doesn't make use of it for simplicity's sake. - communicator.waitForShutdown(); - } + // + // Create an object adapter for the authenticator. + var authenticatorAdapter = communicator.createObjectAdapter("Authenticator"); + var authenticator = new AuthenticatorI(); + authenticatorAdapter.add(authenticator, Ice.Util.stringToIdentity("authenticator")); + authenticatorAdapter.activate(); + + // Set of all the operations to require authorization for. + HashSet securedOperations = new HashSet(new string[] { "setTemp", "shutdown" }); + // Create an object adapter for the thermostat. + var thermostatAdapter = communicator.createObjectAdapter("Thermostat"); + var interceptor = new InterceptorI(new ThermostatI(), authenticator, securedOperations); + thermostatAdapter.add(interceptor, Ice.Util.stringToIdentity("thermostat")); + thermostatAdapter.activate(); + + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/Ice/interceptor/ThermostatI.cs b/csharp/Ice/interceptor/ThermostatI.cs index 40d5c129a..b5489374f 100644 --- a/csharp/Ice/interceptor/ThermostatI.cs +++ b/csharp/Ice/interceptor/ThermostatI.cs @@ -1,15 +1,12 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -class ThermostatI : ThermostatDisp_ +internal class ThermostatI : ThermostatDisp_ { public override float getTemp(Ice.Current current) { - lock(this) + lock (this) { return _temperature; } @@ -17,7 +14,7 @@ public override float getTemp(Ice.Current current) public override void setTemp(float temp, Ice.Current current) { - lock(this) + lock (this) { _temperature = temp; } diff --git a/csharp/Ice/interceptor/msbuild/client/client.csproj b/csharp/Ice/interceptor/msbuild/client/client.csproj index 1b5de1733..c31014890 100644 --- a/csharp/Ice/interceptor/msbuild/client/client.csproj +++ b/csharp/Ice/interceptor/msbuild/client/client.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/interceptor/msbuild/server/server.csproj b/csharp/Ice/interceptor/msbuild/server/server.csproj index 2ac215ee7..1f66e8c40 100644 --- a/csharp/Ice/interceptor/msbuild/server/server.csproj +++ b/csharp/Ice/interceptor/msbuild/server/server.csproj @@ -15,5 +15,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/invoke/Client.cs b/csharp/Ice/invoke/Client.cs index a3306cc56..3a42b8b1a 100644 --- a/csharp/Ice/invoke/Client.cs +++ b/csharp/Ice/invoke/Client.cs @@ -1,12 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -using System.Collections.Generic; -public class Client +internal class Client { public static int Main(string[] args) { @@ -14,27 +10,21 @@ public static int Main(string[] args) try { - // // The new communicator is automatically destroyed (disposed) at the end of the // using statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // The communicator initialization removes all Ice-related arguments from args + if (args.Length > 0) { - // - // The communicator initialization removes all Ice-related arguments from args - // - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -45,19 +35,19 @@ public static int Main(string[] args) private class ReadValueCallback { - public void invoke(Ice.Value obj) + public void Invoke(Ice.Value obj) { - this.obj = obj; + this.Obj = obj; } - internal Ice.Value obj; + internal Ice.Value Obj; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { var obj = communicator.propertyToProxy("Printer.Proxy"); - menu(); + Menu(); string line = null; do @@ -67,144 +57,129 @@ private static int run(Ice.Communicator communicator) Console.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); - if(line == null) + if (line == null) { break; } byte[] outParams; - if(line.Equals("1")) + if (line.Equals("1")) { - // // Marshal the in parameter. - // var outStream = new Ice.OutputStream(communicator); outStream.startEncapsulation(); outStream.writeString("The streaming API works!"); outStream.endEncapsulation(); - // // Invoke operation. - // - if(!obj.ice_invoke("printString", Ice.OperationMode.Normal, outStream.finished(), - out outParams)) + if (!obj.ice_invoke("printString", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { Console.Error.WriteLine("Unknown user exception"); } } - else if(line.Equals("2")) + else if (line.Equals("2")) { - // // Marshal the in parameter. - // var outStream = new Ice.OutputStream(communicator); outStream.startEncapsulation(); string[] arr = { "The", "streaming", "API", "works!" }; StringSeqHelper.write(outStream, arr); outStream.endEncapsulation(); - // // Invoke operation. - // - if(!obj.ice_invoke("printStringSequence", Ice.OperationMode.Normal, outStream.finished(), - out outParams)) + if (!obj.ice_invoke( + "printStringSequence", + Ice.OperationMode.Normal, + outStream.finished(), + out outParams)) { Console.Error.WriteLine("Unknown user exception"); } } - else if(line.Equals("3")) + else if (line.Equals("3")) { - // // Marshal the in parameter. - // var outStream = new Ice.OutputStream(communicator); outStream.startEncapsulation(); var dict = new Dictionary() { { "The", "streaming" }, - { "API", "works!"} + { "API", "works!" } }; StringDictHelper.write(outStream, dict); outStream.endEncapsulation(); - // // Invoke operation. - // - if(!obj.ice_invoke("printDictionary", Ice.OperationMode.Normal, outStream.finished(), - out outParams)) + if (!obj.ice_invoke( + "printDictionary", + Ice.OperationMode.Normal, + outStream.finished(), + out outParams)) { Console.Error.WriteLine("Unknown user exception"); } } - else if(line.Equals("4")) + else if (line.Equals("4")) { - // // Marshal the in parameter. - // var outStream = new Ice.OutputStream(communicator); outStream.startEncapsulation(); ColorHelper.write(outStream, Color.green); outStream.endEncapsulation(); - // // Invoke operation. - // - if(!obj.ice_invoke("printEnum", Ice.OperationMode.Normal, outStream.finished(), out outParams)) + if (!obj.ice_invoke("printEnum", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { Console.Error.WriteLine("Unknown user exception"); } } - else if(line.Equals("5")) + else if (line.Equals("5")) { - // // Marshal the in parameter. - // var outStream = new Ice.OutputStream(communicator); outStream.startEncapsulation(); var s = new Structure("red", Color.red); Structure.ice_write(outStream, s); outStream.endEncapsulation(); - // // Invoke operation. - // - if(!obj.ice_invoke("printStruct", Ice.OperationMode.Normal, outStream.finished(), - out outParams)) + if (!obj.ice_invoke( + "printStruct", + Ice.OperationMode.Normal, + outStream.finished(), + out outParams)) { Console.Error.WriteLine("Unknown user exception"); } } - else if(line.Equals("6")) + else if (line.Equals("6")) { - // // Marshal the in parameter. - // var outStream = new Ice.OutputStream(communicator); outStream.startEncapsulation(); Structure[] arr = { - new Structure("red", Color.red), - new Structure("green", Color.green), - new Structure("blue", Color.blue) + new("red", Color.red), + new("green", Color.green), + new("blue", Color.blue) }; StructureSeqHelper.write(outStream, arr); outStream.endEncapsulation(); - // // Invoke operation. - // - if(!obj.ice_invoke("printStructSequence", Ice.OperationMode.Normal, outStream.finished(), - out outParams)) + if (!obj.ice_invoke( + "printStructSequence", + Ice.OperationMode.Normal, + outStream.finished(), + out outParams)) { Console.Error.WriteLine("Unknown user exception"); } } - else if(line.Equals("7")) + else if (line.Equals("7")) { - // // Marshal the in parameter. - // Ice.OutputStream outStream = new Ice.OutputStream(communicator); outStream.startEncapsulation(); var c = new C(new Structure("blue", Color.blue)); @@ -212,44 +187,36 @@ private static int run(Ice.Communicator communicator) outStream.writePendingValues(); outStream.endEncapsulation(); - // // Invoke operation. - // - if(!obj.ice_invoke("printClass", Ice.OperationMode.Normal, outStream.finished(), out outParams)) + if (!obj.ice_invoke("printClass", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { Console.Error.WriteLine("Unknown user exception"); } } - else if(line.Equals("8")) + else if (line.Equals("8")) { - // // Invoke operation. - // - if(!obj.ice_invoke("getValues", Ice.OperationMode.Normal, null, out outParams)) + if (!obj.ice_invoke("getValues", Ice.OperationMode.Normal, null, out outParams)) { Console.Error.WriteLine("Unknown user exception"); continue; } - // // Unmarshal the results. - // var inStream = new Ice.InputStream(communicator, outParams); inStream.startEncapsulation(); var cb = new ReadValueCallback(); - inStream.readValue(cb.invoke); + inStream.readValue(cb.Invoke); var str = inStream.readString(); inStream.readPendingValues(); - var c = cb.obj as C; + var c = cb.Obj as C; Console.Error.WriteLine("Got string `" + str + "' and class: s.name=" + c.s.name + ", s.value=" + c.s.value); } - else if(line.Equals("9")) + else if (line.Equals("9")) { - // // Invoke operation. - // - if(obj.ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, null, out outParams)) + if (obj.ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, null, out outParams)) { Console.Error.WriteLine("Expected exception"); continue; @@ -261,45 +228,45 @@ private static int run(Ice.Communicator communicator) { inStream.throwException(); } - catch(PrintFailure) + catch (PrintFailure) { // Expected. } - catch(Ice.UserException) + catch (Ice.UserException) { Console.Error.WriteLine("Unknown user exception"); } inStream.endEncapsulation(); } - else if(line.Equals("s")) + else if (line.Equals("s")) { obj.ice_invoke("shutdown", Ice.OperationMode.Normal, null, out outParams); } - else if(line.Equals("x")) + else if (line.Equals("x")) { // Nothing to do. } - else if(line.Equals("?")) + else if (line.Equals("?")) { - menu(); + Menu(); } else { Console.Error.WriteLine("unknown command `" + line + "'"); - menu(); + Menu(); } } - catch(Ice.LocalException ex) + catch (Ice.LocalException ex) { Console.Error.WriteLine(ex); } } - while(!line.Equals("x")); + while (!line.Equals("x")); return 0; } - private static void menu() + private static void Menu() { Console.WriteLine( "usage:\n" + diff --git a/csharp/Ice/invoke/PrinterI.cs b/csharp/Ice/invoke/PrinterI.cs index 222135159..fd72da880 100644 --- a/csharp/Ice/invoke/PrinterI.cs +++ b/csharp/Ice/invoke/PrinterI.cs @@ -1,20 +1,17 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class PrinterI : Ice.Blobject +internal class PrinterI : Ice.Blobject { private class ReadValueCallback { - public void invoke(Ice.Value obj) + public void Invoke(Ice.Value obj) { - this.obj = obj; + this.Obj = obj; } - internal Ice.Value obj; + internal Ice.Value Obj; } public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Current current) @@ -25,24 +22,24 @@ public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Curre var communicator = current.adapter.getCommunicator(); Ice.InputStream inStream = null; - if(inParams.Length > 0) + if (inParams.Length > 0) { inStream = new Ice.InputStream(communicator, inParams); inStream.startEncapsulation(); } - if(current.operation.Equals("printString")) + if (current.operation.Equals("printString")) { var message = inStream.readString(); Console.WriteLine("Printing string `" + message + "'"); } - else if(current.operation.Equals("printStringSequence")) + else if (current.operation.Equals("printStringSequence")) { var seq = StringSeqHelper.read(inStream); Console.Write("Printing string sequence {"); - for(int i = 0; i < seq.Length; ++i) + for (int i = 0; i < seq.Length; ++i) { - if(i > 0) + if (i > 0) { Console.Write(", "); } @@ -50,14 +47,14 @@ public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Curre } Console.WriteLine("}"); } - else if(current.operation.Equals("printDictionary")) + else if (current.operation.Equals("printDictionary")) { var dict = StringDictHelper.read(inStream); Console.Write("Printing dictionary {"); bool first = true; - foreach(var e in dict) + foreach (var e in dict) { - if(!first) + if (!first) { Console.Write(", "); } @@ -66,23 +63,23 @@ public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Curre } Console.WriteLine("}"); } - else if(current.operation.Equals("printEnum")) + else if (current.operation.Equals("printEnum")) { var c = ColorHelper.read(inStream); Console.WriteLine("Printing enum " + c); } - else if(current.operation.Equals("printStruct")) + else if (current.operation.Equals("printStruct")) { var s = Structure.ice_read(inStream); Console.WriteLine("Printing struct: name=" + s.name + ", value=" + s.value); } - else if(current.operation.Equals("printStructSequence")) + else if (current.operation.Equals("printStructSequence")) { var seq = StructureSeqHelper.read(inStream); Console.Write("Printing struct sequence: {"); - for(int i = 0; i < seq.Length; ++i) + for (int i = 0; i < seq.Length; ++i) { - if(i > 0) + if (i > 0) { Console.Write(", "); } @@ -90,15 +87,15 @@ public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Curre } Console.WriteLine("}"); } - else if(current.operation.Equals("printClass")) + else if (current.operation.Equals("printClass")) { var cb = new ReadValueCallback(); - inStream.readValue(cb.invoke); + inStream.readValue(cb.Invoke); inStream.readPendingValues(); - var c = cb.obj as C; + var c = cb.Obj as C; Console.WriteLine("Printing class: s.name=" + c.s.name + ", s.value=" + c.s.value); } - else if(current.operation.Equals("getValues")) + else if (current.operation.Equals("getValues")) { var c = new C(new Structure("green", Color.green)); var outStream = new Ice.OutputStream(communicator); @@ -109,7 +106,7 @@ public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Curre outStream.endEncapsulation(); outParams = outStream.finished(); } - else if(current.operation.Equals("throwPrintFailure")) + else if (current.operation.Equals("throwPrintFailure")) { Console.WriteLine("Throwing PrintFailure"); var ex = new PrintFailure("paper tray empty"); @@ -120,7 +117,7 @@ public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Curre outParams = outStream.finished(); result = false; } - else if(current.operation.Equals("shutdown")) + else if (current.operation.Equals("shutdown")) { current.adapter.getCommunicator().shutdown(); } @@ -129,9 +126,7 @@ public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Curre throw new Ice.OperationNotExistException(current.id, current.facet, current.operation); } - // // Make sure we read all in parameters - // inStream.endEncapsulation(); return result; } diff --git a/csharp/Ice/invoke/Server.cs b/csharp/Ice/invoke/Server.cs index 73fc6f9f9..8ba535d23 100644 --- a/csharp/Ice/invoke/Server.cs +++ b/csharp/Ice/invoke/Server.cs @@ -1,10 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; - -public class Server +internal class Server { public static int Main(string[] args) { @@ -12,32 +8,26 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.server")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.server"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - var adapter = communicator.createObjectAdapter("Printer"); - adapter.add(new PrinterI(), Ice.Util.stringToIdentity("printer")); - adapter.activate(); - communicator.waitForShutdown(); - } + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + var adapter = communicator.createObjectAdapter("Printer"); + adapter.add(new PrinterI(), Ice.Util.stringToIdentity("printer")); + adapter.activate(); + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/Ice/invoke/msbuild/client/client.csproj b/csharp/Ice/invoke/msbuild/client/client.csproj index 3021d8e0f..541a4d607 100644 --- a/csharp/Ice/invoke/msbuild/client/client.csproj +++ b/csharp/Ice/invoke/msbuild/client/client.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/invoke/msbuild/server/server.csproj b/csharp/Ice/invoke/msbuild/server/server.csproj index 24dde6494..094d936a8 100644 --- a/csharp/Ice/invoke/msbuild/server/server.csproj +++ b/csharp/Ice/invoke/msbuild/server/server.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/latency/Client.cs b/csharp/Ice/latency/Client.cs index bb81d9ba0..20f836977 100644 --- a/csharp/Ice/latency/Client.cs +++ b/csharp/Ice/latency/Client.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class Client +internal class Client { public static int Main(string[] args) { @@ -13,29 +10,23 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -44,25 +35,23 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { PingPrx ping = PingPrxHelper.checkedCast(communicator.propertyToProxy("Ping.Proxy")); - if(ping == null) + if (ping == null) { Console.Error.WriteLine("invalid proxy"); return 1; } - // // A method needs to be invoked thousands of times before the JIT compiler // will convert it to native code. To ensure an accurate latency measurement, // we need to "warm up" the JIT compiler. - // { int reps = 20000; Console.Error.Write("warming up the JIT compiler..."); Console.Error.Flush(); - for(int i = 0; i < reps; i++) + for (int i = 0; i < reps; i++) { ping.ice_ping(); } diff --git a/csharp/Ice/latency/Server.cs b/csharp/Ice/latency/Server.cs index 18c270bee..688812bba 100644 --- a/csharp/Ice/latency/Server.cs +++ b/csharp/Ice/latency/Server.cs @@ -1,12 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; - -public class Server +internal class Server { - class PingI : Demo.PingDisp_ + private class PingI : Demo.PingDisp_ { } @@ -16,32 +12,26 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.server")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.server"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - var adapter = communicator.createObjectAdapter("Latency"); - adapter.add(new PingI(), Ice.Util.stringToIdentity("ping")); - adapter.activate(); - communicator.waitForShutdown(); - } + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + var adapter = communicator.createObjectAdapter("Latency"); + adapter.add(new PingI(), Ice.Util.stringToIdentity("ping")); + adapter.activate(); + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/Ice/latency/msbuild/client/client.csproj b/csharp/Ice/latency/msbuild/client/client.csproj index 9956002dc..b154a6fce 100644 --- a/csharp/Ice/latency/msbuild/client/client.csproj +++ b/csharp/Ice/latency/msbuild/client/client.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/latency/msbuild/server/server.csproj b/csharp/Ice/latency/msbuild/server/server.csproj index 8f72d93dc..b2f75f5be 100644 --- a/csharp/Ice/latency/msbuild/server/server.csproj +++ b/csharp/Ice/latency/msbuild/server/server.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/minimal/Client.cs b/csharp/Ice/minimal/Client.cs index 3df3ca101..579c626a0 100644 --- a/csharp/Ice/minimal/Client.cs +++ b/csharp/Ice/minimal/Client.cs @@ -1,25 +1,20 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; using Demo; -public class Client +internal class Client { public static int Main(string[] args) { try { - using(var communicator = Ice.Util.initialize(ref args)) - { - var hello = HelloPrxHelper.checkedCast( - communicator.stringToProxy("hello:default -h localhost -p 10000")); - hello.sayHello(); - } + using var communicator = Ice.Util.initialize(ref args); + var hello = HelloPrxHelper.checkedCast( + communicator.stringToProxy("hello:default -h localhost -p 10000")); + hello.sayHello(); return 0; } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); return 1; diff --git a/csharp/Ice/minimal/Printer.cs b/csharp/Ice/minimal/Printer.cs index e2ebac5da..bd70dba20 100644 --- a/csharp/Ice/minimal/Printer.cs +++ b/csharp/Ice/minimal/Printer.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; using Demo; /// Implements Slice interface `Hello` by printing messages. -public class Printer : HelloDisp_ +internal class Printer : HelloDisp_ { /// Prints a message to the standard output. + /// The current object of the corresponding incoming request. public override void sayHello(Ice.Current current) { Console.WriteLine("Hello World!"); diff --git a/csharp/Ice/minimal/Server.cs b/csharp/Ice/minimal/Server.cs index fe7852e27..4ce70c9af 100644 --- a/csharp/Ice/minimal/Server.cs +++ b/csharp/Ice/minimal/Server.cs @@ -1,31 +1,25 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; - -public class Server +internal class Server { public static int Main(string[] args) { try { - using(var communicator = Ice.Util.initialize(ref args)) + using var communicator = Ice.Util.initialize(ref args); + // Shut down the communicator on Ctrl+C or Ctrl+Break. + Console.CancelKeyPress += (sender, eventArgs) => { - // Shut down the communicator on Ctrl+C or Ctrl+Break. - Console.CancelKeyPress += (sender, eventArgs) => - { - eventArgs.Cancel = true; - communicator.shutdown(); - }; + eventArgs.Cancel = true; + communicator.shutdown(); + }; - var adapter = communicator.createObjectAdapterWithEndpoints("Hello", "default -h localhost -p 10000"); - adapter.add(new Printer(), Ice.Util.stringToIdentity("hello")); - adapter.activate(); - communicator.waitForShutdown(); - } + var adapter = communicator.createObjectAdapterWithEndpoints("Hello", "default -h localhost -p 10000"); + adapter.add(new Printer(), Ice.Util.stringToIdentity("hello")); + adapter.activate(); + communicator.waitForShutdown(); } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); return 1; diff --git a/csharp/Ice/minimal/msbuild/client/client.csproj b/csharp/Ice/minimal/msbuild/client/client.csproj index 456e9310f..c3b19fbfd 100644 --- a/csharp/Ice/minimal/msbuild/client/client.csproj +++ b/csharp/Ice/minimal/msbuild/client/client.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/minimal/msbuild/server/server.csproj b/csharp/Ice/minimal/msbuild/server/server.csproj index 6ea848d82..6467741f1 100644 --- a/csharp/Ice/minimal/msbuild/server/server.csproj +++ b/csharp/Ice/minimal/msbuild/server/server.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/multicast/Client.cs b/csharp/Ice/multicast/Client.cs index e6e2b94cf..d86b93870 100644 --- a/csharp/Ice/multicast/Client.cs +++ b/csharp/Ice/multicast/Client.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class Client +internal class Client { public static int Main(string[] args) { @@ -13,29 +10,23 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -44,7 +35,7 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { var adapter = communicator.createObjectAdapter("DiscoverReply"); var replyI = new DiscoverReplyI(); @@ -54,14 +45,14 @@ private static int run(Ice.Communicator communicator) var discover = DiscoverPrxHelper.uncheckedCast( communicator.propertyToProxy("Discover.Proxy").ice_datagram()); discover.lookup(reply); - var obj = replyI.waitReply(2000); - if(obj == null) + var obj = replyI.WaitReply(2000); + if (obj == null) { Console.Error.WriteLine("no replies"); return 1; } var hello = HelloPrxHelper.checkedCast(obj); - if(hello == null) + if (hello == null) { Console.Error.WriteLine("invalid reply"); return 1; diff --git a/csharp/Ice/multicast/DiscoverI.cs b/csharp/Ice/multicast/DiscoverI.cs index 5c75761e0..8b103c664 100644 --- a/csharp/Ice/multicast/DiscoverI.cs +++ b/csharp/Ice/multicast/DiscoverI.cs @@ -1,17 +1,9 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -public class DiscoverI : DiscoverDisp_ +internal class DiscoverI(Ice.ObjectPrx obj) : DiscoverDisp_ { - public - DiscoverI(Ice.ObjectPrx obj) - { - _obj = obj; - } - public override void lookup(DiscoverReplyPrx reply, Ice.Current current) { @@ -19,11 +11,11 @@ public override void { reply.reply(_obj); } - catch(Ice.LocalException) + catch (Ice.LocalException) { // Ignore } } - private Ice.ObjectPrx _obj; + private Ice.ObjectPrx _obj = obj; } diff --git a/csharp/Ice/multicast/DiscoverReplyI.cs b/csharp/Ice/multicast/DiscoverReplyI.cs index 62100bb6e..a1615976d 100644 --- a/csharp/Ice/multicast/DiscoverReplyI.cs +++ b/csharp/Ice/multicast/DiscoverReplyI.cs @@ -1,18 +1,15 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System.Threading; -public class DiscoverReplyI : DiscoverReplyDisp_ +internal class DiscoverReplyI : DiscoverReplyDisp_ { public override void reply(Ice.ObjectPrx obj, Ice.Current current) { - lock(this) + lock (this) { - if(_obj == null) + if (_obj == null) { _obj = obj; } @@ -21,15 +18,15 @@ public override void } public Ice.ObjectPrx - waitReply(long timeout) + WaitReply(long timeout) { - lock(this) + lock (this) { - long end = System.DateTime.Now.Ticks / 1000 + timeout; - while(_obj == null) + long end = (System.DateTime.Now.Ticks / 1000) + timeout; + while (_obj == null) { - int delay = (int)(end - System.DateTime.Now.Ticks / 1000); - if(delay > 0) + int delay = (int)(end - (System.DateTime.Now.Ticks / 1000)); + if (delay > 0) { Monitor.Wait(this, delay); } diff --git a/csharp/Ice/multicast/HelloI.cs b/csharp/Ice/multicast/HelloI.cs index 05ba22f15..0365afa22 100644 --- a/csharp/Ice/multicast/HelloI.cs +++ b/csharp/Ice/multicast/HelloI.cs @@ -1,10 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -public class HelloI : HelloDisp_ +internal class HelloI : HelloDisp_ { public override void sayHello(Ice.Current current) diff --git a/csharp/Ice/multicast/Server.cs b/csharp/Ice/multicast/Server.cs index 9163ff58f..9c780c163 100644 --- a/csharp/Ice/multicast/Server.cs +++ b/csharp/Ice/multicast/Server.cs @@ -1,10 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; - -public class Server +internal class Server { public static int Main(string[] args) { @@ -12,37 +8,31 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.server")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.server"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - var adapter = communicator.createObjectAdapter("Hello"); - var discoverAdapter = communicator.createObjectAdapter("Discover"); + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + var adapter = communicator.createObjectAdapter("Hello"); + var discoverAdapter = communicator.createObjectAdapter("Discover"); - var hello = adapter.addWithUUID(new HelloI()); - discoverAdapter.add(new DiscoverI(hello), Ice.Util.stringToIdentity("discover")); + var hello = adapter.addWithUUID(new HelloI()); + discoverAdapter.add(new DiscoverI(hello), Ice.Util.stringToIdentity("discover")); - discoverAdapter.activate(); - adapter.activate(); - communicator.waitForShutdown(); - } + discoverAdapter.activate(); + adapter.activate(); + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/Ice/multicast/msbuild/client/client.csproj b/csharp/Ice/multicast/msbuild/client/client.csproj index d414a826e..c49c2f604 100644 --- a/csharp/Ice/multicast/msbuild/client/client.csproj +++ b/csharp/Ice/multicast/msbuild/client/client.csproj @@ -14,5 +14,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/multicast/msbuild/server/server.csproj b/csharp/Ice/multicast/msbuild/server/server.csproj index d03fb46fd..da2c34710 100644 --- a/csharp/Ice/multicast/msbuild/server/server.csproj +++ b/csharp/Ice/multicast/msbuild/server/server.csproj @@ -15,5 +15,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/nested/Client.cs b/csharp/Ice/nested/Client.cs index 65a9173b6..3c4800802 100644 --- a/csharp/Ice/nested/Client.cs +++ b/csharp/Ice/nested/Client.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class Client +internal class Client { public static int Main(string[] args) { @@ -13,27 +10,21 @@ public static int Main(string[] args) try { - // // The new communicator is automatically destroyed (disposed) at the end of the // using statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // The communicator initialization removes all Ice-related arguments from args + if (args.Length > 0) { - // - // The communicator initialization removes all Ice-related arguments from args - // - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -42,20 +33,18 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { var nested = NestedPrxHelper.checkedCast(communicator.propertyToProxy("Nested.Proxy")); - if(nested == null) + if (nested == null) { Console.Error.WriteLine("invalid proxy"); return 1; } - // // Ensure the invocation times out if the nesting level is too // high and there are no more threads in the thread pool to // dispatch the call. - // nested = (NestedPrx)nested.ice_invocationTimeout(5000); var adapter = communicator.createObjectAdapter("Nested.Client"); @@ -78,25 +67,25 @@ private static int run(Ice.Communicator communicator) Console.Out.Write("enter nesting level or 'x' for exit: "); Console.Out.Flush(); s = Console.In.ReadLine(); - if(s == null) + if (s == null) { break; } var level = int.Parse(s); - if(level > 0) + if (level > 0) { nested.nestedCall(level, self); } } - catch(FormatException) + catch (FormatException) { } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); } } - while(!s.Equals("x")); + while (!s.Equals("x")); return 0; } diff --git a/csharp/Ice/nested/NestedI.cs b/csharp/Ice/nested/NestedI.cs index 5c964e403..71fcd4979 100644 --- a/csharp/Ice/nested/NestedI.cs +++ b/csharp/Ice/nested/NestedI.cs @@ -1,10 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -class NestedI : NestedDisp_ +internal class NestedI : NestedDisp_ { internal NestedI(NestedPrx self) { @@ -14,16 +12,14 @@ internal NestedI(NestedPrx self) public override void nestedCall(int level, NestedPrx proxy, Ice.Current current) { System.Console.Out.WriteLine("" + level); - if(--level > 0) + if (--level > 0) { - // // Ensure the invocation times out if the nesting level is too // high and there are no more threads in the thread pool to // dispatch the call. - // ((NestedPrx)proxy.ice_invocationTimeout(5000)).nestedCall(level, _self); } } - private NestedPrx _self; + private readonly NestedPrx _self; } diff --git a/csharp/Ice/nested/Server.cs b/csharp/Ice/nested/Server.cs index bb71a83a5..0ff91f3e4 100644 --- a/csharp/Ice/nested/Server.cs +++ b/csharp/Ice/nested/Server.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class Server +internal class Server { public static int Main(string[] args) { @@ -13,35 +10,29 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.server")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.server"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - var adapter = communicator.createObjectAdapter("Nested.Server"); - var self = - NestedPrxHelper.uncheckedCast(adapter.createProxy(Ice.Util.stringToIdentity("nestedServer"))); - adapter.add(new NestedI(self), Ice.Util.stringToIdentity("nestedServer")); - adapter.activate(); + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + var adapter = communicator.createObjectAdapter("Nested.Server"); + var self = + NestedPrxHelper.uncheckedCast(adapter.createProxy(Ice.Util.stringToIdentity("nestedServer"))); + adapter.add(new NestedI(self), Ice.Util.stringToIdentity("nestedServer")); + adapter.activate(); - communicator.waitForShutdown(); - } + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/Ice/nested/msbuild/client/client.csproj b/csharp/Ice/nested/msbuild/client/client.csproj index c7bf4d05b..13c4984a9 100644 --- a/csharp/Ice/nested/msbuild/client/client.csproj +++ b/csharp/Ice/nested/msbuild/client/client.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/nested/msbuild/server/server.csproj b/csharp/Ice/nested/msbuild/server/server.csproj index f868c13b1..ae5e45781 100644 --- a/csharp/Ice/nested/msbuild/server/server.csproj +++ b/csharp/Ice/nested/msbuild/server/server.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/optional/Client.cs b/csharp/Ice/optional/Client.cs index b1980a3f3..72be40db4 100644 --- a/csharp/Ice/optional/Client.cs +++ b/csharp/Ice/optional/Client.cs @@ -1,13 +1,10 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; #nullable enable -public class Client +internal class Client { public static int Main(string[] args) { @@ -15,29 +12,23 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + status = Run(communicator); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -46,40 +37,32 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { var contactdb = ContactDBPrxHelper.uncheckedCast(communicator.propertyToProxy("ContactDB.Proxy")); - if(contactdb == null) + if (contactdb == null) { Console.Error.WriteLine("invalid proxy"); return 1; } - // // Add a contact for "john". All parameters are provided. - // var johnNumber = "123-456-7890"; contactdb.addContact("john", NumberType.HOME, johnNumber, 0); Console.Write("Checking john... "); - // // Find the phone number for "john". - // var number = contactdb.queryNumber("john"); - // // HasValue tests if an optional value is set. - // - if(number is null) + if (number is null) { Console.Write("number is incorrect "); } - // // Call Value to retrieve the optional value. - // - if(number != johnNumber) + if (number != johnNumber) { Console.Write("number is incorrect "); } @@ -87,141 +70,125 @@ private static int run(Ice.Communicator communicator) // Optional can also be used in an out parameter. int? dialgroup; contactdb.queryDialgroup("john", out dialgroup); - if(dialgroup != 0) + if (dialgroup != 0) { Console.Write("dialgroup is incorrect "); } Contact? info = contactdb.query("john"); - // // All of the info parameters should be set. Each of the optional members // of the class map to C# nullable type. - // - if(info?.type != NumberType.HOME || info.number != johnNumber || info.dialGroup != 0) + if (info?.type != NumberType.HOME || info.number != johnNumber || info.dialGroup != 0) { Console.Write("info is incorrect "); } Console.WriteLine("ok"); - // // Add a contact for "steve". The behavior of the server is to // default construct the Contact, and then assign all set parameters. // Since the default value of NumberType in the slice definition // is NumberType.HOME and in this case the NumberType is unset it will take // the default value. - // var steveNumber = "234-567-8901"; contactdb.addContact("steve", null, steveNumber, 1); Console.Write("Checking steve... "); number = contactdb.queryNumber("steve"); - if(number != steveNumber) + if (number != steveNumber) { Console.Write("number is incorrect "); } info = contactdb.query("steve"); - // // Check the value for the NumberType. - // - if(info?.type != NumberType.HOME) + if (info?.type != NumberType.HOME) { Console.Write("info is incorrect "); } - if(info?.number != steveNumber || info.dialGroup != 1) + if (info?.number != steveNumber || info.dialGroup != 1) { Console.Write("info is incorrect "); } contactdb.queryDialgroup("steve", out dialgroup); - if(dialgroup != 1) + if (dialgroup != 1) { Console.Write("dialgroup is incorrect "); } Console.WriteLine("ok"); - // // Add a contact from "frank". Here the dialGroup field isn't set. - // var frankNumber = "345-678-9012"; contactdb.addContact("frank", NumberType.CELL, frankNumber, null); Console.Write("Checking frank... "); number = contactdb.queryNumber("frank"); - if(number != frankNumber) + if (number != frankNumber) { Console.Write("number is incorrect "); } info = contactdb.query("frank"); - // // The dial group field should be unset. - // - if(info?.dialGroup is not null) + if (info?.dialGroup is not null) { Console.Write("info is incorrect "); } - if(info?.type != NumberType.CELL || info.number != frankNumber) + if (info?.type != NumberType.CELL || info.number != frankNumber) { Console.Write("info is incorrect "); } contactdb.queryDialgroup("frank", out dialgroup); - if(dialgroup is not null) + if (dialgroup is not null) { Console.Write("dialgroup is incorrect "); } Console.WriteLine("ok"); - // // Add a contact from "anne". The number field isn't set. - // contactdb.addContact("anne", NumberType.OFFICE, null, 2); Console.Write("Checking anne... "); number = contactdb.queryNumber("anne"); - if(number is not null) + if (number is not null) { Console.Write("number is incorrect "); } info = contactdb.query("anne"); - // // The number field should be unset. - // - if(info?.number is not null) + if (info?.number is not null) { Console.Write("info is incorrect "); } - if(info?.type != NumberType.OFFICE || info.dialGroup != 2) + if (info?.type != NumberType.OFFICE || info.dialGroup != 2) { Console.Write("info is incorrect "); } contactdb.queryDialgroup("anne", out dialgroup); - if(dialgroup != 2) + if (dialgroup != 2) { Console.Write("dialgroup is incorrect "); } - // // The optional fields can be used to determine what fields to // update on the contact. Here we update only the number for anne, // the remainder of the fields are unchanged. - // var anneNumber = "456-789-0123"; contactdb.updateContact("anne", null, anneNumber, null); number = contactdb.queryNumber("anne"); - if(number != anneNumber) + if (number != anneNumber) { Console.Write("number is incorrect "); } info = contactdb.query("anne"); - if(info?.number != anneNumber || info.type != NumberType.OFFICE || info.dialGroup != 2) + if (info?.number != anneNumber || info.type != NumberType.OFFICE || info.dialGroup != 2) { Console.Write("info is incorrect "); } diff --git a/csharp/Ice/optional/ContactDBI.cs b/csharp/Ice/optional/ContactDBI.cs index 63a425e06..80ae4cb86 100644 --- a/csharp/Ice/optional/ContactDBI.cs +++ b/csharp/Ice/optional/ContactDBI.cs @@ -1,51 +1,52 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System.Collections.Generic; #nullable enable -public class ContactDBI : ContactDBDisp_ +internal class ContactDBI : ContactDBDisp_ { - Dictionary _contacts = new Dictionary(); + private Dictionary _contacts = new Dictionary(); - public override void addContact(string name, NumberType? type, string? number, - int? dialGroup, Ice.Current current) + public override void addContact(string name, NumberType? type, string? number, int? dialGroup, Ice.Current current) { - var contact = new Contact(); - contact.name = name; - if(type is not null) + var contact = new Contact + { + name = name + }; + if (type is not null) { contact.type = type; } - if(number is not null) + if (number is not null) { contact.number = number; } - if(dialGroup is not null) + if (dialGroup is not null) { contact.dialGroup = dialGroup; } _contacts[name] = contact; } - public override void updateContact(string name, NumberType? type, string? number, - int? dialGroup, Ice.Current current) + public override void updateContact( + string name, + NumberType? type, + string? number, + int? dialGroup, + Ice.Current current) { - Contact? c; - if(_contacts.TryGetValue(name, out c)) + if (_contacts.TryGetValue(name, out Contact? c)) { - if(type is not null) + if (type is not null) { c.type = type; } - if(number is not null) + if (number is not null) { c.number = number; } - if(dialGroup is not null) + if (dialGroup is not null) { c.dialGroup = dialGroup; } @@ -54,7 +55,7 @@ public override void updateContact(string name, NumberType? type, string? number public override Contact? query(string name, Ice.Current current) { - if(_contacts.TryGetValue(name, out Contact? c)) + if (_contacts.TryGetValue(name, out Contact? c)) { return c; } @@ -63,7 +64,7 @@ public override void updateContact(string name, NumberType? type, string? number public override string? queryNumber(string name, Ice.Current current) { - if(_contacts.TryGetValue(name, out Contact? c)) + if (_contacts.TryGetValue(name, out Contact? c)) { return c.number; } @@ -72,7 +73,7 @@ public override void updateContact(string name, NumberType? type, string? number public override void queryDialgroup(string name, out int? dialGroup, Ice.Current current) { - if(_contacts.TryGetValue(name, out Contact? c)) + if (_contacts.TryGetValue(name, out Contact? c)) { dialGroup = c.dialGroup; } diff --git a/csharp/Ice/optional/Server.cs b/csharp/Ice/optional/Server.cs index 893e9fe4c..b4edd693e 100644 --- a/csharp/Ice/optional/Server.cs +++ b/csharp/Ice/optional/Server.cs @@ -1,10 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; - -public class Server +internal class Server { public static int Main(string[] args) { @@ -12,32 +8,26 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.server")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.server"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - var adapter = communicator.createObjectAdapter("ContactDB"); - adapter.add(new ContactDBI(), Ice.Util.stringToIdentity("contactdb")); - adapter.activate(); - communicator.waitForShutdown(); - } + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + var adapter = communicator.createObjectAdapter("ContactDB"); + adapter.add(new ContactDBI(), Ice.Util.stringToIdentity("contactdb")); + adapter.activate(); + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/Ice/optional/msbuild/client/client.csproj b/csharp/Ice/optional/msbuild/client/client.csproj index f4939f256..4c40cc66d 100644 --- a/csharp/Ice/optional/msbuild/client/client.csproj +++ b/csharp/Ice/optional/msbuild/client/client.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/optional/msbuild/server/server.csproj b/csharp/Ice/optional/msbuild/server/server.csproj index 9836c4781..39ab78bf9 100644 --- a/csharp/Ice/optional/msbuild/server/server.csproj +++ b/csharp/Ice/optional/msbuild/server/server.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/partial/Client.cs b/csharp/Ice/partial/Client.cs index 0753620c4..989571cdc 100644 --- a/csharp/Ice/partial/Client.cs +++ b/csharp/Ice/partial/Client.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class Client +internal class Client { public static int Main(string[] args) { @@ -13,29 +10,23 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + status = Run(communicator); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -44,64 +35,62 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { var station = MeasurementStationPrxHelper.checkedCast(communicator.propertyToProxy("MeasurementStation.Proxy")); - if(station == null) + if (station == null) { Console.Error.WriteLine("invalid proxy"); return 1; } - // // Get a random measurement. - // var distance = station.getDistance(); - // // Using the properties defined in the partial struct Distance we can access // the value represented by this object in a more convenient way. - // - Console.WriteLine("distance: {0} meters equal {1} yards", Math.Round(distance.Meters, 4), - Math.Round(distance.Yards, 4)); + Console.WriteLine( + "distance: {0} meters equal {1} yards", + Math.Round(distance.Meters, 4), + Math.Round(distance.Yards, 4)); - // // This works equally well for types created locally. - // distance = new Distance(1); - Console.WriteLine("distance: {0} meters equal {1} yards", Math.Round(distance.Meters, 4), - Math.Round(distance.Yards, 4)); + Console.WriteLine( + "distance: {0} meters equal {1} yards", + Math.Round(distance.Meters, 4), + Math.Round(distance.Yards, 4)); - // // The same apply for generated class types like Speed. - // var speed = station.getSpeed(); - Console.WriteLine("speed: {0} m/s is equal {1} km/h {2} mph", + Console.WriteLine( + "speed: {0} m/s is equal {1} km/h {2} mph", Math.Round(speed.MetersPerSecond, 4), Math.Round(speed.KilometersPerHour, 4), Math.Round(speed.MilesPerHour, 4)); - // // Again this works equally well for objects created locally. - // speed = new Speed(1); - Console.WriteLine("speed: {0} m/s is equal {1} km/h {2} mph", + Console.WriteLine( + "speed: {0} m/s is equal {1} km/h {2} mph", Math.Round(speed.MetersPerSecond, 4), Math.Round(speed.KilometersPerHour, 4), Math.Round(speed.MilesPerHour, 4)); speed.KilometersPerHour = 1; - Console.WriteLine("speed: {0} m/s is equal {1} km/h {2} mph", + Console.WriteLine( + "speed: {0} m/s is equal {1} km/h {2} mph", Math.Round(speed.MetersPerSecond, 4), Math.Round(speed.KilometersPerHour, 4), Math.Round(speed.MilesPerHour, 4)); speed.MilesPerHour = 1; - Console.WriteLine("speed: {0} m/s is equal {1} km/h {2} mph", + Console.WriteLine( + "speed: {0} m/s is equal {1} km/h {2} mph", Math.Round(speed.MetersPerSecond, 4), Math.Round(speed.KilometersPerHour, 4), Math.Round(speed.MilesPerHour, 4)); diff --git a/csharp/Ice/partial/MeasurementStationI.cs b/csharp/Ice/partial/MeasurementStationI.cs index 2f9b5fcfe..788c12ba4 100644 --- a/csharp/Ice/partial/MeasurementStationI.cs +++ b/csharp/Ice/partial/MeasurementStationI.cs @@ -1,30 +1,28 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using Ice; -using System; -using System.Linq; -using System.Collections.Generic; -public class MeasurementStationI : MeasurementStationDisp_ +internal class MeasurementStationI : MeasurementStationDisp_ { - public override Distance getDistance(Current current = null) + public override Distance getDistance(Ice.Current current = null) { - var distance = new Distance(); - distance.Yards = random.NextDouble() * 1200; + var distance = new Distance + { + Yards = random.NextDouble() * 1200 + }; return distance; } - public override Speed getSpeed(Current current = null) + public override Speed getSpeed(Ice.Current current = null) { - var speed = new Speed(); - speed.MilesPerHour = random.NextDouble() * 120; + var speed = new Speed + { + MilesPerHour = random.NextDouble() * 120 + }; return speed; } - public override void shutdown(Current current) + public override void shutdown(Ice.Current current) { current.adapter.getCommunicator().shutdown(); } diff --git a/csharp/Ice/partial/Measurements.cs b/csharp/Ice/partial/Measurements.cs index c258e47ae..92a77a26c 100644 --- a/csharp/Ice/partial/Measurements.cs +++ b/csharp/Ice/partial/Measurements.cs @@ -1,34 +1,37 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. namespace Demo { - // - // Because the Distance generated struct is defined as a partial type, - // we can manually add some extra methods that are convenient for our - // application. - // - partial record struct Distance + /// Because the Distance generated struct is defined as a partial type, + /// we can manually add some extra methods that are convenient for our + /// application. + /// + public partial record struct Distance { + /// Gets or sets the distance in yards. + /// public double Yards { - get + readonly get { return value * YardConversionFactor; } + set { this.value = value / YardConversionFactor; } } + /// Gets or sets the distance in meters. + /// public double Meters { - get + readonly get { return value; } + set { this.value = value; @@ -37,43 +40,52 @@ public double Meters private const double YardConversionFactor = 1.0936; } - // - // Because the Speed generated class is defined as a partial type, - // we can manually add some extra methods that are convenient for our - // application. - // - partial class Speed + + /// Because the Temperature generated class is defined as a partial type, + /// we can manually add some extra methods that are convenient for our + /// application. + /// + public partial class Speed { + /// Gets or sets the speed in miles per hour. + /// public double MilesPerHour { get { return value * MilesPerHourConversionFactor; } + set { this.value = value / MilesPerHourConversionFactor; } } + /// Gets or sets the speed in kilometers per hour. + /// public double KilometersPerHour { get { return value * KilometersPerHourConversionFactor; } + set { this.value = value / KilometersPerHourConversionFactor; } } + /// Gets or sets the speed in meters per second. + /// public double MetersPerSecond { get { return value; } + set { this.value = value; diff --git a/csharp/Ice/partial/Server.cs b/csharp/Ice/partial/Server.cs index ba262a850..31bdf865e 100644 --- a/csharp/Ice/partial/Server.cs +++ b/csharp/Ice/partial/Server.cs @@ -1,10 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; - -public class Server +internal class Server { public static int Main(string[] args) { @@ -12,32 +8,26 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.server")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.server"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - var adapter = communicator.createObjectAdapter("MeasurementStation"); - adapter.add(new MeasurementStationI(), Ice.Util.stringToIdentity("measurementstation")); - adapter.activate(); - communicator.waitForShutdown(); - } + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + var adapter = communicator.createObjectAdapter("MeasurementStation"); + adapter.add(new MeasurementStationI(), Ice.Util.stringToIdentity("measurementstation")); + adapter.activate(); + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/Ice/partial/msbuild/client/client.csproj b/csharp/Ice/partial/msbuild/client/client.csproj index 326ebef93..012de392b 100644 --- a/csharp/Ice/partial/msbuild/client/client.csproj +++ b/csharp/Ice/partial/msbuild/client/client.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/partial/msbuild/server/server.csproj b/csharp/Ice/partial/msbuild/server/server.csproj index 70b1ff405..fec44a948 100644 --- a/csharp/Ice/partial/msbuild/server/server.csproj +++ b/csharp/Ice/partial/msbuild/server/server.csproj @@ -14,5 +14,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/plugin/Client.cs b/csharp/Ice/plugin/Client.cs index fe932e676..552c5ba09 100644 --- a/csharp/Ice/plugin/Client.cs +++ b/csharp/Ice/plugin/Client.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class Client +internal class Client { public static int Main(string[] args) { @@ -13,27 +10,21 @@ public static int Main(string[] args) try { - // // The new communicator is automatically destroyed (disposed) at the end of the // using statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // The communicator initialization removes all Ice-related arguments from args + if (args.Length > 0) { - // - // The communicator initialization removes all Ice-related arguments from args - // - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -42,16 +33,16 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { var hello = HelloPrxHelper.checkedCast(communicator.propertyToProxy("Hello.Proxy")); - if(hello == null) + if (hello == null) { Console.Error.WriteLine("invalid proxy"); return 1; } - menu(); + Menu(); string line = null; do @@ -61,33 +52,33 @@ private static int run(Ice.Communicator communicator) Console.Out.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); - if(line == null) + if (line == null) { break; } - if(line.Equals("t")) + if (line.Equals("t")) { hello.sayHello(); } - else if(line.Equals("s")) + else if (line.Equals("s")) { hello.shutdown(); } - else if(line.Equals("x")) + else if (line.Equals("x")) { // Nothing to do } - else if(line.Equals("?")) + else if (line.Equals("?")) { - menu(); + Menu(); } else { Console.WriteLine("unknown command `" + line + "'"); - menu(); + Menu(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); } @@ -97,7 +88,7 @@ private static int run(Ice.Communicator communicator) return 0; } - private static void menu() + private static void Menu() { Console.Write( "usage:\n" + diff --git a/csharp/Ice/plugin/HelloI.cs b/csharp/Ice/plugin/HelloI.cs index d77f91a5b..e2e697746 100644 --- a/csharp/Ice/plugin/HelloI.cs +++ b/csharp/Ice/plugin/HelloI.cs @@ -1,10 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -public class HelloI : HelloDisp_ +internal class HelloI : HelloDisp_ { public override void sayHello(Ice.Current current) { diff --git a/csharp/Ice/plugin/HelloPluginFactoryI.cs b/csharp/Ice/plugin/HelloPluginFactoryI.cs index 893caea22..b07ff64d2 100644 --- a/csharp/Ice/plugin/HelloPluginFactoryI.cs +++ b/csharp/Ice/plugin/HelloPluginFactoryI.cs @@ -1,8 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -public class HelloPluginFactoryI : Ice.PluginFactory +internal class HelloPluginFactoryI : Ice.PluginFactory { public Ice.Plugin create(Ice.Communicator communicator, string name, string[] args) { diff --git a/csharp/Ice/plugin/HelloPluginI.cs b/csharp/Ice/plugin/HelloPluginI.cs index 1980cf9a4..9ac860c9c 100644 --- a/csharp/Ice/plugin/HelloPluginI.cs +++ b/csharp/Ice/plugin/HelloPluginI.cs @@ -1,14 +1,7 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -public class HelloPluginI : Ice.Plugin +internal class HelloPluginI(Ice.Communicator communicator) : Ice.Plugin { - public HelloPluginI(Ice.Communicator communicator) - { - _communicator = communicator; - } - public void initialize() { var adapter = _communicator.createObjectAdapter("Hello"); @@ -20,5 +13,5 @@ public void destroy() { } - private Ice.Communicator _communicator; + private Ice.Communicator _communicator = communicator; } diff --git a/csharp/Ice/plugin/LoggerI.cs b/csharp/Ice/plugin/LoggerI.cs index 9c5ca5a59..37e4e1fdf 100644 --- a/csharp/Ice/plugin/LoggerI.cs +++ b/csharp/Ice/plugin/LoggerI.cs @@ -1,10 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using System; -public class LoggerI : Ice.Logger +internal class LoggerI : Ice.Logger { public void print(string message) { diff --git a/csharp/Ice/plugin/LoggerPluginFactoryI.cs b/csharp/Ice/plugin/LoggerPluginFactoryI.cs index 27f210900..825781c82 100644 --- a/csharp/Ice/plugin/LoggerPluginFactoryI.cs +++ b/csharp/Ice/plugin/LoggerPluginFactoryI.cs @@ -1,8 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -public class LoggerPluginFactoryI : Ice.PluginFactory +internal class LoggerPluginFactoryI : Ice.PluginFactory { public Ice.Plugin create(Ice.Communicator communicator, string name, string[] args) { diff --git a/csharp/Ice/plugin/Server.cs b/csharp/Ice/plugin/Server.cs index e6cf14b9e..bcccbf84e 100644 --- a/csharp/Ice/plugin/Server.cs +++ b/csharp/Ice/plugin/Server.cs @@ -1,10 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using System; -public class Server +internal class Server { public static int Main(string[] args) { @@ -12,29 +10,23 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.server")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.server"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - communicator.waitForShutdown(); - } + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/Ice/plugin/msbuild/client/client.csproj b/csharp/Ice/plugin/msbuild/client/client.csproj index 456e9310f..c3b19fbfd 100644 --- a/csharp/Ice/plugin/msbuild/client/client.csproj +++ b/csharp/Ice/plugin/msbuild/client/client.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/plugin/msbuild/helloplugin/helloplugin.csproj b/csharp/Ice/plugin/msbuild/helloplugin/helloplugin.csproj index 6b1dc90c0..f1fc9658f 100644 --- a/csharp/Ice/plugin/msbuild/helloplugin/helloplugin.csproj +++ b/csharp/Ice/plugin/msbuild/helloplugin/helloplugin.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/plugin/msbuild/loggerplugin/loggerplugin.csproj b/csharp/Ice/plugin/msbuild/loggerplugin/loggerplugin.csproj index 0df081733..e1e63133d 100644 --- a/csharp/Ice/plugin/msbuild/loggerplugin/loggerplugin.csproj +++ b/csharp/Ice/plugin/msbuild/loggerplugin/loggerplugin.csproj @@ -11,5 +11,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/plugin/msbuild/server/server.csproj b/csharp/Ice/plugin/msbuild/server/server.csproj index c12cac04b..ddf843c31 100644 --- a/csharp/Ice/plugin/msbuild/server/server.csproj +++ b/csharp/Ice/plugin/msbuild/server/server.csproj @@ -11,5 +11,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/properties/Client.cs b/csharp/Ice/properties/Client.cs index 880222c72..b1676a4b9 100644 --- a/csharp/Ice/properties/Client.cs +++ b/csharp/Ice/properties/Client.cs @@ -1,13 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -using System.Collections.Generic; - -public class Client +internal class Client { public static int Main(string[] args) { @@ -15,27 +10,21 @@ public static int Main(string[] args) try { - // // The new communicator is automatically destroyed (disposed) at the end of the // using statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // The communicator initialization removes all Ice-related arguments from args + if (args.Length > 0) { - // - // The communicator initialization removes all Ice-related arguments from args - // - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -44,10 +33,10 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { var props = PropsPrxHelper.checkedCast(communicator.propertyToProxy("Props.Proxy")); - if(props == null) + if (props == null) { Console.Error.WriteLine("invalid proxy"); return 1; @@ -69,8 +58,8 @@ private static int run(Ice.Communicator communicator) { "Demo.Prop3", "30" } }; - show(admin); - menu(); + Show(admin); + Menu(); string line = null; do @@ -80,17 +69,17 @@ private static int run(Ice.Communicator communicator) Console.Out.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); - if(line == null) + if (line == null) { break; } - if(line.Equals("1") || line.Equals("2")) + if (line.Equals("1") || line.Equals("2")) { var dict = line.Equals("1") ? batch1 : batch2; Console.Out.WriteLine("Sending:"); - foreach(var e in dict) + foreach (var e in dict) { - if(e.Key.StartsWith("Demo")) + if (e.Key.StartsWith("Demo")) { Console.Out.WriteLine(" " + e.Key + "=" + e.Value); } @@ -101,16 +90,16 @@ private static int run(Ice.Communicator communicator) Console.Out.WriteLine("Changes:"); var changes = props.getChanges(); - if(changes.Count == 0) + if (changes.Count == 0) { Console.Out.WriteLine(" None."); } else { - foreach(var e in changes) + foreach (var e in changes) { Console.Out.Write(" " + e.Key); - if(e.Value.Length == 0) + if (e.Value.Length == 0) { Console.Out.WriteLine(" was removed"); } @@ -121,39 +110,39 @@ private static int run(Ice.Communicator communicator) } } } - else if(line.Equals("c")) + else if (line.Equals("c")) { - show(admin); + Show(admin); } - else if(line.Equals("s")) + else if (line.Equals("s")) { props.shutdown(); } - else if(line.Equals("x")) + else if (line.Equals("x")) { // Nothing to do } - else if(line.Equals("?")) + else if (line.Equals("?")) { - menu(); + Menu(); } else { Console.Out.WriteLine("unknown command `" + line + "'"); - menu(); + Menu(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); } } - while(!line.Equals("x")); + while (!line.Equals("x")); return 0; } - private static void menu() + private static void Menu() { Console.Out.WriteLine( "\n" + @@ -166,11 +155,11 @@ private static void menu() "?: help\n"); } - private static void show(Ice.PropertiesAdminPrx admin) + private static void Show(Ice.PropertiesAdminPrx admin) { var props = admin.getPropertiesForPrefix("Demo"); Console.Out.WriteLine("Server's current settings:"); - foreach(KeyValuePair e in props) + foreach (KeyValuePair e in props) { Console.Out.WriteLine(" " + e.Key + "=" + e.Value); } diff --git a/csharp/Ice/properties/Server.cs b/csharp/Ice/properties/Server.cs index 872f506a7..a8feeb693 100644 --- a/csharp/Ice/properties/Server.cs +++ b/csharp/Ice/properties/Server.cs @@ -1,35 +1,25 @@ - -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -using System.Threading; -using System.Collections.Generic; -public class Server +internal class Server { - // // The servant implements the Slice interface Demo::Props as well as the // native callback interface Ice.PropertiesAdminUpdateCallback. - // - class PropsI : PropsDisp_ + private class PropsI : PropsDisp_ { public PropsI() { _called = false; } - override public Dictionary getChanges(Ice.Current current) + public override Dictionary getChanges(Ice.Current current) { - lock(this) + lock (this) { - // // Make sure that we have received the property updates before we // return the results. - // - while(!_called) + while (!_called) { Monitor.Wait(this); } @@ -39,14 +29,14 @@ override public Dictionary getChanges(Ice.Current current) } } - override public void shutdown(Ice.Current current) + public override void shutdown(Ice.Current current) { current.adapter.getCommunicator().shutdown(); } - public void updated(Dictionary changes) + public void Updated(Dictionary changes) { - lock(this) + lock (this) { _changes = changes; _called = true; @@ -54,7 +44,7 @@ public void updated(Dictionary changes) } } - Dictionary _changes; + private Dictionary _changes; private bool _called; } @@ -64,41 +54,33 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.server")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.server"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - var props = new PropsI(); + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + var props = new PropsI(); - // - // Retrieve the PropertiesAdmin facet and use props.updated as the update callback. - // - var obj = communicator.findAdminFacet("Properties"); - var admin = (Ice.NativePropertiesAdmin)obj; - admin.addUpdateCallback(props.updated); + // Retrieve the PropertiesAdmin facet and use props.updated as the update callback. + var obj = communicator.findAdminFacet("Properties"); + var admin = (Ice.NativePropertiesAdmin)obj; + admin.addUpdateCallback(props.Updated); - var adapter = communicator.createObjectAdapter("Props"); - adapter.add(props, Ice.Util.stringToIdentity("props")); - adapter.activate(); - communicator.waitForShutdown(); - } + var adapter = communicator.createObjectAdapter("Props"); + adapter.add(props, Ice.Util.stringToIdentity("props")); + adapter.activate(); + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/Ice/properties/msbuild/client/client.csproj b/csharp/Ice/properties/msbuild/client/client.csproj index 3984d7868..e8612c98f 100644 --- a/csharp/Ice/properties/msbuild/client/client.csproj +++ b/csharp/Ice/properties/msbuild/client/client.csproj @@ -12,8 +12,17 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - ../../Props.ice + ../../Props.ice diff --git a/csharp/Ice/properties/msbuild/server/server.csproj b/csharp/Ice/properties/msbuild/server/server.csproj index dc9d0b4ea..3d6beec7e 100644 --- a/csharp/Ice/properties/msbuild/server/server.csproj +++ b/csharp/Ice/properties/msbuild/server/server.csproj @@ -12,8 +12,17 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - ../../Props.ice + ../../Props.ice diff --git a/csharp/Ice/session/Client.cs b/csharp/Ice/session/Client.cs index 0daf86831..58161322c 100644 --- a/csharp/Ice/session/Client.cs +++ b/csharp/Ice/session/Client.cs @@ -1,12 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -using System.Collections.Generic; -public class Client +internal class Client { public static int Main(string[] args) { @@ -14,27 +10,21 @@ public static int Main(string[] args) try { - // // The new communicator is automatically destroyed (disposed) at the end of the // using statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // The communicator initialization removes all Ice-related arguments from args + if (args.Length > 0) { - // - // The communicator initialization removes all Ice-related arguments from args - // - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -43,7 +33,7 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { string name; do @@ -52,17 +42,17 @@ private static int run(Ice.Communicator communicator) Console.Out.Flush(); name = Console.In.ReadLine(); - if(name == null) + if (name == null) { return 1; } name = name.Trim(); } - while(name.Length == 0); + while (name.Length == 0); var basePrx = communicator.propertyToProxy("SessionFactory.Proxy"); var factory = SessionFactoryPrxHelper.checkedCast(basePrx); - if(factory == null) + if (factory == null) { Console.Error.WriteLine("invalid proxy"); return 1; @@ -72,23 +62,23 @@ private static int run(Ice.Communicator communicator) var hellos = new List(); - menu(); + Menu(); bool destroy = true; bool shutdown = false; - while(true) + while (true) { Console.Out.Write("==> "); Console.Out.Flush(); string line = Console.In.ReadLine(); - if(line == null) + if (line == null) { break; } - if(line.Length > 0 && Char.IsDigit(line[0])) + if (line.Length > 0 && char.IsDigit(line[0])) { - int index = Int32.Parse(line); - if(index < hellos.Count) + int index = int.Parse(line); + if (index < hellos.Count) { var hello = hellos[index]; hello.sayHello(); @@ -100,49 +90,49 @@ private static int run(Ice.Communicator communicator) "Use `c' to create a new hello object."); } } - else if(line.Equals("c")) + else if (line.Equals("c")) { hellos.Add(session.createHello()); Console.Out.WriteLine("Created hello object " + (hellos.Count - 1)); } - else if(line.Equals("s")) + else if (line.Equals("s")) { destroy = false; shutdown = true; break; } - else if(line.Equals("x")) + else if (line.Equals("x")) { break; } - else if(line.Equals("t")) + else if (line.Equals("t")) { destroy = false; break; } - else if(line.Equals("?")) + else if (line.Equals("?")) { - menu(); + Menu(); } else { Console.Out.WriteLine("Unknown command `" + line + "'."); - menu(); + Menu(); } } - if(destroy) + if (destroy) { session.destroy(); } - if(shutdown) + if (shutdown) { factory.shutdown(); } return 0; } - private static void menu() + private static void Menu() { Console.Out.WriteLine( "usage:\n" + diff --git a/csharp/Ice/session/HelloI.cs b/csharp/Ice/session/HelloI.cs index 09332f44a..de9c01855 100644 --- a/csharp/Ice/session/HelloI.cs +++ b/csharp/Ice/session/HelloI.cs @@ -1,24 +1,15 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class HelloI : HelloDisp_ +internal class HelloI(string name, int id) : HelloDisp_ { - public HelloI(string name, int id) - { - _name = name; - _id = id; - } - public override void sayHello(Ice.Current c) { Console.Out.WriteLine("Hello object #" + _id + " for session `" + _name + "' says:\n" + "Hello " + _name + "!"); } - private string _name; - private int _id; + private string _name = name; + private readonly int _id = id; } diff --git a/csharp/Ice/session/Server.cs b/csharp/Ice/session/Server.cs index b73710770..7225840b0 100644 --- a/csharp/Ice/session/Server.cs +++ b/csharp/Ice/session/Server.cs @@ -1,10 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; - -public class Server +internal class Server { public static int Main(string[] args) { @@ -12,32 +8,26 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.server")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.server"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - var adapter = communicator.createObjectAdapter("SessionFactory"); - adapter.add(new SessionFactoryI(), Ice.Util.stringToIdentity("SessionFactory")); - adapter.activate(); - communicator.waitForShutdown(); - } + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + var adapter = communicator.createObjectAdapter("SessionFactory"); + adapter.add(new SessionFactoryI(), Ice.Util.stringToIdentity("SessionFactory")); + adapter.activate(); + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/Ice/session/SessionFactoryI.cs b/csharp/Ice/session/SessionFactoryI.cs index 89e6f680b..26915ddeb 100644 --- a/csharp/Ice/session/SessionFactoryI.cs +++ b/csharp/Ice/session/SessionFactoryI.cs @@ -1,22 +1,17 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class SessionFactoryI : SessionFactoryDisp_ +internal class SessionFactoryI : SessionFactoryDisp_ { public override SessionPrx create(string name, Ice.Current current) { var session = new SessionI(name); var proxy = SessionPrxHelper.uncheckedCast(current.adapter.addWithUUID(session)); - // // Remove endpoints to ensure that calls are collocated-only // This way, if we invoke on the proxy during shutdown, the invocation fails immediately // without attempting to establish any connection - // var collocProxy = SessionPrxHelper.uncheckedCast(proxy.ice_endpoints(new Ice.Endpoint[0])); current.con.setCloseCallback(_ => diff --git a/csharp/Ice/session/SessionI.cs b/csharp/Ice/session/SessionI.cs index 9dec70ecb..b33bf30ce 100644 --- a/csharp/Ice/session/SessionI.cs +++ b/csharp/Ice/session/SessionI.cs @@ -1,12 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -using System.Collections.Generic; -public class SessionI : SessionDisp_ +internal class SessionI : SessionDisp_ { public SessionI(string name) { @@ -20,9 +16,9 @@ public SessionI(string name) public override HelloPrx createHello(Ice.Current current) { - lock(this) + lock (this) { - if(_destroy) + if (_destroy) { throw new Ice.ObjectNotExistException(); } @@ -35,9 +31,9 @@ public override HelloPrx createHello(Ice.Current current) public override string getName(Ice.Current c) { - lock(this) + lock (this) { - if(_destroy) + if (_destroy) { throw new Ice.ObjectNotExistException(); } @@ -48,25 +44,25 @@ public override string getName(Ice.Current c) public override void destroy(Ice.Current current) { - lock(this) + lock (this) { - if(_destroy) + if (_destroy) { throw new Ice.ObjectNotExistException(); } _destroy = true; - Console.Out.WriteLine("The session " + _name + " is now destroyed."); + Console.Out.WriteLine("The session " + _name + " is now destroyed."); try { current.adapter.remove(current.id); - foreach(HelloPrx p in _objs) + foreach (HelloPrx p in _objs) { current.adapter.remove(p.ice_getIdentity()); } } - catch(Ice.ObjectAdapterDeactivatedException) + catch (Ice.ObjectAdapterDeactivatedException) { // This method is called on shutdown of the server, in which // case this exception is expected. diff --git a/csharp/Ice/session/msbuild/client/client.csproj b/csharp/Ice/session/msbuild/client/client.csproj index 513dc2e01..860c094e9 100644 --- a/csharp/Ice/session/msbuild/client/client.csproj +++ b/csharp/Ice/session/msbuild/client/client.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/session/msbuild/server/server.csproj b/csharp/Ice/session/msbuild/server/server.csproj index dd1909282..99ea70393 100644 --- a/csharp/Ice/session/msbuild/server/server.csproj +++ b/csharp/Ice/session/msbuild/server/server.csproj @@ -15,5 +15,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/throughput/Client.cs b/csharp/Ice/throughput/Client.cs index 92912361b..c3374ecaf 100644 --- a/csharp/Ice/throughput/Client.cs +++ b/csharp/Ice/throughput/Client.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class Client +internal class Client { public static int Main(string[] args) { @@ -13,27 +10,21 @@ public static int Main(string[] args) try { - // // The new communicator is automatically destroyed (disposed) at the end of the // using statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // The communicator initialization removes all Ice-related arguments from args + if (args.Length > 0) { - // - // The communicator initialization removes all Ice-related arguments from args - // - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -42,10 +33,10 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { var throughput = ThroughputPrxHelper.checkedCast(communicator.propertyToProxy("Throughput.Proxy")); - if(throughput == null) + if (throughput == null) { Console.Error.WriteLine("invalid proxy"); return 1; @@ -55,13 +46,13 @@ private static int run(Ice.Communicator communicator) var byteSeq = new byte[ByteSeqSize.value]; var stringSeq = new string[StringSeqSize.value]; - for(int i = 0; i < StringSeqSize.value; ++i) + for (int i = 0; i < StringSeqSize.value; ++i) { stringSeq[i] = "hello"; } var structSeq = new StringDouble[StringDoubleSeqSize.value]; - for(int i = 0; i < StringDoubleSeqSize.value; ++i) + for (int i = 0; i < StringDoubleSeqSize.value; ++i) { structSeq[i] = new StringDouble(); structSeq[i].s = "hello"; @@ -69,19 +60,17 @@ private static int run(Ice.Communicator communicator) } var fixedSeq = new Fixed[FixedSeqSize.value]; - for(int i = 0; i < FixedSeqSize.value; ++i) + for (int i = 0; i < FixedSeqSize.value; ++i) { fixedSeq[i].i = 0; fixedSeq[i].j = 0; fixedSeq[i].d = 0; } - // // A method needs to be invoked thousands of times before the // JIT compiler will convert it to native code. To ensure an // accurate throughput measurement, we need to "warm up" the // JIT compiler. - // { var warmupBytes = new byte[1]; var warmupStrings = new string[1]; @@ -93,7 +82,7 @@ private static int run(Ice.Communicator communicator) Console.Error.Write("warming up the client/server..."); Console.Error.Flush(); - for(int i = 0; i < 10000; i++) + for (int i = 0; i < 10000; i++) { throughput.sendByteSeq(warmupBytes); throughput.sendStringSeq(warmupStrings); @@ -115,11 +104,9 @@ private static int run(Ice.Communicator communicator) Console.Error.WriteLine("ok"); } - menu(); + Menu(); - // // By default use byte sequence. - // char currentType = '1'; int seqSize = ByteSeqSize.value; @@ -131,7 +118,7 @@ private static int run(Ice.Communicator communicator) Console.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); - if(line == null) + if (line == null) { break; } @@ -139,10 +126,10 @@ private static int run(Ice.Communicator communicator) long tmsec = DateTime.Now.Ticks / 10000; int repetitions = 100; - if(line.Equals("1") || line.Equals("2") || line.Equals("3") || line.Equals("4")) + if (line.Equals("1") || line.Equals("2") || line.Equals("3") || line.Equals("4")) { currentType = line[0]; - switch(currentType) + switch (currentType) { case '1': { @@ -170,9 +157,9 @@ private static int run(Ice.Communicator communicator) } } } - else if(line.Equals("t") || line.Equals("o") || line.Equals("r") || line.Equals("e")) + else if (line.Equals("t") || line.Equals("o") || line.Equals("r") || line.Equals("e")) { - if(currentType == '1') + if (currentType == '1') { repetitions = 1000; // Use more iterations for byte sequences as it's a lot faster } @@ -203,7 +190,7 @@ private static int run(Ice.Communicator communicator) } Console.Write(" " + repetitions); - switch(currentType) + switch (currentType) { case '1': { @@ -228,7 +215,7 @@ private static int run(Ice.Communicator communicator) } Console.Write(" sequences of size " + seqSize); - if(c == 'o') + if (c == 'o') { Console.Write(" as oneway"); } @@ -237,11 +224,11 @@ private static int run(Ice.Communicator communicator) for (int i = 0; i < repetitions; ++i) { - switch(currentType) + switch (currentType) { case '1': { - switch(c) + switch (c) { case 't': { @@ -272,7 +259,7 @@ private static int run(Ice.Communicator communicator) case '2': { - switch(c) + switch (c) { case 't': { @@ -303,7 +290,7 @@ private static int run(Ice.Communicator communicator) case '3': { - switch(c) + switch (c) { case 't': { @@ -334,7 +321,7 @@ private static int run(Ice.Communicator communicator) case '4': { - switch(c) + switch (c) { case 't': { @@ -365,11 +352,11 @@ private static int run(Ice.Communicator communicator) } } - double dmsec = DateTime.Now.Ticks / 10000 - tmsec; + double dmsec = (DateTime.Now.Ticks / 10000) - tmsec; Console.WriteLine("time for " + repetitions + " sequences: " + dmsec.ToString("F") + "ms"); Console.WriteLine("time per sequence: " + ((double)(dmsec / repetitions)).ToString("F") + "ms"); int wireSize = 0; - switch(currentType) + switch (currentType) { case '1': { @@ -394,41 +381,41 @@ private static int run(Ice.Communicator communicator) } } double mbit = repetitions * seqSize * wireSize * 8.0 / dmsec / 1000.0; - if(c == 'e') + if (c == 'e') { mbit *= 2; } Console.WriteLine("throughput: " + mbit.ToString("#.##") + "Mbps"); } - else if(line.Equals("s")) + else if (line.Equals("s")) { throughput.shutdown(); } - else if(line.Equals("x")) + else if (line.Equals("x")) { // Nothing to do } - else if(line.Equals("?")) + else if (line.Equals("?")) { - menu(); + Menu(); } else { Console.WriteLine("unknown command `" + line + "'"); - menu(); + Menu(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); } } - while(!line.Equals("x")); + while (!line.Equals("x")); return 0; } - private static void menu() + private static void Menu() { Console.WriteLine("usage:\n" + "\n" diff --git a/csharp/Ice/throughput/Server.cs b/csharp/Ice/throughput/Server.cs index 799216c7c..2a7b13dcb 100644 --- a/csharp/Ice/throughput/Server.cs +++ b/csharp/Ice/throughput/Server.cs @@ -1,10 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; - -public class Server +internal class Server { public static int Main(string[] args) { @@ -12,32 +8,26 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.server")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.server"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - var adapter = communicator.createObjectAdapter("Throughput"); - adapter.add(new ThroughputI(), Ice.Util.stringToIdentity("throughput")); - adapter.activate(); - communicator.waitForShutdown(); - } + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + var adapter = communicator.createObjectAdapter("Throughput"); + adapter.add(new ThroughputI(), Ice.Util.stringToIdentity("throughput")); + adapter.activate(); + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/Ice/throughput/ThroughputI.cs b/csharp/Ice/throughput/ThroughputI.cs index cd21ed200..36f0078f9 100644 --- a/csharp/Ice/throughput/ThroughputI.cs +++ b/csharp/Ice/throughput/ThroughputI.cs @@ -1,28 +1,26 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -public sealed class ThroughputI : ThroughputDisp_ +internal sealed class ThroughputI : ThroughputDisp_ { public ThroughputI() { _byteSeq = new byte[ByteSeqSize.value]; _stringSeq = new string[StringSeqSize.value]; - for(int i = 0; i < StringSeqSize.value; ++i) + for (int i = 0; i < StringSeqSize.value; ++i) { _stringSeq[i] = "hello"; } _structSeq = new StringDouble[StringDoubleSeqSize.value]; - for(int i = 0; i < StringDoubleSeqSize.value; ++i) + for (int i = 0; i < StringDoubleSeqSize.value; ++i) { _structSeq[i] = new StringDouble(); _structSeq[i].s = "hello"; _structSeq[i].d = 3.14; } _fixedSeq = new Fixed[FixedSeqSize.value]; - for(int i = 0; i < FixedSeqSize.value; ++i) + for (int i = 0; i < FixedSeqSize.value; ++i) { _fixedSeq[i].i = 0; _fixedSeq[i].j = 0; @@ -53,7 +51,7 @@ public override void sendByteSeq(byte[] seq, Ice.Current current) public override byte[] recvByteSeq(Ice.Current current) { - if(_warmup) + if (_warmup) { return _warmupByteSeq; } @@ -74,7 +72,7 @@ public override void sendStringSeq(string[] seq, Ice.Current current) public override string[] recvStringSeq(Ice.Current current) { - if(_warmup) + if (_warmup) { return _warmupStringSeq; } @@ -95,7 +93,7 @@ public override void sendStructSeq(StringDouble[] seq, Ice.Current current) public override StringDouble[] recvStructSeq(Ice.Current current) { - if(_warmup) + if (_warmup) { return _warmupStructSeq; } @@ -116,7 +114,7 @@ public override void sendFixedSeq(Fixed[] seq, Ice.Current current) public override Fixed[] recvFixedSeq(Ice.Current current) { - if(_warmup) + if (_warmup) { return _warmupFixedSeq; } @@ -136,15 +134,15 @@ public override void shutdown(Ice.Current current) current.adapter.getCommunicator().shutdown(); } - private byte[] _byteSeq; - private string[] _stringSeq; - private StringDouble[] _structSeq; - private Fixed[] _fixedSeq; + private readonly byte[] _byteSeq; + private readonly string[] _stringSeq; + private readonly StringDouble[] _structSeq; + private readonly Fixed[] _fixedSeq; - private byte[] _warmupByteSeq = new byte[1]; - private string[] _warmupStringSeq = new string[1]; - private StringDouble[] _warmupStructSeq = new StringDouble[] { new StringDouble() }; - private Fixed[] _warmupFixedSeq = new Fixed[1]; + private readonly byte[] _warmupByteSeq = new byte[1]; + private readonly string[] _warmupStringSeq = new string[1]; + private readonly StringDouble[] _warmupStructSeq = new StringDouble[] { new() }; + private readonly Fixed[] _warmupFixedSeq = new Fixed[1]; private bool _needsWarmup = true; private bool _warmup = false; diff --git a/csharp/Ice/throughput/msbuild/client/client.csproj b/csharp/Ice/throughput/msbuild/client/client.csproj index 221c494d8..4efc975f2 100644 --- a/csharp/Ice/throughput/msbuild/client/client.csproj +++ b/csharp/Ice/throughput/msbuild/client/client.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Ice/throughput/msbuild/server/server.csproj b/csharp/Ice/throughput/msbuild/server/server.csproj index c9b659c01..42cde6d27 100644 --- a/csharp/Ice/throughput/msbuild/server/server.csproj +++ b/csharp/Ice/throughput/msbuild/server/server.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/IceBox/hello/Client.cs b/csharp/IceBox/hello/Client.cs index 075da0432..e37e5f10b 100644 --- a/csharp/IceBox/hello/Client.cs +++ b/csharp/IceBox/hello/Client.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class Client +internal class Client { public static int Main(string[] args) { @@ -13,24 +10,18 @@ public static int Main(string[] args) try { - // // The new communicator is automatically destroyed (disposed) at the end of the // using statement - // - using (var communicator = Ice.Util.initialize(ref args, "config.client")) + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // The communicator initialization removes all Ice-related arguments from args + if (args.Length > 0) { - // - // The communicator initialization removes all Ice-related arguments from args - // - if (args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } catch (Exception ex) @@ -42,7 +33,7 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { var twoway = HelloPrxHelper.checkedCast( communicator.propertyToProxy("Hello.Proxy").ice_twoway().ice_secure(false)); @@ -58,7 +49,7 @@ private static int run(Ice.Communicator communicator) bool secure = false; - menu(); + Menu(); string line = null; do @@ -139,12 +130,12 @@ private static int run(Ice.Communicator communicator) } else if (line.Equals("?")) { - menu(); + Menu(); } else { Console.WriteLine("unknown command `" + line + "'"); - menu(); + Menu(); } } catch (Exception ex) @@ -157,7 +148,7 @@ private static int run(Ice.Communicator communicator) return 0; } - private static void menu() + private static void Menu() { Console.Write( "usage:\n" + diff --git a/csharp/IceBox/hello/HelloI.cs b/csharp/IceBox/hello/HelloI.cs index 1ed75b98e..a1f60a9ff 100644 --- a/csharp/IceBox/hello/HelloI.cs +++ b/csharp/IceBox/hello/HelloI.cs @@ -1,10 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -public class HelloI : HelloDisp_ +internal class HelloI : HelloDisp_ { public override void sayHello(Ice.Current current) { diff --git a/csharp/IceBox/hello/HelloServiceI.cs b/csharp/IceBox/hello/HelloServiceI.cs index 97dce73e5..a7dcdb407 100644 --- a/csharp/IceBox/hello/HelloServiceI.cs +++ b/csharp/IceBox/hello/HelloServiceI.cs @@ -1,10 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using IceBox; - -class HelloServiceI : IceBox.Service +internal class HelloServiceI : IceBox.Service { public void start(string name, Ice.Communicator communicator, string[] args) { diff --git a/csharp/IceBox/hello/msbuild/client/client.csproj b/csharp/IceBox/hello/msbuild/client/client.csproj index 456e9310f..c3b19fbfd 100644 --- a/csharp/IceBox/hello/msbuild/client/client.csproj +++ b/csharp/IceBox/hello/msbuild/client/client.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/IceBox/hello/msbuild/helloservice/helloservice.csproj b/csharp/IceBox/hello/msbuild/helloservice/helloservice.csproj index d33b4badc..be03061bb 100644 --- a/csharp/IceBox/hello/msbuild/helloservice/helloservice.csproj +++ b/csharp/IceBox/hello/msbuild/helloservice/helloservice.csproj @@ -12,6 +12,15 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/csharp/IceDiscovery/hello/Client.cs b/csharp/IceDiscovery/hello/Client.cs index 58e794e49..84d37eddd 100644 --- a/csharp/IceDiscovery/hello/Client.cs +++ b/csharp/IceDiscovery/hello/Client.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class Client +internal class Client { public static int Main(string[] args) { @@ -13,27 +10,21 @@ public static int Main(string[] args) try { - // // The new communicator is automatically destroyed (disposed) at the end of the // using statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // The communicator initialization removes all Ice-related arguments from args + if (args.Length > 0) { - // - // The communicator initialization removes all Ice-related arguments from args - // - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -42,10 +33,10 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { var twoway = HelloPrxHelper.checkedCast(communicator.stringToProxy("hello")); - if(twoway == null) + if (twoway == null) { Console.Error.WriteLine("invalid proxy"); return 1; @@ -53,13 +44,13 @@ private static int run(Ice.Communicator communicator) var oneway = (HelloPrx)twoway.ice_oneway(); var batchOneway = (HelloPrx)twoway.ice_batchOneway(); var datagram = (HelloPrx)twoway.ice_datagram(); - var batchDatagram =(HelloPrx)twoway.ice_batchDatagram(); + var batchDatagram = (HelloPrx)twoway.ice_batchDatagram(); bool secure = false; int timeout = -1; int delay = 0; - menu(); + Menu(); string line = null; do @@ -69,25 +60,25 @@ private static int run(Ice.Communicator communicator) Console.Out.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); - if(line == null) + if (line == null) { break; } - if(line.Equals("t")) + if (line.Equals("t")) { twoway.sayHello(delay); } - else if(line.Equals("o")) + else if (line.Equals("o")) { oneway.sayHello(delay); } - else if(line.Equals("O")) + else if (line.Equals("O")) { batchOneway.sayHello(delay); } - else if(line.Equals("d")) + else if (line.Equals("d")) { - if(secure) + if (secure) { Console.WriteLine("secure datagrams are not supported"); } @@ -96,9 +87,9 @@ private static int run(Ice.Communicator communicator) datagram.sayHello(delay); } } - else if(line.Equals("D")) + else if (line.Equals("D")) { - if(secure) + if (secure) { Console.WriteLine("secure datagrams are not supported"); } @@ -107,17 +98,17 @@ private static int run(Ice.Communicator communicator) batchDatagram.sayHello(delay); } } - else if(line.Equals("f")) + else if (line.Equals("f")) { batchOneway.ice_flushBatchRequests(); - if(!secure) + if (!secure) { batchDatagram.ice_flushBatchRequests(); } } - else if(line.Equals("T")) + else if (line.Equals("T")) { - if(timeout == -1) + if (timeout == -1) { timeout = 2000; } @@ -130,7 +121,7 @@ private static int run(Ice.Communicator communicator) oneway = (HelloPrx)oneway.ice_invocationTimeout(timeout); batchOneway = (HelloPrx)batchOneway.ice_invocationTimeout(timeout); - if(timeout == -1) + if (timeout == -1) { Console.WriteLine("timeout is now switched off"); } @@ -139,9 +130,9 @@ private static int run(Ice.Communicator communicator) Console.WriteLine("timeout is now set to 2000ms"); } } - else if(line.Equals("P")) + else if (line.Equals("P")) { - if(delay == 0) + if (delay == 0) { delay = 2500; } @@ -150,7 +141,7 @@ private static int run(Ice.Communicator communicator) delay = 0; } - if(delay == 0) + if (delay == 0) { Console.WriteLine("server delay is now deactivated"); } @@ -159,7 +150,7 @@ private static int run(Ice.Communicator communicator) Console.WriteLine("server delay is now set to 2500ms"); } } - else if(line.Equals("S")) + else if (line.Equals("S")) { secure = !secure; @@ -169,7 +160,7 @@ private static int run(Ice.Communicator communicator) datagram = (HelloPrx)datagram.ice_secure(secure); batchDatagram = (HelloPrx)batchDatagram.ice_secure(secure); - if(secure) + if (secure) { Console.WriteLine("secure mode is now on"); } @@ -178,25 +169,25 @@ private static int run(Ice.Communicator communicator) Console.WriteLine("secure mode is now off"); } } - else if(line.Equals("s")) + else if (line.Equals("s")) { twoway.shutdown(); } - else if(line.Equals("x")) + else if (line.Equals("x")) { // Nothing to do } - else if(line.Equals("?")) + else if (line.Equals("?")) { - menu(); + Menu(); } else { Console.WriteLine("unknown command `" + line + "'"); - menu(); + Menu(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); } @@ -206,7 +197,7 @@ private static int run(Ice.Communicator communicator) return 0; } - private static void menu() + private static void Menu() { Console.Write( "usage:\n" + diff --git a/csharp/IceDiscovery/hello/HelloI.cs b/csharp/IceDiscovery/hello/HelloI.cs index 404999553..b9f8a9d3b 100644 --- a/csharp/IceDiscovery/hello/HelloI.cs +++ b/csharp/IceDiscovery/hello/HelloI.cs @@ -1,14 +1,12 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -public class HelloI : HelloDisp_ +internal class HelloI : HelloDisp_ { public override void sayHello(int delay, Ice.Current current) { - if(delay > 0) + if (delay > 0) { System.Threading.Thread.Sleep(delay); } diff --git a/csharp/IceDiscovery/hello/Server.cs b/csharp/IceDiscovery/hello/Server.cs index 6809b6367..d9553d13e 100644 --- a/csharp/IceDiscovery/hello/Server.cs +++ b/csharp/IceDiscovery/hello/Server.cs @@ -1,10 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; - -public class Server +internal class Server { public static int Main(string[] args) { @@ -12,32 +8,26 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.server")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.server"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - var adapter = communicator.createObjectAdapter("Hello"); - adapter.add(new HelloI(), Ice.Util.stringToIdentity("hello")); - adapter.activate(); - communicator.waitForShutdown(); - } + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + var adapter = communicator.createObjectAdapter("Hello"); + adapter.add(new HelloI(), Ice.Util.stringToIdentity("hello")); + adapter.activate(); + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/IceDiscovery/hello/msbuild/client/client.csproj b/csharp/IceDiscovery/hello/msbuild/client/client.csproj index 456e9310f..c3b19fbfd 100644 --- a/csharp/IceDiscovery/hello/msbuild/client/client.csproj +++ b/csharp/IceDiscovery/hello/msbuild/client/client.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/IceDiscovery/hello/msbuild/server/server.csproj b/csharp/IceDiscovery/hello/msbuild/server/server.csproj index f21a23c9a..c12295699 100644 --- a/csharp/IceDiscovery/hello/msbuild/server/server.csproj +++ b/csharp/IceDiscovery/hello/msbuild/server/server.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/IceDiscovery/replication/Client.cs b/csharp/IceDiscovery/replication/Client.cs index 10d6fd76f..b594d2bce 100644 --- a/csharp/IceDiscovery/replication/Client.cs +++ b/csharp/IceDiscovery/replication/Client.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class Client +internal class Client { public static int Main(string[] args) { @@ -13,27 +10,21 @@ public static int Main(string[] args) try { - // // The new communicator is automatically destroyed (disposed) at the end of the // using statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // The communicator initialization removes all Ice-related arguments from args + if (args.Length > 0) { - // - // The communicator initialization removes all Ice-related arguments from args - // - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -42,33 +33,31 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { - // // Get the hello proxy. We configure the proxy to not cache the // server connection with the proxy and to disable the locator // cache. With this configuration, the IceGrid locator will be // queried for each invocation on the proxy and the invocation // will be sent over the server connection matching the returned // endpoints. - // var obj = communicator.stringToProxy("hello"); obj = obj.ice_connectionCached(false); obj = obj.ice_locatorCacheTimeout(0); var hello = HelloPrxHelper.checkedCast(obj); - if(hello == null) + if (hello == null) { Console.Error.WriteLine("invalid proxy"); return 1; } - while(true) + while (true) { Console.Out.Write("enter the number of iterations: "); Console.Out.Flush(); string line = Console.In.ReadLine(); - if(line == null || line.Equals("x")) + if (line == null || line.Equals("x")) { break; } @@ -77,18 +66,18 @@ private static int run(Ice.Communicator communicator) Console.Out.Write("enter the delay between each greetings (in ms): "); Console.Out.Flush(); line = Console.In.ReadLine(); - if(line == null || line.Equals("x")) + if (line == null || line.Equals("x")) { break; } int delay = Convert.ToInt32(line); - if(delay < 0) + if (delay < 0) { delay = 500; // 500 milli-seconds } - for(int i = 0; i < count; i++) + for (int i = 0; i < count; i++) { Console.Out.WriteLine(hello.getGreeting()); System.Threading.Thread.Sleep(delay); diff --git a/csharp/IceDiscovery/replication/HelloI.cs b/csharp/IceDiscovery/replication/HelloI.cs index dbb7a2d5b..d806f3708 100644 --- a/csharp/IceDiscovery/replication/HelloI.cs +++ b/csharp/IceDiscovery/replication/HelloI.cs @@ -1,16 +1,9 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -public class HelloI : HelloDisp_ +internal class HelloI(string name) : HelloDisp_ { - public HelloI(string name) - { - _name = name; - } - public override string getGreeting(Ice.Current current) { return _name + " says Hello World!"; @@ -22,5 +15,5 @@ public override void shutdown(Ice.Current current) current.adapter.getCommunicator().shutdown(); } - private string _name; + private string _name = name; } diff --git a/csharp/IceDiscovery/replication/Server.cs b/csharp/IceDiscovery/replication/Server.cs index d0ab78034..0728018ac 100644 --- a/csharp/IceDiscovery/replication/Server.cs +++ b/csharp/IceDiscovery/replication/Server.cs @@ -1,10 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; - -public class Server +internal class Server { public static int Main(string[] args) { @@ -12,33 +8,27 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args)) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - var adapter = communicator.createObjectAdapter("Hello"); - var hello = new HelloI(communicator.getProperties().getProperty("Ice.ProgramName")); - adapter.add(hello, Ice.Util.stringToIdentity("hello")); - adapter.activate(); - communicator.waitForShutdown(); - } + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + var adapter = communicator.createObjectAdapter("Hello"); + var hello = new HelloI(communicator.getProperties().getProperty("Ice.ProgramName")); + adapter.add(hello, Ice.Util.stringToIdentity("hello")); + adapter.activate(); + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/IceDiscovery/replication/msbuild/client/client.csproj b/csharp/IceDiscovery/replication/msbuild/client/client.csproj index 456e9310f..c3b19fbfd 100644 --- a/csharp/IceDiscovery/replication/msbuild/client/client.csproj +++ b/csharp/IceDiscovery/replication/msbuild/client/client.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/IceDiscovery/replication/msbuild/server/server.csproj b/csharp/IceDiscovery/replication/msbuild/server/server.csproj index f21a23c9a..c12295699 100644 --- a/csharp/IceDiscovery/replication/msbuild/server/server.csproj +++ b/csharp/IceDiscovery/replication/msbuild/server/server.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/IceGrid/icebox/Client.cs b/csharp/IceGrid/icebox/Client.cs index 697a86cdf..07061321a 100644 --- a/csharp/IceGrid/icebox/Client.cs +++ b/csharp/IceGrid/icebox/Client.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class Client +internal class Client { public static int Main(string[] args) { @@ -13,41 +10,33 @@ public static int Main(string[] args) try { - // // The new communicator is automatically destroyed (disposed) at the end of the // using statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - // - // The communicator initialization removes all Ice-related arguments from args - // - if(args.Length > 0) + // The communicator initialization removes all Ice-related arguments from args + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + var hello = HelloPrxHelper.uncheckedCast(communicator.propertyToProxy("Hello.Proxy")); + if (hello == null) { - Console.Error.WriteLine("too many arguments"); + Console.Error.WriteLine("Hello.Proxy not found"); status = 1; } else { - var hello = HelloPrxHelper.uncheckedCast(communicator.propertyToProxy("Hello.Proxy")); - if(hello == null) - { - Console.Error.WriteLine("Hello.Proxy not found"); - status = 1; - } - else - { - hello.sayHello(); - } + hello.sayHello(); } } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/IceGrid/icebox/HelloI.cs b/csharp/IceGrid/icebox/HelloI.cs index 74f3ea403..8845dd487 100644 --- a/csharp/IceGrid/icebox/HelloI.cs +++ b/csharp/IceGrid/icebox/HelloI.cs @@ -1,39 +1,32 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -public class HelloI : HelloDisp_ +internal class HelloI(string serviceName) : HelloDisp_ { - public HelloI(string serviceName) - { - _serviceName = serviceName; - } - public override void sayHello(Ice.Current current) { var lang = System.Environment.GetEnvironmentVariable("LANG") != null ? System.Environment.GetEnvironmentVariable("LANG") : "en"; var greeting = "Hello, "; - if(lang.Equals("fr")) + if (lang.Equals("fr")) { greeting = "Bonjour, "; } - else if(lang.Equals("de")) + else if (lang.Equals("de")) { greeting = "Hallo, "; } - else if(lang.Equals("es")) + else if (lang.Equals("es")) { greeting = "Hola, "; } - else if(lang.Equals("it")) + else if (lang.Equals("it")) { greeting = "Ciao, "; } System.Console.Out.WriteLine(greeting + _serviceName); } - private string _serviceName; + private string _serviceName = serviceName; } diff --git a/csharp/IceGrid/icebox/HelloServiceI.cs b/csharp/IceGrid/icebox/HelloServiceI.cs index 790c8b712..0eb0e443c 100644 --- a/csharp/IceGrid/icebox/HelloServiceI.cs +++ b/csharp/IceGrid/icebox/HelloServiceI.cs @@ -1,10 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using IceBox; - -class HelloServiceI : Service +internal class HelloServiceI : IceBox.Service { public void start(string name, Ice.Communicator communicator, string[] args) { diff --git a/csharp/IceGrid/icebox/msbuild/client/client.csproj b/csharp/IceGrid/icebox/msbuild/client/client.csproj index 5f07007b9..362bf4326 100644 --- a/csharp/IceGrid/icebox/msbuild/client/client.csproj +++ b/csharp/IceGrid/icebox/msbuild/client/client.csproj @@ -12,8 +12,17 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - ../../Hello.ice + ../../Hello.ice diff --git a/csharp/IceGrid/icebox/msbuild/helloservice/helloservice.csproj b/csharp/IceGrid/icebox/msbuild/helloservice/helloservice.csproj index 7bd1b51e5..b8f40cbbe 100644 --- a/csharp/IceGrid/icebox/msbuild/helloservice/helloservice.csproj +++ b/csharp/IceGrid/icebox/msbuild/helloservice/helloservice.csproj @@ -12,6 +12,15 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/csharp/IceGrid/simple/Client.cs b/csharp/IceGrid/simple/Client.cs index 67ceb5a7a..f33472bcf 100644 --- a/csharp/IceGrid/simple/Client.cs +++ b/csharp/IceGrid/simple/Client.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -public class Client +internal class Client { public static int Main(string[] args) { @@ -13,27 +10,21 @@ public static int Main(string[] args) try { - // // The new communicator is automatically destroyed (disposed) at the end of the // using statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.client")) + using var communicator = Ice.Util.initialize(ref args, "config.client"); + // The communicator initialization removes all Ice-related arguments from args + if (args.Length > 0) { - // - // The communicator initialization removes all Ice-related arguments from args - // - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - status = run(communicator); - } + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + status = Run(communicator); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -42,26 +33,26 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { HelloPrx hello = null; try { hello = HelloPrxHelper.checkedCast(communicator.stringToProxy("hello")); } - catch(Ice.NotRegisteredException) + catch (Ice.NotRegisteredException) { var query = IceGrid.QueryPrxHelper.checkedCast(communicator.stringToProxy("DemoIceGrid/Query")); hello = HelloPrxHelper.checkedCast(query.findObjectByType("::Demo::Hello")); } - if(hello == null) + if (hello == null) { Console.WriteLine("couldn't find a `::Demo::Hello' object"); return 1; } - menu(); + Menu(); string line = null; do @@ -71,43 +62,43 @@ private static int run(Ice.Communicator communicator) Console.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); - if(line == null) + if (line == null) { break; } - if(line.Equals("t")) + if (line.Equals("t")) { hello.sayHello(); } - else if(line.Equals("s")) + else if (line.Equals("s")) { hello.shutdown(); } - else if(line.Equals("x")) + else if (line.Equals("x")) { // Nothing to do } - else if(line.Equals("?")) + else if (line.Equals("?")) { - menu(); + Menu(); } else { Console.WriteLine("unknown command `" + line + "'"); - menu(); + Menu(); } } - catch(Ice.LocalException ex) + catch (Ice.LocalException ex) { Console.WriteLine(ex); } } - while(!line.Equals("x")); + while (!line.Equals("x")); return 0; } - private static void menu() + private static void Menu() { Console.WriteLine( "usage:\n" + diff --git a/csharp/IceGrid/simple/HelloI.cs b/csharp/IceGrid/simple/HelloI.cs index 5b16b612c..5f33aae6b 100644 --- a/csharp/IceGrid/simple/HelloI.cs +++ b/csharp/IceGrid/simple/HelloI.cs @@ -1,17 +1,9 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; using Demo; -public class HelloI : HelloDisp_ +internal class HelloI(string name) : HelloDisp_ { - public HelloI(string name) - { - _name = name; - } - public override void sayHello(Ice.Current current) { Console.WriteLine(_name + " says Hello World!"); @@ -23,5 +15,5 @@ public override void shutdown(Ice.Current current) current.adapter.getCommunicator().shutdown(); } - private string _name; + private string _name = name; } diff --git a/csharp/IceGrid/simple/Server.cs b/csharp/IceGrid/simple/Server.cs index 9553dd7c5..d3e562b6a 100644 --- a/csharp/IceGrid/simple/Server.cs +++ b/csharp/IceGrid/simple/Server.cs @@ -1,10 +1,6 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. -using System; - -public class Server +internal class Server { public static int Main(string[] args) { @@ -12,34 +8,28 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args)) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - if(args.Length > 0) - { - Console.Error.WriteLine("too many arguments"); - status = 1; - } - else - { - var adapter = communicator.createObjectAdapter("Hello"); - var properties = communicator.getProperties(); - var id = Ice.Util.stringToIdentity(properties.getProperty("Identity")); - adapter.add(new HelloI(properties.getProperty("Ice.ProgramName")), id); - adapter.activate(); - communicator.waitForShutdown(); - } + if (args.Length > 0) + { + Console.Error.WriteLine("too many arguments"); + status = 1; + } + else + { + var adapter = communicator.createObjectAdapter("Hello"); + var properties = communicator.getProperties(); + var id = Ice.Util.stringToIdentity(properties.getProperty("Identity")); + adapter.add(new HelloI(properties.getProperty("Ice.ProgramName")), id); + adapter.activate(); + communicator.waitForShutdown(); } } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; diff --git a/csharp/IceGrid/simple/msbuild/client/client.csproj b/csharp/IceGrid/simple/msbuild/client/client.csproj index 456e9310f..c3b19fbfd 100644 --- a/csharp/IceGrid/simple/msbuild/client/client.csproj +++ b/csharp/IceGrid/simple/msbuild/client/client.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/IceGrid/simple/msbuild/server/server.csproj b/csharp/IceGrid/simple/msbuild/server/server.csproj index f21a23c9a..c12295699 100644 --- a/csharp/IceGrid/simple/msbuild/server/server.csproj +++ b/csharp/IceGrid/simple/msbuild/server/server.csproj @@ -13,5 +13,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/IceStorm/clock/Publisher.cs b/csharp/IceStorm/clock/Publisher.cs index 8171d107a..2d64599ad 100644 --- a/csharp/IceStorm/clock/Publisher.cs +++ b/csharp/IceStorm/clock/Publisher.cs @@ -1,13 +1,9 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; -using System.Diagnostics; using System.Globalization; -public class Publisher +internal class Publisher { public static int Main(string[] args) { @@ -15,21 +11,15 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.pub")) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args, "config.pub"); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - status = run(communicator, args); - } + status = Run(communicator, args); } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -38,30 +28,30 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator, string[] args) + private static int Run(Ice.Communicator communicator, string[] args) { string option = "None"; string topicName = "time"; int i; - for(i = 0; i < args.Length; ++i) + for (i = 0; i < args.Length; ++i) { - String oldoption = option; - if(args[i].Equals("--datagram")) + string oldoption = option; + if (args[i].Equals("--datagram")) { option = "Datagram"; } - else if(args[i].Equals("--twoway")) + else if (args[i].Equals("--twoway")) { option = "Twoway"; } - else if(args[i].Equals("--oneway")) + else if (args[i].Equals("--oneway")) { option = "Oneway"; } - else if(args[i].StartsWith("--")) + else if (args[i].StartsWith("--")) { - usage(); + Usage(); return 1; } else @@ -70,63 +60,60 @@ private static int run(Ice.Communicator communicator, string[] args) break; } - if(!oldoption.Equals(option) && !oldoption.Equals("None")) + if (!oldoption.Equals(option) && !oldoption.Equals("None")) { - usage(); + Usage(); return 1; } } - if(i != args.Length) + if (i != args.Length) { - usage(); + Usage(); return 1; } IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast( communicator.propertyToProxy("TopicManager.Proxy")); - if(manager == null) + if (manager == null) { Console.WriteLine("invalid proxy"); return 1; } - // // Retrieve the topic. - // IceStorm.TopicPrx topic; try { topic = manager.retrieve(topicName); } - catch(IceStorm.NoSuchTopic) + catch (IceStorm.NoSuchTopic) { try { topic = manager.create(topicName); } - catch(IceStorm.TopicExists) + catch (IceStorm.TopicExists) { Console.WriteLine("temporary error. try again."); return 1; } } - // // Get the topic's publisher object, and create a Clock proxy with // the mode specified as an argument of this application. - // Ice.ObjectPrx publisher = topic.getPublisher(); - if(option.Equals("Datagram")) + if (option.Equals("Datagram")) { publisher = publisher.ice_datagram(); } - else if(option.Equals("Twoway")) + else if (option.Equals("Twoway")) { // Do nothing. } - else // if(oneway) + else { + // if(oneway) publisher = publisher.ice_oneway(); } ClockPrx clock = ClockPrxHelper.uncheckedCast(publisher); @@ -134,13 +121,13 @@ private static int run(Ice.Communicator communicator, string[] args) Console.WriteLine("publishing tick events. Press ^C to terminate the application."); try { - while(true) + while (true) { clock.tick(System.DateTime.Now.ToString("G", DateTimeFormatInfo.InvariantInfo)); System.Threading.Thread.Sleep(1000); } } - catch(Ice.CommunicatorDestroyedException) + catch (Ice.CommunicatorDestroyedException) { // Ignore } @@ -148,7 +135,7 @@ private static int run(Ice.Communicator communicator, string[] args) return 0; } - private static void usage() + private static void Usage() { Console.WriteLine("Usage: [--datagram|--twoway|--oneway] [topic]"); } diff --git a/csharp/IceStorm/clock/Subscriber.cs b/csharp/IceStorm/clock/Subscriber.cs index 3cb306a47..2339cad51 100644 --- a/csharp/IceStorm/clock/Subscriber.cs +++ b/csharp/IceStorm/clock/Subscriber.cs @@ -1,15 +1,11 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; using System.Diagnostics; -using System.Collections.Generic; -public class Subscriber +internal class Subscriber { - public class ClockI : ClockDisp_ + internal class ClockI : ClockDisp_ { public override void tick(string date, Ice.Current current) { @@ -23,26 +19,20 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args, "config.sub")) - { - // - // Shutdown the communicator on Ctrl+C or Ctrl+Break - // (always use Cancel = true with shutdown) - // - Console.CancelKeyPress += (sender, eventArgs) => - { - eventArgs.Cancel = true; - communicator.shutdown(); - }; + using var communicator = Ice.Util.initialize(ref args, "config.sub"); + // Shutdown the communicator on Ctrl+C or Ctrl+Break + // (always use Cancel = true with shutdown) + Console.CancelKeyPress += (sender, eventArgs) => + { + eventArgs.Cancel = true; + communicator.shutdown(); + }; - status = run(communicator, args); - } + status = Run(communicator, args); } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -51,7 +41,7 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator, string[] args) + private static int Run(Ice.Communicator communicator, string[] args) { args = communicator.getProperties().parseCommandLineOptions("Clock", args); @@ -61,52 +51,52 @@ private static int run(Ice.Communicator communicator, string[] args) string id = null; string retryCount = null; int i; - for(i = 0; i < args.Length; ++i) + for (i = 0; i < args.Length; ++i) { - String oldoption = option; - if(args[i].Equals("--datagram")) + string oldoption = option; + if (args[i].Equals("--datagram")) { option = "Datagram"; } - else if(args[i].Equals("--twoway")) + else if (args[i].Equals("--twoway")) { option = "Twoway"; } - else if(args[i].Equals("--ordered")) + else if (args[i].Equals("--ordered")) { option = "Ordered"; } - else if(args[i].Equals("--oneway")) + else if (args[i].Equals("--oneway")) { option = "Oneway"; } - else if(args[i].Equals("--batch")) + else if (args[i].Equals("--batch")) { batch = true; } - else if(args[i].Equals("--id")) + else if (args[i].Equals("--id")) { ++i; - if(i >= args.Length) + if (i >= args.Length) { - usage(); + Usage(); return 1; } id = args[i]; } - else if(args[i].Equals("--retryCount")) + else if (args[i].Equals("--retryCount")) { ++i; - if(i >= args.Length) + if (i >= args.Length) { - usage(); + Usage(); return 1; } retryCount = args[i]; } - else if(args[i].StartsWith("--")) + else if (args[i].StartsWith("--")) { - usage(); + Usage(); return 1; } else @@ -115,20 +105,20 @@ private static int run(Ice.Communicator communicator, string[] args) break; } - if(!oldoption.Equals(option) && !oldoption.Equals("None")) + if (!oldoption.Equals(option) && !oldoption.Equals("None")) { - usage(); + Usage(); return 1; } } - if(i != args.Length) + if (i != args.Length) { - usage(); + Usage(); return 1; } - if(batch && (option.Equals("Twoway") || option.Equals("Ordered"))) + if (batch && (option.Equals("Twoway") || option.Equals("Ordered"))) { Console.WriteLine("batch can only be set with oneway or datagram"); return 1; @@ -136,27 +126,25 @@ private static int run(Ice.Communicator communicator, string[] args) IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast( communicator.propertyToProxy("TopicManager.Proxy")); - if(manager == null) + if (manager == null) { Console.WriteLine("invalid proxy"); return 1; } - // // Retrieve the topic. - // IceStorm.TopicPrx topic; try { topic = manager.retrieve(topicName); } - catch(IceStorm.NoSuchTopic) + catch (IceStorm.NoSuchTopic) { try { topic = manager.create(topicName); } - catch(IceStorm.TopicExists) + catch (IceStorm.TopicExists) { Console.WriteLine("temporary error. try again."); return 1; @@ -164,7 +152,6 @@ private static int run(Ice.Communicator communicator, string[] args) } Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Clock.Subscriber"); - // // Add a servant for the Ice object. If --id is used the // identity comes from the command line, otherwise a UUID is // used. @@ -172,30 +159,25 @@ private static int run(Ice.Communicator communicator, string[] args) // id is not directly altered since it is used below to // detect whether subscribeAndGetPublisher can raise // AlreadySubscribed. - // Ice.Identity subId = new Ice.Identity(id, ""); - if(subId.name == null) + if (subId.name == null) { subId.name = Guid.NewGuid().ToString(); } Ice.ObjectPrx subscriber = adapter.add(new ClockI(), subId); - // // Activate the object adapter before subscribing. - // adapter.activate(); Dictionary qos = new Dictionary(); - if(retryCount != null) + if (retryCount != null) { qos["retryCount"] = retryCount; } - // // Set up the proxy. - // - if(option.Equals("Datagram")) + if (option.Equals("Datagram")) { - if(batch) + if (batch) { subscriber = subscriber.ice_batchDatagram(); } @@ -204,18 +186,18 @@ private static int run(Ice.Communicator communicator, string[] args) subscriber = subscriber.ice_datagram(); } } - else if(option.Equals("Twoway")) + else if (option.Equals("Twoway")) { // Do nothing to the subscriber proxy. Its already twoway. } - else if(option.Equals("Ordered")) + else if (option.Equals("Ordered")) { // Do nothing to the subscriber proxy. Its already twoway. qos["reliability"] = "ordered"; } - else if(option.Equals("Oneway") || option.Equals("None")) + else if (option.Equals("Oneway") || option.Equals("None")) { - if(batch) + if (batch) { subscriber = subscriber.ice_batchOneway(); } @@ -229,7 +211,7 @@ private static int run(Ice.Communicator communicator, string[] args) { topic.subscribeAndGetPublisher(qos, subscriber); } - catch(IceStorm.AlreadySubscribed) + catch (IceStorm.AlreadySubscribed) { // This should never occur when subscribing with an UUID Debug.Assert(id != null); @@ -242,7 +224,7 @@ private static int run(Ice.Communicator communicator, string[] args) return 0; } - private static void usage() + private static void Usage() { Console.WriteLine("Usage: [--batch] [--datagram|--twoway|--ordered|--oneway] " + "[--retryCount count] [--id id] [topic]"); diff --git a/csharp/IceStorm/clock/msbuild/publisher/publisher.csproj b/csharp/IceStorm/clock/msbuild/publisher/publisher.csproj index e66f5ea76..d3103b43c 100644 --- a/csharp/IceStorm/clock/msbuild/publisher/publisher.csproj +++ b/csharp/IceStorm/clock/msbuild/publisher/publisher.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/IceStorm/clock/msbuild/subscriber/subscriber.csproj b/csharp/IceStorm/clock/msbuild/subscriber/subscriber.csproj index 4c4e43e65..5a6ed10fa 100644 --- a/csharp/IceStorm/clock/msbuild/subscriber/subscriber.csproj +++ b/csharp/IceStorm/clock/msbuild/subscriber/subscriber.csproj @@ -12,5 +12,13 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/csharp/Manual/printer/Client/Client.csproj b/csharp/Manual/printer/Client/Client.csproj index bebc2db06..1bda16364 100644 --- a/csharp/Manual/printer/Client/Client.csproj +++ b/csharp/Manual/printer/Client/Client.csproj @@ -19,8 +19,17 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - ../Printer.ice + ../Printer.ice diff --git a/csharp/Manual/printer/Client/Program.cs b/csharp/Manual/printer/Client/Program.cs index ea506dc87..10bd41508 100644 --- a/csharp/Manual/printer/Client/Program.cs +++ b/csharp/Manual/printer/Client/Program.cs @@ -1,31 +1,21 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Demo; -using System; namespace Client { - public class Program + internal class Program { public static int Main(string[] args) { try { - using(Ice.Communicator communicator = Ice.Util.initialize(ref args)) - { - var obj = communicator.stringToProxy("SimplePrinter:default -h localhost -p 10000"); - var printer = PrinterPrxHelper.checkedCast(obj); - if(printer == null) - { - throw new ApplicationException("Invalid proxy"); - } - - printer.printString("Hello World!"); - } + using Ice.Communicator communicator = Ice.Util.initialize(ref args); + var obj = communicator.stringToProxy("SimplePrinter:default -h localhost -p 10000"); + var printer = PrinterPrxHelper.checkedCast(obj) ?? throw new ApplicationException("Invalid proxy"); + printer.printString("Hello World!"); } - catch(Exception e) + catch (Exception e) { Console.Error.WriteLine(e); return 1; diff --git a/csharp/Manual/printer/Server/Program.cs b/csharp/Manual/printer/Server/Program.cs index 54cbfee64..86a546b79 100644 --- a/csharp/Manual/printer/Server/Program.cs +++ b/csharp/Manual/printer/Server/Program.cs @@ -1,12 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -using System; +// Copyright (c) ZeroC, Inc. namespace Server { - public class PrinterI : Demo.PrinterDisp_ + internal class PrinterI : Demo.PrinterDisp_ { public override void printString(string s, Ice.Current current) { @@ -14,22 +10,20 @@ public override void printString(string s, Ice.Current current) } } - public class Program + internal class Program { public static int Main(string[] args) { try { - using(Ice.Communicator communicator = Ice.Util.initialize(ref args)) - { - var adapter = - communicator.createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -h localhost -p 10000"); - adapter.add(new PrinterI(), Ice.Util.stringToIdentity("SimplePrinter")); - adapter.activate(); - communicator.waitForShutdown(); - } + using Ice.Communicator communicator = Ice.Util.initialize(ref args); + var adapter = + communicator.createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -h localhost -p 10000"); + adapter.add(new PrinterI(), Ice.Util.stringToIdentity("SimplePrinter")); + adapter.activate(); + communicator.waitForShutdown(); } - catch(Exception e) + catch (Exception e) { Console.Error.WriteLine(e); return 1; diff --git a/csharp/Manual/printer/Server/Server.csproj b/csharp/Manual/printer/Server/Server.csproj index e68e1339c..2c43f21dd 100644 --- a/csharp/Manual/printer/Server/Server.csproj +++ b/csharp/Manual/printer/Server/Server.csproj @@ -19,8 +19,17 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - ../Printer.ice + ../Printer.ice diff --git a/csharp/Manual/simpleFilesystem/Client/Client.csproj b/csharp/Manual/simpleFilesystem/Client/Client.csproj index b0d46ba71..239033f29 100644 --- a/csharp/Manual/simpleFilesystem/Client/Client.csproj +++ b/csharp/Manual/simpleFilesystem/Client/Client.csproj @@ -19,8 +19,17 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - ../Filesystem.ice + ../Filesystem.ice diff --git a/csharp/Manual/simpleFilesystem/Client/Program.cs b/csharp/Manual/simpleFilesystem/Client/Program.cs index 38a809b57..0b76b2206 100644 --- a/csharp/Manual/simpleFilesystem/Client/Program.cs +++ b/csharp/Manual/simpleFilesystem/Client/Program.cs @@ -1,74 +1,58 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Filesystem; -using System; -public class Program +internal class Program { + public static int Main(string[] args) + { + try + { + using Ice.Communicator ic = Ice.Util.initialize(ref args); + // Create a proxy for the root directory + var obj = ic.stringToProxy("RootDir:default -h localhost -p 10000"); + + // Down-cast the proxy to a Directory proxy + var rootDir = DirectoryPrxHelper.checkedCast(obj) ?? throw new ApplicationException("Invalid proxy"); + + // Recursively list the contents of the root directory + Console.WriteLine("Contents of root directory:"); + ListRecursive(rootDir, 0); + } + catch (Exception e) + { + Console.Error.WriteLine(e); + return 1; + } + return 0; + } + // Recursively print the contents of directory "dir" in tree fashion. // For files, show the contents of each file. The "depth" // parameter is the current nesting level (for indentation). - - static void listRecursive(DirectoryPrx dir, int depth) + private static void ListRecursive(DirectoryPrx dir, int depth) { var indent = new string('\t', ++depth); NodePrx[] contents = dir.list(); - foreach(var node in contents) + foreach (var node in contents) { var subdir = DirectoryPrxHelper.checkedCast(node); var file = FilePrxHelper.uncheckedCast(node); Console.WriteLine(indent + node.name() + (subdir != null ? " (directory):" : " (file):")); - if(subdir != null) + if (subdir != null) { - listRecursive(subdir, depth); + ListRecursive(subdir, depth); } else { var text = file.read(); - for(int j = 0; j < text.Length; ++j) + for (int j = 0; j < text.Length; ++j) { Console.WriteLine(indent + "\t" + text[j]); } } } } - - public static int Main(string[] args) - { - try - { - using(Ice.Communicator ic = Ice.Util.initialize(ref args)) - { - // - // Create a proxy for the root directory - // - var obj = ic.stringToProxy("RootDir:default -h localhost -p 10000"); - - // - // Down-cast the proxy to a Directory proxy - // - var rootDir = DirectoryPrxHelper.checkedCast(obj); - if(rootDir == null) - { - throw new ApplicationException("Invalid proxy"); - } - - // - // Recursively list the contents of the root directory - // - Console.WriteLine("Contents of root directory:"); - listRecursive(rootDir, 0); - } - } - catch(Exception e) - { - Console.Error.WriteLine(e); - return 1; - } - return 0; - } } diff --git a/csharp/Manual/simpleFilesystem/Server/DirectoryI.cs b/csharp/Manual/simpleFilesystem/Server/DirectoryI.cs index 10eee547f..97b20a72f 100644 --- a/csharp/Manual/simpleFilesystem/Server/DirectoryI.cs +++ b/csharp/Manual/simpleFilesystem/Server/DirectoryI.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Filesystem; -using System.Collections.Generic; -public class DirectoryI : DirectoryDisp_ +internal class DirectoryI : DirectoryDisp_ { // DirectoryI constructor public DirectoryI(string name, DirectoryI parent) @@ -13,9 +10,7 @@ public DirectoryI(string name, DirectoryI parent) _name = name; _parent = parent; - // // Create an identity. The root directory has the fixed identity "RootDir" - // _id = new Ice.Identity(); _id.name = _parent != null ? System.Guid.NewGuid().ToString() : "RootDir"; } @@ -34,23 +29,23 @@ public override NodePrx[] list(Ice.Current current) // addChild is called by the child in order to add // itself to the _contents member of the parent - public void addChild(NodePrx child) + public void AddChild(NodePrx child) { _contents.Add(child); } // Add servant to ASM and parent's _contents map. - public void activate(Ice.ObjectAdapter a) + public void Activate(Ice.ObjectAdapter a) { var thisNode = NodePrxHelper.uncheckedCast(a.add(this, _id)); - if(_parent != null) + if (_parent != null) { - _parent.addChild(thisNode); + _parent.AddChild(thisNode); } } private string _name; - private DirectoryI _parent; + private readonly DirectoryI _parent; private Ice.Identity _id; private List _contents = new List(); } diff --git a/csharp/Manual/simpleFilesystem/Server/FileI.cs b/csharp/Manual/simpleFilesystem/Server/FileI.cs index f01044a6c..e1eb4bf68 100644 --- a/csharp/Manual/simpleFilesystem/Server/FileI.cs +++ b/csharp/Manual/simpleFilesystem/Server/FileI.cs @@ -1,11 +1,9 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Filesystem; using System.Diagnostics; -public class FileI : FileDisp_ +internal class FileI : FileDisp_ { // FileI constructor public FileI(string name, DirectoryI parent) @@ -15,9 +13,7 @@ public FileI(string name, DirectoryI parent) Debug.Assert(_parent != null); - // // Create an identity - // _id = new Ice.Identity(); _id.name = System.Guid.NewGuid().ToString(); } @@ -41,14 +37,14 @@ public override void write(string[] text, Ice.Current current = null) } // Add servant to ASM and parent's _contents map. - public void activate(Ice.ObjectAdapter a) + public void Activate(Ice.ObjectAdapter a) { var thisNode = NodePrxHelper.uncheckedCast(a.add(this, _id)); - _parent.addChild(thisNode); + _parent.AddChild(thisNode); } private string _name; - private DirectoryI _parent; + private readonly DirectoryI _parent; private Ice.Identity _id; private string[] _lines; } diff --git a/csharp/Manual/simpleFilesystem/Server/Program.cs b/csharp/Manual/simpleFilesystem/Server/Program.cs index aa21f580a..ca6fdf346 100644 --- a/csharp/Manual/simpleFilesystem/Server/Program.cs +++ b/csharp/Manual/simpleFilesystem/Server/Program.cs @@ -1,11 +1,8 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. using Filesystem; -using System; -public class Program +internal class Program { public static int Main(string[] args) { @@ -13,21 +10,15 @@ public static int Main(string[] args) try { - // // using statement - communicator is automatically destroyed // at the end of this statement - // - using(var communicator = Ice.Util.initialize(ref args)) - { - // - // Destroy the communicator on Ctrl+C or Ctrl+Break - // - Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); + using var communicator = Ice.Util.initialize(ref args); + // Destroy the communicator on Ctrl+C or Ctrl+Break + Console.CancelKeyPress += (sender, eventArgs) => communicator.destroy(); - status = run(communicator); - } + status = Run(communicator); } - catch(Exception ex) + catch (Exception ex) { Console.Error.WriteLine(ex); status = 1; @@ -36,68 +27,57 @@ public static int Main(string[] args) return status; } - private static int run(Ice.Communicator communicator) + private static int Run(Ice.Communicator communicator) { - // // Create an object adapter. - // var adapter = communicator.createObjectAdapterWithEndpoints("SimpleFilesystem", "default -h localhost -p 10000"); - // // Create the root directory (with name "/" and no parent) - // var root = new DirectoryI("/", null); - root.activate(adapter); + root.Activate(adapter); - // // Create a file called "README" in the root directory - // var file = new FileI("README", root); - var text = new string[]{ "This file system contains a collection of poetry." }; + var text = new string[] { "This file system contains a collection of poetry." }; try { file.write(text); } - catch(GenericError e) + catch (GenericError e) { Console.Error.WriteLine(e.reason); } - file.activate(adapter); + file.Activate(adapter); - // // Create a directory called "Coleridge" in the root directory - // var coleridge = new DirectoryI("Coleridge", root); - coleridge.activate(adapter); + coleridge.Activate(adapter); - // // Create a file called "Kubla_Khan" in the Coleridge directory - // file = new FileI("Kubla_Khan", coleridge); - text = new string[]{ "In Xanadu did Kubla Khan", - "A stately pleasure-dome decree:", - "Where Alph, the sacred river, ran", - "Through caverns measureless to man", - "Down to a sunless sea." }; + text = + [ + "In Xanadu did Kubla Khan", + "A stately pleasure-dome decree:", + "Where Alph, the sacred river, ran", + "Through caverns measureless to man", + "Down to a sunless sea." + ]; try { file.write(text); } - catch(GenericError e) + catch (GenericError e) { Console.Error.WriteLine(e.reason); } - file.activate(adapter); + file.Activate(adapter); - // // All objects are created, allow client requests now - // adapter.activate(); - // // Wait until we are done - // communicator.waitForShutdown(); return 0; diff --git a/csharp/Manual/simpleFilesystem/Server/Server.csproj b/csharp/Manual/simpleFilesystem/Server/Server.csproj index 26444522f..e8de6d588 100644 --- a/csharp/Manual/simpleFilesystem/Server/Server.csproj +++ b/csharp/Manual/simpleFilesystem/Server/Server.csproj @@ -19,8 +19,17 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - ../Filesystem.ice + ../Filesystem.ice diff --git a/stylecop.json b/stylecop.json new file mode 100644 index 000000000..69df86b80 --- /dev/null +++ b/stylecop.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "documentationRules": { + "companyName": "ZeroC", + "copyrightText": "Copyright (c) ZeroC, Inc.", + "xmlHeader": false, + "documentInterfaces": false, + "documentExposedElements": true, + "documentInternalElements": false, + "documentPrivateElements": false, + "documentPrivateFields": false + } + } +}