Compare commits
	
		
			108 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					da3d363dd2 | ||
| 
						 | 
					e4db04fd3e | ||
| 
						 | 
					79ea6dc46d | ||
| 
						 | 
					db50455545 | ||
| 
						 | 
					ba619605b9 | ||
| 
						 | 
					6b4fa3d63b | ||
| 
						 | 
					43312c3362 | ||
| 
						 | 
					94585fc3f2 | ||
| 
						 | 
					e35dc32284 | ||
| 
						 | 
					08e5857fc8 | ||
| 
						 | 
					bdbb99e17b | ||
| 
						 | 
					311ad9a2cc | ||
| 
						 | 
					259534c423 | ||
| 
						 | 
					d28beb5ae2 | ||
| 
						 | 
					3c5bdcbef8 | ||
| 
						 | 
					bc59f15d59 | ||
| 
						 | 
					5459722b24 | ||
| 
						 | 
					ed7e8f411a | ||
| 
						 | 
					16b430ef2f | ||
| 
						 | 
					05dd763f1b | ||
| 
						 | 
					c53cbe0096 | ||
| 
						 | 
					6d6ca3f633 | ||
| 
						 | 
					f989b59330 | ||
| 
						 | 
					db4fd905a2 | ||
| 
						 | 
					ed9f31df1f | ||
| 
						 | 
					018a48dd65 | ||
| 
						 | 
					9381a4e4c6 | ||
| 
						 | 
					93b39c97a7 | ||
| 
						 | 
					379d31dbfd | ||
| 
						 | 
					be2134313a | ||
| 
						 | 
					4ba5b64f66 | ||
| 
						 | 
					1195fa1b7e | ||
| 
						 | 
					5f48a06413 | ||
| 
						 | 
					38d8781734 | ||
| 
						 | 
					ae0131086e | ||
| 
						 | 
					57a4f2fb05 | ||
| 
						 | 
					d92f0a6f82 | ||
| 
						 | 
					ccd824dcc3 | ||
| 
						 | 
					339dc635e5 | ||
| 
						 | 
					9209bada7a | ||
| 
						 | 
					5b0537a04a | ||
| 
						 | 
					8fe51a15d5 | ||
| 
						 | 
					d2d1f66cf6 | ||
| 
						 | 
					c9bb863108 | ||
| 
						 | 
					caacc27fd2 | ||
| 
						 | 
					41f52d0b87 | ||
| 
						 | 
					90cc4e7ca6 | ||
| 
						 | 
					25f1563ef5 | ||
| 
						 | 
					399cee2eac | ||
| 
						 | 
					7903031fcc | ||
| 
						 | 
					d9ed50ef20 | ||
| 
						 | 
					00a1cb9826 | ||
| 
						 | 
					ce7106af32 | ||
| 
						 | 
					25701aa001 | ||
| 
						 | 
					ee15df00a4 | ||
| 
						 | 
					070040a1d3 | ||
| 
						 | 
					7ec3818c1c | ||
| 
						 | 
					615db818bc | ||
| 
						 | 
					31514d59c6 | ||
| 
						 | 
					371845f8ae | ||
| 
						 | 
					6a66d51092 | ||
| 
						 | 
					22ad8ee6fc | ||
| 
						 | 
					34480447f1 | ||
| 
						 | 
					e9abfeef48 | ||
| 
						 | 
					7009cf468a | ||
| 
						 | 
					be7c2e3afe | ||
| 
						 | 
					894767e65b | ||
| 
						 | 
					29e6c54550 | ||
| 
						 | 
					8643659c80 | ||
| 
						 | 
					dbcec2f299 | ||
| 
						 | 
					fea7b6af42 | ||
| 
						 | 
					1a34c7b4c4 | ||
| f8b0ca332b | |||
| 
						 | 
					a5fb32fa75 | ||
| 
						 | 
					a3e3bd7d85 | ||
| cb526d400c | |||
| 
						 | 
					ab1ee48396 | ||
| 
						 | 
					91c7035162 | ||
| 
						 | 
					cf345ce467 | ||
| 
						 | 
					81ae64a7c8 | ||
| 
						 | 
					b04db19170 | ||
| 
						 | 
					cc6f5461e5 | ||
| 
						 | 
					8dff41e4c0 | ||
| 
						 | 
					0d5cf05ab4 | ||
| 
						 | 
					ad7b14773a | ||
| 
						 | 
					33b89eb696 | ||
| 
						 | 
					1e17b9dcb5 | ||
| 
						 | 
					0fde9d5425 | ||
| 
						 | 
					ed6368250a | ||
| 
						 | 
					11e1d14fcf | ||
| 
						 | 
					ab4765ae0a | ||
| 
						 | 
					fcbdc0b392 | ||
| 
						 | 
					0e0399c7d9 | ||
| 
						 | 
					2d796505b7 | ||
| 
						 | 
					1fd296a021 | ||
| 
						 | 
					f19f3f5833 | ||
| 
						 | 
					d545bc2ded | ||
| 
						 | 
					ceb24fc3dc | ||
| 
						 | 
					3890d27d7f | ||
| 
						 | 
					7bf99a7390 | ||
| 6653fd2768 | |||
| 491459236b | |||
| 
						 | 
					da38776ebb | ||
| 202f11a500 | |||
| 
						 | 
					fece29b071 | ||
| 
						 | 
					570d990a94 | ||
| 
						 | 
					d7b0a471f0 | ||
| 
						 | 
					e38eb7aa1c | 
							
								
								
									
										226
									
								
								.editorconfig
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										226
									
								
								.editorconfig
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,226 @@
 | 
			
		||||
# Remove the line below if you want to inherit .editorconfig settings from higher directories
 | 
			
		||||
root = true
 | 
			
		||||
 | 
			
		||||
# C# files
 | 
			
		||||
[*.cs]
 | 
			
		||||
 | 
			
		||||
#### Core EditorConfig Options ####
 | 
			
		||||
 | 
			
		||||
# Indentation and spacing
 | 
			
		||||
indent_size = 3
 | 
			
		||||
indent_style = tab
 | 
			
		||||
tab_width = 3
 | 
			
		||||
 | 
			
		||||
# New line preferences
 | 
			
		||||
end_of_line = crlf
 | 
			
		||||
insert_final_newline = false
 | 
			
		||||
 | 
			
		||||
#### .NET Coding Conventions ####
 | 
			
		||||
 | 
			
		||||
# Organize usings
 | 
			
		||||
dotnet_separate_import_directive_groups = false
 | 
			
		||||
dotnet_sort_system_directives_first = true
 | 
			
		||||
file_header_template = unset
 | 
			
		||||
 | 
			
		||||
# this. and Me. preferences
 | 
			
		||||
dotnet_style_qualification_for_event = false
 | 
			
		||||
dotnet_style_qualification_for_field = false
 | 
			
		||||
dotnet_style_qualification_for_method = false
 | 
			
		||||
dotnet_style_qualification_for_property = false
 | 
			
		||||
 | 
			
		||||
# Language keywords vs BCL types preferences
 | 
			
		||||
dotnet_style_predefined_type_for_locals_parameters_members = true
 | 
			
		||||
dotnet_style_predefined_type_for_member_access = true
 | 
			
		||||
 | 
			
		||||
# Parentheses preferences
 | 
			
		||||
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
 | 
			
		||||
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
 | 
			
		||||
dotnet_style_parentheses_in_other_operators = never_if_unnecessary
 | 
			
		||||
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
 | 
			
		||||
 | 
			
		||||
# Modifier preferences
 | 
			
		||||
dotnet_style_require_accessibility_modifiers = for_non_interface_members
 | 
			
		||||
 | 
			
		||||
# Expression-level preferences
 | 
			
		||||
dotnet_style_coalesce_expression = true
 | 
			
		||||
dotnet_style_collection_initializer = true
 | 
			
		||||
dotnet_style_explicit_tuple_names = true
 | 
			
		||||
dotnet_style_namespace_match_folder = true
 | 
			
		||||
dotnet_style_null_propagation = true
 | 
			
		||||
dotnet_style_object_initializer = true
 | 
			
		||||
dotnet_style_operator_placement_when_wrapping = beginning_of_line
 | 
			
		||||
dotnet_style_prefer_auto_properties = true
 | 
			
		||||
dotnet_style_prefer_compound_assignment = true
 | 
			
		||||
dotnet_style_prefer_conditional_expression_over_assignment = true
 | 
			
		||||
dotnet_style_prefer_conditional_expression_over_return = true
 | 
			
		||||
dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed
 | 
			
		||||
dotnet_style_prefer_inferred_anonymous_type_member_names = true
 | 
			
		||||
dotnet_style_prefer_inferred_tuple_names = true
 | 
			
		||||
dotnet_style_prefer_is_null_check_over_reference_equality_method = true
 | 
			
		||||
dotnet_style_prefer_simplified_boolean_expressions = true
 | 
			
		||||
dotnet_style_prefer_simplified_interpolation = true
 | 
			
		||||
 | 
			
		||||
# Field preferences
 | 
			
		||||
dotnet_style_readonly_field = true
 | 
			
		||||
 | 
			
		||||
# Parameter preferences
 | 
			
		||||
dotnet_code_quality_unused_parameters = all
 | 
			
		||||
 | 
			
		||||
# Suppression preferences
 | 
			
		||||
dotnet_remove_unnecessary_suppression_exclusions = none
 | 
			
		||||
 | 
			
		||||
# New line preferences
 | 
			
		||||
dotnet_style_allow_multiple_blank_lines_experimental = false
 | 
			
		||||
dotnet_style_allow_statement_immediately_after_block_experimental = false
 | 
			
		||||
 | 
			
		||||
#### C# Coding Conventions ####
 | 
			
		||||
 | 
			
		||||
# var preferences
 | 
			
		||||
csharp_style_var_elsewhere = true
 | 
			
		||||
csharp_style_var_for_built_in_types = true
 | 
			
		||||
csharp_style_var_when_type_is_apparent = true
 | 
			
		||||
 | 
			
		||||
# Expression-bodied members
 | 
			
		||||
csharp_style_expression_bodied_accessors = true
 | 
			
		||||
csharp_style_expression_bodied_constructors = false
 | 
			
		||||
csharp_style_expression_bodied_indexers = true
 | 
			
		||||
csharp_style_expression_bodied_lambdas = true
 | 
			
		||||
csharp_style_expression_bodied_local_functions = false
 | 
			
		||||
csharp_style_expression_bodied_methods = false
 | 
			
		||||
csharp_style_expression_bodied_operators = false
 | 
			
		||||
csharp_style_expression_bodied_properties = true
 | 
			
		||||
 | 
			
		||||
# Pattern matching preferences
 | 
			
		||||
csharp_style_pattern_matching_over_as_with_null_check = true
 | 
			
		||||
csharp_style_pattern_matching_over_is_with_cast_check = true
 | 
			
		||||
csharp_style_prefer_extended_property_pattern = true
 | 
			
		||||
csharp_style_prefer_not_pattern = true
 | 
			
		||||
csharp_style_prefer_pattern_matching = true
 | 
			
		||||
csharp_style_prefer_switch_expression = true
 | 
			
		||||
 | 
			
		||||
# Null-checking preferences
 | 
			
		||||
csharp_style_conditional_delegate_call = true
 | 
			
		||||
 | 
			
		||||
# Modifier preferences
 | 
			
		||||
csharp_prefer_static_local_function = true
 | 
			
		||||
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async
 | 
			
		||||
csharp_style_prefer_readonly_struct = true
 | 
			
		||||
 | 
			
		||||
# Code-block preferences
 | 
			
		||||
csharp_prefer_braces = when_multiline
 | 
			
		||||
csharp_prefer_simple_using_statement = true
 | 
			
		||||
csharp_style_namespace_declarations = file_scoped
 | 
			
		||||
csharp_style_prefer_method_group_conversion = true
 | 
			
		||||
csharp_style_prefer_top_level_statements = true
 | 
			
		||||
 | 
			
		||||
# Expression-level preferences
 | 
			
		||||
csharp_prefer_simple_default_expression = true
 | 
			
		||||
csharp_style_deconstructed_variable_declaration = true
 | 
			
		||||
csharp_style_implicit_object_creation_when_type_is_apparent = true
 | 
			
		||||
csharp_style_inlined_variable_declaration = true
 | 
			
		||||
csharp_style_prefer_index_operator = true
 | 
			
		||||
csharp_style_prefer_local_over_anonymous_function = true
 | 
			
		||||
csharp_style_prefer_null_check_over_type_check = true
 | 
			
		||||
csharp_style_prefer_range_operator = true
 | 
			
		||||
csharp_style_prefer_tuple_swap = true
 | 
			
		||||
csharp_style_prefer_utf8_string_literals = true
 | 
			
		||||
csharp_style_throw_expression = true
 | 
			
		||||
csharp_style_unused_value_assignment_preference = discard_variable
 | 
			
		||||
csharp_style_unused_value_expression_statement_preference = discard_variable
 | 
			
		||||
 | 
			
		||||
# 'using' directive preferences
 | 
			
		||||
csharp_using_directive_placement = outside_namespace
 | 
			
		||||
 | 
			
		||||
# New line preferences
 | 
			
		||||
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
 | 
			
		||||
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false
 | 
			
		||||
csharp_style_allow_embedded_statements_on_same_line_experimental = false
 | 
			
		||||
 | 
			
		||||
#### 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 = true
 | 
			
		||||
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 = false
 | 
			
		||||
 | 
			
		||||
#### Naming styles ####
 | 
			
		||||
 | 
			
		||||
# Naming rules
 | 
			
		||||
 | 
			
		||||
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
 | 
			
		||||
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
 | 
			
		||||
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
 | 
			
		||||
 | 
			
		||||
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
 | 
			
		||||
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
 | 
			
		||||
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
 | 
			
		||||
 | 
			
		||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
 | 
			
		||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
 | 
			
		||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
 | 
			
		||||
 | 
			
		||||
# Symbol specifications
 | 
			
		||||
 | 
			
		||||
dotnet_naming_symbols.interface.applicable_kinds = interface
 | 
			
		||||
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
 | 
			
		||||
dotnet_naming_symbols.interface.required_modifiers = 
 | 
			
		||||
 | 
			
		||||
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
 | 
			
		||||
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
 | 
			
		||||
dotnet_naming_symbols.types.required_modifiers = 
 | 
			
		||||
 | 
			
		||||
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
 | 
			
		||||
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
 | 
			
		||||
dotnet_naming_symbols.non_field_members.required_modifiers = 
 | 
			
		||||
 | 
			
		||||
# Naming styles
 | 
			
		||||
 | 
			
		||||
dotnet_naming_style.pascal_case.required_prefix = 
 | 
			
		||||
dotnet_naming_style.pascal_case.required_suffix = 
 | 
			
		||||
dotnet_naming_style.pascal_case.word_separator = 
 | 
			
		||||
dotnet_naming_style.pascal_case.capitalization = pascal_case
 | 
			
		||||
 | 
			
		||||
dotnet_naming_style.begins_with_i.required_prefix = I
 | 
			
		||||
dotnet_naming_style.begins_with_i.required_suffix = 
 | 
			
		||||
dotnet_naming_style.begins_with_i.word_separator = 
 | 
			
		||||
dotnet_naming_style.begins_with_i.capitalization = pascal_case
 | 
			
		||||
							
								
								
									
										4
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
			
		||||
[submodule "dependencies/Connected"]
 | 
			
		||||
	path = dependencies/Connected
 | 
			
		||||
	url = https://git.tompit.com/Connected/Connected.git
 | 
			
		||||
	branch = develop
 | 
			
		||||
							
								
								
									
										160
									
								
								Framework.sln
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										160
									
								
								Framework.sln
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,160 @@
 | 
			
		||||
 | 
			
		||||
Microsoft Visual Studio Solution File, Format Version 12.00
 | 
			
		||||
# Visual Studio Version 17
 | 
			
		||||
VisualStudioVersion = 17.4.33015.44
 | 
			
		||||
MinimumVisualStudioVersion = 10.0.40219.1
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Caching", "src\Connected.Caching\Connected.Caching.csproj", "{BF6FFC2B-455F-42E9-AEE5-FFC6AC62FDDD}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Collections", "src\Connected.Collections\Connected.Collections.csproj", "{A590C0CC-B45F-4C6C-A616-E21336E3AD67}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Configuration", "src\Connected.Configuration\Connected.Configuration.csproj", "{A4792E5A-9E84-4E97-8BBA-ADF6FAEA2555}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Data", "src\Connected.Data\Connected.Data.csproj", "{D6CE9557-D44E-42BC-A456-60D585CE2BD1}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Entities", "src\Connected.Entities\Connected.Entities.csproj", "{70AB5354-7DD1-49F5-8588-2EF1950282AE}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Globalization", "src\Connected.Globalization\Connected.Globalization.csproj", "{30E25D63-B98C-4BF0-99F3-65F551AB8224}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Hosting", "src\Connected.Hosting\Connected.Hosting.csproj", "{7A96AE54-D136-4ADF-8CFC-4207CA7AF4E8}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Instance", "src\Connected.Instance\Connected.Instance.csproj", "{A0C1D651-0EE4-409C-85A7-422650A3882D}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Interop", "src\Connected.Interop\Connected.Interop.csproj", "{4EDCE178-8C40-41CF-BA03-D42766AC2F35}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Middleware", "src\Connected.Middleware\Connected.Middleware.csproj", "{82B81B59-1062-4856-8F3A-F887C0D93E50}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Net", "src\Connected.Net\Connected.Net.csproj", "{800B4133-DF4B-4DE3-A47F-7735DB51C071}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Notifications", "src\Connected.Notifications\Connected.Notifications.csproj", "{4C26289D-C683-4198-8CA2-904F44FA2833}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Rest", "src\Connected.Rest\Connected.Rest.csproj", "{50B5809D-E6AF-4098-95A8-3D19E97952BE}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Runtime", "src\Connected.Runtime\Connected.Runtime.csproj", "{4CDE950C-ECDA-4B93-B24E-968BFA83D92D}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Security", "src\Connected.Security\Connected.Security.csproj", "{EF5503C2-224B-45C5-8F8F-0EE5C99C305C}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Services", "src\Connected.Services\Connected.Services.csproj", "{73987148-A515-4523-BC4D-8B41DF2F3FD8}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Threading", "src\Connected.Threading\Connected.Threading.csproj", "{F14222DE-D0CE-4C76-B4B7-3312B3855B65}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Validation", "src\Connected.Validation\Connected.Validation.csproj", "{BAE4A983-1C9E-4ADA-AB0A-C401EBBA6A0C}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Expressions", "src\Connected.Expressions\Connected.Expressions.csproj", "{E597528B-95CA-4ACB-A44B-2C0737084581}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Data.Tests", "src\Connected.Data.Tests\Connected.Data.Tests.csproj", "{C6520F60-774E-41B1-8B17-7EF0B825BF6A}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{D6F579A8-2BDD-4E47-BF39-FB8650E5039E}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Expressions.Tests", "src\Connected.Expressions.Tests\Connected.Expressions.Tests.csproj", "{9D4ED240-112A-467D-BCD7-2989DD172B83}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Dependencies", "Dependencies", "{FC409A4C-5FC3-4597-85BC-21DBB018450D}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected", "dependencies\Connected\src\Connected\Connected.csproj", "{451651E0-F7E2-42C3-B8C8-474D89B220B6}"
 | 
			
		||||
EndProject
 | 
			
		||||
