Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions Samples/Metadata/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
insert_final_newline = true
indent_style = tab
indent_size = 4

# C# files
[*.cs]
# New line preferences
csharp_new_line_before_open_brace = none
csharp_new_line_before_catch = false
csharp_new_line_before_else = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_anonymous_types = false
csharp_new_line_before_members_in_object_initializers = false
csharp_new_line_within_query_expression_clauses = true

# Indentation preferences
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = flush_left

# avoid this. unless absolutely necessary
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion

# only use var when it's obvious what the variable type is
csharp_style_var_for_built_in_types = true:none
csharp_style_var_when_type_is_apparent = true:none
csharp_style_var_elsewhere = true:suggestion

# use language keywords instead of BCL types
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

# name all constant fields using PascalCase
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style

dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.required_modifiers = const

dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# static fields should have s_ prefix
dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields

dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static

dotnet_naming_style.static_prefix_style.capitalization = pascal_case

# internal and private fields should be _camelCase
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style

dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal

dotnet_naming_style.camel_case_underscore_style.required_prefix = _
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case

# Code style defaults
dotnet_sort_system_directives_first = true
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = false

# Expression-level preferences
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion

# Expression-bodied members
csharp_style_expression_bodied_methods = false:none
csharp_style_expression_bodied_constructors = false:none
csharp_style_expression_bodied_operators = false:none
csharp_style_expression_bodied_properties = true:none
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none

# Pattern matching
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion

# Null checking preferences
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

# 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 = do_not_ignore
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

# Xml project files
[*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}]
indent_size = 2

# Xml config files
[*.{props,targets,config,nuspec}]
indent_size = 2

[*.{cmd,ps1}]
indent_size = 8

[*.{yaml, yml}]
indent_size = 2

[*.iss]
indent_size = 2
indent_style = space
7 changes: 5 additions & 2 deletions Samples/Metadata/MetadataSamples.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33205.214
# Visual Studio Version 18
VisualStudioVersion = 18.8.12009.203 stable
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleMetadata", "SimpleMetadata\SimpleMetadata.csproj", "{5D07F2E4-0E18-45B0-9892-301D0F376674}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PersistedMetadata", "PersistedMetadata\PersistedMetadata.csproj", "{E7948E00-48F4-40EC-AEA7-95D4D980FF3A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E37482FD-52F2-4C89-80A8-635EC3D17626}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
125 changes: 62 additions & 63 deletions Samples/Metadata/PersistedMetadata/MessageWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,76 +12,75 @@
using ReactiveDomain.Messaging.Bus;
using Terminal.Gui;

namespace PersistedMetadata
namespace PersistedMetadata;

