Compare commits
33 Commits
main
...
features/n
Author | SHA1 | Date | |
---|---|---|---|
![]() |
49f9255464 | ||
![]() |
f753603d80 | ||
![]() |
7f68deae44 | ||
![]() |
b3fc6134d7 | ||
![]() |
337a52792d | ||
![]() |
1fefc3dfa7 | ||
![]() |
a03a157786 | ||
![]() |
0806e7bc81 | ||
![]() |
1b4a8d757a | ||
![]() |
0db6e1669f | ||
![]() |
7fcfc280f5 | ||
![]() |
cd890bb70e | ||
![]() |
4cec02f73e | ||
![]() |
c6f0eecd1e | ||
8c9c2f33fb | |||
![]() |
55eaf3e789 | ||
![]() |
a0fd946748 | ||
![]() |
878f0d76f5 | ||
![]() |
c3553d2787 | ||
![]() |
43d059b12a | ||
![]() |
925d43e5c5 | ||
![]() |
7c9a20bc96 | ||
![]() |
a1c6b94085 | ||
![]() |
c9239ebda5 | ||
![]() |
375c41ff84 | ||
![]() |
ee5e5c3f23 | ||
![]() |
8c77d8441e | ||
d89cac3c25 | |||
82a34bddf2 | |||
![]() |
e374b41b08 | ||
821b90f1ab | |||
![]() |
c95b896011 | ||
![]() |
100e9ed085 |
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 = 4
|
||||
indent_style = tab
|
||||
tab_width = 4
|
||||
|
||||
# New line preferences
|
||||
end_of_line = crlf
|
||||
insert_final_newline = false
|
||||
|
||||
#### .NET Coding Conventions ####
|
||||
|
||||
# Organize usings
|
||||
dotnet_separate_import_directive_groups = false
|
||||
dotnet_sort_system_directives_first = true
|
||||
file_header_template = unset
|
||||
|
||||
# this. and Me. preferences
|
||||
dotnet_style_qualification_for_event = false
|
||||
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
|
61
Connected.Common.sln
Normal file
61
Connected.Common.sln
Normal file
@ -0,0 +1,61 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.4.32916.344
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Common", "src\Connected.Common\Connected.Common.csproj", "{CB582FC6-7A9A-46D1-BA75-4A103E096674}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Common.Model", "src\Connected.Common.Model\Connected.Common.Model.csproj", "{ABF6BF35-ED9F-43A9-8581-23CBD9701E94}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Common.Notes", "src\Connected.Common.Notes\Connected.Common.Notes.csproj", "{05B6148F-467C-4090-8FEA-8EA16A4D9956}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Common.Notes.Model", "src\Connected.Common.Notes.Model\Connected.Common.Notes.Model.csproj", "{DF77BAAB-8223-4BEA-B7BA-0C087D9C6750}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Common.Numbering.Model", "src\Connected.Common.Numbering.Model\Connected.Common.Numbering.Model.csproj", "{83F83DE6-28BF-4AB7-902E-42D38A54A578}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Common.Numbering", "src\Connected.Common.Numbering\Connected.Common.Numbering.csproj", "{4E810676-E37E-4C25-95FC-747BB32E5A69}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Common.Numbering.Middleware", "src\Connected.Common.Numbering.Middleware\Connected.Common.Numbering.Middleware.csproj", "{424C1CBE-8490-431C-A0A8-1ACB22A65864}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{CB582FC6-7A9A-46D1-BA75-4A103E096674}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CB582FC6-7A9A-46D1-BA75-4A103E096674}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CB582FC6-7A9A-46D1-BA75-4A103E096674}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CB582FC6-7A9A-46D1-BA75-4A103E096674}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{ABF6BF35-ED9F-43A9-8581-23CBD9701E94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ABF6BF35-ED9F-43A9-8581-23CBD9701E94}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ABF6BF35-ED9F-43A9-8581-23CBD9701E94}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ABF6BF35-ED9F-43A9-8581-23CBD9701E94}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{05B6148F-467C-4090-8FEA-8EA16A4D9956}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{05B6148F-467C-4090-8FEA-8EA16A4D9956}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{05B6148F-467C-4090-8FEA-8EA16A4D9956}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{05B6148F-467C-4090-8FEA-8EA16A4D9956}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DF77BAAB-8223-4BEA-B7BA-0C087D9C6750}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DF77BAAB-8223-4BEA-B7BA-0C087D9C6750}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DF77BAAB-8223-4BEA-B7BA-0C087D9C6750}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DF77BAAB-8223-4BEA-B7BA-0C087D9C6750}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{83F83DE6-28BF-4AB7-902E-42D38A54A578}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{83F83DE6-28BF-4AB7-902E-42D38A54A578}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{83F83DE6-28BF-4AB7-902E-42D38A54A578}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{83F83DE6-28BF-4AB7-902E-42D38A54A578}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4E810676-E37E-4C25-95FC-747BB32E5A69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4E810676-E37E-4C25-95FC-747BB32E5A69}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4E810676-E37E-4C25-95FC-747BB32E5A69}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4E810676-E37E-4C25-95FC-747BB32E5A69}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{424C1CBE-8490-431C-A0A8-1ACB22A65864}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{424C1CBE-8490-431C-A0A8-1ACB22A65864}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{424C1CBE-8490-431C-A0A8-1ACB22A65864}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{424C1CBE-8490-431C-A0A8-1ACB22A65864}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {23EF0531-5260-4441-876C-7569138BD7FA}
|
||||
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
7
build/buildProjects.bat
Normal file
7
build/buildProjects.bat
Normal file
@ -0,0 +1,7 @@
|
||||
dotnet build ../src/Connected.Common.Model/Connected.Common.Model.csproj
|
||||
dotnet build ../src/Connected.Common/Connected.Common.csproj
|
||||
dotnet build ../src/Connected.Common.Numbering.Model/Connected.Common.Numbering.Model.csproj
|
||||
dotnet build ../src/Connected.Common.Numbering.Middleware/Connected.Common.Numbering.Middleware.csproj
|
||||
dotnet build ../src/Connected.Common.Numbering/Connected.Common.Numbering.csproj
|
||||
dotnet build ../src/Connected.Common.Notes.Model/Connected.Common.Notes.Model.csproj
|
||||
dotnet build ../src/Connected.Common.Notes/Connected.Common.Notes.csproj
|
17
nuget.config
Normal file
17
nuget.config
Normal file
@ -0,0 +1,17 @@
|
||||
<?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" />
|
||||
<add key="Local repository" value="%LOCAL_NUGET%" />
|
||||
</packageSources>
|
||||
|
||||
<disabledPackageSources />
|
||||
</configuration>
|
8
src/Connected.Common.Model/CommonRoutes.cs
Normal file
8
src/Connected.Common.Model/CommonRoutes.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace Connected.Common;
|
||||
|
||||
public static class CommonRoutes
|
||||
{
|
||||
public const string Common = "/common";
|
||||
public const string Management = "/management";
|
||||
public const string Documents = "/documents";
|
||||
}
|
44
src/Connected.Common.Model/Connected.Common.Model.csproj
Normal file
44
src/Connected.Common.Model/Connected.Common.Model.csproj
Normal file
@ -0,0 +1,44 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>Connected.Common</RootNamespace>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<Title>$(AssemblyName)</Title>
|
||||
<Authors>Tom PIT ltd</Authors>
|
||||
<Copyright>2022 Tom PIT ltd</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="Connected" Version="1.0.*-*"/>
|
||||
<PackageReference Include="Nerdbank.GitVersioning"
|
||||
Version="3.5.119"
|
||||
PrivateAssets="all"
|
||||
Condition="!Exists('packages.config')" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\..\LICENSE">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
<None Include="..\..\README.md">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyPackages" AfterTargets="Pack">
|
||||
<Copy SourceFiles="$(OutputPath)..\$(PackageId).$(PackageVersion).nupkg" DestinationFolder="$([System.Environment]::GetEnvironmentVariable('LOCAL_NUGET'))" />
|
||||
<Copy SourceFiles="$(OutputPath)..\$(PackageId).$(PackageVersion).snupkg" DestinationFolder="$([System.Environment]::GetEnvironmentVariable('LOCAL_NUGET'))" />
|
||||
</Target>
|
||||
</Project>
|
41
src/Connected.Common.Model/Documents/DocumentArgs.cs
Normal file
41
src/Connected.Common.Model/Documents/DocumentArgs.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Connected.Annotations;
|
||||
using Connected.ServiceModel;
|
||||
|
||||
namespace Connected.Common.Documents;
|
||||
|
||||
public class DocumentArgs : Dto
|
||||
{
|
||||
[MaxLength(32)]
|
||||
public string? Code { get; set; } = default!;
|
||||
}
|
||||
|
||||
public abstract class InsertDocumentArgs : DocumentArgs
|
||||
{
|
||||
public int? Author { get; set; } = default!;
|
||||
|
||||
public DateTimeOffset? Created { get; set; }
|
||||
}
|
||||
|
||||
public abstract class UpdateDocumentArgs<TPrimaryKey> : DocumentArgs
|
||||
where TPrimaryKey : notnull
|
||||
{
|
||||
[MinValue(1)]
|
||||
public TPrimaryKey Id { get; set; } = default!;
|
||||
|
||||
public DateTimeOffset? Modified { get; set; }
|
||||
|
||||
public int? Owner { get; set; }
|
||||
}
|
||||
|
||||
public sealed class SelectDocumentArgs : Dto
|
||||
{
|
||||
[Required, MaxLength(32)]
|
||||
public string Domain { get; set; } = default!;
|
||||
|
||||
[Required, MaxLength(32)]
|
||||
public string Type { get; set; } = default!;
|
||||
|
||||
[Required, MaxLength(32)]
|
||||
public string Code { set; get; } = default!;
|
||||
}
|
41
src/Connected.Common.Model/Documents/IDocument.cs
Normal file
41
src/Connected.Common.Model/Documents/IDocument.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using Connected.Data;
|
||||
|
||||
namespace Connected.Common.Documents;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the base entity for all documents.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Document is primary entity of the business processes. It provides
|
||||
/// schema which is used in a business process lifecycle. Documents, apart from
|
||||
/// some basic validation, do not provide any specifiec business logic. Business
|
||||
/// processes are entirely responsible for the business logic.
|
||||
/// </remarks>
|
||||
public interface IDocument<TPrimaryKey> : IPrimaryKey<TPrimaryKey>
|
||||
where TPrimaryKey : notnull
|
||||
{
|
||||
/// <summary>
|
||||
/// The date when document was created.
|
||||
/// </summary>
|
||||
DateTimeOffset Created { get; init; }
|
||||
/// <summary>
|
||||
/// The date when document was last updated.
|
||||
/// </summary>
|
||||
DateTimeOffset? Modified { get; init; }
|
||||
/// <summary>
|
||||
/// The unique identifier of the document. This is
|
||||
/// usually set by a customer specific numbering system.
|
||||
/// </summary>
|
||||
string? Code { get; init; }
|
||||
/// <summary>
|
||||
/// The user which created the document. Can be null if document was created by the system.
|
||||
/// </summary>
|
||||
int? Author { get; init; }
|
||||
/// <summary>
|
||||
/// The user last modified the document. Once user modifies the document it becomes the Owner.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This behavior could be overriden in documents implementation.
|
||||
/// </remarks>
|
||||
int? Owner { get; init; }
|
||||
}
|
9
src/Connected.Common.Model/Documents/IDocumentService.cs
Normal file
9
src/Connected.Common.Model/Documents/IDocumentService.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using Connected.Notifications;
|
||||
|
||||
namespace Connected.Common.Documents;
|
||||
public interface IDocumentService<TDocumentPrimaryKey, TDetailPrimaryKey> : IServiceNotifications<TDocumentPrimaryKey>
|
||||
{
|
||||
event ServiceEventHandler<PrimaryKeyEventArgs<TDetailPrimaryKey>>? ItemInserted;
|
||||
event ServiceEventHandler<PrimaryKeyEventArgs<TDetailPrimaryKey>>? ItemUpdated;
|
||||
event ServiceEventHandler<PrimaryKeyEventArgs<TDetailPrimaryKey>>? ItemDeleted;
|
||||
}
|
6
src/Connected.Common.Model/Units.cs
Normal file
6
src/Connected.Common.Model/Units.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace Connected.Common;
|
||||
|
||||
public static class Units
|
||||
{
|
||||
public const int MB = 1024 * 1024;
|
||||
}
|
14
src/Connected.Common.Model/version.json
Normal file
14
src/Connected.Common.Model/version.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
|
||||
"version": "1.0-prerelease",
|
||||
"semVer1NumericIdentifierPadding": 4,
|
||||
"nugetPackageVersion": {
|
||||
"semVer": 2, // optional. Set to either 1 or 2 to control how the NuGet package version string is generated. Default is 1.
|
||||
"precision": "build" // optional. Use when you want to use a more or less precise package version than the default major.minor.build.
|
||||
},
|
||||
"cloudBuild": {
|
||||
"buildNumber": {
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
}
|
3
src/Connected.Common.Notes.Model/Boot.cs
Normal file
3
src/Connected.Common.Notes.Model/Boot.cs
Normal file
@ -0,0 +1,3 @@
|
||||
using Connected.Annotations;
|
||||
|
||||
[assembly: MicroService(MicroServiceType.Contract)]
|
@ -0,0 +1,44 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>Connected.Common.Notes</RootNamespace>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<Title>$(AssemblyName)</Title>
|
||||
<Authors>Tom PIT ltd</Authors>
|
||||
<Copyright>2022 Tom PIT ltd</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="Connected.Common.Model" Version="1.0.*-*" />
|
||||
<PackageReference Include="Nerdbank.GitVersioning"
|
||||
Version="3.5.119"
|
||||
PrivateAssets="all"
|
||||
Condition="!Exists('packages.config')" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\..\LICENSE">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
<None Include="..\..\README.md">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyPackages" AfterTargets="Pack">
|
||||
<Copy SourceFiles="$(OutputPath)..\$(PackageId).$(PackageVersion).nupkg" DestinationFolder="$([System.Environment]::GetEnvironmentVariable('LOCAL_NUGET'))" />
|
||||
<Copy SourceFiles="$(OutputPath)..\$(PackageId).$(PackageVersion).snupkg" DestinationFolder="$([System.Environment]::GetEnvironmentVariable('LOCAL_NUGET'))" />
|
||||
</Target>
|
||||
</Project>
|
9
src/Connected.Common.Notes.Model/INote.cs
Normal file
9
src/Connected.Common.Notes.Model/INote.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using Connected.Data;
|
||||
|
||||
namespace Connected.Common.Notes;
|
||||
|
||||
public interface INote : IEntityContainer<long>
|
||||
{
|
||||
int Author { get; init; }
|
||||
DateTimeOffset Created { get; init; }
|
||||
}
|
9
src/Connected.Common.Notes.Model/INoteSearch.cs
Normal file
9
src/Connected.Common.Notes.Model/INoteSearch.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using Connected.Data;
|
||||
|
||||
namespace Connected.Common.Notes;
|
||||
public interface INoteSearch : IEntityContainer<long>
|
||||
{
|
||||
int Author { get; init; }
|
||||
string Text { get; init; }
|
||||
DateTimeOffset Created { get; init; }
|
||||
}
|
24
src/Connected.Common.Notes.Model/INoteService.cs
Normal file
24
src/Connected.Common.Notes.Model/INoteService.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System.Collections.Immutable;
|
||||
using Connected.Annotations;
|
||||
using Connected.ServiceModel;
|
||||
using Connected.ServiceModel.Search;
|
||||
|
||||
namespace Connected.Common.Notes;
|
||||
|
||||
[Service]
|
||||
[ServiceUrl(NoteUrls.Notes)]
|
||||
public interface INoteService
|
||||
{
|
||||
Task<ImmutableList<INote>> Query(NoteArgs args);
|
||||
Task<INote?> Select(PrimaryKeyArgs<long> args);
|
||||
|
||||
Task<long> Insert(InsertNoteArgs args);
|
||||
Task Update(UpdateNoteArgs args);
|
||||
Task Delete(PrimaryKeyArgs<long> args);
|
||||
|
||||
Task<ImmutableList<INoteText>> QueryText(QueryNoteTextArgs args);
|
||||
[ServiceMethod(ServiceMethodVerbs.Get)]
|
||||
Task<INoteText?> SelectText(SelectNoteTextArgs args);
|
||||
|
||||
Task<ImmutableList<INoteSearch>> Search(SearchArgs args);
|
||||
}
|
10
src/Connected.Common.Notes.Model/INoteText.cs
Normal file
10
src/Connected.Common.Notes.Model/INoteText.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using Connected.Data;
|
||||
|
||||
namespace Connected.Common.Notes;
|
||||
|
||||
public interface INoteText : IPrimaryKey<long>
|
||||
{
|
||||
string Entity { get; init; }
|
||||
string EntityId { get; init; }
|
||||
string? Text { get; init; }
|
||||
}
|
44
src/Connected.Common.Notes.Model/NoteArgs.cs
Normal file
44
src/Connected.Common.Notes.Model/NoteArgs.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Connected.ServiceModel;
|
||||
|
||||
namespace Connected.Common.Notes;
|
||||
public class NoteArgs : Dto
|
||||
{
|
||||
[Required, MaxLength(128)]
|
||||
public string Entity { get; set; } = default!;
|
||||
|
||||
[Required, MaxLength(128)]
|
||||
public string PrimaryKey { get; set; } = default!;
|
||||
}
|
||||
|
||||
public class InsertNoteArgs : NoteArgs
|
||||
{
|
||||
[Range(1, int.MaxValue)]
|
||||
public int Author { get; set; }
|
||||
|
||||
public DateTimeOffset? Created { get; set; }
|
||||
|
||||
[Required, MaxLength(1024 * 1024)]
|
||||
public string Text { get; set; } = default!;
|
||||
}
|
||||
|
||||
public sealed class UpdateNoteArgs : PrimaryKeyArgs<long>
|
||||
{
|
||||
[Required, MaxLength(Units.MB)]
|
||||
public string Text { get; set; } = default!;
|
||||
}
|
||||
|
||||
public sealed class QueryNoteTextArgs : PrimaryKeyListArgs<long>
|
||||
{
|
||||
[Required, MaxLength(128)]
|
||||
public string Entity { get; set; } = default!;
|
||||
}
|
||||
|
||||
public sealed class SelectNoteTextArgs : PrimaryKeyArgs<long>
|
||||
{
|
||||
[Required, MaxLength(128)]
|
||||
public string Entity { get; set; } = default!;
|
||||
|
||||
[Required, MaxLength(128)]
|
||||
public string EntityId { get; set; } = default!;
|
||||
}
|
5
src/Connected.Common.Notes.Model/NoteUrls.cs
Normal file
5
src/Connected.Common.Notes.Model/NoteUrls.cs
Normal file
@ -0,0 +1,5 @@
|
||||
namespace Connected.Common.Notes;
|
||||
public static class NoteUrls
|
||||
{
|
||||
public const string Notes = $"{CommonRoutes.Common}/notes";
|
||||
}
|
14
src/Connected.Common.Notes.Model/version.json
Normal file
14
src/Connected.Common.Notes.Model/version.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
|
||||
"version": "1.0-prerelease",
|
||||
"semVer1NumericIdentifierPadding": 4,
|
||||
"nugetPackageVersion": {
|
||||
"semVer": 2, // optional. Set to either 1 or 2 to control how the NuGet package version string is generated. Default is 1.
|
||||
"precision": "build" // optional. Use when you want to use a more or less precise package version than the default major.minor.build.
|
||||
},
|
||||
"cloudBuild": {
|
||||
"buildNumber": {
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
}
|
3
src/Connected.Common.Notes/Bootstrap.cs
Normal file
3
src/Connected.Common.Notes/Bootstrap.cs
Normal file
@ -0,0 +1,3 @@
|
||||
using Connected.Annotations;
|
||||
|
||||
[assembly: MicroService(MicroServiceType.Sys)]
|
44
src/Connected.Common.Notes/Connected.Common.Notes.csproj
Normal file
44
src/Connected.Common.Notes/Connected.Common.Notes.csproj
Normal file
@ -0,0 +1,44 @@
|
||||
<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 ltd</Authors>
|
||||
<Copyright>2022 Tom PIT ltd</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="Connected.Common.Notes.Model" Version="1.0.*-*" />
|
||||
<PackageReference Include="Connected.Common" Version="1.0.*-*" />
|
||||
<PackageReference Include="Nerdbank.GitVersioning"
|
||||
Version="3.5.119"
|
||||
PrivateAssets="all"
|
||||
Condition="!Exists('packages.config')" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\..\LICENSE">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
<None Include="..\..\README.md">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyPackages" AfterTargets="Pack">
|
||||
<Copy SourceFiles="$(OutputPath)..\$(PackageId).$(PackageVersion).nupkg" DestinationFolder="$([System.Environment]::GetEnvironmentVariable('LOCAL_NUGET'))" />
|
||||
<Copy SourceFiles="$(OutputPath)..\$(PackageId).$(PackageVersion).snupkg" DestinationFolder="$([System.Environment]::GetEnvironmentVariable('LOCAL_NUGET'))" />
|
||||
</Target>
|
||||
</Project>
|
17
src/Connected.Common.Notes/Note.cs
Normal file
17
src/Connected.Common.Notes/Note.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using Connected.Annotations;
|
||||
using Connected.Entities.Annotations;
|
||||
using Connected.Entities.Containers;
|
||||
|
||||
namespace Connected.Common.Notes;
|
||||
|
||||
[Table(Schema = Constants.CommonSchema)]
|
||||
public sealed record Note : ContainerEntity<long>, INote
|
||||
{
|
||||
public const string EntityKey = $"{Constants.CommonSchema}.{nameof(Note)}";
|
||||
|
||||
[Ordinal(0)]
|
||||
public int Author { get; init; }
|
||||
|
||||
[Ordinal(1)]
|
||||
public DateTimeOffset Created { get; init; }
|
||||
}
|
240
src/Connected.Common.Notes/NoteOps.cs
Normal file
240
src/Connected.Common.Notes/NoteOps.cs
Normal file
@ -0,0 +1,240 @@
|
||||
using System.Collections.Immutable;
|
||||
using Connected.Caching;
|
||||
using Connected.Entities;
|
||||
using Connected.Entities.Storage;
|
||||
using Connected.Notifications;
|
||||
using Connected.Notifications.Events;
|
||||
using Connected.ServiceModel;
|
||||
using Connected.ServiceModel.Search;
|
||||
using Connected.Services;
|
||||
|
||||
namespace Connected.Common.Notes;
|
||||
internal static class NoteOps
|
||||
{
|
||||
/// <summary>
|
||||
/// Deletes the note entity, its text and search entity from the storage.
|
||||
/// </summary>
|
||||
public class Delete : ServiceAction<PrimaryKeyArgs<long>>
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a new <see cref="Delete"/> instance.
|
||||
/// </summary>
|
||||
public Delete(IStorageProvider storage, IEventService events)
|
||||
{
|
||||
Storage = storage;
|
||||
Events = events;
|
||||
}
|
||||
|
||||
private IStorageProvider Storage { get; }
|
||||
private IEventService Events { get; }
|
||||
|
||||
protected override async Task OnInvoke()
|
||||
{
|
||||
/*
|
||||
* First delete the entity.
|
||||
*/
|
||||
await Storage.Open<Note>().Update(Arguments.AsEntity<Note>(State.Deleted));
|
||||
/*
|
||||
* Delete the note's text.
|
||||
*/
|
||||
await Storage.Open<NoteText>().Update(Arguments.AsEntity<NoteText>(State.Deleted));
|
||||
/*
|
||||
* Delete search entry.
|
||||
*/
|
||||
await Storage.Open<NoteSearch>().Update(Arguments.AsEntity<NoteSearch>(State.Deleted));
|
||||
}
|
||||
|
||||
protected override async Task OnCommitted()
|
||||
{
|
||||
/*
|
||||
* We are triggering notify only for the entity, not for text and search transactions.
|
||||
* Note that we don't cache text and search entries. They are read from the storage every time
|
||||
* it is requested.
|
||||
*/
|
||||
await Events.Enqueue(this, typeof(NoteService), nameof(IServiceNotifications<long>.Deleted), Arguments);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Inserts a new note entity into storage.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This class inserts a new <see cref="INote"/> entity into storage, then inserts text
|
||||
/// into table storage and the creates a search index entry.
|
||||
/// </remarks>
|
||||
public sealed class Insert : ServiceFunction<InsertNoteArgs, long>
|
||||
{
|
||||
public Insert(IStorageProvider storage, IEventService events)
|
||||
{
|
||||
Storage = storage;
|
||||
Events = events;
|
||||
}
|
||||
|
||||
private IStorageProvider Storage { get; }
|
||||
private IEventService Events { get; }
|
||||
|
||||
protected override async Task<long> OnInvoke()
|
||||
{
|
||||
/*
|
||||
* This call inserts a new record into storage (database) and returns its id.
|
||||
*/
|
||||
var result = await Storage.Open<Note>().Update(Arguments.AsEntity<Note>(State.New));
|
||||
/*
|
||||
* We'll be using a newly inserted id to create a new record in the table
|
||||
* storage for text.
|
||||
*/
|
||||
await Storage.Open<NoteText>().Update(Arguments.AsEntity<NoteText>(State.New, new { result.Id }));
|
||||
/*
|
||||
* And create entry in the search index.
|
||||
*/
|
||||
//await Storage.Open<NoteSearch>().Update(Arguments.AsEntity<NoteSearch>(State.New, new { result.Id }));
|
||||
|
||||
return result.Id;
|
||||
}
|
||||
|
||||
protected override async Task OnCommitted()
|
||||
{
|
||||
await Events.Enqueue(this, typeof(NoteService), nameof(IServiceNotifications<long>.Inserted), new PrimaryKeyArgs<long> { Id = Result });
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Update : ServiceAction<UpdateNoteArgs>
|
||||
{
|
||||
public Update(IStorageProvider storage, ICacheContext cache, IEventService events, INoteService notes)
|
||||
{
|
||||
Storage = storage;
|
||||
Cache = cache;
|
||||
Events = events;
|
||||
Notes = notes;
|
||||
}
|
||||
|
||||
private IStorageProvider Storage { get; }
|
||||
private ICacheContext Cache { get; }
|
||||
private IEventService Events { get; }
|
||||
private INoteService Notes { get; }
|
||||
|
||||
protected override async Task OnInvoke()
|
||||
{
|
||||
if (await Notes.Select(Arguments.Id) is not INote entity)
|
||||
return;
|
||||
|
||||
await Storage.Open<Note>().Update(Arguments.AsEntity<Note>(State.Default), Arguments, async () =>
|
||||
{
|
||||
await Cache.Remove(Note.EntityKey, Arguments.Id);
|
||||
|
||||
return (await Notes.Select(Arguments.Id)) as Note;
|
||||
});
|
||||
|
||||
await Storage.Open<NoteText>().Update(Arguments.AsEntity<NoteText>(State.Default), Arguments, async () =>
|
||||
{
|
||||
await Cache.Remove(NoteText.EntityKey, Arguments.Id);
|
||||
|
||||
return (await Notes.SelectText(new SelectNoteTextArgs
|
||||
{
|
||||
Entity = entity.Entity,
|
||||
EntityId = entity.EntityId,
|
||||
Id = Arguments.Id
|
||||
})) as NoteText;
|
||||
});
|
||||
|
||||
await Storage.Open<NoteSearch>().Update(Arguments.AsEntity<NoteSearch>(State.Default));
|
||||
}
|
||||
|
||||
protected override async Task OnCommitted()
|
||||
{
|
||||
await Cache.Remove(Note.EntityKey, Arguments.Id);
|
||||
await Cache.Remove(NoteText.EntityKey, Arguments.Id);
|
||||
|
||||
await Events.Enqueue(this, typeof(NoteService), nameof(IServiceNotifications<long>.Updated), new PrimaryKeyArgs<long> { Id = Arguments.Id });
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Query : ServiceFunction<NoteArgs, ImmutableList<INote>>
|
||||
{
|
||||
public Query(IStorageProvider provider)
|
||||
{
|
||||
Provider = provider;
|
||||
}
|
||||
|
||||
private IStorageProvider Provider { get; }
|
||||
|
||||
protected override async Task<ImmutableList<INote>> OnInvoke()
|
||||
{
|
||||
return await (from dc in Provider.Open<Note>() select dc).AsEntities<INote>();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Select : ServiceFunction<PrimaryKeyArgs<long>, INote>
|
||||
{
|
||||
public Select(IStorageProvider provider, ICacheContext cache)
|
||||
{
|
||||
Provider = provider;
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private IStorageProvider Provider { get; }
|
||||
private ICacheContext Cache { get; }
|
||||
|
||||
protected override Task<INote?> OnInvoke()
|
||||
{
|
||||
return Cache.Get<INote>(Note.EntityKey, Arguments.Id,
|
||||
async (f) =>
|
||||
{
|
||||
return await (from dc in Provider.Open<Note>() where dc.Id == Arguments.Id select dc).AsEntity();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Search : ServiceFunction<SearchArgs, ImmutableList<INoteSearch>>
|
||||
{
|
||||
public Search(IStorageProvider storage)
|
||||
{
|
||||
Storage = storage;
|
||||
}
|
||||
|
||||
private IStorageProvider Storage { get; }
|
||||
|
||||
protected override async Task<ImmutableList<INoteSearch>?> OnInvoke()
|
||||
{
|
||||
return await (from dc in Storage.Open<NoteSearch>()
|
||||
where dc.Text.Contains(Arguments.Text)
|
||||
select dc).AsEntities<INoteSearch>();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class QueryText : ServiceFunction<QueryNoteTextArgs, ImmutableList<INoteText>>
|
||||
{
|
||||
public QueryText(IStorageProvider storage)
|
||||
{
|
||||
Storage = storage;
|
||||
}
|
||||
|
||||
private IStorageProvider Storage { get; }
|
||||
|
||||
protected override async Task<ImmutableList<INoteText>?> OnInvoke()
|
||||
{
|
||||
return await (from dc in Storage.Open<NoteText>()
|
||||
where string.Equals(dc.Entity, Arguments.Entity, StringComparison.Ordinal)
|
||||
&& Arguments.IdList.Any(f => f == dc.Id)
|
||||
select dc).AsEntities<INoteText>();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SelectText : ServiceFunction<SelectNoteTextArgs, INoteText>
|
||||
{
|
||||
public SelectText(IStorageProvider provider)
|
||||
{
|
||||
Provider = provider;
|
||||
}
|
||||
|
||||
private IStorageProvider Provider { get; }
|
||||
|
||||
protected override async Task<INoteText?> OnInvoke()
|
||||
{
|
||||
return await (from dc in Provider.Open<NoteText>()
|
||||
where string.Equals(dc.Entity, Arguments.Entity)
|
||||
&& string.Equals(dc.EntityId, Arguments.EntityId)
|
||||
&& dc.Id == Arguments.Id
|
||||
select dc).AsEntity();
|
||||
}
|
||||
}
|
||||
}
|
17
src/Connected.Common.Notes/NoteSearch.cs
Normal file
17
src/Connected.Common.Notes/NoteSearch.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using Connected.Annotations;
|
||||
using Connected.Entities.Annotations;
|
||||
using Connected.Entities.Containers;
|
||||
|
||||
namespace Connected.Common.Notes;
|
||||
[Persistence(Persistence = ColumnPersistence.InMemory)]
|
||||
public record NoteSearch : ContainerEntity<long>, INoteSearch
|
||||
{
|
||||
[Ordinal(0)]
|
||||
public int Author { get; init; }
|
||||
|
||||
[Ordinal(1), Length(Units.MB)]
|
||||
public string Text { get; init; } = default!;
|
||||
|
||||
[Ordinal(2)]
|
||||
public DateTimeOffset Created { get; init; }
|
||||
}
|
61
src/Connected.Common.Notes/NoteService.cs
Normal file
61
src/Connected.Common.Notes/NoteService.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System.Collections.Immutable;
|
||||
using Connected.ServiceModel;
|
||||
using Connected.ServiceModel.Search;
|
||||
using Connected.Services;
|
||||
|
||||
namespace Connected.Common.Notes;
|
||||
internal sealed class NoteService : Service, INoteService
|
||||
{
|
||||
public NoteService(IContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task Delete(PrimaryKeyArgs<long> args)
|
||||
{
|
||||
await Invoke(GetOperation<NoteOps.Delete>(), args);
|
||||
}
|
||||
|
||||
public async Task<long> Insert(InsertNoteArgs args)
|
||||
{
|
||||
return await Invoke(GetOperation<NoteOps.Insert>(), args);
|
||||
}
|
||||
|
||||
public async Task<ImmutableList<INote>> Query(NoteArgs args)
|
||||
{
|
||||
return await Invoke(GetOperation<NoteOps.Query>(), args);
|
||||
}
|
||||
|
||||
public async Task<ImmutableList<INoteText>> QueryText(QueryNoteTextArgs args)
|
||||
{
|
||||
return await Invoke(GetOperation<NoteOps.QueryText>(), args);
|
||||
}
|
||||
|
||||
public async Task<ImmutableList<INoteSearch>> Search(SearchArgs args)
|
||||
{
|
||||
return await Invoke(GetOperation<NoteOps.Search>(), args);
|
||||
}
|
||||
|
||||
public async Task<INote?> Select(PrimaryKeyArgs<long> args)
|
||||
{
|
||||
return await Invoke(GetOperation<NoteOps.Select>(), args);
|
||||
}
|
||||
|
||||
public async Task<INoteText?> SelectText(SelectNoteTextArgs args)
|
||||
{
|
||||
await Invoke(GetOperation<NoteOps.Insert>(), new InsertNoteArgs
|
||||
{
|
||||
Entity = "Entity",
|
||||
PrimaryKey = "10",
|
||||
Author = 10,
|
||||
Created = DateTime.UtcNow,
|
||||
Text = "Note text"
|
||||
}, "Insert");
|
||||
|
||||
return await Invoke(GetOperation<NoteOps.SelectText>(), args);
|
||||
}
|
||||
|
||||
public async Task Update(UpdateNoteArgs args)
|
||||
{
|
||||
await Invoke(GetOperation<NoteOps.Update>(), args);
|
||||
}
|
||||
}
|
20
src/Connected.Common.Notes/NoteText.cs
Normal file
20
src/Connected.Common.Notes/NoteText.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Connected.Annotations;
|
||||
using Connected.Entities.Annotations;
|
||||
using Connected.ServiceModel.Annotations;
|
||||
using Connected.ServiceModel.Data;
|
||||
|
||||
namespace Connected.Common.Notes;
|
||||
public sealed record NoteText : TableEntity<long, string>, INoteText
|
||||
{
|
||||
public const string EntityKey = $"{Constants.CommonSchema}.{nameof(NoteText)}";
|
||||
|
||||
[Ordinal(-50000), PartitionKey, MaxLength(128)]
|
||||
public string Entity { get; init; } = default!;
|
||||
|
||||
[Ordinal(-49000), PrimaryKey, MaxLength(128)]
|
||||
public string EntityId { get; init; } = default!;
|
||||
|
||||
[Ordinal(0), Length(Units.MB), Nullable]
|
||||
public string? Text { get; init; }
|
||||
}
|
14
src/Connected.Common.Notes/version.json
Normal file
14
src/Connected.Common.Notes/version.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
|
||||
"version": "1.0-prerelease",
|
||||
"semVer1NumericIdentifierPadding": 4,
|
||||
"nugetPackageVersion": {
|
||||
"semVer": 2, // optional. Set to either 1 or 2 to control how the NuGet package version string is generated. Default is 1.
|
||||
"precision": "build" // optional. Use when you want to use a more or less precise package version than the default major.minor.build.
|
||||
},
|
||||
"cloudBuild": {
|
||||
"buildNumber": {
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>Connected.Common.Numbering</RootNamespace>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<Title>$(AssemblyName)</Title>
|
||||
<Authors>Tom PIT ltd</Authors>
|
||||
<Copyright>2022 Tom PIT ltd</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="Connected.Common.Numbering.Model" Version="1.0.*-*"/>
|
||||
<PackageReference Include="Nerdbank.GitVersioning"
|
||||
Version="3.5.119"
|
||||
PrivateAssets="all"
|
||||
Condition="!Exists('packages.config')" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\..\LICENSE">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
<None Include="..\..\README.md">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyPackages" AfterTargets="Pack">
|
||||
<Copy SourceFiles="$(OutputPath)..\$(PackageId).$(PackageVersion).nupkg" DestinationFolder="$([System.Environment]::GetEnvironmentVariable('LOCAL_NUGET'))" />
|
||||
<Copy SourceFiles="$(OutputPath)..\$(PackageId).$(PackageVersion).snupkg" DestinationFolder="$([System.Environment]::GetEnvironmentVariable('LOCAL_NUGET'))" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
@ -0,0 +1,14 @@
|
||||
namespace Connected.Common.Numbering;
|
||||
/// <summary>
|
||||
/// Provides middleware for providing a numbering algorithm.
|
||||
/// </summary>
|
||||
public interface INumberingProvider : IMiddleware
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new value based on the specified arguments.
|
||||
/// </summary>
|
||||
/// <param name="args">The arguments providing information about the entity for which
|
||||
/// value need to be provided.</param>
|
||||
/// <returns>A new value if the numbering is supported by the middleware, <c>null</c> otherwise.</returns>
|
||||
Task<string> Invoke(NumberingCalculateArgs args);
|
||||
}
|
14
src/Connected.Common.Numbering.Middleware/version.json
Normal file
14
src/Connected.Common.Numbering.Middleware/version.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
|
||||
"version": "1.0-prerelease",
|
||||
"semVer1NumericIdentifierPadding": 4,
|
||||
"nugetPackageVersion": {
|
||||
"semVer": 2, // optional. Set to either 1 or 2 to control how the NuGet package version string is generated. Default is 1.
|
||||
"precision": "build" // optional. Use when you want to use a more or less precise package version than the default major.minor.build.
|
||||
},
|
||||
"cloudBuild": {
|
||||
"buildNumber": {
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>Connected.Common.Numbering</RootNamespace>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<Title>$(AssemblyName)</Title>
|
||||
<Authors>Tom PIT ltd</Authors>
|
||||
<Copyright>2022 Tom PIT ltd</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="Connected.Services" Version ="1.0.*-*"/>
|
||||
<PackageReference Include="Nerdbank.GitVersioning"
|
||||
Version="3.5.119"
|
||||
PrivateAssets="all"
|
||||
Condition="!Exists('packages.config')" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\..\LICENSE">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
<None Include="..\..\README.md">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyPackages" AfterTargets="Pack">
|
||||
<Copy SourceFiles="$(OutputPath)..\$(PackageId).$(PackageVersion).nupkg" DestinationFolder="$([System.Environment]::GetEnvironmentVariable('LOCAL_NUGET'))" />
|
||||
<Copy SourceFiles="$(OutputPath)..\$(PackageId).$(PackageVersion).snupkg" DestinationFolder="$([System.Environment]::GetEnvironmentVariable('LOCAL_NUGET'))" />
|
||||
</Target>
|
||||
</Project>
|
8
src/Connected.Common.Numbering.Model/INumbering.cs
Normal file
8
src/Connected.Common.Numbering.Model/INumbering.cs
Normal file
@ -0,0 +1,8 @@
|
||||
using Connected.Data;
|
||||
|
||||
namespace Connected.Common.Numbering;
|
||||
public interface INumbering : IPrimaryKey<int>
|
||||
{
|
||||
string Entity { get; init; }
|
||||
string Value { get; init; }
|
||||
}
|
17
src/Connected.Common.Numbering.Model/INumberingService.cs
Normal file
17
src/Connected.Common.Numbering.Model/INumberingService.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using Connected.Annotations;
|
||||
using Connected.ServiceModel;
|
||||
|
||||
namespace Connected.Common.Numbering;
|
||||
[Service]
|
||||
[ServiceUrl(NumberingUrls.Numbering)]
|
||||
public interface INumberingService
|
||||
{
|
||||
[ServiceMethod(ServiceMethodVerbs.Get | ServiceMethodVerbs.Post)]
|
||||
Task<string> Calculate(NumberingCalculateArgs args);
|
||||
|
||||
[ServiceMethod(ServiceMethodVerbs.Get | ServiceMethodVerbs.Post)]
|
||||
Task<INumbering?> Select(NumberingSelectArgs args);
|
||||
|
||||
[ServiceMethod(ServiceMethodVerbs.Get | ServiceMethodVerbs.Post)]
|
||||
Task<INumbering?> Select(PrimaryKeyArgs<int> args);
|
||||
}
|
15
src/Connected.Common.Numbering.Model/NumberingArgs.cs
Normal file
15
src/Connected.Common.Numbering.Model/NumberingArgs.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Connected.ServiceModel;
|
||||
|
||||
namespace Connected.Common.Numbering;
|
||||
public sealed class NumberingCalculateArgs : Dto
|
||||
{
|
||||
[Required, MaxLength(128)]
|
||||
public string Entity { get; set; } = default!;
|
||||
}
|
||||
|
||||
public sealed class NumberingSelectArgs : Dto
|
||||
{
|
||||
[Required, MaxLength(128)]
|
||||
public string Entity { get; set; } = default!;
|
||||
}
|
5
src/Connected.Common.Numbering.Model/NumberingUrls.cs
Normal file
5
src/Connected.Common.Numbering.Model/NumberingUrls.cs
Normal file
@ -0,0 +1,5 @@
|
||||
namespace Connected.Common.Numbering;
|
||||
public static class NumberingUrls
|
||||
{
|
||||
public const string Numbering = "common/numbering";
|
||||
}
|
14
src/Connected.Common.Numbering.Model/version.json
Normal file
14
src/Connected.Common.Numbering.Model/version.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
|
||||
"version": "1.0-prerelease",
|
||||
"semVer1NumericIdentifierPadding": 4,
|
||||
"nugetPackageVersion": {
|
||||
"semVer": 2, // optional. Set to either 1 or 2 to control how the NuGet package version string is generated. Default is 1.
|
||||
"precision": "build" // optional. Use when you want to use a more or less precise package version than the default major.minor.build.
|
||||
},
|
||||
"cloudBuild": {
|
||||
"buildNumber": {
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<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 ltd</Authors>
|
||||
<Copyright>2022 Tom PIT ltd</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="Connected.Common.Numbering.Middleware" Version="1.0.*-*" />
|
||||
<PackageReference Include="Connected.Common.Numbering.Model" Version="1.0.*-*" />
|
||||
<PackageReference Include="Connected.Common" Version="1.0.*-*" />
|
||||
<PackageReference Include="Nerdbank.GitVersioning"
|
||||
Version="3.5.119"
|
||||
PrivateAssets="all"
|
||||
Condition="!Exists('packages.config')" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\..\LICENSE">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
<None Include="..\..\README.md">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyPackages" AfterTargets="Pack">
|
||||
<Copy SourceFiles="$(OutputPath)..\$(PackageId).$(PackageVersion).nupkg" DestinationFolder="$([System.Environment]::GetEnvironmentVariable('LOCAL_NUGET'))" />
|
||||
<Copy SourceFiles="$(OutputPath)..\$(PackageId).$(PackageVersion).snupkg" DestinationFolder="$([System.Environment]::GetEnvironmentVariable('LOCAL_NUGET'))" />
|
||||
</Target>
|
||||
</Project>
|
23
src/Connected.Common.Numbering/DefaultProvider.cs
Normal file
23
src/Connected.Common.Numbering/DefaultProvider.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using Connected.Annotations;
|
||||
using Connected.Middleware;
|
||||
|
||||
namespace Connected.Common.Numbering;
|
||||
|
||||
[Priority(0)]
|
||||
internal sealed class DefaultProvider : MiddlewareComponent, INumberingProvider
|
||||
{
|
||||
public DefaultProvider(INumberingService numbering)
|
||||
{
|
||||
Numbering = numbering;
|
||||
}
|
||||
|
||||
private INumberingService Numbering { get; }
|
||||
|
||||
public async Task<string> Invoke(NumberingCalculateArgs args)
|
||||
{
|
||||
if (Numbering is not NumberingService service)
|
||||
throw new InvalidCastException(nameof(NumberingService));
|
||||
|
||||
return await service.NextValue(args);
|
||||
}
|
||||
}
|
15
src/Connected.Common.Numbering/Numbering.cs
Normal file
15
src/Connected.Common.Numbering/Numbering.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Connected.Annotations;
|
||||
using Connected.Entities.Annotations;
|
||||
using Connected.Entities.Consistency;
|
||||
|
||||
namespace Connected.Common.Numbering;
|
||||
[Table(Schema = CommonSchemas.CommonSchema)]
|
||||
internal sealed record Numbering : ConsistentEntity<int>, INumbering
|
||||
{
|
||||
[Ordinal(0), MaxLength(128), Index(Name = $"ui_{CommonSchemas.CommonSchema}_numbering_entity")]
|
||||
public string Entity { get; init; } = default!;
|
||||
|
||||
[Ordinal(1), MaxLength(128)]
|
||||
public string Value { get; init; } = default!;
|
||||
}
|
137
src/Connected.Common.Numbering/NumberingOps.cs
Normal file
137
src/Connected.Common.Numbering/NumberingOps.cs
Normal file
@ -0,0 +1,137 @@
|
||||
using Connected.Entities;
|
||||
using Connected.Entities.Storage;
|
||||
using Connected.Interop;
|
||||
using Connected.Middleware;
|
||||
using Connected.ServiceModel;
|
||||
using Connected.Services;
|
||||
|
||||
namespace Connected.Common.Numbering;
|
||||
internal sealed class NumberingOps
|
||||
{
|
||||
public sealed class Calculate : ServiceFunction<NumberingCalculateArgs, string>
|
||||
{
|
||||
public Calculate(IMiddlewareService middleware)
|
||||
{
|
||||
Middleware = middleware;
|
||||
}
|
||||
|
||||
private IMiddlewareService Middleware { get; }
|
||||
|
||||
protected override async Task<string?> OnInvoke()
|
||||
{
|
||||
foreach (var middleware in await Middleware.Query<INumberingProvider>())
|
||||
{
|
||||
if (await middleware.Invoke(Arguments) is string result && !string.IsNullOrEmpty(result))
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class NextValue : ServiceFunction<NumberingCalculateArgs, string>
|
||||
{
|
||||
public NextValue(IStorageProvider storage, INumberingService numbering)
|
||||
{
|
||||
Storage = storage;
|
||||
Numbering = numbering;
|
||||
}
|
||||
|
||||
private IStorageProvider Storage { get; }
|
||||
private INumberingService Numbering { get; }
|
||||
|
||||
protected override async Task<string?> OnInvoke()
|
||||
{
|
||||
var result = await Prepare();
|
||||
|
||||
await Storage.Open<Numbering>().Update(result, Arguments,
|
||||
async () =>
|
||||
{
|
||||
result = await Prepare();
|
||||
|
||||
return result;
|
||||
},
|
||||
async (f) =>
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
return f;
|
||||
});
|
||||
|
||||
return result.Value;
|
||||
}
|
||||
|
||||
private async Task<Numbering> Prepare()
|
||||
{
|
||||
var current = await Numbering.Select(Arguments.AsArguments<NumberingSelectArgs>());
|
||||
|
||||
if (current is null)
|
||||
{
|
||||
var id = await TryInsert();
|
||||
|
||||
if (id == 0)
|
||||
current = await Numbering.Select(Arguments.AsArguments<NumberingSelectArgs>());
|
||||
else
|
||||
current = await Numbering.Select(id);
|
||||
}
|
||||
|
||||
if (current is null)
|
||||
throw new NullReferenceException(nameof(INumbering));
|
||||
|
||||
var newValue = string.Empty;
|
||||
|
||||
if (TypeConversion.TryConvert(current.Value, out long existingValue))
|
||||
newValue = existingValue++.ToString();
|
||||
else
|
||||
newValue = current.Value;
|
||||
|
||||
return (Numbering)current with { Value = newValue };
|
||||
}
|
||||
|
||||
private async Task<int> TryInsert()
|
||||
{
|
||||
try
|
||||
{
|
||||
return (await Storage.Open<Numbering>().Update(Arguments.AsEntity<Numbering>(State.New))).Id;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SelectByEntity : ServiceFunction<NumberingSelectArgs, INumbering>
|
||||
{
|
||||
public SelectByEntity(IStorageProvider storage)
|
||||
{
|
||||
Storage = storage;
|
||||
}
|
||||
|
||||
private IStorageProvider Storage { get; }
|
||||
|
||||
protected override async Task<INumbering?> OnInvoke()
|
||||
{
|
||||
return await (from e in Storage.Open<Numbering>()
|
||||
where string.Equals(e.Entity, Arguments.Entity, StringComparison.OrdinalIgnoreCase)
|
||||
select e).AsEntity();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Select : ServiceFunction<PrimaryKeyArgs<int>, INumbering>
|
||||
{
|
||||
public Select(IStorageProvider storage)
|
||||
{
|
||||
Storage = storage;
|
||||
}
|
||||
|
||||
private IStorageProvider Storage { get; }
|
||||
|
||||
protected override async Task<INumbering?> OnInvoke()
|
||||
{
|
||||
return await (from e in Storage.Open<Numbering>()
|
||||
where e.Id == Arguments.Id
|
||||
select e).AsEntity();
|
||||
}
|
||||
}
|
||||
}
|
31
src/Connected.Common.Numbering/NumberingService.cs
Normal file
31
src/Connected.Common.Numbering/NumberingService.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using Connected.ServiceModel;
|
||||
using Connected.Services;
|
||||
using Ops = Connected.Common.Numbering.NumberingOps;
|
||||
|
||||
namespace Connected.Common.Numbering;
|
||||
internal sealed class NumberingService : Service, INumberingService
|
||||
{
|
||||
public NumberingService(IContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<string> Calculate(NumberingCalculateArgs args)
|
||||
{
|
||||
return await Invoke(GetOperation<Ops.Calculate>(), args);
|
||||
}
|
||||
|
||||
public async Task<INumbering?> Select(NumberingSelectArgs args)
|
||||
{
|
||||
return await Invoke(GetOperation<Ops.SelectByEntity>(), args);
|
||||
}
|
||||
|
||||
public async Task<INumbering?> Select(PrimaryKeyArgs<int> args)
|
||||
{
|
||||
return await Invoke(GetOperation<Ops.Select>(), args);
|
||||
}
|
||||
|
||||
internal async Task<string> NextValue(NumberingCalculateArgs args)
|
||||
{
|
||||
return await Invoke(GetOperation<Ops.NextValue>(), args);
|
||||
}
|
||||
}
|
14
src/Connected.Common.Numbering/version.json
Normal file
14
src/Connected.Common.Numbering/version.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
|
||||
"version": "1.0-prerelease",
|
||||
"semVer1NumericIdentifierPadding": 4,
|
||||
"nugetPackageVersion": {
|
||||
"semVer": 2, // optional. Set to either 1 or 2 to control how the NuGet package version string is generated. Default is 1.
|
||||
"precision": "build" // optional. Use when you want to use a more or less precise package version than the default major.minor.build.
|
||||
},
|
||||
"cloudBuild": {
|
||||
"buildNumber": {
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Events\" />
|
||||
<Folder Include="Documents\" />
|
||||
<Folder Include="Notifications\" />
|
||||
<Folder Include="Tasks\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\connected.framework\src\Connected.Entities\Connected.Entities.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
114
src/Connected.Common.Workspace/IWorkspaceEntity.cs
Normal file
114
src/Connected.Common.Workspace/IWorkspaceEntity.cs
Normal file
@ -0,0 +1,114 @@
|
||||
using Connected.Common.Workspace.Messaging;
|
||||
using Connected.Entities.Consistency;
|
||||
using Connected.Security.Identity;
|
||||
|
||||
namespace Connected.Common.Workspace;
|
||||
/// <summary>
|
||||
/// Specifies the read state of the <see cref="IWorkspaceEntity"/> entity.
|
||||
/// </summary>
|
||||
public enum ReadStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// The entity has not been read by the <see cref="IWorkspaceEntity.IdentityId"/>.
|
||||
/// </summary>
|
||||
New = 0,
|
||||
/// <summary>
|
||||
/// The entity has been read by the <see cref="IWorkspaceEntity.IdentityId"/>.
|
||||
/// </summary>
|
||||
Read = 1
|
||||
}
|
||||
/// <summary>
|
||||
/// Specifies what kind of actions can be performed by the identity on each <see cref="IWorkspaceEntity"/> entity.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum IdentityVerbs
|
||||
{
|
||||
/// <summary>
|
||||
/// The entity is read only. Identity cannot perform any actions on it
|
||||
/// except reading.
|
||||
/// </summary>
|
||||
ReadOnly = 0,
|
||||
/// <summary>
|
||||
/// The entity can be deleted from the workspace by the identity.
|
||||
/// </summary>
|
||||
AllowDelete = 1
|
||||
}
|
||||
/// <summary>
|
||||
/// Represents a base entity for all workspace related entities.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Digital Workspace offers many different services serving different purposes. Each service introduces
|
||||
/// its own set of entities. All top level entities inherits from this entity, for example <see cref="IMessage"/>.
|
||||
/// </remarks>
|
||||
public interface IWorkspaceEntity : IConsistentEntity<long>
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of identity to which workspace entity belongs to (like Recipient).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The most common type of the identity entity is <see cref="IUser"/>.
|
||||
/// </remarks>
|
||||
string IdentityEntity { get; init; }
|
||||
/// <summary>
|
||||
/// The id of the identity to which workspace entity belongs. This could be the id of the user,
|
||||
/// device, organization unit or any other entity id.
|
||||
/// </summary>
|
||||
string IdentityId { get; init; }
|
||||
/// <summary>
|
||||
/// The date and time the workspace entity has been created.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This value can represent the value when the origin entity has been created or when
|
||||
/// the workspace entity has been created. This value is specific to the service implementation.
|
||||
/// </remarks>
|
||||
DateTimeOffset Created { get; init; }
|
||||
/// <summary>
|
||||
/// The date and time the workspace entity expires.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Expired workspace entities are automatically deleted from the system. If this value is <c>null</c>,
|
||||
/// workspace entity never expires.
|
||||
/// </remarks>
|
||||
DateTimeOffset? Expires { get; init; }
|
||||
/// <summary>
|
||||
/// The title of the entity.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This should be as short as possible so user can quickly recognize the nature of the entity.
|
||||
/// </remarks>
|
||||
string Title { get; init; }
|
||||
/// <summary>
|
||||
/// The short description of the entity. Can be <c>null</c>.
|
||||
/// </summary>
|
||||
string? Description { get; init; }
|
||||
/// <summary>
|
||||
/// The read status of the entity. This serves primary for a UI purpose to enable visual feedback
|
||||
/// to the user.
|
||||
/// </summary>
|
||||
ReadStatus Status { get; init; }
|
||||
/// <summary>
|
||||
/// The domain to which this entity belongs.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Each workspace entity should have one and only one domain to which it originates.
|
||||
/// </remarks>
|
||||
string Domain { get; init; }
|
||||
/// <summary>
|
||||
/// Zero or more tags that represents additional meta data of the workspace entity.
|
||||
/// </summary>
|
||||
string? Tags { get; init; }
|
||||
/// <summary>
|
||||
/// The entity which triggered this workspace entity to be created. Can be <c>null</c> if it was
|
||||
/// automatically generated by the underlying system.
|
||||
/// </summary>
|
||||
string? AuthorEntity { get; init; }
|
||||
/// <summary>
|
||||
/// The id of the entity which created this workspace entity. Can be <c>null</c> if it was
|
||||
/// automatically generated by the underlying system.
|
||||
/// </summary>
|
||||
string? AuthorId { get; init; }
|
||||
/// <summary>
|
||||
/// Actions that can be performed by the identity on the workspace entity.
|
||||
/// </summary>
|
||||
IdentityVerbs Verbs { get; init; }
|
||||
}
|
22
src/Connected.Common.Workspace/Identities/IIdentity.cs
Normal file
22
src/Connected.Common.Workspace/Identities/IIdentity.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using Connected.Data;
|
||||
|
||||
namespace Connected.Common.Workspace.Identities;
|
||||
/// <summary>
|
||||
/// Represents the workspace identity.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Workspace supports identities through the <see cref="IIdentityService"/>. There could
|
||||
/// be any number of different identities, such as users or devices which are provided via
|
||||
/// different identity providers.
|
||||
/// </remarks>
|
||||
public interface IIdentity : IPrimaryKey<string>
|
||||
{
|
||||
/// <summary>
|
||||
/// The display name of the identity. This should be short and descriptive.
|
||||
/// </summary>
|
||||
string DisplayName { get; init; }
|
||||
/// <summary>
|
||||
/// The Url of the identity's avatar if it is supported.
|
||||
/// </summary>
|
||||
string Avatar { get; init; }
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace Connected.Common.Workspace.Identities;
|
||||
/// <summary>
|
||||
/// The provider service used for providing identity descriptors.
|
||||
/// </summary>
|
||||
public interface IIdentityService
|
||||
{
|
||||
/// <summary>
|
||||
/// Queries identities for the specified set of entity types and their ids.
|
||||
/// </summary>
|
||||
/// <param name="args">The arguments containing entity types and their ids.</param>
|
||||
/// <returns>The list of identities that matches the specified criteria.</returns>
|
||||
Task<ImmutableList<IIdentity>> Query(QueryIdentitiesArgs args);
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
using Connected.Annotations;
|
||||
using Connected.ServiceModel;
|
||||
|
||||
namespace Connected.Common.Workspace.Identities;
|
||||
public sealed class QueryIdentitiesArgs : QueryArgs
|
||||
{
|
||||
[NonDefault]
|
||||
public Dictionary<string, string> Items { get; set; } = default!;
|
||||
}
|
5
src/Connected.Common.Workspace/Messaging/IMessage.cs
Normal file
5
src/Connected.Common.Workspace/Messaging/IMessage.cs
Normal file
@ -0,0 +1,5 @@
|
||||
namespace Connected.Common.Workspace.Messaging;
|
||||
public interface IMessage : IWorkspaceEntity
|
||||
{
|
||||
|
||||
}
|
15
src/Connected.Common.Workspace/Messaging/IMessagesService.cs
Normal file
15
src/Connected.Common.Workspace/Messaging/IMessagesService.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.Collections.Immutable;
|
||||
using Connected.Notifications;
|
||||
using Connected.ServiceModel;
|
||||
|
||||
namespace Connected.Common.Workspace.Messaging;
|
||||
public interface IMessagesService : IServiceNotifications<long>
|
||||
{
|
||||
Task<ImmutableList<IMessage>> Query(QueryMessageArgs args);
|
||||
Task<IMessage?> Select(PrimaryKeyArgs<long> args);
|
||||
|
||||
Task<long> Insert(InsertMessageArgs args);
|
||||
Task Update(UpdateMessageArgs args);
|
||||
Task Patch(PatchArgs<long> args);
|
||||
Task Delete(PrimaryKeyArgs<long> args);
|
||||
}
|
21
src/Connected.Common.Workspace/Messaging/MessageArgs.cs
Normal file
21
src/Connected.Common.Workspace/Messaging/MessageArgs.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Connected.ServiceModel;
|
||||
|
||||
namespace Connected.Common.Workspace.Messaging;
|
||||
public sealed class QueryMessageArgs : QueryArgs
|
||||
{
|
||||
[Required, MaxLength(128)]
|
||||
public string IdentityEntity { get; set; } = default!;
|
||||
[Required, MaxLength(128)]
|
||||
public string IdentityId { get; set; } = default!;
|
||||
}
|
||||
|
||||
public sealed class InsertMessageArgs : InsertWorkspaceArgs
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public sealed class UpdateMessageArgs : UpdateWorkspaceArgs
|
||||
{
|
||||
|
||||
}
|
67
src/Connected.Common.Workspace/WorkspaceArgs.cs
Normal file
67
src/Connected.Common.Workspace/WorkspaceArgs.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Connected.ServiceModel;
|
||||
|
||||
namespace Connected.Common.Workspace;
|
||||
/// <summary>
|
||||
/// The base class for the arguments used when inserting one of the
|
||||
/// implementations of the <see cref="IWorkspaceEntity"/> entity.
|
||||
/// </summary>
|
||||
public abstract class InsertWorkspaceArgs : Dto
|
||||
{
|
||||
/// <inheritdoc cref="IWorkspaceEntity.IdentityEntity"/>
|
||||
[Required, MaxLength(128)]
|
||||
public string IdentityEntity { get; set; } = default!;
|
||||
/// <inheritdoc cref="IWorkspaceEntity.IdentityId"/>
|
||||
[Required, MaxLength(128)]
|
||||
public string IdentityId { get; set; } = default!;
|
||||
/// <inheritdoc cref="IWorkspaceEntity.Created"/>
|
||||
public DateTimeOffset? Created { get; set; }
|
||||
/// <inheritdoc cref="IWorkspaceEntity.Expires"/>
|
||||
public DateTimeOffset? Expires { get; set; }
|
||||
/// <inheritdoc cref="IWorkspaceEntity.Title"/>
|
||||
[Required, MaxLength(128)]
|
||||
public string Title { get; set; } = default!;
|
||||
/// <inheritdoc cref="IWorkspaceEntity.Description"/>
|
||||
[MaxLength(256)]
|
||||
public string? Description { get; set; }
|
||||
/// <inheritdoc cref="IWorkspaceEntity.Status"/>
|
||||
public ReadStatus? Status { get; set; }
|
||||
/// <inheritdoc cref="IWorkspaceEntity.Domain"/>
|
||||
[Required, MaxLength(128)]
|
||||
public string Domain { get; init; } = default!;
|
||||
/// <inheritdoc cref="IWorkspaceEntity.Tags"/>
|
||||
[MaxLength(256)]
|
||||
public string? Tags { get; init; }
|
||||
/// <inheritdoc cref="IWorkspaceEntity.AuthorEntity"/>
|
||||
[MaxLength(128)]
|
||||
public string? AuthorEntity { get; init; }
|
||||
/// <inheritdoc cref="IWorkspaceEntity.AuthorId"/>
|
||||
[MaxLength(128)]
|
||||
public string? AuthorId { get; init; }
|
||||
/// <inheritdoc cref="IWorkspaceEntity.Verbs"/>
|
||||
public IdentityVerbs? Verbs { get; init; }
|
||||
}
|
||||
/// <summary>
|
||||
/// The base class used when updating one of the
|
||||
/// implementations of the <see cref="IWorkspaceEntity"/> entity.
|
||||
/// </summary>
|
||||
public abstract class UpdateWorkspaceArgs : PrimaryKeyArgs<long>
|
||||
{
|
||||
/// <inheritdoc cref="IWorkspaceEntity.Created"/>
|
||||
public DateTimeOffset? Created { get; set; }
|
||||
/// <inheritdoc cref="IWorkspaceEntity.Expires"/>
|
||||
public DateTimeOffset? Expires { get; set; }
|
||||
/// <inheritdoc cref="IWorkspaceEntity.Title"/>
|
||||
[Required, MaxLength(128)]
|
||||
public string Title { get; set; } = default!;
|
||||
/// <inheritdoc cref="IWorkspaceEntity.Description"/>
|
||||
[MaxLength(256)]
|
||||
public string? Description { get; set; }
|
||||
/// <inheritdoc cref="IWorkspaceEntity.Status"/>
|
||||
public ReadStatus? Status { get; set; }
|
||||
/// <inheritdoc cref="IWorkspaceEntity.Tags"/>
|
||||
[MaxLength(256)]
|
||||
public string? Tags { get; init; }
|
||||
/// <inheritdoc cref="IWorkspaceEntity.Verbs"/>
|
||||
public IdentityVerbs? Verbs { get; init; }
|
||||
}
|
25
src/Connected.Common/Collections/MessageJob.cs
Normal file
25
src/Connected.Common/Collections/MessageJob.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Connected.Collections.Concurrent;
|
||||
using Connected.Collections.Queues;
|
||||
using Connected.ServiceModel;
|
||||
|
||||
namespace Connected.Common.Collections;
|
||||
internal sealed class MessageJob : DispatcherJob<IQueueMessage>
|
||||
{
|
||||
public MessageJob(IContextProvider provider)
|
||||
{
|
||||
Provider = provider;
|
||||
}
|
||||
|
||||
public IContextProvider Provider { get; }
|
||||
|
||||
protected override async Task OnInvoke(IQueueMessage args, CancellationToken cancellationToken)
|
||||
{
|
||||
//TODO: need to do proper conversions
|
||||
using var ctx = Provider.Create();
|
||||
var type = Type.GetType(args.Queue);
|
||||
var client = ctx.GetService(type) as IQueueClient<QueueArgs>;
|
||||
|
||||
await client.Initialize();
|
||||
await client.Invoke(args, args.Arguments);
|
||||
}
|
||||
}
|
19
src/Connected.Common/Collections/QueueCache.cs
Normal file
19
src/Connected.Common/Collections/QueueCache.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using Connected.Entities.Caching;
|
||||
|
||||
namespace Connected.Common.Collections;
|
||||
|
||||
internal interface IQueueCache : IEntityCacheClient<QueueMessage, long>
|
||||
{
|
||||
void Update(QueueMessage message);
|
||||
}
|
||||
internal class QueueCache : EntityCacheClient<QueueMessage, long>, IQueueCache
|
||||
{
|
||||
public QueueCache(IEntityCacheContext context) : base(context, QueueMessage.CacheKey)
|
||||
{
|
||||
}
|
||||
|
||||
public void Update(QueueMessage message)
|
||||
{
|
||||
Set(message.Id, message, TimeSpan.Zero);
|
||||
}
|
||||
}
|
53
src/Connected.Common/Collections/QueueClientService.cs
Normal file
53
src/Connected.Common/Collections/QueueClientService.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using Connected.Collections.Queues;
|
||||
using Connected.Hosting.Workers;
|
||||
using Connected.Middleware;
|
||||
using Connected.ServiceModel;
|
||||
|
||||
namespace Connected.Common.Collections;
|
||||
internal sealed class QueueClientService : ScheduledWorker
|
||||
{
|
||||
public QueueClientService(IContextProvider provider)
|
||||
{
|
||||
Dispatcher = new();
|
||||
Timer = TimeSpan.FromMilliseconds(500);
|
||||
Queues = new();
|
||||
Provider = provider;
|
||||
}
|
||||
|
||||
private IContextProvider Provider { get; }
|
||||
private QueueMessageDispatcher Dispatcher { get; }
|
||||
|
||||
private List<string> Queues { get; }
|
||||
|
||||
public override async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
using var ctx = Provider.Create();
|
||||
|
||||
if (ctx.GetService<IMiddlewareService>() is not IMiddlewareService middleware)
|
||||
return;
|
||||
|
||||
foreach (var m in await middleware.Query<IQueueClient<QueueArgs>>())
|
||||
{
|
||||
if (m.GetType().FullName is string fullName)
|
||||
Queues.Add(fullName);
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnInvoke(CancellationToken cancellationToken)
|
||||
{
|
||||
using var ctx = Provider.Create();
|
||||
|
||||
if (ctx.GetService<IQueueService>() is not IQueueService queue)
|
||||
return;
|
||||
|
||||
var messages = await queue.Dequeue(new DequeueArgs
|
||||
{
|
||||
MaxCount = Dispatcher.Available,
|
||||
NextVisible = TimeSpan.FromSeconds(30),
|
||||
Queues = Queues
|
||||
});
|
||||
|
||||
foreach (var message in messages)
|
||||
Dispatcher.Enqueue(message);
|
||||
}
|
||||
}
|
49
src/Connected.Common/Collections/QueueMessage.cs
Normal file
49
src/Connected.Common/Collections/QueueMessage.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using Connected.Annotations;
|
||||
using Connected.Collections.Queues;
|
||||
using Connected.Data;
|
||||
using Connected.Entities.Annotations;
|
||||
using Connected.Entities.Concurrency;
|
||||
|
||||
namespace Connected.Common.Collections;
|
||||
/// <inheritdoc cref="IQueueMessage"/>
|
||||
[Table(Schema = SchemaAttribute.SysSchema)]
|
||||
internal sealed record QueueMessage : ConcurrentEntity<long>, IQueueMessage
|
||||
{
|
||||
public const string CacheKey = $"{SchemaAttribute.SysSchema}.{nameof(QueueMessage)}";
|
||||
/// <inheritdoc cref="IQueueMessage.Created"/>
|
||||
[Ordinal(0), Date(Kind = DateKind.DateTime)]
|
||||
public DateTime Created { get; init; }
|
||||
/// <inheritdoc cref="IQueueMessage.DequeueCount"/>
|
||||
[Ordinal(2)]
|
||||
public int DequeueCount { get; init; }
|
||||
/// <inheritdoc cref="IQueueMessage.DequeueTimestamp"/>
|
||||
[Ordinal(3), Date(Kind = DateKind.DateTime)]
|
||||
public DateTime? DequeueTimestamp { get; init; }
|
||||
/// <inheritdoc cref="IQueueMessage.Queue"/>
|
||||
[Ordinal(4), Length(32)]
|
||||
public string Queue { get; init; } = default!;
|
||||
/// <summary>
|
||||
/// The serialized value of the arguments if specified.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If the queue message must be persisted the arguments get serialized
|
||||
/// and stored in this property. When selected from the storage, the
|
||||
/// Arguments object is recreated from this property.
|
||||
/// Note that queue serialized Arguments must be less that 1024 characters long.
|
||||
/// </
|
||||
[Ordinal(7), Length(1024)]
|
||||
public string? SerializedArguments { get; init; }
|
||||
/// <inheritdoc cref="IPopReceipt.NextVisible"/>
|
||||
[Ordinal(8), Date(Kind = DateKind.DateTime)]
|
||||
public DateTime NextVisible { get; init; }
|
||||
/// <inheritdoc cref="IPopReceipt.PopReceipt"/>
|
||||
[Ordinal(9)]
|
||||
public Guid? PopReceipt { get; init; }
|
||||
/// <inheritdoc cref="IPopReceipt.PopReceipt"/>
|
||||
/// <remarks>
|
||||
/// This property is persisted through the <see cref="SerializedArguments"/>
|
||||
/// property.
|
||||
/// </remarks>
|
||||
[Persistence(Persistence = ColumnPersistence.InMemory)]
|
||||
public QueueArgs Arguments { get; init; }
|
||||
}
|
10
src/Connected.Common/Collections/QueueMessageDispatcher.cs
Normal file
10
src/Connected.Common/Collections/QueueMessageDispatcher.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using Connected.Collections.Concurrent;
|
||||
using Connected.Collections.Queues;
|
||||
|
||||
namespace Connected.Common.Collections;
|
||||
internal sealed class QueueMessageDispatcher : Dispatcher<IQueueMessage, MessageJob>
|
||||
{
|
||||
public QueueMessageDispatcher() : base(128)
|
||||
{
|
||||
}
|
||||
}
|
98
src/Connected.Common/Collections/QueueOps.cs
Normal file
98
src/Connected.Common/Collections/QueueOps.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using System.Collections.Immutable;
|
||||
using Connected.Collections.Queues;
|
||||
using Connected.Entities;
|
||||
using Connected.Interop;
|
||||
using Connected.Services;
|
||||
|
||||
namespace Connected.Common.Collections;
|
||||
|
||||
internal sealed class QueueOps
|
||||
{
|
||||
public sealed class Dequeue : ServiceFunction<DequeueArgs, ImmutableList<IQueueMessage>>
|
||||
{
|
||||
public Dequeue(IQueueCache cache)
|
||||
{
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private IQueueCache Cache { get; }
|
||||
|
||||
protected override async Task<ImmutableList<IQueueMessage>?> OnInvoke()
|
||||
{
|
||||
var targets = await SelectTargets();
|
||||
var result = new List<IQueueMessage>();
|
||||
|
||||
if (!targets.Any())
|
||||
return ImmutableList<IQueueMessage>.Empty;
|
||||
|
||||
foreach (var message in targets)
|
||||
{
|
||||
var modified = new QueueMessage
|
||||
{
|
||||
DequeueTimestamp = DateTime.UtcNow,
|
||||
Arguments = message.Arguments,
|
||||
Created = message.Created,
|
||||
DequeueCount = message.DequeueCount + 1,
|
||||
Id = message.Id,
|
||||
NextVisible = DateTime.UtcNow.Add(Arguments.NextVisible),
|
||||
PopReceipt = Guid.NewGuid(),
|
||||
Queue = message.Queue,
|
||||
State = State.Default,
|
||||
Sync = message.Sync,
|
||||
ETag = message.ETag
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
Cache.Update(modified);
|
||||
result.Add(modified);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//concurrent exception, someone was faster
|
||||
}
|
||||
}
|
||||
|
||||
return result.ToImmutableList();
|
||||
}
|
||||
|
||||
private async Task<ImmutableList<QueueMessage>> SelectTargets()
|
||||
{
|
||||
var targets = new List<QueueMessage>();
|
||||
|
||||
var items = await (from dc in Cache
|
||||
where dc.NextVisible <= DateTime.UtcNow
|
||||
&& dc.Arguments.Options.Expire > DateTime.UtcNow
|
||||
&& Arguments.Queues.Any(f => string.Equals(f, dc.Queue, StringComparison.OrdinalIgnoreCase))
|
||||
select dc).AsEntities();
|
||||
|
||||
if (!items.Any())
|
||||
return ImmutableList<QueueMessage>.Empty;
|
||||
|
||||
var ordered = targets.OrderBy(f => f.NextVisible).ThenBy(f => f.Id);
|
||||
|
||||
if (ordered.Count() <= Arguments.MaxCount)
|
||||
return ordered.ToImmutableList();
|
||||
|
||||
return ordered.Take(Arguments.MaxCount).ToImmutableList();
|
||||
}
|
||||
}
|
||||
public sealed class Enqueue<TClient> : ServiceAction<QueueArgs>
|
||||
{
|
||||
public Enqueue(IQueueCache cache)
|
||||
{
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private IQueueCache Cache { get; }
|
||||
|
||||
protected override Task OnInvoke()
|
||||
{
|
||||
var message = Serializer.Serialize(Arguments);
|
||||
|
||||
Cache.Update(Arguments.AsEntity<QueueMessage>(State.New, new { Arguments, SerializedMessage = message, Queue = typeof(TClient).FullName }));
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
40
src/Connected.Common/Collections/QueueService.cs
Normal file
40
src/Connected.Common/Collections/QueueService.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System.Collections.Immutable;
|
||||
using Connected.Collections;
|
||||
using Connected.Collections.Queues;
|
||||
using Connected.Net;
|
||||
using Connected.ServiceModel;
|
||||
using Connected.Services;
|
||||
using Ops = Connected.Common.Collections.QueueOps;
|
||||
|
||||
namespace Connected.Common.Collections;
|
||||
|
||||
internal sealed class QueueService : DistributedService, IQueueService
|
||||
{
|
||||
public QueueService(IContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<ImmutableList<IQueueMessage>> Dequeue(DequeueArgs args)
|
||||
{
|
||||
if (await IsServer())
|
||||
return await Invoke(GetOperation<Ops.Dequeue>(), args) ?? ImmutableList<IQueueMessage>.Empty;
|
||||
|
||||
if (await Http.Get<List<QueueMessage>>(await ParseUrl(CollectionRoutes.Queue), args) is List<QueueMessage> result)
|
||||
return result.ToImmutableList<IQueueMessage>();
|
||||
|
||||
return ImmutableList<IQueueMessage>.Empty;
|
||||
}
|
||||
|
||||
public async Task Enqueue<TClient, TArgs>(TArgs args)
|
||||
where TClient : IQueueClient<TArgs>
|
||||
where TArgs : QueueArgs
|
||||
{
|
||||
if (await IsServer())
|
||||
{
|
||||
await Invoke(GetOperation<Ops.Enqueue<TClient>>(), args);
|
||||
return;
|
||||
}
|
||||
|
||||
await Http.Post<ImmutableList<IQueueMessage>>(await ParseUrl(CollectionRoutes.Queue), new object[] { typeof(TClient), args });
|
||||
}
|
||||
}
|
6
src/Connected.Common/CommonSchemas.cs
Normal file
6
src/Connected.Common/CommonSchemas.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace Connected.Common;
|
||||
public static class CommonSchemas
|
||||
{
|
||||
public const string DocumentSchema = "dcm";
|
||||
public const string CommonSchema = "cmn";
|
||||
}
|
37
src/Connected.Common/CommonStartup.cs
Normal file
37
src/Connected.Common/CommonStartup.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using Connected.Annotations;
|
||||
using Connected.Common.Documents;
|
||||
using Connected.Common.Globalization;
|
||||
using Connected.Common.Security.Identity;
|
||||
using Connected.Globalization;
|
||||
using Connected.Net.Endpoints;
|
||||
using Connected.Net.Server;
|
||||
using Connected.Security.Identity;
|
||||
using Connected.ServiceModel;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
[assembly: MicroService(MicroServiceType.Service)]
|
||||
|
||||
namespace Connected.Common;
|
||||
|
||||
internal class CommonStartup : Startup
|
||||
{
|
||||
protected override void OnConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddScoped(typeof(IGlobalizationService), typeof(GlobalizationService));
|
||||
services.AddScoped(typeof(IIdentityService), typeof(IdentityService));
|
||||
services.AddTransient(typeof(IDocumentLocker<,>), typeof(DocumentLocker<,>));
|
||||
}
|
||||
protected override async Task OnInitialize(IConfiguration config)
|
||||
{
|
||||
if (Services is null || Services.GetService<IContextProvider>() is not IContextProvider provider)
|
||||
return;
|
||||
|
||||
using var ctx = provider.Create();
|
||||
|
||||
if (ctx.GetService<IEndpointService>() is not IEndpointService endpoints || ctx.GetService<IEndpointServer>() is not IEndpointServer server)
|
||||
return;
|
||||
|
||||
await server.Initialize(await endpoints.Query(), ctx.CancellationToken);
|
||||
}
|
||||
}
|
62
src/Connected.Common/Connected.Common.csproj
Normal file
62
src/Connected.Common/Connected.Common.csproj
Normal file
@ -0,0 +1,62 @@
|
||||
<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 ltd</Authors>
|
||||
<Copyright>2022 Tom PIT ltd</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="Connected.Common.Model" Version="1.0.*-*"/>
|
||||
<PackageReference Include="Connected.ServiceModel" Version="1.0.*-*"/>
|
||||
<PackageReference Include="Connected.Services" Version="1.0.*-*"/>
|
||||
<PackageReference Include="Connected.Security" Version="1.0.*-*"/>
|
||||
<PackageReference Include="Nerdbank.GitVersioning"
|
||||
Version="3.5.119"
|
||||
PrivateAssets="all"
|
||||
Condition="!Exists('packages.config')" />
|
||||
</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>
|
||||
<CustomToolNamespace></CustomToolNamespace>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\..\LICENSE">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
<None Include="..\..\README.md">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyPackages" AfterTargets="Pack">
|
||||
<Copy SourceFiles="$(OutputPath)..\$(PackageId).$(PackageVersion).nupkg" DestinationFolder="$([System.Environment]::GetEnvironmentVariable('LOCAL_NUGET'))" />
|
||||
<Copy SourceFiles="$(OutputPath)..\$(PackageId).$(PackageVersion).snupkg" DestinationFolder="$([System.Environment]::GetEnvironmentVariable('LOCAL_NUGET'))" />
|
||||
</Target>
|
||||
</Project>
|
19
src/Connected.Common/Definitions.cs
Normal file
19
src/Connected.Common/Definitions.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using Connected.Data;
|
||||
|
||||
namespace Connected.Common;
|
||||
|
||||
public static class RecordStatusLocalizer
|
||||
{
|
||||
public static string Localize(Status status) =>
|
||||
status switch
|
||||
{
|
||||
Status.Enabled => SR.RecordStatusEnabled,
|
||||
Status.Disabled => SR.RecordStatusDisabled,
|
||||
_ => status.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
public static class Constants
|
||||
{
|
||||
public const string CommonSchema = "cmn";
|
||||
}
|
22
src/Connected.Common/Distributed/DistributedLock.cs
Normal file
22
src/Connected.Common/Distributed/DistributedLock.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Connected.Annotations;
|
||||
using Connected.Entities.Annotations;
|
||||
using Connected.ServiceModel.Annotations;
|
||||
using Connected.ServiceModel.Data;
|
||||
|
||||
namespace Connected.Common.Distributed;
|
||||
|
||||
[Table(Schema = CommonSchemas.CommonSchema)]
|
||||
internal sealed record DistributedLock : TableEntity<Guid, string>, IDistributedLock
|
||||
{
|
||||
public const string EntityKey = $"{SchemaAttribute.SysSchema}.{nameof(DistributedLock)}";
|
||||
|
||||
[Ordinal(-50000), PartitionKey, MaxLength(128)]
|
||||
public string Entity { get; init; } = default!;
|
||||
|
||||
[Ordinal(-49000), PrimaryKey, MaxLength(128)]
|
||||
public string EntityId { get; init; } = default!;
|
||||
|
||||
[Ordinal(1)]
|
||||
public DateTimeOffset Expiration { get; init; }
|
||||
}
|
19
src/Connected.Common/Distributed/DistributedLockArgs.cs
Normal file
19
src/Connected.Common/Distributed/DistributedLockArgs.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Connected.ServiceModel;
|
||||
|
||||
namespace Connected.Common.Distributed;
|
||||
public sealed class DistributedLockArgs : Dto
|
||||
{
|
||||
[Required, MaxLength(128)]
|
||||
public string Entity { get; set; } = default!;
|
||||
|
||||
[Required, MaxLength(128)]
|
||||
public string EntityId { get; set; } = default!;
|
||||
|
||||
public TimeSpan? Duration { get; set; }
|
||||
}
|
||||
|
||||
public sealed class DistributedLockPingArgs : PrimaryKeyArgs<Guid>
|
||||
{
|
||||
public TimeSpan? Duration { get; set; }
|
||||
}
|
126
src/Connected.Common/Distributed/DistributedLockOps.cs
Normal file
126
src/Connected.Common/Distributed/DistributedLockOps.cs
Normal file
@ -0,0 +1,126 @@
|
||||
using Connected.Caching;
|
||||
using Connected.Entities;
|
||||
using Connected.Entities.Storage;
|
||||
using Connected.ServiceModel;
|
||||
using Connected.Services;
|
||||
|
||||
namespace Connected.Common.Distributed;
|
||||
internal sealed class DistributedLockOps
|
||||
{
|
||||
public class Lock : ServiceFunction<DistributedLockArgs, Guid>
|
||||
{
|
||||
static Lock()
|
||||
{
|
||||
SynchronizationState = new();
|
||||
}
|
||||
private static HashSet<string> SynchronizationState { get; }
|
||||
|
||||
public Lock(IStorageProvider storage, ICacheContext cache)
|
||||
{
|
||||
Cache = cache;
|
||||
Storage = storage;
|
||||
}
|
||||
|
||||
private ICacheContext Cache { get; }
|
||||
private IStorageProvider Storage { get; }
|
||||
private IDistributedLock Entity { get; set; }
|
||||
protected override async Task<Guid> OnInvoke()
|
||||
{
|
||||
/*
|
||||
* We must ensure that only one lock request is performed at a time for each entity. This is
|
||||
* because we must guarantee that one and only one entry exist for each entity and its primary key.
|
||||
*/
|
||||
var key = $"{Arguments.Entity}.{Arguments.EntityId}".ToLowerInvariant();
|
||||
/*
|
||||
* If the hashset already holds the key it means someone else was faster than we and we are not able to
|
||||
* perform a lock.
|
||||
*/
|
||||
if (!SynchronizationState.Add(key))
|
||||
throw new SynchronizationLockException($"{SR.ValLock} ({key})");
|
||||
|
||||
try
|
||||
{
|
||||
Entity = await Storage.Open<DistributedLock>().Update(Arguments.AsEntity<DistributedLock>(State.New, new
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Expiration = DateTime.UtcNow.Add(Arguments.Duration ?? TimeSpan.FromSeconds(5))
|
||||
}));
|
||||
|
||||
return Entity.Id;
|
||||
}
|
||||
finally
|
||||
{
|
||||
/*
|
||||
* Free to remove the hash lock. Any subsequent lock requests will fail at data protection level.
|
||||
*/
|
||||
SynchronizationState.Remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnCommitted()
|
||||
{
|
||||
/*
|
||||
* Put the lock it the local cache.
|
||||
*/
|
||||
Cache.Set(DistributedLock.EntityKey, Entity.Id, Entity, TimeSpan.Zero);
|
||||
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Unlock : ServiceAction<PrimaryKeyArgs<Guid>>
|
||||
{
|
||||
public Unlock(IStorageProvider storage, ICacheContext cache)
|
||||
{
|
||||
Storage = storage;
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private IStorageProvider Storage { get; }
|
||||
private ICacheContext Cache { get; }
|
||||
|
||||
protected override async Task OnInvoke()
|
||||
{
|
||||
await Storage.Open<DistributedLock>().Update(Arguments.AsEntity<DistributedLock>(State.Deleted));
|
||||
}
|
||||
|
||||
protected override async Task OnCommitted()
|
||||
{
|
||||
await Cache.Remove(DistributedLock.EntityKey, Arguments.Id);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Ping : ServiceAction<DistributedLockPingArgs>
|
||||
{
|
||||
public Ping(IStorageProvider storage, ICacheContext cache)
|
||||
{
|
||||
Storage = storage;
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private IStorageProvider Storage { get; }
|
||||
private ICacheContext Cache { get; }
|
||||
|
||||
protected override async Task OnInvoke()
|
||||
{
|
||||
var entity = await Cache.Get<IDistributedLock>(DistributedLock.EntityKey, Arguments.Id,
|
||||
async (f) =>
|
||||
{
|
||||
return await (from dc in Storage.Open<DistributedLock>() where dc.Id == Arguments.Id select dc).AsEntity();
|
||||
});
|
||||
|
||||
if (entity is not null)
|
||||
{
|
||||
await Storage.Open<DistributedLock>().Update(Arguments.AsEntity<DistributedLock>(State.Default, new
|
||||
{
|
||||
Expiration = DateTime.UtcNow.Add(Arguments.Duration ?? TimeSpan.FromSeconds(5))
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnCommitted()
|
||||
{
|
||||
await Cache.Remove(DistributedLock.EntityKey, Arguments.Id);
|
||||
}
|
||||
}
|
||||
}
|
73
src/Connected.Common/Distributed/DistributedLockProtector.cs
Normal file
73
src/Connected.Common/Distributed/DistributedLockProtector.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using Connected.Caching;
|
||||
using Connected.Data.DataProtection;
|
||||
using Connected.Data.EntityProtection;
|
||||
using Connected.Entities;
|
||||
using Connected.Entities.Storage;
|
||||
using Connected.Middleware;
|
||||
|
||||
namespace Connected.Common.Distributed;
|
||||
internal sealed class DistributedLockProtector : MiddlewareComponent, IEntityProtector<DistributedLock>
|
||||
{
|
||||
public DistributedLockProtector(IStorageProvider storage, ICacheContext cache)
|
||||
{
|
||||
Storage = storage;
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private IStorageProvider Storage { get; }
|
||||
private ICacheContext Cache { get; }
|
||||
|
||||
public async Task Invoke(EntityProtectionArgs<DistributedLock> args)
|
||||
{
|
||||
/*
|
||||
* We don't care for deleted entities.
|
||||
*/
|
||||
if (args.State == State.Deleted)
|
||||
return;
|
||||
/*
|
||||
* The most important thing is to prevent duplicate inserts. If the lock
|
||||
* already exists we will reject the transaction. Each entity record can have
|
||||
* only one entry in the distributed lock table.
|
||||
*/
|
||||
if (args.State == State.New)
|
||||
{
|
||||
/*
|
||||
* First we'll look into the memory cache.
|
||||
*/
|
||||
var existing = Cache.Get<DistributedLock>(DistributedLock.EntityKey,
|
||||
f => string.Equals(f.Entity, args.Entity.Entity, StringComparison.OrdinalIgnoreCase)
|
||||
&& string.Equals(f.EntityId, args.Entity.EntityId, StringComparison.OrdinalIgnoreCase));
|
||||
/*
|
||||
* If the cache entry exists and holds a valid lock, we simply reject the transaction.
|
||||
*/
|
||||
if (existing is not null && existing.Expiration > DateTime.UtcNow)
|
||||
throw new InvalidOperationException($"{SR.ValLock} ({args.Entity.Entity}, {args.Entity.EntityId})");
|
||||
/*
|
||||
* Entry doesn't exist in the cache. Let's look in the storage. Note that this scenarios is unusual because
|
||||
* locks tend to be short and there are only two possible schenarios that lock exists in the storage but not
|
||||
* in the cache:
|
||||
* - the process has rebooted
|
||||
* - the master has changed. It this case all distributed services are redirected to the new master which must
|
||||
* load record by record from the cache. In this case it's most probably that all locks already expired but we
|
||||
* must check that anyway
|
||||
*/
|
||||
var entry = await (from dc in Storage.Open<DistributedLock>()
|
||||
where string.Equals(dc.Entity, args.Entity.Entity, StringComparison.OrdinalIgnoreCase)
|
||||
&& string.Equals(dc.EntityId, args.Entity.EntityId, StringComparison.OrdinalIgnoreCase)
|
||||
select dc).AsEntity();
|
||||
/*
|
||||
* It exists, we must perform additional checks.
|
||||
*/
|
||||
if (entry is not null)
|
||||
{
|
||||
/*
|
||||
* Set it in the cache so it gets deleted by the recycling service.
|
||||
*/
|
||||
Cache.Set(DistributedLock.EntityKey, entry.Id, entry, TimeSpan.Zero);
|
||||
|
||||
if (entry.Expiration > DateTime.UtcNow)
|
||||
throw new InvalidOperationException($"{SR.ValLock} ({args.Entity.Entity}, {args.Entity.EntityId})");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
32
src/Connected.Common/Distributed/DistributedLockService.cs
Normal file
32
src/Connected.Common/Distributed/DistributedLockService.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using Connected.ServiceModel;
|
||||
using Connected.Services;
|
||||
using Ops = Connected.Common.Distributed.DistributedLockOps;
|
||||
|
||||
namespace Connected.Common.Distributed;
|
||||
internal sealed class DistributedLockService : DistributedService, IDistributedLockService
|
||||
{
|
||||
public DistributedLockService(IContext context) : base(context)
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// This method performs a distribubuted lock on an entity. If the lock
|
||||
/// cannot be obtained the exception is thrown.
|
||||
/// </summary>
|
||||
/// <param name="args">The arguments containing the entity on which
|
||||
/// a distributed lock will be performed.</param>
|
||||
/// <returns>The key of a newly acquired lock.</returns>
|
||||
public async Task<Guid> Lock(DistributedLockArgs args)
|
||||
{
|
||||
return await Invoke(GetOperation<Ops.Lock>(), args);
|
||||
}
|
||||
|
||||
public async Task Ping(DistributedLockPingArgs args)
|
||||
{
|
||||
await Invoke(GetOperation<Ops.Ping>(), args);
|
||||
}
|
||||
|
||||
public async Task Unlock(PrimaryKeyArgs<Guid> args)
|
||||
{
|
||||
await Invoke(GetOperation<Ops.Unlock>(), args);
|
||||
}
|
||||
}
|
9
src/Connected.Common/Distributed/IDistributedLock.cs
Normal file
9
src/Connected.Common/Distributed/IDistributedLock.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using Connected.Data;
|
||||
|
||||
namespace Connected.Common.Distributed;
|
||||
public interface IDistributedLock : IPrimaryKey<Guid>
|
||||
{
|
||||
string Entity { get; init; }
|
||||
string EntityId { get; init; }
|
||||
DateTimeOffset Expiration { get; init; }
|
||||
}
|
12
src/Connected.Common/Distributed/IDistributedLockService.cs
Normal file
12
src/Connected.Common/Distributed/IDistributedLockService.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using Connected.Annotations;
|
||||
using Connected.ServiceModel;
|
||||
|
||||
namespace Connected.Common.Distributed;
|
||||
|
||||
[Service]
|
||||
public interface IDistributedLockService
|
||||
{
|
||||
Task<Guid> Lock(DistributedLockArgs args);
|
||||
Task Unlock(PrimaryKeyArgs<Guid> args);
|
||||
Task Ping(DistributedLockPingArgs args);
|
||||
}
|
32
src/Connected.Common/Documents/Document.cs
Normal file
32
src/Connected.Common/Documents/Document.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Connected.Annotations;
|
||||
using Connected.Entities.Annotations;
|
||||
using Connected.Entities.Consistency;
|
||||
|
||||
namespace Connected.Common.Documents;
|
||||
/// <summary>
|
||||
/// Default implementation of the <see cref="IDocument{TPrimaryKey}"/> interface.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPrimaryKey">The type of the primary key used by document.
|
||||
/// This is usually <c>int</c> or <c>long</c>.
|
||||
/// </typeparam>
|
||||
[Table(Schema = CommonSchemas.DocumentSchema)]
|
||||
public abstract record Document<TPrimaryKey> : ConsistentEntity<TPrimaryKey>, IDocument<TPrimaryKey>
|
||||
where TPrimaryKey : notnull
|
||||
{
|
||||
/// <inheritdoc cref="IDocument{TPrimaryKey}.Created"/>
|
||||
[Ordinal(-1007), Date(Kind = DateKind.SmallDateTime)]
|
||||
public DateTimeOffset Created { get; init; }
|
||||
/// <inheritdoc cref="IDocument{TPrimaryKey}.Modified"/>
|
||||
[Ordinal(-1006), Nullable, Date(Kind = DateKind.SmallDateTime)]
|
||||
public DateTimeOffset? Modified { get; init; }
|
||||
/// <inheritdoc cref="IDocument{TPrimaryKey}.Code"/>
|
||||
[Ordinal(-1005), MaxLength(32), Nullable]
|
||||
public string? Code { get; init; } = default!;
|
||||
/// <inheritdoc cref="IDocument{TPrimaryKey}.Author"/>
|
||||
[Ordinal(-1004), Nullable]
|
||||
public int? Author { get; init; }
|
||||
/// <inheritdoc cref="IDocument{TPrimaryKey}.Owner"/>
|
||||
[Ordinal(-1003), Nullable]
|
||||
public int? Owner { get; init; }
|
||||
}
|
59
src/Connected.Common/Documents/DocumentListener.cs
Normal file
59
src/Connected.Common/Documents/DocumentListener.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using Connected.Notifications.Events;
|
||||
|
||||
namespace Connected.Common.Documents;
|
||||
public abstract class DocumentListener<TArgs, TDocument, TPrimaryKey> : EventListener<TArgs>
|
||||
where TArgs : IDto
|
||||
where TDocument : IDocument<TPrimaryKey>
|
||||
where TPrimaryKey : notnull
|
||||
{
|
||||
public DocumentListener(IDocumentLocker<TDocument, TPrimaryKey> locker)
|
||||
{
|
||||
Locker = locker;
|
||||
}
|
||||
|
||||
private IDocumentLocker<TDocument, TPrimaryKey> Locker { get; }
|
||||
protected abstract TDocument Document { get; }
|
||||
protected override async Task OnInvoke()
|
||||
{
|
||||
await OnPreparing();
|
||||
|
||||
if (Document is null)
|
||||
return;
|
||||
|
||||
Locker.Expired += async (s, e) => { await OnException(new TimeoutException()); };
|
||||
|
||||
try
|
||||
{
|
||||
await Locker.Lock(Document);
|
||||
await OnInvoking();
|
||||
await Locker.Unlock();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Locker.Unlock();
|
||||
await OnException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual async Task<bool> OnPreparing()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected virtual async Task OnInvoking()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected virtual async Task OnException(Exception ex)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected override void OnDisposing()
|
||||
{
|
||||
Locker.Dispose();
|
||||
}
|
||||
}
|
95
src/Connected.Common/Documents/DocumentLocker.cs
Normal file
95
src/Connected.Common/Documents/DocumentLocker.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using Connected.Common.Distributed;
|
||||
using Connected.Interop;
|
||||
using Connected.ServiceModel;
|
||||
using Connected.Threading;
|
||||
|
||||
namespace Connected.Common.Documents;
|
||||
internal sealed class DocumentLocker<TDocument, TPrimaryKey> : IDocumentLocker<TDocument, TPrimaryKey>
|
||||
where TDocument : IDocument<TPrimaryKey>
|
||||
where TPrimaryKey : notnull
|
||||
|
||||
{
|
||||
public event EventHandler? Expired;
|
||||
public DocumentLocker(IDistributedLockService locking)
|
||||
{
|
||||
Locking = locking;
|
||||
Cancel = new();
|
||||
}
|
||||
|
||||
private bool IsDisposed { get; set; }
|
||||
public Guid Key { get; private set; }
|
||||
private IDistributedLockService Locking { get; }
|
||||
|
||||
public TimeSpan LockTimeout { get; set; } = TimeSpan.FromSeconds(2);
|
||||
public TimeSpan Timeout { get; set; } = TimeSpan.FromMilliseconds(1500);
|
||||
public TimeSpan Lifetime { get; set; } = TimeSpan.FromSeconds(30);
|
||||
private CancellationTokenSource Cancel { get; }
|
||||
public async Task Lock(TDocument document)
|
||||
{
|
||||
var id = TypeConversion.Convert<string>(document.Id);
|
||||
|
||||
if (string.IsNullOrEmpty(id))
|
||||
throw new NullReferenceException(nameof(document.Id));
|
||||
/*
|
||||
* Obtain the lock on the document to ensure no other process
|
||||
* will change it while we are updating the stock. If the lock
|
||||
* could not be obtained the exception will be thrown.
|
||||
*/
|
||||
Key = await Locking.Lock(new DistributedLockArgs
|
||||
{
|
||||
Duration = LockTimeout,
|
||||
Entity = typeof(TDocument).Name,
|
||||
EntityId = id
|
||||
});
|
||||
/*
|
||||
* Make sure we don't get outdated by using the scheduled
|
||||
* task which will ping the lock before it expires.
|
||||
*/
|
||||
using var timeout = new ScheduledTask(async () =>
|
||||
{
|
||||
await Locking.Ping(new DistributedLockPingArgs
|
||||
{
|
||||
Id = Key,
|
||||
Duration = LockTimeout
|
||||
});
|
||||
}, async () =>
|
||||
{
|
||||
await Unlock();
|
||||
|
||||
Expired?.Invoke(this, EventArgs.Empty);
|
||||
}, Timeout, Lifetime, Cancel.Token);
|
||||
|
||||
timeout.Start();
|
||||
}
|
||||
|
||||
public async Task Unlock()
|
||||
{
|
||||
/*
|
||||
* Finally release the lock on the document so it becomes
|
||||
* updatable again.
|
||||
*/
|
||||
await Locking.Unlock(new PrimaryKeyArgs<Guid> { Id = Key });
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
AsyncUtils.RunSync(Unlock);
|
||||
|
||||
Cancel.Cancel();
|
||||
Cancel.Dispose();
|
||||
}
|
||||
|
||||
IsDisposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
15
src/Connected.Common/Documents/DocumentService.cs
Normal file
15
src/Connected.Common/Documents/DocumentService.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using Connected.Notifications;
|
||||
using Connected.ServiceModel;
|
||||
using Connected.Services;
|
||||
|
||||
namespace Connected.Common.Documents;
|
||||
public abstract class DocumentService<TDocumentPrimaryKey, TItemPrimaryKey> : EntityService<TDocumentPrimaryKey>, IDocumentService<TDocumentPrimaryKey, TItemPrimaryKey>
|
||||
{
|
||||
protected DocumentService(IContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public event ServiceEventHandler<PrimaryKeyEventArgs<TItemPrimaryKey>>? ItemInserted;
|
||||
public event ServiceEventHandler<PrimaryKeyEventArgs<TItemPrimaryKey>>? ItemUpdated;
|
||||
public event ServiceEventHandler<PrimaryKeyEventArgs<TItemPrimaryKey>>? ItemDeleted;
|
||||
}
|
13
src/Connected.Common/Documents/IDocumentLocker.cs
Normal file
13
src/Connected.Common/Documents/IDocumentLocker.cs
Normal file
@ -0,0 +1,13 @@
|
||||
namespace Connected.Common.Documents;
|
||||
public interface IDocumentLocker<TDocument, TPrimaryKey> : IDisposable
|
||||
where TDocument : IDocument<TPrimaryKey>
|
||||
where TPrimaryKey : notnull
|
||||
{
|
||||
event EventHandler? Expired;
|
||||
Guid Key { get; }
|
||||
TimeSpan LockTimeout { get; set; }
|
||||
TimeSpan Timeout { get; set; }
|
||||
TimeSpan Lifetime { get; set; }
|
||||
Task Lock(TDocument document);
|
||||
Task Unlock();
|
||||
}
|
61
src/Connected.Common/Documents/Validators.cs
Normal file
61
src/Connected.Common/Documents/Validators.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using Connected.Middleware;
|
||||
using Connected.Security.Identity;
|
||||
using Connected.Validation;
|
||||
|
||||
namespace Connected.Common.Documents;
|
||||
public abstract class InsertDocumentValidator<TDocumentArgs> : MiddlewareComponent, IValidator<TDocumentArgs>
|
||||
where TDocumentArgs : InsertDocumentArgs
|
||||
{
|
||||
public InsertDocumentValidator(IUserService users)
|
||||
{
|
||||
Users = users;
|
||||
}
|
||||
protected IUserService Users { get; }
|
||||
protected TDocumentArgs Arguments { get; private set; }
|
||||
public async Task Validate(TDocumentArgs args)
|
||||
{
|
||||
Arguments = args;
|
||||
|
||||
await ValidateAuthor();
|
||||
}
|
||||
|
||||
protected virtual async Task OnValidating()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task ValidateAuthor()
|
||||
{
|
||||
if (Arguments.Author is null)
|
||||
return;
|
||||
|
||||
if (await Users.Select(Arguments.Author) is null)
|
||||
throw new ArgumentException(nameof(Arguments.Author));
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class UpdateDocumentValidator<TDocumentArgs, TPrimaryKey> : MiddlewareComponent, IValidator<TDocumentArgs>
|
||||
where TDocumentArgs : UpdateDocumentArgs<TPrimaryKey>
|
||||
where TPrimaryKey : notnull
|
||||
{
|
||||
public UpdateDocumentValidator(IUserService users)
|
||||
{
|
||||
Users = users;
|
||||
}
|
||||
|
||||
protected IUserService Users { get; }
|
||||
|
||||
public async Task Validate(TDocumentArgs args)
|
||||
{
|
||||
await ValidateOwner(args);
|
||||
}
|
||||
|
||||
private async Task ValidateOwner(TDocumentArgs args)
|
||||
{
|
||||
if (args.Owner is null)
|
||||
return;
|
||||
|
||||
if (await Users.Select(args.Owner) is null)
|
||||
throw new ArgumentException(nameof(args.Owner));
|
||||
}
|
||||
}
|
104
src/Connected.Common/Globalization/GlobalizationService.cs
Normal file
104
src/Connected.Common/Globalization/GlobalizationService.cs
Normal file
@ -0,0 +1,104 @@
|
||||
using System.Globalization;
|
||||
using Connected.Data;
|
||||
using Connected.Globalization;
|
||||
using Connected.Globalization.Languages;
|
||||
using Connected.Security.Identity;
|
||||
using Connected.ServiceModel;
|
||||
|
||||
namespace Connected.Common.Globalization;
|
||||
|
||||
internal class GlobalizationService : IGlobalizationService
|
||||
{
|
||||
private ILanguage _language;
|
||||
private CultureInfo _culture;
|
||||
public GlobalizationService(IIdentityService identityService, ILanguageService languageService)
|
||||
{
|
||||
IdentityService = identityService;
|
||||
LanguageService = languageService;
|
||||
}
|
||||
|
||||
private IIdentityService IdentityService { get; }
|
||||
private ILanguageService LanguageService { get; }
|
||||
|
||||
public TimeZoneInfo TimeZone
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!IdentityService.IsAuthenticated || IdentityService.CurrentUser is null)
|
||||
return TimeZoneInfo.Utc;
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if (TimeZoneInfo.FindSystemTimeZoneById(IdentityService.CurrentUser.TimeZone) is not TimeZoneInfo timezone)
|
||||
return TimeZoneInfo.Utc;
|
||||
else
|
||||
return timezone;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return TimeZoneInfo.Utc;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public DateTimeOffset Now => FromUtc(DateTimeOffset.UtcNow);
|
||||
|
||||
public async Task<ILanguage?> GetCurrentLanguage()
|
||||
{
|
||||
if (_language is null)
|
||||
{
|
||||
if (IdentityService.CurrentUser is not null && IdentityService.CurrentUser.Language > 0)
|
||||
_language = await LanguageService.Select(new PrimaryKeyArgs<int>() { Id = IdentityService.CurrentUser.Language });
|
||||
|
||||
if (_language is not null && _language.Status == Status.Disabled)
|
||||
_language = null;
|
||||
}
|
||||
|
||||
return _language;
|
||||
}
|
||||
public async Task<CultureInfo> GetCurrentCulture()
|
||||
{
|
||||
if (_culture is null)
|
||||
{
|
||||
if (await GetCurrentLanguage() is not ILanguage language)
|
||||
_culture = Thread.CurrentThread.CurrentUICulture;
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if (CultureInfo.GetCultureInfo(language.Lcid) is not CultureInfo culture)
|
||||
_culture = Thread.CurrentThread.CurrentUICulture;
|
||||
}
|
||||
catch
|
||||
{
|
||||
_culture = Thread.CurrentThread.CurrentUICulture;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _culture;
|
||||
}
|
||||
|
||||
public DateTime FromUtc(DateTime value)
|
||||
{
|
||||
return DateExtensions.FromUtc(value, TimeZone);
|
||||
}
|
||||
|
||||
public DateTimeOffset FromUtc(DateTimeOffset value)
|
||||
{
|
||||
return DateExtensions.FromUtc(value, TimeZone);
|
||||
}
|
||||
|
||||
public DateTime ToUtc(DateTime value)
|
||||
{
|
||||
return DateExtensions.ToUtc(value, TimeZone);
|
||||
}
|
||||
|
||||
public DateTimeOffset ToUtc(DateTimeOffset value)
|
||||
{
|
||||
return DateExtensions.ToUtc(value, TimeZone);
|
||||
}
|
||||
}
|
31
src/Connected.Common/Globalization/Language.cs
Normal file
31
src/Connected.Common/Globalization/Language.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using Connected.Annotations;
|
||||
using Connected.Data;
|
||||
using Connected.Entities.Annotations;
|
||||
using Connected.Entities.Consistency;
|
||||
using Connected.Globalization.Languages;
|
||||
|
||||
namespace Connected.Common.Globalization;
|
||||
|
||||
/// <summary>
|
||||
/// The implementation of the <see cref="ILanguage"/> entity.
|
||||
/// </summary>
|
||||
[Table(Schema = SchemaAttribute.SysSchema)]
|
||||
internal record Language : ConsistentEntity<int>, ILanguage
|
||||
{
|
||||
public const string CacheKey = $"{SchemaAttribute.SysSchema}.{nameof(Language)}";
|
||||
|
||||
[Length(128)]
|
||||
[Ordinal(0)]
|
||||
public string? Name { get; init; }
|
||||
|
||||
[Ordinal(1)]
|
||||
public int Lcid { get; init; }
|
||||
|
||||
[Default(Status.Enabled)]
|
||||
[Ordinal(2)]
|
||||
public Status Status { get; init; }
|
||||
|
||||
[Length(128)]
|
||||
[Ordinal(3)]
|
||||
public string? Mappings { get; init; }
|
||||
}
|
77
src/Connected.Common/Globalization/LanguageCache.cs
Normal file
77
src/Connected.Common/Globalization/LanguageCache.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using System.Collections.Immutable;
|
||||
using Connected.Entities.Caching;
|
||||
using Connected.ServiceModel;
|
||||
|
||||
namespace Connected.Common.Globalization;
|
||||
|
||||
internal interface ILanguageCache : IEntityCacheClient<Language, int>
|
||||
{
|
||||
Language? Select(string mappings);
|
||||
}
|
||||
/// <summary>
|
||||
/// Represents stateful cache of the <see cref="Language"/> entities.
|
||||
/// </summary>
|
||||
internal class LanguageCache : EntityCacheClient<Language, int>, ILanguageCache
|
||||
{
|
||||
private readonly Dictionary<string, Language> _mappings;
|
||||
public LanguageCache(IEntityCacheContext context) : base(context, Language.CacheKey)
|
||||
{
|
||||
_mappings = new Dictionary<string, Language>(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private Dictionary<string, Language> Mappings => _mappings;
|
||||
protected override async Task<ImmutableList<Language>> OnInitializing(IContext context)
|
||||
{
|
||||
var result = await base.OnInitializing(context);
|
||||
|
||||
await ResetMappings();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override async Task<Language> OnInvalidating(IContext context, int id)
|
||||
{
|
||||
var result = await base.OnInvalidating(context, id);
|
||||
|
||||
await ResetMappings();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public Language? Select(string mappings)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(mappings))
|
||||
return null;
|
||||
|
||||
var tokens = mappings.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (var token in tokens)
|
||||
{
|
||||
if (Mappings.TryGetValue(token.Trim(), out Language? language))
|
||||
return language;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task ResetMappings()
|
||||
{
|
||||
Mappings.Clear();
|
||||
|
||||
foreach (var language in await All())
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(language.Mappings))
|
||||
continue;
|
||||
|
||||
var tokens = language.Mappings.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (var token in tokens)
|
||||
{
|
||||
if (Mappings.TryGetValue(token.Trim(), out _))
|
||||
continue;
|
||||
|
||||
Mappings.Add(token.Trim(), language);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
233
src/Connected.Common/Globalization/LanguageOps.cs
Normal file
233
src/Connected.Common/Globalization/LanguageOps.cs
Normal file
@ -0,0 +1,233 @@
|
||||
using System.Collections.Immutable;
|
||||
using Connected.Entities;
|
||||
using Connected.Entities.Storage;
|
||||
using Connected.Globalization.Languages;
|
||||
using Connected.Notifications.Events;
|
||||
using Connected.ServiceModel;
|
||||
using Connected.Services;
|
||||
|
||||
namespace Connected.Common.Globalization;
|
||||
|
||||
/// <summary>
|
||||
/// Queries all <see cref="ILanguage"/> records except those marked as deleting.
|
||||
/// </summary>
|
||||
internal sealed class QueryLanguages : ServiceFunction<IDto, ImmutableList<ILanguage>?>
|
||||
{
|
||||
public QueryLanguages(ILanguageCache cache)
|
||||
{
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private ILanguageCache Cache { get; }
|
||||
protected override async Task<ImmutableList<ILanguage>?> OnInvoke()
|
||||
{
|
||||
/*
|
||||
* Filter records to return only currently valid record. Those with
|
||||
* deleting state should never be returned to any client.
|
||||
*/
|
||||
return await (from dc in Cache
|
||||
select dc).AsEntities<ILanguage>();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Queries the <see cref="ILanguage"/> records for the specified set of ids.
|
||||
/// </summary>
|
||||
internal sealed class LookupLanguages : ServiceFunction<PrimaryKeyListArgs<int>, ImmutableList<ILanguage>>
|
||||
{
|
||||
public LookupLanguages(ILanguageCache cache)
|
||||
{
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private ILanguageCache Cache { get; }
|
||||
protected override async Task<ImmutableList<ILanguage>?> OnInvoke()
|
||||
{
|
||||
if (Arguments?.IdList is null)
|
||||
return default;
|
||||
|
||||
return await (from dc in Cache
|
||||
where Arguments.IdList.Any(f => f == dc.Id)
|
||||
select dc).AsEntities<ILanguage>();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns first <see cref="ILanguage"/> with matches the provided mapping.
|
||||
/// </summary>
|
||||
internal sealed class ResolveLanguage : ServiceFunction<LanguageResolveArgs, ILanguage?>
|
||||
{
|
||||
public ResolveLanguage(ILanguageCache cache)
|
||||
{
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private ILanguageCache Cache { get; }
|
||||
protected override Task<ILanguage?> OnInvoke()
|
||||
{
|
||||
return Task.FromResult<ILanguage?>(Cache.Select(Arguments.Mapping));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns <see cref="ILanguage"/> with the specified id or null
|
||||
/// if the record for the specified id does not exist.
|
||||
/// </summary>
|
||||
internal sealed class SelectLanguage : ServiceFunction<PrimaryKeyArgs<int>, ILanguage?>
|
||||
{
|
||||
public SelectLanguage(ILanguageCache cache)
|
||||
{
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private ILanguageCache Cache { get; }
|
||||
protected override async Task<ILanguage?> OnInvoke()
|
||||
{
|
||||
return await (from dc in Cache
|
||||
where dc.Id == Arguments.Id
|
||||
select dc).AsEntity();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns <see cref="ILanguage"/> with the specified name and rate or null if
|
||||
/// the record with the specified arguments does not exist.
|
||||
/// </summary>
|
||||
internal sealed class SelectLanguageByName : ServiceFunction<NameArgs, ILanguage?>
|
||||
{
|
||||
public SelectLanguageByName(ILanguageCache cache)
|
||||
{
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private ILanguageCache Cache { get; }
|
||||
|
||||
protected override async Task<ILanguage?> OnInvoke()
|
||||
{
|
||||
return await (from dc in Cache
|
||||
where string.Equals(dc.Name, Arguments.Name, StringComparison.OrdinalIgnoreCase)
|
||||
select dc).AsEntity();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Inserts a new <see cref="ILanguage"/> and returns its Id.
|
||||
/// </summary>
|
||||
internal sealed class InsertLanguage : ServiceFunction<LanguageInsertArgs, int>
|
||||
{
|
||||
public InsertLanguage(ILanguageService languageService, IStorageProvider storage, IEventService events, ILanguageCache cache)
|
||||
{
|
||||
LanguageService = languageService;
|
||||
Storage = storage;
|
||||
Events = events;
|
||||
Cache = cache;
|
||||
}
|
||||
/// <summary>
|
||||
/// We need this service to call a distribute event.
|
||||
/// </summary>
|
||||
private ILanguageService LanguageService { get; }
|
||||
private IStorageProvider Storage { get; }
|
||||
private IEventService Events { get; }
|
||||
private ILanguageCache Cache { get; }
|
||||
|
||||
protected override async Task<int> OnInvoke()
|
||||
{
|
||||
/*
|
||||
* First, create a new entity from the passed arguments and mark its state as new. This will
|
||||
* signal the DatabaseContext to perform an insert operation when calling the Update.
|
||||
*/
|
||||
var entity = Arguments.AsEntity<Language>(State.New);
|
||||
/*
|
||||
* Call update on the DatabaseContext. This call will return a new ILanguage of the inserted
|
||||
* entity.
|
||||
*/
|
||||
var result = await Storage.Open<Language>().Update(entity);
|
||||
/*
|
||||
* Return a newly inserted id to the caller.
|
||||
*/
|
||||
return result.Id;
|
||||
}
|
||||
|
||||
protected override async Task OnCommitted()
|
||||
{
|
||||
await Cache.Refresh(Result);
|
||||
/*
|
||||
* If ILanguageServer is our implementation (and should be) it's a IServerNotificationsTriggers
|
||||
* for sure.
|
||||
*/
|
||||
await Events.Enqueue(this, LanguageService, ServiceEvents.Inserted, Result);
|
||||
}
|
||||
}
|
||||
internal sealed class DeleteLanguage : ServiceAction<PrimaryKeyArgs<int>>
|
||||
{
|
||||
public DeleteLanguage(ILanguageService languageService, IStorageProvider storage, ILanguageCache cache, IEventService events)
|
||||
{
|
||||
LanguageService = languageService;
|
||||
Storage = storage;
|
||||
Cache = cache;
|
||||
Events = events;
|
||||
}
|
||||
|
||||
private ILanguageService LanguageService { get; }
|
||||
private IStorageProvider Storage { get; }
|
||||
private ILanguageCache Cache { get; }
|
||||
private IEventService Events { get; }
|
||||
|
||||
protected override async Task OnInvoke()
|
||||
{
|
||||
var entity = new Language { Id = Arguments.Id, State = State.Deleted };
|
||||
|
||||
await Storage.Open<Language>().Update(entity);
|
||||
}
|
||||
|
||||
protected override async Task OnCommitted()
|
||||
{
|
||||
await Cache.Remove(Arguments.Id);
|
||||
await Events.Enqueue(this, LanguageService, ServiceEvents.Deleted, Arguments.Id);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Updates <see cref="ILanguage"/> entity.
|
||||
/// </summary>
|
||||
internal sealed class UpdateLanguage : ServiceAction<LanguageUpdateArgs>
|
||||
{
|
||||
public UpdateLanguage(ILanguageService languageService, IStorageProvider storage, ILanguageCache cache, IEventService events)
|
||||
{
|
||||
LanguageService = languageService;
|
||||
Storage = storage;
|
||||
Cache = cache;
|
||||
Events = events;
|
||||
}
|
||||
private ILanguageService LanguageService { get; }
|
||||
private IStorageProvider Storage { get; }
|
||||
private ILanguageCache Cache { get; }
|
||||
private IEventService Events { get; }
|
||||
|
||||
protected override async Task OnInvoke()
|
||||
{
|
||||
/*
|
||||
* Updating Concurrency entity requires a bit more logic. Since Concurrency entity
|
||||
* guarantees data consistency we must use a retry logic in case of
|
||||
* Concurrency failure. We'll call Update method with reload lambda function.
|
||||
*/
|
||||
await Storage.Open<Language>().Update(await Load(), Arguments, async () =>
|
||||
{
|
||||
/*
|
||||
* Remove entry from the cache to ensure it will be loaded from the database
|
||||
* next time.
|
||||
*/
|
||||
await Cache.Refresh(Arguments.Id);
|
||||
|
||||
return await Load();
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<Language> Load() => await (from dc in Cache where dc.Id == Arguments.Id select dc).AsEntity();
|
||||
protected override async Task OnCommitted()
|
||||
{
|
||||
/*
|
||||
* Once the update is complete remove the entity from the cache because its concurrency
|
||||
* state is not valid enymore.
|
||||
*/
|
||||
await Cache.Remove(Arguments.Id);
|
||||
/*
|
||||
* Now trigger the distributed event notifying the update has completed.
|
||||
*/
|
||||
await Events.Enqueue(this, LanguageService, ServiceEvents.Updated, Arguments.Id);
|
||||
}
|
||||
}
|
66
src/Connected.Common/Globalization/LanguageService.cs
Normal file
66
src/Connected.Common/Globalization/LanguageService.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System.Collections.Immutable;
|
||||
using Connected.Common.Security;
|
||||
using Connected.Globalization.Languages;
|
||||
using Connected.ServiceModel;
|
||||
using Connected.Services;
|
||||
using Connected.Services.Annotations;
|
||||
|
||||
namespace Connected.Common.Globalization;
|
||||
|
||||
/// <summary>
|
||||
/// The implementation of the <see cref="ILanguageService"/> service.
|
||||
/// </summary>
|
||||
internal class LanguageService : EntityService<int>, ILanguageService
|
||||
{
|
||||
public LanguageService(IContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
[ServiceAuthorization(CommonClaims.CommonDelete)]
|
||||
public async Task Delete(PrimaryKeyArgs<int> args)
|
||||
{
|
||||
await Invoke(GetOperation<DeleteLanguage>(), args);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(CommonClaims.CommonAdd)]
|
||||
public async Task<int> Insert(LanguageInsertArgs args)
|
||||
{
|
||||
return await Invoke(GetOperation<InsertLanguage>(), args);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(CommonClaims.CommonRead)]
|
||||
public async Task<ImmutableList<ILanguage>?> Query()
|
||||
{
|
||||
return await Invoke(GetOperation<QueryLanguages>(), Dto.Empty);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(CommonClaims.CommonRead)]
|
||||
public async Task<ImmutableList<ILanguage>?> Query(PrimaryKeyListArgs<int> args)
|
||||
{
|
||||
return await Invoke(GetOperation<LookupLanguages>(), args);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(CommonClaims.CommonRead)]
|
||||
public async Task<ILanguage?> Resolve(LanguageResolveArgs args)
|
||||
{
|
||||
return await Invoke(GetOperation<ResolveLanguage>(), args);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(CommonClaims.CommonRead)]
|
||||
public async Task<ILanguage?> Select(PrimaryKeyArgs<int> args)
|
||||
{
|
||||
return await Invoke(GetOperation<SelectLanguage>(), args);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(CommonClaims.CommonRead)]
|
||||
public async Task<ILanguage?> Select(NameArgs args)
|
||||
{
|
||||
return await Invoke(GetOperation<SelectLanguageByName>(), args);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(CommonClaims.CommonModify)]
|
||||
public async Task Update(LanguageUpdateArgs args)
|
||||
{
|
||||
await Invoke(GetOperation<UpdateLanguage>(), args);
|
||||
}
|
||||
}
|
29
src/Connected.Common/Net/Endpoint.cs
Normal file
29
src/Connected.Common/Net/Endpoint.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using Connected.Annotations;
|
||||
using Connected.Data;
|
||||
using Connected.Entities.Annotations;
|
||||
using Connected.Entities.Consistency;
|
||||
using Connected.Net.Endpoints;
|
||||
|
||||
namespace Connected.Common.Net;
|
||||
|
||||
[Table(Schema = SchemaAttribute.DefaultSchema)]
|
||||
internal record Endpoint : ConsistentEntity<int>, IEndpoint
|
||||
{
|
||||
public const string CacheKey = $"{SchemaAttribute.SysSchema}.{nameof(Endpoint)}";
|
||||
|
||||
[Ordinal(0)]
|
||||
[Length(128)]
|
||||
public string? Name { get; init; }
|
||||
|
||||
[Length(128)]
|
||||
[Ordinal(1)]
|
||||
public string? Address { get; init; }
|
||||
|
||||
[Default(Status.Enabled)]
|
||||
[Ordinal(2)]
|
||||
[Length(128)]
|
||||
public string? AuthenticationToken { get; init; }
|
||||
|
||||
[Ordinal(3)]
|
||||
public Status Status { get; init; }
|
||||
}
|
11
src/Connected.Common/Net/EndpointCache.cs
Normal file
11
src/Connected.Common/Net/EndpointCache.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using Connected.Entities.Caching;
|
||||
|
||||
namespace Connected.Common.Net;
|
||||
|
||||
internal interface IEndpointCache : IEntityCacheClient<Endpoint, int> { }
|
||||
internal class EndpointCache : EntityCacheClient<Endpoint, int>, IEndpointCache
|
||||
{
|
||||
public EndpointCache(IEntityCacheContext cachingService) : base(cachingService, Endpoint.CacheKey)
|
||||
{
|
||||
}
|
||||
}
|
42
src/Connected.Common/Net/EndpointOps.cs
Normal file
42
src/Connected.Common/Net/EndpointOps.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System.Collections.Immutable;
|
||||
using Connected.Entities;
|
||||
using Connected.Net.Endpoints;
|
||||
using Connected.ServiceModel;
|
||||
using Connected.Services;
|
||||
|
||||
namespace Connected.Common.Net;
|
||||
|
||||
/// <summary>
|
||||
/// Endpoints are singleton but their service is scoped so we must use Isolated database connections for all methods.
|
||||
/// </summary>
|
||||
internal sealed class QueryEndpoints : ServiceFunction<IDto, ImmutableList<IEndpoint>?>
|
||||
{
|
||||
public QueryEndpoints(IEndpointCache cache)
|
||||
{
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private IEndpointCache Cache { get; }
|
||||
|
||||
protected override async Task<ImmutableList<IEndpoint>?> OnInvoke()
|
||||
{
|
||||
return await (from dc in Cache
|
||||
select dc).AsEntities<IEndpoint>();
|
||||
}
|
||||
}
|
||||
internal sealed class SelectEndpoint : ServiceFunction<PrimaryKeyArgs<int>, IEndpoint?>
|
||||
{
|
||||
public SelectEndpoint(IEndpointCache cache)
|
||||
{
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private IEndpointCache Cache { get; }
|
||||
|
||||
protected override async Task<IEndpoint?> OnInvoke()
|
||||
{
|
||||
return await (from dc in Cache
|
||||
where dc.Id == Arguments.Id
|
||||
select dc).AsEntity();
|
||||
}
|
||||
}
|
27
src/Connected.Common/Net/EndpointService.cs
Normal file
27
src/Connected.Common/Net/EndpointService.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System.Collections.Immutable;
|
||||
using Connected.Net;
|
||||
using Connected.Net.Endpoints;
|
||||
using Connected.ServiceModel;
|
||||
using Connected.Services;
|
||||
using Connected.Services.Annotations;
|
||||
|
||||
namespace Connected.Common.Net;
|
||||
|
||||
internal sealed class EndpointService : EntityService<int>, IEndpointService
|
||||
{
|
||||
public EndpointService(IContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
[ServiceAuthorization(NetClaims.NetDiscovery)]
|
||||
public async Task<ImmutableList<IEndpoint>?> Query()
|
||||
{
|
||||
return await Invoke(GetOperation<QueryEndpoints>(), Dto.Empty);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(NetClaims.NetDiscovery)]
|
||||
public async Task<IEndpoint?> Select(PrimaryKeyArgs<int> args)
|
||||
{
|
||||
return await Invoke(GetOperation<SelectEndpoint>(), args);
|
||||
}
|
||||
}
|
99
src/Connected.Common/SR.Designer.cs
generated
Normal file
99
src/Connected.Common/SR.Designer.cs
generated
Normal file
@ -0,0 +1,99 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <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.Common {
|
||||
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.Common.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 System roles are read only.
|
||||
/// </summary>
|
||||
internal static string ErrSysRole {
|
||||
get {
|
||||
return ResourceManager.GetString("ErrSysRole", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Disabled.
|
||||
/// </summary>
|
||||
internal static string RecordStatusDisabled {
|
||||
get {
|
||||
return ResourceManager.GetString("RecordStatusDisabled", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Enabled.
|
||||
/// </summary>
|
||||
internal static string RecordStatusEnabled {
|
||||
get {
|
||||
return ResourceManager.GetString("RecordStatusEnabled", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Cannot acquire distributed lock.
|
||||
/// </summary>
|
||||
internal static string ValLock {
|
||||
get {
|
||||
return ResourceManager.GetString("ValLock", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
132
src/Connected.Common/SR.resx
Normal file
132
src/Connected.Common/SR.resx
Normal file
@ -0,0 +1,132 @@
|
||||
<?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="ErrSysRole" xml:space="preserve">
|
||||
<value>System roles are read only</value>
|
||||
</data>
|
||||
<data name="RecordStatusDisabled" xml:space="preserve">
|
||||
<value>Disabled</value>
|
||||
</data>
|
||||
<data name="RecordStatusEnabled" xml:space="preserve">
|
||||
<value>Enabled</value>
|
||||
</data>
|
||||
<data name="ValLock" xml:space="preserve">
|
||||
<value>Cannot acquire distributed lock</value>
|
||||
</data>
|
||||
</root>
|
9
src/Connected.Common/Security/CommonClaims.cs
Normal file
9
src/Connected.Common/Security/CommonClaims.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace Connected.Common.Security;
|
||||
|
||||
public static class CommonClaims
|
||||
{
|
||||
public const string CommonDelete = "Common Delete";
|
||||
public const string CommonRead = "Common Read";
|
||||
public const string CommonAdd = "Common Add";
|
||||
public const string CommonModify = "Common Modify";
|
||||
}
|
17
src/Connected.Common/Security/Identity/IdentityService.cs
Normal file
17
src/Connected.Common/Security/Identity/IdentityService.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using Connected.Security.Identity;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Connected.Common.Security.Identity;
|
||||
|
||||
internal class IdentityService : IIdentityService
|
||||
{
|
||||
public IdentityService(IHttpContextAccessor contextAccessor)
|
||||
{
|
||||
HttpContext = contextAccessor.HttpContext;
|
||||
}
|
||||
|
||||
private HttpContext? HttpContext { get; }
|
||||
public IUser? CurrentUser => Identity?.User;
|
||||
public bool IsAuthenticated => Identity is not null && Identity.IsAuthenticated;
|
||||
private UserIdentity? Identity => HttpContext?.User?.Identity as UserIdentity;
|
||||
}
|
16
src/Connected.Common/Security/Identity/Role.cs
Normal file
16
src/Connected.Common/Security/Identity/Role.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using Connected.Annotations;
|
||||
using Connected.Entities.Annotations;
|
||||
using Connected.Entities.Consistency;
|
||||
using Connected.Security.Identity;
|
||||
|
||||
namespace Connected.Common.Security.Identity;
|
||||
|
||||
[Table(Schema = SchemaAttribute.SysSchema)]
|
||||
internal record Role : ConsistentEntity<int>, IRole
|
||||
{
|
||||
public const string CacheKey = $"{SchemaAttribute.SysSchema}.{nameof(Role)}";
|
||||
|
||||
[Length(128)]
|
||||
[Ordinal(0)]
|
||||
public string? Name { get; init; }
|
||||
}
|
40
src/Connected.Common/Security/Identity/RoleCache.cs
Normal file
40
src/Connected.Common/Security/Identity/RoleCache.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using Connected.Entities.Caching;
|
||||
using Connected.Security.Identity;
|
||||
|
||||
namespace Connected.Common.Security.Identity;
|
||||
|
||||
internal interface IRoleCache : IEntityCacheClient<Role, int> { }
|
||||
internal sealed class RoleCache : EntityCacheClient<Role, int>, IRoleCache
|
||||
{
|
||||
public RoleCache(IEntityCacheContext context) : base(context, Role.CacheKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override Task OnInitialized()
|
||||
{
|
||||
/*
|
||||
* Register system or predefined roles. This roles cannot be changed. They differ
|
||||
* from other roles in that they have a negative ids.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Full control role. This role passed all authorization policies.
|
||||
*/
|
||||
Set(-1, new Role { Id = -1, Name = Roles.FullControl }, TimeSpan.Zero);
|
||||
/*
|
||||
* Implicit role assigned to every authenticated user.
|
||||
*/
|
||||
Set(-2, new Role { Id = -2, Name = Roles.Authenticated }, TimeSpan.Zero);
|
||||
/*
|
||||
* Implicit role assigned to non authenticated user.
|
||||
*/
|
||||
Set(-3, new Role { Id = -3, Name = Roles.Anonymous }, TimeSpan.Zero);
|
||||
/*
|
||||
* Implicit role assigned to every user
|
||||
* regardless if it's authenticated or not.
|
||||
*/
|
||||
Set(-4, new Role { Id = -4, Name = Roles.Everyone }, TimeSpan.Zero);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
182
src/Connected.Common/Security/Identity/RoleOps.cs
Normal file
182
src/Connected.Common/Security/Identity/RoleOps.cs
Normal file
@ -0,0 +1,182 @@
|
||||
using System.Collections.Immutable;
|
||||
using Connected.Entities;
|
||||
using Connected.Entities.Storage;
|
||||
using Connected.Notifications;
|
||||
using Connected.Notifications.Events;
|
||||
using Connected.Security.Identity;
|
||||
using Connected.ServiceModel;
|
||||
using Connected.Services;
|
||||
using Connected.Validation;
|
||||
|
||||
namespace Connected.Common.Security.Identity;
|
||||
|
||||
internal sealed class QueryRoles : ServiceFunction<IDto, ImmutableList<IRole>>
|
||||
{
|
||||
public QueryRoles(IRoleCache cache)
|
||||
{
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private IRoleCache Cache { get; }
|
||||
protected override async Task<ImmutableList<IRole>?> OnInvoke()
|
||||
{
|
||||
return await (from dc in Cache
|
||||
select dc).AsEntities<IRole>();
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class SelectRole : ServiceFunction<PrimaryKeyArgs<int>, IRole?>
|
||||
{
|
||||
public SelectRole(IRoleCache cache)
|
||||
{
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private IRoleCache Cache { get; }
|
||||
protected override async Task<IRole?> OnInvoke()
|
||||
{
|
||||
return await (from dc in Cache
|
||||
where dc.Id == Arguments.Id
|
||||
select dc).AsEntity();
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class SelectRoleByName : ServiceFunction<NameArgs, IRole?>
|
||||
{
|
||||
public SelectRoleByName(IRoleCache cache)
|
||||
{
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private IRoleCache Cache { get; }
|
||||
protected override async Task<IRole?> OnInvoke()
|
||||
{
|
||||
return await (from dc in Cache
|
||||
where string.Equals(dc.Name, Arguments.Name, StringComparison.OrdinalIgnoreCase)
|
||||
select dc).AsEntity();
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class LookupRoles : ServiceFunction<PrimaryKeyListArgs<int>, ImmutableList<IRole>?>
|
||||
{
|
||||
public LookupRoles(IRoleCache cache)
|
||||
{
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private IRoleCache Cache { get; }
|
||||
protected override async Task<ImmutableList<IRole>?> OnInvoke()
|
||||
{
|
||||
if (Arguments.IdList is null)
|
||||
return default;
|
||||
|
||||
return await (from dc in Cache
|
||||
where Arguments.IdList.Any(f => f == dc.Id)
|
||||
select dc).AsEntities<IRole>();
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class InsertRole : ServiceFunction<RoleArgs, int>
|
||||
{
|
||||
public InsertRole(IRoleService roleService, IRoleCache cache, IStorageProvider storage, IEventService events)
|
||||
{
|
||||
RoleService = roleService;
|
||||
Cache = cache;
|
||||
Storage = storage;
|
||||
Events = events;
|
||||
}
|
||||
|
||||
private IStorageProvider Storage { get; }
|
||||
private IEventService Events { get; }
|
||||
private IRoleCache Cache { get; }
|
||||
private IRoleService RoleService { get; }
|
||||
|
||||
private IRole? Entity { get; set; }
|
||||
protected override async Task<int> OnInvoke()
|
||||
{
|
||||
if (await RoleService.Select(new NameArgs { Name = Arguments.Name }) is not null)
|
||||
throw ValidationExceptions.ValueExists(nameof(Arguments.Name), Arguments.Name);
|
||||
|
||||
if (Arguments.AsEntity<Role>(State.New) is not Role entity)
|
||||
throw EntityExceptions.EntityCastException(Arguments.GetType(), typeof(Role));
|
||||
|
||||
Entity = await Storage.Open<Role>().Update(entity);
|
||||
|
||||
return Entity.Id;
|
||||
}
|
||||
|
||||
protected override async Task OnCommitted()
|
||||
{
|
||||
await Cache.Refresh(Entity.Id);
|
||||
await Events.Enqueue(this, RoleService, nameof(IServiceNotifications<int>.Inserted), Result);
|
||||
}
|
||||
|
||||
protected override async Task OnRolledBack()
|
||||
{
|
||||
await Cache.Refresh(Result);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class DeleteRole : ServiceAction<PrimaryKeyArgs<int>>
|
||||
{
|
||||
public DeleteRole(IRoleService roleService, IStorageProvider storage, IRoleCache cache, IEventService events)
|
||||
{
|
||||
RoleService = roleService;
|
||||
Storage = storage;
|
||||
Cache = cache;
|
||||
Events = events;
|
||||
}
|
||||
|
||||
private IRoleService RoleService { get; }
|
||||
private IStorageProvider Storage { get; }
|
||||
private IRoleCache Cache { get; }
|
||||
private IEventService Events { get; }
|
||||
|
||||
protected override async Task OnInvoke()
|
||||
{
|
||||
if (await RoleService.Select(Arguments.Id) is IRole existing && existing.Id < 1)
|
||||
throw new AccessViolationException($"{SR.ErrSysRole} ({existing.Name})");
|
||||
|
||||
await Storage.Open<Role>().Update(new Role { Id = Arguments.Id, State = State.Deleted });
|
||||
}
|
||||
|
||||
protected override async Task OnCommitted()
|
||||
{
|
||||
await Cache.Remove(Arguments.Id);
|
||||
await Events.Enqueue(this, RoleService, ServiceEvents.Deleted, Arguments.Id);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class UpdateRole : ServiceAction<RoleUpdateArgs>
|
||||
{
|
||||
public UpdateRole(IRoleService roleService, IStorageProvider storage, IRoleCache cache, IEventService events)
|
||||
{
|
||||
RoleService = roleService;
|
||||
Storage = storage;
|
||||
Cache = cache;
|
||||
Events = events;
|
||||
}
|
||||
|
||||
private IStorageProvider Storage { get; }
|
||||
private IRoleCache Cache { get; }
|
||||
private IEventService Events { get; }
|
||||
private IRoleService RoleService { get; }
|
||||
|
||||
protected override async Task OnInvoke()
|
||||
{
|
||||
await Storage.Open<Role>().Update(await Load(), Arguments, async () =>
|
||||
{
|
||||
await Cache.Refresh(Arguments.Id);
|
||||
|
||||
return await Load();
|
||||
});
|
||||
|
||||
await Cache.Refresh(Arguments.Id);
|
||||
}
|
||||
|
||||
private async Task<Role> Load() => await (from dc in Cache where dc.Id == Arguments.Id select dc).AsEntity();
|
||||
protected override async Task OnCommitted()
|
||||
{
|
||||
await Events.Enqueue(this, RoleService, ServiceEvents.Updated, Arguments.Id);
|
||||
}
|
||||
}
|
57
src/Connected.Common/Security/Identity/RoleService.cs
Normal file
57
src/Connected.Common/Security/Identity/RoleService.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System.Collections.Immutable;
|
||||
using Connected.Security;
|
||||
using Connected.Security.Identity;
|
||||
using Connected.ServiceModel;
|
||||
using Connected.Services;
|
||||
using Connected.Services.Annotations;
|
||||
|
||||
namespace Connected.Common.Security.Identity;
|
||||
|
||||
internal class RoleService : EntityService<int>, IRoleService
|
||||
{
|
||||
public RoleService(IContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
[ServiceAuthorization(SecurityClaims.SecurityDelete)]
|
||||
public async Task Delete(PrimaryKeyArgs<int> args)
|
||||
{
|
||||
await Invoke(GetOperation<DeleteRole>(), args);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(SecurityClaims.SecurityAdd)]
|
||||
public async Task<int> Insert(RoleArgs args)
|
||||
{
|
||||
return await Invoke(GetOperation<InsertRole>(), args);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(SecurityClaims.SecurityRead)]
|
||||
public async Task<ImmutableList<IRole>?> Query()
|
||||
{
|
||||
return await Invoke(GetOperation<QueryRoles>(), Dto.Empty);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(SecurityClaims.SecurityRead)]
|
||||
public async Task<ImmutableList<IRole>?> Query(PrimaryKeyListArgs<int> args)
|
||||
{
|
||||
return await Invoke(GetOperation<LookupRoles>(), args);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(SecurityClaims.SecurityRead)]
|
||||
public async Task<IRole?> Select(PrimaryKeyArgs<int> args)
|
||||
{
|
||||
return await Invoke(GetOperation<SelectRole>(), args);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(SecurityClaims.SecurityRead)]
|
||||
public async Task<IRole?> Select(NameArgs args)
|
||||
{
|
||||
return await Invoke(GetOperation<SelectRoleByName>(), args);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(SecurityClaims.SecurityModify)]
|
||||
public async Task Update(RoleUpdateArgs args)
|
||||
{
|
||||
await Invoke(GetOperation<UpdateRole>(), args);
|
||||
}
|
||||
}
|
62
src/Connected.Common/Security/Identity/User.cs
Normal file
62
src/Connected.Common/Security/Identity/User.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using Connected.Annotations;
|
||||
using Connected.Entities.Annotations;
|
||||
using Connected.Entities.Consistency;
|
||||
using Connected.Security.Identity;
|
||||
|
||||
namespace Connected.Common.Security.Identity;
|
||||
|
||||
[Table(Schema = SchemaAttribute.SysSchema)]
|
||||
internal record class User : ConsistentEntity<int>, IUser, IUserPassport
|
||||
{
|
||||
public const string CacheKey = $"{SchemaAttribute.SysSchema}.{nameof(User)}";
|
||||
|
||||
[Length(32)]
|
||||
[Ordinal(0)]
|
||||
[Nullable]
|
||||
public string? FirstName { get; init; }
|
||||
|
||||
[Length(64)]
|
||||
[Ordinal(1)]
|
||||
[Nullable]
|
||||
public string? LastName { get; init; }
|
||||
|
||||
[Length(128)]
|
||||
[Ordinal(2)]
|
||||
[Nullable]
|
||||
public string? LoginName { get; init; }
|
||||
|
||||
[Length(256)]
|
||||
[Ordinal(3)]
|
||||
[Nullable]
|
||||
public string? Email { get; init; }
|
||||
|
||||
[Length(256)]
|
||||
[Ordinal(4)]
|
||||
[Nullable]
|
||||
public string? TimeZone { get; init; }
|
||||
|
||||
[Ordinal(5)]
|
||||
[Nullable]
|
||||
public int Language { get; init; }
|
||||
|
||||
[Ordinal(6)]
|
||||
[Nullable]
|
||||
[Length(256)]
|
||||
public byte[] Password { get; init; }
|
||||
|
||||
[Ordinal(7)]
|
||||
[Nullable]
|
||||
[Length(32)]
|
||||
public byte[] Pin { get; init; }
|
||||
|
||||
[Ordinal(8)]
|
||||
public UserStatus Status { get; init; }
|
||||
|
||||
[Nullable]
|
||||
[Ordinal(9)]
|
||||
public DateTime PasswordExpiration { get; init; }
|
||||
|
||||
[Nullable]
|
||||
[Ordinal(10)]
|
||||
public Guid AuthenticationToken { get; init; }
|
||||
}
|
11
src/Connected.Common/Security/Identity/UserCache.cs
Normal file
11
src/Connected.Common/Security/Identity/UserCache.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using Connected.Entities.Caching;
|
||||
|
||||
namespace Connected.Common.Security.Identity;
|
||||
|
||||
internal interface IUserCache : IEntityCacheClient<User, int> { }
|
||||
internal sealed class UserCache : EntityCacheClient<User, int>, IUserCache
|
||||
{
|
||||
public UserCache(IEntityCacheContext context) : base(context, User.CacheKey)
|
||||
{
|
||||
}
|
||||
}
|
236
src/Connected.Common/Security/Identity/UserOps.cs
Normal file
236
src/Connected.Common/Security/Identity/UserOps.cs
Normal file
@ -0,0 +1,236 @@
|
||||
using System.Collections.Immutable;
|
||||
using Connected.Entities;
|
||||
using Connected.Entities.Storage;
|
||||
using Connected.Notifications.Events;
|
||||
using Connected.Security.Cryptography;
|
||||
using Connected.Security.Identity;
|
||||
using Connected.ServiceModel;
|
||||
using Connected.Services;
|
||||
|
||||
namespace Connected.Common.Security.Identity;
|
||||
|
||||
internal sealed class QueryUsers : ServiceFunction<IDto, ImmutableList<IUser>?>
|
||||
{
|
||||
public QueryUsers(IUserCache cache)
|
||||
{
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private IUserCache Cache { get; }
|
||||
protected override async Task<ImmutableList<IUser>?> OnInvoke()
|
||||
{
|
||||
return await (from dc in Cache select dc).AsEntities<IUser>();
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class SelectUser : ServiceFunction<PrimaryKeyArgs<int>, IUser?>
|
||||
{
|
||||
public SelectUser(IUserCache cache)
|
||||
{
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private IUserCache Cache { get; }
|
||||
protected override async Task<IUser?> OnInvoke()
|
||||
{
|
||||
return await (from dc in Cache
|
||||
where dc.Id == Arguments.Id
|
||||
select dc).AsEntity();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Resolves user by a specified criteria string
|
||||
/// </summary>
|
||||
internal sealed class ResolveUser : ServiceFunction<UserResolveArgs, IUser?>
|
||||
{
|
||||
public ResolveUser(IUserCache cache)
|
||||
{
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private IUserCache Cache { get; }
|
||||
protected override async Task<IUser?> OnInvoke()
|
||||
{
|
||||
/*
|
||||
* First, try to resolve by login name
|
||||
*/
|
||||
if (await (from dc in Cache where string.Equals(dc.LoginName, Arguments.Criteria, StringComparison.OrdinalIgnoreCase) select dc).AsEntity() is IUser user)
|
||||
return user;
|
||||
/*
|
||||
* Next, try by authentication token
|
||||
*/
|
||||
if (Guid.TryParse(Arguments.Criteria, out Guid authenticationToken))
|
||||
{
|
||||
if (await (from dc in Cache where dc.AuthenticationToken == authenticationToken select dc).AsEntity() is IUser authUser)
|
||||
return authUser;
|
||||
}
|
||||
/*
|
||||
* Next, try by email
|
||||
*/
|
||||
if (Arguments.Criteria?.Contains('@') == true)
|
||||
{
|
||||
if (await (from dc in Cache where string.Equals(dc.Email, Arguments.Criteria, StringComparison.OrdinalIgnoreCase) select dc).AsEntity() is IUser emailUser)
|
||||
return emailUser;
|
||||
}
|
||||
/*
|
||||
* Now by id
|
||||
*/
|
||||
if (int.TryParse(Arguments.Criteria, out int id))
|
||||
{
|
||||
if (await (from dc in Cache where dc.Id == id select dc).AsEntity() is IUser idUser)
|
||||
return idUser;
|
||||
}
|
||||
/*
|
||||
* Doesn't exist.
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class LookupUsers : ServiceFunction<PrimaryKeyListArgs<int>, ImmutableList<IUser>?>
|
||||
{
|
||||
public LookupUsers(IUserCache cache)
|
||||
{
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private IUserCache Cache { get; }
|
||||
protected override async Task<ImmutableList<IUser>?> OnInvoke()
|
||||
{
|
||||
if (Arguments.IdList is null)
|
||||
return default;
|
||||
|
||||
return await (from dc in Cache
|
||||
where Arguments.IdList.Contains(dc.Id)
|
||||
select dc).AsEntities<IUser>();
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class InsertUser : ServiceFunction<UserInsertArgs, int>
|
||||
{
|
||||
public InsertUser(IUserService userService, IUserCache cache, IStorageProvider storage, IEventService events)
|
||||
{
|
||||
UserService = userService;
|
||||
Cache = cache;
|
||||
Storage = storage;
|
||||
Events = events;
|
||||
}
|
||||
|
||||
private IUserCache Cache { get; }
|
||||
private IStorageProvider Storage { get; }
|
||||
private IEventService Events { get; }
|
||||
private IUserService UserService { get; }
|
||||
|
||||
protected override async Task<int> OnInvoke()
|
||||
{
|
||||
if (Arguments.AsEntity<User>(State.New) is not User entity)
|
||||
throw EntityExceptions.EntityCastException(Arguments.GetType(), typeof(User));
|
||||
|
||||
var result = await Storage.Open<User>().Update(entity);
|
||||
|
||||
return result.Id;
|
||||
}
|
||||
|
||||
protected override async Task OnCommitted()
|
||||
{
|
||||
await Cache.Refresh(Result);
|
||||
await Events.Enqueue(this, UserService, ServiceEvents.Inserted, Result);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class DeleteUser : ServiceAction<PrimaryKeyArgs<int>>
|
||||
{
|
||||
public DeleteUser(IUserService userService, IStorageProvider storage, IUserCache cache, IEventService events)
|
||||
{
|
||||
UserService = userService;
|
||||
Storage = storage;
|
||||
Cache = cache;
|
||||
Events = events;
|
||||
}
|
||||
|
||||
private IUserService UserService { get; }
|
||||
private IStorageProvider Storage { get; }
|
||||
private IUserCache Cache { get; }
|
||||
private IEventService Events { get; }
|
||||
|
||||
protected override async Task OnInvoke()
|
||||
{
|
||||
await Storage.Open<User>().Update(new User { Id = Arguments.Id, State = State.Deleted });
|
||||
}
|
||||
|
||||
protected override async Task OnCommitted()
|
||||
{
|
||||
await Cache.Remove(Arguments.Id);
|
||||
await Events.Enqueue(this, UserService, ServiceEvents.Deleted, Arguments.Id);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class UpdateUser : ServiceAction<UserUpdateArgs>
|
||||
{
|
||||
public UpdateUser(IUserService userService, IUserCache cache, IStorageProvider storage, IEventService events)
|
||||
{
|
||||
UserService = userService;
|
||||
Cache = cache;
|
||||
Storage = storage;
|
||||
Events = events;
|
||||
}
|
||||
|
||||
private IUserService UserService { get; }
|
||||
private IUserCache Cache { get; }
|
||||
private IStorageProvider Storage { get; }
|
||||
private IEventService Events { get; }
|
||||
|
||||
protected override async Task OnInvoke()
|
||||
{
|
||||
await Storage.Open<User>().Update(await Load(), Arguments, async () =>
|
||||
{
|
||||
await Cache.Refresh(Arguments.Id);
|
||||
|
||||
return await Load();
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<User?> Load() => await (from dc in Cache where dc.Id == Arguments.Id select dc).AsEntity();
|
||||
|
||||
protected override async Task OnCommitted()
|
||||
{
|
||||
await Cache.Refresh(Arguments.Id);
|
||||
await Events.Enqueue(this, UserService, ServiceEvents.Updated, Arguments.Id);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class UserUpdatePassword : ServiceAction<UserPasswordArgs>
|
||||
{
|
||||
public UserUpdatePassword(IUserService userService, ICryptographyService cryptographyService, IStorageProvider storage, IUserCache cache, IEventService events)
|
||||
{
|
||||
UserService = userService;
|
||||
CryptographyService = cryptographyService;
|
||||
Storage = storage;
|
||||
Cache = cache;
|
||||
Events = events;
|
||||
}
|
||||
|
||||
private IUserService UserService { get; }
|
||||
private ICryptographyService CryptographyService { get; }
|
||||
private IStorageProvider Storage { get; }
|
||||
public IUserCache Cache { get; }
|
||||
public IEventService Events { get; }
|
||||
|
||||
protected override async Task OnInvoke()
|
||||
{
|
||||
await Storage.Open<User>().Update(await Load(), Arguments, async () =>
|
||||
{
|
||||
await Cache.Refresh(Arguments.Id);
|
||||
|
||||
return await Load();
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<User?> Load() => await (from dc in Cache where dc.Id == Arguments.Id select dc).AsEntity();
|
||||
|
||||
protected override async Task OnCommitted()
|
||||
{
|
||||
await Cache.Refresh(Arguments.Id);
|
||||
await Events.Enqueue(this, UserService, ServiceEvents.Updated, Arguments.Id);
|
||||
}
|
||||
}
|
63
src/Connected.Common/Security/Identity/UserService.cs
Normal file
63
src/Connected.Common/Security/Identity/UserService.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using System.Collections.Immutable;
|
||||
using Connected.Security;
|
||||
using Connected.Security.Identity;
|
||||
using Connected.ServiceModel;
|
||||
using Connected.Services;
|
||||
using Connected.Services.Annotations;
|
||||
|
||||
namespace Connected.Common.Security.Identity;
|
||||
|
||||
internal class UserService : EntityService<int>, IUserService
|
||||
{
|
||||
public UserService(IContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
[ServiceAuthorization(SecurityClaims.SecurityDelete)]
|
||||
public async Task Delete(PrimaryKeyArgs<int> args)
|
||||
{
|
||||
await Invoke(GetOperation<DeleteUser>(), args);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(SecurityClaims.SecurityAdd)]
|
||||
public async Task<int> Insert(UserInsertArgs args)
|
||||
{
|
||||
return await Invoke(GetOperation<InsertUser>(), args);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(SecurityClaims.SecurityRead)]
|
||||
public async Task<ImmutableList<IUser>?> Query()
|
||||
{
|
||||
return await Invoke(GetOperation<QueryUsers>(), Dto.Empty);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(SecurityClaims.SecurityRead)]
|
||||
public async Task<ImmutableList<IUser>?> Query(PrimaryKeyListArgs<int> args)
|
||||
{
|
||||
return await Invoke(GetOperation<LookupUsers>(), args);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(SecurityClaims.SecurityRead)]
|
||||
public async Task<IUser?> Resolve(UserResolveArgs args)
|
||||
{
|
||||
return await Invoke(GetOperation<ResolveUser>(), args);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(SecurityClaims.SecurityRead)]
|
||||
public async Task<IUser?> Select(PrimaryKeyArgs<int> args)
|
||||
{
|
||||
return await Invoke(GetOperation<SelectUser>(), args);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(SecurityClaims.SecurityModify, SecurityClaims.SecurityModifySelf)]
|
||||
public async Task Update(UserUpdateArgs args)
|
||||
{
|
||||
await Invoke(GetOperation<UpdateUser>(), args);
|
||||
}
|
||||
|
||||
[ServiceAuthorization(SecurityClaims.SecurityModify, SecurityClaims.SecurityModifySelf)]
|
||||
public async Task UpdatePassword(UserPasswordArgs args)
|
||||
{
|
||||
await Invoke(GetOperation<UserUpdatePassword>(), args);
|
||||
}
|
||||
}
|
20
src/Connected.Common/Security/Membership/Membership.cs
Normal file
20
src/Connected.Common/Security/Membership/Membership.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using Connected.Annotations;
|
||||
using Connected.Entities;
|
||||
using Connected.Entities.Annotations;
|
||||
using Connected.Security.Membership;
|
||||
|
||||
namespace Connected.Common.Security.Membership;
|
||||
|
||||
[Table(Schema = SchemaAttribute.SysSchema)]
|
||||
internal sealed record Membership : Entity<int>, IMembership
|
||||
{
|
||||
public const string CacheKey = $"{SchemaAttribute.SysSchema}.{nameof(Membership)}";
|
||||
|
||||
[Ordinal(0)]
|
||||
[Index(Name = $"idx_{SchemaAttribute.SysSchema}_{nameof(User)}_{nameof(Role)}", Unique = true)]
|
||||
public int User { get; init; }
|
||||
|
||||
[Ordinal(1)]
|
||||
[Index(Name = $"idx_{SchemaAttribute.SysSchema}_{nameof(User)}_{nameof(Role)}", Unique = true)]
|
||||
public int Role { get; init; }
|
||||
}
|
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