Global
 | 
			
		||||
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 | 
			
		||||
		Debug|Any CPU = Debug|Any CPU
 | 
			
		||||
		Release|Any CPU = Release|Any CPU
 | 
			
		||||
	EndGlobalSection
 | 
			
		||||
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
 | 
			
		||||
		{BF6FFC2B-455F-42E9-AEE5-FFC6AC62FDDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{BF6FFC2B-455F-42E9-AEE5-FFC6AC62FDDD}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{BF6FFC2B-455F-42E9-AEE5-FFC6AC62FDDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{BF6FFC2B-455F-42E9-AEE5-FFC6AC62FDDD}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{A590C0CC-B45F-4C6C-A616-E21336E3AD67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{A590C0CC-B45F-4C6C-A616-E21336E3AD67}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{A590C0CC-B45F-4C6C-A616-E21336E3AD67}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{A590C0CC-B45F-4C6C-A616-E21336E3AD67}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{A4792E5A-9E84-4E97-8BBA-ADF6FAEA2555}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{A4792E5A-9E84-4E97-8BBA-ADF6FAEA2555}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{A4792E5A-9E84-4E97-8BBA-ADF6FAEA2555}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{A4792E5A-9E84-4E97-8BBA-ADF6FAEA2555}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{D6CE9557-D44E-42BC-A456-60D585CE2BD1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{D6CE9557-D44E-42BC-A456-60D585CE2BD1}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{D6CE9557-D44E-42BC-A456-60D585CE2BD1}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{D6CE9557-D44E-42BC-A456-60D585CE2BD1}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{70AB5354-7DD1-49F5-8588-2EF1950282AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{70AB5354-7DD1-49F5-8588-2EF1950282AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{70AB5354-7DD1-49F5-8588-2EF1950282AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{70AB5354-7DD1-49F5-8588-2EF1950282AE}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{30E25D63-B98C-4BF0-99F3-65F551AB8224}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{30E25D63-B98C-4BF0-99F3-65F551AB8224}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{30E25D63-B98C-4BF0-99F3-65F551AB8224}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{30E25D63-B98C-4BF0-99F3-65F551AB8224}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{7A96AE54-D136-4ADF-8CFC-4207CA7AF4E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{7A96AE54-D136-4ADF-8CFC-4207CA7AF4E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{7A96AE54-D136-4ADF-8CFC-4207CA7AF4E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{7A96AE54-D136-4ADF-8CFC-4207CA7AF4E8}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{A0C1D651-0EE4-409C-85A7-422650A3882D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{A0C1D651-0EE4-409C-85A7-422650A3882D}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{A0C1D651-0EE4-409C-85A7-422650A3882D}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{A0C1D651-0EE4-409C-85A7-422650A3882D}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{4EDCE178-8C40-41CF-BA03-D42766AC2F35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{4EDCE178-8C40-41CF-BA03-D42766AC2F35}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{4EDCE178-8C40-41CF-BA03-D42766AC2F35}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{4EDCE178-8C40-41CF-BA03-D42766AC2F35}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{82B81B59-1062-4856-8F3A-F887C0D93E50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{82B81B59-1062-4856-8F3A-F887C0D93E50}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{82B81B59-1062-4856-8F3A-F887C0D93E50}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{82B81B59-1062-4856-8F3A-F887C0D93E50}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{800B4133-DF4B-4DE3-A47F-7735DB51C071}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{800B4133-DF4B-4DE3-A47F-7735DB51C071}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{800B4133-DF4B-4DE3-A47F-7735DB51C071}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{800B4133-DF4B-4DE3-A47F-7735DB51C071}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{4C26289D-C683-4198-8CA2-904F44FA2833}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{4C26289D-C683-4198-8CA2-904F44FA2833}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{4C26289D-C683-4198-8CA2-904F44FA2833}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{4C26289D-C683-4198-8CA2-904F44FA2833}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{50B5809D-E6AF-4098-95A8-3D19E97952BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{50B5809D-E6AF-4098-95A8-3D19E97952BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{50B5809D-E6AF-4098-95A8-3D19E97952BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{50B5809D-E6AF-4098-95A8-3D19E97952BE}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{4CDE950C-ECDA-4B93-B24E-968BFA83D92D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{4CDE950C-ECDA-4B93-B24E-968BFA83D92D}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{4CDE950C-ECDA-4B93-B24E-968BFA83D92D}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{4CDE950C-ECDA-4B93-B24E-968BFA83D92D}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{EF5503C2-224B-45C5-8F8F-0EE5C99C305C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{EF5503C2-224B-45C5-8F8F-0EE5C99C305C}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{EF5503C2-224B-45C5-8F8F-0EE5C99C305C}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{EF5503C2-224B-45C5-8F8F-0EE5C99C305C}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{73987148-A515-4523-BC4D-8B41DF2F3FD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{73987148-A515-4523-BC4D-8B41DF2F3FD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{73987148-A515-4523-BC4D-8B41DF2F3FD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{73987148-A515-4523-BC4D-8B41DF2F3FD8}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{F14222DE-D0CE-4C76-B4B7-3312B3855B65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{F14222DE-D0CE-4C76-B4B7-3312B3855B65}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{F14222DE-D0CE-4C76-B4B7-3312B3855B65}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{F14222DE-D0CE-4C76-B4B7-3312B3855B65}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{BAE4A983-1C9E-4ADA-AB0A-C401EBBA6A0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{BAE4A983-1C9E-4ADA-AB0A-C401EBBA6A0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{BAE4A983-1C9E-4ADA-AB0A-C401EBBA6A0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{BAE4A983-1C9E-4ADA-AB0A-C401EBBA6A0C}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{E597528B-95CA-4ACB-A44B-2C0737084581}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{E597528B-95CA-4ACB-A44B-2C0737084581}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{E597528B-95CA-4ACB-A44B-2C0737084581}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{E597528B-95CA-4ACB-A44B-2C0737084581}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{C6520F60-774E-41B1-8B17-7EF0B825BF6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{C6520F60-774E-41B1-8B17-7EF0B825BF6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{C6520F60-774E-41B1-8B17-7EF0B825BF6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{C6520F60-774E-41B1-8B17-7EF0B825BF6A}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{9D4ED240-112A-467D-BCD7-2989DD172B83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{9D4ED240-112A-467D-BCD7-2989DD172B83}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{9D4ED240-112A-467D-BCD7-2989DD172B83}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{9D4ED240-112A-467D-BCD7-2989DD172B83}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{451651E0-F7E2-42C3-B8C8-474D89B220B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{451651E0-F7E2-42C3-B8C8-474D89B220B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{451651E0-F7E2-42C3-B8C8-474D89B220B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{451651E0-F7E2-42C3-B8C8-474D89B220B6}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
	EndGlobalSection
 | 
			
		||||
	GlobalSection(SolutionProperties) = preSolution
 | 
			
		||||
		HideSolutionNode = FALSE
 | 
			
		||||
	EndGlobalSection
 | 
			
		||||
	GlobalSection(NestedProjects) = preSolution
 | 
			
		||||
		{C6520F60-774E-41B1-8B17-7EF0B825BF6A} = {D6F579A8-2BDD-4E47-BF39-FB8650E5039E}
 | 
			
		||||
		{9D4ED240-112A-467D-BCD7-2989DD172B83} = {D6F579A8-2BDD-4E47-BF39-FB8650E5039E}
 | 
			
		||||
		{451651E0-F7E2-42C3-B8C8-474D89B220B6} = {FC409A4C-5FC3-4597-85BC-21DBB018450D}
 | 
			
		||||
	EndGlobalSection
 | 
			
		||||
	GlobalSection(ExtensibilityGlobals) = postSolution
 | 
			
		||||
		SolutionGuid = {C63B5A75-C99A-45D7-A691-26E568A51740}
 | 
			
		||||
	EndGlobalSection
 | 
			
		||||
EndGlobal
 | 
			
		||||
							
								
								
									
										661
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										661
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,661 @@
 | 
			
		||||
                    GNU AFFERO GENERAL PUBLIC LICENSE
 | 
			
		||||
                       Version 3, 19 November 2007
 | 
			
		||||
 | 
			
		||||
 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
 | 
			
		||||
 Everyone is permitted to copy and distribute verbatim copies
 | 
			
		||||
 of this license document, but changing it is not allowed.
 | 
			
		||||
 | 
			
		||||
                            Preamble
 | 
			
		||||
 | 
			
		||||
  The GNU Affero General Public License is a free, copyleft license for
 | 
			
		||||
software and other kinds of works, specifically designed to ensure
 | 
			
		||||
cooperation with the community in the case of network server software.
 | 
			
		||||
 | 
			
		||||
  The licenses for most software and other practical works are designed
 | 
			
		||||
to take away your freedom to share and change the works.  By contrast,
 | 
			
		||||
our General Public Licenses are intended to guarantee your freedom to
 | 
			
		||||
share and change all versions of a program--to make sure it remains free
 | 
			
		||||
software for all its users.
 | 
			
		||||
 | 
			
		||||
  When we speak of free software, we are referring to freedom, not
 | 
			
		||||
price.  Our General Public Licenses are designed to make sure that you
 | 
			
		||||
have the freedom to distribute copies of free software (and charge for
 | 
			
		||||
them if you wish), that you receive source code or can get it if you
 | 
			
		||||
want it, that you can change the software or use pieces of it in new
 | 
			
		||||
free programs, and that you know you can do these things.
 | 
			
		||||
 | 
			
		||||
  Developers that use our General Public Licenses protect your rights
 | 
			
		||||
with two steps: (1) assert copyright on the software, and (2) offer
 | 
			
		||||
you this License which gives you legal permission to copy, distribute
 | 
			
		||||
and/or modify the software.
 | 
			
		||||
 | 
			
		||||
  A secondary benefit of defending all users' freedom is that
 | 
			
		||||
improvements made in alternate versions of the program, if they
 | 
			
		||||
receive widespread use, become available for other developers to
 | 
			
		||||
incorporate.  Many developers of free software are heartened and
 | 
			
		||||
encouraged by the resulting cooperation.  However, in the case of
 | 
			
		||||
software used on network servers, this result may fail to come about.
 | 
			
		||||
The GNU General Public License permits making a modified version and
 | 
			
		||||
letting the public access it on a server without ever releasing its
 | 
			
		||||
source code to the public.
 | 
			
		||||
 | 
			
		||||
  The GNU Affero General Public License is designed specifically to
 | 
			
		||||
ensure that, in such cases, the modified source code becomes available
 | 
			
		||||
to the community.  It requires the operator of a network server to
 | 
			
		||||
provide the source code of the modified version running there to the
 | 
			
		||||
users of that server.  Therefore, public use of a modified version, on
 | 
			
		||||
a publicly accessible server, gives the public access to the source
 | 
			
		||||
code of the modified version.
 | 
			
		||||
 | 
			
		||||
  An older license, called the Affero General Public License and
 | 
			
		||||
published by Affero, was designed to accomplish similar goals.  This is
 | 
			
		||||
a different license, not a version of the Affero GPL, but Affero has
 | 
			
		||||
released a new version of the Affero GPL which permits relicensing under
 | 
			
		||||
this license.
 | 
			
		||||
 | 
			
		||||
  The precise terms and conditions for copying, distribution and
 | 
			
		||||
modification follow.
 | 
			
		||||
 | 
			
		||||
                       TERMS AND CONDITIONS
 | 
			
		||||
 | 
			
		||||
  0. Definitions.
 | 
			
		||||
 | 
			
		||||
  "This License" refers to version 3 of the GNU Affero General Public License.
 | 
			
		||||
 | 
			
		||||
  "Copyright" also means copyright-like laws that apply to other kinds of
 | 
			
		||||
works, such as semiconductor masks.
 | 
			
		||||
 | 
			
		||||
  "The Program" refers to any copyrightable work licensed under this
 | 
			
		||||
License.  Each licensee is addressed as "you".  "Licensees" and
 | 
			
		||||
"recipients" may be individuals or organizations.
 | 
			
		||||
 | 
			
		||||
  To "modify" a work means to copy from or adapt all or part of the work
 | 
			
		||||
in a fashion requiring copyright permission, other than the making of an
 | 
			
		||||
exact copy.  The resulting work is called a "modified version" of the
 | 
			
		||||
earlier work or a work "based on" the earlier work.
 | 
			
		||||
 | 
			
		||||
  A "covered work" means either the unmodified Program or a work based
 | 
			
		||||
on the Program.
 | 
			
		||||
 | 
			
		||||
  To "propagate" a work means to do anything with it that, without
 | 
			
		||||
permission, would make you directly or secondarily liable for
 | 
			
		||||
infringement under applicable copyright law, except executing it on a
 | 
			
		||||
computer or modifying a private copy.  Propagation includes copying,
 | 
			
		||||
distribution (with or without modification), making available to the
 | 
			
		||||
public, and in some countries other activities as well.
 | 
			
		||||
 | 
			
		||||
  To "convey" a work means any kind of propagation that enables other
 | 
			
		||||
parties to make or receive copies.  Mere interaction with a user through
 | 
			
		||||
a computer network, with no transfer of a copy, is not conveying.
 | 
			
		||||
 | 
			
		||||
  An interactive user interface displays "Appropriate Legal Notices"
 | 
			
		||||
to the extent that it includes a convenient and prominently visible
 | 
			
		||||
feature that (1) displays an appropriate copyright notice, and (2)
 | 
			
		||||
tells the user that there is no warranty for the work (except to the
 | 
			
		||||
extent that warranties are provided), that licensees may convey the
 | 
			
		||||
work under this License, and how to view a copy of this License.  If
 | 
			
		||||
the interface presents a list of user commands or options, such as a
 | 
			
		||||
menu, a prominent item in the list meets this criterion.
 | 
			
		||||
 | 
			
		||||
  1. Source Code.
 | 
			
		||||
 | 
			
		||||
  The "source code" for a work means the preferred form of the work
 | 
			
		||||
for making modifications to it.  "Object code" means any non-source
 | 
			
		||||
form of a work.
 | 
			
		||||
 | 
			
		||||
  A "Standard Interface" means an interface that either is an official
 | 
			
		||||
standard defined by a recognized standards body, or, in the case of
 | 
			
		||||
interfaces specified for a particular programming language, one that
 | 
			
		||||
is widely used among developers working in that language.
 | 
			
		||||
 | 
			
		||||
  The "System Libraries" of an executable work include anything, other
 | 
			
		||||
than the work as a whole, that (a) is included in the normal form of
 | 
			
		||||
packaging a Major Component, but which is not part of that Major
 | 
			
		||||
Component, and (b) serves only to enable use of the work with that
 | 
			
		||||
Major Component, or to implement a Standard Interface for which an
 | 
			
		||||
implementation is available to the public in source code form.  A
 | 
			
		||||
"Major Component", in this context, means a major essential component
 | 
			
		||||
(kernel, window system, and so on) of the specific operating system
 | 
			
		||||
(if any) on which the executable work runs, or a compiler used to
 | 
			
		||||
produce the work, or an object code interpreter used to run it.
 | 
			
		||||
 | 
			
		||||
  The "Corresponding Source" for a work in object code form means all
 | 
			
		||||
the source code needed to generate, install, and (for an executable
 | 
			
		||||
work) run the object code and to modify the work, including scripts to
 | 
			
		||||
control those activities.  However, it does not include the work's
 | 
			
		||||
System Libraries, or general-purpose tools or generally available free
 | 
			
		||||
programs which are used unmodified in performing those activities but
 | 
			
		||||
which are not part of the work.  For example, Corresponding Source
 | 
			
		||||
includes interface definition files associated with source files for
 | 
			
		||||
the work, and the source code for shared libraries and dynamically
 | 
			
		||||
linked subprograms that the work is specifically designed to require,
 | 
			
		||||
such as by intimate data communication or control flow between those
 | 
			
		||||
subprograms and other parts of the work.
 | 
			
		||||
 | 
			
		||||
  The Corresponding Source need not include anything that users
 | 
			
		||||
can regenerate automatically from other parts of the Corresponding
 | 
			
		||||
Source.
 | 
			
		||||
 | 
			
		||||
  The Corresponding Source for a work in source code form is that
 | 
			
		||||
same work.
 | 
			
		||||
 | 
			
		||||
  2. Basic Permissions.
 | 
			
		||||
 | 
			
		||||
  All rights granted under this License are granted for the term of
 | 
			
		||||
copyright on the Program, and are irrevocable provided the stated
 | 
			
		||||
conditions are met.  This License explicitly affirms your unlimited
 | 
			
		||||
permission to run the unmodified Program.  The output from running a
 | 
			
		||||
covered work is covered by this License only if the output, given its
 | 
			
		||||
content, constitutes a covered work.  This License acknowledges your
 | 
			
		||||
rights of fair use or other equivalent, as provided by copyright law.
 | 
			
		||||
 | 
			
		||||
  You may make, run and propagate covered works that you do not
 | 
			
		||||
convey, without conditions so long as your license otherwise remains
 | 
			
		||||
in force.  You may convey covered works to others for the sole purpose
 | 
			
		||||
of having them make modifications exclusively for you, or provide you
 | 
			
		||||
with facilities for running those works, provided that you comply with
 | 
			
		||||
the terms of this License in conveying all material for which you do
 | 
			
		||||
not control copyright.  Those thus making or running the covered works
 | 
			
		||||
for you must do so exclusively on your behalf, under your direction
 | 
			
		||||
and control, on terms that prohibit them from making any copies of
 | 
			
		||||
your copyrighted material outside their relationship with you.
 | 
			
		||||
 | 
			
		||||
  Conveying under any other circumstances is permitted solely under
 | 
			
		||||
the conditions stated below.  Sublicensing is not allowed; section 10
 | 
			
		||||
makes it unnecessary.
 | 
			
		||||
 | 
			
		||||
  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
 | 
			
		||||
 | 
			
		||||
  No covered work shall be deemed part of an effective technological
 | 
			
		||||
measure under any applicable law fulfilling obligations under article
 | 
			
		||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
 | 
			
		||||
similar laws prohibiting or restricting circumvention of such
 | 
			
		||||
measures.
 | 
			
		||||
 | 
			
		||||
  When you convey a covered work, you waive any legal power to forbid
 | 
			
		||||
circumvention of technological measures to the extent such circumvention
 | 
			
		||||
is effected by exercising rights under this License with respect to
 | 
			
		||||
the covered work, and you disclaim any intention to limit operation or
 | 
			
		||||
modification of the work as a means of enforcing, against the work's
 | 
			
		||||
users, your or third parties' legal rights to forbid circumvention of
 | 
			
		||||
technological measures.
 | 
			
		||||
 | 
			
		||||
  4. Conveying Verbatim Copies.
 | 
			
		||||
 | 
			
		||||
  You may convey verbatim copies of the Program's source code as you
 | 
			
		||||
receive it, in any medium, provided that you conspicuously and
 | 
			
		||||
appropriately publish on each copy an appropriate copyright notice;
 | 
			
		||||
keep intact all notices stating that this License and any
 | 
			
		||||
non-permissive terms added in accord with section 7 apply to the code;
 | 
			
		||||
keep intact all notices of the absence of any warranty; and give all
 | 
			
		||||
recipients a copy of this License along with the Program.
 | 
			
		||||
 | 
			
		||||
  You may charge any price or no price for each copy that you convey,
 | 
			
		||||
and you may offer support or warranty protection for a fee.
 | 
			
		||||
 | 
			
		||||
  5. Conveying Modified Source Versions.
 | 
			
		||||
 | 
			
		||||
  You may convey a work based on the Program, or the modifications to
 | 
			
		||||
produce it from the Program, in the form of source code under the
 | 
			
		||||
terms of section 4, provided that you also meet all of these conditions:
 | 
			
		||||
 | 
			
		||||
    a) The work must carry prominent notices stating that you modified
 | 
			
		||||
    it, and giving a relevant date.
 | 
			
		||||
 | 
			
		||||
    b) The work must carry prominent notices stating that it is
 | 
			
		||||
    released under this License and any conditions added under section
 | 
			
		||||
    7.  This requirement modifies the requirement in section 4 to
 | 
			
		||||
    "keep intact all notices".
 | 
			
		||||
 | 
			
		||||
    c) You must license the entire work, as a whole, under this
 | 
			
		||||
    License to anyone who comes into possession of a copy.  This
 | 
			
		||||
    License will therefore apply, along with any applicable section 7
 | 
			
		||||
    additional terms, to the whole of the work, and all its parts,
 | 
			
		||||
    regardless of how they are packaged.  This License gives no
 | 
			
		||||
    permission to license the work in any other way, but it does not
 | 
			
		||||
    invalidate such permission if you have separately received it.
 | 
			
		||||
 | 
			
		||||
    d) If the work has interactive user interfaces, each must display
 | 
			
		||||
    Appropriate Legal Notices; however, if the Program has interactive
 | 
			
		||||
    interfaces that do not display Appropriate Legal Notices, your
 | 
			
		||||
    work need not make them do so.
 | 
			
		||||
 | 
			
		||||
  A compilation of a covered work with other separate and independent
 | 
			
		||||
works, which are not by their nature extensions of the covered work,
 | 
			
		||||
and which are not combined with it such as to form a larger program,
 | 
			
		||||
in or on a volume of a storage or distribution medium, is called an
 | 
			
		||||
"aggregate" if the compilation and its resulting copyright are not
 | 
			
		||||
used to limit the access or legal rights of the compilation's users
 | 
			
		||||
beyond what the individual works permit.  Inclusion of a covered work
 | 
			
		||||
in an aggregate does not cause this License to apply to the other
 | 
			
		||||
parts of the aggregate.
 | 
			
		||||
 | 
			
		||||
  6. Conveying Non-Source Forms.
 | 
			
		||||
 | 
			
		||||
  You may convey a covered work in object code form under the terms
 | 
			
		||||
of sections 4 and 5, provided that you also convey the
 | 
			
		||||
machine-readable Corresponding Source under the terms of this License,
 | 
			
		||||
in one of these ways:
 | 
			
		||||
 | 
			
		||||
    a) Convey the object code in, or embodied in, a physical product
 | 
			
		||||
    (including a physical distribution medium), accompanied by the
 | 
			
		||||
    Corresponding Source fixed on a durable physical medium
 | 
			
		||||
    customarily used for software interchange.
 | 
			
		||||
 | 
			
		||||
    b) Convey the object code in, or embodied in, a physical product
 | 
			
		||||
    (including a physical distribution medium), accompanied by a
 | 
			
		||||
    written offer, valid for at least three years and valid for as
 | 
			
		||||
    long as you offer spare parts or customer support for that product
 | 
			
		||||
    model, to give anyone who possesses the object code either (1) a
 | 
			
		||||
    copy of the Corresponding Source for all the software in the
 | 
			
		||||
    product that is covered by this License, on a durable physical
 | 
			
		||||
    medium customarily used for software interchange, for a price no
 | 
			
		||||
    more than your reasonable cost of physically performing this
 | 
			
		||||
    conveying of source, or (2) access to copy the
 | 
			
		||||
    Corresponding Source from a network server at no charge.
 | 
			
		||||
 | 
			
		||||
    c) Convey individual copies of the object code with a copy of the
 | 
			
		||||
    written offer to provide the Corresponding Source.  This
 | 
			
		||||
    alternative is allowed only occasionally and noncommercially, and
 | 
			
		||||
    only if you received the object code with such an offer, in accord
 | 
			
		||||
    with subsection 6b.
 | 
			
		||||
 | 
			
		||||
    d) Convey the object code by offering access from a designated
 | 
			
		||||
    place (gratis or for a charge), and offer equivalent access to the
 | 
			
		||||
    Corresponding Source in the same way through the same place at no
 | 
			
		||||
    further charge.  You need not require recipients to copy the
 | 
			
		||||
    Corresponding Source along with the object code.  If the place to
 | 
			
		||||
    copy the object code is a network server, the Corresponding Source
 | 
			
		||||
    may be on a different server (operated by you or a third party)
 | 
			
		||||
    that supports equivalent copying facilities, provided you maintain
 | 
			
		||||
    clear directions next to the object code saying where to find the
 | 
			
		||||
    Corresponding Source.  Regardless of what server hosts the
 | 
			
		||||
    Corresponding Source, you remain obligated to ensure that it is
 | 
			
		||||
    available for as long as needed to satisfy these requirements.
 | 
			
		||||
 | 
			
		||||
    e) Convey the object code using peer-to-peer transmission, provided
 | 
			
		||||
    you inform other peers where the object code and Corresponding
 | 
			
		||||
    Source of the work are being offered to the general public at no
 | 
			
		||||
    charge under subsection 6d.
 | 
			
		||||
 | 
			
		||||
  A separable portion of the object code, whose source code is excluded
 | 
			
		||||
from the Corresponding Source as a System Library, need not be
 | 
			
		||||
included in conveying the object code work.
 | 
			
		||||
 | 
			
		||||
  A "User Product" is either (1) a "consumer product", which means any
 | 
			
		||||
tangible personal property which is normally used for personal, family,
 | 
			
		||||
or household purposes, or (2) anything designed or sold for incorporation
 | 
			
		||||
into a dwelling.  In determining whether a product is a consumer product,
 | 
			
		||||
doubtful cases shall be resolved in favor of coverage.  For a particular
 | 
			
		||||
product received by a particular user, "normally used" refers to a
 | 
			
		||||
typical or common use of that class of product, regardless of the status
 | 
			
		||||
of the particular user or of the way in which the particular user
 | 
			
		||||
actually uses, or expects or is expected to use, the product.  A product
 | 
			
		||||
is a consumer product regardless of whether the product has substantial
 | 
			
		||||
commercial, industrial or non-consumer uses, unless such uses represent
 | 
			
		||||
the only significant mode of use of the product.
 | 
			
		||||
 | 
			
		||||
  "Installation Information" for a User Product means any methods,
 | 
			
		||||
procedures, authorization keys, or other information required to install
 | 
			
		||||
and execute modified versions of a covered work in that User Product from
 | 
			
		||||
a modified version of its Corresponding Source.  The information must
 | 
			
		||||
suffice to ensure that the continued functioning of the modified object
 | 
			
		||||
code is in no case prevented or interfered with solely because
 | 
			
		||||
modification has been made.
 | 
			
		||||
 | 
			
		||||
  If you convey an object code work under this section in, or with, or
 | 
			
		||||
specifically for use in, a User Product, and the conveying occurs as
 | 
			
		||||
part of a transaction in which the right of possession and use of the
 | 
			
		||||
User Product is transferred to the recipient in perpetuity or for a
 | 
			
		||||
fixed term (regardless of how the transaction is characterized), the
 | 
			
		||||
Corresponding Source conveyed under this section must be accompanied
 | 
			
		||||
by the Installation Information.  But this requirement does not apply
 | 
			
		||||
if neither you nor any third party retains the ability to install
 | 
			
		||||
modified object code on the User Product (for example, the work has
 | 
			
		||||
been installed in ROM).
 | 
			
		||||
 | 
			
		||||
  The requirement to provide Installation Information does not include a
 | 
			
		||||
requirement to continue to provide support service, warranty, or updates
 | 
			
		||||
for a work that has been modified or installed by the recipient, or for
 | 
			
		||||
the User Product in which it has been modified or installed.  Access to a
 | 
			
		||||
network may be denied when the modification itself materially and
 | 
			
		||||
adversely affects the operation of the network or violates the rules and
 | 
			
		||||
protocols for communication across the network.
 | 
			
		||||
 | 
			
		||||
  Corresponding Source conveyed, and Installation Information provided,
 | 
			
		||||
in accord with this section must be in a format that is publicly
 | 
			
		||||
documented (and with an implementation available to the public in
 | 
			
		||||
source code form), and must require no special password or key for
 | 
			
		||||
unpacking, reading or copying.
 | 
			
		||||
 | 
			
		||||
  7. Additional Terms.
 | 
			
		||||
 | 
			
		||||
  "Additional permissions" are terms that supplement the terms of this
 | 
			
		||||
License by making exceptions from one or more of its conditions.
 | 
			
		||||
Additional permissions that are applicable to the entire Program shall
 | 
			
		||||
be treated as though they were included in this License, to the extent
 | 
			
		||||
that they are valid under applicable law.  If additional permissions
 | 
			
		||||
apply only to part of the Program, that part may be used separately
 | 
			
		||||
under those permissions, but the entire Program remains governed by
 | 
			
		||||
this License without regard to the additional permissions.
 | 
			
		||||
 | 
			
		||||
  When you convey a copy of a covered work, you may at your option
 | 
			
		||||
remove any additional permissions from that copy, or from any part of
 | 
			
		||||
it.  (Additional permissions may be written to require their own
 | 
			
		||||
removal in certain cases when you modify the work.)  You may place
 | 
			
		||||
additional permissions on material, added by you to a covered work,
 | 
			
		||||
for which you have or can give appropriate copyright permission.
 | 
			
		||||
 | 
			
		||||
  Notwithstanding any other provision of this License, for material you
 | 
			
		||||
add to a covered work, you may (if authorized by the copyright holders of
 | 
			
		||||
that material) supplement the terms of this License with terms:
 | 
			
		||||
 | 
			
		||||
    a) Disclaiming warranty or limiting liability differently from the
 | 
			
		||||
    terms of sections 15 and 16 of this License; or
 | 
			
		||||
 | 
			
		||||
    b) Requiring preservation of specified reasonable legal notices or
 | 
			
		||||
    author attributions in that material or in the Appropriate Legal
 | 
			
		||||
    Notices displayed by works containing it; or
 | 
			
		||||
 | 
			
		||||
    c) Prohibiting misrepresentation of the origin of that material, or
 | 
			
		||||
    requiring that modified versions of such material be marked in
 | 
			
		||||
    reasonable ways as different from the original version; or
 | 
			
		||||
 | 
			
		||||
    d) Limiting the use for publicity purposes of names of licensors or
 | 
			
		||||
    authors of the material; or
 | 
			
		||||
 | 
			
		||||
    e) Declining to grant rights under trademark law for use of some
 | 
			
		||||
    trade names, trademarks, or service marks; or
 | 
			
		||||
 | 
			
		||||
    f) Requiring indemnification of licensors and authors of that
 | 
			
		||||
    material by anyone who conveys the material (or modified versions of
 | 
			
		||||
    it) with contractual assumptions of liability to the recipient, for
 | 
			
		||||
    any liability that these contractual assumptions directly impose on
 | 
			
		||||
    those licensors and authors.
 | 
			
		||||
 | 
			
		||||
  All other non-permissive additional terms are considered "further
 | 
			
		||||
restrictions" within the meaning of section 10.  If the Program as you
 | 
			
		||||
received it, or any part of it, contains a notice stating that it is
 | 
			
		||||
governed by this License along with a term that is a further
 | 
			
		||||
restriction, you may remove that term.  If a license document contains
 | 
			
		||||
a further restriction but permits relicensing or conveying under this
 | 
			
		||||
License, you may add to a covered work material governed by the terms
 | 
			
		||||
of that license document, provided that the further restriction does
 | 
			
		||||
not survive such relicensing or conveying.
 | 
			
		||||
 | 
			
		||||
  If you add terms to a covered work in accord with this section, you
 | 
			
		||||
must place, in the relevant source files, a statement of the
 | 
			
		||||
additional terms that apply to those files, or a notice indicating
 | 
			
		||||
where to find the applicable terms.
 | 
			
		||||
 | 
			
		||||
  Additional terms, permissive or non-permissive, may be stated in the
 | 
			
		||||
form of a separately written license, or stated as exceptions;
 | 
			
		||||
the above requirements apply either way.
 | 
			
		||||
 | 
			
		||||
  8. Termination.
 | 
			
		||||
 | 
			
		||||
  You may not propagate or modify a covered work except as expressly
 | 
			
		||||
provided under this License.  Any attempt otherwise to propagate or
 | 
			
		||||
modify it is void, and will automatically terminate your rights under
 | 
			
		||||
this License (including any patent licenses granted under the third
 | 
			
		||||
paragraph of section 11).
 | 
			
		||||
 | 
			
		||||
  However, if you cease all violation of this License, then your
 | 
			
		||||
license from a particular copyright holder is reinstated (a)
 | 
			
		||||
provisionally, unless and until the copyright holder explicitly and
 | 
			
		||||
finally terminates your license, and (b) permanently, if the copyright
 | 
			
		||||
holder fails to notify you of the violation by some reasonable means
 | 
			
		||||
prior to 60 days after the cessation.
 | 
			
		||||
 | 
			
		||||
  Moreover, your license from a particular copyright holder is
 | 
			
		||||
reinstated permanently if the copyright holder notifies you of the
 | 
			
		||||
violation by some reasonable means, this is the first time you have
 | 
			
		||||
received notice of violation of this License (for any work) from that
 | 
			
		||||
copyright holder, and you cure the violation prior to 30 days after
 | 
			
		||||
your receipt of the notice.
 | 
			
		||||
 | 
			
		||||
  Termination of your rights under this section does not terminate the
 | 
			
		||||
licenses of parties who have received copies or rights from you under
 | 
			
		||||
this License.  If your rights have been terminated and not permanently
 | 
			
		||||
reinstated, you do not qualify to receive new licenses for the same
 | 
			
		||||
material under section 10.
 | 
			
		||||
 | 
			
		||||
  9. Acceptance Not Required for Having Copies.
 | 
			
		||||
 | 
			
		||||
  You are not required to accept this License in order to receive or
 | 
			
		||||
run a copy of the Program.  Ancillary propagation of a covered work
 | 
			
		||||
occurring solely as a consequence of using peer-to-peer transmission
 | 
			
		||||
to receive a copy likewise does not require acceptance.  However,
 | 
			
		||||
nothing other than this License grants you permission to propagate or
 | 
			
		||||
modify any covered work.  These actions infringe copyright if you do
 | 
			
		||||
not accept this License.  Therefore, by modifying or propagating a
 | 
			
		||||
covered work, you indicate your acceptance of this License to do so.
 | 
			
		||||
 | 
			
		||||
  10. Automatic Licensing of Downstream Recipients.
 | 
			
		||||
 | 
			
		||||
  Each time you convey a covered work, the recipient automatically
 | 
			
		||||
receives a license from the original licensors, to run, modify and
 | 
			
		||||
propagate that work, subject to this License.  You are not responsible
 | 
			
		||||
for enforcing compliance by third parties with this License.
 | 
			
		||||
 | 
			
		||||
  An "entity transaction" is a transaction transferring control of an
 | 
			
		||||
organization, or substantially all assets of one, or subdividing an
 | 
			
		||||
organization, or merging organizations.  If propagation of a covered
 | 
			
		||||
work results from an entity transaction, each party to that
 | 
			
		||||
transaction who receives a copy of the work also receives whatever
 | 
			
		||||
licenses to the work the party's predecessor in interest had or could
 | 
			
		||||
give under the previous paragraph, plus a right to possession of the
 | 
			
		||||
Corresponding Source of the work from the predecessor in interest, if
 | 
			
		||||
the predecessor has it or can get it with reasonable efforts.
 | 
			
		||||
 | 
			
		||||
  You may not impose any further restrictions on the exercise of the
 | 
			
		||||
rights granted or affirmed under this License.  For example, you may
 | 
			
		||||
not impose a license fee, royalty, or other charge for exercise of
 | 
			
		||||
rights granted under this License, and you may not initiate litigation
 | 
			
		||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
 | 
			
		||||
any patent claim is infringed by making, using, selling, offering for
 | 
			
		||||
sale, or importing the Program or any portion of it.
 | 
			
		||||
 | 
			
		||||
  11. Patents.
 | 
			
		||||
 | 
			
		||||
  A "contributor" is a copyright holder who authorizes use under this
 | 
			
		||||
License of the Program or a work on which the Program is based.  The
 | 
			
		||||
work thus licensed is called the contributor's "contributor version".
 | 
			
		||||
 | 
			
		||||
  A contributor's "essential patent claims" are all patent claims
 | 
			
		||||
owned or controlled by the contributor, whether already acquired or
 | 
			
		||||
hereafter acquired, that would be infringed by some manner, permitted
 | 
			
		||||
by this License, of making, using, or selling its contributor version,
 | 
			
		||||
but do not include claims that would be infringed only as a
 | 
			
		||||
consequence of further modification of the contributor version.  For
 | 
			
		||||
purposes of this definition, "control" includes the right to grant
 | 
			
		||||
patent sublicenses in a manner consistent with the requirements of
 | 
			
		||||
this License.
 | 
			
		||||
 | 
			
		||||
  Each contributor grants you a non-exclusive, worldwide, royalty-free
 | 
			
		||||
patent license under the contributor's essential patent claims, to
 | 
			
		||||
make, use, sell, offer for sale, import and otherwise run, modify and
 | 
			
		||||
propagate the contents of its contributor version.
 | 
			
		||||
 | 
			
		||||
  In the following three paragraphs, a "patent license" is any express
 | 
			
		||||
agreement or commitment, however denominated, not to enforce a patent
 | 
			
		||||
(such as an express permission to practice a patent or covenant not to
 | 
			
		||||
sue for patent infringement).  To "grant" such a patent license to a
 | 
			
		||||
party means to make such an agreement or commitment not to enforce a
 | 
			
		||||
patent against the party.
 | 
			
		||||
 | 
			
		||||
  If you convey a covered work, knowingly relying on a patent license,
 | 
			
		||||
and the Corresponding Source of the work is not available for anyone
 | 
			
		||||
to copy, free of charge and under the terms of this License, through a
 | 
			
		||||
publicly available network server or other readily accessible means,
 | 
			
		||||
then you must either (1) cause the Corresponding Source to be so
 | 
			
		||||
available, or (2) arrange to deprive yourself of the benefit of the
 | 
			
		||||
patent license for this particular work, or (3) arrange, in a manner
 | 
			
		||||
consistent with the requirements of this License, to extend the patent
 | 
			
		||||
license to downstream recipients.  "Knowingly relying" means you have
 | 
			
		||||
actual knowledge that, but for the patent license, your conveying the
 | 
			
		||||
covered work in a country, or your recipient's use of the covered work
 | 
			
		||||
in a country, would infringe one or more identifiable patents in that
 | 
			
		||||
country that you have reason to believe are valid.
 | 
			
		||||
 | 
			
		||||
  If, pursuant to or in connection with a single transaction or
 | 
			
		||||
arrangement, you convey, or propagate by procuring conveyance of, a
 | 
			
		||||
covered work, and grant a patent license to some of the parties
 | 
			
		||||
receiving the covered work authorizing them to use, propagate, modify
 | 
			
		||||
or convey a specific copy of the covered work, then the patent license
 | 
			
		||||
you grant is automatically extended to all recipients of the covered
 | 
			
		||||
work and works based on it.
 | 
			
		||||
 | 
			
		||||
  A patent license is "discriminatory" if it does not include within
 | 
			
		||||
the scope of its coverage, prohibits the exercise of, or is
 | 
			
		||||
conditioned on the non-exercise of one or more of the rights that are
 | 
			
		||||
specifically granted under this License.  You may not convey a covered
 | 
			
		||||
work if you are a party to an arrangement with a third party that is
 | 
			
		||||
in the business of distributing software, under which you make payment
 | 
			
		||||
to the third party based on the extent of your activity of conveying
 | 
			
		||||
the work, and under which the third party grants, to any of the
 | 
			
		||||
parties who would receive the covered work from you, a discriminatory
 | 
			
		||||
patent license (a) in connection with copies of the covered work
 | 
			
		||||
conveyed by you (or copies made from those copies), or (b) primarily
 | 
			
		||||
for and in connection with specific products or compilations that
 | 
			
		||||
contain the covered work, unless you entered into that arrangement,
 | 
			
		||||
or that patent license was granted, prior to 28 March 2007.
 | 
			
		||||
 | 
			
		||||
  Nothing in this License shall be construed as excluding or limiting
 | 
			
		||||
any implied license or other defenses to infringement that may
 | 
			
		||||
otherwise be available to you under applicable patent law.
 | 
			
		||||
 | 
			
		||||
  12. No Surrender of Others' Freedom.
 | 
			
		||||
 | 
			
		||||
  If conditions are imposed on you (whether by court order, agreement or
 | 
			
		||||
otherwise) that contradict the conditions of this License, they do not
 | 
			
		||||
excuse you from the conditions of this License.  If you cannot convey a
 | 
			
		||||
covered work so as to satisfy simultaneously your obligations under this
 | 
			
		||||
License and any other pertinent obligations, then as a consequence you may
 | 
			
		||||
not convey it at all.  For example, if you agree to terms that obligate you
 | 
			
		||||
to collect a royalty for further conveying from those to whom you convey
 | 
			
		||||
the Program, the only way you could satisfy both those terms and this
 | 
			
		||||
License would be to refrain entirely from conveying the Program.
 | 
			
		||||
 | 
			
		||||
  13. Remote Network Interaction; Use with the GNU General Public License.
 | 
			
		||||
 | 
			
		||||
  Notwithstanding any other provision of this License, if you modify the
 | 
			
		||||
Program, your modified version must prominently offer all users
 | 
			
		||||
interacting with it remotely through a computer network (if your version
 | 
			
		||||
supports such interaction) an opportunity to receive the Corresponding
 | 
			
		||||
Source of your version by providing access to the Corresponding Source
 | 
			
		||||
from a network server at no charge, through some standard or customary
 | 
			
		||||
means of facilitating copying of software.  This Corresponding Source
 | 
			
		||||
shall include the Corresponding Source for any work covered by version 3
 | 
			
		||||
of the GNU General Public License that is incorporated pursuant to the
 | 
			
		||||
following paragraph.
 | 
			
		||||
 | 
			
		||||
  Notwithstanding any other provision of this License, you have
 | 
			
		||||
permission to link or combine any covered work with a work licensed
 | 
			
		||||
under version 3 of the GNU General Public License into a single
 | 
			
		||||
combined work, and to convey the resulting work.  The terms of this
 | 
			
		||||
License will continue to apply to the part which is the covered work,
 | 
			
		||||
but the work with which it is combined will remain governed by version
 | 
			
		||||
3 of the GNU General Public License.
 | 
			
		||||
 | 
			
		||||
  14. Revised Versions of this License.
 | 
			
		||||
 | 
			
		||||
  The Free Software Foundation may publish revised and/or new versions of
 | 
			
		||||
the GNU Affero General Public License from time to time.  Such new versions
 | 
			
		||||
will be similar in spirit to the present version, but may differ in detail to
 | 
			
		||||
address new problems or concerns.
 | 
			
		||||
 | 
			
		||||
  Each version is given a distinguishing version number.  If the
 | 
			
		||||
Program specifies that a certain numbered version of the GNU Affero General
 | 
			
		||||
Public License "or any later version" applies to it, you have the
 | 
			
		||||
option of following the terms and conditions either of that numbered
 | 
			
		||||
version or of any later version published by the Free Software
 | 
			
		||||
Foundation.  If the Program does not specify a version number of the
 | 
			
		||||
GNU Affero General Public License, you may choose any version ever published
 | 
			
		||||
by the Free Software Foundation.
 | 
			
		||||
 | 
			
		||||
  If the Program specifies that a proxy can decide which future
 | 
			
		||||
versions of the GNU Affero General Public License can be used, that proxy's
 | 
			
		||||
public statement of acceptance of a version permanently authorizes you
 | 
			
		||||
to choose that version for the Program.
 | 
			
		||||
 | 
			
		||||
  Later license versions may give you additional or different
 | 
			
		||||
permissions.  However, no additional obligations are imposed on any
 | 
			
		||||
author or copyright holder as a result of your choosing to follow a
 | 
			
		||||
later version.
 | 
			
		||||
 | 
			
		||||
  15. Disclaimer of Warranty.
 | 
			
		||||
 | 
			
		||||
  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
 | 
			
		||||
APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
 | 
			
		||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
 | 
			
		||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
 | 
			
		||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 | 
			
		||||
PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
 | 
			
		||||
IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
 | 
			
		||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
 | 
			
		||||
 | 
			
		||||
  16. Limitation of Liability.
 | 
			
		||||
 | 
			
		||||
  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
 | 
			
		||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
 | 
			
		||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
 | 
			
		||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
 | 
			
		||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
 | 
			
		||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
 | 
			
		||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
 | 
			
		||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
 | 
			
		||||
SUCH DAMAGES.
 | 
			
		||||
 | 
			
		||||
  17. Interpretation of Sections 15 and 16.
 | 
			
		||||
 | 
			
		||||
  If the disclaimer of warranty and limitation of liability provided
 | 
			
		||||
above cannot be given local legal effect according to their terms,
 | 
			
		||||
reviewing courts shall apply local law that most closely approximates
 | 
			
		||||
an absolute waiver of all civil liability in connection with the
 | 
			
		||||
Program, unless a warranty or assumption of liability accompanies a
 | 
			
		||||
copy of the Program in return for a fee.
 | 
			
		||||
 | 
			
		||||
                     END OF TERMS AND CONDITIONS
 | 
			
		||||
 | 
			
		||||
            How to Apply These Terms to Your New Programs
 | 
			
		||||
 | 
			
		||||
  If you develop a new program, and you want it to be of the greatest
 | 
			
		||||
possible use to the public, the best way to achieve this is to make it
 | 
			
		||||
free software which everyone can redistribute and change under these terms.
 | 
			
		||||
 | 
			
		||||
  To do so, attach the following notices to the program.  It is safest
 | 
			
		||||
to attach them to the start of each source file to most effectively
 | 
			
		||||
state the exclusion of warranty; and each file should have at least
 | 
			
		||||
the "copyright" line and a pointer to where the full notice is found.
 | 
			
		||||
 | 
			
		||||
    <one line to give the program's name and a brief idea of what it does.>
 | 
			
		||||
    Copyright (C) <year>  <name of author>
 | 
			
		||||
 | 
			
		||||
    This program is free software: you can redistribute it and/or modify
 | 
			
		||||
    it under the terms of the GNU Affero General Public License as published
 | 
			
		||||
    by the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
    (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
    This program is distributed in the hope that it will be useful,
 | 
			
		||||
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
    GNU Affero General Public License for more details.
 | 
			
		||||
 | 
			
		||||
    You should have received a copy of the GNU Affero General Public License
 | 
			
		||||
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
Also add information on how to contact you by electronic and paper mail.
 | 
			
		||||
 | 
			
		||||
  If your software can interact with users remotely through a computer
 | 
			
		||||
network, you should also make sure that it provides a way for users to
 | 
			
		||||
get its source.  For example, if your program is a web application, its
 | 
			
		||||
interface could display a "Source" link that leads users to an archive
 | 
			
		||||
of the code.  There are many ways you could offer source, and different
 | 
			
		||||
solutions will be better for different programs; see section 13 for the
 | 
			
		||||
specific requirements.
 | 
			
		||||
 | 
			
		||||
  You should also get your employer (if you work as a programmer) or school,
 | 
			
		||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
 | 
			
		||||
For more information on this, and how to apply and follow the GNU AGPL, see
 | 
			
		||||
<https://www.gnu.org/licenses/>.
 | 
			
		||||
							
								
								
									
										0
									
								
								build/.gitkeep
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								build/.gitkeep
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										20
									
								
								build/buildProjects.bat
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								build/buildProjects.bat
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,20 @@
 | 
			
		||||
dotnet build ../src/Connected.Runtime/Connected.Runtime.csproj
 | 
			
		||||
dotnet build ../src/Connected.Configuration/Connected.Configuration.csproj
 | 
			
		||||
dotnet build ../src/Connected.Threading/Connected.Threading.csproj
 | 
			
		||||
dotnet build ../src/Connected.Interop/Connected.Interop.csproj
 | 
			
		||||
dotnet build ../src/Connected.Hosting/Connected.Hosting.csproj
 | 
			
		||||
dotnet build ../src/Connected.Globalization/Connected.Globalization.csproj
 | 
			
		||||
dotnet build ../src/Connected.Collections/Connected.Collections.csproj
 | 
			
		||||
dotnet build ../src/Connected.Middleware/Connected.Middleware.csproj
 | 
			
		||||
dotnet build ../src/Connected.Security/Connected.Security.csproj
 | 
			
		||||
dotnet build ../src/Connected.Validation/Connected.Validation.csproj
 | 
			
		||||
dotnet build ../src/Connected.Net/Connected.Net.csproj
 | 
			
		||||
dotnet build ../src/Connected.Notifications/Connected.Notifications.csproj
 | 
			
		||||
dotnet build ../src/Connected.Caching/Connected.Caching.csproj
 | 
			
		||||
dotnet build ../src/Connected.Entities/Connected.Entities.csproj
 | 
			
		||||
dotnet build ../src/Connected.Expressions/Connected.Expressions.csproj
 | 
			
		||||
dotnet build ../src/Connected.Data/Connected.Data.csproj
 | 
			
		||||
dotnet build ../src/Connected.Services/Connected.Services.csproj
 | 
			
		||||
dotnet build ../src/Connected.Rest/Connected.Rest.csproj
 | 
			
		||||
dotnet build ../src/Connected.Instance/Connected.Instance.csproj
 | 
			
		||||
dotnet build ../src/Connected.Framework/Connected.Framework.csproj
 | 
			
		||||
							
								
								
									
										22
									
								
								build/init.bat
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								build/init.bat
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,22 @@
 | 
			
		||||
@echo off
 | 
			
		||||
 | 
			
		||||
SET root=%cd%
 | 
			
		||||
 | 
			
		||||
echo "Syncing submodules"
 | 
			
		||||
git submodule sync
 | 
			
		||||
git submodule update --init --remote
 | 
			
		||||
echo "Submodules up to date"
 | 
			
		||||
 | 
			
		||||
FOR /F "delims=" %%a IN ('DIR "../dependencies" /A:d /B') DO (
 | 
			
		||||
    echo Handling %%a
 | 
			
		||||
    cd "../dependencies/%%a/build"
 | 
			
		||||
    echo %cd%
 | 
			
		||||
    IF EXIST init.bat  (
 | 
			
		||||
        echo "found init.bat"
 | 
			
		||||
	call init
 | 
			
		||||
    )    
 | 
			
		||||
    cd %root%
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
cd ../
 | 
			
		||||
dotnet build
 | 
			
		||||
							
								
								
									
										1
									
								
								dependencies/Connected
									
									
									
									
										vendored
									
									
										Submodule
									
								
							
							
								
								
								
								
								
								
									
									
								
							
						
						
									
										1
									
								
								dependencies/Connected
									
									
									
									
										vendored
									
									
										Submodule
									
								
							@ -0,0 +1 @@
 | 
			
		||||
Subproject commit 9eb9949950a4b99f31e8800eb41e1b97ec00f8be
 | 
			
		||||
							
								
								
									
										15
									
								
								nuget.config
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								nuget.config
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<configuration>
 | 
			
		||||
    <config>
 | 
			
		||||
        <add key="repositoryPath" value="%PACKAGEHOME%/External" />
 | 
			
		||||
    </config>
 | 
			
		||||
 | 
			
		||||
    <packageRestore>
 | 
			
		||||
        <add key="enabled" value="True" />
 | 
			
		||||
        <add key="automatic" value="True" />
 | 
			
		||||
    </packageRestore>
 | 
			
		||||
    <packageSources>
 | 
			
		||||
        <add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
 | 
			
		||||
    </packageSources>
 | 
			
		||||
    <disabledPackageSources />
 | 
			
		||||
</configuration>
 | 
			
		||||
							
								
								
									
										6
									
								
								src/Connected.Caching/Annotations/CacheKeyAttribute.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/Connected.Caching/Annotations/CacheKeyAttribute.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,6 @@
 | 
			
		||||
namespace Connected.Caching.Annotations;
 | 
			
		||||
 | 
			
		||||
[AttributeUsage(AttributeTargets.Property)]
 | 
			
		||||
public sealed class CacheKeyAttribute : Attribute
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										432
									
								
								src/Connected.Caching/Cache.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										432
									
								
								src/Connected.Caching/Cache.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,432 @@
 | 
			
		||||
using System.Collections.Concurrent;
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
using Connected.Interop;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
internal abstract class Cache : ICache
 | 
			
		||||
{
 | 
			
		||||
	private bool _disposedValue;
 | 
			
		||||
	private readonly ConcurrentDictionary<string, Entries> _items;
 | 
			
		||||
	private readonly Task _scavenger;
 | 
			
		||||
	private readonly CancellationTokenSource _cancel = new();
 | 
			
		||||
 | 
			
		||||
	public event CacheInvalidateHandler? Invalidating;
 | 
			
		||||
	public event CacheInvalidateHandler? Invalidated;
 | 
			
		||||
 | 
			
		||||
	public Cache()
 | 
			
		||||
	{
 | 
			
		||||
		_scavenger = new Task(OnScaveging, _cancel.Token, TaskCreationOptions.LongRunning);
 | 
			
		||||
		_items = new ConcurrentDictionary<string, Entries>();
 | 
			
		||||
 | 
			
		||||
		_scavenger.Start();
 | 
			
		||||
	}
 | 
			
		||||
	private ConcurrentDictionary<string, Entries> Items => _items;
 | 
			
		||||
	private CancellationTokenSource Cancel => _cancel;
 | 
			
		||||
 | 
			
		||||
	private void OnScaveging()
 | 
			
		||||
	{
 | 
			
		||||
		var token = Cancel.Token;
 | 
			
		||||
 | 
			
		||||
		while (!token.IsCancellationRequested)
 | 
			
		||||
		{
 | 
			
		||||
			try
 | 
			
		||||
			{
 | 
			
		||||
				foreach (var i in Items)
 | 
			
		||||
					i.Value.Scave();
 | 
			
		||||
 | 
			
		||||
				var empties = Items.Where(f => f.Value.Count == 0).Select(f => f.Key);
 | 
			
		||||
 | 
			
		||||
				foreach (var i in empties)
 | 
			
		||||
					Items.TryRemove(i, out _);
 | 
			
		||||
 | 
			
		||||
				token.WaitHandle.WaitOne(TimeSpan.FromMinutes(1));
 | 
			
		||||
			}
 | 
			
		||||
			catch { }
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	public virtual bool IsEmpty(string key)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value))
 | 
			
		||||
			return value.Any();
 | 
			
		||||
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public virtual bool Exists(string key)
 | 
			
		||||
	{
 | 
			
		||||
		return Items.ContainsKey(key);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void CreateKey(string key)
 | 
			
		||||
	{
 | 
			
		||||
		if (Exists(key))
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		Items.TryAdd(key, new Entries());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public IEnumerator<T>? GetEnumerator<T>(string key)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value))
 | 
			
		||||
			return value.GetEnumerator<T>();
 | 
			
		||||
 | 
			
		||||
		return new List<T>().GetEnumerator();
 | 
			
		||||
	}
 | 
			
		||||
	public virtual ImmutableList<T>? All<T>(string key)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value))
 | 
			
		||||
			return value.All<T>();
 | 
			
		||||
 | 
			
		||||
		return default;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public int Count(string key)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value))
 | 
			
		||||
			return value.Count;
 | 
			
		||||
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public virtual T? Get<T>(string key, Func<T, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value) && value.Get(predicate) is IEntry entry)
 | 
			
		||||
			return GetValue<T>(entry);
 | 
			
		||||
 | 
			
		||||
		return default;
 | 
			
		||||
	}
 | 
			
		||||
	public virtual async Task<T?> Get<T>(string key, Func<T, bool> predicate, Func<EntryOptions, Task<T>> retrieve)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value) && value.Get(predicate) is IEntry entry)
 | 
			
		||||
			return GetValue<T>(entry);
 | 
			
		||||
 | 
			
		||||
		if (retrieve is null)
 | 
			
		||||
			return default;
 | 
			
		||||
 | 
			
		||||
		var options = new EntryOptions();
 | 
			
		||||
		T instance = await retrieve(options);
 | 
			
		||||
 | 
			
		||||
		if (EqualityComparer<T>.Default.Equals(instance, default))
 | 
			
		||||
		{
 | 
			
		||||
			if (!options.AllowNull)
 | 
			
		||||
				return default;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (string.IsNullOrWhiteSpace(options.Key))
 | 
			
		||||
			throw new SysException(this, SR.ErrCacheKeyNull);
 | 
			
		||||
 | 
			
		||||
		Set(key, options.Key, instance, options.Duration, options.SlidingExpiration);
 | 
			
		||||
 | 
			
		||||
		return instance;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public virtual async Task<T?> Get<T>(string key, object id, Func<EntryOptions, Task<T>>? retrieve)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value) && value.Get(id is null ? null : id.ToString()) is IEntry entry)
 | 
			
		||||
			return GetValue<T>(entry);
 | 
			
		||||
 | 
			
		||||
		if (retrieve is null)
 | 
			
		||||
			return default;
 | 
			
		||||
 | 
			
		||||
		var options = new EntryOptions
 | 
			
		||||
		{
 | 
			
		||||
			Key = id is null ? null : id.ToString()
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
		T instance = await retrieve(options);
 | 
			
		||||
 | 
			
		||||
		if (EqualityComparer<T>.Default.Equals(instance, default))
 | 
			
		||||
		{
 | 
			
		||||
			if (!options.AllowNull)
 | 
			
		||||
				return default;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		Set(key, options.Key, instance, options.Duration, options.SlidingExpiration);
 | 
			
		||||
 | 
			
		||||
		return instance;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	internal void ClearCore(string key)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value))
 | 
			
		||||
			value.Clear();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public virtual async Task Clear(string key)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value))
 | 
			
		||||
			value.Clear();
 | 
			
		||||
 | 
			
		||||
		await Task.CompletedTask;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public virtual T? Get<T>(string key, object id)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value) && value.Get(id is null ? null : id.ToString()) is IEntry entry)
 | 
			
		||||
			return GetValue<T>(entry);
 | 
			
		||||
 | 
			
		||||
		return default;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public IEntry? Get(string key, object id)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value))
 | 
			
		||||
			return value.Get(id is null ? null : id.ToString());
 | 
			
		||||
 | 
			
		||||
		return default;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public virtual T? Get<T>(string key, Func<dynamic, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value) && value.Get(predicate) is IEntry entry)
 | 
			
		||||
			return GetValue<T>(entry);
 | 
			
		||||
 | 
			
		||||
		return default;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public virtual T? First<T>(string key)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value) && value.First() is IEntry entry)
 | 
			
		||||
			return GetValue<T>(entry);
 | 
			
		||||
 | 
			
		||||
		return default;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public virtual ImmutableList<T>? Where<T>(string key, Func<T, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value))
 | 
			
		||||
			return value.Where(predicate);
 | 
			
		||||
 | 
			
		||||
		return default;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void CopyTo(string key, object id, IEntry instance)
 | 
			
		||||
	{
 | 
			
		||||
		if (!Items.TryGetValue(key, out Entries? value))
 | 
			
		||||
		{
 | 
			
		||||
			value = new Entries();
 | 
			
		||||
 | 
			
		||||
			if (!Items.TryAdd(key, value))
 | 
			
		||||
				return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		value.Set(id is null ? null : id.ToString(), instance.Instance, instance.Duration, instance.SlidingExpiration);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public virtual T? Set<T>(string key, object id, T? instance)
 | 
			
		||||
	{
 | 
			
		||||
		return Set(key, id, instance, TimeSpan.Zero);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public virtual T? Set<T>(string key, object id, T? instance, TimeSpan duration)
 | 
			
		||||
	{
 | 
			
		||||
		return Set(key, id, instance, duration, false);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public virtual T? Set<T>(string key, object id, T? instance, TimeSpan duration, bool slidingExpiration)
 | 
			
		||||
	{
 | 
			
		||||
		if (!Items.TryGetValue(key, out Entries? value))
 | 
			
		||||
		{
 | 
			
		||||
			value = new Entries();
 | 
			
		||||
 | 
			
		||||
			if (!Items.TryAdd(key, value))
 | 
			
		||||
				return default;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		value.Set(id is null ? null : id.ToString(), instance, duration, slidingExpiration);
 | 
			
		||||
 | 
			
		||||
		return instance;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	internal void RemoveCore(string key, object id)
 | 
			
		||||
	{
 | 
			
		||||
		if (id is null)
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value))
 | 
			
		||||
			value.Remove(id.ToString());
 | 
			
		||||
	}
 | 
			
		||||
	public virtual async Task Remove(string key, object id)
 | 
			
		||||
	{
 | 
			
		||||
		await Remove(key, id, true);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private async Task Remove(string key, object id, bool removing)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value))
 | 
			
		||||
			value.Remove(id is null ? null : id.ToString());
 | 
			
		||||
 | 
			
		||||
		if (removing)
 | 
			
		||||
			await OnRemove(key, id);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected virtual async Task OnRemove(string key, object id)
 | 
			
		||||
	{
 | 
			
		||||
		await Task.CompletedTask;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public async Task Invalidate(string key, object id)
 | 
			
		||||
	{
 | 
			
		||||
		await InvalidateCore(key, id, false);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	internal async Task InvalidateCore(string key, object id, bool fromNotification)
 | 
			
		||||
	{
 | 
			
		||||
		/*
 | 
			
		||||
			* we store existing instance but it is not
 | 
			
		||||
			* removed from the cache yet. This is because other
 | 
			
		||||
			* threads can access this instance while we are
 | 
			
		||||
			* retrieving a new version from the source
 | 
			
		||||
			*/
 | 
			
		||||
		var existing = Get<object>(key, id);
 | 
			
		||||
		var args = new CacheEventArgs(id is null ? null : id.ToString(), key);
 | 
			
		||||
		/*
 | 
			
		||||
			* this two events invalidate that cache reference.
 | 
			
		||||
			* note that if no new version exists the existing one
 | 
			
		||||
			* is still available to other threads.
 | 
			
		||||
			*/
 | 
			
		||||
		try
 | 
			
		||||
		{
 | 
			
		||||
			Invalidating?.Invoke(args);
 | 
			
		||||
		}
 | 
			
		||||
		catch { }
 | 
			
		||||
 | 
			
		||||
		try
 | 
			
		||||
		{
 | 
			
		||||
			if (!fromNotification)
 | 
			
		||||
				await OnInvalidating(args);
 | 
			
		||||
 | 
			
		||||
			await OnInvalidate(args);
 | 
			
		||||
		}
 | 
			
		||||
		catch { }
 | 
			
		||||
		/*
 | 
			
		||||
			* now find out if a new version has been set for the
 | 
			
		||||
			* specified key
 | 
			
		||||
			*/
 | 
			
		||||
		var newInstance = Get<object>(key, id);
 | 
			
		||||
		/*
 | 
			
		||||
			* if no existing reference exists there is no need for
 | 
			
		||||
			* removing anything
 | 
			
		||||
			*/
 | 
			
		||||
		if (existing is not null)
 | 
			
		||||
		{
 | 
			
		||||
			/*
 | 
			
		||||
				 * we have an existing instance. we are dealing with two possible scenarios:
 | 
			
		||||
				 * - newInstance is null because entity has been deleted
 | 
			
		||||
				 * - newInstance is actually the same instance as the existing which means a new
 | 
			
		||||
				 * version does not exist. In both cases we must remove existing reference because
 | 
			
		||||
				 * at this point it is not valid anymore.
 | 
			
		||||
				 * note that the third case exists: reference has been replaced. in that case there
 | 
			
		||||
				 * is nothing to do because Invalidating events has already replaced reference with a
 | 
			
		||||
				 * new version.
 | 
			
		||||
				 */
 | 
			
		||||
			if (newInstance is null)
 | 
			
		||||
				await Remove(key, id, false);
 | 
			
		||||
			else if (existing.Equals(newInstance) && args.Behavior == InvalidateBehavior.RemoveSameInstance)
 | 
			
		||||
				await Remove(key, id, false);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		try
 | 
			
		||||
		{
 | 
			
		||||
			Invalidated?.Invoke(args);
 | 
			
		||||
		}
 | 
			
		||||
		catch { }
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected internal virtual async Task OnInvalidating(CacheEventArgs e)
 | 
			
		||||
	{
 | 
			
		||||
		await Task.CompletedTask;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected virtual async Task OnInvalidate(CacheEventArgs e)
 | 
			
		||||
	{
 | 
			
		||||
		await Task.CompletedTask;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void Clear()
 | 
			
		||||
	{
 | 
			
		||||
		foreach (var i in Items)
 | 
			
		||||
			i.Value.Clear();
 | 
			
		||||
 | 
			
		||||
		Items.Clear();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public virtual async Task<ImmutableList<string>?> Remove<T>(string key, Func<T, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value))
 | 
			
		||||
		{
 | 
			
		||||
			var result = value.Remove(predicate);
 | 
			
		||||
 | 
			
		||||
			if (result is not null && result.Any())
 | 
			
		||||
				await OnRemove(key, result);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return default;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected virtual async Task OnRemove(string key, ImmutableList<string> ids)
 | 
			
		||||
	{
 | 
			
		||||
		await Task.CompletedTask;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public ImmutableList<string>? Keys(string key)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value))
 | 
			
		||||
			return value.Keys;
 | 
			
		||||
 | 
			
		||||
		return default;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public ImmutableList<string> Keys()
 | 
			
		||||
	{
 | 
			
		||||
		return Items.Keys.ToImmutableList();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public bool Any(string key)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryGetValue(key, out Entries? value))
 | 
			
		||||
			return value.Any();
 | 
			
		||||
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private static T? GetValue<T>(IEntry entry)
 | 
			
		||||
	{
 | 
			
		||||
		if (entry is null || entry.Instance is null)
 | 
			
		||||
			return default;
 | 
			
		||||
 | 
			
		||||
		if (TypeConversion.TryConvert(entry.Instance, out T? result))
 | 
			
		||||
			return result;
 | 
			
		||||
 | 
			
		||||
		return default;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected virtual void OnDisposing(bool disposing)
 | 
			
		||||
	{
 | 
			
		||||
		if (!_disposedValue)
 | 
			
		||||
		{
 | 
			
		||||
			if (disposing)
 | 
			
		||||
			{
 | 
			
		||||
				Cancel.Cancel();
 | 
			
		||||
				Clear();
 | 
			
		||||
 | 
			
		||||
				if (_scavenger is not null)
 | 
			
		||||
				{
 | 
			
		||||
					_cancel.Cancel();
 | 
			
		||||
 | 
			
		||||
					if (_scavenger.IsCompleted)
 | 
			
		||||
						_scavenger.Dispose();
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			_disposedValue = true;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Dispose()
 | 
			
		||||
	{
 | 
			
		||||
		OnDisposing(true);
 | 
			
		||||
		GC.SuppressFinalize(this);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										128
									
								
								src/Connected.Caching/CacheClient.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										128
									
								
								src/Connected.Caching/CacheClient.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,128 @@
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
public abstract class CacheClient<TEntry, TKey> : ICacheClient<TEntry, TKey> where TEntry : class
 | 
			
		||||
{
 | 
			
		||||
	protected CacheClient(ICachingService cachingService, string key)
 | 
			
		||||
	{
 | 
			
		||||
		if (cachingService is null)
 | 
			
		||||
			throw new ArgumentException(nameof(cachingService));
 | 
			
		||||
 | 
			
		||||
		CachingService = cachingService;
 | 
			
		||||
		Key = key;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public string Key { get; }
 | 
			
		||||
	protected bool IsDisposed { get; set; }
 | 
			
		||||
	protected async Task Remove(TKey id)
 | 
			
		||||
	{
 | 
			
		||||
		if (id is null)
 | 
			
		||||
			throw new ArgumentNullException(nameof(id));
 | 
			
		||||
 | 
			
		||||
		await CachingService.Remove(Key, id);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected async Task Remove(Func<TEntry, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		await CachingService.Remove(Key, predicate);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected async Task Refresh(TKey id)
 | 
			
		||||
	{
 | 
			
		||||
		if (id is null)
 | 
			
		||||
			throw new ArgumentNullException(nameof(id));
 | 
			
		||||
 | 
			
		||||
		await CachingService.Invalidate(Key, id);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected ICachingService CachingService { get; }
 | 
			
		||||
 | 
			
		||||
	public int Count => CachingService.Count(Key);
 | 
			
		||||
	protected virtual ICollection<string>? Keys => CachingService.Keys(Key);
 | 
			
		||||
 | 
			
		||||
	protected virtual Task<ImmutableList<TEntry>?> All()
 | 
			
		||||
	{
 | 
			
		||||
		return Task.FromResult(CachingService.All<TEntry>(Key));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected virtual async Task<TEntry?> Get(TKey id, Func<EntryOptions, Task<TEntry>> retrieve)
 | 
			
		||||
	{
 | 
			
		||||
		if (id is null)
 | 
			
		||||
			throw new ArgumentNullException(nameof(id));
 | 
			
		||||
 | 
			
		||||
		return await CachingService.Get(Key, id, retrieve);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected virtual Task<TEntry?> Get(TKey id)
 | 
			
		||||
	{
 | 
			
		||||
		if (id is null)
 | 
			
		||||
			throw new ArgumentNullException(nameof(id));
 | 
			
		||||
 | 
			
		||||
		return Task.FromResult(CachingService.Get<TEntry>(Key, id));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected virtual Task<TEntry?> First()
 | 
			
		||||
	{
 | 
			
		||||
		return Task.FromResult(CachingService.First<TEntry>(Key));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected virtual async Task<TEntry?> Get(Func<TEntry, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		return await CachingService.Get(Key, predicate, null);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected virtual Task<ImmutableList<TEntry>?> Where(Func<TEntry, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		return Task.FromResult(CachingService.Where(Key, predicate));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected virtual void Set(TKey id, TEntry instance)
 | 
			
		||||
	{
 | 
			
		||||
		if (id is null)
 | 
			
		||||
			throw new ArgumentNullException(nameof(id));
 | 
			
		||||
 | 
			
		||||
		CachingService.Set(Key, id, instance);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected virtual void Set(TKey id, TEntry instance, TimeSpan duration)
 | 
			
		||||
	{
 | 
			
		||||
		if (id is null)
 | 
			
		||||
			throw new ArgumentNullException(nameof(id));
 | 
			
		||||
 | 
			
		||||
		CachingService.Set(Key, id, instance, duration);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void Dispose(bool disposing)
 | 
			
		||||
	{
 | 
			
		||||
		if (!IsDisposed)
 | 
			
		||||
		{
 | 
			
		||||
			if (disposing)
 | 
			
		||||
				OnDisposing();
 | 
			
		||||
 | 
			
		||||
			IsDisposed = true;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected virtual void OnDisposing()
 | 
			
		||||
	{
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Dispose()
 | 
			
		||||
	{
 | 
			
		||||
		Dispose(true);
 | 
			
		||||
		GC.SuppressFinalize(this);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public virtual IEnumerator<TEntry> GetEnumerator()
 | 
			
		||||
	{
 | 
			
		||||
		return CachingService?.GetEnumerator<TEntry>(Key);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	IEnumerator IEnumerable.GetEnumerator()
 | 
			
		||||
	{
 | 
			
		||||
		return GetEnumerator();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										220
									
								
								src/Connected.Caching/CacheContext.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										220
									
								
								src/Connected.Caching/CacheContext.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,220 @@
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using Connected.Interop;
 | 
			
		||||
using Connected.ServiceModel.Transactions;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
internal class CacheContext : Cache, ICacheContext
 | 
			
		||||
{
 | 
			
		||||
	public CacheContext(ICachingService cachingService, ITransactionContext transactionContext)
 | 
			
		||||
	{
 | 
			
		||||
		CachingService = cachingService;
 | 
			
		||||
		TransactionContext = transactionContext;
 | 
			
		||||
 | 
			
		||||
		TransactionContext.StateChanged += OnTransactionContextStateChanged;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void OnTransactionContextStateChanged(object? sender, EventArgs e)
 | 
			
		||||
	{
 | 
			
		||||
		if (TransactionContext.State == MiddlewareTransactionState.Committing)
 | 
			
		||||
			Flush();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private ICachingService CachingService { get; }
 | 
			
		||||
	private ITransactionContext TransactionContext { get; }
 | 
			
		||||
 | 
			
		||||
	public override bool Exists(string key)
 | 
			
		||||
	{
 | 
			
		||||
		return base.Exists(key) || (CachingService is not null && CachingService.Exists(key));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override bool IsEmpty(string key)
 | 
			
		||||
	{
 | 
			
		||||
		return base.IsEmpty(key) || (CachingService is not null && CachingService.IsEmpty(key));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override ImmutableList<T>? All<T>(string key)
 | 
			
		||||
	{
 | 
			
		||||
		return Merge(base.All<T>(key), CachingService?.All<T>(key));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override async Task<T> Get<T>(string key, object id, Func<EntryOptions, Task<T>>? retrieve)
 | 
			
		||||
	{
 | 
			
		||||
		if (!TransactionContext.IsDirty)
 | 
			
		||||
		{
 | 
			
		||||
			if (retrieve is null)
 | 
			
		||||
				return default;
 | 
			
		||||
 | 
			
		||||
			return await CachingService.Get(key, id, retrieve);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return await base.Get(key, id, (f) =>
 | 
			
		||||
		{
 | 
			
		||||
			var shared = CachingService.Get<T>(key, id);
 | 
			
		||||
 | 
			
		||||
			if (shared is not null)
 | 
			
		||||
				return Task.FromResult(shared);
 | 
			
		||||
 | 
			
		||||
			if (retrieve is null)
 | 
			
		||||
				return default;
 | 
			
		||||
 | 
			
		||||
			return retrieve(f);
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override async Task<T> Get<T>(string key, Func<T, bool> predicate, Func<EntryOptions, Task<T>>? retrieve)
 | 
			
		||||
	{
 | 
			
		||||
		if (!TransactionContext.IsDirty)
 | 
			
		||||
		{
 | 
			
		||||
			if (retrieve is null)
 | 
			
		||||
				return default;
 | 
			
		||||
 | 
			
		||||
			return await CachingService.Get(key, predicate, retrieve);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return await base.Get(key, predicate, (f) =>
 | 
			
		||||
		{
 | 
			
		||||
			var shared = CachingService.Get(key, predicate);
 | 
			
		||||
 | 
			
		||||
			if (shared is not null)
 | 
			
		||||
				return Task.FromResult(shared);
 | 
			
		||||
 | 
			
		||||
			return retrieve(f);
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override T Get<T>(string key, object id)
 | 
			
		||||
	{
 | 
			
		||||
		var contextItem = base.Get<T>(key, id);
 | 
			
		||||
 | 
			
		||||
		if (contextItem is not null)
 | 
			
		||||
			return contextItem;
 | 
			
		||||
 | 
			
		||||
		return CachingService.Get<T>(key, id);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override T Get<T>(string key, Func<T, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		var contextItem = base.Get<T>(key, predicate);
 | 
			
		||||
 | 
			
		||||
		if (contextItem is not null)
 | 
			
		||||
			return contextItem;
 | 
			
		||||
 | 
			
		||||
		return CachingService.Get(key, predicate);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override async Task Clear(string key)
 | 
			
		||||
	{
 | 
			
		||||
		await base.Clear(key);
 | 
			
		||||
		await CachingService.Clear(key);
 | 
			
		||||
	}
 | 
			
		||||
	public override T First<T>(string key)
 | 
			
		||||
	{
 | 
			
		||||
		if (base.First<T>(key) is T result)
 | 
			
		||||
			return result;
 | 
			
		||||
 | 
			
		||||
		return CachingService.First<T>(key);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override ImmutableList<T> Where<T>(string key, Func<T, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		return Merge(base.Where(key, predicate), CachingService.Where(key, predicate));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override T Set<T>(string key, object id, T instance)
 | 
			
		||||
	{
 | 
			
		||||
		if (!TransactionContext.IsDirty)
 | 
			
		||||
			return CachingService.Set(key, id, instance);
 | 
			
		||||
 | 
			
		||||
		return base.Set(key, id, instance);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override T Set<T>(string key, object id, T instance, TimeSpan duration)
 | 
			
		||||
	{
 | 
			
		||||
		if (!TransactionContext.IsDirty)
 | 
			
		||||
			return CachingService.Set(key, id, instance, duration);
 | 
			
		||||
 | 
			
		||||
		return base.Set(key, id, instance, duration);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override T Set<T>(string key, object id, T instance, TimeSpan duration, bool slidingExpiration)
 | 
			
		||||
	{
 | 
			
		||||
		if (!TransactionContext.IsDirty)
 | 
			
		||||
			return CachingService.Set(key, id, instance, duration, slidingExpiration);
 | 
			
		||||
 | 
			
		||||
		return base.Set(key, id, instance, duration, slidingExpiration);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override async Task Remove(string key, object id)
 | 
			
		||||
	{
 | 
			
		||||
		await base.Remove(key, id);
 | 
			
		||||
		await CachingService.Remove(key, id);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override async Task<ImmutableList<string>?> Remove<T>(string key, Func<T, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		var local = await base.Remove(key, predicate);
 | 
			
		||||
		var shared = await CachingService.Remove(key, predicate);
 | 
			
		||||
 | 
			
		||||
		if (local is not null && shared is not null)
 | 
			
		||||
			return local.AddRange(shared);
 | 
			
		||||
 | 
			
		||||
		return local is not null ? local : shared;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Flush()
 | 
			
		||||
	{
 | 
			
		||||
		CachingService.Merge(this);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private static ImmutableList<T>? Merge<T>(ImmutableList<T>? contextItems, ImmutableList<T>? sharedItems)
 | 
			
		||||
	{
 | 
			
		||||
		if (contextItems is null)
 | 
			
		||||
			return sharedItems;
 | 
			
		||||
 | 
			
		||||
		var result = new List<T>(contextItems);
 | 
			
		||||
 | 
			
		||||
		foreach (var sharedItem in sharedItems)
 | 
			
		||||
		{
 | 
			
		||||
			if (sharedItem is null)
 | 
			
		||||
				continue;
 | 
			
		||||
 | 
			
		||||
			if (CachingExtensions.GetCacheKeyProperty(sharedItem) is not PropertyInfo cacheProperty)
 | 
			
		||||
			{
 | 
			
		||||
				//Q: should we compare every property and add only if not matched?
 | 
			
		||||
				contextItems.Add(sharedItem);
 | 
			
		||||
				continue;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if (FindExisting(cacheProperty.GetValue(sharedItems), contextItems) is null)
 | 
			
		||||
				result.Add(sharedItem);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return result.ToImmutableList();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private static T? FindExisting<T>(object value, ImmutableList<T> items)
 | 
			
		||||
	{
 | 
			
		||||
		if (items is null || items.IsEmpty)
 | 
			
		||||
			return default;
 | 
			
		||||
 | 
			
		||||
		if (CachingExtensions.GetCacheKeyProperty(items[0]) is not PropertyInfo cacheProperty)
 | 
			
		||||
			return default;
 | 
			
		||||
 | 
			
		||||
		foreach (var item in items)
 | 
			
		||||
		{
 | 
			
		||||
			var id = cacheProperty.GetValue(item);
 | 
			
		||||
 | 
			
		||||
			if (TypeComparer.Compare(id, value))
 | 
			
		||||
				return item;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return default;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected override async Task OnInvalidate(CacheEventArgs e)
 | 
			
		||||
	{
 | 
			
		||||
		await CachingService.Invalidate(e.Key, e.Id);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										27
									
								
								src/Connected.Caching/CacheEventArgs.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/Connected.Caching/CacheEventArgs.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,27 @@
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
public enum InvalidateBehavior : byte
 | 
			
		||||
{
 | 
			
		||||
	RemoveSameInstance = 1,
 | 
			
		||||
	KeepSameInstance = 2
 | 
			
		||||
}
 | 
			
		||||
public class CacheEventArgs : EventArgs
 | 
			
		||||
{
 | 
			
		||||
	public CacheEventArgs(string id, string key)
 | 
			
		||||
	{
 | 
			
		||||
		Key = key;
 | 
			
		||||
		Id = id;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public CacheEventArgs(string id, string key, InvalidateBehavior behavior)
 | 
			
		||||
	{
 | 
			
		||||
		Key = key;
 | 
			
		||||
		Id = id;
 | 
			
		||||
		Behavior = behavior;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public string Id { get; init; }
 | 
			
		||||
	public string Key { get; init; }
 | 
			
		||||
 | 
			
		||||
	public InvalidateBehavior Behavior { get; set; } = InvalidateBehavior.RemoveSameInstance;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										16
									
								
								src/Connected.Caching/CacheNotificationArgs.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/Connected.Caching/CacheNotificationArgs.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
public class CacheNotificationArgs
 | 
			
		||||
{
 | 
			
		||||
	public CacheNotificationArgs(string method)
 | 
			
		||||
	{
 | 
			
		||||
		if (string.IsNullOrWhiteSpace(method))
 | 
			
		||||
			throw new ArgumentException(null, nameof(method));
 | 
			
		||||
 | 
			
		||||
		Method = method;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public string? Key { get; init; }
 | 
			
		||||
	public List<string>? Ids { get; init; }
 | 
			
		||||
	public string Method { get; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										13
									
								
								src/Connected.Caching/CachingExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/Connected.Caching/CachingExtensions.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using Connected.Caching.Annotations;
 | 
			
		||||
using Connected.Interop;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
public static class CachingExtensions
 | 
			
		||||
{
 | 
			
		||||
	public static PropertyInfo? GetCacheKeyProperty(object instance)
 | 
			
		||||
	{
 | 
			
		||||
		return Properties.GetPropertyAttribute<CacheKeyAttribute>(instance);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										151
									
								
								src/Connected.Caching/CachingService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										151
									
								
								src/Connected.Caching/CachingService.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,151 @@
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
using Connected.Caching.Net;
 | 
			
		||||
using Connected.Net.Server;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
internal sealed class CachingService : MemoryCache, ICachingService, IDisposable, IAsyncDisposable
 | 
			
		||||
{
 | 
			
		||||
	public CachingService(IEndpointServer server, CacheServer state, CacheServerConnection backplaneClient)
 | 
			
		||||
	{
 | 
			
		||||
		if (server is null)
 | 
			
		||||
			throw new ArgumentException(null, nameof(server));
 | 
			
		||||
 | 
			
		||||
		if (state is null)
 | 
			
		||||
			throw new ArgumentException(null, nameof(state));
 | 
			
		||||
 | 
			
		||||
		BackplaneClient = backplaneClient;
 | 
			
		||||
 | 
			
		||||
		Server = server;
 | 
			
		||||
		BackplaneServer = state;
 | 
			
		||||
 | 
			
		||||
		server.Changed += OnServerChanged;
 | 
			
		||||
		server.Initialized += OnServerInitialized;
 | 
			
		||||
		BackplaneServer.Received += OnReceived;
 | 
			
		||||
		BackplaneClient.Received += OnReceived;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private CacheServerConnection BackplaneClient { get; set; }
 | 
			
		||||
	private CacheServer BackplaneServer { get; }
 | 
			
		||||
	private IEndpointServer Server { get; }
 | 
			
		||||
 | 
			
		||||
	private async void OnServerInitialized(object? sender, EventArgs e)
 | 
			
		||||
	{
 | 
			
		||||
		await Initialize();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public async Task Initialize()
 | 
			
		||||
	{
 | 
			
		||||
		await BackplaneClient.Disconnect();
 | 
			
		||||
 | 
			
		||||
		try
 | 
			
		||||
		{
 | 
			
		||||
			if (!await Server.IsServer())
 | 
			
		||||
			{
 | 
			
		||||
				await BackplaneClient.Initialize(Server.ServerUrl);
 | 
			
		||||
				await BackplaneClient.Connect();
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		catch
 | 
			
		||||
		{
 | 
			
		||||
			// Server probably not initalized yet
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private async void OnReceived(object? sender, CacheNotificationArgs e)
 | 
			
		||||
	{
 | 
			
		||||
		if (string.Equals(e.Method, nameof(Clear), StringComparison.Ordinal))
 | 
			
		||||
			ClearCore(e.Key);
 | 
			
		||||
		else if (string.Equals(e.Method, nameof(Remove), StringComparison.Ordinal))
 | 
			
		||||
		{
 | 
			
		||||
			if (e.Ids is not null && e.Ids.Any())
 | 
			
		||||
			{
 | 
			
		||||
				foreach (var id in e.Ids)
 | 
			
		||||
					RemoveCore(e.Key, id);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		else if (string.Equals(e.Method, nameof(Invalidate), StringComparison.Ordinal))
 | 
			
		||||
		{
 | 
			
		||||
			if (e.Ids is not null && e.Ids.Any())
 | 
			
		||||
			{
 | 
			
		||||
				foreach (var id in e.Ids)
 | 
			
		||||
					await InvalidateCore(e.Key, id, true);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private async void OnServerChanged(object? sender, ServerChangedArgs e)
 | 
			
		||||
	{
 | 
			
		||||
		await Initialize();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override async Task Clear(string key)
 | 
			
		||||
	{
 | 
			
		||||
		await base.Clear(key);
 | 
			
		||||
 | 
			
		||||
		var args = new CacheNotificationArgs(nameof(Clear)) { Key = key };
 | 
			
		||||
 | 
			
		||||
		if (await Server.IsServer())
 | 
			
		||||
			await BackplaneServer.Send(args);
 | 
			
		||||
		else
 | 
			
		||||
			await BackplaneClient.Notify(nameof(Clear), args);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
	protected internal override async Task OnInvalidating(CacheEventArgs e)
 | 
			
		||||
	{
 | 
			
		||||
		var args = new CacheNotificationArgs(nameof(Invalidate))
 | 
			
		||||
		{
 | 
			
		||||
			Ids = new List<string> { e.Id },
 | 
			
		||||
			Key = e.Key
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
		if (await Server.IsServer())
 | 
			
		||||
			await BackplaneServer.Send(args);
 | 
			
		||||
		else
 | 
			
		||||
			await BackplaneClient.Notify(nameof(Invalidate), args);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected override async Task OnRemove(string key, ImmutableList<string> ids)
 | 
			
		||||
	{
 | 
			
		||||
		await base.OnRemove(key, ids);
 | 
			
		||||
 | 
			
		||||
		var args = new CacheNotificationArgs(nameof(Remove))
 | 
			
		||||
		{
 | 
			
		||||
			Ids = ids.ToList(),
 | 
			
		||||
			Key = key
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
		if (await Server.IsServer())
 | 
			
		||||
			await BackplaneServer.Send(args);
 | 
			
		||||
		else
 | 
			
		||||
			await BackplaneClient.Notify(nameof(Remove), args);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected override async Task OnRemove(string key, object? id)
 | 
			
		||||
	{
 | 
			
		||||
		await base.OnRemove(key, id);
 | 
			
		||||
 | 
			
		||||
		var ids = new List<string>();
 | 
			
		||||
 | 
			
		||||
		if (id is not null)
 | 
			
		||||
			ids.Add(id.ToString());
 | 
			
		||||
 | 
			
		||||
		await OnRemove(key, ids.ToImmutableList());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public async ValueTask DisposeAsync()
 | 
			
		||||
	{
 | 
			
		||||
		Server.Changed -= OnServerChanged;
 | 
			
		||||
		Server.Initialized -= OnServerInitialized;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	protected override void OnDisposing(bool disposing)
 | 
			
		||||
	{
 | 
			
		||||
		Server.Changed -= OnServerChanged;
 | 
			
		||||
		Server.Initialized -= OnServerInitialized;
 | 
			
		||||
 | 
			
		||||
		base.OnDisposing(disposing);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										33
									
								
								src/Connected.Caching/CachingStartup.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/Connected.Caching/CachingStartup.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,33 @@
 | 
			
		||||
using Connected.Annotations;
 | 
			
		||||
using Connected.Caching.Net;
 | 
			
		||||
using Microsoft.AspNetCore.Builder;
 | 
			
		||||
using Microsoft.Extensions.Configuration;
 | 
			
		||||
using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
 | 
			
		||||
[assembly: MicroService(MicroServiceType.Sys)]
 | 
			
		||||
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
internal class CachingStartup : Startup
 | 
			
		||||
{
 | 
			
		||||
	public const string CachingHub = "/caching";
 | 
			
		||||
 | 
			
		||||
	protected override void OnConfigure(WebApplication app)
 | 
			
		||||
	{
 | 
			
		||||
		app.MapHub<CacheHub>(CachingHub);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected override void OnConfigureServices(IServiceCollection services)
 | 
			
		||||
	{
 | 
			
		||||
		services.AddSingleton(typeof(CacheServer));
 | 
			
		||||
		services.AddSingleton(typeof(CacheServerConnection));
 | 
			
		||||
		services.AddSingleton(typeof(ICachingService), typeof(CachingService));
 | 
			
		||||
		services.AddScoped(typeof(ICacheContext), typeof(CacheContext));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected override async Task OnInitialize(IConfiguration config)
 | 
			
		||||
	{
 | 
			
		||||
		if (Services is not null && Services.GetService<ICachingService>() is ICachingService service)
 | 
			
		||||
			await service.Initialize();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										56
									
								
								src/Connected.Caching/Connected.Caching.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								src/Connected.Caching/Connected.Caching.csproj
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,56 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
 | 
			
		||||
	<PropertyGroup>
 | 
			
		||||
		<TargetFramework>net7.0</TargetFramework>
 | 
			
		||||
		<ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
		<Nullable>enable</Nullable>
 | 
			
		||||
		<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
 | 
			
		||||
		<Title>$(AssemblyName)</Title>
 | 
			
		||||
		<Authors>Tom PIT</Authors>
 | 
			
		||||
		<Copyright>2022 Tom PIT</Copyright>
 | 
			
		||||
		<PackageProjectUrl>https://git.tompit.com/Connected/Info</PackageProjectUrl>
 | 
			
		||||
		<PackageReadmeFile>README.md</PackageReadmeFile>
 | 
			
		||||
		<PackageTags>connected;platform;</PackageTags>
 | 
			
		||||
		<IncludeSymbols>True</IncludeSymbols>
 | 
			
		||||
		<SymbolPackageFormat>snupkg</SymbolPackageFormat>
 | 
			
		||||
		<PackageLicenseFile>LICENSE</PackageLicenseFile>
 | 
			
		||||
		<PackageOutputPath>$(OutputPath)</PackageOutputPath>
 | 
			
		||||
	</PropertyGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
		<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.*-*" />
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
		<Compile Update="SR.Designer.cs">
 | 
			
		||||
			<DesignTime>True</DesignTime>
 | 
			
		||||
			<AutoGen>True</AutoGen>
 | 
			
		||||
			<DependentUpon>SR.resx</DependentUpon>
 | 
			
		||||
		</Compile>
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
		<EmbeddedResource Update="SR.resx">
 | 
			
		||||
			<Generator>ResXFileCodeGenerator</Generator>
 | 
			
		||||
			<LastGenOutput>SR.Designer.cs</LastGenOutput>
 | 
			
		||||
		</EmbeddedResource>
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
		<None Include="..\..\LICENSE">
 | 
			
		||||
			<Pack>True</Pack>
 | 
			
		||||
			<PackagePath>\</PackagePath>
 | 
			
		||||
		</None>
 | 
			
		||||
		<None Include="..\..\README.md">
 | 
			
		||||
			<Pack>True</Pack>
 | 
			
		||||
			<PackagePath>\</PackagePath>
 | 
			
		||||
		</None>
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
	  <ProjectReference Include="..\Connected.Interop\Connected.Interop.csproj" />
 | 
			
		||||
	  <ProjectReference Include="..\Connected.Net\Connected.Net.csproj" />
 | 
			
		||||
	  <ProjectReference Include="..\Connected.Runtime\Connected.Runtime.csproj" />
 | 
			
		||||
	  <ProjectReference Include="..\Connected.Threading\Connected.Threading.csproj" />
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
</Project>
 | 
			
		||||
							
								
								
									
										260
									
								
								src/Connected.Caching/Entries.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										260
									
								
								src/Connected.Caching/Entries.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,260 @@
 | 
			
		||||
using System.Collections.Concurrent;
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
using Connected.Interop;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
internal class Entries
 | 
			
		||||
{
 | 
			
		||||
	private readonly Lazy<ConcurrentDictionary<string, IEntry>> _items = new();
 | 
			
		||||
 | 
			
		||||
	private ConcurrentDictionary<string, IEntry> Items => _items.Value;
 | 
			
		||||
	public ImmutableList<string> Keys => Items.Keys.ToImmutableList();
 | 
			
		||||
	public int Count => Items.Count;
 | 
			
		||||
 | 
			
		||||
	public bool Any()
 | 
			
		||||
	{
 | 
			
		||||
		return Items.Any();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Scave()
 | 
			
		||||
	{
 | 
			
		||||
		var expired = new HashSet<string>();
 | 
			
		||||
 | 
			
		||||
		foreach (var i in Items)
 | 
			
		||||
		{
 | 
			
		||||
			var r = i.Value;
 | 
			
		||||
 | 
			
		||||
			if (r is null || r.Expired)
 | 
			
		||||
				expired.Add(i.Key);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		foreach (var i in expired)
 | 
			
		||||
			Remove(i);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public ImmutableList<T> All<T>()
 | 
			
		||||
	{
 | 
			
		||||
		var r = new List<T>();
 | 
			
		||||
		var expired = Items.Where(f => f.Value.Expired);
 | 
			
		||||
 | 
			
		||||
		foreach (var e in expired)
 | 
			
		||||
			Remove(e.Value.Id);
 | 
			
		||||
 | 
			
		||||
		var instances = Items.Select(f => f.Value.Instance);
 | 
			
		||||
 | 
			
		||||
		foreach (var i in instances)
 | 
			
		||||
		{
 | 
			
		||||
			if (TypeConversion.TryConvert(i, out T? result) && result is not null)
 | 
			
		||||
				r.Add(result);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return r.ToImmutableList();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Remove(string key)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.IsEmpty)
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		if (Items.TryRemove(key, out IEntry? v))
 | 
			
		||||
			v.Dispose();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Set(string key, object? instance, TimeSpan duration, bool slidingExpiration)
 | 
			
		||||
	{
 | 
			
		||||
		Items[key] = new Entry(key, instance, duration, slidingExpiration);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public IEnumerator<T> GetEnumerator<T>()
 | 
			
		||||
	{
 | 
			
		||||
		return new EntryEnumerator<T>(Items);
 | 
			
		||||
	}
 | 
			
		||||
	public IEntry? Get(string key)
 | 
			
		||||
	{
 | 
			
		||||
		return Find(key);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public IEntry? First()
 | 
			
		||||
	{
 | 
			
		||||
		if (!Any())
 | 
			
		||||
			return default;
 | 
			
		||||
 | 
			
		||||
		return Items.First().Value;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public IEntry? Get<T>(Func<T, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		return Find(predicate);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public IEntry? Get<T>(Func<dynamic, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		return Find<T>(predicate);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public ImmutableList<string>? Remove<T>(Func<T, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		if (Where(predicate) is not ImmutableList<string> ds || ds.IsEmpty)
 | 
			
		||||
			return default;
 | 
			
		||||
 | 
			
		||||
		var result = new HashSet<string>();
 | 
			
		||||
 | 
			
		||||
		foreach (var i in ds)
 | 
			
		||||
		{
 | 
			
		||||
			var key = Items.FirstOrDefault(f => InstanceEquals(f.Value?.Instance, i)).Key;
 | 
			
		||||
 | 
			
		||||
			RemoveInternal(key);
 | 
			
		||||
 | 
			
		||||
			result.Add(key);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return result.ToImmutableList();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public ImmutableList<T>? Where<T>(Func<T, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		var values = Items.Select(f => f.Value.Instance).Cast<T>();
 | 
			
		||||
 | 
			
		||||
		if (values is null || !values.Any())
 | 
			
		||||
			return default;
 | 
			
		||||
 | 
			
		||||
		var filtered = values.Where(predicate);
 | 
			
		||||
 | 
			
		||||
		if (filtered is null || !filtered.Any())
 | 
			
		||||
			return default;
 | 
			
		||||
 | 
			
		||||
		var r = new List<T>();
 | 
			
		||||
 | 
			
		||||
		foreach (var i in filtered)
 | 
			
		||||
		{
 | 
			
		||||
			var ce = Items.FirstOrDefault(f => InstanceEquals(f.Value?.Instance, i));
 | 
			
		||||
 | 
			
		||||
			if (ce.Value is null)
 | 
			
		||||
				continue;
 | 
			
		||||
 | 
			
		||||
			if (ce.Value.Expired)
 | 
			
		||||
			{
 | 
			
		||||
				RemoveInternal(ce.Value.Id);
 | 
			
		||||
				continue;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			ce.Value.Hit();
 | 
			
		||||
			r.Add(i);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return r.ToImmutableList();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void RemoveInternal(string key)
 | 
			
		||||
	{
 | 
			
		||||
		if (Items.TryRemove(key, out IEntry? d))
 | 
			
		||||
			d.Dispose();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private IEntry? Find<T>(Func<T, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		var instances = Items.Select(f => f.Value?.Instance).Cast<T>();
 | 
			
		||||
 | 
			
		||||
		if (instances is null || !instances.Any())
 | 
			
		||||
			return default;
 | 
			
		||||
 | 
			
		||||
		if (instances.FirstOrDefault(predicate) is not T instance)
 | 
			
		||||
			return default;
 | 
			
		||||
 | 
			
		||||
		var ce = Items.Values.FirstOrDefault(f => InstanceEquals(f.Instance, instance));
 | 
			
		||||
 | 
			
		||||
		if (ce is null)
 | 
			
		||||
			return default;
 | 
			
		||||
 | 
			
		||||
		if (ce.Expired)
 | 
			
		||||
		{
 | 
			
		||||
			RemoveInternal(ce.Id);
 | 
			
		||||
			return default;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		ce.Hit();
 | 
			
		||||
 | 
			
		||||
		return ce;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private IEntry? Find<T>(Func<dynamic, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		var instances = Items.Select(f => f.Value?.Instance).Cast<dynamic>();
 | 
			
		||||
 | 
			
		||||
		if (instances is null || !instances.Any())
 | 
			
		||||
			return default;
 | 
			
		||||
 | 
			
		||||
		if (instances.FirstOrDefault(predicate) is not T instance)
 | 
			
		||||
			return default;
 | 
			
		||||
 | 
			
		||||
		if (Items.Values.FirstOrDefault(f => InstanceEquals(f.Instance, instance)) is not IEntry ce)
 | 
			
		||||
			return default;
 | 
			
		||||
 | 
			
		||||
		if (ce.Expired)
 | 
			
		||||
		{
 | 
			
		||||
			RemoveInternal(ce.Id);
 | 
			
		||||
			return default;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		ce.Hit();
 | 
			
		||||
 | 
			
		||||
		return ce;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private IEntry? Find(string key)
 | 
			
		||||
	{
 | 
			
		||||
		if (!Items.ContainsKey(key))
 | 
			
		||||
			return default;
 | 
			
		||||
 | 
			
		||||
		if (Items.TryGetValue(key, out IEntry? d))
 | 
			
		||||
		{
 | 
			
		||||
			if (d.Expired)
 | 
			
		||||
			{
 | 
			
		||||
				RemoveInternal(key);
 | 
			
		||||
				return default;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			d.Hit();
 | 
			
		||||
 | 
			
		||||
			return d;
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			RemoveInternal(key);
 | 
			
		||||
 | 
			
		||||
			return default;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public bool Exists(string key)
 | 
			
		||||
	{
 | 
			
		||||
		return Find(key) is not null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Clear()
 | 
			
		||||
	{
 | 
			
		||||
		foreach (var i in Items)
 | 
			
		||||
			Remove(i.Key);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private static bool InstanceEquals(object? left, object? right)
 | 
			
		||||
	{
 | 
			
		||||
		/*
 | 
			
		||||
		 * TODO: implement IEquality check
 | 
			
		||||
		 */
 | 
			
		||||
		if (left is null || right is null)
 | 
			
		||||
			return false;
 | 
			
		||||
 | 
			
		||||
		if (left.GetType().IsPrimitive)
 | 
			
		||||
			return left == right;
 | 
			
		||||
 | 
			
		||||
		if (left is string && right is string)
 | 
			
		||||
			return string.Compare(left.ToString(), right.ToString(), false) == 0;
 | 
			
		||||
 | 
			
		||||
		if (left.GetType().IsValueType && right.GetType().IsValueType)
 | 
			
		||||
			return left.Equals(right);
 | 
			
		||||
 | 
			
		||||
		return ReferenceEqualityComparer.Instance.Equals(left, right);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										35
									
								
								src/Connected.Caching/Entry.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/Connected.Caching/Entry.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,35 @@
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
internal class Entry : IEntry
 | 
			
		||||
{
 | 
			
		||||
	public Entry(string id, object? instance, TimeSpan duration, bool slidingExpiration)
 | 
			
		||||
	{
 | 
			
		||||
		Id = id;
 | 
			
		||||
		Instance = instance;
 | 
			
		||||
		SlidingExpiration = slidingExpiration;
 | 
			
		||||
		Duration = duration;
 | 
			
		||||
 | 
			
		||||
		if (Duration > TimeSpan.Zero)
 | 
			
		||||
			ExpirationDate = DateTime.UtcNow.AddTicks(duration.Ticks);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public bool SlidingExpiration { get; }
 | 
			
		||||
	private DateTime ExpirationDate { get; set; }
 | 
			
		||||
	public TimeSpan Duration { get; set; }
 | 
			
		||||
 | 
			
		||||
	public object? Instance { get; }
 | 
			
		||||
	public string Id { get; }
 | 
			
		||||
	public bool Expired => ExpirationDate != DateTime.MinValue && ExpirationDate < DateTime.UtcNow;
 | 
			
		||||
 | 
			
		||||
	public void Hit()
 | 
			
		||||
	{
 | 
			
		||||
		if (SlidingExpiration && Duration > TimeSpan.Zero)
 | 
			
		||||
			ExpirationDate = DateTime.UtcNow.AddTicks(Duration.Ticks);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Dispose()
 | 
			
		||||
	{
 | 
			
		||||
		if (Instance is IDisposable disposable)
 | 
			
		||||
			disposable.Dispose();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										43
									
								
								src/Connected.Caching/EntryEnumerator.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								src/Connected.Caching/EntryEnumerator.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,43 @@
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Collections.Concurrent;
 | 
			
		||||
using Connected.Interop;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
internal class EntryEnumerator<T> : IEnumerator<T>
 | 
			
		||||
{
 | 
			
		||||
	public EntryEnumerator(ConcurrentDictionary<string, IEntry> items)
 | 
			
		||||
	{
 | 
			
		||||
		Items = items;
 | 
			
		||||
		Index = -1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private int Count => Items.Count;
 | 
			
		||||
	private int Index { get; set; }
 | 
			
		||||
	private ConcurrentDictionary<string, IEntry> Items { get; }
 | 
			
		||||
 | 
			
		||||
	public T Current => TypeConversion.TryConvert(Items.ElementAt(Index).Value.Instance, out T result) ? result : default;
 | 
			
		||||
 | 
			
		||||
	object IEnumerator.Current => Current;
 | 
			
		||||
 | 
			
		||||
	public void Dispose()
 | 
			
		||||
	{
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public bool MoveNext()
 | 
			
		||||
	{
 | 
			
		||||
		if (Index < Count - 1)
 | 
			
		||||
		{
 | 
			
		||||
			Index++;
 | 
			
		||||
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Reset()
 | 
			
		||||
	{
 | 
			
		||||
		Index = -1;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										16
									
								
								src/Connected.Caching/EntryOptions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/Connected.Caching/EntryOptions.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
public class EntryOptions
 | 
			
		||||
{
 | 
			
		||||
	public string Key { get; set; }
 | 
			
		||||
	public string? KeyProperty { get; set; }
 | 
			
		||||
	public TimeSpan Duration { get; set; }
 | 
			
		||||
	public bool SlidingExpiration { get; set; }
 | 
			
		||||
	public bool AllowNull { get; set; }
 | 
			
		||||
 | 
			
		||||
	public EntryOptions()
 | 
			
		||||
	{
 | 
			
		||||
		Duration = TimeSpan.FromMinutes(5);
 | 
			
		||||
		SlidingExpiration = true;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										39
									
								
								src/Connected.Caching/ICache.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/Connected.Caching/ICache.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,39 @@
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
public delegate void CacheInvalidateHandler(CacheEventArgs e);
 | 
			
		||||
public interface ICache : IDisposable
 | 
			
		||||
{
 | 
			
		||||
	event CacheInvalidateHandler? Invalidating;
 | 
			
		||||
	event CacheInvalidateHandler? Invalidated;
 | 
			
		||||
 | 
			
		||||
	ImmutableList<T>? All<T>(string key);
 | 
			
		||||
 | 
			
		||||
	Task<T?> Get<T>(string key, object id, Func<EntryOptions, Task<T?>>? retrieve);
 | 
			
		||||
	T? Get<T>(string key, object id);
 | 
			
		||||
	IEntry? Get(string key, object id);
 | 
			
		||||
	Task<T?> Get<T>(string key, Func<T, bool> predicate, Func<EntryOptions, Task<T?>>? retrieve);
 | 
			
		||||
	T? Get<T>(string key, Func<T, bool> predicate);
 | 
			
		||||
	T? First<T>(string key);
 | 
			
		||||
	IEnumerator<T>? GetEnumerator<T>(string key);
 | 
			
		||||
 | 
			
		||||
	ImmutableList<T>? Where<T>(string key, Func<T, bool> predicate);
 | 
			
		||||
	bool Exists(string key);
 | 
			
		||||
	bool IsEmpty(string key);
 | 
			
		||||
	void CreateKey(string key);
 | 
			
		||||
	Task Clear(string key);
 | 
			
		||||
 | 
			
		||||
	T? Set<T>(string key, object id, T? instance);
 | 
			
		||||
	T? Set<T>(string key, object id, T? instance, TimeSpan duration);
 | 
			
		||||
	T? Set<T>(string key, object id, T? instance, TimeSpan duration, bool slidingExpiration);
 | 
			
		||||
	void CopyTo(string key, object id, IEntry entry);
 | 
			
		||||
	Task<ImmutableList<string>?> Remove<T>(string key, Func<T, bool> predicate);
 | 
			
		||||
	Task Remove(string key, object id);
 | 
			
		||||
	Task Invalidate(string key, object id);
 | 
			
		||||
 | 
			
		||||
	int Count(string key);
 | 
			
		||||
	bool Any(string key);
 | 
			
		||||
	ImmutableList<string>? Keys(string key);
 | 
			
		||||
	ImmutableList<string>? Keys();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										7
									
								
								src/Connected.Caching/ICacheClient.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/Connected.Caching/ICacheClient.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
public interface ICacheClient<TEntry, TKey> : IEnumerable<TEntry>, IDisposable
 | 
			
		||||
{
 | 
			
		||||
	string Key { get; }
 | 
			
		||||
	int Count { get; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										6
									
								
								src/Connected.Caching/ICacheContext.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/Connected.Caching/ICacheContext.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,6 @@
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
public interface ICacheContext : ICache
 | 
			
		||||
{
 | 
			
		||||
	void Flush();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										7
									
								
								src/Connected.Caching/ICachingService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/Connected.Caching/ICachingService.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
public interface ICachingService : ICache
 | 
			
		||||
{
 | 
			
		||||
	void Merge(ICache cache);
 | 
			
		||||
	Task Initialize();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								src/Connected.Caching/IEntry.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/Connected.Caching/IEntry.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
public interface IEntry : IDisposable
 | 
			
		||||
{
 | 
			
		||||
	object? Instance { get; }
 | 
			
		||||
	string Id { get; }
 | 
			
		||||
	bool Expired { get; }
 | 
			
		||||
	TimeSpan Duration { get; }
 | 
			
		||||
	bool SlidingExpiration { get; }
 | 
			
		||||
	void Hit();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										6
									
								
								src/Connected.Caching/IMemoryCache.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/Connected.Caching/IMemoryCache.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,6 @@
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
public interface IMemoryCache : ICache
 | 
			
		||||
{
 | 
			
		||||
	void Merge(ICache cache);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										6
									
								
								src/Connected.Caching/IStatefulCacheClient.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/Connected.Caching/IStatefulCacheClient.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,6 @@
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
public interface IStatefulCacheClient<TEntry, TKey> : ICacheClient<TEntry, TKey>
 | 
			
		||||
{
 | 
			
		||||
	event CacheInvalidateHandler Invalidate;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										24
									
								
								src/Connected.Caching/MemoryCache.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/Connected.Caching/MemoryCache.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,24 @@
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
internal class MemoryCache : Cache, IMemoryCache
 | 
			
		||||
{
 | 
			
		||||
	public void Merge(ICache cache)
 | 
			
		||||
	{
 | 
			
		||||
		if (cache.Keys() is not ImmutableList<string> keys)
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		foreach (var key in keys)
 | 
			
		||||
		{
 | 
			
		||||
			if (cache.Keys(key) is not ImmutableList<string> entryKeys)
 | 
			
		||||
				continue;
 | 
			
		||||
 | 
			
		||||
			foreach (var entryKey in entryKeys)
 | 
			
		||||
			{
 | 
			
		||||
				if (cache.Get(key, entryKey) is IEntry entry)
 | 
			
		||||
					CopyTo(key, entryKey, entry);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								src/Connected.Caching/Net/CacheHub.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/Connected.Caching/Net/CacheHub.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
using Connected.Net.Hubs;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Caching.Net;
 | 
			
		||||
 | 
			
		||||
//TODO: implement authorization and add logic to reject connections if not an endpoint server
 | 
			
		||||
internal class CacheHub : StatefulHub<CacheNotificationArgs>
 | 
			
		||||
{
 | 
			
		||||
	public CacheHub(CacheServer server) : base(server)
 | 
			
		||||
	{
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								src/Connected.Caching/Net/CacheServer.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/Connected.Caching/Net/CacheServer.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
using Connected.Net.Hubs;
 | 
			
		||||
using Microsoft.AspNetCore.SignalR;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Caching.Net;
 | 
			
		||||
 | 
			
		||||
internal class CacheServer : Server<CacheHub, CacheNotificationArgs>
 | 
			
		||||
{
 | 
			
		||||
	public CacheServer(IHubContext<CacheHub> hub) : base(hub)
 | 
			
		||||
	{
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										36
									
								
								src/Connected.Caching/Net/CacheServerConnection.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/Connected.Caching/Net/CacheServerConnection.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,36 @@
 | 
			
		||||
using Connected.Net.Hubs;
 | 
			
		||||
using Connected.Net.Messaging;
 | 
			
		||||
using Connected.Net.Server;
 | 
			
		||||
using Microsoft.AspNetCore.SignalR.Client;
 | 
			
		||||
using Microsoft.Extensions.Logging;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Caching.Net;
 | 
			
		||||
 | 
			
		||||
internal class CacheServerConnection : ServerConnection
 | 
			
		||||
{
 | 
			
		||||
	public event EventHandler<CacheNotificationArgs>? Received;
 | 
			
		||||
 | 
			
		||||
	public CacheServerConnection(IEndpointServer server, ILogger<CacheServerConnection> logger) : base(server)
 | 
			
		||||
	{
 | 
			
		||||
		Logger = logger;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private ILogger<CacheServerConnection> Logger { get; }
 | 
			
		||||
 | 
			
		||||
	public override async Task Initialize(string hubUrl)
 | 
			
		||||
	{
 | 
			
		||||
		await base.Initialize(hubUrl);
 | 
			
		||||
 | 
			
		||||
		Connection.On<MessageAcknowledgeArgs, CacheNotificationArgs>("Notify", (a, e) =>
 | 
			
		||||
		{
 | 
			
		||||
			Connection.InvokeAsync(nameof(CacheHub.Acknowledge), a);
 | 
			
		||||
 | 
			
		||||
			Received?.Invoke(this, e);
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		Connection.On<ServerExceptionArgs>("Exception", (e) =>
 | 
			
		||||
		{
 | 
			
		||||
			Logger.LogError("Caching hub exception: {message}", e.Message);
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								src/Connected.Caching/Net/CacheWorker.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/Connected.Caching/Net/CacheWorker.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
using Connected.Net.Hubs;
 | 
			
		||||
using Microsoft.AspNetCore.SignalR;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Caching.Net;
 | 
			
		||||
 | 
			
		||||
internal sealed class CacheWorker : ServerWorker<CacheNotificationArgs, CacheHub>
 | 
			
		||||
{
 | 
			
		||||
	public CacheWorker(CacheServer server, IHubContext<CacheHub> hub) : base(server, hub)
 | 
			
		||||
	{
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										72
									
								
								src/Connected.Caching/SR.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								src/Connected.Caching/SR.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							@ -0,0 +1,72 @@
 | 
			
		||||
//------------------------------------------------------------------------------
 | 
			
		||||
// <auto-generated>
 | 
			
		||||
//     This code was generated by a tool.
 | 
			
		||||
//     Runtime Version:4.0.30319.42000
 | 
			
		||||
//
 | 
			
		||||
//     Changes to this file may cause incorrect behavior and will be lost if
 | 
			
		||||
//     the code is regenerated.
 | 
			
		||||
// </auto-generated>
 | 
			
		||||
//------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
namespace Connected.Caching {
 | 
			
		||||
    using System;
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    ///   A strongly-typed resource class, for looking up localized strings, etc.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    // This class was auto-generated by the StronglyTypedResourceBuilder
 | 
			
		||||
    // class via a tool like ResGen or Visual Studio.
 | 
			
		||||
    // To add or remove a member, edit your .ResX file then rerun ResGen
 | 
			
		||||
    // with the /str option, or rebuild your VS project.
 | 
			
		||||
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
 | 
			
		||||
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
 | 
			
		||||
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
 | 
			
		||||
    internal class SR {
 | 
			
		||||
        
 | 
			
		||||
        private static global::System.Resources.ResourceManager resourceMan;
 | 
			
		||||
        
 | 
			
		||||
        private static global::System.Globalization.CultureInfo resourceCulture;
 | 
			
		||||
        
 | 
			
		||||
        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
 | 
			
		||||
        internal SR() {
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   Returns the cached ResourceManager instance used by this class.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
 | 
			
		||||
        internal static global::System.Resources.ResourceManager ResourceManager {
 | 
			
		||||
            get {
 | 
			
		||||
                if (object.ReferenceEquals(resourceMan, null)) {
 | 
			
		||||
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Connected.Caching.SR", typeof(SR).Assembly);
 | 
			
		||||
                    resourceMan = temp;
 | 
			
		||||
                }
 | 
			
		||||
                return resourceMan;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   Overrides the current thread's CurrentUICulture property for all
 | 
			
		||||
        ///   resource lookups using this strongly typed resource class.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
 | 
			
		||||
        internal static global::System.Globalization.CultureInfo Culture {
 | 
			
		||||
            get {
 | 
			
		||||
                return resourceCulture;
 | 
			
		||||
            }
 | 
			
		||||
            set {
 | 
			
		||||
                resourceCulture = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   Looks up a localized string similar to Cache Key property not set. Please set 'Key' property before returning value from cache retrieve handler or set CacheKeyAttribute on at least one property..
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal static string ErrCacheKeyNull {
 | 
			
		||||
            get {
 | 
			
		||||
                return ResourceManager.GetString("ErrCacheKeyNull", resourceCulture);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										123
									
								
								src/Connected.Caching/SR.resx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										123
									
								
								src/Connected.Caching/SR.resx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,123 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<root>
 | 
			
		||||
  <!-- 
 | 
			
		||||
    Microsoft ResX Schema 
 | 
			
		||||
    
 | 
			
		||||
    Version 2.0
 | 
			
		||||
    
 | 
			
		||||
    The primary goals of this format is to allow a simple XML format 
 | 
			
		||||
    that is mostly human readable. The generation and parsing of the 
 | 
			
		||||
    various data types are done through the TypeConverter classes 
 | 
			
		||||
    associated with the data types.
 | 
			
		||||
    
 | 
			
		||||
    Example:
 | 
			
		||||
    
 | 
			
		||||
    ... ado.net/XML headers & schema ...
 | 
			
		||||
    <resheader name="resmimetype">text/microsoft-resx</resheader>
 | 
			
		||||
    <resheader name="version">2.0</resheader>
 | 
			
		||||
    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
 | 
			
		||||
    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
 | 
			
		||||
    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
 | 
			
		||||
    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
 | 
			
		||||
    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
 | 
			
		||||
        <value>[base64 mime encoded serialized .NET Framework object]</value>
 | 
			
		||||
    </data>
 | 
			
		||||
    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
 | 
			
		||||
        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
 | 
			
		||||
        <comment>This is a comment</comment>
 | 
			
		||||
    </data>
 | 
			
		||||
                
 | 
			
		||||
    There are any number of "resheader" rows that contain simple 
 | 
			
		||||
    name/value pairs.
 | 
			
		||||
    
 | 
			
		||||
    Each data row contains a name, and value. The row also contains a 
 | 
			
		||||
    type or mimetype. Type corresponds to a .NET class that support 
 | 
			
		||||
    text/value conversion through the TypeConverter architecture. 
 | 
			
		||||
    Classes that don't support this are serialized and stored with the 
 | 
			
		||||
    mimetype set.
 | 
			
		||||
    
 | 
			
		||||
    The mimetype is used for serialized objects, and tells the 
 | 
			
		||||
    ResXResourceReader how to depersist the object. This is currently not 
 | 
			
		||||
    extensible. For a given mimetype the value must be set accordingly:
 | 
			
		||||
    
 | 
			
		||||
    Note - application/x-microsoft.net.object.binary.base64 is the format 
 | 
			
		||||
    that the ResXResourceWriter will generate, however the reader can 
 | 
			
		||||
    read any of the formats listed below.
 | 
			
		||||
    
 | 
			
		||||
    mimetype: application/x-microsoft.net.object.binary.base64
 | 
			
		||||
    value   : The object must be serialized with 
 | 
			
		||||
            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
 | 
			
		||||
            : and then encoded with base64 encoding.
 | 
			
		||||
    
 | 
			
		||||
    mimetype: application/x-microsoft.net.object.soap.base64
 | 
			
		||||
    value   : The object must be serialized with 
 | 
			
		||||
            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
 | 
			
		||||
            : and then encoded with base64 encoding.
 | 
			
		||||
 | 
			
		||||
    mimetype: application/x-microsoft.net.object.bytearray.base64
 | 
			
		||||
    value   : The object must be serialized into a byte array 
 | 
			
		||||
            : using a System.ComponentModel.TypeConverter
 | 
			
		||||
            : and then encoded with base64 encoding.
 | 
			
		||||
    -->
 | 
			
		||||
  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
 | 
			
		||||
    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
 | 
			
		||||
    <xsd:element name="root" msdata:IsDataSet="true">
 | 
			
		||||
      <xsd:complexType>
 | 
			
		||||
        <xsd:choice maxOccurs="unbounded">
 | 
			
		||||
          <xsd:element name="metadata">
 | 
			
		||||
            <xsd:complexType>
 | 
			
		||||
              <xsd:sequence>
 | 
			
		||||
                <xsd:element name="value" type="xsd:string" minOccurs="0" />
 | 
			
		||||
              </xsd:sequence>
 | 
			
		||||
              <xsd:attribute name="name" use="required" type="xsd:string" />
 | 
			
		||||
              <xsd:attribute name="type" type="xsd:string" />
 | 
			
		||||
              <xsd:attribute name="mimetype" type="xsd:string" />
 | 
			
		||||
              <xsd:attribute ref="xml:space" />
 | 
			
		||||
            </xsd:complexType>
 | 
			
		||||
          </xsd:element>
 | 
			
		||||
          <xsd:element name="assembly">
 | 
			
		||||
            <xsd:complexType>
 | 
			
		||||
              <xsd:attribute name="alias" type="xsd:string" />
 | 
			
		||||
              <xsd:attribute name="name" type="xsd:string" />
 | 
			
		||||
            </xsd:complexType>
 | 
			
		||||
          </xsd:element>
 | 
			
		||||
          <xsd:element name="data">
 | 
			
		||||
            <xsd:complexType>
 | 
			
		||||
              <xsd:sequence>
 | 
			
		||||
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
 | 
			
		||||
                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
 | 
			
		||||
              </xsd:sequence>
 | 
			
		||||
              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
 | 
			
		||||
              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
 | 
			
		||||
              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
 | 
			
		||||
              <xsd:attribute ref="xml:space" />
 | 
			
		||||
            </xsd:complexType>
 | 
			
		||||
          </xsd:element>
 | 
			
		||||
          <xsd:element name="resheader">
 | 
			
		||||
            <xsd:complexType>
 | 
			
		||||
              <xsd:sequence>
 | 
			
		||||
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
 | 
			
		||||
              </xsd:sequence>
 | 
			
		||||
              <xsd:attribute name="name" type="xsd:string" use="required" />
 | 
			
		||||
            </xsd:complexType>
 | 
			
		||||
          </xsd:element>
 | 
			
		||||
        </xsd:choice>
 | 
			
		||||
      </xsd:complexType>
 | 
			
		||||
    </xsd:element>
 | 
			
		||||
  </xsd:schema>
 | 
			
		||||
  <resheader name="resmimetype">
 | 
			
		||||
    <value>text/microsoft-resx</value>
 | 
			
		||||
  </resheader>
 | 
			
		||||
  <resheader name="version">
 | 
			
		||||
    <value>2.0</value>
 | 
			
		||||
  </resheader>
 | 
			
		||||
  <resheader name="reader">
 | 
			
		||||
    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
 | 
			
		||||
  </resheader>
 | 
			
		||||
  <resheader name="writer">
 | 
			
		||||
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
 | 
			
		||||
  </resheader>
 | 
			
		||||
  <data name="ErrCacheKeyNull" xml:space="preserve">
 | 
			
		||||
    <value>Cache Key property not set. Please set 'Key' property before returning value from cache retrieve handler or set CacheKeyAttribute on at least one property.</value>
 | 
			
		||||
  </data>
 | 
			
		||||
</root>
 | 
			
		||||
							
								
								
									
										113
									
								
								src/Connected.Caching/StatefulCacheClient.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								src/Connected.Caching/StatefulCacheClient.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,113 @@
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
using System.Globalization;
 | 
			
		||||
using Connected.Interop;
 | 
			
		||||
using Connected.Threading;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Caching;
 | 
			
		||||
 | 
			
		||||
public abstract class StatefulCacheClient<TEntry, TKey> : CacheClient<TEntry, TKey>, IStatefulCacheClient<TEntry, TKey> where TEntry : class
 | 
			
		||||
{
 | 
			
		||||
	public event CacheInvalidateHandler Invalidate;
 | 
			
		||||
	protected StatefulCacheClient(ICachingService cachingService, string key) : base(cachingService, key)
 | 
			
		||||
	{
 | 
			
		||||
		Locker = new AsyncLockerSlim();
 | 
			
		||||
 | 
			
		||||
		CachingService.Invalidating += OnInvalidate;
 | 
			
		||||
	}
 | 
			
		||||
	private AsyncLockerSlim? Locker { get; set; }
 | 
			
		||||
	protected virtual InvalidateBehavior InvalidateBehavior { get; } = InvalidateBehavior.KeepSameInstance;
 | 
			
		||||
	private bool Initialized { get; set; }
 | 
			
		||||
	private async void OnInvalidate(CacheEventArgs e)
 | 
			
		||||
	{
 | 
			
		||||
		if (string.Equals(e.Key, Key, StringComparison.OrdinalIgnoreCase))
 | 
			
		||||
		{
 | 
			
		||||
			if (Initialized)
 | 
			
		||||
				await OnInvalidate(TypeConversion.Convert<TKey>(e.Id, CultureInfo.InvariantCulture));
 | 
			
		||||
 | 
			
		||||
			Invalidate?.Invoke(e);
 | 
			
		||||
 | 
			
		||||
			e.Behavior = InvalidateBehavior;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	protected virtual async Task OnInvalidate(TKey id)
 | 
			
		||||
	{
 | 
			
		||||
		await Task.CompletedTask;
 | 
			
		||||
	}
 | 
			
		||||
	protected virtual async Task OnInitializing()
 | 
			
		||||
	{
 | 
			
		||||
		await Task.CompletedTask;
 | 
			
		||||
	}
 | 
			
		||||
	protected async Task Initialize()
 | 
			
		||||
	{
 | 
			
		||||
		if (Initialized || IsDisposed || Locker is null)
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		await Locker.LockAsync(async () =>
 | 
			
		||||
		{
 | 
			
		||||
			if (Initialized || IsDisposed)
 | 
			
		||||
				return;
 | 
			
		||||
 | 
			
		||||
			await OnInitializing();
 | 
			
		||||
 | 
			
		||||
			Initialized = true;
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		if (Initialized)
 | 
			
		||||
			await OnInitialized();
 | 
			
		||||
	}
 | 
			
		||||
	protected virtual async Task OnInitialized()
 | 
			
		||||
	{
 | 
			
		||||
		await Task.CompletedTask;
 | 
			
		||||
	}
 | 
			
		||||
	protected override async Task<ImmutableList<TEntry>?> All()
 | 
			
		||||
	{
 | 
			
		||||
		await Initialize();
 | 
			
		||||
 | 
			
		||||
		return base.All().Result;
 | 
			
		||||
	}
 | 
			
		||||
	protected override async Task<TEntry?> First()
 | 
			
		||||
	{
 | 
			
		||||
		await Initialize();
 | 
			
		||||
 | 
			
		||||
		return await base.First();
 | 
			
		||||
	}
 | 
			
		||||
	protected override async Task<TEntry?> Get(Func<TEntry, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		await Initialize();
 | 
			
		||||
 | 
			
		||||
		return await base.Get(predicate);
 | 
			
		||||
	}
 | 
			
		||||
	protected override async Task<TEntry?> Get(TKey id)
 | 
			
		||||
	{
 | 
			
		||||
		await Initialize();
 | 
			
		||||
 | 
			
		||||
		return await base.Get(id);
 | 
			
		||||
	}
 | 
			
		||||
	protected override async Task<TEntry?> Get(TKey id, Func<EntryOptions, Task<TEntry>> retrieve)
 | 
			
		||||
	{
 | 
			
		||||
		await Initialize();
 | 
			
		||||
 | 
			
		||||
		return await base.Get(id, retrieve);
 | 
			
		||||
	}
 | 
			
		||||
	protected override async Task<ImmutableList<TEntry>?> Where(Func<TEntry, bool> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		await Initialize();
 | 
			
		||||
 | 
			
		||||
		return await base.Where(predicate);
 | 
			
		||||
	}
 | 
			
		||||
	protected override void OnDisposing()
 | 
			
		||||
	{
 | 
			
		||||
		if (Locker is not null)
 | 
			
		||||
		{
 | 
			
		||||
			Locker?.Dispose();
 | 
			
		||||
			Locker = null;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override IEnumerator<TEntry> GetEnumerator()
 | 
			
		||||
	{
 | 
			
		||||
		AsyncUtils.RunSync(Initialize);
 | 
			
		||||
 | 
			
		||||
		return base.GetEnumerator();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										76
									
								
								src/Connected.Collections/CollectionExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								src/Connected.Collections/CollectionExtensions.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,76 @@
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using Connected.Annotations;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Collections;
 | 
			
		||||
 | 
			
		||||
public static class CollectionExtensions
 | 
			
		||||
{
 | 
			
		||||
	public static ImmutableArray<TSource> ToImmutableArray<TSource>(this IEnumerable<TSource> items, bool performLock)
 | 
			
		||||
	{
 | 
			
		||||
		if (!performLock)
 | 
			
		||||
			return items.ToImmutableArray();
 | 
			
		||||
 | 
			
		||||
		lock (items)
 | 
			
		||||
			return items.ToImmutableArray();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static ImmutableList<TSource> ToImmutableList<TSource>(this IEnumerable<TSource> items, bool performLock)
 | 
			
		||||
	{
 | 
			
		||||
		if (!performLock)
 | 
			
		||||
			return items.ToImmutableList();
 | 
			
		||||
 | 
			
		||||
		lock (items)
 | 
			
		||||
			return items.ToImmutableList();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static void SortByOrdinal<TElement>(this List<TElement> items)
 | 
			
		||||
	{
 | 
			
		||||
		items.Sort((left, right) =>
 | 
			
		||||
		{
 | 
			
		||||
			var leftOrdinal = left is Type lt ? lt.GetCustomAttribute<OrdinalAttribute>() : left?.GetType().GetCustomAttribute<OrdinalAttribute>();
 | 
			
		||||
			var rightOrdinal = right is Type rt ? rt.GetCustomAttribute<OrdinalAttribute>() : right?.GetType().GetCustomAttribute<OrdinalAttribute>();
 | 
			
		||||
 | 
			
		||||
			if (leftOrdinal is null && rightOrdinal is null)
 | 
			
		||||
				return 0;
 | 
			
		||||
 | 
			
		||||
			if (leftOrdinal is not null && rightOrdinal is null)
 | 
			
		||||
				return -1;
 | 
			
		||||
 | 
			
		||||
			if (leftOrdinal is null && rightOrdinal is not null)
 | 
			
		||||
				return 1;
 | 
			
		||||
 | 
			
		||||
			if (leftOrdinal?.Value == rightOrdinal?.Value)
 | 
			
		||||
				return 0;
 | 
			
		||||
			else if (leftOrdinal?.Value < rightOrdinal?.Value)
 | 
			
		||||
				return 1;
 | 
			
		||||
			else
 | 
			
		||||
				return -1;
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static void SortByPriority<TElement>(this List<TElement> items)
 | 
			
		||||
	{
 | 
			
		||||
		items.Sort((left, right) =>
 | 
			
		||||
		{
 | 
			
		||||
			var leftPriority = left is Type lt ? lt.GetCustomAttribute<PriorityAttribute>() : left?.GetType().GetCustomAttribute<PriorityAttribute>();
 | 
			
		||||
			var rightPriority = right is Type rt ? rt.GetCustomAttribute<PriorityAttribute>() : right?.GetType().GetCustomAttribute<PriorityAttribute>();
 | 
			
		||||
 | 
			
		||||
			if (leftPriority is null && rightPriority is null)
 | 
			
		||||
				return 0;
 | 
			
		||||
 | 
			
		||||
			if (leftPriority is not null && rightPriority is null)
 | 
			
		||||
				return -1;
 | 
			
		||||
 | 
			
		||||
			if (leftPriority is null && rightPriority is not null)
 | 
			
		||||
				return 1;
 | 
			
		||||
 | 
			
		||||
			if (leftPriority?.Value == rightPriority?.Value)
 | 
			
		||||
				return 0;
 | 
			
		||||
			else if (leftPriority?.Value > rightPriority?.Value)
 | 
			
		||||
				return -1;
 | 
			
		||||
			else
 | 
			
		||||
				return 1;
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										6
									
								
								src/Connected.Collections/CollectionRoutes.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/Connected.Collections/CollectionRoutes.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,6 @@
 | 
			
		||||
namespace Connected.Collections;
 | 
			
		||||
 | 
			
		||||
public static class CollectionRoutes
 | 
			
		||||
{
 | 
			
		||||
	public const string Queue = "/sys/queue";
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										16
									
								
								src/Connected.Collections/CollectionsStartup.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/Connected.Collections/CollectionsStartup.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
			
		||||
using Connected.Annotations;
 | 
			
		||||
using Microsoft.AspNetCore.Builder;
 | 
			
		||||
 | 
			
		||||
[assembly: MicroService(MicroServiceType.Sys)]
 | 
			
		||||
 | 
			
		||||
namespace Connected.Collections;
 | 
			
		||||
 | 
			
		||||
internal class CollectionsStartup : Startup
 | 
			
		||||
{
 | 
			
		||||
	public static WebApplication? Application { get; private set; }
 | 
			
		||||
 | 
			
		||||
	protected override void OnConfigure(WebApplication app)
 | 
			
		||||
	{
 | 
			
		||||
		Application = app;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										177
									
								
								src/Connected.Collections/Concurrent/Dispatcher.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										177
									
								
								src/Connected.Collections/Concurrent/Dispatcher.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,177 @@
 | 
			
		||||
using System.Collections.Concurrent;
 | 
			
		||||
using Connected;
 | 
			
		||||
using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Collections.Concurrent;
 | 
			
		||||
 | 
			
		||||
public abstract class Dispatcher<TArgs, TJob> : IDispatcher<TArgs, TJob>
 | 
			
		||||
	where TJob : IDispatcherJob<TArgs>
 | 
			
		||||
{
 | 
			
		||||
	private CancellationTokenSource _tokenSource;
 | 
			
		||||
	protected Dispatcher(int size)
 | 
			
		||||
	{
 | 
			
		||||
		WorkerSize = size;
 | 
			
		||||
 | 
			
		||||
		_tokenSource = new();
 | 
			
		||||
 | 
			
		||||
		Queue = new();
 | 
			
		||||
		Jobs = new();
 | 
			
		||||
		QueuedDispatchers = new();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public CancellationToken CancellationToken => _tokenSource.Token;
 | 
			
		||||
	private ConcurrentQueue<TArgs> Queue { get; set; }
 | 
			
		||||
	private List<DispatcherJob<TArgs>> Jobs { get; set; }
 | 
			
		||||
	protected bool IsDisposed { get; private set; }
 | 
			
		||||
	private int WorkerSize { get; }
 | 
			
		||||
	public int Available => Math.Max(0, WorkerSize * 4 - Queue.Count - QueuedDispatchers.Sum(f => f.Value.Count));
 | 
			
		||||
	private ConcurrentDictionary<string, QueuedDispatcher<TArgs, TJob>> QueuedDispatchers { get; set; }
 | 
			
		||||
	public DispatcherProcessBehavior Behavior => DispatcherProcessBehavior.Parallel;
 | 
			
		||||
 | 
			
		||||
	public void Cancel()
 | 
			
		||||
	{
 | 
			
		||||
		_tokenSource?.Cancel();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public bool Dequeue(out TArgs? item)
 | 
			
		||||
	{
 | 
			
		||||
		return Queue.TryDequeue(out item);
 | 
			
		||||
	}
 | 
			
		||||
	public bool Enqueue(string queue, TArgs item)
 | 
			
		||||
	{
 | 
			
		||||
		if (EnsureDispatcher(queue) is not QueuedDispatcher<TArgs, TJob> dispatcher)
 | 
			
		||||
			throw new SysException(this, $"{SR.ErrCreateQueuedDispatcher} ({queue})");
 | 
			
		||||
 | 
			
		||||
		return dispatcher.Enqueue(item);
 | 
			
		||||
	}
 | 
			
		||||
	public bool Enqueue(TArgs item)
 | 
			
		||||
	{
 | 
			
		||||
		Queue.Enqueue(item);
 | 
			
		||||
 | 
			
		||||
		if (Jobs.Count < WorkerSize)
 | 
			
		||||
		{
 | 
			
		||||
			/*
 | 
			
		||||
			 * Dispatcher jobs should be transient so it's safe to request a service from the root collection.
 | 
			
		||||
			 */
 | 
			
		||||
			if (CollectionsStartup.Application.Services.GetService<TJob>() is not DispatcherJob<TArgs> job)
 | 
			
		||||
				throw new NullReferenceException($"{SR.ErrCreateService} ({typeof(DispatcherJob<TArgs>).Name})");
 | 
			
		||||
 | 
			
		||||
			job.Completed += OnCompleted;
 | 
			
		||||
 | 
			
		||||
			lock (Jobs)
 | 
			
		||||
			{
 | 
			
		||||
				Jobs.Add(job);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			job.Run(Queue, CancellationToken);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void OnCompleted(object? sender, EventArgs e)
 | 
			
		||||
	{
 | 
			
		||||
		if (sender is not DispatcherJob<TArgs> job)
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		if (Queue.IsEmpty)
 | 
			
		||||
		{
 | 
			
		||||
			lock (Jobs)
 | 
			
		||||
			{
 | 
			
		||||
				Jobs.Remove(job);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			job.Dispose();
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
			job.Run(Queue, CancellationToken);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private QueuedDispatcher<TArgs, TJob>? EnsureDispatcher(string queueName)
 | 
			
		||||
	{
 | 
			
		||||
		if (QueuedDispatchers.TryGetValue(queueName, out QueuedDispatcher<TArgs, TJob>? result))
 | 
			
		||||
			return result;
 | 
			
		||||
 | 
			
		||||
		result = new QueuedDispatcher<TArgs, TJob>(this, queueName);
 | 
			
		||||
 | 
			
		||||
		result.Completed += OnQueuedCompleted;
 | 
			
		||||
 | 
			
		||||
		if (!QueuedDispatchers.TryAdd(queueName, result))
 | 
			
		||||
		{
 | 
			
		||||
			result.Completed -= OnQueuedCompleted;
 | 
			
		||||
 | 
			
		||||
			if (QueuedDispatchers.TryGetValue(queueName, out QueuedDispatcher<TArgs, TJob>? retryResult))
 | 
			
		||||
				return retryResult;
 | 
			
		||||
			else
 | 
			
		||||
				return default;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return result;
 | 
			
		||||
	}
 | 
			
		||||
	private void OnQueuedCompleted(object? sender, EventArgs e)
 | 
			
		||||
	{
 | 
			
		||||
		if (sender is not QueuedDispatcher<TArgs, TJob> dispatcher)
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		if (dispatcher.Count > 0)
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		QueuedDispatchers.Remove(dispatcher.QueueName, out _);
 | 
			
		||||
 | 
			
		||||
		dispatcher.Dispose();
 | 
			
		||||
	}
 | 
			
		||||
	private void Dispose(bool disposing)
 | 
			
		||||
	{
 | 
			
		||||
		if (!IsDisposed)
 | 
			
		||||
		{
 | 
			
		||||
			if (disposing)
 | 
			
		||||
			{
 | 
			
		||||
				if (_tokenSource is not null)
 | 
			
		||||
				{
 | 
			
		||||
					if (!_tokenSource.IsCancellationRequested)
 | 
			
		||||
						_tokenSource.Cancel();
 | 
			
		||||
 | 
			
		||||
					_tokenSource.Dispose();
 | 
			
		||||
					_tokenSource = null;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				if (Queue is not null)
 | 
			
		||||
				{
 | 
			
		||||
					Queue.Clear();
 | 
			
		||||
					Queue = null;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				if (Jobs is not null)
 | 
			
		||||
				{
 | 
			
		||||
					foreach (var job in Jobs)
 | 
			
		||||
						job.Dispose();
 | 
			
		||||
 | 
			
		||||
					Jobs.Clear();
 | 
			
		||||
					Jobs = null;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				if (QueuedDispatchers is not null)
 | 
			
		||||
				{
 | 
			
		||||
					foreach (var dispatcher in QueuedDispatchers)
 | 
			
		||||
						dispatcher.Value.Dispose();
 | 
			
		||||
 | 
			
		||||
					QueuedDispatchers.Clear();
 | 
			
		||||
					Queue = null;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			IsDisposed = true;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected virtual void OnDisposing()
 | 
			
		||||
	{
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
	public void Dispose()
 | 
			
		||||
	{
 | 
			
		||||
		Dispose(true);
 | 
			
		||||
		GC.SuppressFinalize(this);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										103
									
								
								src/Connected.Collections/Concurrent/DispatcherJob.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								src/Connected.Collections/Concurrent/DispatcherJob.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,103 @@
 | 
			
		||||
using System.Collections.Concurrent;
 | 
			
		||||
using System.ComponentModel;
 | 
			
		||||
using Connected.Data;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Collections.Concurrent;
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// This class acts as a job unit of the <see cref="IDispatcher{T}"/>.
 | 
			
		||||
/// </summary>
 | 
			
		||||
/// <typeparam name="TArgs"></typeparam>
 | 
			
		||||
public abstract class DispatcherJob<TArgs> : IDispatcherJob<TArgs>, IDisposable
 | 
			
		||||
{
 | 
			
		||||
	public event EventHandler? Completed;
 | 
			
		||||
	public bool IsRunning { get; private set; }
 | 
			
		||||
	protected bool IsDisposed { get; private set; }
 | 
			
		||||
	private CancellationToken CancellationToken { get; set; }
 | 
			
		||||
 | 
			
		||||
	internal void Run(ConcurrentQueue<TArgs> queue, CancellationToken cancellationToken)
 | 
			
		||||
	{
 | 
			
		||||
		CancellationToken = cancellationToken;
 | 
			
		||||
 | 
			
		||||
		if (IsRunning)
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		Task.Run(async () =>
 | 
			
		||||
		{
 | 
			
		||||
			IsRunning = true;
 | 
			
		||||
			TArgs? item = default;
 | 
			
		||||
 | 
			
		||||
			try
 | 
			
		||||
			{
 | 
			
		||||
				while (queue.TryDequeue(out item))
 | 
			
		||||
				{
 | 
			
		||||
					if (item is null)
 | 
			
		||||
						continue;
 | 
			
		||||
 | 
			
		||||
					if (item is IPopReceipt pr && pr.NextVisible <= DateTime.UtcNow)
 | 
			
		||||
						continue;
 | 
			
		||||
 | 
			
		||||
					await Invoke(item);
 | 
			
		||||
 | 
			
		||||
					if (cancellationToken.IsCancellationRequested || IsDisposed)
 | 
			
		||||
						break;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			catch (Exception ex)
 | 
			
		||||
			{
 | 
			
		||||
				await HandleException(item, ex);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			IsRunning = false;
 | 
			
		||||
			Completed?.Invoke(this, EventArgs.Empty);
 | 
			
		||||
 | 
			
		||||
		}, CancellationToken);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void OnCompleted(object? sender, RunWorkerCompletedEventArgs e)
 | 
			
		||||
	{
 | 
			
		||||
		Completed?.Invoke(this, EventArgs.Empty);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public async Task Invoke(TArgs args)
 | 
			
		||||
	{
 | 
			
		||||
		await OnInvoke(args, CancellationToken);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected virtual async Task OnInvoke(TArgs args, CancellationToken cancellationToken)
 | 
			
		||||
	{
 | 
			
		||||
		await Task.CompletedTask;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private async Task HandleException(TArgs? args, Exception ex)
 | 
			
		||||
	{
 | 
			
		||||
		await OnHandleEception(args, ex);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected virtual async Task OnHandleEception(TArgs? args, Exception ex)
 | 
			
		||||
	{
 | 
			
		||||
		await Task.CompletedTask;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Dispose()
 | 
			
		||||
	{
 | 
			
		||||
		Dispose(true);
 | 
			
		||||
		GC.SuppressFinalize(this);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected virtual void Dispose(bool disposing)
 | 
			
		||||
	{
 | 
			
		||||
		if (IsDisposed)
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		if (disposing)
 | 
			
		||||
			OnDisposing();
 | 
			
		||||
 | 
			
		||||
		IsDisposed = true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected virtual void OnDisposing()
 | 
			
		||||
	{
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								src/Connected.Collections/Concurrent/IDispatcher.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/Connected.Collections/Concurrent/IDispatcher.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
			
		||||
namespace Connected.Collections.Concurrent;
 | 
			
		||||
 | 
			
		||||
public enum DispatcherProcessBehavior
 | 
			
		||||
{
 | 
			
		||||
	Parallel = 1,
 | 
			
		||||
	Queued = 2
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public interface IDispatcher<TArgs, TJob> : IDisposable
 | 
			
		||||
	where TJob : IDispatcherJob<TArgs>
 | 
			
		||||
{
 | 
			
		||||
	bool Dequeue(out TArgs? item);
 | 
			
		||||
	bool Enqueue(TArgs item);
 | 
			
		||||
	bool Enqueue(string queue, TArgs item);
 | 
			
		||||
	DispatcherProcessBehavior Behavior { get; }
 | 
			
		||||
 | 
			
		||||
	CancellationToken CancellationToken { get; }
 | 
			
		||||
	void Cancel();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										7
									
								
								src/Connected.Collections/Concurrent/IDispatcherJob.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/Connected.Collections/Concurrent/IDispatcherJob.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
			
		||||
namespace Connected.Collections.Concurrent;
 | 
			
		||||
 | 
			
		||||
public interface IDispatcherJob<TArgs> : IDisposable
 | 
			
		||||
{
 | 
			
		||||
	Task Invoke(TArgs args);
 | 
			
		||||
	bool IsRunning { get; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										99
									
								
								src/Connected.Collections/Concurrent/QueuedDispatcher.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										99
									
								
								src/Connected.Collections/Concurrent/QueuedDispatcher.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,99 @@
 | 
			
		||||
using System.Collections.Concurrent;
 | 
			
		||||
using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Collections.Concurrent;
 | 
			
		||||
 | 
			
		||||
internal sealed class QueuedDispatcher<TArgs, TJob> : IDispatcher<TArgs, TJob>
 | 
			
		||||
	where TJob : IDispatcherJob<TArgs>
 | 
			
		||||
{
 | 
			
		||||
	public event EventHandler? Completed;
 | 
			
		||||
 | 
			
		||||
	public QueuedDispatcher(IDispatcher<TArgs, TJob> dispatcher, string queueName)
 | 
			
		||||
	{
 | 
			
		||||
		Dispatcher = dispatcher;
 | 
			
		||||
		Queue = new();
 | 
			
		||||
		QueueName = queueName;
 | 
			
		||||
 | 
			
		||||
		/*
 | 
			
		||||
		 * Dispatcher jobs should be transient so it's safe to request a service from the root collection.
 | 
			
		||||
		 */
 | 
			
		||||
		if (CollectionsStartup.Application?.Services.GetService<DispatcherJob<TArgs>>() is not DispatcherJob<TArgs> job)
 | 
			
		||||
			throw new SysException(this, $"{SR.ErrCreateService} ({typeof(DispatcherJob<TArgs>).Name})");
 | 
			
		||||
 | 
			
		||||
		job.Completed += OnCompleted;
 | 
			
		||||
 | 
			
		||||
		Job = job;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public CancellationToken CancellationToken => Dispatcher.CancellationToken;
 | 
			
		||||
	public bool IsDisposed { get; private set; }
 | 
			
		||||
	public DispatcherProcessBehavior Behavior => DispatcherProcessBehavior.Queued;
 | 
			
		||||
	public string QueueName { get; }
 | 
			
		||||
	private DispatcherJob<TArgs> Job { get; set; }
 | 
			
		||||
	private IDispatcher<TArgs, TJob> Dispatcher { get; set; }
 | 
			
		||||
	public int Count => Queue.Count;
 | 
			
		||||
	private ConcurrentQueue<TArgs> Queue { get; set; }
 | 
			
		||||
 | 
			
		||||
	public void Cancel()
 | 
			
		||||
	{
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public bool Dequeue(out TArgs? item)
 | 
			
		||||
	{
 | 
			
		||||
		return Queue.TryDequeue(out item);
 | 
			
		||||
	}
 | 
			
		||||
	public bool Enqueue(TArgs item)
 | 
			
		||||
	{
 | 
			
		||||
		if (IsDisposed)
 | 
			
		||||
			return false;
 | 
			
		||||
 | 
			
		||||
		Queue.Enqueue(item);
 | 
			
		||||
 | 
			
		||||
		if (!Job.IsRunning)
 | 
			
		||||
			Job.Run(Queue, CancellationToken);
 | 
			
		||||
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void OnCompleted(object? sender, EventArgs e)
 | 
			
		||||
	{
 | 
			
		||||
		if (sender is not DispatcherJob<TArgs> job)
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		if (!Queue.IsEmpty)
 | 
			
		||||
		{
 | 
			
		||||
			job.Run(Queue, CancellationToken);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		Completed?.Invoke(this, EventArgs.Empty);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public bool Enqueue(string queue, TArgs args)
 | 
			
		||||
	{
 | 
			
		||||
		return Dispatcher.Enqueue(queue, args);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void Dispose(bool disposing)
 | 
			
		||||
	{
 | 
			
		||||
		if (!IsDisposed)
 | 
			
		||||
		{
 | 
			
		||||
			if (disposing)
 | 
			
		||||
			{
 | 
			
		||||
				if (Job is not null)
 | 
			
		||||
				{
 | 
			
		||||
					Job.Dispose();
 | 
			
		||||
					Job = null;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			IsDisposed = true;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	public void Dispose()
 | 
			
		||||
	{
 | 
			
		||||
		Dispose(true);
 | 
			
		||||
		GC.SuppressFinalize(this);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										51
									
								
								src/Connected.Collections/Connected.Collections.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								src/Connected.Collections/Connected.Collections.csproj
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,51 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
 | 
			
		||||
	<PropertyGroup>
 | 
			
		||||
		<TargetFramework>net7.0</TargetFramework>
 | 
			
		||||
		<ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
		<Nullable>enable</Nullable>
 | 
			
		||||
		<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
 | 
			
		||||
		<Title>$(AssemblyName)</Title>
 | 
			
		||||
		<Authors>Tom PIT</Authors>
 | 
			
		||||
		<Copyright>2022 Tom PIT</Copyright>
 | 
			
		||||
		<PackageProjectUrl>https://git.tompit.com/Connected/Info</PackageProjectUrl>
 | 
			
		||||
		<PackageReadmeFile>README.md</PackageReadmeFile>
 | 
			
		||||
		<PackageTags>connected;platform;</PackageTags>
 | 
			
		||||
		<IncludeSymbols>True</IncludeSymbols>
 | 
			
		||||
		<SymbolPackageFormat>snupkg</SymbolPackageFormat>
 | 
			
		||||
		<PackageLicenseFile>LICENSE</PackageLicenseFile>
 | 
			
		||||
		<PackageOutputPath>$(OutputPath)</PackageOutputPath>
 | 
			
		||||
	</PropertyGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
		<Compile Update="SR.Designer.cs">
 | 
			
		||||
			<DesignTime>True</DesignTime>
 | 
			
		||||
			<AutoGen>True</AutoGen>
 | 
			
		||||
			<DependentUpon>SR.resx</DependentUpon>
 | 
			
		||||
		</Compile>
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
		<EmbeddedResource Update="SR.resx">
 | 
			
		||||
			<Generator>ResXFileCodeGenerator</Generator>
 | 
			
		||||
			<LastGenOutput>SR.Designer.cs</LastGenOutput>
 | 
			
		||||
		</EmbeddedResource>
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
		<None Include="..\..\LICENSE">
 | 
			
		||||
			<Pack>True</Pack>
 | 
			
		||||
			<PackagePath>\</PackagePath>
 | 
			
		||||
		</None>
 | 
			
		||||
		<None Include="..\..\README.md">
 | 
			
		||||
			<Pack>True</Pack>
 | 
			
		||||
			<PackagePath>\</PackagePath>
 | 
			
		||||
		</None>
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
	  <ProjectReference Include="..\..\dependencies\Connected\src\Connected\Connected.csproj" />
 | 
			
		||||
	  <ProjectReference Include="..\Connected.Interop\Connected.Interop.csproj" />
 | 
			
		||||
	  <ProjectReference Include="..\Connected.Runtime\Connected.Runtime.csproj" />
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
</Project>
 | 
			
		||||
							
								
								
									
										33
									
								
								src/Connected.Collections/Iterator.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/Connected.Collections/Iterator.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,33 @@
 | 
			
		||||
using Connected.Collections.Iterators;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Collections;
 | 
			
		||||
 | 
			
		||||
public class Iterator
 | 
			
		||||
{
 | 
			
		||||
	private IIterator _iterator;
 | 
			
		||||
	public Iterator(object value)
 | 
			
		||||
	{
 | 
			
		||||
		if (value is null)
 | 
			
		||||
			throw new ArgumentException(nameof(value));
 | 
			
		||||
 | 
			
		||||
		if (DictionaryIterator.CanHandle(value))
 | 
			
		||||
			_iterator = new DictionaryIterator(value);
 | 
			
		||||
		else if (ListIterator.CanHandle(value))
 | 
			
		||||
			_iterator = new ListIterator(value);
 | 
			
		||||
		else if (ArrayIterator.CanHandle(value))
 | 
			
		||||
			_iterator = new ArrayIterator(value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public async Task<bool> MoveNext(Func<object, Task<object>> processor)
 | 
			
		||||
	{
 | 
			
		||||
		if (!_iterator.MoveNext())
 | 
			
		||||
			return false;
 | 
			
		||||
 | 
			
		||||
		if (await processor(_iterator.Current) is object value)
 | 
			
		||||
			_iterator.Add(value);
 | 
			
		||||
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public object? Result => _iterator.Result;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										32
									
								
								src/Connected.Collections/Iterators/ArrayIterator.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								src/Connected.Collections/Iterators/ArrayIterator.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,32 @@
 | 
			
		||||
namespace Connected.Collections.Iterators;
 | 
			
		||||
 | 
			
		||||
internal class ArrayIterator : IIterator
 | 
			
		||||
{
 | 
			
		||||
	public ArrayIterator(object value)
 | 
			
		||||
	{
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
	public object? Result => throw new NotImplementedException();
 | 
			
		||||
 | 
			
		||||
	public object Current => throw new NotImplementedException();
 | 
			
		||||
 | 
			
		||||
	public static bool CanHandle(object value)
 | 
			
		||||
	{
 | 
			
		||||
		return value.GetType().IsArray;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Add(object value)
 | 
			
		||||
	{
 | 
			
		||||
		throw new NotImplementedException();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public bool MoveNext()
 | 
			
		||||
	{
 | 
			
		||||
		throw new NotImplementedException();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Reset()
 | 
			
		||||
	{
 | 
			
		||||
		throw new NotImplementedException();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										75
									
								
								src/Connected.Collections/Iterators/DictionaryIterator.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								src/Connected.Collections/Iterators/DictionaryIterator.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,75 @@
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
using Connected.Interop;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Collections.Iterators;
 | 
			
		||||
 | 
			
		||||
internal class DictionaryIterator : IIterator
 | 
			
		||||
{
 | 
			
		||||
	private readonly object _value;
 | 
			
		||||
	private IDictionary _result;
 | 
			
		||||
	public DictionaryIterator(object value)
 | 
			
		||||
	{
 | 
			
		||||
		_value = value;
 | 
			
		||||
 | 
			
		||||
		if (value is not IDictionary dictionary)
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		Enumerator = dictionary.GetEnumerator();
 | 
			
		||||
 | 
			
		||||
		CreateResult();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static bool CanHandle(object value)
 | 
			
		||||
	{
 | 
			
		||||
		var arguments = value.GetType().GetGenericArguments();
 | 
			
		||||
		var kvp = typeof(KeyValuePair<,>).MakeGenericType(arguments);
 | 
			
		||||
		var en = typeof(IEnumerable<>).MakeGenericType(kvp);
 | 
			
		||||
 | 
			
		||||
		return value.GetType() == en;
 | 
			
		||||
	}
 | 
			
		||||
	private void CreateResult()
 | 
			
		||||
	{
 | 
			
		||||
		if (_value.GetType() == typeof(IImmutableDictionary<,>))
 | 
			
		||||
			_result = _value.GetType().MakeGenericType(_value.GetType().GenericTypeArguments).CreateInstance<IDictionary>();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private IDictionaryEnumerator? Enumerator { get; }
 | 
			
		||||
	public object? Current => Enumerator?.Value;
 | 
			
		||||
 | 
			
		||||
	public object? Result
 | 
			
		||||
	{
 | 
			
		||||
		get
 | 
			
		||||
		{
 | 
			
		||||
			if (_value is null)
 | 
			
		||||
				return null;
 | 
			
		||||
 | 
			
		||||
			throw new NotImplementedException();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public bool MoveNext()
 | 
			
		||||
	{
 | 
			
		||||
		if (Enumerator is null)
 | 
			
		||||
			return false;
 | 
			
		||||
 | 
			
		||||
		return Enumerator.MoveNext();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Reset()
 | 
			
		||||
	{
 | 
			
		||||
		if (Enumerator is null)
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		Enumerator.Reset();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	public void Add(object value)
 | 
			
		||||
	{
 | 
			
		||||
		if (Current is null || Enumerator is null)
 | 
			
		||||
			throw new InvalidOperationException(SR.ErrIteratorCurrentNull);
 | 
			
		||||
 | 
			
		||||
		_result.Add(Enumerator.Key, value);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										10
									
								
								src/Connected.Collections/Iterators/IIterator.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/Connected.Collections/Iterators/IIterator.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
			
		||||
using System.Collections;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Collections.Iterators;
 | 
			
		||||
 | 
			
		||||
internal interface IIterator : IEnumerator
 | 
			
		||||
{
 | 
			
		||||
	void Add(object value);
 | 
			
		||||
 | 
			
		||||
	object? Result { get; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										36
									
								
								src/Connected.Collections/Iterators/ListIterator.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/Connected.Collections/Iterators/ListIterator.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,36 @@
 | 
			
		||||
namespace Connected.Collections.Iterators;
 | 
			
		||||
 | 
			
		||||
internal class ListIterator : IIterator
 | 
			
		||||
{
 | 
			
		||||
	public ListIterator(object value)
 | 
			
		||||
	{
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public object? Result => throw new NotImplementedException();
 | 
			
		||||
 | 
			
		||||
	public object Current => throw new NotImplementedException();
 | 
			
		||||
 | 
			
		||||
	public static bool CanHandle(object value)
 | 
			
		||||
	{
 | 
			
		||||
		var arguments = value.GetType().GetGenericArguments();
 | 
			
		||||
		var list = typeof(IList<>).MakeGenericType(arguments);
 | 
			
		||||
 | 
			
		||||
		return value.GetType() == list;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Add(object value)
 | 
			
		||||
	{
 | 
			
		||||
		throw new NotImplementedException();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public bool MoveNext()
 | 
			
		||||
	{
 | 
			
		||||
		throw new NotImplementedException();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Reset()
 | 
			
		||||
	{
 | 
			
		||||
		throw new NotImplementedException();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										6
									
								
								src/Connected.Collections/Queues/IQueueClient.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/Connected.Collections/Queues/IQueueClient.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,6 @@
 | 
			
		||||
namespace Connected.Collections.Queues;
 | 
			
		||||
public interface IQueueClient<TArgs> : IMiddleware
 | 
			
		||||
	where TArgs : QueueArgs
 | 
			
		||||
{
 | 
			
		||||
	Task Invoke(IQueueMessage message, TArgs args);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										48
									
								
								src/Connected.Collections/Queues/IQueueMessage.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								src/Connected.Collections/Queues/IQueueMessage.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,48 @@
 | 
			
		||||
using Connected.Data;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Collections.Queues;
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// Represents a single queue message.
 | 
			
		||||
/// </summary>
 | 
			
		||||
/// <remarks>
 | 
			
		||||
/// A queue message represents a unit of queued or deferred work which
 | 
			
		||||
/// can be processed distributed anywhere or in any client which
 | 
			
		||||
/// has access to the Queue REST service.
 | 
			
		||||
/// </remarks>
 | 
			
		||||
public interface IQueueMessage : IPrimaryKey<long>, IPopReceipt
 | 
			
		||||
{
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// Date date and time the queue message was created.
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	DateTime Created { get; init; }
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// The number of times the clients dequeued the message.
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	/// <remarks>
 | 
			
		||||
	/// There are numerous reasons why queue message gets dequeued multiple
 | 
			
		||||
	/// times. It could be that not all conditions were met at the time
 | 
			
		||||
	/// of processing or that queue message was not processed quich enough and 
 | 
			
		||||
	/// its pop receipt expired. In such cases message returns to the queue and 
 | 
			
		||||
	/// waits for the next client to dequeue it.
 | 
			
		||||
	/// </remarks>
 | 
			
		||||
	int DequeueCount { get; init; }
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// The timestamp message was last dequeued.
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	DateTime? DequeueTimestamp { get; init; }
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// The queue to which the message belongs. 
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	/// <remarks>
 | 
			
		||||
	/// Every queue client must specify which queue processes.
 | 
			
		||||
	/// </remarks>
 | 
			
		||||
	string Queue { get; init; }
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// The arguments object which contains information about the message.
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	/// <remarks>
 | 
			
		||||
	/// Most queue messages do have an argument object, mostly providing na id of the
 | 
			
		||||
	/// entity or record for which processing should be performed.
 | 
			
		||||
	/// </remarks>
 | 
			
		||||
	QueueArgs Arguments { get; init; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										34
									
								
								src/Connected.Collections/Queues/IQueueService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/Connected.Collections/Queues/IQueueService.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,34 @@
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
using Connected.Annotations;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Collections.Queues;
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// Represents a distributed service for processing queue messages.
 | 
			
		||||
/// </summary>
 | 
			
		||||
/// <remarks>
 | 
			
		||||
/// Queue mechanism is mostly used as an internal logic of processes
 | 
			
		||||
/// and resources to offload work from the main thread to achieve better
 | 
			
		||||
/// responsiveness of the system. Aggregations and calculations are good
 | 
			
		||||
/// examples of queue usage. You should use queue whenever you must
 | 
			
		||||
/// perform any kind of work that is not necessary to perform it in a single
 | 
			
		||||
/// transaction scope.
 | 
			
		||||
/// </remarks>
 | 
			
		||||
[Service]
 | 
			
		||||
[ServiceUrl(CollectionRoutes.Queue)]
 | 
			
		||||
public interface IQueueService
 | 
			
		||||
{
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// Enqueues the queue message.
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	/// <typeparam name="TArgs">The type of the arguments used in queue message</typeparam>
 | 
			
		||||
	/// <param name="args">The arguments containing information about a queue message.</param>
 | 
			
		||||
	Task Enqueue<TClient, TArgs>(TArgs args)
 | 
			
		||||
		where TClient : IQueueClient<TArgs>
 | 
			
		||||
		where TArgs : QueueArgs;
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// Dequeues the queue messages based on the provided arguments.
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	/// <param name="args">The arguments containing information about dequeue criteria.</param>
 | 
			
		||||
	/// <returns>A list of valid queue messages that can be immediatelly processed.S</returns>
 | 
			
		||||
	Task<ImmutableList<IQueueMessage>> Dequeue(DequeueArgs args);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										44
									
								
								src/Connected.Collections/Queues/QueueArgs.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								src/Connected.Collections/Queues/QueueArgs.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,44 @@
 | 
			
		||||
using System.ComponentModel.DataAnnotations;
 | 
			
		||||
using Connected.Annotations;
 | 
			
		||||
using Connected.ServiceModel;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Collections.Queues;
 | 
			
		||||
 | 
			
		||||
public class QueueArgs : Dto
 | 
			
		||||
{
 | 
			
		||||
	public QueueArgs()
 | 
			
		||||
	{
 | 
			
		||||
		Options = new();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public EnqueueOptions Options { get; set; }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public class PrimaryKeyQueueArgs<TPrimaryKey> : QueueArgs
 | 
			
		||||
	where TPrimaryKey : notnull
 | 
			
		||||
{
 | 
			
		||||
	public TPrimaryKey Id { get; set; } = default!;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public sealed class EnqueueOptions
 | 
			
		||||
{
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// The date and time the queue message expires.
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	/// <remarks>
 | 
			
		||||
	/// Queue messages that are not processed until they expire
 | 
			
		||||
	/// gets automatically deleted by the system.
 | 
			
		||||
	/// </remarks>
 | 
			
		||||
	public DateTime Expire { get; set; } = DateTime.UtcNow.AddHours(48);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public sealed class DequeueArgs : Dto
 | 
			
		||||
{
 | 
			
		||||
	[NonDefault]
 | 
			
		||||
	public List<string> Queues { get; set; } = default!;
 | 
			
		||||
 | 
			
		||||
	[Range(1, int.MaxValue)]
 | 
			
		||||
	public int MaxCount { get; set; }
 | 
			
		||||
 | 
			
		||||
	public TimeSpan NextVisible { get; set; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										90
									
								
								src/Connected.Collections/SR.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								src/Connected.Collections/SR.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							@ -0,0 +1,90 @@
 | 
			
		||||
//------------------------------------------------------------------------------
 | 
			
		||||
// <auto-generated>
 | 
			
		||||
//     This code was generated by a tool.
 | 
			
		||||
//     Runtime Version:4.0.30319.42000
 | 
			
		||||
//
 | 
			
		||||
//     Changes to this file may cause incorrect behavior and will be lost if
 | 
			
		||||
//     the code is regenerated.
 | 
			
		||||
// </auto-generated>
 | 
			
		||||
//------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
namespace Connected.Collections {
 | 
			
		||||
    using System;
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    ///   A strongly-typed resource class, for looking up localized strings, etc.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    // This class was auto-generated by the StronglyTypedResourceBuilder
 | 
			
		||||
    // class via a tool like ResGen or Visual Studio.
 | 
			
		||||
    // To add or remove a member, edit your .ResX file then rerun ResGen
 | 
			
		||||
    // with the /str option, or rebuild your VS project.
 | 
			
		||||
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
 | 
			
		||||
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
 | 
			
		||||
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
 | 
			
		||||
    internal class SR {
 | 
			
		||||
        
 | 
			
		||||
        private static global::System.Resources.ResourceManager resourceMan;
 | 
			
		||||
        
 | 
			
		||||
        private static global::System.Globalization.CultureInfo resourceCulture;
 | 
			
		||||
        
 | 
			
		||||
        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
 | 
			
		||||
        internal SR() {
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   Returns the cached ResourceManager instance used by this class.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
 | 
			
		||||
        internal static global::System.Resources.ResourceManager ResourceManager {
 | 
			
		||||
            get {
 | 
			
		||||
                if (object.ReferenceEquals(resourceMan, null)) {
 | 
			
		||||
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Connected.Collections.SR", typeof(SR).Assembly);
 | 
			
		||||
                    resourceMan = temp;
 | 
			
		||||
                }
 | 
			
		||||
                return resourceMan;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   Overrides the current thread's CurrentUICulture property for all
 | 
			
		||||
        ///   resource lookups using this strongly typed resource class.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
 | 
			
		||||
        internal static global::System.Globalization.CultureInfo Culture {
 | 
			
		||||
            get {
 | 
			
		||||
                return resourceCulture;
 | 
			
		||||
            }
 | 
			
		||||
            set {
 | 
			
		||||
                resourceCulture = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   Looks up a localized string similar to Cannot create queued dispatcher.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal static string ErrCreateQueuedDispatcher {
 | 
			
		||||
            get {
 | 
			
		||||
                return ResourceManager.GetString("ErrCreateQueuedDispatcher", resourceCulture);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   Looks up a localized string similar to Cannot create service instance.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal static string ErrCreateService {
 | 
			
		||||
            get {
 | 
			
		||||
                return ResourceManager.GetString("ErrCreateService", resourceCulture);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   Looks up a localized string similar to Iterator does not have current value.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal static string ErrIteratorCurrentNull {
 | 
			
		||||
            get {
 | 
			
		||||
                return ResourceManager.GetString("ErrIteratorCurrentNull", resourceCulture);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										129
									
								
								src/Connected.Collections/SR.resx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										129
									
								
								src/Connected.Collections/SR.resx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,129 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<root>
 | 
			
		||||
  <!-- 
 | 
			
		||||
    Microsoft ResX Schema 
 | 
			
		||||
    
 | 
			
		||||
    Version 2.0
 | 
			
		||||
    
 | 
			
		||||
    The primary goals of this format is to allow a simple XML format 
 | 
			
		||||
    that is mostly human readable. The generation and parsing of the 
 | 
			
		||||
    various data types are done through the TypeConverter classes 
 | 
			
		||||
    associated with the data types.
 | 
			
		||||
    
 | 
			
		||||
    Example:
 | 
			
		||||
    
 | 
			
		||||
    ... ado.net/XML headers & schema ...
 | 
			
		||||
    <resheader name="resmimetype">text/microsoft-resx</resheader>
 | 
			
		||||
    <resheader name="version">2.0</resheader>
 | 
			
		||||
    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
 | 
			
		||||
    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
 | 
			
		||||
    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
 | 
			
		||||
    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
 | 
			
		||||
    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
 | 
			
		||||
        <value>[base64 mime encoded serialized .NET Framework object]</value>
 | 
			
		||||
    </data>
 | 
			
		||||
    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
 | 
			
		||||
        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
 | 
			
		||||
        <comment>This is a comment</comment>
 | 
			
		||||
    </data>
 | 
			
		||||
                
 | 
			
		||||
    There are any number of "resheader" rows that contain simple 
 | 
			
		||||
    name/value pairs.
 | 
			
		||||
    
 | 
			
		||||
    Each data row contains a name, and value. The row also contains a 
 | 
			
		||||
    type or mimetype. Type corresponds to a .NET class that support 
 | 
			
		||||
    text/value conversion through the TypeConverter architecture. 
 | 
			
		||||
    Classes that don't support this are serialized and stored with the 
 | 
			
		||||
    mimetype set.
 | 
			
		||||
    
 | 
			
		||||
    The mimetype is used for serialized objects, and tells the 
 | 
			
		||||
    ResXResourceReader how to depersist the object. This is currently not 
 | 
			
		||||
    extensible. For a given mimetype the value must be set accordingly:
 | 
			
		||||
    
 | 
			
		||||
    Note - application/x-microsoft.net.object.binary.base64 is the format 
 | 
			
		||||
    that the ResXResourceWriter will generate, however the reader can 
 | 
			
		||||
    read any of the formats listed below.
 | 
			
		||||
    
 | 
			
		||||
    mimetype: application/x-microsoft.net.object.binary.base64
 | 
			
		||||
    value   : The object must be serialized with 
 | 
			
		||||
            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
 | 
			
		||||
            : and then encoded with base64 encoding.
 | 
			
		||||
    
 | 
			
		||||
    mimetype: application/x-microsoft.net.object.soap.base64
 | 
			
		||||
    value   : The object must be serialized with 
 | 
			
		||||
            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
 | 
			
		||||
            : and then encoded with base64 encoding.
 | 
			
		||||
 | 
			
		||||
    mimetype: application/x-microsoft.net.object.bytearray.base64
 | 
			
		||||
    value   : The object must be serialized into a byte array 
 | 
			
		||||
            : using a System.ComponentModel.TypeConverter
 | 
			
		||||
            : and then encoded with base64 encoding.
 | 
			
		||||
    -->
 | 
			
		||||
  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
 | 
			
		||||
    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
 | 
			
		||||
    <xsd:element name="root" msdata:IsDataSet="true">
 | 
			
		||||
      <xsd:complexType>
 | 
			
		||||
        <xsd:choice maxOccurs="unbounded">
 | 
			
		||||
          <xsd:element name="metadata">
 | 
			
		||||
            <xsd:complexType>
 | 
			
		||||
              <xsd:sequence>
 | 
			
		||||
                <xsd:element name="value" type="xsd:string" minOccurs="0" />
 | 
			
		||||
              </xsd:sequence>
 | 
			
		||||
              <xsd:attribute name="name" use="required" type="xsd:string" />
 | 
			
		||||
              <xsd:attribute name="type" type="xsd:string" />
 | 
			
		||||
              <xsd:attribute name="mimetype" type="xsd:string" />
 | 
			
		||||
              <xsd:attribute ref="xml:space" />
 | 
			
		||||
            </xsd:complexType>
 | 
			
		||||
          </xsd:element>
 | 
			
		||||
          <xsd:element name="assembly">
 | 
			
		||||
            <xsd:complexType>
 | 
			
		||||
              <xsd:attribute name="alias" type="xsd:string" />
 | 
			
		||||
              <xsd:attribute name="name" type="xsd:string" />
 | 
			
		||||
            </xsd:complexType>
 | 
			
		||||
          </xsd:element>
 | 
			
		||||
          <xsd:element name="data">
 | 
			
		||||
            <xsd:complexType>
 | 
			
		||||
              <xsd:sequence>
 | 
			
		||||
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
 | 
			
		||||
                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
 | 
			
		||||
              </xsd:sequence>
 | 
			
		||||
              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
 | 
			
		||||
              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
 | 
			
		||||
              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
 | 
			
		||||
              <xsd:attribute ref="xml:space" />
 | 
			
		||||
            </xsd:complexType>
 | 
			
		||||
          </xsd:element>
 | 
			
		||||
          <xsd:element name="resheader">
 | 
			
		||||
            <xsd:complexType>
 | 
			
		||||
              <xsd:sequence>
 | 
			
		||||
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
 | 
			
		||||
              </xsd:sequence>
 | 
			
		||||
              <xsd:attribute name="name" type="xsd:string" use="required" />
 | 
			
		||||
            </xsd:complexType>
 | 
			
		||||
          </xsd:element>
 | 
			
		||||
        </xsd:choice>
 | 
			
		||||
      </xsd:complexType>
 | 
			
		||||
    </xsd:element>
 | 
			
		||||
  </xsd:schema>
 | 
			
		||||
  <resheader name="resmimetype">
 | 
			
		||||
    <value>text/microsoft-resx</value>
 | 
			
		||||
  </resheader>
 | 
			
		||||
  <resheader name="version">
 | 
			
		||||
    <value>2.0</value>
 | 
			
		||||
  </resheader>
 | 
			
		||||
  <resheader name="reader">
 | 
			
		||||
    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
 | 
			
		||||
  </resheader>
 | 
			
		||||
  <resheader name="writer">
 | 
			
		||||
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
 | 
			
		||||
  </resheader>
 | 
			
		||||
  <data name="ErrCreateQueuedDispatcher" xml:space="preserve">
 | 
			
		||||
    <value>Cannot create queued dispatcher</value>
 | 
			
		||||
  </data>
 | 
			
		||||
  <data name="ErrCreateService" xml:space="preserve">
 | 
			
		||||
    <value>Cannot create service instance</value>
 | 
			
		||||
  </data>
 | 
			
		||||
  <data name="ErrIteratorCurrentNull" xml:space="preserve">
 | 
			
		||||
    <value>Iterator does not have current value</value>
 | 
			
		||||
  </data>
 | 
			
		||||
</root>
 | 
			
		||||
@ -0,0 +1,11 @@
 | 
			
		||||
namespace Connected.Configuration.Authentication;
 | 
			
		||||
 | 
			
		||||
internal class AuthenticationConfiguration : IAuthenticationConfiguration
 | 
			
		||||
{
 | 
			
		||||
	public AuthenticationConfiguration()
 | 
			
		||||
	{
 | 
			
		||||
		JwToken = new JwTokenConfiguration();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public IJwTokenConfiguration JwToken { get; }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,6 @@
 | 
			
		||||
namespace Connected.Configuration.Authentication;
 | 
			
		||||
 | 
			
		||||
public interface IAuthenticationConfiguration
 | 
			
		||||
{
 | 
			
		||||
	IJwTokenConfiguration JwToken { get; }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,10 @@
 | 
			
		||||
namespace Connected.Configuration.Authentication
 | 
			
		||||
{
 | 
			
		||||
	public interface IJwTokenConfiguration
 | 
			
		||||
	{
 | 
			
		||||
		string Issuer { get; }
 | 
			
		||||
		string Audience { get; }
 | 
			
		||||
		string Key { get; }
 | 
			
		||||
		int Duration { get; }
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,13 @@
 | 
			
		||||
namespace Connected.Configuration.Authentication
 | 
			
		||||
{
 | 
			
		||||
	internal class JwTokenConfiguration : IJwTokenConfiguration
 | 
			
		||||
	{
 | 
			
		||||
		public string? Issuer { get; set; }
 | 
			
		||||
 | 
			
		||||
		public string? Audience { get; set; }
 | 
			
		||||
 | 
			
		||||
		public string? Key { get; set; } = "D78RF30487F4G0F8Z34F834F";
 | 
			
		||||
 | 
			
		||||
		public int Duration { get; set; } = 30;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										25
									
								
								src/Connected.Configuration/ConfigurationService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/Connected.Configuration/ConfigurationService.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,25 @@
 | 
			
		||||
using Connected.Configuration.Authentication;
 | 
			
		||||
using Connected.Configuration.Endpoints;
 | 
			
		||||
using Microsoft.Extensions.Configuration;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Configuration;
 | 
			
		||||
 | 
			
		||||
internal class ConfigurationService : IConfigurationService
 | 
			
		||||
{
 | 
			
		||||
	public ConfigurationService(IConfiguration configuration)
 | 
			
		||||
	{
 | 
			
		||||
		Endpoint = new EndpointConfiguration(configuration.GetSection("endpoint"));
 | 
			
		||||
		
 | 
			
		||||
		Storage = new StorageConfiguration(configuration.GetSection("storage"));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public IEndpointConfiguration Endpoint { get; }
 | 
			
		||||
 | 
			
		||||
	public IAuthenticationConfiguration Authentication => throw new NotImplementedException();
 | 
			
		||||
	public IStorageConfiguration Storage { get; }
 | 
			
		||||
 | 
			
		||||
	/*
 | 
			
		||||
	 * TODO: hardcoded
 | 
			
		||||
	 */
 | 
			
		||||
	public ProcessType Type => ProcessType.BackEnd;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										16
									
								
								src/Connected.Configuration/ConfigurationStart.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/Connected.Configuration/ConfigurationStart.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
			
		||||
using Connected.Annotations;
 | 
			
		||||
using Connected.Configuration.Environment;
 | 
			
		||||
using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
 | 
			
		||||
[assembly: MicroService(MicroServiceType.Sys)]
 | 
			
		||||
 | 
			
		||||
namespace Connected.Configuration;
 | 
			
		||||
 | 
			
		||||
internal class ConfigurationStart : Startup
 | 
			
		||||
{
 | 
			
		||||
	protected override void OnConfigureServices(IServiceCollection services)
 | 
			
		||||
	{
 | 
			
		||||
		services.AddSingleton(typeof(IConfigurationService), typeof(ConfigurationService));
 | 
			
		||||
		services.AddSingleton(typeof(IEnvironmentService), typeof(EnvironmentService));
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										7
									
								
								src/Connected.Configuration/ConfigurationUrls.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/Connected.Configuration/ConfigurationUrls.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
			
		||||
namespace Connected.Configuration
 | 
			
		||||
{
 | 
			
		||||
	public static class ConfigurationUrls
 | 
			
		||||
	{
 | 
			
		||||
		public const string Settings = "/configuration/settings";
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										34
									
								
								src/Connected.Configuration/Connected.Configuration.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/Connected.Configuration/Connected.Configuration.csproj
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,34 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
 | 
			
		||||
	<PropertyGroup>
 | 
			
		||||
		<TargetFramework>net7.0</TargetFramework>
 | 
			
		||||
		<ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
		<Nullable>enable</Nullable>
 | 
			
		||||
		<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
 | 
			
		||||
		<Title>$(AssemblyName)</Title>
 | 
			
		||||
		<Authors>Tom PIT</Authors>
 | 
			
		||||
		<Copyright>2022 Tom PIT</Copyright>
 | 
			
		||||
		<PackageProjectUrl>https://git.tompit.com/Connected/Info</PackageProjectUrl>
 | 
			
		||||
		<PackageReadmeFile>README.md</PackageReadmeFile>
 | 
			
		||||
		<PackageTags>connected;platform;</PackageTags>
 | 
			
		||||
		<IncludeSymbols>True</IncludeSymbols>
 | 
			
		||||
		<SymbolPackageFormat>snupkg</SymbolPackageFormat>
 | 
			
		||||
		<PackageLicenseFile>LICENSE</PackageLicenseFile>
 | 
			
		||||
		<PackageOutputPath>$(OutputPath)</PackageOutputPath>
 | 
			
		||||
	</PropertyGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
		<None Include="..\..\LICENSE">
 | 
			
		||||
			<Pack>True</Pack>
 | 
			
		||||
			<PackagePath>\</PackagePath>
 | 
			
		||||
		</None>
 | 
			
		||||
		<None Include="..\..\README.md">
 | 
			
		||||
			<Pack>True</Pack>
 | 
			
		||||
			<PackagePath>\</PackagePath>
 | 
			
		||||
		</None>
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
	  <ProjectReference Include="..\Connected.Runtime\Connected.Runtime.csproj" />
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
</Project>
 | 
			
		||||
							
								
								
									
										22
									
								
								src/Connected.Configuration/DatabaseConfiguration.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/Connected.Configuration/DatabaseConfiguration.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,22 @@
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
using Microsoft.Extensions.Configuration;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Configuration
 | 
			
		||||
{
 | 
			
		||||
	internal class DatabaseConfiguration : IDatabaseConfiguration
 | 
			
		||||
	{
 | 
			
		||||
		private readonly List<string> _shards;
 | 
			
		||||
 | 
			
		||||
		public DatabaseConfiguration(IConfiguration configuration)
 | 
			
		||||
		{
 | 
			
		||||
			DefaultConnectionString = "";
 | 
			
		||||
			_shards = new();
 | 
			
		||||
			configuration.Bind(this);
 | 
			
		||||
			configuration.Bind("shards", _shards);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public string? DefaultConnectionString { get; init; }
 | 
			
		||||
 | 
			
		||||
		public ImmutableList<string> Shards => _shards.ToImmutableList();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,14 @@
 | 
			
		||||
using Microsoft.Extensions.Configuration;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Configuration.Endpoints
 | 
			
		||||
{
 | 
			
		||||
	internal sealed class EndpointConfiguration : IEndpointConfiguration
 | 
			
		||||
	{
 | 
			
		||||
		public EndpointConfiguration(IConfiguration configuration) 
 | 
			
		||||
		{
 | 
			
		||||
			configuration.Bind(this);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public string? Address { get; set; }
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,7 @@
 | 
			
		||||
namespace Connected.Configuration.Endpoints
 | 
			
		||||
{
 | 
			
		||||
	public interface IEndpointConfiguration
 | 
			
		||||
	{
 | 
			
		||||
		string Address { get; }
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,33 @@
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using Connected.Annotations;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Configuration.Environment;
 | 
			
		||||
 | 
			
		||||
internal class EnvironmentService : IEnvironmentService
 | 
			
		||||
{
 | 
			
		||||
	private List<Assembly>? _assemblies;
 | 
			
		||||
	public List<Assembly> All => _assemblies ??= QueryAssemblies();
 | 
			
		||||
 | 
			
		||||
	public EnvironmentService()
 | 
			
		||||
	{
 | 
			
		||||
		Services = new EnvironmentServices();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public ImmutableList<Assembly> MicroServices => All.ToImmutableList();
 | 
			
		||||
 | 
			
		||||
	public IEnvironmentServices Services { get; }
 | 
			
		||||
 | 
			
		||||
	private static List<Assembly> QueryAssemblies()
 | 
			
		||||
	{
 | 
			
		||||
		var result = new List<Assembly>();
 | 
			
		||||
 | 
			
		||||
		foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
 | 
			
		||||
		{
 | 
			
		||||
			if (assembly.GetCustomAttribute<MicroServiceAttribute>() is not null)
 | 
			
		||||
				result.Add(assembly);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return result;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,17 @@
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Configuration.Environment
 | 
			
		||||
{
 | 
			
		||||
	internal class EnvironmentServices : IEnvironmentServices
 | 
			
		||||
	{
 | 
			
		||||
		public ImmutableList<Type> Services => RegisteredServices.Services;
 | 
			
		||||
 | 
			
		||||
		public ImmutableList<Type> ServiceMethods => RegisteredServices.ServiceOperations;
 | 
			
		||||
 | 
			
		||||
		public ImmutableList<Type> Arguments => RegisteredServices.Arguments;
 | 
			
		||||
 | 
			
		||||
		public ImmutableList<Type> IoCEndpoints => RegisteredServices.Middleware;
 | 
			
		||||
 | 
			
		||||
		public ImmutableList<Type> EntityCache => RegisteredServices.EntityCache;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,12 @@
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Configuration.Environment
 | 
			
		||||
{
 | 
			
		||||
	public interface IEnvironmentService
 | 
			
		||||
	{
 | 
			
		||||
		ImmutableList<Assembly> MicroServices { get; }
 | 
			
		||||
 | 
			
		||||
		IEnvironmentServices Services { get; }
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,13 @@
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Configuration.Environment
 | 
			
		||||
{
 | 
			
		||||
	public interface IEnvironmentServices
 | 
			
		||||
	{
 | 
			
		||||
		ImmutableList<Type> Services { get; }
 | 
			
		||||
		ImmutableList<Type> ServiceMethods { get; }
 | 
			
		||||
		ImmutableList<Type> Arguments { get; }
 | 
			
		||||
		ImmutableList<Type> IoCEndpoints { get; }
 | 
			
		||||
		ImmutableList<Type> EntityCache { get; }
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										21
									
								
								src/Connected.Configuration/IConfigurationService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/Connected.Configuration/IConfigurationService.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,21 @@
 | 
			
		||||
using Connected.Configuration.Authentication;
 | 
			
		||||
using Connected.Configuration.Endpoints;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Configuration;
 | 
			
		||||
 | 
			
		||||
public enum ProcessType
 | 
			
		||||
{
 | 
			
		||||
	FrontEnd = 1,
 | 
			
		||||
	BackEnd = 2,
 | 
			
		||||
	Service = 3
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public interface IConfigurationService
 | 
			
		||||
{
 | 
			
		||||
	IEndpointConfiguration Endpoint { get; }
 | 
			
		||||
 | 
			
		||||
	IAuthenticationConfiguration Authentication { get; }
 | 
			
		||||
	IStorageConfiguration Storage { get; }
 | 
			
		||||
 | 
			
		||||
	ProcessType Type { get; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								src/Connected.Configuration/IDatabaseConfiguration.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/Connected.Configuration/IDatabaseConfiguration.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Configuration
 | 
			
		||||
{
 | 
			
		||||
	public interface IDatabaseConfiguration
 | 
			
		||||
	{
 | 
			
		||||
		string? DefaultConnectionString { get; }
 | 
			
		||||
 | 
			
		||||
		ImmutableList<string> Shards { get; }
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										7
									
								
								src/Connected.Configuration/IStorageConfiguration.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/Connected.Configuration/IStorageConfiguration.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
			
		||||
namespace Connected.Configuration
 | 
			
		||||
{
 | 
			
		||||
	public interface IStorageConfiguration
 | 
			
		||||
	{
 | 
			
		||||
		IDatabaseConfiguration Databases { get; }
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										56
									
								
								src/Connected.Configuration/RegisteredServices.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								src/Connected.Configuration/RegisteredServices.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,56 @@
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Configuration
 | 
			
		||||
{
 | 
			
		||||
	public static class RegisteredServices
 | 
			
		||||
	{
 | 
			
		||||
		private static readonly List<Type> _services;
 | 
			
		||||
		private static readonly List<Type> _serviceOperations;
 | 
			
		||||
		private static readonly List<Type> _arguments;
 | 
			
		||||
		private static readonly List<Type> _middleware;
 | 
			
		||||
		private static readonly List<Type> _entityCache;
 | 
			
		||||
 | 
			
		||||
		static RegisteredServices()
 | 
			
		||||
		{
 | 
			
		||||
			_services = new List<Type>();
 | 
			
		||||
			_serviceOperations = new List<Type>();
 | 
			
		||||
			_arguments = new List<Type>();
 | 
			
		||||
			_middleware = new List<Type>();
 | 
			
		||||
			_entityCache = new List<Type>();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public static ImmutableList<Type> Services => _services.ToImmutableList();
 | 
			
		||||
 | 
			
		||||
		public static ImmutableList<Type> ServiceOperations => _serviceOperations.ToImmutableList();
 | 
			
		||||
 | 
			
		||||
		public static ImmutableList<Type> Arguments => _arguments.ToImmutableList();
 | 
			
		||||
		public static ImmutableList<Type> Middleware => _middleware.ToImmutableList();
 | 
			
		||||
 | 
			
		||||
		public static ImmutableList<Type> EntityCache => _entityCache.ToImmutableList();
 | 
			
		||||
 | 
			
		||||
		public static void AddApiService(Type type)
 | 
			
		||||
		{
 | 
			
		||||
			_services.Add(type);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public static void AddApi(Type type)
 | 
			
		||||
		{
 | 
			
		||||
			_serviceOperations.Add(type);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public static void AddArgument(Type type)
 | 
			
		||||
		{
 | 
			
		||||
			_arguments.Add(type);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public static void AddMiddleware(Type type)
 | 
			
		||||
		{
 | 
			
		||||
			_middleware.Add(type);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public static void AddEntityCache(Type type)
 | 
			
		||||
		{
 | 
			
		||||
			_entityCache.Add(type);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								src/Connected.Configuration/Settings/ISetting.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/Connected.Configuration/Settings/ISetting.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
using Connected.Data;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Configuration.Settings;
 | 
			
		||||
 | 
			
		||||
public interface ISetting : IPrimaryKey<int>
 | 
			
		||||
{
 | 
			
		||||
	string Name { get; init; }
 | 
			
		||||
	string Value { get; init; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										25
									
								
								src/Connected.Configuration/Settings/ISettingsService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/Connected.Configuration/Settings/ISettingsService.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,25 @@
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
using Connected.Annotations;
 | 
			
		||||
using Connected.ServiceModel;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Configuration.Settings;
 | 
			
		||||
 | 
			
		||||
[Service]
 | 
			
		||||
[ServiceUrl(ConfigurationUrls.Settings)]
 | 
			
		||||
public interface ISettingsService
 | 
			
		||||
{
 | 
			
		||||
	[ServiceMethod(ServiceMethodVerbs.Get | ServiceMethodVerbs.Post)]
 | 
			
		||||
	Task<ISetting?> Select(PrimaryKeyArgs<int> args);
 | 
			
		||||
 | 
			
		||||
	[ServiceMethod(ServiceMethodVerbs.Get | ServiceMethodVerbs.Post)]
 | 
			
		||||
	Task<ISetting?> Select(NameArgs args);
 | 
			
		||||
 | 
			
		||||
	[ServiceMethod(ServiceMethodVerbs.Get)]
 | 
			
		||||
	Task<ImmutableList<ISetting>> Query();
 | 
			
		||||
 | 
			
		||||
	[ServiceMethod(ServiceMethodVerbs.Post | ServiceMethodVerbs.Patch)]
 | 
			
		||||
	Task Update(SettingsArgs args);
 | 
			
		||||
 | 
			
		||||
	[ServiceMethod(ServiceMethodVerbs.Post | ServiceMethodVerbs.Delete)]
 | 
			
		||||
	Task Delete(PrimaryKeyArgs<int> args);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										14
									
								
								src/Connected.Configuration/Settings/SettingsArgs.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/Connected.Configuration/Settings/SettingsArgs.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
			
		||||
using System.ComponentModel.DataAnnotations;
 | 
			
		||||
using Connected.ServiceModel;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Configuration.Settings;
 | 
			
		||||
 | 
			
		||||
public class SettingsArgs : Dto
 | 
			
		||||
{
 | 
			
		||||
	[Required]
 | 
			
		||||
	[MaxLength(128)]
 | 
			
		||||
	public string? Name { get; set; }
 | 
			
		||||
 | 
			
		||||
	[MaxLength(1024)]
 | 
			
		||||
	public string? Value { get; set; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										14
									
								
								src/Connected.Configuration/StorageConfiguration.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/Connected.Configuration/StorageConfiguration.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
			
		||||
using Microsoft.Extensions.Configuration;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Configuration
 | 
			
		||||
{
 | 
			
		||||
	internal class StorageConfiguration : IStorageConfiguration
 | 
			
		||||
	{
 | 
			
		||||
		public StorageConfiguration(IConfiguration configuration)
 | 
			
		||||
		{
 | 
			
		||||
			Databases = new DatabaseConfiguration(configuration.GetSection("databases"));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public IDatabaseConfiguration Databases { get; }
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										28
									
								
								src/Connected.Data.Tests/Connected.Data.Tests.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/Connected.Data.Tests/Connected.Data.Tests.csproj
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,28 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <TargetFramework>net7.0</TargetFramework>
 | 
			
		||||
    <ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
    <Nullable>enable</Nullable>
 | 
			
		||||
 | 
			
		||||
    <IsPackable>false</IsPackable>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
 | 
			
		||||
    <PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
 | 
			
		||||
    <PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
 | 
			
		||||
    <PackageReference Include="coverlet.collector" Version="3.1.2" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <Folder Include="Storage\" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <ProjectReference Include="..\Connected.Data\Connected.Data.csproj" />
 | 
			
		||||
    <ProjectReference Include="..\Connected.Entities\Connected.Entities.csproj" />
 | 
			
		||||
    <ProjectReference Include="..\Connected.Expressions\Connected.Expressions.csproj" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
</Project>
 | 
			
		||||
							
								
								
									
										134
									
								
								src/Connected.Data.Tests/Translation/TranslatorTests.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										134
									
								
								src/Connected.Data.Tests/Translation/TranslatorTests.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,134 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Connected.Expressions;
 | 
			
		||||
using Connected.Data.Sql;
 | 
			
		||||
using Connected.Expressions.Translation;
 | 
			
		||||
using System.Linq.Expressions;
 | 
			
		||||
using Connected.Data.Storage;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using Connected.Entities;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Data.Tests.Translation;
 | 
			
		||||
 | 
			
		||||
[TestClass]
 | 
			
		||||
public class TranslatorTests
 | 
			
		||||
{
 | 
			
		||||
	[TestMethod]
 | 
			
		||||
	public void Translator_GeneratesBasicSelectExpression_UsingTSQL()
 | 
			
		||||
	{
 | 
			
		||||
		var context = new ExpressionCompilationContext(new TSqlLanguage());
 | 
			
		||||
 | 
			
		||||
		var translator = new Translator(context);
 | 
			
		||||
 | 
			
		||||
		var data = SampleData.All();
 | 
			
		||||
 | 
			
		||||
		var dataQueryable = data.AsQueryable();
 | 
			
		||||
 | 
			
		||||
		var query = (from x in dataQueryable select x);
 | 
			
		||||
 | 
			
		||||
		var operatorMethodInfo = QueryableMethods.SingleOrDefaultWithoutPredicate;
 | 
			
		||||
 | 
			
		||||
		if (operatorMethodInfo.IsGenericMethod)
 | 
			
		||||
		{
 | 
			
		||||
			operatorMethodInfo = operatorMethodInfo.GetGenericArguments().Length == 2
 | 
			
		||||
					  ? operatorMethodInfo.MakeGenericMethod(typeof(DummyEntity), typeof(DummyEntity).GetGenericArguments().Single())
 | 
			
		||||
					  : operatorMethodInfo.MakeGenericMethod(typeof(DummyEntity));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		var expr = Expression.Call(instance: null, method: operatorMethodInfo, arguments: new[] { query.Expression });
 | 
			
		||||
 | 
			
		||||
		var result = translator.Translate(expr) as ProjectionExpression;
 | 
			
		||||
 | 
			
		||||
		var select = result.Select;
 | 
			
		||||
 | 
			
		||||
		Assert.IsInstanceOfType(select, typeof(SelectExpression));
 | 
			
		||||
		Assert.IsInstanceOfType(select.From, typeof(TableExpression));
 | 
			
		||||
		Assert.IsNull(select.Where, "Where should be null");
 | 
			
		||||
		Assert.IsNull(select.Take, "Take should be null");
 | 
			
		||||
		Assert.IsNull(select.Skip, "Skip should be null");
 | 
			
		||||
		Assert.AreEqual(0, select.GroupBy.Count);
 | 
			
		||||
		Assert.IsFalse(select.IsReverse);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	[TestMethod]
 | 
			
		||||
	public void Translator_GeneratesSelectExpression_WithWhere_UsingTSQL()
 | 
			
		||||
	{
 | 
			
		||||
		var context = new ExpressionCompilationContext(new TSqlLanguage());
 | 
			
		||||
 | 
			
		||||
		var translator = new Translator(context);
 | 
			
		||||
 | 
			
		||||
		var data = SampleData.All();
 | 
			
		||||
 | 
			
		||||
		var dataQueryable = data.AsQueryable();
 | 
			
		||||
 | 
			
		||||
		var query = (from x in dataQueryable where x.Id == 1 select x);
 | 
			
		||||
 | 
			
		||||
		var operatorMethodInfo = QueryableMethods.SingleOrDefaultWithoutPredicate;
 | 
			
		||||
 | 
			
		||||
		if (operatorMethodInfo.IsGenericMethod)
 | 
			
		||||
		{
 | 
			
		||||
			operatorMethodInfo = operatorMethodInfo.GetGenericArguments().Length == 2
 | 
			
		||||
					  ? operatorMethodInfo.MakeGenericMethod(typeof(DummyEntity), typeof(DummyEntity).GetGenericArguments().Single())
 | 
			
		||||
					  : operatorMethodInfo.MakeGenericMethod(typeof(DummyEntity));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		var expr = Expression.Call(instance: null, method: operatorMethodInfo, arguments: new[] { query.Expression });
 | 
			
		||||
 | 
			
		||||
		var result = translator.Translate(expr) as ProjectionExpression;
 | 
			
		||||
 | 
			
		||||
		var select = result.Select;
 | 
			
		||||
 | 
			
		||||
		Assert.IsInstanceOfType(select, typeof(SelectExpression));
 | 
			
		||||
		Assert.IsInstanceOfType(select.From, typeof(TableExpression));
 | 
			
		||||
		Assert.IsNotNull(select.Where, "Where should not be null");
 | 
			
		||||
		Assert.IsNull(select.Take, "Take should be null");
 | 
			
		||||
		Assert.IsNull(select.Skip, "Skip should be null");
 | 
			
		||||
		Assert.AreEqual(0, select.GroupBy.Count);
 | 
			
		||||
		Assert.IsFalse(select.IsReverse);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public record DummyEntity : Entity<long>;
 | 
			
		||||
 | 
			
		||||
internal static class SampleData 
 | 
			
		||||
{
 | 
			
		||||
	public static List<DummyEntity> All() 
 | 
			
		||||
	{
 | 
			
		||||
		return new List<DummyEntity> 
 | 
			
		||||
		{
 | 
			
		||||
			new DummyEntity{ Id = 1},
 | 
			
		||||
			new DummyEntity{ Id = 2},
 | 
			
		||||
			new DummyEntity{ Id = 3},
 | 
			
		||||
			new DummyEntity{ Id = 4},
 | 
			
		||||
			new DummyEntity{ Id = 5}
 | 
			
		||||
		};
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
internal static class QueryableMethods
 | 
			
		||||
{
 | 
			
		||||
	static QueryableMethods()
 | 
			
		||||
	{
 | 
			
		||||
		var queryableMethodGroups = typeof(Queryable)
 | 
			
		||||
			.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)
 | 
			
		||||
			.GroupBy(mi => mi.Name)
 | 
			
		||||
			.ToDictionary(e => e.Key, l => l.ToList());
 | 
			
		||||
 | 
			
		||||
		SingleWithoutPredicate = GetMethod(nameof(Queryable.Single), 1, types => new[] { typeof(IQueryable<>).MakeGenericType(types[0]) });
 | 
			
		||||
		SingleOrDefaultWithoutPredicate = GetMethod(nameof(Queryable.SingleOrDefault), 1, types => new[] { typeof(IQueryable<>).MakeGenericType(types[0]) });
 | 
			
		||||
 | 
			
		||||
		MethodInfo GetMethod(string name, int genericParameterCount, Func<Type[], Type[]> parameterGenerator)
 | 
			
		||||
		{
 | 
			
		||||
			return queryableMethodGroups[name].Single(mi => ((genericParameterCount == 0 && !mi.IsGenericMethod)
 | 
			
		||||
							|| (mi.IsGenericMethod && mi.GetGenericArguments().Length == genericParameterCount))
 | 
			
		||||
							&& mi.GetParameters().Select(e => e.ParameterType).SequenceEqual(parameterGenerator(mi.IsGenericMethod ? mi.GetGenericArguments() : Array.Empty<Type>())));
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static MethodInfo SingleWithoutPredicate { get; }
 | 
			
		||||
	public static MethodInfo SingleOrDefaultWithoutPredicate { get; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1
									
								
								src/Connected.Data.Tests/Usings.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								src/Connected.Data.Tests/Usings.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
			
		||||
global using Microsoft.VisualStudio.TestTools.UnitTesting;
 | 
			
		||||
							
								
								
									
										15
									
								
								src/Connected.Data/Annotations/ColumnAttribute.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/Connected.Data/Annotations/ColumnAttribute.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
			
		||||
using Connected.Entities.Annotations;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Data.Annotations;
 | 
			
		||||
 | 
			
		||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
 | 
			
		||||
internal sealed class ColumnAttribute : MemberAttribute
 | 
			
		||||
{
 | 
			
		||||
	public string? Name { get; set; }
 | 
			
		||||
	public string? TableId { get; set; }
 | 
			
		||||
	public string? DbType { get; set; }
 | 
			
		||||
	public bool IsComputed { get; set; }
 | 
			
		||||
	public bool IsPrimaryKey { get; set; }
 | 
			
		||||
	public bool IsGenerated { get; set; }
 | 
			
		||||
	public bool IsReadOnly { get; set; }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,8 @@
 | 
			
		||||
namespace Connected.Data.Annotations
 | 
			
		||||
{
 | 
			
		||||
   [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
 | 
			
		||||
   internal class MemberExtensionAttribute : Attribute
 | 
			
		||||
   {
 | 
			
		||||
      public string TableId { get; set; }
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								src/Connected.Data/Annotations/NestedEntityAttribute.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/Connected.Data/Annotations/NestedEntityAttribute.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
using Connected.Entities.Annotations;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Data.Annotations;
 | 
			
		||||
 | 
			
		||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
 | 
			
		||||
internal class NestedEntityAttribute : MemberAttribute
 | 
			
		||||
{
 | 
			
		||||
	public Type? RuntimeType { get; set; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										59
									
								
								src/Connected.Data/Connected.Data.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								src/Connected.Data/Connected.Data.csproj
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,59 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
 | 
			
		||||
	<PropertyGroup>
 | 
			
		||||
		<TargetFramework>net7.0</TargetFramework>
 | 
			
		||||
		<ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
		<Nullable>enable</Nullable>
 | 
			
		||||
		<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
 | 
			
		||||
		<Title>$(AssemblyName)</Title>
 | 
			
		||||
		<Authors>Tom PIT</Authors>
 | 
			
		||||
		<Copyright>2022 Tom PIT</Copyright>
 | 
			
		||||
		<PackageProjectUrl>https://git.tompit.com/Connected/Info</PackageProjectUrl>
 | 
			
		||||
		<PackageReadmeFile>README.md</PackageReadmeFile>
 | 
			
		||||
		<PackageTags>connected;platform;</PackageTags>
 | 
			
		||||
		<IncludeSymbols>True</IncludeSymbols>
 | 
			
		||||
		<SymbolPackageFormat>snupkg</SymbolPackageFormat>
 | 
			
		||||
		<PackageLicenseFile>LICENSE</PackageLicenseFile>
 | 
			
		||||
		<PackageOutputPath>$(OutputPath)</PackageOutputPath>
 | 
			
		||||
	</PropertyGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
		<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.*-*" />
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
		<Compile Update="SR.Designer.cs">
 | 
			
		||||
			<DesignTime>True</DesignTime>
 | 
			
		||||
			<AutoGen>True</AutoGen>
 | 
			
		||||
			<DependentUpon>SR.resx</DependentUpon>
 | 
			
		||||
		</Compile>
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
		<EmbeddedResource Update="SR.resx">
 | 
			
		||||
			<Generator>ResXFileCodeGenerator</Generator>
 | 
			
		||||
			<LastGenOutput>SR.Designer.cs</LastGenOutput>
 | 
			
		||||
		</EmbeddedResource>
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
		<None Include="..\..\LICENSE">
 | 
			
		||||
			<Pack>True</Pack>
 | 
			
		||||
			<PackagePath>\</PackagePath>
 | 
			
		||||
		</None>
 | 
			
		||||
		<None Include="..\..\README.md">
 | 
			
		||||
			<Pack>True</Pack>
 | 
			
		||||
			<PackagePath>\</PackagePath>
 | 
			
		||||
		</None>
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
	  <ProjectReference Include="..\Connected.Caching\Connected.Caching.csproj" />
 | 
			
		||||
	  <ProjectReference Include="..\Connected.Entities\Connected.Entities.csproj" />
 | 
			
		||||
	  <ProjectReference Include="..\Connected.Expressions\Connected.Expressions.csproj" />
 | 
			
		||||
	  <ProjectReference Include="..\Connected.Globalization\Connected.Globalization.csproj" />
 | 
			
		||||
	  <ProjectReference Include="..\Connected.Interop\Connected.Interop.csproj" />
 | 
			
		||||
	  <ProjectReference Include="..\Connected.Threading\Connected.Threading.csproj" />
 | 
			
		||||
	  <ProjectReference Include="..\Connected.Validation\Connected.Validation.csproj" />
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
</Project>
 | 
			
		||||
							
								
								
									
										100
									
								
								src/Connected.Data/DataExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										100
									
								
								src/Connected.Data/DataExtensions.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,100 @@
 | 
			
		||||
using Connected.Data.Storage;
 | 
			
		||||
using Connected.Entities.Annotations;
 | 
			
		||||
using Connected.Entities.Storage;
 | 
			
		||||
using Connected.Interop;
 | 
			
		||||
using Connected.ServiceModel;
 | 
			
		||||
using System.Data;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Data;
 | 
			
		||||
 | 
			
		||||
public static class DataExtensions
 | 
			
		||||
{
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// Sets <see cref="StorageConnectionMode.Isolated"/> value to the <see cref="IConnectionProvider"/> on the
 | 
			
		||||
	/// provided <see cref="IContext"/>.
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	/// <param name="context">The <see cref="IContext"/> to set the <see cref="StorageConnectionMode.Isolated"/> value.</param>
 | 
			
		||||
	public static void UseIsolatedConnections(this IContext context)
 | 
			
		||||
	{
 | 
			
		||||
		if (context.GetService<IConnectionProvider>() is IConnectionProvider provider)
 | 
			
		||||
			provider.Mode = StorageConnectionMode.Isolated;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static DbType ToDbType(PropertyInfo property)
 | 
			
		||||
	{
 | 
			
		||||
		var type = property.PropertyType;
 | 
			
		||||
 | 
			
		||||
		if (type.IsEnum)
 | 
			
		||||
			type = Enum.GetUnderlyingType(type);
 | 
			
		||||
 | 
			
		||||
		if (type == typeof(char) || type == typeof(string))
 | 
			
		||||
		{
 | 
			
		||||
			if (property.FindAttribute<ETagAttribute>() != null)
 | 
			
		||||
				return DbType.Binary;
 | 
			
		||||
 | 
			
		||||
			var str = property.FindAttribute<StringAttribute>();
 | 
			
		||||
 | 
			
		||||
			if (str is null)
 | 
			
		||||
				return DbType.String;
 | 
			
		||||
 | 
			
		||||
			return str.Kind switch
 | 
			
		||||
			{
 | 
			
		||||
				StringKind.NVarChar => DbType.String,
 | 
			
		||||
				StringKind.VarChar => DbType.AnsiString,
 | 
			
		||||
				StringKind.Char => DbType.AnsiStringFixedLength,
 | 
			
		||||
				StringKind.NChar => DbType.StringFixedLength,
 | 
			
		||||
				_ => DbType.String,
 | 
			
		||||
			};
 | 
			
		||||
		}
 | 
			
		||||
		else if (type == typeof(byte))
 | 
			
		||||
			return DbType.Byte;
 | 
			
		||||
		else if (type == typeof(bool))
 | 
			
		||||
			return DbType.Boolean;
 | 
			
		||||
		else if (type == typeof(DateTime) || type == typeof(DateTimeOffset))
 | 
			
		||||
		{
 | 
			
		||||
			var att = property.FindAttribute<DateAttribute>();
 | 
			
		||||
 | 
			
		||||
			if (att is null)
 | 
			
		||||
				return DbType.DateTime2;
 | 
			
		||||
 | 
			
		||||
			return att.Kind switch
 | 
			
		||||
			{
 | 
			
		||||
				DateKind.Date => DbType.Date,
 | 
			
		||||
				DateKind.DateTime => DbType.DateTime,
 | 
			
		||||
				DateKind.DateTime2 => DbType.DateTime2,
 | 
			
		||||
				DateKind.SmallDateTime => DbType.DateTime,
 | 
			
		||||
				DateKind.Time => DbType.Time,
 | 
			
		||||
				_ => DbType.DateTime2,
 | 
			
		||||
			};
 | 
			
		||||
		}
 | 
			
		||||
		else if (type == typeof(decimal))
 | 
			
		||||
			return DbType.Decimal;
 | 
			
		||||
		else if (type == typeof(double))
 | 
			
		||||
			return DbType.Double;
 | 
			
		||||
		else if (type == typeof(Guid))
 | 
			
		||||
			return DbType.Guid;
 | 
			
		||||
		else if (type == typeof(short))
 | 
			
		||||
			return DbType.Int16;
 | 
			
		||||
		else if (type == typeof(int))
 | 
			
		||||
			return DbType.Int32;
 | 
			
		||||
		else if (type == typeof(long))
 | 
			
		||||
			return DbType.Int64;
 | 
			
		||||
		else if (type == typeof(sbyte))
 | 
			
		||||
			return DbType.SByte;
 | 
			
		||||
		else if (type == typeof(float))
 | 
			
		||||
			return DbType.Single;
 | 
			
		||||
		else if (type == typeof(TimeSpan))
 | 
			
		||||
			return DbType.Time;
 | 
			
		||||
		else if (type == typeof(ushort))
 | 
			
		||||
			return DbType.UInt16;
 | 
			
		||||
		else if (type == typeof(uint))
 | 
			
		||||
			return DbType.UInt32;
 | 
			
		||||
		else if (type == typeof(ulong))
 | 
			
		||||
			return DbType.UInt64;
 | 
			
		||||
		else if (type == typeof(byte[]))
 | 
			
		||||
			return DbType.Binary;
 | 
			
		||||
		else
 | 
			
		||||
			return DbType.Binary;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										25
									
								
								src/Connected.Data/DataStartup.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/Connected.Data/DataStartup.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,25 @@
 | 
			
		||||
using System.Runtime.CompilerServices;
 | 
			
		||||
using Connected.Annotations;
 | 
			
		||||
using Connected.Data.DataProtection;
 | 
			
		||||
using Connected.Data.Schema;
 | 
			
		||||
using Connected.Data.Sharding;
 | 
			
		||||
using Connected.Data.Storage;
 | 
			
		||||
using Connected.Entities.Storage;
 | 
			
		||||
using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
 | 
			
		||||
[assembly: MicroService(MicroServiceType.Sys)]
 | 
			
		||||
[assembly: InternalsVisibleTo("Connected.Data.Tests")]
 | 
			
		||||
 | 
			
		||||
namespace Connected.Data;
 | 
			
		||||
 | 
			
		||||
internal sealed class DataStartup : Startup
 | 
			
		||||
{
 | 
			
		||||
	protected override void OnConfigureServices(IServiceCollection services)
 | 
			
		||||
	{
 | 
			
		||||
		services.AddScoped(typeof(ISchemaService), typeof(SchemaService));
 | 
			
		||||
		services.AddScoped(typeof(IShardingService), typeof(ShardingService));
 | 
			
		||||
		services.AddScoped(typeof(IConnectionProvider), typeof(ConnectionProvider));
 | 
			
		||||
		services.AddScoped(typeof(IStorageProvider), typeof(StorageProvider));
 | 
			
		||||
		services.AddScoped(typeof(IEntityProtectionService), typeof(EntityProtectionService));
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										14
									
								
								src/Connected.Data/EntityProtection/EntityProtectionArgs.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/Connected.Data/EntityProtection/EntityProtectionArgs.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
			
		||||
using Connected.Entities;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Data.EntityProtection;
 | 
			
		||||
public sealed class EntityProtectionArgs<TEntity> : EventArgs
 | 
			
		||||
{
 | 
			
		||||
	public EntityProtectionArgs(TEntity entity, State state)
 | 
			
		||||
	{
 | 
			
		||||
		Entity = entity;
 | 
			
		||||
		State = state;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public TEntity Entity { get; }
 | 
			
		||||
	public State State { get; }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,25 @@
 | 
			
		||||
using Connected.Data.EntityProtection;
 | 
			
		||||
using Connected.Middleware;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Data.DataProtection;
 | 
			
		||||
 | 
			
		||||
internal class EntityProtectionService : IEntityProtectionService
 | 
			
		||||
{
 | 
			
		||||
	public EntityProtectionService(IMiddlewareService middleware)
 | 
			
		||||
	{
 | 
			
		||||
		Middleware = middleware;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public IMiddlewareService Middleware { get; }
 | 
			
		||||
 | 
			
		||||
	public async Task Invoke<TEntity>(EntityProtectionArgs<TEntity> args)
 | 
			
		||||
	{
 | 
			
		||||
		var middleware = await Middleware.Query<IEntityProtector<TEntity>>();
 | 
			
		||||
 | 
			
		||||
		if (!middleware.Any())
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		foreach (var m in middleware)
 | 
			
		||||
			await m.Invoke(args);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,9 @@
 | 
			
		||||
using Connected.Data.EntityProtection;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Data.DataProtection
 | 
			
		||||
{
 | 
			
		||||
	public interface IEntityProtectionService
 | 
			
		||||
	{
 | 
			
		||||
		Task Invoke<TEntity>(EntityProtectionArgs<TEntity> args);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										8
									
								
								src/Connected.Data/EntityProtection/IEntityProtector.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/Connected.Data/EntityProtection/IEntityProtector.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
			
		||||
using Connected.Data.EntityProtection;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Data.DataProtection;
 | 
			
		||||
 | 
			
		||||
public interface IEntityProtector<TEntity> : IMiddleware
 | 
			
		||||
{
 | 
			
		||||
	Task Invoke(EntityProtectionArgs<TEntity> args);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										125
									
								
								src/Connected.Data/EntityVersion.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										125
									
								
								src/Connected.Data/EntityVersion.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,125 @@
 | 
			
		||||
using Connected.Interop;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Data;
 | 
			
		||||
 | 
			
		||||
internal class EntityVersion : IComparable, IEquatable<EntityVersion>, IComparable<EntityVersion>
 | 
			
		||||
{
 | 
			
		||||
	public static readonly EntityVersion? Zero = default;
 | 
			
		||||
 | 
			
		||||
	private readonly ulong Value;
 | 
			
		||||
 | 
			
		||||
	private EntityVersion(ulong value)
 | 
			
		||||
	{
 | 
			
		||||
		Value = value;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static EntityVersion? Parse(object value)
 | 
			
		||||
	{
 | 
			
		||||
		if (!TypeConversion.TryConvert(value, out string? v))
 | 
			
		||||
			return Zero;
 | 
			
		||||
 | 
			
		||||
		if (string.IsNullOrWhiteSpace(v))
 | 
			
		||||
			return Zero;
 | 
			
		||||
 | 
			
		||||
		return new EntityVersion(Convert.ToUInt64(v, 16));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static implicit operator EntityVersion(ulong value)
 | 
			
		||||
	{
 | 
			
		||||
		return new EntityVersion(value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static implicit operator EntityVersion(long value)
 | 
			
		||||
	{
 | 
			
		||||
		return new EntityVersion(unchecked((ulong)value));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static explicit operator EntityVersion?(byte[] value)
 | 
			
		||||
	{
 | 
			
		||||
		if (value is null)
 | 
			
		||||
			return null;
 | 
			
		||||
 | 
			
		||||
		return new EntityVersion((ulong)value[0] << 56 | (ulong)value[1] << 48 | (ulong)value[2] << 40 | (ulong)value[3] << 32 | (ulong)value[4] << 24 | (ulong)value[5] << 16 | (ulong)value[6] << 8 | value[7]);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static implicit operator byte[](EntityVersion timestamp)
 | 
			
		||||
	{
 | 
			
		||||
		var r = new byte[8];
 | 
			
		||||
 | 
			
		||||
		r[0] = (byte)(timestamp.Value >> 56);
 | 
			
		||||
		r[1] = (byte)(timestamp.Value >> 48);
 | 
			
		||||
		r[2] = (byte)(timestamp.Value >> 40);
 | 
			
		||||
		r[3] = (byte)(timestamp.Value >> 32);
 | 
			
		||||
		r[4] = (byte)(timestamp.Value >> 24);
 | 
			
		||||
		r[5] = (byte)(timestamp.Value >> 16);
 | 
			
		||||
		r[6] = (byte)(timestamp.Value >> 8);
 | 
			
		||||
		r[7] = (byte)timestamp.Value;
 | 
			
		||||
 | 
			
		||||
		return r;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override bool Equals(object? obj)
 | 
			
		||||
	{
 | 
			
		||||
		return obj is Version version && Equals(version);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override int GetHashCode()
 | 
			
		||||
	{
 | 
			
		||||
		return Value.GetHashCode();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public bool Equals(EntityVersion? other)
 | 
			
		||||
	{
 | 
			
		||||
		return other?.Value == Value;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	int IComparable.CompareTo(object? obj)
 | 
			
		||||
	{
 | 
			
		||||
		return obj is null ? 1 : CompareTo((EntityVersion)obj);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public int CompareTo(EntityVersion? other)
 | 
			
		||||
	{
 | 
			
		||||
		return Value == other?.Value ? 0 : Value < other?.Value ? -1 : 1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static bool operator ==(EntityVersion comparand1, EntityVersion comparand2)
 | 
			
		||||
	{
 | 
			
		||||
		return comparand1.Equals(comparand2);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static bool operator !=(EntityVersion comparand1, EntityVersion comparand2)
 | 
			
		||||
	{
 | 
			
		||||
		return !comparand1.Equals(comparand2);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static bool operator >(EntityVersion comparand1, EntityVersion comparand2)
 | 
			
		||||
	{
 | 
			
		||||
		return comparand1.CompareTo(comparand2) > 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static bool operator >=(EntityVersion comparand1, EntityVersion comparand2)
 | 
			
		||||
	{
 | 
			
		||||
		return comparand1.CompareTo(comparand2) >= 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static bool operator <(EntityVersion comparand1, EntityVersion comparand2)
 | 
			
		||||
	{
 | 
			
		||||
		return comparand1.CompareTo(comparand2) < 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static bool operator <=(EntityVersion comparand1, EntityVersion comparand2)
 | 
			
		||||
	{
 | 
			
		||||
		return comparand1.CompareTo(comparand2) <= 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override string ToString()
 | 
			
		||||
	{
 | 
			
		||||
		return Value.ToString("x16");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static EntityVersion Max(EntityVersion comparand1, EntityVersion comparand2)
 | 
			
		||||
	{
 | 
			
		||||
		return comparand1.Value < comparand2.Value ? comparand2 : comparand1;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										192
									
								
								src/Connected.Data/FieldMappings.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										192
									
								
								src/Connected.Data/FieldMappings.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,192 @@
 | 
			
		||||
using Connected.Entities.Annotations;
 | 
			
		||||
using Connected.Interop;
 | 
			
		||||
using System.Data;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Data;
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// Performs mapping between <see cref="IDataReader"/> fields and entity properties.
 | 
			
		||||
/// </summary>
 | 
			
		||||
/// <typeparam name="TEntity">The entity type to be used.</typeparam>
 | 
			
		||||
internal class FieldMappings<TEntity>
 | 
			
		||||
{
 | 
			
		||||
	private Dictionary<int, PropertyInfo> _properties;
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// Creates a new <see cref="FieldMappings{TEntity}"/> object.
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	/// <param name="reader">The <see cref="IDataReader"/> providing entity records.</param>
 | 
			
		||||
	public FieldMappings(IDataReader reader)
 | 
			
		||||
	{
 | 
			
		||||
		Initialize(reader);
 | 
			
		||||
	}
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// Cached properties use when looping through the records.
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	private Dictionary<int, PropertyInfo> Properties => _properties;
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// Initializes the mappings base on the provided <see cref="IDataReader"/>
 | 
			
		||||
	/// and <typeparamref name="TEntity"/>
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	/// <param name="reader">The active reader containing records.</param>
 | 
			
		||||
	private void Initialize(IDataReader reader)
 | 
			
		||||
	{
 | 
			
		||||
		/*
 | 
			
		||||
		 * For primitive types there are no mappings since it's an scalar call.
 | 
			
		||||
		 */
 | 
			
		||||
		if (typeof(TEntity).IsTypePrimitive())
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		_properties = new Dictionary<int, PropertyInfo>();
 | 
			
		||||
		/*
 | 
			
		||||
		 * We are binding only properties, not fields.
 | 
			
		||||
		 */
 | 
			
		||||
		var properties = typeof(TEntity).GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
 | 
			
		||||
 | 
			
		||||
		for (var i = 0; i < reader.FieldCount; i++)
 | 
			
		||||
		{
 | 
			
		||||
			if (FieldMappings<TEntity>.ResolveProperty(properties, reader.GetName(i)) is PropertyInfo property)
 | 
			
		||||
				_properties.Add(i, property);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// Creates a new instance of the <see cref="TEntity"/> and binds
 | 
			
		||||
	/// properties from the provided <see cref="IDataReader"/>.
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	/// <param name="reader">The <see cref="IDataReader"/> containing the record.</param>
 | 
			
		||||
	/// <returns>A new instance of the <see cref="TEntity"/> with bound values from the <see cref="IDataReader"/>.</returns>
 | 
			
		||||
	public TEntity? CreateInstance(IDataReader reader)
 | 
			
		||||
	{
 | 
			
		||||
		/*
 | 
			
		||||
		 * For primitive return values we'll use only the first field and return itž
 | 
			
		||||
		 * to the caller.
 | 
			
		||||
		 */
 | 
			
		||||
		if (typeof(TEntity).IsTypePrimitive())
 | 
			
		||||
		{
 | 
			
		||||
			if (reader.FieldCount == 0)
 | 
			
		||||
				return default;
 | 
			
		||||
 | 
			
		||||
			if (TypeConversion.TryConvert(reader[0], out TEntity? result))
 | 
			
		||||
				return result;
 | 
			
		||||
 | 
			
		||||
			return default;
 | 
			
		||||
		}
 | 
			
		||||
		/*
 | 
			
		||||
		 * It's an actual entity. First, create a new instance. Entities should have
 | 
			
		||||
		 * public parameterless constructor.
 | 
			
		||||
		 */
 | 
			
		||||
		if (typeof(TEntity?).CreateInstance<TEntity>() is not TEntity instance)
 | 
			
		||||
			throw new NullReferenceException(typeof(TEntity).FullName);
 | 
			
		||||
 | 
			
		||||
		foreach (var property in Properties)
 | 
			
		||||
			Bind(instance, property, reader);
 | 
			
		||||
 | 
			
		||||
		return instance;
 | 
			
		||||
	}
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// Resolves a correct property from the entity's properties based on a <see cref="IDataReader"/> field name.
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	/// <param name="properties">The entity's properties.</param>
 | 
			
		||||
	/// <param name="name">The <see cref="IDataReader"/> field name.</param>
 | 
			
		||||
	/// <returns>A <see cref="PropertyInfo"/> if found, <c>null</c> otherwise.</returns>
 | 
			
		||||
	private static PropertyInfo? ResolveProperty(PropertyInfo[] properties, string name)
 | 
			
		||||
	{
 | 
			
		||||
		/*
 | 
			
		||||
		 * There are two ways to map a property (evaluated in the following order):
 | 
			
		||||
		 * 1. from property name
 | 
			
		||||
		 * 2. from MemberAttribute
 | 
			
		||||
		 * 
 | 
			
		||||
		 * We'll first perform case insensitive comparison because fields in the database are usually stored in a camelCase format.
 | 
			
		||||
		 */
 | 
			
		||||
		if (properties.FirstOrDefault(f => string.Equals(f.Name, name, StringComparison.OrdinalIgnoreCase)) is PropertyInfo property && property.CanWrite)
 | 
			
		||||
		{
 | 
			
		||||
			/*
 | 
			
		||||
			 * Property is found, examine if the persistence from the storage is supported.
 | 
			
		||||
			 */
 | 
			
		||||
			var att = property.FindAttribute<PersistenceAttribute>();
 | 
			
		||||
 | 
			
		||||
			if (att is null || att.Persistence.HasFlag(ColumnPersistence.Read))
 | 
			
		||||
				return property;
 | 
			
		||||
		}
 | 
			
		||||
		/*
 | 
			
		||||
		 * Property wasn't found, let's try to find it via MemberAttribute.
 | 
			
		||||
		 */
 | 
			
		||||
		foreach (var prop in properties)
 | 
			
		||||
		{
 | 
			
		||||
			/*
 | 
			
		||||
			 * It's case insensitive comparison again because we don't want bother user with exact matching. Since a database is probably case insensitive anyway
 | 
			
		||||
			 * there is no option to store columns with case sensitive names.
 | 
			
		||||
			 */
 | 
			
		||||
			if (prop.FindAttribute<MemberAttribute>() is MemberAttribute nameAttribute && string.Compare(nameAttribute.Member, name, true) == 0 && prop.CanWrite)
 | 
			
		||||
				return prop;
 | 
			
		||||
		}
 | 
			
		||||
		/*
 | 
			
		||||
		 * Property could't be found. The field will be ognored when reading data.
 | 
			
		||||
		 */
 | 
			
		||||
		return default;
 | 
			
		||||
	}
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// Binds the <see cref="IDataReader"/> value to the entity's property.
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	/// <param name="instance">The instance of the entity.</param>
 | 
			
		||||
	/// <param name="property">The property on which value to be set.</param>
 | 
			
		||||
	/// <param name="reader">The <see cref="IDataReader"/>providing the value.</param>
 | 
			
		||||
	private static void Bind(object instance, KeyValuePair<int, PropertyInfo> property, IDataReader reader)
 | 
			
		||||
	{
 | 
			
		||||
		var value = reader.GetValue(property.Key);
 | 
			
		||||
		/*
 | 
			
		||||
		 * We won't bind null values. We'll leave the property as is.
 | 
			
		||||
		 */
 | 
			
		||||
		if (value is null || Convert.IsDBNull(value))
 | 
			
		||||
			return;
 | 
			
		||||
		/*
 | 
			
		||||
		 * We have a few exceptions when binding values.
 | 
			
		||||
		 */
 | 
			
		||||
		if (property.Value.PropertyType == typeof(string) && value is byte[] bv)
 | 
			
		||||
		{
 | 
			
		||||
			/*
 | 
			
		||||
			 * If the property is string and the reader's value is byte array we are probably dealing
 | 
			
		||||
			 * with Consistency field. We'll first check if the property contains the attribute. If so,
 | 
			
		||||
			 * we'll convert byte array to eTag kind of value. If not we'll simply convert value to base64
 | 
			
		||||
			 * string.
 | 
			
		||||
			 */
 | 
			
		||||
			if (property.Value.FindAttribute<ETagAttribute>() is not null)
 | 
			
		||||
			{
 | 
			
		||||
				var versionValue = (EntityVersion?)bv;
 | 
			
		||||
 | 
			
		||||
				if (versionValue is null)
 | 
			
		||||
					value = Convert.ToBase64String(bv);
 | 
			
		||||
				else
 | 
			
		||||
					value = versionValue.ToString();
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
				value = Convert.ToBase64String(bv);
 | 
			
		||||
		}
 | 
			
		||||
		else if (property.Value.PropertyType == typeof(DateTimeOffset))
 | 
			
		||||
		{
 | 
			
		||||
			/*
 | 
			
		||||
			 * We don't perform any conversions on dates. All dates should be stored in a UTC
 | 
			
		||||
			 * format so we simply set the correct kind of date so it can be later correctly
 | 
			
		||||
			 * converted
 | 
			
		||||
			 */
 | 
			
		||||
			value = new DateTimeOffset(DateTime.SpecifyKind((DateTime)value, DateTimeKind.Utc));
 | 
			
		||||
		}
 | 
			
		||||
		else if (property.Value.PropertyType == typeof(DateTime))
 | 
			
		||||
		{
 | 
			
		||||
			/*
 | 
			
		||||
			 * Like DateTimeOffset, the same is true for DateTime values
 | 
			
		||||
			 */
 | 
			
		||||
			value = DateTime.SpecifyKind((DateTime)value, DateTimeKind.Utc);
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			/*
 | 
			
		||||
			 * For other values we just perform a conversion.
 | 
			
		||||
			 */
 | 
			
		||||
			value = TypeConversion.Convert(value, property.Value.PropertyType);
 | 
			
		||||
		}
 | 
			
		||||
		/*
 | 
			
		||||
		 * Now bind the property from the converted value.
 | 
			
		||||
		 */
 | 
			
		||||
		property.Value.SetValue(instance, value);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										72
									
								
								src/Connected.Data/SR.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								src/Connected.Data/SR.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							@ -0,0 +1,72 @@
 | 
			
		||||
//------------------------------------------------------------------------------
 | 
			
		||||
// <auto-generated>
 | 
			
		||||
//     This code was generated by a tool.
 | 
			
		||||
//     Runtime Version:4.0.30319.42000
 | 
			
		||||
//
 | 
			
		||||
//     Changes to this file may cause incorrect behavior and will be lost if
 | 
			
		||||
//     the code is regenerated.
 | 
			
		||||
// </auto-generated>
 | 
			
		||||
//------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
namespace Connected.Data {
 | 
			
		||||
    using System;
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    ///   A strongly-typed resource class, for looking up localized strings, etc.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    // This class was auto-generated by the StronglyTypedResourceBuilder
 | 
			
		||||
    // class via a tool like ResGen or Visual Studio.
 | 
			
		||||
    // To add or remove a member, edit your .ResX file then rerun ResGen
 | 
			
		||||
    // with the /str option, or rebuild your VS project.
 | 
			
		||||
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
 | 
			
		||||
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
 | 
			
		||||
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
 | 
			
		||||
    internal class SR {
 | 
			
		||||
        
 | 
			
		||||
        private static global::System.Resources.ResourceManager resourceMan;
 | 
			
		||||
        
 | 
			
		||||
        private static global::System.Globalization.CultureInfo resourceCulture;
 | 
			
		||||
        
 | 
			
		||||
        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
 | 
			
		||||
        internal SR() {
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   Returns the cached ResourceManager instance used by this class.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
 | 
			
		||||
        internal static global::System.Resources.ResourceManager ResourceManager {
 | 
			
		||||
            get {
 | 
			
		||||
                if (object.ReferenceEquals(resourceMan, null)) {
 | 
			
		||||
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Connected.Data.SR", typeof(SR).Assembly);
 | 
			
		||||
                    resourceMan = temp;
 | 
			
		||||
                }
 | 
			
		||||
                return resourceMan;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   Overrides the current thread's CurrentUICulture property for all
 | 
			
		||||
        ///   resource lookups using this strongly typed resource class.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
 | 
			
		||||
        internal static global::System.Globalization.CultureInfo Culture {
 | 
			
		||||
            get {
 | 
			
		||||
                return resourceCulture;
 | 
			
		||||
            }
 | 
			
		||||
            set {
 | 
			
		||||
                resourceCulture = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   Looks up a localized string similar to Data concurrency issue occured.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal static string ErrDataConcurrency {
 | 
			
		||||
            get {
 | 
			
		||||
                return ResourceManager.GetString("ErrDataConcurrency", resourceCulture);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										123
									
								
								src/Connected.Data/SR.resx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										123
									
								
								src/Connected.Data/SR.resx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,123 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<root>
 | 
			
		||||
  <!-- 
 | 
			
		||||
    Microsoft ResX Schema 
 | 
			
		||||
    
 | 
			
		||||
    Version 2.0
 | 
			
		||||
    
 | 
			
		||||
    The primary goals of this format is to allow a simple XML format 
 | 
			
		||||
    that is mostly human readable. The generation and parsing of the 
 | 
			
		||||
    various data types are done through the TypeConverter classes 
 | 
			
		||||
    associated with the data types.
 | 
			
		||||
    
 | 
			
		||||
    Example:
 | 
			
		||||
    
 | 
			
		||||
    ... ado.net/XML headers & schema ...
 | 
			
		||||
    <resheader name="resmimetype">text/microsoft-resx</resheader>
 | 
			
		||||
    <resheader name="version">2.0</resheader>
 | 
			
		||||
    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
 | 
			
		||||
    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
 | 
			
		||||
    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
 | 
			
		||||
    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
 | 
			
		||||
    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
 | 
			
		||||
        <value>[base64 mime encoded serialized .NET Framework object]</value>
 | 
			
		||||
    </data>
 | 
			
		||||
    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
 | 
			
		||||
        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
 | 
			
		||||
        <comment>This is a comment</comment>
 | 
			
		||||
    </data>
 | 
			
		||||
                
 | 
			
		||||
    There are any number of "resheader" rows that contain simple 
 | 
			
		||||
    name/value pairs.
 | 
			
		||||
    
 | 
			
		||||
    Each data row contains a name, and value. The row also contains a 
 | 
			
		||||
    type or mimetype. Type corresponds to a .NET class that support 
 | 
			
		||||
    text/value conversion through the TypeConverter architecture. 
 | 
			
		||||
    Classes that don't support this are serialized and stored with the 
 | 
			
		||||
    mimetype set.
 | 
			
		||||
    
 | 
			
		||||
    The mimetype is used for serialized objects, and tells the 
 | 
			
		||||
    ResXResourceReader how to depersist the object. This is currently not 
 | 
			
		||||
    extensible. For a given mimetype the value must be set accordingly:
 | 
			
		||||
    
 | 
			
		||||
    Note - application/x-microsoft.net.object.binary.base64 is the format 
 | 
			
		||||
    that the ResXResourceWriter will generate, however the reader can 
 | 
			
		||||
    read any of the formats listed below.
 | 
			
		||||
    
 | 
			
		||||
    mimetype: application/x-microsoft.net.object.binary.base64
 | 
			
		||||
    value   : The object must be serialized with 
 | 
			
		||||
            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
 | 
			
		||||
            : and then encoded with base64 encoding.
 | 
			
		||||
    
 | 
			
		||||
    mimetype: application/x-microsoft.net.object.soap.base64
 | 
			
		||||
    value   : The object must be serialized with 
 | 
			
		||||
            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
 | 
			
		||||
            : and then encoded with base64 encoding.
 | 
			
		||||
 | 
			
		||||
    mimetype: application/x-microsoft.net.object.bytearray.base64
 | 
			
		||||
    value   : The object must be serialized into a byte array 
 | 
			
		||||
            : using a System.ComponentModel.TypeConverter
 | 
			
		||||
            : and then encoded with base64 encoding.
 | 
			
		||||
    -->
 | 
			
		||||
  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
 | 
			
		||||
    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
 | 
			
		||||
    <xsd:element name="root" msdata:IsDataSet="true">
 | 
			
		||||
      <xsd:complexType>
 | 
			
		||||
        <xsd:choice maxOccurs="unbounded">
 | 
			
		||||
          <xsd:element name="metadata">
 | 
			
		||||
            <xsd:complexType>
 | 
			
		||||
              <xsd:sequence>
 | 
			
		||||
                <xsd:element name="value" type="xsd:string" minOccurs="0" />
 | 
			
		||||
              </xsd:sequence>
 | 
			
		||||
              <xsd:attribute name="name" use="required" type="xsd:string" />
 | 
			
		||||
              <xsd:attribute name="type" type="xsd:string" />
 | 
			
		||||
              <xsd:attribute name="mimetype" type="xsd:string" />
 | 
			
		||||
              <xsd:attribute ref="xml:space" />
 | 
			
		||||
            </xsd:complexType>
 | 
			
		||||
          </xsd:element>
 | 
			
		||||
          <xsd:element name="assembly">
 | 
			
		||||
            <xsd:complexType>
 | 
			
		||||
              <xsd:attribute name="alias" type="xsd:string" />
 | 
			
		||||
              <xsd:attribute name="name" type="xsd:string" />
 | 
			
		||||
            </xsd:complexType>
 | 
			
		||||
          </xsd:element>
 | 
			
		||||
          <xsd:element name="data">
 | 
			
		||||
            <xsd:complexType>
 | 
			
		||||
              <xsd:sequence>
 | 
			
		||||
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
 | 
			
		||||
                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
 | 
			
		||||
              </xsd:sequence>
 | 
			
		||||
              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
 | 
			
		||||
              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
 | 
			
		||||
              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
 | 
			
		||||
              <xsd:attribute ref="xml:space" />
 | 
			
		||||
            </xsd:complexType>
 | 
			
		||||
          </xsd:element>
 | 
			
		||||
          <xsd:element name="resheader">
 | 
			
		||||
            <xsd:complexType>
 | 
			
		||||
              <xsd:sequence>
 | 
			
		||||
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
 | 
			
		||||
              </xsd:sequence>
 | 
			
		||||
              <xsd:attribute name="name" type="xsd:string" use="required" />
 | 
			
		||||
            </xsd:complexType>
 | 
			
		||||
          </xsd:element>
 | 
			
		||||
        </xsd:choice>
 | 
			
		||||
      </xsd:complexType>
 | 
			
		||||
    </xsd:element>
 | 
			
		||||
  </xsd:schema>
 | 
			
		||||
  <resheader name="resmimetype">
 | 
			
		||||
    <value>text/microsoft-resx</value>
 | 
			
		||||
  </resheader>
 | 
			
		||||
  <resheader name="version">
 | 
			
		||||
    <value>2.0</value>
 | 
			
		||||
  </resheader>
 | 
			
		||||
  <resheader name="reader">
 | 
			
		||||
    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
 | 
			
		||||
  </resheader>
 | 
			
		||||
  <resheader name="writer">
 | 
			
		||||
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
 | 
			
		||||
  </resheader>
 | 
			
		||||
  <data name="ErrDataConcurrency" xml:space="preserve">
 | 
			
		||||
    <value>Data concurrency issue occured</value>
 | 
			
		||||
  </data>
 | 
			
		||||
</root>
 | 
			
		||||
							
								
								
									
										38
									
								
								src/Connected.Data/Schema/EntitySchema.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/Connected.Data/Schema/EntitySchema.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,38 @@
 | 
			
		||||
namespace Connected.Data.Schema
 | 
			
		||||
{
 | 
			
		||||
	internal class EntitySchema : ISchema
 | 
			
		||||
	{
 | 
			
		||||
		public EntitySchema()
 | 
			
		||||
		{
 | 
			
		||||
			Columns = new();
 | 
			
		||||
		}
 | 
			
		||||
		public List<ISchemaColumn> Columns { get; }
 | 
			
		||||
 | 
			
		||||
		public string? Schema { get; set; }
 | 
			
		||||
		public string? Name { get; set; }
 | 
			
		||||
		public string? Type { get; set; }
 | 
			
		||||
		public bool Ignore { get; set; }
 | 
			
		||||
		public bool Equals(ISchema? other)
 | 
			
		||||
		{
 | 
			
		||||
			if (other is null)
 | 
			
		||||
				return false;
 | 
			
		||||
 | 
			
		||||
			if (!string.Equals(Name, other.Name, StringComparison.Ordinal))
 | 
			
		||||
				return false;
 | 
			
		||||
 | 
			
		||||
			if (!string.Equals(Schema, other.Schema, StringComparison.Ordinal))
 | 
			
		||||
				return false;
 | 
			
		||||
 | 
			
		||||
			if (Columns.Count != other.Columns.Count)
 | 
			
		||||
				return false;
 | 
			
		||||
 | 
			
		||||
			for (var i = 0; i < Columns.Count; i++)
 | 
			
		||||
			{
 | 
			
		||||
				if (Columns[i] is not IEquatable<ISchemaColumn> left || !left.Equals(other.Columns[i]))
 | 
			
		||||
					return false;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										64
									
								
								src/Connected.Data/Schema/ExistingColumn.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								src/Connected.Data/Schema/ExistingColumn.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,64 @@
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
using System.Data;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using Connected.Data.Schema.Sql;
 | 
			
		||||
using Connected.Entities.Annotations;
 | 
			
		||||
 | 
			
		||||
namespace Connected.Data.Schema;
 | 
			
		||||
 | 
			
		||||
internal class ExistingColumn : ISchemaColumn, IExistingSchemaColumn
 | 
			
		||||
{
 | 
			
		||||
	public ExistingColumn(ISchema schema)
 | 
			
		||||
	{
 | 
			
		||||
		Schema = schema;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private ISchema Schema { get; }
 | 
			
		||||
 | 
			
		||||
	public string Name { get; set; }
 | 
			
		||||
 | 
			
		||||
	public DbType DataType { get; set; }
 | 
			
		||||
 | 
			
		||||
	public bool IsIdentity { get; set; }
 | 
			
		||||
	public bool IsVersion { get; set; }
 | 
			
		||||
 | 
			
		||||
	public bool IsUnique { get; set; }
 | 
			
		||||
 | 
			
		||||
	public bool IsIndex { get; set; }
 | 
			
		||||
 | 
			
		||||
	public bool IsPrimaryKey { get; set; }
 | 
			
		||||
 | 
			
		||||
	public string DefaultValue { get; set; }
 | 
			
		||||
 | 
			
		||||
	public int MaxLength { get; set; }
 | 
			
		||||
 | 
			
		||||
	public bool IsNullable { get; set; }
 | 
			
		||||
 | 
			
		||||
	public string DependencyType { get; set; }
 | 
			
		||||
 | 
			
		||||
	public string DependencyProperty { get; set; }
 | 
			
		||||
 | 
			
		||||
	public string Index { get; set; }
 | 
			
		||||
	public int Precision { get; set; }
 | 
			
		||||
	public int Scale { get; set; }
 | 
			
		||||
 | 
			
		||||
	public DateKind DateKind { get; set; } = DateKind.DateTime;
 | 
			
		||||
	public BinaryKind BinaryKind { get; set; } = BinaryKind.VarBinary;
 | 
			
		||||
 | 
			
		||||
	public PropertyInfo Property { get; set; }
 | 
			
		||||
	public int DatePrecision { get; set; }
 | 
			
		||||
 | 
			
		||||
	public ImmutableArray<string> QueryIndexColumns(string column)
 | 
			
		||||
	{
 | 
			
		||||
		if (Schema is not ExistingSchema existing)
 | 
			
		||||
			return ImmutableArray<string>.Empty;
 | 
			
		||||
 | 
			
		||||
		foreach (var index in existing.Indexes)
 | 
			
		||||
		{
 | 
			
		||||
			if (index.Columns.Contains(column, StringComparer.OrdinalIgnoreCase))
 | 
			
		||||
				return index.Columns.ToImmutableArray();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return ImmutableArray<string>.Empty;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
Some files were not shown because too many files have changed in this diff Show More
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user