public partial class MessageWindow
{
public partial class MessageWindow
private readonly IBus _bus;
private Messages.Sender _currentUser;
public MessageWindow(InMemoryBus bus)
{
private readonly IBus _bus;
private Messages.Sender _currentUser;
public MessageWindow(InMemoryBus bus)
{
_bus = bus;
InitializeComponent();
quit.Clicked += () => Application.RequestStop();
bus.Subscribe(new AdHocHandler<Messages.Greeting>(ReceiveGreetings));
bus.Subscribe(new AdHocHandler<Messages.Farewell>(ReceiveFarewells));
sendGreeting.Clicked += SendGreetings;
sendFarewell.Clicked += SendFarewell;
editMeMenuItem1.Action = () => { _currentUser = new Messages.Sender { Name = "Alice" }; senderName.Text = _currentUser.Name; };
editMeMenuItem2.Action = () => { _currentUser = new Messages.Sender { Name = "Bob" }; senderName.Text = _currentUser.Name; };
}
private bool TryGetCurrentUser(out Messages.Sender user)
_bus = bus;
InitializeComponent();
quit.Clicked += () => Application.RequestStop();
bus.Subscribe(new AdHocHandler<Messages.Greeting>(ReceiveGreetings));
bus.Subscribe(new AdHocHandler<Messages.Farewell>(ReceiveFarewells));
sendGreeting.Clicked += SendGreetings;
sendFarewell.Clicked += SendFarewell;
editMeMenuItem1.Action = () => { _currentUser = new Messages.Sender { Name = "Alice" }; senderName.Text = _currentUser.Name; };
editMeMenuItem2.Action = () => { _currentUser = new Messages.Sender { Name = "Bob" }; senderName.Text = _currentUser.Name; };
}
private bool TryGetCurrentUser(out Messages.Sender user)
{
user = _currentUser;
if (_currentUser == null)
{
user = _currentUser;
if (_currentUser == null)
{
MessageBox.Query(55, 7, "Error", "Please login via the login menu at the top ^^^ first.", "Ok");
return false;
}
return true;
MessageBox.Query(55, 7, "Error", "Please login via the login menu at the top ^^^ first.", "Ok");
return false;
}
return true;
}

public void SendGreetings()
{
//get the logged-in user
if(!TryGetCurrentUser(out var user)){ return;}
//create message with greeting data
var msg = new Messages.Greeting((string)msgText.Text);
//add sender metadata to the message
msg.WriteMetadatum<Messages.Sender>(user);
_bus.Publish(msg);
}
public void SendFarewell()
{
//get the logged-in user
if(!TryGetCurrentUser(out var user)){ return;}
//create message with Farewell data
var msg = new Messages.Farewell((string)msgText.Text);
//add sender metadata to the message
msg.WriteMetadatum<Messages.Sender>(user);
_bus.Publish(msg);
}
public void ReceiveGreetings(Messages.Greeting msg)
{
// message type
msgType.Text = msg.GetType().Name;
public void SendGreetings()
{
//get the logged-in user
if(!TryGetCurrentUser(out var user)){ return;}
//create message with greeting data
var msg = new Messages.Greeting((string)msgText.Text);
//add sender metadata to the message
msg.WriteMetadatum<Messages.Sender>(user);
_bus.Publish(msg);
}
public void SendFarewell()
{
//get the logged-in user
if(!TryGetCurrentUser(out var user)){ return;}
//create message with Farewell data
var msg = new Messages.Farewell((string)msgText.Text);
//add sender metadata to the message
msg.WriteMetadatum<Messages.Sender>(user);
_bus.Publish(msg);
}
public void ReceiveGreetings(Messages.Greeting msg)
{
// message type
msgType.Text = msg.GetType().Name;

//read message data
msgTextReceived.Text = msg.Text;
//read message data
msgTextReceived.Text = msg.Text;

//read sender metadata
msgFrom.Text = msg.ReadMetadatum<Messages.Sender>().Name;
}
public void ReceiveFarewells(Messages.Farewell msg)
{
//message type
msgType.Text = msg.GetType().Name;
//read sender metadata
msgFrom.Text = msg.ReadMetadatum<Messages.Sender>().Name;
}
public void ReceiveFarewells(Messages.Farewell msg)
{
//message type
msgType.Text = msg.GetType().Name;

//read message data
msgTextReceived.Text = msg.Text;
//read message data
msgTextReceived.Text = msg.Text;

//read sender metadata
msgFrom.Text = msg.ReadMetadatum<Messages.Sender>().Name;
}
//read sender metadata
msgFrom.Text = msg.ReadMetadatum<Messages.Sender>().Name;
}
}
}
16 changes: 7 additions & 9 deletions Samples/Metadata/PersistedMetadata/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace PersistedMetadata;

public class Messages
{
public record Greeting(string Text) : Message;
public class Messages {
public record Greeting(string Text) : Message;

public record Farewell(string Text) : Message;
public record Farewell(string Text) : Message;

public class Sender
{
public string Name;
}
}
public class Sender {
public string? Name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ReactiveDomain" Version="0.14.1" />
<PackageReference Include="ReactiveDomain" Version="0.15.3" />
<PackageReference Include="Terminal.Gui" Version="1.19.0" />
</ItemGroup>

Expand Down
18 changes: 8 additions & 10 deletions Samples/Metadata/PersistedMetadata/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

namespace PersistedMetadata;

internal class Program
{
static void Main(string[] args)
{
Application.Init();
Application.Top.Add(new MessageWindow(new InMemoryBus("message bus")));
Application.Run();
internal class Program {
static void Main(string[] args) {
Application.Init();
Application.Top.Add(new MessageWindow(new InMemoryBus("message bus")));
Application.Run();

Application.Shutdown();
}
}
Application.Shutdown();
}
}
16 changes: 7 additions & 9 deletions Samples/Metadata/SimpleMetadata/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace SimpleMetadata;

public class Messages
{
public record Greeting(string Text) : Message;
public class Messages {
public record Greeting(string Text) : Message;

public record Farewell(string Text) : Message;
public record Farewell(string Text) : Message;

public class Sender
{
public string Name;
}
}
public class Sender {
public string? Name;
}
}
Loading
Loading