diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b1977ef --- /dev/null +++ b/.editorconfig @@ -0,0 +1,478 @@ +# editorconfig.org + +# top-most EditorConfig file +root = true + +# Default settings: +# A newline ending every file +# Use 4 spaces as indentation +[*] +insert_final_newline = true +indent_style = space +indent_size = 4 + +[project.json] +indent_size = 2 + +# C# files +[*.cs] +# New line preferences +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true +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_switch_labels = true +csharp_indent_labels = one_less_than_current + +# Modifier preferences +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion + +# use this. +dotnet_style_qualification_for_field = true:none +dotnet_style_qualification_for_property = true:none +dotnet_style_qualification_for_method = true:none +dotnet_style_qualification_for_event = true:none + +# only use var when it's obvious what the variable type is +csharp_style_var_for_built_in_types = true:none +csharp_style_var_when_type_is_apparent = true:none +csharp_style_var_elsewhere = true:none + +# Types: use keywords instead of BCL types, and permit var only when the type is clear +csharp_style_var_for_built_in_types = false:suggestion +csharp_style_var_when_type_is_apparent = false:none +csharp_style_var_elsewhere = false:suggestion +dotnet_style_predefined_type_for_locals_parameters_members = true:warning +dotnet_style_predefined_type_for_member_access = true:warning + +# name all constant fields using PascalCase +dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields +dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style +dotnet_naming_symbols.constant_fields.applicable_kinds = field +dotnet_naming_symbols.constant_fields.required_modifiers = const +dotnet_naming_style.pascal_case_style.capitalization = pascal_case + +# static fields should have s_ prefix +dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion +dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields +dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style +dotnet_naming_symbols.static_fields.applicable_kinds = field +dotnet_naming_symbols.static_fields.required_modifiers = static +dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected +dotnet_naming_style.static_prefix_style.required_prefix = s_ +dotnet_naming_style.static_prefix_style.capitalization = camel_case + +# internal and private fields should be _camelCase +dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion +dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields +dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style +dotnet_naming_symbols.private_internal_fields.applicable_kinds = field +dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal +dotnet_naming_style.camel_case_underscore_style.required_prefix = _ +dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case + +# Code style defaults +csharp_using_directive_placement = outside_namespace:warning +dotnet_separate_import_directive_groups = false +dotnet_sort_system_directives_first = true +csharp_prefer_braces = true:silent +csharp_preserve_single_line_blocks = true:none +csharp_preserve_single_line_statements = false:none +csharp_prefer_static_local_function = true:suggestion +csharp_prefer_simple_using_statement = false:none + +# Code quality +dotnet_style_readonly_field = true:suggestion +dotnet_code_quality_unused_parameters = non_public:suggestion + +# Parentheses preferences +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent + +# Modifier preferences +dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning + +# Field preferences +dotnet_style_readonly_field = true:warning + +# Expression-level preferences +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_auto_properties = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +csharp_prefer_simple_default_expression = true:suggestion +dotnet_style_prefer_compound_assignment = true:warning +dotnet_style_prefer_simplified_interpolation = true:suggestion + +# Expression-bodied members +csharp_style_expression_bodied_methods = true:suggestion +csharp_style_expression_bodied_constructors = true:suggestion +csharp_style_expression_bodied_operators = true:suggestion +csharp_style_expression_bodied_properties = true:suggestion +csharp_style_expression_bodied_indexers = true:suggestion +csharp_style_expression_bodied_accessors = true:suggestion +csharp_style_expression_bodied_lambdas = true:suggestion +csharp_style_expression_bodied_local_functions = true:suggestion + +# Pattern matching +csharp_style_pattern_matching_over_as_with_null_check = true:warning +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_inlined_variable_declaration = true:suggestion +csharp_style_prefer_switch_expression = true:suggestion + +# Null checking preferences +csharp_style_throw_expression = true:suggestion +csharp_style_conditional_delegate_call = true:suggestion + +# Other features +csharp_style_prefer_index_operator = false:none +csharp_style_prefer_range_operator = false:none +csharp_style_pattern_local_over_anonymous_function = false:none + +# Space preferences +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = do_not_ignore +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +# analyzers +# CA1851: Possible multiple enumerations of 'IEnumerable' collection - https://github.com/dotnet/roslyn-analyzers/issues/6379 +dotnet_diagnostic.CA1851.severity = suggestion + +dotnet_diagnostic.AvoidAsyncVoid.severity = suggestion + +dotnet_diagnostic.CA1000.severity = none +dotnet_diagnostic.CA1001.severity = error +dotnet_diagnostic.CA1009.severity = error +dotnet_diagnostic.CA1016.severity = error +dotnet_diagnostic.CA1030.severity = none +dotnet_diagnostic.CA1031.severity = none +dotnet_diagnostic.CA1033.severity = none +dotnet_diagnostic.CA1036.severity = none +dotnet_diagnostic.CA1049.severity = error +dotnet_diagnostic.CA1056.severity = suggestion +dotnet_diagnostic.CA1060.severity = error +dotnet_diagnostic.CA1061.severity = error +dotnet_diagnostic.CA1063.severity = error +dotnet_diagnostic.CA1065.severity = error +dotnet_diagnostic.CA1301.severity = error +dotnet_diagnostic.CA1303.severity = none +dotnet_diagnostic.CA1308.severity = none +dotnet_diagnostic.CA1400.severity = error +dotnet_diagnostic.CA1401.severity = error +dotnet_diagnostic.CA1403.severity = error +dotnet_diagnostic.CA1404.severity = error +dotnet_diagnostic.CA1405.severity = error +dotnet_diagnostic.CA1410.severity = error +dotnet_diagnostic.CA1415.severity = error +dotnet_diagnostic.CA1507.severity = error +dotnet_diagnostic.CA1710.severity = suggestion +dotnet_diagnostic.CA1724.severity = none +dotnet_diagnostic.CA1810.severity = none +dotnet_diagnostic.CA1821.severity = error +dotnet_diagnostic.CA1900.severity = error +dotnet_diagnostic.CA1901.severity = error +dotnet_diagnostic.CA2000.severity = none +dotnet_diagnostic.CA2002.severity = error +dotnet_diagnostic.CA2007.severity = none +dotnet_diagnostic.CA2100.severity = error +dotnet_diagnostic.CA2101.severity = error +dotnet_diagnostic.CA2108.severity = error +dotnet_diagnostic.CA2111.severity = error +dotnet_diagnostic.CA2112.severity = error +dotnet_diagnostic.CA2114.severity = error +dotnet_diagnostic.CA2116.severity = error +dotnet_diagnostic.CA2117.severity = error +dotnet_diagnostic.CA2122.severity = error +dotnet_diagnostic.CA2123.severity = error +dotnet_diagnostic.CA2124.severity = error +dotnet_diagnostic.CA2126.severity = error +dotnet_diagnostic.CA2131.severity = error +dotnet_diagnostic.CA2132.severity = error +dotnet_diagnostic.CA2133.severity = error +dotnet_diagnostic.CA2134.severity = error +dotnet_diagnostic.CA2137.severity = error +dotnet_diagnostic.CA2138.severity = error +dotnet_diagnostic.CA2140.severity = error +dotnet_diagnostic.CA2141.severity = error +dotnet_diagnostic.CA2146.severity = error +dotnet_diagnostic.CA2147.severity = error +dotnet_diagnostic.CA2149.severity = error +dotnet_diagnostic.CA2200.severity = error +dotnet_diagnostic.CA2202.severity = error +dotnet_diagnostic.CA2207.severity = error +dotnet_diagnostic.CA2212.severity = error +dotnet_diagnostic.CA2213.severity = error +dotnet_diagnostic.CA2214.severity = error +dotnet_diagnostic.CA2216.severity = error +dotnet_diagnostic.CA2220.severity = error +dotnet_diagnostic.CA2229.severity = error +dotnet_diagnostic.CA2231.severity = error +dotnet_diagnostic.CA2232.severity = error +dotnet_diagnostic.CA2235.severity = error +dotnet_diagnostic.CA2236.severity = error +dotnet_diagnostic.CA2237.severity = error +dotnet_diagnostic.CA2238.severity = error +dotnet_diagnostic.CA2240.severity = error +dotnet_diagnostic.CA2241.severity = error +dotnet_diagnostic.CA2242.severity = error + +dotnet_diagnostic.CS1701.severity = silent + +dotnet_diagnostic.RCS1001.severity = error +dotnet_diagnostic.RCS1018.severity = error +dotnet_diagnostic.RCS1037.severity = error +dotnet_diagnostic.RCS1055.severity = error +dotnet_diagnostic.RCS1062.severity = error +dotnet_diagnostic.RCS1066.severity = error +dotnet_diagnostic.RCS1069.severity = suggestion +dotnet_diagnostic.RCS1071.severity = error +dotnet_diagnostic.RCS1074.severity = error +dotnet_diagnostic.RCS1090.severity = suggestion +dotnet_diagnostic.RCS1138.severity = error +dotnet_diagnostic.RCS1139.severity = error +dotnet_diagnostic.RCS1163.severity = suggestion +dotnet_diagnostic.RCS1168.severity = suggestion +dotnet_diagnostic.RCS1188.severity = error +dotnet_diagnostic.RCS1201.severity = error +dotnet_diagnostic.RCS1207.severity = error +dotnet_diagnostic.RCS1211.severity = error +dotnet_diagnostic.RCS1507.severity = error + +dotnet_diagnostic.SA1000.severity = error +dotnet_diagnostic.SA1001.severity = error +dotnet_diagnostic.SA1002.severity = error +dotnet_diagnostic.SA1003.severity = error +dotnet_diagnostic.SA1004.severity = error +dotnet_diagnostic.SA1005.severity = error +dotnet_diagnostic.SA1006.severity = error +dotnet_diagnostic.SA1007.severity = error +dotnet_diagnostic.SA1008.severity = error +dotnet_diagnostic.SA1009.severity = error +dotnet_diagnostic.SA1010.severity = error +dotnet_diagnostic.SA1011.severity = error +dotnet_diagnostic.SA1012.severity = error +dotnet_diagnostic.SA1013.severity = error +dotnet_diagnostic.SA1014.severity = error +dotnet_diagnostic.SA1015.severity = error +dotnet_diagnostic.SA1016.severity = error +dotnet_diagnostic.SA1017.severity = error +dotnet_diagnostic.SA1018.severity = error +dotnet_diagnostic.SA1019.severity = error +dotnet_diagnostic.SA1020.severity = error +dotnet_diagnostic.SA1021.severity = error +dotnet_diagnostic.SA1022.severity = error +dotnet_diagnostic.SA1023.severity = error +dotnet_diagnostic.SA1024.severity = error +dotnet_diagnostic.SA1025.severity = error +dotnet_diagnostic.SA1026.severity = error +dotnet_diagnostic.SA1027.severity = error +dotnet_diagnostic.SA1028.severity = error +dotnet_diagnostic.SA1100.severity = error +dotnet_diagnostic.SA1101.severity = suggestion +dotnet_diagnostic.SA1102.severity = error +dotnet_diagnostic.SA1103.severity = error +dotnet_diagnostic.SA1104.severity = error +dotnet_diagnostic.SA1105.severity = error +dotnet_diagnostic.SA1106.severity = error +dotnet_diagnostic.SA1107.severity = error +dotnet_diagnostic.SA1108.severity = error +dotnet_diagnostic.SA1110.severity = error +dotnet_diagnostic.SA1111.severity = error +dotnet_diagnostic.SA1112.severity = error +dotnet_diagnostic.SA1113.severity = error +dotnet_diagnostic.SA1114.severity = error +dotnet_diagnostic.SA1115.severity = error +dotnet_diagnostic.SA1116.severity = error +dotnet_diagnostic.SA1117.severity = suggestion +dotnet_diagnostic.SA1118.severity = error +dotnet_diagnostic.SA1119.severity = error +dotnet_diagnostic.SA1120.severity = error +dotnet_diagnostic.SA1121.severity = error +dotnet_diagnostic.SA1122.severity = error +dotnet_diagnostic.SA1123.severity = error +dotnet_diagnostic.SA1124.severity = error +dotnet_diagnostic.SA1125.severity = error +dotnet_diagnostic.SA1127.severity = error +dotnet_diagnostic.SA1128.severity = error +dotnet_diagnostic.SA1129.severity = error +dotnet_diagnostic.SA1130.severity = error +dotnet_diagnostic.SA1131.severity = error +dotnet_diagnostic.SA1132.severity = suggestion +dotnet_diagnostic.SA1133.severity = error +dotnet_diagnostic.SA1134.severity = error +dotnet_diagnostic.SA1135.severity = error +dotnet_diagnostic.SA1136.severity = error +dotnet_diagnostic.SA1137.severity = error +dotnet_diagnostic.SA1139.severity = error +dotnet_diagnostic.SA1200.severity = none +dotnet_diagnostic.SA1201.severity = suggestion +dotnet_diagnostic.SA1202.severity = suggestion +dotnet_diagnostic.SA1203.severity = error +dotnet_diagnostic.SA1204.severity = suggestion +dotnet_diagnostic.SA1205.severity = error +dotnet_diagnostic.SA1206.severity = error +dotnet_diagnostic.SA1207.severity = error +dotnet_diagnostic.SA1208.severity = error +dotnet_diagnostic.SA1209.severity = error +dotnet_diagnostic.SA1210.severity = error +dotnet_diagnostic.SA1211.severity = error +dotnet_diagnostic.SA1212.severity = error +dotnet_diagnostic.SA1213.severity = error +dotnet_diagnostic.SA1214.severity = error +dotnet_diagnostic.SA1216.severity = error +dotnet_diagnostic.SA1217.severity = error +dotnet_diagnostic.SA1300.severity = suggestion +dotnet_diagnostic.SA1302.severity = error +dotnet_diagnostic.SA1303.severity = error +dotnet_diagnostic.SA1304.severity = error +dotnet_diagnostic.SA1306.severity = none +dotnet_diagnostic.SA1307.severity = error +dotnet_diagnostic.SA1308.severity = error +dotnet_diagnostic.SA1309.severity = none +dotnet_diagnostic.SA1310.severity = error +dotnet_diagnostic.SA1311.severity = none +dotnet_diagnostic.SA1312.severity = error +dotnet_diagnostic.SA1313.severity = error +dotnet_diagnostic.SA1314.severity = error +dotnet_diagnostic.SA1316.severity = none +dotnet_diagnostic.SA1400.severity = error +dotnet_diagnostic.SA1401.severity = suggestion +dotnet_diagnostic.SA1402.severity = suggestion +dotnet_diagnostic.SA1403.severity = error +dotnet_diagnostic.SA1404.severity = error +dotnet_diagnostic.SA1405.severity = error +dotnet_diagnostic.SA1406.severity = error +dotnet_diagnostic.SA1407.severity = error +dotnet_diagnostic.SA1408.severity = error +dotnet_diagnostic.SA1410.severity = error +dotnet_diagnostic.SA1411.severity = error +dotnet_diagnostic.SA1413.severity = error +dotnet_diagnostic.SA1500.severity = error +dotnet_diagnostic.SA1501.severity = error +dotnet_diagnostic.SA1502.severity = error +dotnet_diagnostic.SA1503.severity = error +dotnet_diagnostic.SA1504.severity = error +dotnet_diagnostic.SA1505.severity = error +dotnet_diagnostic.SA1506.severity = error +dotnet_diagnostic.SA1507.severity = error +dotnet_diagnostic.SA1508.severity = error +dotnet_diagnostic.SA1509.severity = error +dotnet_diagnostic.SA1510.severity = error +dotnet_diagnostic.SA1511.severity = error +dotnet_diagnostic.SA1512.severity = error +dotnet_diagnostic.SA1513.severity = error +dotnet_diagnostic.SA1514.severity = error +dotnet_diagnostic.SA1515.severity = error +dotnet_diagnostic.SA1516.severity = error +dotnet_diagnostic.SA1517.severity = error +dotnet_diagnostic.SA1518.severity = error +dotnet_diagnostic.SA1519.severity = error +dotnet_diagnostic.SA1520.severity = error +dotnet_diagnostic.SA1600.severity = suggestion +dotnet_diagnostic.SA1601.severity = error +dotnet_diagnostic.SA1602.severity = error +dotnet_diagnostic.SA1604.severity = error +dotnet_diagnostic.SA1605.severity = error +dotnet_diagnostic.SA1606.severity = error +dotnet_diagnostic.SA1607.severity = error +dotnet_diagnostic.SA1608.severity = error +dotnet_diagnostic.SA1610.severity = error +dotnet_diagnostic.SA1611.severity = error +dotnet_diagnostic.SA1612.severity = error +dotnet_diagnostic.SA1613.severity = error +dotnet_diagnostic.SA1614.severity = error +dotnet_diagnostic.SA1615.severity = error +dotnet_diagnostic.SA1616.severity = error +dotnet_diagnostic.SA1617.severity = error +dotnet_diagnostic.SA1618.severity = error +dotnet_diagnostic.SA1619.severity = error +dotnet_diagnostic.SA1620.severity = error +dotnet_diagnostic.SA1621.severity = error +dotnet_diagnostic.SA1622.severity = error +dotnet_diagnostic.SA1623.severity = error +dotnet_diagnostic.SA1624.severity = error +dotnet_diagnostic.SA1625.severity = error +dotnet_diagnostic.SA1626.severity = error +dotnet_diagnostic.SA1627.severity = error +dotnet_diagnostic.SA1629.severity = error +dotnet_diagnostic.SA1633.severity = none +dotnet_diagnostic.SA1634.severity = error +dotnet_diagnostic.SA1635.severity = error +dotnet_diagnostic.SA1636.severity = none +dotnet_diagnostic.SA1637.severity = none +dotnet_diagnostic.SA1638.severity = none +dotnet_diagnostic.SA1640.severity = error +dotnet_diagnostic.SA1641.severity = error +dotnet_diagnostic.SA1642.severity = error +dotnet_diagnostic.SA1643.severity = error +dotnet_diagnostic.SA1649.severity = warning +dotnet_diagnostic.SA1651.severity = error + +dotnet_diagnostic.SX1101.severity = none +dotnet_diagnostic.SX1309.severity = error +dotnet_diagnostic.SX1623.severity = none + +# C++ Files +[*.{cpp,h,in}] +curly_bracket_next_line = true +indent_brace_style = Allman + +# Xml project files +[*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] +indent_size = 2 + +# Xml build files +[*.builds] +indent_size = 2 + +# Xml files +[*.{xml,stylecop,resx,ruleset}] +indent_size = 2 + +# Xml config files +[*.{props,targets,config,nuspec}] +indent_size = 2 + +# Shell scripts +[*.sh] +end_of_line = lf +[*.{cmd, bat}] +end_of_line = crlf diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9befbbf --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto + +# Explicitly declare text files you want to always be normalized and converted +# to native line endings on checkout. +*.cs text + +# Declare files that will always have CRLF line endings on checkout. +*.sln text eol=crlf \ No newline at end of file diff --git a/.github/workflows/nuget-publish.yml b/.github/workflows/nuget-publish.yml new file mode 100644 index 0000000..a915886 --- /dev/null +++ b/.github/workflows/nuget-publish.yml @@ -0,0 +1,135 @@ +name: Build and Publish NuGet Packages + +on: + push: + branches: [ main, master ] + tags: [ 'v*' ] + pull_request: + branches: [ main, master ] + +env: + DOTNET_VERSION: '9.0.x' + NUGET_SOURCE: 'https://api.nuget.org/v3/index.json' + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Required for GitVersion + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Install GitVersion + uses: gittools/actions/gitversion/setup@v0.10.2 + with: + versionSpec: '5.x' + + - name: Determine Version + uses: gittools/actions/gitversion/execute@v0.10.2 + id: gitversion + + - name: Display Version + run: | + echo "Version: ${{ steps.gitversion.outputs.semVer }}" + echo "NuGetVersionV2: ${{ steps.gitversion.outputs.nuGetVersionV2 }}" + + - name: Restore dependencies for core projects + run: | + dotnet restore EightBot.Orbit.Core/EightBot.Orbit.Core.csproj + dotnet restore EightBot.Orbit.Client/EightBot.Orbit.Client.csproj + dotnet restore EightBot.Orbit.Server/EightBot.Orbit.Server.csproj + dotnet restore EightBot.Orbit.Server.Web/EightBot.Orbit.Server.Web.csproj + dotnet restore EightBot.Orbit.Tests/EightBot.Orbit.Tests.csproj + + - name: Build core projects + run: | + dotnet build EightBot.Orbit.Core/EightBot.Orbit.Core.csproj --configuration Release --no-restore /p:Version=${{ steps.gitversion.outputs.assemblySemVer }} /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} + dotnet build EightBot.Orbit.Client/EightBot.Orbit.Client.csproj --configuration Release --no-restore /p:Version=${{ steps.gitversion.outputs.assemblySemVer }} /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} + dotnet build EightBot.Orbit.Server/EightBot.Orbit.Server.csproj --configuration Release --no-restore /p:Version=${{ steps.gitversion.outputs.assemblySemVer }} /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} + dotnet build EightBot.Orbit.Server.Web/EightBot.Orbit.Server.Web.csproj --configuration Release --no-restore /p:Version=${{ steps.gitversion.outputs.assemblySemVer }} /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} + dotnet build EightBot.Orbit.Tests/EightBot.Orbit.Tests.csproj --configuration Release --no-restore + + - name: Run tests + continue-on-error: true + run: dotnet test EightBot.Orbit.Tests/EightBot.Orbit.Tests.csproj --configuration Release --no-build --verbosity normal --filter "FullyQualifiedName~OrbitClientTests" + + - name: Pack NuGet packages + run: | + dotnet pack EightBot.Orbit.Core/EightBot.Orbit.Core.csproj --configuration Release --no-build --output ./artifacts /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} + dotnet pack EightBot.Orbit.Client/EightBot.Orbit.Client.csproj --configuration Release --no-build --output ./artifacts /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} + dotnet pack EightBot.Orbit.Server/EightBot.Orbit.Server.csproj --configuration Release --no-build --output ./artifacts /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} + dotnet pack EightBot.Orbit.Server.Web/EightBot.Orbit.Server.Web.csproj --configuration Release --no-build --output ./artifacts /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} + + - name: Upload NuGet packages as artifacts + uses: actions/upload-artifact@v4 + with: + name: nuget-packages + path: ./artifacts/*.nupkg + + outputs: + version: ${{ steps.gitversion.outputs.nuGetVersionV2 }} + + publish: + needs: build-and-test + runs-on: ubuntu-latest + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) + + steps: + - name: Download NuGet packages + uses: actions/download-artifact@v4 + with: + name: nuget-packages + path: ./artifacts + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Publish to NuGet (Release) + if: startsWith(github.ref, 'refs/tags/') + run: | + for package in ./artifacts/*.nupkg; do + echo "Publishing $package to NuGet..." + dotnet nuget push "$package" --api-key ${{ secrets.EIGHTBOT_NUGET_APIKEY }} --source ${{ env.NUGET_SOURCE }} --skip-duplicate + done + + - name: Publish to NuGet (Prerelease) + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' + run: | + for package in ./artifacts/*.nupkg; do + echo "Publishing $package to NuGet as prerelease..." + dotnet nuget push "$package" --api-key ${{ secrets.EIGHTBOT_NUGET_APIKEY }} --source ${{ env.NUGET_SOURCE }} --skip-duplicate + done + + create-release: + needs: [build-and-test, publish] + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Download NuGet packages + uses: actions/download-artifact@v4 + with: + name: nuget-packages + path: ./artifacts + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + files: ./artifacts/*.nupkg + generate_release_notes: true + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index c7bb927..8f18c28 100644 --- a/.gitignore +++ b/.gitignore @@ -1,406 +1,404 @@ -# globs -Makefile.in -*.userprefs -*.usertasks -config.make -config.status -aclocal.m4 -install-sh -autom4te.cache/ -*.tar.gz -tarballs/ -test-results/ - -# Mac bundle stuff -*.dmg -*.app - -# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore -# Windows thumbnail cache files -Thumbs.db -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# content below from: https://github.com/github/gitignore/blob/master/VisualStudio.gitignore -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -## -## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore - -# User-specific files -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ - -# Visual Studio 2015/2017 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# Visual Studio 2017 auto generated files -Generated\ Files/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# Benchmark Results -BenchmarkDotNet.Artifacts/ - -# .NET Core -project.lock.json -project.fragment.lock.json -artifacts/ - -# StyleCop -StyleCopReport.xml - -# Files built by Visual Studio -*_i.c -*_p.c -*_h.h -*.ilk -*.meta -*.obj -*.iobj -*.pch -*.pdb -*.ipdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*_wpftmp.csproj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# Visual Studio Trace Files -*.e2e - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# AxoCover is a Code Coverage Tool -.axoCover/* -!.axoCover/settings.json - -# Visual Studio code coverage results -*.coverage -*.coveragexml - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# Note: Comment the next line if you want to checkin your web deploy settings, -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* -# except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/[Pp]ackages/repositories.config -# NuGet v3's project.json files produces more ignorable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt -*.appx - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -orleans.codegen.cs - -# Including strong name files can present a security risk -# (https://github.com/github/gitignore/pull/2483#issue-259490424) -#*.snk - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm -ServiceFabricBackup/ -*.rptproj.bak - -# SQL Server files -*.mdf -*.ldf -*.ndf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings -*.rptproj.rsuser - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat -node_modules/ - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# JetBrains Rider -.idea/ -*.sln.iml - -# CodeRush personal settings -.cr/personal - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc - -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config - -# Tabs Studio -*.tss - -# Telerik's JustMock configuration file -*.jmconfig - -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs - -# OpenCover UI analysis results -OpenCover/ - -# Azure Stream Analytics local run output -ASALocalRun/ - -# MSBuild Binary and Structured Log -*.binlog - -# NVidia Nsight GPU debugger configuration file -*.nvuser - -# MFractors (Xamarin productivity tool) working folder -.mfractor/ - -# Local History for Visual Studio +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio .localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + +*.DS_Store + +.idea/ + tools/ diff --git a/Directory.build.props b/Directory.build.props new file mode 100644 index 0000000..8912cbd --- /dev/null +++ b/Directory.build.props @@ -0,0 +1,41 @@ + + + true + latest + $(NoWarn);CS1591 + + + Eight-Bot, Inc. + 2023 Eight-Bot + icon.png + Eight-Bot, Inc. + https://eight.bot + https://github.com/TheEightBot/TychoDB + git + nosql;database;json + Tycho DB + Lightweight and highly opioninated NoSQL database written on top of SQLite + Lightweight and highly opioninated NoSQL database written on top of SQLite + logo.png + + + + + + + + + + + + + diff --git a/EightBot.Orbit.Client/CategorySearch.cs b/EightBot.Orbit.Client/CategorySearch.cs deleted file mode 100644 index d19849b..0000000 --- a/EightBot.Orbit.Client/CategorySearch.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -namespace EightBot.Orbit.Client -{ - public enum CategorySearch - { - FullMatch, - StartsWith, - Contains - } -} diff --git a/EightBot.Orbit.Client/ClientNotInitializedException.cs b/EightBot.Orbit.Client/ClientNotInitializedException.cs index 6e1c170..077669d 100644 --- a/EightBot.Orbit.Client/ClientNotInitializedException.cs +++ b/EightBot.Orbit.Client/ClientNotInitializedException.cs @@ -1,24 +1,26 @@ using System; using System.Runtime.Serialization; -namespace EightBot.Orbit.Client +namespace EightBot.Orbit.Client; + +public class ClientNotInitializedException : Exception { - public class ClientNotInitializedException : Exception + public ClientNotInitializedException() { - public ClientNotInitializedException() - { - } + } - public ClientNotInitializedException(string message) : base(message) - { - } + public ClientNotInitializedException(string message) + : base(message) + { + } - public ClientNotInitializedException(string message, Exception innerException) : base(message, innerException) - { - } + public ClientNotInitializedException(string message, Exception innerException) + : base(message, innerException) + { + } - protected ClientNotInitializedException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } + protected ClientNotInitializedException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } } diff --git a/EightBot.Orbit.Client/EightBot.Orbit.Client.csproj b/EightBot.Orbit.Client/EightBot.Orbit.Client.csproj index f5346c5..0ef4fd2 100644 --- a/EightBot.Orbit.Client/EightBot.Orbit.Client.csproj +++ b/EightBot.Orbit.Client/EightBot.Orbit.Client.csproj @@ -1,17 +1,14 @@ - netstandard2.0 + net9.0 - - - - - + + diff --git a/EightBot.Orbit.Client/ISyncReconciler.cs b/EightBot.Orbit.Client/ISyncReconciler.cs index a51fa15..96ce98a 100644 --- a/EightBot.Orbit.Client/ISyncReconciler.cs +++ b/EightBot.Orbit.Client/ISyncReconciler.cs @@ -1,8 +1,6 @@ -using System; -namespace EightBot.Orbit.Client +namespace EightBot.Orbit.Client; + +public interface ISyncReconciler { - public interface ISyncReconciler - { - T Reconcile(ServerSyncInfo server, ClientSyncInfo client); - } -} + T Reconcile(ServerSyncInfo server, ClientSyncInfo client); +} \ No newline at end of file diff --git a/EightBot.Orbit.Client/OrbitClient.cs b/EightBot.Orbit.Client/OrbitClient.cs index 8da615f..b18b7fa 100644 --- a/EightBot.Orbit.Client/OrbitClient.cs +++ b/EightBot.Orbit.Client/OrbitClient.cs @@ -3,935 +3,748 @@ using System.IO; using System.Linq; using System.Linq.Expressions; -using System.Threading.Tasks; -using LiteDB; - -namespace EightBot.Orbit.Client +using System.Threading.RateLimiting; +using System.Threading.Tasks; +using TychoDB; + +namespace EightBot.Orbit.Client; + +public class OrbitClient : IDisposable { - public class OrbitClient - { - private const string - OrbitCacheDb = "OrbitCache.db", - SyncCollection = "Synchronizable", + private const string + OrbitCacheDb = "OrbitCache.db", + SyncCollection = "Synchronizable", - SynchronizableTypeIdIndex = nameof(Synchronizable.TypeId), - SynchronizableCategory = nameof(Synchronizable.Category), - SynchronizableTypeNameIndex = nameof(Synchronizable.TypeName), - SynchronizableModifiedTimestampIndex = nameof(Synchronizable.ModifiedTimestamp), - SynchronizableOperationIndex = nameof(Synchronizable.Operation); + SynchronizableTypeIdIndex = nameof(Synchronizable.TypeId), + SynchronizableModifiedTimestampIndex = nameof(Synchronizable.ModifiedTimestamp), + SynchronizableOperationIndex = nameof(Synchronizable.Operation); - private readonly object _scaffoldingLock = new object(); + private readonly object _scaffoldingLock = new object(); - private readonly ISyncReconciler _syncReconciler; + private readonly ISyncReconciler _syncReconciler; - private readonly Dictionary _registeredTypes = - new Dictionary(); + private readonly IJsonSerializer _jsonSerializer; - private readonly ProcessingQueue _processingQueue = new ProcessingQueue(); + private readonly RateLimiter _limiter = + new ConcurrencyLimiter( + new ConcurrencyLimiterOptions + { + PermitLimit = 1, + QueueLimit = int.MaxValue, + QueueProcessingOrder = QueueProcessingOrder.OldestFirst, + }); - private LiteDatabase _db; + private TychoDB.Tycho _db; + private bool _disposedValue; - private string _additionalConnectionStringParameters; + public static string PartitionSeparator { get; set; } = "___"; - public static string CategorySeparator { get; set; } = "___"; + public string CacheDirectory { get; private set; } - public string CachePath { get; private set; } + public string CachePath { get; private set; } - public bool Initialized { get; private set; } + public bool Initialized { get; private set; } - public OrbitClient(ISyncReconciler syncReconciler = null) - { - _syncReconciler = syncReconciler ?? new SyncReconcilers.ServerWinsSyncReconciler(); - } + public OrbitClient(IJsonSerializer jsonSerializer, ISyncReconciler syncReconciler = null) + { + _jsonSerializer = jsonSerializer; + _syncReconciler = syncReconciler ?? new SyncReconcilers.ServerWinsSyncReconciler(); + } - public OrbitClient Initialize(string cacheDirectory, string customCacheName = null, string additionalConnectionStringParameters = null, bool deleteExistingCache = false) + public OrbitClient Initialize(string cacheDirectory, string customCacheName = null, bool deleteExistingCache = false) + { + lock (_scaffoldingLock) { - lock(_scaffoldingLock) + if (Initialized) { - if(!Initialized) - { - Initialized = true; + return this; + } - CachePath = Path.Combine(cacheDirectory, customCacheName ?? OrbitCacheDb); + Initialized = true; - if(deleteExistingCache && File.Exists(CachePath)) - { - File.Delete(CachePath); - } + CacheDirectory = cacheDirectory; - _additionalConnectionStringParameters = additionalConnectionStringParameters; + CachePath = Path.Combine(cacheDirectory, customCacheName ?? OrbitCacheDb); - _db = new LiteDatabase($"Filename={CachePath};{additionalConnectionStringParameters}"); + if (deleteExistingCache && File.Exists(CachePath)) + { + File.Delete(CachePath); + } - try - { - _db.Shrink (); - } - catch (InvalidOperationException) - { - // There is not much we can do here. Some platforms do not accept this configuration - } + _db = new Tycho(cacheDirectory, _jsonSerializer, rebuildCache: deleteExistingCache, requireTypeRegistration: true); - var syncCollection = _db.GetCollection(SyncCollection); + _db.Connect() + .AddTypeRegistration>() + .CreateIndex>(x => x.TypeId, "idxSynchronizableTypeId") + .CreateIndex>(x => x.ModifiedTimestamp, "idxSynchronizableModifiedTimestamp") + .CreateIndex>(x => x.Operation, "idxSynchronizableOperation"); + } - syncCollection.EnsureIndex(SynchronizableTypeIdIndex); - syncCollection.EnsureIndex(SynchronizableCategory); - syncCollection.EnsureIndex(SynchronizableTypeNameIndex); - syncCollection.EnsureIndex(SynchronizableModifiedTimestampIndex); - syncCollection.EnsureIndex(SynchronizableOperationIndex); - } + return this; + } + + public OrbitClient Startup() + { + lock (_scaffoldingLock) + { + if (Initialized) + { + return this; } + _db.Connect(); + + Initialized = true; + return this; } + } - public OrbitClient Startup() + public void Shutdown() + { + lock (_scaffoldingLock) { - lock(_scaffoldingLock) + if (!Initialized) { - if (Initialized && _db != null) - { - return this; - } + return; + } - _db = new LiteDatabase($"Filename={CachePath};{_additionalConnectionStringParameters}"); - Initialized = true; + _db?.Disconnect(); - return this; - } + Initialized = false; } + } - public void Shutdown() + public OrbitClient AddTypeRegistration( + Expression> idSelector, + EqualityComparer idComparer = null) + where T : class + { + lock (_scaffoldingLock) { - lock(_scaffoldingLock) + if (!Initialized) { - if (!Initialized || _db == null) - return; - - _db?.Dispose(); - _db = null; - - Initialized = false; + throw new ClientNotInitializedException($"{nameof(Initialize)} must be called before you can add type registrations."); } - } - public Task CleanUp() - { - return _processingQueue - .Queue ( - () => - { - _db.Shrink (); - }); + _db.AddTypeRegistration(idSelector, idComparer) + .AddTypeRegistration, object>(x => x.TypeId); } - public OrbitClient AddTypeRegistration(Func additionalProcessing = null, string typeNameOverride = null) - where T : class + return this; + } + + public OrbitClient AddTypeRegistrationWithCustomKeySelector( + Func idSelector, + EqualityComparer idComparer = null) + where T : class + { + lock (_scaffoldingLock) { - lock (_scaffoldingLock) + if (!Initialized) { - if (!Initialized) - throw new ClientNotInitializedException($"{nameof(Initialize)} must be called before you can add type registrations."); + throw new ClientNotInitializedException($"{nameof(Initialize)} must be called before you can add type registrations."); + } - var rti = RegisteredTypeInformation.Create(typeNameOverride); + _db.AddTypeRegistrationWithCustomKeySelector(idSelector, idComparer) + .AddTypeRegistration, object>(x => x.TypeId); + } - _registeredTypes[rti.ObjectType] = rti; - } + return this; + } + public async Task<(bool Success, ClientOperationType OperationResult)> CreateAsync(T obj, string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); - return this; - } + var result = await ItemExistsAndAvailable(obj, partition).ConfigureAwait(false); - public OrbitClient AddTypeRegistration(Expression> idSelector, Func additionalProcessing = null, bool requiresIdMapping = false, string typeNameOverride = null) - where T : class + if (!result.IsDeleted && !result.Exists) { - lock(_scaffoldingLock) - { - if (!Initialized) - throw new ClientNotInitializedException($"{nameof(Initialize)} must be called before you can add type registrations."); + await _db + .WriteObjectAsync(GetAsSynchronizable(obj, ClientOperationType.Create), partition) + .ConfigureAwait(false); - var rti = RegisteredTypeInformation.Create(idSelector, typeNameOverride); + return (true, ClientOperationType.Create); + } - _registeredTypes[rti.ObjectType] = rti; + return (false, ClientOperationType.NoOperation); + } - if(requiresIdMapping) - { - _db.Mapper - .Entity() - .Id(idSelector, false); - } - } + public async Task<(bool Success, ClientOperationType OperationResult)> UpdateAsync(T obj, string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); + var result = await ItemExistsAndAvailable(obj, partition).ConfigureAwait(false); - return this; + if (!result.IsDeleted && result.Exists) + { + await _db + .WriteObjectAsync(GetAsSynchronizable(obj, ClientOperationType.Update, partition), partition) + .ConfigureAwait(false); + + return (true, ClientOperationType.Update); } - public OrbitClient AddTypeRegistration(Expression> idSelector, Expression> idProperty, bool requiresIdMapping = false, string typeNameOverride = null) - where T : class - { - lock(_scaffoldingLock) - { - if (!Initialized) - throw new ClientNotInitializedException($"{nameof(Initialize)} must be called before you can add type registrations."); + return (false, ClientOperationType.NoOperation); + } - var rti = RegisteredTypeInformation.Create(idSelector, idProperty, typeNameOverride); + public async Task<(bool Success, ClientOperationType OperationResult)> UpsertAsync(T obj, string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); - _registeredTypes[rti.ObjectType] = rti; + var result = await ItemExistsAndAvailable(obj, partition).ConfigureAwait(false); - if(requiresIdMapping) - { - _db.Mapper - .Entity() - .Id(idProperty, false); - } - } + if (!result.IsDeleted && result.Exists) + { + await _db + .WriteObjectAsync(GetAsSynchronizable(obj, ClientOperationType.Update, partition), partition) + .ConfigureAwait(false); - return this; + return (true, ClientOperationType.Update); } - - public Task<(bool Success, ClientOperationType OperationResult)> Create(T obj, string category = null) - where T : class + else if (!result.IsDeleted) { - return _processingQueue.Queue( - () => - { - var result = ItemExistsAndAvailable(obj, category); + await _db + .WriteObjectAsync(GetAsSynchronizable(obj, ClientOperationType.Create, partition), partition) + .ConfigureAwait(false); - if (!result.IsDeleted && !result.Exists) - { - var syncCollection = GetSynchronizableTypeCollection(); - syncCollection.Insert(GetAsSynchronizable(obj, ClientOperationType.Create, category)); + return (true, ClientOperationType.Create); + } - return (true, ClientOperationType.Create); - } + return (false, ClientOperationType.NoOperation); + } - return (false, ClientOperationType.NoOperation); - }); - } + public async Task<(bool Success, ClientOperationType OperationResult)> DeleteAsync(T obj, string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); - public Task<(bool Success, ClientOperationType OperationResult)> Update(T obj, string category = null) - where T : class - { - return _processingQueue.Queue( - () => - { - var result = ItemExistsAndAvailable(obj, category); - if (!result.IsDeleted && result.Exists) - { - var syncCollection = GetSynchronizableTypeCollection(); - syncCollection.Insert(GetAsSynchronizable(obj, ClientOperationType.Update, category)); - return (true, ClientOperationType.Update); - } - - return (false, ClientOperationType.NoOperation); - }); - } + var result = await ItemExistsAndAvailable(obj, partition).ConfigureAwait(false); - public Task<(bool Success, ClientOperationType OperationResult)> Upsert(T obj, string category = null) - where T : class + if (!result.IsDeleted && result.Exists) { - return _processingQueue.Queue( - () => - { - var syncCollection = GetSynchronizableTypeCollection(); - - var result = ItemExistsAndAvailable(obj, category); - - if (!result.IsDeleted && result.Exists) - { - syncCollection.Insert(GetAsSynchronizable(obj, ClientOperationType.Update, category)); - return (true, ClientOperationType.Update); - } - else if(!result.IsDeleted) - { - syncCollection.Insert(GetAsSynchronizable(obj, ClientOperationType.Create, category)); - return (true, ClientOperationType.Create); - } - - return (false, ClientOperationType.NoOperation); - }); - } + await _db.WriteObjectAsync(GetAsSynchronizable(obj, ClientOperationType.Delete, partition), partition); - public Task<(bool Success, ClientOperationType OperationResult)> Delete(T obj, string category = null) - where T : class - { - return _processingQueue.Queue( - () => - { - var result = ItemExistsAndAvailable(obj, category); - if (!result.IsDeleted && result.Exists) - { - var syncCollection = GetSynchronizableTypeCollection(); - syncCollection.Insert(GetAsSynchronizable(obj, ClientOperationType.Delete, category)); - return (true, ClientOperationType.Delete); - } - - return (false, ClientOperationType.NoOperation); - }); + return (true, ClientOperationType.Delete); } - public async Task> GetCategories() - where T : class - { - var rti = _registeredTypes[typeof(T)]; - var ctn = rti.GetCategoryTypeName(); - - var typeCollectionNames = - await _processingQueue - .Queue( - () => - { - return _db.GetCollectionNames() - ?.Where(x => x.StartsWith(ctn, StringComparison.Ordinal) && x.Contains(CategorySeparator)) - ?.Select(x => x.Substring(x.IndexOf(CategorySeparator, StringComparison.Ordinal) + CategorySeparator.Length)) - ?.ToList() - ?? new List(); - }) - .ConfigureAwait(false); + return (false, ClientOperationType.NoOperation); + } - //TODO: This could be optimized - var latestSyncables = await GetAllLatestSyncQueue().ConfigureAwait(false); - - var syncCategories = - await _processingQueue - .Queue( - () => - { - var syncCollection = GetSynchronizableTypeCollection(); - - return syncCollection - .Find(Query.And( - Query.Not(SynchronizableCategory, null), - Query.EQ(SynchronizableTypeNameIndex, GetTypeFullName()))) - .GroupBy(x => x.Category) - .Select(x => x.Key) - .ToList(); - }) - .ConfigureAwait(false); + public async Task> GetAllOfAsync(string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); - return syncCategories?.Any() ?? false - ? typeCollectionNames.Union(syncCategories) - : typeCollectionNames; - } + return await _db.ReadObjectsAsync(partition); + } - public Task> GetAllOf (string category = null) - where T : class - { - return _processingQueue.Queue( - () => - { - var typeCollection = GetTypeCollection(category); - - return typeCollection.FindAll().ToList(); - }); - } - - public async Task> GetAllLatest(string category = null) - where T : class - { - var allOfType = await GetAllOf(category).ConfigureAwait(false); + public async Task> GetAllLatestAsync(string partition = null) + where T : class + { + var allOfType = new List(await GetAllOfAsync(partition).ConfigureAwait(false)); - var latestSyncables = await GetAllLatestSyncQueue(category).ConfigureAwait(false); + var latestSyncables = await GetAllLatestSyncQueueAsync(partition).ConfigureAwait(false); - var rti = _registeredTypes[typeof(T)]; + var rti = _db.GetRegisteredTypeInformationFor(); - for (int i = 0; i < latestSyncables.Count; i++) - { - var latest = latestSyncables[i]; + var matchedIndexes = new List(); - var id = rti.GetId(latest); + for (int i = 0; i < latestSyncables.Count(); i++) + { + var latest = latestSyncables.ElementAt(i); - var index = allOfType - .FindIndex( - x => - { - var itemId = rti.GetId(x); - return itemId == id; - }); + var index = -1; - if (index >= 0) + for (int allOfTypeIndex = 0; allOfTypeIndex < allOfType.Count; allOfTypeIndex++) + { + if (matchedIndexes.Contains(allOfTypeIndex)) { - allOfType[index] = latest; + continue; } - else + + if (rti.CompareIdsFor(latest, allOfType[allOfTypeIndex])) { - allOfType.Add(latest); + matchedIndexes.Add(allOfTypeIndex); + index = allOfTypeIndex; + break; } } - return allOfType; + if (index >= 0) + { + allOfType[index] = latest; + } + else + { + allOfType.Add(latest); + } } - public Task GetLatest(T obj, string category = null) - where T : class - { - var rti = _registeredTypes[typeof(T)]; + return allOfType; + } - var id = rti.GetId(obj); + public async Task GetLatestAsync(object key, string partition = null) + where T : class + { + var syncQueueItem = await GetLatestSyncQueue(key, partition).ConfigureAwait(false); - return GetLatestInternal(id, category); + if (syncQueueItem == null) + { + return await _db.ReadObjectAsync(key, partition).ConfigureAwait(false); } - public Task GetLatest(TId id, string category = null) - where T : class + if (syncQueueItem.Operation == ClientOperationType.Delete) { - return GetLatestInternal(new BsonValue(id), category); + return default(T); } - private Task GetLatestInternal(BsonValue id, string category = null) - where T : class + return syncQueueItem.Value; + } + + public async Task GetLatestAsync(T obj, string partition = null) + where T : class + { + var syncQueueItem = await GetLatestSyncQueue(obj, partition).ConfigureAwait(false); + + if (syncQueueItem == null) { - return _processingQueue.Queue( - () => - { - var syncCollection = GetSynchronizableTypeCollection(); + return await _db.ReadObjectAsync(obj, partition).ConfigureAwait(false); + } - var cacheable = - syncCollection - .FindOne( - Query.And( - Query.All(SynchronizableModifiedTimestampIndex, Query.Descending), - GetItemQueryWithId(id, category))); + if (syncQueueItem.Operation == ClientOperationType.Delete) + { + return default(T); + } - if (cacheable != null) - return cacheable.Value; + return syncQueueItem.Value; + } - var typeCollection = GetTypeCollection(category); + public async Task> GetAllLatestSyncQueueAsync(string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); + + return + (await _db.ReadObjectsAsync>(partition).ConfigureAwait(false)) + ?.OrderByDescending(x => x.ModifiedTimestamp) + ?.GroupBy(x => x.TypeId) + ?.Where(x => !x.Any(i => i.Operation == ClientOperationType.Delete)) + ?.Select(x => x.First().Value) + ?.ToArray() + ?? Enumerable.Empty(); + } - return typeCollection.FindById(id); - }); - } + public async Task PopulateCacheAsync(IEnumerable items, string partition = null, bool terminateSyncQueueHistory = false) + where T : class + { + await DeleteCacheItemsAsync(partition).ConfigureAwait(false); - public Task> GetAllLatestSyncQueue(string category = null) - where T: class + if (terminateSyncQueueHistory) { - return _processingQueue.Queue( - () => - { - var syncCollection = GetSynchronizableTypeCollection(); - - return syncCollection - .Find(GetItemQuery(category)) - ?.ToList() - ?.OrderByDescending(x => x.ModifiedTimestamp) - ?.GroupBy(x => x.TypeId) - ?.Where(x => !x.Any(i => i.Operation == (int)ClientOperationType.Delete)) - ?.Select(x => x.First().Value) - ?.ToList() - ?? new List(); - }); + await TerminateSyncQueueHistoryAsync(partition).ConfigureAwait(false); } - public async Task PopulateCache(IEnumerable items, string category = null, bool terminateSyncQueueHistory = false) - where T : class - { - if(!(await DropCache(category).ConfigureAwait(false))) - { - return false; - } + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); - if (terminateSyncQueueHistory && !(await TerminateSyncQueueHistory(category).ConfigureAwait(false))) - return false; + return await _db.WriteObjectsAsync(items, partition).ConfigureAwait(false); + } - return await _processingQueue - .Queue( - () => - { - var typeCollection = GetTypeCollection(category); + public async Task DeleteCacheItemAsync(T item, string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); - return typeCollection.Upsert(items) == items.Count(); - }) - .ConfigureAwait(false); + var rti = _db.GetRegisteredTypeInformationFor(); - } - - public Task DropCache(string category = null) - { - return _processingQueue.Queue( - () => - { - var rti = _registeredTypes[typeof(T)]; - var ctn = rti.GetCategoryTypeName(category); + return await _db.DeleteObjectAsync(rti.GetIdFor(item), partition).ConfigureAwait(false); + } - var typeCollection = GetTypeCollection (category); + public async Task DeleteCacheItemsAsync(string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); - if (!_db.CollectionExists(ctn)) - return true; + var result = await _db.DeleteObjectsAsync(partition).ConfigureAwait(false); + return result >= 0; + } - return _db.DropCollection(ctn); - }); - } + public async Task UpsertCacheItemAsync(T item, string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); - public Task DeleteCacheItem(T item, string category = null) - where T : class - { - return _processingQueue.Queue( - () => - { - var typeCollection = GetTypeCollection(category); + return await _db.WriteObjectAsync(item, partition).ConfigureAwait(false); + } - return typeCollection.Delete(GetId (item)); - }); - } + public async Task UpsertCacheItemsAsync(IEnumerable items, string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); - public Task UpsertCacheItem(T item, string category = null) - where T : class - { - return _processingQueue.Queue( - () => - { - var typeCollection = GetTypeCollection(category); + return await _db.WriteObjectsAsync(items, partition).ConfigureAwait(false); + } - return typeCollection.Upsert(item); - }); - } + public async Task>> GetSyncHistoryAsync(T obj, string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); - public Task UpsertCacheItems (IEnumerable items, string category = null) - where T : class - { - return _processingQueue.Queue( - () => - { - var typeCollection = GetTypeCollection(category); + var items = + await _db + .ReadObjectsAsync>( + partition, + GetSynchronizableItemFilter(obj)) + .ConfigureAwait(false); - return typeCollection.Upsert(items) == items.Count(); - }); - } + return items + ?.OrderByDescending(x => x.ModifiedTimestamp) + ?.Select(x => GetAsClientSyncInfo(x)) + ?.ToArray() + ?? Enumerable.Empty>(); + } - public Task>> GetSyncHistory(T obj, string category = null) - where T : class - { - var id = GetId(obj); - return GetSyncHistoryInternal(id, category); - } + public async Task>> GetSyncHistoryAsync(SyncType syncType = SyncType.Latest, string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); - private Task>> GetSyncHistoryInternal(BsonValue id, string category = null) - where T : class - { - return _processingQueue.Queue( - () => - { - var syncCollection = GetSynchronizableTypeCollection(); - - var cacheables = - syncCollection - .Find( - Query.And( - Query.All(SynchronizableModifiedTimestampIndex, Query.Descending), - GetItemQueryWithId(id, category))) - ?.ToList(); - - return - cacheables - ?.Select(x => GetAsClientSyncInfo(x)) - ?.ToList() - ?? Enumerable.Empty>(); - }); - } + var items = + await _db + .ReadObjectsAsync(partition, GetSynchronizableItemFilter()) + .ConfigureAwait(false); - public Task>> GetSyncHistory(SyncType syncType = SyncType.Latest, string category = null, CategorySearch categorySearch = CategorySearch.FullMatch) - where T : class - { - return _processingQueue.Queue( - () => - { - var syncCollection = GetSynchronizableTypeCollection(); - - switch (syncType) - { - case SyncType.Latest: - return syncCollection - .Find(GetItemQuery(category, categorySearch)) - ?.OrderByDescending(x => x.ModifiedTimestamp) - ?.GroupBy(x => x.TypeId) - ?.Where(x => x?.Any() ?? false) - ?.Select( - x => - { - var latest = x.FirstOrDefault(); - return - latest != default - ? GetAsClientSyncInfo(latest) - : default; - }) - ?.Where (x => x != default) - ?.ToList() - ?? Enumerable.Empty>(); - case SyncType.FullHistory: - return syncCollection - .Find(GetItemQuery(category, categorySearch)) - ?.Where(x => x != default) - ?.OrderBy(x => x.ModifiedTimestamp) - ?.Select(x => GetAsClientSyncInfo(x)) - ?.ToList() - ?? Enumerable.Empty>(); - } - - return Enumerable.Empty>(); - }); - } + switch (syncType) + { + case SyncType.Latest: + return items + ?.OrderByDescending(x => x.ModifiedTimestamp) + ?.GroupBy(x => x.TypeId) + ?.Where(x => x?.Any() ?? false) + ?.Select( + x => + { + var latest = x.FirstOrDefault(); + return + latest != default + ? GetAsClientSyncInfo(latest) + : default; + }) + ?.Where(x => x != default) + ?.ToArray() + ?? Enumerable.Empty>(); + case SyncType.FullHistory: + return items + ?.Where(x => x != default) + ?.OrderBy(x => x.ModifiedTimestamp) + ?.Select(x => GetAsClientSyncInfo(x)) + ?.ToList() + ?? Enumerable.Empty>(); + } + + return Enumerable.Empty>(); + } - public Task GetSyncHistoryCount(SyncType syncType = SyncType.Latest, string category = null, CategorySearch categorySearch = CategorySearch.FullMatch) - where T : class + public async Task ReplaceSyncQueueHistoryAsync(T obj, string partition = null) + where T : class + { + if (!(await TerminateSyncQueueHistoryForAsync(obj, partition).ConfigureAwait(false))) { - return _processingQueue.Queue( - () => - { - var syncCollection = GetSynchronizableTypeCollection(); - - switch (syncType) - { - case SyncType.Latest: - return syncCollection - .Count(GetItemQuery(category, categorySearch)); - case SyncType.FullHistory: - return syncCollection - .Count(GetItemQuery(category, categorySearch)); - } - - return 0; - }); + return false; } - public async Task ReplaceSyncQueueHistory(T obj, string category = null) - where T : class - { - if (!(await TerminateSyncQueueHistory(obj, category).ConfigureAwait(false))) - return false; + return (await CreateAsync(obj, partition).ConfigureAwait(false)).Success; + } - return (await Create(obj, category).ConfigureAwait(false)).Success; - } + public async Task TerminateSyncQueueHistoryForAsync(T obj, string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); - public Task TerminateSyncQueueHistory(T obj, string category = null) - where T : class - { - return _processingQueue.Queue( - () => - { - var syncCollection = GetSynchronizableTypeCollection(); + var result = + await _db + .DeleteObjectsAsync( + partition, + GetSynchronizableItemFilter(obj)) + .ConfigureAwait(false); - return syncCollection.Delete(GetItemQuery(obj, category)) > 0; - }); - } + return result >= 0; + } - public Task TerminateSyncQueueHistories (IEnumerable objs, string category = null) - where T : class - { - return _processingQueue.Queue( - () => - { - var syncCollection = GetSynchronizableTypeCollection(); + public async Task TerminateSyncQueueHistoriesForAsync(IEnumerable objs, string partition = null) + where T : class + { + var objsArray = objs as T[] ?? objs.ToArray(); - var deletions = 0; - foreach (var obj in objs) - { - deletions += syncCollection.Delete(GetItemQuery(obj, category)); - } + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); - return deletions == objs.Count(); - }); - } + var deletions = 0; - public Task TerminateSyncQueueHistory(string category = null) - where T : class + foreach (var obj in objsArray) { - return _processingQueue.Queue( - () => - { - var syncCollection = GetSynchronizableTypeCollection(); + var deleteResult = + await _db + .DeleteObjectsAsync( + partition, + GetSynchronizableItemFilter(obj)) + .ConfigureAwait(false); - return syncCollection.Delete(GetItemQuery(category)) > 0; - }); + deletions += deleteResult > 0 ? 1 : 0; } - public Task TerminateSyncQueueHistoryAt(T obj, DateTimeOffset offset, string category = null) - where T : class + return deletions == objsArray.Length; + } + + public async Task TerminateSyncQueueHistoryAsync(string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); + + var result = + await _db + .DeleteObjectsAsync( + partition, + FilterBuilder> + .Create() + .Filter(FilterType.Equals, x => x.Partition, partition)) + .ConfigureAwait(false); + + return result >= 0; + } + + public async Task TerminateSyncQueueHistoryAtAsync(T obj, DateTimeOffset offset, string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); + + var result = + await _db + .DeleteObjectsAsync( + partition, + GetSynchronizableItemFilter(obj) + .And() + .Filter(FilterType.Equals, x => x.ModifiedTimestamp, offset.ToUnixTimeMilliseconds())) + .ConfigureAwait(false); + + return result >= 0; + } + + public async Task TerminateSyncQueueHistoryBeforeAsync(T obj, DateTimeOffset offset, string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); + + var result = + await _db + .DeleteObjectsAsync( + partition, + GetSynchronizableItemFilter(obj) + .And() + .Filter(FilterType.LessThan, x => x.ModifiedTimestamp, offset.ToUnixTimeMilliseconds())) + .ConfigureAwait(false); + + return result >= 0; + } + + public async Task TerminateSyncQueueHistoryAfterAsync(T obj, DateTimeOffset offset, string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); + + var result = + await _db + .DeleteObjectsAsync( + partition, + GetSynchronizableItemFilter(obj) + .And() + .Filter(FilterType.GreaterThan, x => x.ModifiedTimestamp, offset.ToUnixTimeMilliseconds())) + .ConfigureAwait(false); + + return result >= 0; + } + + public async Task ReconcileAsync(IEnumerable> serverSyncInformation, string partition = null) + where T : class + { + var latest = await GetSyncHistoryAsync(SyncType.Latest, partition).ConfigureAwait(false); + + var replacements = new List(); + var inserts = new List(); + + var rti = _db.GetRegisteredTypeInformationFor(); + + if (latest.Any()) { - return _processingQueue.Queue( - () => + foreach (var serverSyncInfo in serverSyncInformation) + { + var latestClientUpdate = latest.FirstOrDefault(x => rti.CompareIdsFor(serverSyncInfo.Value, x.Value)); + + if (latestClientUpdate != null) { - var syncCollection = GetSynchronizableTypeCollection(); - - return syncCollection - .Delete( - Query.And( - GetItemQuery(obj, category), - Query.EQ(SynchronizableModifiedTimestampIndex, offset.ToUnixTimeMilliseconds()))) > 0; - }); - } + replacements.Add(_syncReconciler.Reconcile(serverSyncInfo, latestClientUpdate)); + continue; + } - public Task TerminateSyncQueueHistoryBefore(T obj, DateTimeOffset offset, string category = null) - where T : class + inserts.Add(serverSyncInfo.Value); + } + } + else { - return _processingQueue.Queue( - () => - { - var syncCollection = GetSynchronizableTypeCollection(); - - return syncCollection - .Delete( - Query.And( - GetItemQuery(obj, category), - Query.LT(SynchronizableModifiedTimestampIndex, offset.ToUnixTimeMilliseconds()))) > 0; - }); + inserts.AddRange(serverSyncInformation.Select(x => x.Value)); } - public Task TerminateSyncQueueHistoryAfter(T obj, DateTimeOffset offset, string category = null) - where T : class + if (replacements.Any()) { - return _processingQueue.Queue( - () => - { - var syncCollection = GetSynchronizableTypeCollection(); - - return syncCollection - .Delete( - Query.And( - GetItemQuery(obj, category), - Query.GT(SynchronizableModifiedTimestampIndex, offset.ToUnixTimeMilliseconds()))) > 0; - }); + await TerminateSyncQueueHistoriesForAsync(replacements, partition).ConfigureAwait(false); + await UpsertCacheItemsAsync(replacements, partition).ConfigureAwait(false); } - public async Task Reconcile (IEnumerable> serverSyncInformation, string category = null) - where T : class + if (inserts.Any()) { - var latest = await GetSyncHistory (SyncType.Latest, category).ConfigureAwait (false); - - var replacements = new List (); - var inserts = new List (); - - if (latest.Any ()) - { - foreach (var serverSyncInfo in serverSyncInformation) - { - var serverItemId = GetId (serverSyncInfo.Value); - var latestClientUpdate = latest.FirstOrDefault (x => GetId (x.Value).Equals (serverItemId)); + await UpsertCacheItemsAsync(inserts, partition).ConfigureAwait(false); + } + } - if (latestClientUpdate != null) - { - replacements.Add (_syncReconciler.Reconcile (serverSyncInfo, latestClientUpdate)); - continue; - } + private async Task<(bool IsDeleted, bool Exists)> ItemExistsAndAvailable(T obj, string partition = null) + where T : class + { + var synchObjects = + await _db + .ReadObjectsAsync>( + partition, + GetSynchronizableItemFilter(obj)) + .ConfigureAwait(false); - inserts.Add (serverSyncInfo.Value); - } - } - else - { - inserts.AddRange (serverSyncInformation.Select (x => x.Value).ToList ()); - } - - if (replacements.Any ()) - { - await TerminateSyncQueueHistories (replacements, category).ConfigureAwait (false); - await UpsertCacheItems (replacements, category).ConfigureAwait (false); - } - - if (inserts.Any ()) - { - await UpsertCacheItems (inserts, category).ConfigureAwait (false); - } - - await CleanUp ().ConfigureAwait (false); - } + var latestObject = synchObjects?.OrderByDescending(x => x.ModifiedTimestamp)?.FirstOrDefault(); - private (bool IsDeleted, bool Exists) ItemExistsAndAvailable(T obj, string category = null) - where T : class + if (latestObject != null) { - var id = GetId(obj); - return ItemExistsAndAvailableWithId(id, category); + return (latestObject?.Operation == ClientOperationType.Delete, true); } - private (bool IsDeleted, bool Exists) ItemExistsAndAvailableWithId(BsonValue id, string category = null) - where T : class - { - var syncCollection = GetSynchronizableTypeCollection(); - - var deleted = - syncCollection - .Count( - Query.And( - Query.EQ(SynchronizableOperationIndex, (int)ClientOperationType.Delete), - GetItemQueryWithId(id, category))); - - var count = syncCollection.Count(GetItemQueryWithId(id, category)); - - if(count == 0) - { - var typeItems = GetTypeCollection(category); - count = typeItems.FindById(id) != default(T) ? 1 : 0; - } + var cachedObject = + await _db + .ReadObjectAsync(obj, partition) + .ConfigureAwait(false); - return (deleted > 0, count > 0); - } + return (false, cachedObject != null); + } - private Task> GetLatestSyncQueue(BsonValue id, string category = null) - where T : class - { - return _processingQueue.Queue( - () => - { - var syncCollection = GetSynchronizableTypeCollection(); + private async Task> GetLatestSyncQueue(T obj, string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); - var cacheable = - syncCollection - .FindOne( - Query.And( - Query.All(SynchronizableModifiedTimestampIndex, Query.Descending), - GetItemQueryWithId(id, category))); + var synchObjects = + await _db + .ReadObjectsAsync>( + partition, + GetSynchronizableItemFilter(obj)) + .ConfigureAwait(false); - return cacheable; - }); - } + return synchObjects?.OrderByDescending(x => x.ModifiedTimestamp)?.FirstOrDefault(); + } - private Synchronizable GetAsSynchronizable(T obj, ClientOperationType operationType, string category = null) - where T : class - { - var rti = _registeredTypes[typeof(T)]; + private async Task> GetLatestSyncQueue(object key, string partition = null) + where T : class + { + using var lease = await _limiter.AcquireAsync().ConfigureAwait(false); - var typeId = rti.GetId(obj); + var synchObjects = + await _db + .ReadObjectsAsync>( + partition, + GetSynchronizableItemFilter(key)) + .ConfigureAwait(false); - if (typeId == null || typeId == BsonValue.Null) - { - throw new Exception("All cachable objects need to have a non-null value for the Id"); - } + return synchObjects?.OrderByDescending(x => x.ModifiedTimestamp)?.FirstOrDefault(); + } - var now = DateTimeOffset.Now; + private Synchronizable GetAsSynchronizable(T obj, ClientOperationType operationType, string partition = null) + where T : class + { + var rti = _db.GetRegisteredTypeInformationFor(); - return new Synchronizable - { - Id = ObjectId.NewObjectId(), - Category = category, - TypeId = typeId, - TypeName = rti.TypeFullName, - Value = obj, - ModifiedTimestamp = now.ToUnixTimeMilliseconds(), - Operation = (int)operationType - }; - } + var now = DateTimeOffset.Now; - private ClientSyncInfo GetAsClientSyncInfo(Synchronizable synchronizable) + return new Synchronizable { - return new ClientSyncInfo - { - ModifiedOn = synchronizable.ModifiedTimestamp, - Operation = (ClientOperationType)synchronizable.Operation, - Category = synchronizable.Category, - Value = synchronizable.Value - }; - } + TypeId = rti.GetIdFor(obj), + Partition = partition, + TypeFullName = rti.TypeFullName, + Value = obj, + ModifiedTimestamp = now.ToUnixTimeMilliseconds(), + Operation = operationType, + }; + } - private Query GetItemQuery(T obj, string category = null, CategorySearch categorySearch = CategorySearch.FullMatch) - where T : class - { - var id = GetId(obj); - return GetItemQueryWithId(id, category, categorySearch); - } + private FilterBuilder> GetSynchronizableItemFilter() + { + var rti = _db.GetRegisteredTypeInformationFor(); - private Query GetItemQuery(string category = null, CategorySearch categorySearch = CategorySearch.FullMatch) - where T : class - { - return - categorySearch == - CategorySearch.StartsWith - ? Query.And( - Query.StartsWith(SynchronizableCategory, category), - Query.EQ(SynchronizableTypeNameIndex, GetTypeFullName())) - : categorySearch == CategorySearch.Contains - ? Query.And( - Query.Contains(SynchronizableCategory, category), - Query.EQ(SynchronizableTypeNameIndex, GetTypeFullName())) - : category != null - ? Query.And( - Query.EQ(SynchronizableCategory, category), - Query.EQ(SynchronizableTypeNameIndex, GetTypeFullName())) - : Query.And( - Query.EQ(SynchronizableCategory, BsonValue.Null), - Query.EQ(SynchronizableTypeNameIndex, GetTypeFullName())); - } + var fb = FilterBuilder> + .Create(); - private Query GetItemQueryWithId(BsonValue id, string category = null, CategorySearch categorySearch = CategorySearch.FullMatch) - where T : class - { - return - categorySearch == CategorySearch.StartsWith - ? Query.And( - Query.EQ(SynchronizableTypeIdIndex, id), - Query.StartsWith(SynchronizableCategory, category), - Query.EQ(SynchronizableTypeNameIndex, GetTypeFullName())) - : categorySearch == CategorySearch.Contains - ? Query.And( - Query.EQ(SynchronizableTypeIdIndex, id), - Query.Contains(SynchronizableCategory, category), - Query.EQ(SynchronizableTypeNameIndex, GetTypeFullName())) - : category != null - ? Query.And( - Query.EQ(SynchronizableTypeIdIndex, id), - Query.EQ(SynchronizableCategory, category), - Query.EQ(SynchronizableTypeNameIndex, GetTypeFullName())) - : Query.And( - Query.EQ(SynchronizableTypeIdIndex, id), - Query.EQ(SynchronizableTypeNameIndex, GetTypeFullName())); - } + return fb; + } - private BsonValue GetId(T obj) - where T : class - { - var rti = _registeredTypes[typeof(T)]; + private FilterBuilder> GetSynchronizableItemFilter(T obj) + { + var rti = _db.GetRegisteredTypeInformationFor(); - return rti.GetId(obj); - } + var fb = FilterBuilder> + .Create() + .Filter(FilterType.Equals, x => x.TypeId, rti.GetIdFor(obj)); - private string GetTypeFullName() - { - var rti = _registeredTypes[typeof(T)]; + return fb; + } - return rti.TypeFullName; - } + private FilterBuilder> GetSynchronizableItemFilter(object key) + { + var rti = _db.GetRegisteredTypeInformationFor(); - private LiteCollection> GetSynchronizableTypeCollection() + var fb = FilterBuilder> + .Create() + .Filter(FilterType.Equals, x => x.TypeId, key); + + return fb; + } + + private ClientSyncInfo GetAsClientSyncInfo(Synchronizable synchronizable) + { + return new ClientSyncInfo { - return _db.GetCollection>(SyncCollection); - } + ModifiedOn = synchronizable.ModifiedTimestamp, + Operation = synchronizable.Operation, + Partition = synchronizable.Partition, + Value = synchronizable.Value, + }; + } - private LiteCollection GetTypeCollection(string category = null) + protected virtual void Dispose(bool disposing) + { + if (!this._disposedValue) { - return Retry ( - () => - { - var rti = _registeredTypes[typeof(T)]; - var ctn = rti.GetCategoryTypeName(category); - - if (!_db.CollectionExists(ctn)) - { - var collection = - !string.IsNullOrEmpty(ctn) - ? _db.GetCollection(ctn) - : _db.GetCollection(); - - if(!string.IsNullOrEmpty(rti.IdProperty)) - { - collection.EnsureIndex(rti.IdProperty); - } - - return collection; - } - - return _db.GetCollection(ctn); - }, - 3); - } + if (disposing) + { + _db?.Disconnect(); + _db?.Dispose(); + + _limiter?.Dispose(); + } - private T Retry (Func action, int retryCount) - { - try - { - return action (); - } - catch when (retryCount != 0) - { - return Retry (action, --retryCount); - } + this._disposedValue = true; } } + + public void Dispose() + { + // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + Dispose(disposing: true); + GC.SuppressFinalize(this); + } } diff --git a/EightBot.Orbit.Client/ProcessingQueue.cs b/EightBot.Orbit.Client/ProcessingQueue.cs deleted file mode 100644 index ece8cde..0000000 --- a/EightBot.Orbit.Client/ProcessingQueue.cs +++ /dev/null @@ -1,239 +0,0 @@ -using System; -using System.Threading.Tasks.Dataflow; -using System.Threading.Tasks; -using System.Threading; -using System.Runtime.Serialization; -using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleTo("EightBot.Orbit.Tests")] -namespace EightBot.Orbit.Client -{ - internal class ProcessingQueue - { - private readonly ActionBlock _taskProcessing; - - public ProcessingQueue() - { - _taskProcessing = - new ActionBlock( - ProcessQueuedTask, - new ExecutionDataflowBlockOptions - { - EnsureOrdered = true, - MaxDegreeOfParallelism = 1 - }); - } - - public async Task Queue(Action processingTask, CancellationToken cancellationToken = default(CancellationToken)) - { - var queuedTask = - new QueuedTask - { - TaskRunner = - _ => - { - processingTask.Invoke(); - return Task.FromResult(_); - } - }; - - if (cancellationToken == default(CancellationToken)) - cancellationToken = CancellationToken.None; - - var queued = await _taskProcessing.SendAsync(queuedTask, cancellationToken).ConfigureAwait(false); - - if (!queued) - { - throw new QueueFailureException("Unable to queue task"); - } - - cancellationToken.CheckIfCancelled(); - - await queuedTask.CompletionSource.Task.ConfigureAwait(false); - - cancellationToken.CheckIfCancelled(); - } - - public async Task Queue(Func processingTask, CancellationToken cancellationToken = default(CancellationToken)) - { - var queuedTask = - new QueuedTask - { - TaskRunner = - _ => - { - var processingResult = processingTask.Invoke(); - return Task.FromResult((object)processingResult); - } - }; - - if (cancellationToken == default(CancellationToken)) - cancellationToken = CancellationToken.None; - - var queued = await _taskProcessing.SendAsync(queuedTask, cancellationToken).ConfigureAwait(false); - - if (!queued) - { - throw new QueueFailureException("Unable to queue task"); - } - - cancellationToken.CheckIfCancelled(); - - var result = await queuedTask.CompletionSource.Task.ConfigureAwait(false); - - cancellationToken.CheckIfCancelled(); - - return (T)result; - } - - public async Task Queue(Func> processingTask, CancellationToken cancellationToken = default(CancellationToken)) - { - var queuedTask = - new QueuedTask - { - TaskRunner = - async _ => - { - return await processingTask.Invoke().ConfigureAwait(false); - } - }; - - if (cancellationToken == default(CancellationToken)) - cancellationToken = CancellationToken.None; - - var queued = await _taskProcessing.SendAsync(queuedTask, cancellationToken).ConfigureAwait(false); - - if (!queued) - { - throw new QueueFailureException("Unable to queue task"); - } - - cancellationToken.CheckIfCancelled(); - - var result = await queuedTask.CompletionSource.Task.ConfigureAwait(false); - - cancellationToken.CheckIfCancelled(); - - return (T)result; - } - - public async Task Queue(T input, Func processingTask, CancellationToken cancellationToken = default(CancellationToken)) - { - var queuedTask = - new QueuedTask - { - Input = input, - TaskRunner = - async x => - { - await processingTask.Invoke((T)x).ConfigureAwait(false); - return default(object); - } - }; - - if (cancellationToken == default(CancellationToken)) - cancellationToken = CancellationToken.None; - - var queued = await _taskProcessing.SendAsync(queuedTask, cancellationToken).ConfigureAwait(false); - - if (!queued) - { - throw new QueueFailureException("Unable to queue task"); - } - - cancellationToken.CheckIfCancelled(); - - await queuedTask.CompletionSource.Task.ConfigureAwait(false); - - cancellationToken.CheckIfCancelled(); - } - - public async Task Queue(TInput input, Func> processingTask, CancellationToken cancellationToken = default(CancellationToken)) - { - var queuedTask = - new QueuedTask - { - Input = input, - TaskRunner = - async x => - { - var result = await processingTask.Invoke((TInput)x).ConfigureAwait(false); - return Task.FromResult(result); - } - }; - - if (cancellationToken == default(CancellationToken)) - cancellationToken = CancellationToken.None; - - var queued = await _taskProcessing.SendAsync(queuedTask, cancellationToken).ConfigureAwait(false); - - if (!queued) - { - throw new QueueFailureException("Unable to queue task"); - } - - cancellationToken.CheckIfCancelled(); - - var processingResult = await queuedTask.CompletionSource.Task.ConfigureAwait(false); - - cancellationToken.CheckIfCancelled(); - - return (TResult)processingResult; - } - - private async Task ProcessQueuedTask(QueuedTask input) - { - try - { - var result = await input.TaskRunner.Invoke(input.Input).ConfigureAwait(false); - - input.CompletionSource.TrySetResult(result); - } - catch (Exception ex) - { - input.CompletionSource.TrySetException(ex); - } - } - } - - public static class QueueExtensions - { - public static void CheckIfCancelled(this CancellationToken cancellationToken) - { - if (cancellationToken != CancellationToken.None && !cancellationToken.IsCancellationRequested) - { - throw new QueueFailureException("The queued task was cancelled"); - } - } - } - - public class QueuedTask - { - public TaskCompletionSource CompletionSource { get; set; } - = new TaskCompletionSource(); - - public object Input { get; set; } - public object Output { get; set; } - - public Func> TaskRunner { get; set; } - } - - public class QueueFailureException : Exception - { - public QueueFailureException() - { - } - - public QueueFailureException(string message) : base(message) - { - } - - public QueueFailureException(string message, Exception innerException) : base(message, innerException) - { - } - - protected QueueFailureException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } - } -} diff --git a/EightBot.Orbit.Client/RegisteredTypeInformation.cs b/EightBot.Orbit.Client/RegisteredTypeInformation.cs deleted file mode 100644 index 8258ac3..0000000 --- a/EightBot.Orbit.Client/RegisteredTypeInformation.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.Linq.Expressions; -using System.Reflection; -using LiteDB; - -namespace EightBot.Orbit.Client -{ - internal struct RegisteredTypeInformation - { - public PropertyInfo PropertyIdSelector { get; set; } - - public Delegate FuncIdSelector { get; set; } - - public bool RequiresIdMapping { get; set; } - - public string IdProperty { get; set; } - - public string TypeFullName { get; set; } - - public string TypeName { get; set; } - - public string TypeNamespace { get; set; } - - public Type ObjectType { get; set; } - - public static RegisteredTypeInformation Create(string typeNameOverride = null) - { - var type = typeof(T); - - var rti = - new RegisteredTypeInformation - { - TypeFullName = type.FullName, - TypeName = typeNameOverride ?? type.Name, - TypeNamespace = type.Namespace, - ObjectType = type - }; - - return rti; - } - - public static RegisteredTypeInformation Create(Expression> idSelector, string typeNameOverride = null) - { - if (idSelector.Body is MemberExpression mex && mex.Member is PropertyInfo pi) - { - var type = typeof(T); - - var rti = - new RegisteredTypeInformation - { - PropertyIdSelector = pi, - IdProperty = pi.Name, - TypeFullName = type.FullName, - TypeName = typeNameOverride ?? type.Name, - TypeNamespace = type.Namespace, - ObjectType = type - }; - - return rti; - } - - throw new ArgumentException($"The expression provided is not a property selector for {typeof(T).Name}", nameof(idSelector)); - } - - public static RegisteredTypeInformation Create(Expression> idSelector, Expression> idProperty, string typeNameOverride = null) - { - if (idSelector is LambdaExpression lex && idProperty.Body is MemberExpression mex && mex.Member is PropertyInfo pi) - { - var compiledExpression = lex.Compile(); - var type = typeof(T); - - var rti = - new RegisteredTypeInformation - { - FuncIdSelector = compiledExpression, - IdProperty = pi.Name, - TypeFullName = type.FullName, - TypeName = typeNameOverride ?? type.Name, - TypeNamespace = type.Namespace, - ObjectType = type - }; - - return rti; - } - - throw new ArgumentException($"The expression provided is not a lambda expression for {typeof(T).Name}", nameof(idSelector)); - } - - public BsonValue GetId(T value) - { - if (PropertyIdSelector != null) - return new BsonValue(PropertyIdSelector.GetValue(value)); - - return - new BsonValue( - FuncIdSelector != null - ? ((Func)FuncIdSelector)(value) - : value); - } - - public string GetCategoryTypeName(string category = null) - { - return - category != null - ? $"{TypeName}{OrbitClient.CategorySeparator}{category}" - : TypeName; - } - } -} diff --git a/EightBot.Orbit.Client/SyncReconcilers/ServerWinsSyncReconciler.cs b/EightBot.Orbit.Client/SyncReconcilers/ServerWinsSyncReconciler.cs index f02dcea..29f2250 100644 --- a/EightBot.Orbit.Client/SyncReconcilers/ServerWinsSyncReconciler.cs +++ b/EightBot.Orbit.Client/SyncReconcilers/ServerWinsSyncReconciler.cs @@ -1,11 +1,9 @@ -using System; -namespace EightBot.Orbit.Client.SyncReconcilers +namespace EightBot.Orbit.Client.SyncReconcilers; + +public class ServerWinsSyncReconciler : ISyncReconciler { - public class ServerWinsSyncReconciler : ISyncReconciler + public T Reconcile(ServerSyncInfo server, ClientSyncInfo client) { - public T Reconcile(ServerSyncInfo server, ClientSyncInfo client) - { - return server.Value; - } + return server.Value; } } diff --git a/EightBot.Orbit.Client/Synchronizable.cs b/EightBot.Orbit.Client/Synchronizable.cs index d95f37f..3df5599 100644 --- a/EightBot.Orbit.Client/Synchronizable.cs +++ b/EightBot.Orbit.Client/Synchronizable.cs @@ -1,23 +1,18 @@ -using System; -using LiteDB; -namespace EightBot.Orbit.Client -{ - internal class Synchronizable - { - public ObjectId Id { get; set; } +namespace EightBot.Orbit.Client; - public string Category { get; set; } +internal class Synchronizable +{ + public object TypeId { get; set; } - public string TypeName { get; set; } + public string TypeFullName { get; set; } - public long ModifiedTimestamp { get; set; } + public string Partition { get; set; } - public long? SyncTimestamp { get; set; } + public long ModifiedTimestamp { get; set; } - public BsonValue TypeId { get; set; } + public long? SyncTimestamp { get; set; } - public T Value { get; set; } + public T Value { get; set; } - public int Operation { get; set; } - } -} + public ClientOperationType Operation { get; set; } +} \ No newline at end of file diff --git a/EightBot.Orbit.Core/ClientOperationType.cs b/EightBot.Orbit.Core/ClientOperationType.cs index a606dc8..23d4f1c 100644 --- a/EightBot.Orbit.Core/ClientOperationType.cs +++ b/EightBot.Orbit.Core/ClientOperationType.cs @@ -1,11 +1,9 @@ -using System; -namespace EightBot.Orbit +namespace EightBot.Orbit; + +public enum ClientOperationType { - public enum ClientOperationType - { - Create, - Update, - Delete, - NoOperation = 99999 - } -} + Create, + Update, + Delete, + NoOperation = 99999, +} \ No newline at end of file diff --git a/EightBot.Orbit.Core/ClientSyncInfo.cs b/EightBot.Orbit.Core/ClientSyncInfo.cs index fcf1dd3..08f0a0d 100644 --- a/EightBot.Orbit.Core/ClientSyncInfo.cs +++ b/EightBot.Orbit.Core/ClientSyncInfo.cs @@ -1,15 +1,12 @@ -using System; +namespace EightBot.Orbit; -namespace EightBot.Orbit +public class ClientSyncInfo { - public class ClientSyncInfo - { - public long ModifiedOn { get; set; } + public long ModifiedOn { get; set; } - public ClientOperationType Operation { get; set; } + public ClientOperationType Operation { get; set; } - public string Category { get; set; } + public string Partition { get; set; } - public T Value { get; set; } - } + public T Value { get; set; } } \ No newline at end of file diff --git a/EightBot.Orbit.Core/EightBot.Orbit.Core.csproj b/EightBot.Orbit.Core/EightBot.Orbit.Core.csproj index 6148865..ddf3704 100644 --- a/EightBot.Orbit.Core/EightBot.Orbit.Core.csproj +++ b/EightBot.Orbit.Core/EightBot.Orbit.Core.csproj @@ -1,11 +1,7 @@ - netstandard2.0 + net9.0 EightBot.Orbit - - - - diff --git a/EightBot.Orbit.Core/ServerOperationType.cs b/EightBot.Orbit.Core/ServerOperationType.cs index 9a07257..80fb610 100644 --- a/EightBot.Orbit.Core/ServerOperationType.cs +++ b/EightBot.Orbit.Core/ServerOperationType.cs @@ -1,11 +1,9 @@ -using System; -namespace EightBot.Orbit +namespace EightBot.Orbit; + +public enum ServerOperationType { - public enum ServerOperationType - { - NotModified, - Created, - Updated, - Deleted - } -} + NotModified, + Created, + Updated, + Deleted, +} \ No newline at end of file diff --git a/EightBot.Orbit.Core/ServerSyncInfo.cs b/EightBot.Orbit.Core/ServerSyncInfo.cs index d4c2cf8..b6325dd 100644 --- a/EightBot.Orbit.Core/ServerSyncInfo.cs +++ b/EightBot.Orbit.Core/ServerSyncInfo.cs @@ -1,6 +1,5 @@ -using System; -namespace EightBot.Orbit -{ +namespace EightBot.Orbit; + public class ServerSyncInfo { public ServerOperationType Operation { get; set; } @@ -10,5 +9,4 @@ public class ServerSyncInfo public long ModifiedOn { get; set; } public T Value { get; set; } -} -} +} \ No newline at end of file diff --git a/EightBot.Orbit.Core/SyncBase.cs b/EightBot.Orbit.Core/SyncBase.cs index 5e910b3..7cdedf3 100644 --- a/EightBot.Orbit.Core/SyncBase.cs +++ b/EightBot.Orbit.Core/SyncBase.cs @@ -1,18 +1,16 @@ using System; -using System.ComponentModel; -namespace EightBot.Orbit +namespace EightBot.Orbit; + +public abstract class SyncBase { - public abstract class SyncBase - { - public Guid Id { get; set; } + public Guid Id { get; set; } - public DateTimeOffset ModifiedDate { get; set; } + public DateTimeOffset ModifiedDate { get; set; } - public virtual bool Equals(SyncBase other) - { - return Id == other.Id - && ModifiedDate == other.ModifiedDate; - } + public virtual bool Equals(SyncBase other) + { + return Id == other.Id + && ModifiedDate == other.ModifiedDate; } -} +} \ No newline at end of file diff --git a/EightBot.Orbit.Core/SyncType.cs b/EightBot.Orbit.Core/SyncType.cs index def3c29..3b9c844 100644 --- a/EightBot.Orbit.Core/SyncType.cs +++ b/EightBot.Orbit.Core/SyncType.cs @@ -1,9 +1,7 @@ -using System; -namespace EightBot.Orbit +namespace EightBot.Orbit; + +public enum SyncType { - public enum SyncType - { - Latest, - FullHistory - } -} + Latest, + FullHistory, +} \ No newline at end of file diff --git a/EightBot.Orbit.Server.Web/EightBot.Orbit.Server.Web.csproj b/EightBot.Orbit.Server.Web/EightBot.Orbit.Server.Web.csproj index fc10ec1..577e331 100644 --- a/EightBot.Orbit.Server.Web/EightBot.Orbit.Server.Web.csproj +++ b/EightBot.Orbit.Server.Web/EightBot.Orbit.Server.Web.csproj @@ -1,7 +1,7 @@  - netcoreapp2.2 + net9.0 true https://cdn3.iconfinder.com/data/icons/unigrid-phantom-science-vol-1/60/003_002_moon_orbit_ecuator_sputnik_satellite-128.png Eight-Bot diff --git a/EightBot.Orbit.Server.Web/Extensions.cs b/EightBot.Orbit.Server.Web/Extensions.cs index f5b4de1..e2e44b2 100644 --- a/EightBot.Orbit.Server.Web/Extensions.cs +++ b/EightBot.Orbit.Server.Web/Extensions.cs @@ -1,94 +1,92 @@ -using EightBot.Nebula.DocumentDb; +using System; +using System.Threading; +using EightBot.Nebula.DocumentDb; using EightBot.Orbit.Server; using EightBot.Orbit.Server.Data; using EightBot.Orbit.Server.Web; using Microsoft.Azure.Cosmos; using Microsoft.Extensions.Logging; -using System; -using System.Threading; -namespace Microsoft.Extensions.DependencyInjection +namespace Microsoft.Extensions.DependencyInjection; + +public static class Extensions { - public static class Extensions + public static IServiceCollection AddOrbitSyncControllers(this IServiceCollection services, Action config) { - public static IServiceCollection AddOrbitSyncControllers(this IServiceCollection services, Action config) + services.AddMvcCore(x => x.Conventions.Add(new OrbitSyncControllerRouteConvention())).ConfigureApplicationPartManager(x => { - services.AddMvcCore(x => x.Conventions.Add(new OrbitSyncControllerRouteConvention())).ConfigureApplicationPartManager(x => - { - var syncControllers = new OrbitSyncControllerFeatureProvider(); + var syncControllers = new OrbitSyncControllerFeatureProvider(); - config.Invoke(syncControllers); + config.Invoke(syncControllers); - x.FeatureProviders.Add(syncControllers); - }); + x.FeatureProviders.Add(syncControllers); + }); - return services; - } - - public static IServiceCollection AddDefaultOrbitSyncCosmosDataClient(this IServiceCollection services, string endpointUri, string authKey, string databaseId, Action config, bool throwErrors = true, int? throughput = 400) - { - services.AddSingleton(x => new CosmosClient(endpointUri, authKey)); + return services; + } - services.AddSingleton(x => - { - var documentDbLogger = x.GetRequiredService().CreateLogger("EightBot.Nebula.DocumentDb"); + public static IServiceCollection AddDefaultOrbitSyncCosmosDataClient(this IServiceCollection services, string endpointUri, string authKey, string databaseId, Action config, bool throwErrors = true, int? throughput = 400) + { + services.AddSingleton(x => new CosmosClient(endpointUri, authKey)); - var comosClient = x.GetRequiredService(); + services.AddSingleton(x => + { + var documentDbLogger = x.GetRequiredService().CreateLogger("EightBot.Nebula.DocumentDb"); - var database = comosClient.CreateDatabaseIfNotExistsAsync(databaseId, throughput).Result; + var comosClient = x.GetRequiredService(); - var dataClient = new DataClient(database, () => Thread.CurrentPrincipal?.Identity?.Name ?? "test") - { - ThrowErrors = throwErrors, - LogError = y => documentDbLogger.LogError(y), - LogInformation = y => documentDbLogger.LogInformation(y) - }; + var database = comosClient.CreateDatabaseIfNotExistsAsync(databaseId, throughput).Result; - config.Invoke(dataClient); + var dataClient = new DataClient(database, () => Thread.CurrentPrincipal?.Identity?.Name ?? "test") + { + ThrowErrors = throwErrors, + LogError = y => documentDbLogger.LogError(y), + LogInformation = y => documentDbLogger.LogInformation(y), + }; - return dataClient; - }); + config.Invoke(dataClient); - services.AddSingleton(); + return dataClient; + }); - return services; - } + services.AddSingleton(); + return services; + } - //public static IServiceCollection AddDefaultOrbitSync(this IServiceCollection services, string databaseUri, string authKey, string databaseId, Action config, bool throwErrors = true, int? throughput = 400) - //{ - // services.AddSingleton(x => - // { - // var documentClient = new DocumentClient(new Uri(databaseUri), authKey, new ConnectionPolicy() { ConnectionMode = ConnectionMode.Gateway }); - // documentClient.OpenAsync().Wait(); - // documentClient.CreateDatabaseIfNotExistsAsync(new Database { Id = databaseId }, new RequestOptions() { OfferThroughput = throughput }).Wait(); + // public static IServiceCollection AddDefaultOrbitSync(this IServiceCollection services, string databaseUri, string authKey, string databaseId, Action config, bool throwErrors = true, int? throughput = 400) + // { + // services.AddSingleton(x => + // { + // var documentClient = new DocumentClient(new Uri(databaseUri), authKey, new ConnectionPolicy() { ConnectionMode = ConnectionMode.Gateway }); + // documentClient.OpenAsync().Wait(); + // documentClient.CreateDatabaseIfNotExistsAsync(new Database { Id = databaseId }, new RequestOptions() { OfferThroughput = throughput }).Wait(); - // var documentDbLogger = x.GetRequiredService().CreateLogger("EightBot.Nebula.DocumentDb"); + // var documentDbLogger = x.GetRequiredService().CreateLogger("EightBot.Nebula.DocumentDb"); - // var dataClient = new DataClient(documentClient, databaseId, x.GetService()?.HttpContext.User) - // { - // ThrowErrors = throwErrors, - // LogError = y => documentDbLogger?.LogError(y), - // LogInformation = y => documentDbLogger?.LogInformation(y) - // }; + // var dataClient = new DataClient(documentClient, databaseId, x.GetService()?.HttpContext.User) + // { + // ThrowErrors = throwErrors, + // LogError = y => documentDbLogger?.LogError(y), + // LogInformation = y => documentDbLogger?.LogInformation(y) + // }; - // //config.Invoke(dataClient); - // dataClient.EnsureCollectionAsync(false); + // //config.Invoke(dataClient); + // dataClient.EnsureCollectionAsync(false); - // return dataClient; - // }); + // return dataClient; + // }); - // services.AddMvcCore(x => x.Conventions.Add(new OrbitSyncControllerRouteConvention())).ConfigureApplicationPartManager(x => - // { - // var syncControllers = new OrbitSyncControllerFeatureProvider(); + // services.AddMvcCore(x => x.Conventions.Add(new OrbitSyncControllerRouteConvention())).ConfigureApplicationPartManager(x => + // { + // var syncControllers = new OrbitSyncControllerFeatureProvider(); - // //config.Invoke(syncControllers); - // syncControllers.EnsureSyncController(false); + // //config.Invoke(syncControllers); + // syncControllers.EnsureSyncController(false); - // x.FeatureProviders.Add(syncControllers); - // }); + // x.FeatureProviders.Add(syncControllers); + // }); - // return services; - //} - } + // return services; + // } } \ No newline at end of file diff --git a/EightBot.Orbit.Server.Web/OrbitSyncControllerFeatureProvider.cs b/EightBot.Orbit.Server.Web/OrbitSyncControllerFeatureProvider.cs index 797dba8..5ef03e8 100644 --- a/EightBot.Orbit.Server.Web/OrbitSyncControllerFeatureProvider.cs +++ b/EightBot.Orbit.Server.Web/OrbitSyncControllerFeatureProvider.cs @@ -1,38 +1,40 @@ -using Microsoft.AspNetCore.Mvc.ApplicationParts; -using Microsoft.AspNetCore.Mvc.Controllers; -using System; +using System; using System.Collections.Generic; using System.Reflection; +using Microsoft.AspNetCore.Mvc.ApplicationParts; +using Microsoft.AspNetCore.Mvc.Controllers; -namespace EightBot.Orbit.Server.Web -{ - public class OrbitSyncControllerFeatureProvider : IApplicationFeatureProvider - { - private Dictionary ControllerTypes = new Dictionary(); +namespace EightBot.Orbit.Server.Web; - public OrbitSyncControllerFeatureProvider() - { +public class OrbitSyncControllerFeatureProvider : IApplicationFeatureProvider +{ + private Dictionary _controllerTypes = new Dictionary(); - } + public OrbitSyncControllerFeatureProvider() + { + } - public OrbitSyncControllerFeatureProvider(Dictionary controllerTypes) - { - this.ControllerTypes = controllerTypes; - } + public OrbitSyncControllerFeatureProvider(Dictionary controllerTypes) + { + this._controllerTypes = controllerTypes; + } - public void EnsureSyncController(bool? authorize = true) - { - this.ControllerTypes[typeof(T)] = authorize.Value; - } + public void EnsureSyncController(bool? authorize = true) + { + this._controllerTypes[typeof(T)] = authorize.Value; + } - public void PopulateFeature(IEnumerable parts, ControllerFeature feature) + public void PopulateFeature(IEnumerable parts, ControllerFeature feature) + { + foreach (KeyValuePair controllerType in this._controllerTypes) { - foreach (KeyValuePair controllerType in this.ControllerTypes) + if (controllerType.Value) + { + feature.Controllers.Add(typeof(SyncControllerAuth<>).MakeGenericType(controllerType.Key).GetTypeInfo()); + } + else { - if (controllerType.Value) - feature.Controllers.Add(typeof(SyncControllerAuth<>).MakeGenericType(controllerType.Key).GetTypeInfo()); - else - feature.Controllers.Add(typeof(SyncController<>).MakeGenericType(controllerType.Key).GetTypeInfo()); + feature.Controllers.Add(typeof(SyncController<>).MakeGenericType(controllerType.Key).GetTypeInfo()); } } } diff --git a/EightBot.Orbit.Server.Web/OrbitSyncControllerRouteConvention.cs b/EightBot.Orbit.Server.Web/OrbitSyncControllerRouteConvention.cs index 7fdee5b..e5f4568 100644 --- a/EightBot.Orbit.Server.Web/OrbitSyncControllerRouteConvention.cs +++ b/EightBot.Orbit.Server.Web/OrbitSyncControllerRouteConvention.cs @@ -1,23 +1,21 @@ using EightBot.Nebula.DocumentDb; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ApplicationModels; -using System; -namespace EightBot.Orbit.Server.Web +namespace EightBot.Orbit.Server.Web; + +public class OrbitSyncControllerRouteConvention : IControllerModelConvention { - public class OrbitSyncControllerRouteConvention : IControllerModelConvention + public void Apply(ControllerModel controller) { - public void Apply(ControllerModel controller) + if (controller.ControllerType.IsGenericType) { - if (controller.ControllerType.IsGenericType) - { - var genericType = controller.ControllerType.GenericTypeArguments[0]; + var genericType = controller.ControllerType.GenericTypeArguments[0]; - controller.Selectors.Add(new SelectorModel - { - AttributeRouteModel = new AttributeRouteModel(new RouteAttribute($"/api/sync/{genericType.Name.Pluralize().ToLowerInvariant()}")), - }); - } + controller.Selectors.Add(new SelectorModel + { + AttributeRouteModel = new AttributeRouteModel(new RouteAttribute($"/api/sync/{genericType.Name.Pluralize().ToLowerInvariant()}")), + }); } } } \ No newline at end of file diff --git a/EightBot.Orbit.Server.Web/SyncController.cs b/EightBot.Orbit.Server.Web/SyncController.cs index 8db46d3..a2d2ab6 100644 --- a/EightBot.Orbit.Server.Web/SyncController.cs +++ b/EightBot.Orbit.Server.Web/SyncController.cs @@ -1,30 +1,30 @@ -using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; -namespace EightBot.Orbit.Server.Web +namespace EightBot.Orbit.Server.Web; + +[Route("api/sync/[controller]")] +[ApiController] +public class SyncController : ControllerBase { - [Route("api/sync/[controller]")] - [ApiController] - public class SyncController : ControllerBase + private readonly IOrbitDataClient _dataClient = null; + + public SyncController(IOrbitDataClient dataClient) { - private readonly IOrbitDataClient DataClient = null; + this._dataClient = dataClient; + } - public SyncController(IOrbitDataClient dataClient) + [HttpPost("")] + public async Task>> Post([FromBody]IEnumerable> syncables) + { + var payload = await this._dataClient.Sync(syncables); + if (payload != null && payload.Count() > 0) { - this.DataClient = dataClient; + return Ok(payload); } - [HttpPost("")] - public async Task>> Post([FromBody]IEnumerable> syncables) - { - var payload = await this.DataClient.Sync(syncables); - if (payload != null && payload.Count() > 0) - return Ok(payload); - else - return BadRequest(); - } + return BadRequest(); } -} \ No newline at end of file +} diff --git a/EightBot.Orbit.Server.Web/SyncControllerAuth.cs b/EightBot.Orbit.Server.Web/SyncControllerAuth.cs index 7605675..ff3eb3d 100644 --- a/EightBot.Orbit.Server.Web/SyncControllerAuth.cs +++ b/EightBot.Orbit.Server.Web/SyncControllerAuth.cs @@ -1,14 +1,12 @@ using Microsoft.AspNetCore.Authorization; -using System; -namespace EightBot.Orbit.Server.Web +namespace EightBot.Orbit.Server.Web; + +[Authorize] +public class SyncControllerAuth : SyncController { - [Authorize] - public class SyncControllerAuth : SyncController + public SyncControllerAuth(IOrbitDataClient dataClient) + : base(dataClient) { - public SyncControllerAuth(IOrbitDataClient dataClient) : base(dataClient) - { - - } } } \ No newline at end of file diff --git a/EightBot.Orbit.Server/Data/OrbitCosmosClient.cs b/EightBot.Orbit.Server/Data/OrbitCosmosClient.cs index 7ff011d..3186830 100644 --- a/EightBot.Orbit.Server/Data/OrbitCosmosClient.cs +++ b/EightBot.Orbit.Server/Data/OrbitCosmosClient.cs @@ -1,102 +1,112 @@ -using EightBot.Nebula.DocumentDb; - -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using EightBot.Nebula.DocumentDb; -namespace EightBot.Orbit.Server.Data -{ - public class OrbitCosmosDataClient : IOrbitDataClient - { - private readonly IDataClient DataClient = null; +namespace EightBot.Orbit.Server.Data; +public class OrbitCosmosDataClient : IOrbitDataClient +{ + private readonly IDataClient _dataClient = null; + public OrbitCosmosDataClient(IDataClient dataClient) + { + this._dataClient = dataClient; + } - public OrbitCosmosDataClient(IDataClient dataClient) - { - this.DataClient = dataClient; - } + public async Task>> Sync(IEnumerable> syncables) + { + var payload = new List>(); - public async Task>> Sync(IEnumerable> syncables) + if (syncables != null && syncables.Count() > 0) { - var payload = new List>(); - - if (syncables != null && syncables.Count() > 0) + for (var i = 0; i < syncables.Count(); i++) { - for (var i = 0; i < syncables.Count(); i++) - { - var syncable = syncables.ElementAt(i); + var syncable = syncables.ElementAt(i); - var id = this.DataClient.GetId(syncable.Value); - var isGuid = Guid.TryParse(id, out var idGuid); + var id = this._dataClient.GetId(syncable.Value); + var isGuid = Guid.TryParse(id, out var idGuid); - var partitionKey = this.DataClient.GetPartitionKey(syncable.Value); + var partitionKey = this._dataClient.GetPartitionKey(syncable.Value); - var syncableLastModified = DateTimeOffset.FromUnixTimeMilliseconds(syncable.ModifiedOn).UtcDateTime; + var syncableLastModified = DateTimeOffset.FromUnixTimeMilliseconds(syncable.ModifiedOn).UtcDateTime; - if (!isGuid || (isGuid && idGuid != Guid.Empty)) + if (!isGuid || (isGuid && idGuid != Guid.Empty)) + { + if (syncable.Operation == ClientOperationType.Create || syncable.Operation == ClientOperationType.Update) { - if (syncable.Operation == ClientOperationType.Create || syncable.Operation == ClientOperationType.Update) + var existingDocumentWithBase = await this._dataClient.Document().GetWithBaseAsync(id, partitionKey).ConfigureAwait(false); + if (existingDocumentWithBase.Document == null) { - var existingDocumentWithBase = await this.DataClient.Document().GetWithBaseAsync(id, partitionKey).ConfigureAwait(false); - if (existingDocumentWithBase.Document == null) + var pk = this._dataClient.GetPartitionKey(syncable.Value); + + var success = await this._dataClient.Document().UpsertAsync(syncable.Value).ConfigureAwait(false); + if (success) { - var pk = this.DataClient.GetPartitionKey(syncable.Value); + await AddToPayload(id, partitionKey, ServerOperationType.Created, DateTime.UtcNow, default(T), payload); + } + } + else + { + var serverLastModified = existingDocumentWithBase.BaseDocument.Timestamp; - var success = await this.DataClient.Document().UpsertAsync(syncable.Value).ConfigureAwait(false); - if (success) - await AddToPayload(id, partitionKey, ServerOperationType.Created, DateTime.UtcNow, default(T), payload); + // Server Wins! + if (serverLastModified > syncableLastModified) + { + await AddToPayload(id, partitionKey, ServerOperationType.Updated, serverLastModified, existingDocumentWithBase.Document, payload); } else { - var serverLastModified = existingDocumentWithBase.BaseDocument.Timestamp; - - // Server Wins! - if (serverLastModified > syncableLastModified) - await AddToPayload(id, partitionKey, ServerOperationType.Updated, serverLastModified, existingDocumentWithBase.Document, payload); - else - { - var success = await this.DataClient.Document().UpsertAsync(syncable.Value).ConfigureAwait(false); - await AddToPayload(id, partitionKey, ServerOperationType.Updated, DateTime.UtcNow, default(T), payload); - } + var success = await this._dataClient.Document().UpsertAsync(syncable.Value).ConfigureAwait(false); + await AddToPayload(id, partitionKey, ServerOperationType.Updated, DateTime.UtcNow, default(T), payload); } } - else if (syncables.ElementAt(i).Operation == ClientOperationType.Delete) + } + else if (syncables.ElementAt(i).Operation == ClientOperationType.Delete) + { + var succes = await this._dataClient.Document().DeleteAsync(id, partitionKey).ConfigureAwait(false); + if (succes) { - var succes = await this.DataClient.Document().DeleteAsync(id, partitionKey).ConfigureAwait(false); - if (succes) - await AddToPayload(id, partitionKey, ServerOperationType.Deleted, DateTime.UtcNow, default(T), payload); - else - await AddToPayload(id, partitionKey, ServerOperationType.NotModified, syncableLastModified, default(T), payload); + await AddToPayload(id, partitionKey, ServerOperationType.Deleted, DateTime.UtcNow, default(T), payload); + } + else + { + await AddToPayload(id, partitionKey, ServerOperationType.NotModified, syncableLastModified, default(T), payload); } } - else - await AddToPayload(id, partitionKey, ServerOperationType.NotModified, syncableLastModified, default(T), payload); + } + else + { + await AddToPayload(id, partitionKey, ServerOperationType.NotModified, syncableLastModified, default(T), payload); } } - - return payload; } - private async Task AddToPayload(string id, object partitionKey, ServerOperationType operation, DateTime modified, T existingDocument, List> payload) - { - var payloadItem = new ServerSyncInfo() { Id = id, Operation = operation }; + return payload; + } + + private async Task AddToPayload(string id, object partitionKey, ServerOperationType operation, DateTimeOffset modified, T existingDocument, List> payload) + { + var payloadItem = new ServerSyncInfo() { Id = id, Operation = operation, }; - if (existingDocument == null && payloadItem.Operation == ServerOperationType.Created || payloadItem.Operation == ServerOperationType.Updated) + if ((existingDocument == null && payloadItem.Operation == ServerOperationType.Created) || payloadItem.Operation == ServerOperationType.Updated) + { + var existingDocumentWithBase = await this._dataClient.Document().GetWithBaseAsync(id, partitionKey).ConfigureAwait(false); + if (existingDocumentWithBase.BaseDocument != null) { - var existingDocumentWithBase = await this.DataClient.Document().GetWithBaseAsync(id, partitionKey).ConfigureAwait(false); - if (existingDocumentWithBase.BaseDocument != null) - modified = existingDocumentWithBase.BaseDocument.Timestamp; + modified = existingDocumentWithBase.BaseDocument.Timestamp; + } - if (existingDocumentWithBase.Document != null) - existingDocument = existingDocumentWithBase.Document; + if (existingDocumentWithBase.Document != null) + { + existingDocument = existingDocumentWithBase.Document; } + } - payloadItem.ModifiedOn = new DateTimeOffset(modified).ToUnixTimeMilliseconds(); - payloadItem.Value = existingDocument; + payloadItem.ModifiedOn = modified.ToUnixTimeMilliseconds(); + payloadItem.Value = existingDocument; - payload.Add(payloadItem); - } + payload.Add(payloadItem); } -} \ No newline at end of file +} diff --git a/EightBot.Orbit.Server/EightBot.Orbit.Server.csproj b/EightBot.Orbit.Server/EightBot.Orbit.Server.csproj index eee241a..8431cde 100644 --- a/EightBot.Orbit.Server/EightBot.Orbit.Server.csproj +++ b/EightBot.Orbit.Server/EightBot.Orbit.Server.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net9.0 true https://cdn3.iconfinder.com/data/icons/unigrid-phantom-science-vol-1/60/003_002_moon_orbit_ecuator_sputnik_satellite-128.png Eight-Bot @@ -11,7 +11,7 @@ - + diff --git a/EightBot.Orbit.Server/IOrbitDataClient.cs b/EightBot.Orbit.Server/IOrbitDataClient.cs index af0d32b..ba21301 100644 --- a/EightBot.Orbit.Server/IOrbitDataClient.cs +++ b/EightBot.Orbit.Server/IOrbitDataClient.cs @@ -1,11 +1,9 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading.Tasks; -namespace EightBot.Orbit.Server +namespace EightBot.Orbit.Server; + +public interface IOrbitDataClient { - public interface IOrbitDataClient - { - Task>> Sync(IEnumerable> syncables); - } + Task>> Sync(IEnumerable> syncables); } \ No newline at end of file diff --git a/EightBot.Orbit.Server/Resolver.cs b/EightBot.Orbit.Server/Resolver.cs index 2875d6b..9a8dd20 100644 --- a/EightBot.Orbit.Server/Resolver.cs +++ b/EightBot.Orbit.Server/Resolver.cs @@ -1,12 +1,9 @@ -using System; +namespace EightBot.Orbit.Server; -namespace EightBot.Orbit.Server +public abstract class Resolver { - public abstract class Resolver + public T Resolve(ClientSyncInfo clientModel, T serverModel) { - public T Resolve(ClientSyncInfo clientModel, T serverModel) - { - return default(T); - } + return default(T); } } \ No newline at end of file diff --git a/EightBot.Orbit.Tests/EightBot.Orbit.Tests.csproj b/EightBot.Orbit.Tests/EightBot.Orbit.Tests.csproj index 7ebed43..17e8cdc 100644 --- a/EightBot.Orbit.Tests/EightBot.Orbit.Tests.csproj +++ b/EightBot.Orbit.Tests/EightBot.Orbit.Tests.csproj @@ -1,19 +1,21 @@  - netcoreapp2.2 + net9.0 false - - - - - - - + + + + + + + + + diff --git a/EightBot.Orbit.Tests/OrbitClientTests.cs b/EightBot.Orbit.Tests/OrbitClientTests.cs index 73ee60f..c619064 100644 --- a/EightBot.Orbit.Tests/OrbitClientTests.cs +++ b/EightBot.Orbit.Tests/OrbitClientTests.cs @@ -1,1116 +1,1078 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.IO; -using EightBot.Orbit.Client; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; using System.Linq; +using System.Threading.Tasks; using Bogus; -using System; -using Bogus.Extensions; -using System.Threading.Tasks; -using FluentAssertions; -using System.ServiceModel.Dispatcher; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics; - -namespace EightBot.Orbit.Tests -{ - [TestClass] - public class OrbitClientTests - { - OrbitClient _client; - - string _tempDbFile; - - public OrbitClientTests() +using EightBot.Orbit.Client; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Shouldly; +using TychoDB; + +namespace EightBot.Orbit.Tests; + +[TestClass] +[DoNotParallelize] +public class OrbitClientTests +{ + private readonly string _tempDbFile; + + private readonly Faker _globalFaker; + + private OrbitClient _client; + + public OrbitClientTests() + { + Randomizer.Seed = new Random(42); + + _globalFaker = new Faker(); + + _tempDbFile = Path.GetTempPath(); + } + + [TestInitialize] + public void Setup() + { + _client = + new OrbitClient(new SystemTextJsonSerializer()) + .Initialize(_tempDbFile, $"{Guid.NewGuid()}.db", deleteExistingCache: true) + .AddTypeRegistration(x => x.StringProperty) + .AddTypeRegistration(x => x.StringProperty) + .AddTypeRegistration(x => x.IntProperty) + .AddTypeRegistration(x => x.TestClassId) + .AddTypeRegistrationWithCustomKeySelector(x => $"{x.FloatProperty}_{x.DoubleProperty}") + .AddTypeRegistrationWithCustomKeySelector(x => x) + .Startup(); + } + + [TestCleanup] + public void Shutdown() + { + _client.Dispose(); + + File.Delete(_client.CachePath); + } + + [TestMethod] + [DoNotParallelize] + public void OrbitClient_Initialize_InitializesSuccessfully() + { + Assert.IsTrue(_client.Initialized); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_ShutdownProcessStartup_ShouldProcess() + { + _client.Shutdown(); + _client.Startup(); + + var stringValue = Guid.NewGuid().ToString(); + + var testFile = + new TestClassA + { + StringProperty = stringValue, + IntProperty = _globalFaker.Random.Int(), + }; + + var result = await _client.CreateAsync(testFile); + + result.Success + .ShouldBeTrue(); + + result.OperationResult + .ShouldBe(ClientOperationType.Create); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_Create_ShouldBeSuccessful() + { + var stringValue = Guid.NewGuid().ToString(); + + var testFile = + new TestClassA + { + StringProperty = stringValue, + IntProperty = _globalFaker.Random.Int(), + }; + + var result = await _client.CreateAsync(testFile); + + result.Success + .ShouldBeTrue(); + + result.OperationResult + .ShouldBe(ClientOperationType.Create); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_CreateWithPartition_ShouldBeSuccessful() + { + var stringValue = Guid.NewGuid().ToString(); + + var testFile = + new TestClassA + { + StringProperty = stringValue, + IntProperty = _globalFaker.Random.Int(), + }; + + var result = await _client.CreateAsync(testFile, "partition"); + + result.Success + .ShouldBeTrue(); + + result.OperationResult + .ShouldBe(ClientOperationType.Create); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_CreateString_ShouldBeSuccessful() + { + var str = "Testing"; + + var result = await _client.CreateAsync(str); + + result.Success + .ShouldBeTrue(); + + result.OperationResult + .ShouldBe(ClientOperationType.Create); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_CreateWithObjectThatUsesFuncProperty_ShouldBeSuccessful() + { + var testFile = + new TestClassD + { + FloatProperty = 10.0f, + DoubleProperty = _globalFaker.Random.Double(), + }; + + var result = await _client.CreateAsync(testFile); + + result.Success + .ShouldBeTrue(); + + result.OperationResult + .ShouldBe(ClientOperationType.Create); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_CreateWithObjectThatUsesFuncPropertyWithPartition_ShouldBeSuccessful() + { + var testFile = + new TestClassD + { + FloatProperty = 10.0f, + DoubleProperty = _globalFaker.Random.Double(), + }; + + var result = await _client.CreateAsync(testFile, "partition"); + + result.Success + .ShouldBeTrue(); + + result.OperationResult + .ShouldBe(ClientOperationType.Create); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertAndGetLatest_ShouldFindMatch() + { + var stringValue = Guid.NewGuid().ToString(); + var testFile = + new TestClassA + { + StringProperty = stringValue, + IntProperty = _globalFaker.Random.Int(), + }; + + await _client.CreateAsync(testFile); + var found = await _client.GetLatestAsync(testFile); + Assert.IsTrue(testFile.IntProperty == found.IntProperty); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertToCacheAndGetLatest_ShouldFindMatch() + { + var stringValue = Guid.NewGuid().ToString(); + var testFile = + new TestClassA + { + StringProperty = stringValue, + IntProperty = _globalFaker.Random.Int(), + }; + + await _client.UpsertCacheItemAsync(testFile); + var found = await _client.GetLatestAsync(testFile); + Assert.IsTrue(testFile.IntProperty == found.IntProperty); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertToCacheWithPartitionAndGetLatest_ShouldFindMatch() + { + var stringValue = Guid.NewGuid().ToString(); + var partition = "partition"; + + var testFile = + new TestClassA + { + StringProperty = stringValue, + IntProperty = _globalFaker.Random.Int(), + }; + + await _client.UpsertCacheItemAsync(testFile, partition); + var found = await _client.GetLatestAsync(testFile, partition); + Assert.IsTrue(testFile.IntProperty == found.IntProperty); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertTestClassEToCacheAndGetLatest_ShouldFindMatch() + { + var testFile = + new TestClassE + { + TestClassId = Guid.NewGuid(), + Values = new List { }, + }; + + await _client.UpsertCacheItemAsync(testFile); + var found = await _client.GetLatestAsync(testFile); + Assert.IsTrue(testFile.TestClassId == found.TestClassId); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertTestClassEToCacheWithPartitionAndGetLatest_ShouldFindMatch() + { + var partition = "partition"; + + var testFile = + new TestClassE + { + TestClassId = Guid.NewGuid(), + Values = new List { }, + }; + + await _client.UpsertCacheItemAsync(testFile, partition); + var found = await _client.GetLatestAsync(testFile, partition); + Assert.IsTrue(testFile.TestClassId == found.TestClassId); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertStringAndGetLatest_ShouldFindMatch() + { + var testStr = "testStr"; + + await _client.CreateAsync(testStr); + var found = await _client.GetLatestAsync(testStr); + Assert.IsTrue(testStr == found); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertAndGetLatestWithPartition_ShouldFindMatch() + { + var stringValue = Guid.NewGuid().ToString(); + var partition = "partition"; + + var testFile = + new TestClassA + { + StringProperty = stringValue, + IntProperty = _globalFaker.Random.Int(), + }; + + await _client.CreateAsync(testFile, partition); + var found = await _client.GetLatestAsync(testFile, partition); + Assert.IsTrue(testFile.IntProperty == found.IntProperty); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertWithObjectThatUsesFuncPropertyAndGetLatest_ShouldFindMatch() + { + var testFile = + new TestClassD + { + FloatProperty = 10.0f, + DoubleProperty = _globalFaker.Random.Double(), + }; + + await _client.CreateAsync(testFile); + var found = await _client.GetLatestAsync(testFile); + Assert.IsTrue(testFile.FloatProperty == found.FloatProperty); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertWithObjectThatUsesFuncPropertyAndGetLatestWithPartition_ShouldFindMatch() + { + var partition = "partition"; + + var testFile = + new TestClassD + { + FloatProperty = 10.0f, + DoubleProperty = _globalFaker.Random.Double(), + }; + + await _client.CreateAsync(testFile, partition); + var found = await _client.GetLatestAsync(testFile, partition); + Assert.IsTrue(testFile.FloatProperty == found.FloatProperty); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertMultipleAndGetAll_CountShouldMatch() + { + var expected = 1; + + var stringValue = Guid.NewGuid().ToString(); + + var testFile1 = + new TestClassA + { + StringProperty = stringValue, + IntProperty = _globalFaker.Random.Int(), + }; + + var testFile2 = + new TestClassA + { + StringProperty = stringValue, + IntProperty = 84, + }; + + var createResult = await _client.CreateAsync(testFile1); + + createResult.OperationResult.ShouldBe(ClientOperationType.Create); + + var updateResult = await _client.UpdateAsync(testFile2); + + updateResult.OperationResult.ShouldBe(ClientOperationType.Update); + + var found = await _client.GetSyncHistoryAsync(testFile1); + Assert.IsTrue(found.Count() == expected); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertMultipleAndGetAllWithPartition_CountShouldMatch() + { + var expected = 1; + + var stringValue = Guid.NewGuid().ToString(); + var partition = "partition"; + + var testFile1 = + new TestClassA + { + StringProperty = stringValue, + IntProperty = _globalFaker.Random.Int(), + }; + + var testFile2 = + new TestClassA + { + StringProperty = stringValue, + IntProperty = 84, + }; + + var createResult = await _client.CreateAsync(testFile1, partition); + + createResult.OperationResult.ShouldBe(ClientOperationType.Create); + + var updateResult = await _client.UpdateAsync(testFile2, partition); + + updateResult.OperationResult.ShouldBe(ClientOperationType.Update); + + var found = await _client.GetSyncHistoryAsync(testFile1, partition); + Assert.IsTrue(found.Count() == expected); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertMultipleAndQuery_DoesGetLatestAsync() + { + var stringValue = Guid.NewGuid().ToString(); + + var testFile1 = + new TestClassA + { + StringProperty = stringValue, + IntProperty = _globalFaker.Random.Int(), + }; + + var testFile2 = + new TestClassA + { + StringProperty = stringValue, + IntProperty = 84, + }; + + var testFile3 = + new TestClassA + { + StringProperty = stringValue, + IntProperty = 168, + }; + + var upsert1 = await _client.UpsertAsync(testFile1); + + upsert1.Success + .ShouldBeTrue(); + + upsert1.OperationResult + .ShouldBe(ClientOperationType.Create); + + var upsert2 = await _client.UpsertAsync(testFile2); + + upsert2.Success + .ShouldBeTrue(); + + upsert2.OperationResult + .ShouldBe(ClientOperationType.Update); + + var upsert3 = await _client.UpsertAsync(testFile3); + + upsert3.Success + .ShouldBeTrue(); + + upsert3.OperationResult + .ShouldBe(ClientOperationType.Update); + + var found = await _client.GetLatestAsync(testFile3); + + Assert.IsTrue(found.IntProperty == testFile3.IntProperty); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertMultipleAndQueryWithPartition_DoesGetLatestAsync() + { + var stringValue = Guid.NewGuid().ToString(); + + var partition = $"partition_{stringValue}"; + + var testFile1 = + new TestClassA + { + StringProperty = stringValue, + IntProperty = _globalFaker.Random.Int(), + }; + + var testFile2 = + new TestClassA + { + StringProperty = stringValue, + IntProperty = _globalFaker.Random.Int(), + }; + + var testFile3 = + new TestClassA + { + StringProperty = stringValue, + IntProperty = _globalFaker.Random.Int(), + }; + + await _client.UpsertAsync(testFile1, partition); + await _client.UpsertAsync(testFile2, partition); + await _client.UpsertAsync(testFile3, partition); + + var found = await _client.GetLatestAsync(testFile3, partition); + + found.IntProperty.ShouldBe(testFile3.IntProperty); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertAndDeleteAndInsert_ShouldNotInsert() + { + var stringValue = Guid.NewGuid().ToString(); + + var testFile1 = + new TestClassA + { + StringProperty = stringValue, + IntProperty = _globalFaker.Random.Int(), + }; + + var testFile2 = + new TestClassA + { + StringProperty = stringValue, + IntProperty = 84, + }; + + var testFile3 = + new TestClassA + { + StringProperty = stringValue, + IntProperty = 168, + }; + + var upsert1Result = await _client.UpsertAsync(testFile1); + + upsert1Result.OperationResult + .ShouldBe(ClientOperationType.Create); + + var deleteResult = await _client.DeleteAsync(testFile2); + + deleteResult.OperationResult + .ShouldBe(ClientOperationType.Delete); + + var upsert2Result = await _client.UpsertAsync(testFile3); + + upsert2Result.OperationResult + .ShouldBe(ClientOperationType.NoOperation); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertAndDeleteAndInsertWithPartition_ShouldNotInsert() + { + var partition = "partition"; + + var stringValue = Guid.NewGuid().ToString(); + + var testFile1 = + new TestClassA + { + StringProperty = stringValue, + IntProperty = 12312, + }; + + var testFile2 = + new TestClassA + { + StringProperty = stringValue, + IntProperty = 2345567, + }; + + var testFile3 = + new TestClassA + { + StringProperty = stringValue, + IntProperty = 2345236, + }; + + var upsert1Result = await _client.UpsertAsync(testFile1, partition); + + upsert1Result.Success + .ShouldBeTrue(); + + upsert1Result.OperationResult + .ShouldBe(ClientOperationType.Create); + + var deleteResult = await _client.DeleteAsync(testFile2, partition); + + deleteResult.Success + .ShouldBeTrue(); + + deleteResult.OperationResult + .ShouldBe(ClientOperationType.Delete); + + var upsert2Result = await _client.UpsertAsync(testFile3, partition); + + upsert2Result.Success + .ShouldBeFalse(); + + upsert2Result.OperationResult + .ShouldBe(ClientOperationType.NoOperation); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertMultipleWithSameKey_ShouldFindRightTypes() + { + var id = "Test Value"; + + var testFile1 = + new TestClassA + { + StringProperty = id, + IntProperty = _globalFaker.Random.Int(), + }; + + var testFile2 = + new TestClassB + { + StringProperty = id, + DoubleProperty = _globalFaker.Random.Double(), + }; + + await _client.UpsertAsync(testFile1); + await _client.UpsertAsync(testFile2); + + var foundA = await _client.GetLatestAsync(id); + var foundB = await _client.GetLatestAsync(id); + + Assert.IsTrue(foundA.IntProperty == testFile1.IntProperty); + Assert.IsTrue(foundB.DoubleProperty == testFile2.DoubleProperty); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertMultipleWithSameKeyWithPartition_ShouldFindRightTypes() + { + var id = "Test Value"; + + var partition = "partition"; + + var testFile1 = + new TestClassA + { + StringProperty = id, + IntProperty = _globalFaker.Random.Int(), + }; + + var testFile2 = + new TestClassB + { + StringProperty = id, + DoubleProperty = _globalFaker.Random.Double(), + }; + + await _client.UpsertAsync(testFile1, partition); + await _client.UpsertAsync(testFile2, partition); + + var foundA = await _client.GetLatestAsync(id, partition); + var foundB = await _client.GetLatestAsync(id, partition); + + Assert.IsTrue(foundA.IntProperty == testFile1.IntProperty); + Assert.IsTrue(foundB.DoubleProperty == testFile2.DoubleProperty); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_GetLatestSyncQueueWithInvalidId_ShouldFindNothing() + { + var expected = 0; + var id = Guid.NewGuid().ToString(); + + var partition = "test"; + + var testFile1 = + new TestClassB + { + StringProperty = id, + DoubleProperty = _globalFaker.Random.Double(), + }; + + var insertSuccess = await _client.UpsertAsync(testFile1, partition); + + insertSuccess.Success.ShouldBeTrue(); + insertSuccess.OperationResult.ShouldBe(ClientOperationType.Create); + + // Simulate server synchronization by reconciling the item + var serverSyncInfo = new List> { - Randomizer.Seed = new Random(42); - - _tempDbFile = Path.GetTempPath(); - } - - [TestInitialize] - public void Setup() - { - _client = - new OrbitClient() - .Initialize(_tempDbFile, additionalConnectionStringParameters: "Mode=Exclusive;", deleteExistingCache: true) - .AddTypeRegistration(x => x.StringProperty, requiresIdMapping: true) - .AddTypeRegistration(x => x.StringProperty, requiresIdMapping: true) - .AddTypeRegistration(x => x.IntProperty, requiresIdMapping: true) - .AddTypeRegistration(x => x.FloatProperty.ToString(), x => x.FloatProperty, requiresIdMapping: true) - .AddTypeRegistration(x => x.TestClassId, requiresIdMapping: true) - .AddTypeRegistration(); - } + new ServerSyncInfo + { + Value = testFile1, + Operation = ServerOperationType.Updated, + }, + }; + + await _client.ReconcileAsync(serverSyncInfo, partition); + + var foundA = await _client.GetAllLatestSyncQueueAsync(); + + var foundCount = foundA.Count(); + + foundCount.ShouldBe(expected); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_GetAllLatest_PerfTest1() + { + var partition = "test"; + + var items = + Enumerable + .Range(1, 2000) + .Select(id => + new ServerSyncInfo + { + Value = + new TestClassA + { + StringProperty = $"id_{id}", + IntProperty = id, + }, + }) + .ToList(); - [TestCleanup] - public void Shutdown() + await _client.ReconcileAsync(items, partition); + + var sw = Stopwatch.StartNew(); + var foundA = await _client.GetAllLatestAsync(partition); + sw.Stop(); + + Console.WriteLine($"GetAllLatest: {sw.ElapsedMilliseconds}ms"); + + foundA.ShouldNotBeEmpty(); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertConcurrent_ShouldNotFail() + { + try { - _client.Shutdown(); - - File.Delete(_client.CachePath); - } - - [TestMethod] - public void OrbitClient_Initialize_InitializesSuccessfully() - { - Assert.IsTrue(_client.Initialized); - } - - [TestMethod] - public async Task OrbitClient_ShutdownProcessStartup_ShouldProcess() - { - _client.Shutdown(); - _client.Startup(); - - var testFile = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 42 - }; - - var result = await _client.Create(testFile); - - result.Success - .Should() - .BeTrue(); - - result.OperationResult - .Should() - .Be(ClientOperationType.Create); - } + var id1 = "id1"; + var id2 = "id2"; - [TestMethod] - public async Task OrbitClient_Create_ShouldBeSuccessful() - { - var testFile = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 42 - }; - - var result = await _client.Create(testFile); - - result.Success - .Should() - .BeTrue(); - - result.OperationResult - .Should() - .Be(ClientOperationType.Create); - } - - [TestMethod] - public async Task OrbitClient_CreateWithCategory_ShouldBeSuccessful() - { - var testFile = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 42 - }; - - var result = await _client.Create(testFile, "category"); - - result.Success - .Should() - .BeTrue(); - - result.OperationResult - .Should() - .Be(ClientOperationType.Create); - } - - [TestMethod] - public async Task OrbitClient_CreateString_ShouldBeSuccessful() - { - var str = "Testing"; - - var result = await _client.Create(str); - - result.Success - .Should() - .BeTrue(); - - result.OperationResult - .Should() - .Be(ClientOperationType.Create); - } - - [TestMethod] - public async Task OrbitClient_CreateWithObjectThatUsesFuncProperty_ShouldBeSuccessful() - { - var testFile = - new TestClassD - { - FloatProperty = 10.0f, - DoubleProperty = 42d - }; - - var result = await _client.Create(testFile); - - result.Success - .Should() - .BeTrue(); - - result.OperationResult - .Should() - .Be(ClientOperationType.Create); - } - - [TestMethod] - public async Task OrbitClient_CreateWithObjectThatUsesFuncPropertyWithCategory_ShouldBeSuccessful() - { - var testFile = - new TestClassD - { - FloatProperty = 10.0f, - DoubleProperty = 42d - }; - - var result = await _client.Create(testFile, "category"); - - result.Success - .Should() - .BeTrue(); - - result.OperationResult - .Should() - .Be(ClientOperationType.Create); - } - - [TestMethod] - public async Task OrbitClient_InsertAndGetLatest_ShouldFindMatch() - { - var testFile = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 42 - }; - - await _client.Create(testFile); - var found = await _client.GetLatest(testFile); - Assert.IsTrue(testFile.IntProperty == found.IntProperty); - } - - [TestMethod] - public async Task OrbitClient_InsertToCacheAndGetLatest_ShouldFindMatch() - { - var testFile = + var max = 100; + + var testFile1 = new TestClassA { - StringProperty = "Test Value", - IntProperty = 42 - }; - - await _client.UpsertCacheItem(testFile); - var found = await _client.GetLatest(testFile); - Assert.IsTrue(testFile.IntProperty == found.IntProperty); - } - - [TestMethod] - public async Task OrbitClient_InsertToCacheWithCategoryAndGetLatest_ShouldFindMatch() - { - var category = "category"; - - var testFile = + StringProperty = id1, + }; + + var testFile2 = new TestClassA { - StringProperty = "Test Value", - IntProperty = 42 - }; - - await _client.UpsertCacheItem(testFile, category); - var found = await _client.GetLatest(testFile, category); - Assert.IsTrue(testFile.IntProperty == found.IntProperty); - } - - [TestMethod] - public async Task OrbitClient_InsertTestClassEToCacheAndGetLatest_ShouldFindMatch() - { - var testFile = - new TestClassE - { - TestClassId = Guid.NewGuid(), - Values = new List { }, - }; - - await _client.UpsertCacheItem(testFile); - var found = await _client.GetLatest(testFile); - Assert.IsTrue(testFile.TestClassId == found.TestClassId); - } - - [TestMethod] - public async Task OrbitClient_InsertTestClassEToCacheWithCategoryAndGetLatest_ShouldFindMatch() - { - var category = "category"; - - var testFile = - new TestClassE - { - TestClassId = Guid.NewGuid(), - Values = new List { }, - }; - - await _client.UpsertCacheItem(testFile, category); - var found = await _client.GetLatest(testFile, category); - Assert.IsTrue(testFile.TestClassId == found.TestClassId); - } - - [TestMethod] - public async Task OrbitClient_InsertStringAndGetLatest_ShouldFindMatch() - { - var testStr = "testStr"; - - await _client.Create(testStr); - var found = await _client.GetLatest(testStr); - Assert.IsTrue(testStr == found); - } - - [TestMethod] - public async Task OrbitClient_InsertAndGetLatestWithCategory_ShouldFindMatch() - { - var category = "category"; - - var testFile = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 42 - }; - - await _client.Create(testFile, category); - var found = await _client.GetLatest(testFile, category); - Assert.IsTrue(testFile.IntProperty == found.IntProperty); - } - - [TestMethod] - public async Task OrbitClient_InsertWithObjectThatUsesFuncPropertyAndGetLatest_ShouldFindMatch() - { - var testFile = - new TestClassD - { - FloatProperty = 10.0f, - DoubleProperty = 42d - }; - - await _client.Create(testFile); - var found = await _client.GetLatest(testFile); - Assert.IsTrue(testFile.FloatProperty == found.FloatProperty); - } - - [TestMethod] - public async Task OrbitClient_InsertWithObjectThatUsesFuncPropertyAndGetLatestWithCategory_ShouldFindMatch() + StringProperty = id2, + }; + + var insert1Test = + Task.Run( + () => + { + for (int i = 1; i <= max; i++) + { + testFile1.IntProperty = i; + _client.UpsertAsync(testFile1); + } + }); + + var insert2Test = + Task.Run( + () => + { + for (int i = 1; i <= max; i++) + { + testFile2.IntProperty = i; + _client.UpsertAsync(testFile2); + } + }); + + await Task.WhenAll(insert1Test, insert2Test); + + var found1 = await _client.GetLatestAsync(id1); + var found2 = await _client.GetLatestAsync(id2); + + Assert.IsNotNull(found1); + Assert.IsTrue(found1.IntProperty == max); + + Assert.IsNotNull(found2); + Assert.IsTrue(found2.IntProperty == max); + } + catch (Exception ex) { - var category = "category"; - - var testFile = - new TestClassD - { - FloatProperty = 10.0f, - DoubleProperty = 42d - }; - - await _client.Create(testFile, category); - var found = await _client.GetLatest(testFile, category); - Assert.IsTrue(testFile.FloatProperty == found.FloatProperty); + Console.WriteLine(ex.StackTrace); + Assert.Fail($"Expected to not fail, but received: {ex.Message}"); } + } - [TestMethod] - public async Task OrbitClient_InsertMultipleAndGetAll_CountShouldMatch() - { - var expected = 2; - - var testFile1 = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 42 - }; + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_BulkInsertAndUpdate_ShouldGetNewValue() + { + var testObjects = + new Faker() + .RuleFor(x => x.StringProperty, (f, u) => $"String_{f.IndexFaker}") + .RuleFor(x => x.IntProperty, (f, u) => f.IndexFaker); - var testFile2 = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 84 - }; - - await _client.Create(testFile1); - await _client.Update(testFile2); - var found = await _client.GetSyncHistory(testFile1); - Assert.IsTrue(found.Count() == expected); - } - - [TestMethod] - public async Task OrbitClient_InsertMultipleAndGetAllWithCategory_CountShouldMatch() - { - var expected = 2; - - var category = "category"; - - var testFile1 = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 42 - }; - - var testFile2 = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 84 - }; - - await _client.Create(testFile1, category); - await _client.Update(testFile2, category); - var found = await _client.GetSyncHistory(testFile1, category); - Assert.IsTrue(found.Count() == expected); + var generatedTestObjects = testObjects.GenerateBetween(100, 100); + + var populated = await _client.PopulateCacheAsync(generatedTestObjects); + + Assert.IsTrue(populated); + + var original = generatedTestObjects[49]; + + var foundObject = await _client.GetLatestAsync(original); + + Assert.AreEqual(foundObject.IntProperty, original.IntProperty); + + foundObject.IntProperty = foundObject.IntProperty * 2; + + var upsertResult = await _client.UpsertAsync(foundObject); + + upsertResult.Success + .ShouldBeTrue(); + + upsertResult.OperationResult + .ShouldBe(ClientOperationType.Update); + + var latest = await _client.GetAllLatestAsync(); + + var updated = latest.FirstOrDefault(x => x.StringProperty == original.StringProperty); + + Assert.IsTrue(updated.IntProperty == foundObject.IntProperty); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_BulkInsertAndUpdateWithPartition_ShouldGetNewValue() + { + var testObjects = + new Faker() + .RuleFor(x => x.StringProperty, (f, u) => $"String_{f.IndexFaker}") + .RuleFor(x => x.IntProperty, (f, u) => f.IndexFaker); + + var partition = "partition"; + + var generatedTestObjects = testObjects.GenerateBetween(100, 100); + + var populated = await _client.PopulateCacheAsync(generatedTestObjects, partition); + + Assert.IsTrue(populated); + + var original = generatedTestObjects[49]; + + var foundObject = await _client.GetLatestAsync(original, partition); + + Assert.AreEqual(foundObject.IntProperty, original.IntProperty); + + foundObject.IntProperty = foundObject.IntProperty * 2; + + var upsertResult = await _client.UpsertAsync(foundObject, partition); + + upsertResult.Success + .ShouldBeTrue(); + + upsertResult.OperationResult + .ShouldBe(ClientOperationType.Update); + + var latest = await _client.GetAllLatestAsync(partition); + + var updated = latest.FirstOrDefault(x => x.StringProperty == original.StringProperty); + + Assert.IsTrue(updated.IntProperty == foundObject.IntProperty); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_BulkInsertAndDelete_ShouldDeleteAll() + { + var expected = 100; + + var testObjects = + new Faker() + .RuleFor(x => x.StringProperty, (f, u) => $"String_{f.IndexFaker}") + .RuleFor(x => x.IntProperty, (f, u) => f.IndexFaker); + + var partition = "partition"; + + var generatedTestObjects = testObjects.GenerateBetween(100, 100); + + var populated = await _client.PopulateCacheAsync(generatedTestObjects, partition); + + Assert.IsTrue(populated); + + var deleteCount = 0; + + foreach (var generatedTestObject in generatedTestObjects) + { + var deleteResult = await _client.DeleteCacheItemAsync(generatedTestObject, partition); + + if (deleteResult == true) + { + deleteCount += 1; + } + + Assert.IsTrue(deleteResult); } - [TestMethod] - public async Task OrbitClient_InsertMultipleAndQuery_DoesGetLatest() - { - var testFile1 = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 42 - }; - - var testFile2 = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 84 - }; - - var testFile3 = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 168 - }; - - var upsert1 = await _client.Upsert(testFile1); - - upsert1.Success - .Should() - .BeTrue(); - - upsert1.OperationResult - .Should() - .Be(ClientOperationType.Create); - - var upsert2 = await _client.Upsert(testFile2); - - upsert2.Success - .Should() - .BeTrue(); - - upsert2.OperationResult - .Should() - .Be(ClientOperationType.Update); - - var upsert3 = await _client.Upsert(testFile3); - - upsert3.Success - .Should() - .BeTrue(); - - upsert3.OperationResult - .Should() - .Be(ClientOperationType.Update); - - var found = await _client.GetLatest(testFile3); - - Assert.IsTrue(found.IntProperty == testFile3.IntProperty); - } - - [TestMethod] - public async Task OrbitClient_InsertMultipleAndQueryWithCategory_DoesGetLatest() - { - var category = "category"; - - var testFile1 = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 42 - }; - - var testFile2 = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 84 - }; - - var testFile3 = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 168 - }; - - await _client.Upsert(testFile1, category); - await _client.Upsert(testFile2, category); - await _client.Upsert(testFile3, category); - - var found = await _client.GetLatest(testFile3, category); - - Assert.IsTrue(found.IntProperty == testFile3.IntProperty); - } - - [TestMethod] - public async Task OrbitClient_InsertAndDeleteAndInsert_ShouldNotInsert() - { - var testFile1 = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 42 - }; - - var testFile2 = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 84 - }; - - var testFile3 = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 168 - }; - - var upsert1Result = await _client.Upsert(testFile1); - - upsert1Result.Success - .Should() - .BeTrue(); - - upsert1Result.OperationResult - .Should() - .Be(ClientOperationType.Create); - - var deleteResult = await _client.Delete(testFile2); - - deleteResult.Success - .Should() - .BeTrue(); - - deleteResult.OperationResult - .Should() - .Be(ClientOperationType.Delete); - - var upsert2Result = await _client.Upsert(testFile3); - - upsert2Result.Success - .Should() - .BeFalse(); - - upsert2Result.OperationResult - .Should() - .Be(ClientOperationType.NoOperation); - } - - [TestMethod] - public async Task OrbitClient_InsertAndDeleteAndInsertWithCategory_ShouldNotInsert() - { - var category = "category"; - - var testFile1 = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 42 - }; - - var testFile2 = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 84 - }; - - var testFile3 = - new TestClassA - { - StringProperty = "Test Value", - IntProperty = 168 - }; - - var upsert1Result = await _client.Upsert(testFile1, category); - - upsert1Result.Success - .Should() - .BeTrue(); - - upsert1Result.OperationResult - .Should() - .Be(ClientOperationType.Create); - - var deleteResult =await _client.Delete(testFile2, category); - - deleteResult.Success - .Should() - .BeTrue(); - - deleteResult.OperationResult - .Should() - .Be(ClientOperationType.Delete); - - var upsert2Result = await _client.Upsert(testFile3, category); - - upsert2Result.Success - .Should() - .BeFalse(); - - upsert2Result.OperationResult - .Should() - .Be(ClientOperationType.NoOperation); + Assert.AreEqual(expected, deleteCount); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_InsertItemsWithCategories_ShouldGetRightItemForPartition() + { + var partition1 = "partition1"; + var partition2 = "partition2"; + + var testFile1 = + new TestClassA + { + StringProperty = "test1", + IntProperty = _globalFaker.Random.Int(), + }; + + var testFile2 = + new TestClassA + { + StringProperty = "test2", + IntProperty = 84, + }; + + await _client.UpsertAsync(testFile1, partition1); + await _client.UpsertAsync(testFile2, partition2); + + var testFile1InPartition2 = await _client.GetLatestAsync(testFile1, partition2); + var testFile2InPartition1 = await _client.GetLatestAsync(testFile2, partition1); + + Assert.IsNull(testFile1InPartition2); + Assert.IsNull(testFile2InPartition1); + + var testFile1InPartition1 = await _client.GetLatestAsync(testFile1, partition1); + var testFile2InPartition2 = await _client.GetLatestAsync(testFile2, partition2); + + Assert.IsNotNull(testFile1InPartition1); + Assert.IsNotNull(testFile2InPartition2); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_Reconcile_ShouldGetServerValue() + { + var index = 1; + + var testObjects = + new Faker() + .RuleFor(x => x.StringProperty, (f, u) => $"String_{index++}") + .RuleFor(x => x.IntProperty, (f, u) => index++) + .RuleFor(x => x.TimestampMillis, (f, u) => DateTimeOffset.Now.ToUnixTimeMilliseconds()); + + var partition = "partition"; + + var generatedTestObjects = testObjects.GenerateBetween(100, 100); + + var populated = await _client.PopulateCacheAsync(generatedTestObjects, partition); + + for (int i = 0; i < 50; i++) + { + await _client.UpsertAsync(generatedTestObjects[i], partition); } - [TestMethod] - public async Task OrbitClient_InsertMultipleWithSameKey_ShouldFindRightTypes() - { - var id = "Test Value"; - - var testFile1 = - new TestClassA - { - StringProperty = id, - IntProperty = 42 - }; - - var testFile2 = - new TestClassB - { - StringProperty = id, - DoubleProperty = 42d - }; - - await _client.Upsert(testFile1); - await _client.Upsert(testFile2); - - var foundA = await _client.GetLatest(id); - var foundB = await _client.GetLatest(id); - - Assert.IsTrue(foundA.IntProperty == testFile1.IntProperty); - Assert.IsTrue(foundB.DoubleProperty == testFile2.DoubleProperty); - } - - [TestMethod] - public async Task OrbitClient_InsertMultipleWithSameKeyWithCategory_ShouldFindRightTypes() - { - var id = "Test Value"; - - var category = "category"; - - var testFile1 = - new TestClassA - { - StringProperty = id, - IntProperty = 42 - }; - - var testFile2 = - new TestClassB - { - StringProperty = id, - DoubleProperty = 42d - }; + Assert.IsTrue(populated); - await _client.Upsert(testFile1, category); - await _client.Upsert(testFile2, category); - - var foundA = await _client.GetLatest (id, category); - var foundB = await _client.GetLatest(id, category); - - Assert.IsTrue(foundA.IntProperty == testFile1.IntProperty); - Assert.IsTrue(foundB.DoubleProperty == testFile2.DoubleProperty); - } - - [TestMethod] - public async Task OrbitClient_GetLatestSyncQueueWithInvalidId_ShouldFindNothing() - { - var id = "Test Value"; - - var category = "test"; - - var testFile1 = - new TestClassA - { - StringProperty = id, - IntProperty = 42 - }; + index = 1; - await _client.Upsert(testFile1, category); - - var foundA = await _client.GetAllLatestSyncQueue(); - - foundA.Should().BeEmpty(); - } - - [TestMethod] - public async Task OrbitClient_GetAllLatest_PerfTest1 () - { - - var category = "test"; - - var items = - Enumerable - .Range(1, 2000) - .Select(id => - new ServerSyncInfo - { - Value = - new TestClassA - { - StringProperty = $"id_{id}", - IntProperty = id - } - }) - .ToList(); - - await _client.Reconcile(items, category); - - var sw = Stopwatch.StartNew(); - var foundA = await _client.GetAllLatest(category); - sw.Stop(); - - Console.WriteLine($"GetAllLatest: {sw.ElapsedMilliseconds}ms"); - - foundA.Should().NotBeEmpty(); - } - - [TestMethod] - public async Task OrbitClient_InsertConcurrent_ShouldNotFail() - { - try - { - var id1 = "id1"; - var id2 = "id2"; - - var max = 100; - - var testFile1 = - new TestClassA + var generatedTestServerObjects = + testObjects + .GenerateBetween(100, 100) + .Select(x => + new ServerSyncInfo { - StringProperty = id1 - }; + Value = x, + Operation = ServerOperationType.Updated, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + }) + .ToList(); - var testFile2 = - new TestClassA - { - StringProperty = id2 - }; + await _client.ReconcileAsync(generatedTestServerObjects, partition); - var insert1Test = - Task.Run( - () => - { - for (int i = 1; i <= max; i++) - { - testFile1.IntProperty = i; - _client.Upsert(testFile1); - } - }); - - var insert2Test = - Task.Run( - () => - { - for (int i = 1; i <= max; i++) - { - testFile2.IntProperty = i; - _client.Upsert(testFile2); - } - }); - - await Task.WhenAll(insert1Test, insert2Test); - - var found1 = await _client.GetLatest(id1); - var found2 = await _client.GetLatest(id2); - - Assert.IsNotNull(found1); - Assert.IsTrue(found1.IntProperty == max); - - Assert.IsNotNull(found2); - Assert.IsTrue(found2.IntProperty == max); - } - catch (Exception ex) - { - Console.WriteLine(ex.StackTrace); - Assert.Fail($"Expected to not fail, but received: {ex.Message}"); - } + var latest = await _client.GetAllLatestAsync(partition); + + foreach (var obj in generatedTestServerObjects) + { + var found = latest.FirstOrDefault(x => x.StringProperty == obj.Value.StringProperty && x.IntProperty == obj.Value.IntProperty && x.TimestampMillis == obj.Value.TimestampMillis); + Assert.IsTrue(found != default); } - [TestMethod] - public async Task OrbitClient_BulkInsertAndUpdate_ShouldGetNewValue() - { - - var testObjects = - new Faker() - .RuleFor(x => x.StringProperty, (f, u) => $"String_{f.IndexFaker}") - .RuleFor(x => x.IntProperty, (f, u) => f.IndexFaker); - - var generatedTestObjects = testObjects.GenerateBetween(100, 100); - - var populated = await _client.PopulateCache(generatedTestObjects); - - Assert.IsTrue(populated); - - var original = generatedTestObjects[49]; - - var foundObject = await _client.GetLatest(original); - - Assert.AreEqual(foundObject.IntProperty, original.IntProperty); - - foundObject.IntProperty = foundObject.IntProperty * 2; - - var upsertResult = await _client.Upsert(foundObject); - - upsertResult.Success - .Should() - .BeTrue(); - - upsertResult.OperationResult - .Should() - .Be(ClientOperationType.Update); - - var latest = await _client.GetAllLatest(); - - var updated = latest.FirstOrDefault(x => x.StringProperty == original.StringProperty); - - Assert.IsTrue(updated.IntProperty == foundObject.IntProperty); - } - - [TestMethod] - public async Task OrbitClient_BulkInsertAndUpdateWithCategory_ShouldGetNewValue() - { - - var testObjects = - new Faker() - .RuleFor(x => x.StringProperty, (f, u) => $"String_{f.IndexFaker}") - .RuleFor(x => x.IntProperty, (f, u) => f.IndexFaker); - - var category = "category"; - - var generatedTestObjects = testObjects.GenerateBetween(100, 100); - - var populated = await _client.PopulateCache(generatedTestObjects, category); - - Assert.IsTrue(populated); - - var original = generatedTestObjects[49]; - - var foundObject = await _client.GetLatest(original, category); - - Assert.AreEqual(foundObject.IntProperty, original.IntProperty); - - foundObject.IntProperty = foundObject.IntProperty * 2; - - var upsertResult = await _client.Upsert(foundObject, category); - - upsertResult.Success - .Should() - .BeTrue(); - - upsertResult.OperationResult - .Should() - .Be(ClientOperationType.Update); - - var latest = await _client.GetAllLatest(category); - - var updated = latest.FirstOrDefault(x => x.StringProperty == original.StringProperty); - - Assert.IsTrue(updated.IntProperty == foundObject.IntProperty); - } - - [TestMethod] - public async Task OrbitClient_BulkInsertAndDelete_ShouldDeleteAll () - { - var expected = 100; - - var testObjects = - new Faker () - .RuleFor (x => x.StringProperty, (f, u) => $"String_{f.IndexFaker}") - .RuleFor (x => x.IntProperty, (f, u) => f.IndexFaker); - - var category = "category"; - - var generatedTestObjects = testObjects.GenerateBetween (100, 100); - - var populated = await _client.PopulateCache (generatedTestObjects, category); - - Assert.IsTrue (populated); - - var deleteCount = 0; - - foreach (var generatedTestObject in generatedTestObjects) - { - var deleteResult = await _client.DeleteCacheItem (generatedTestObject, category); - - if(deleteResult == true) - { - deleteCount += 1; - } - - Assert.IsTrue (deleteResult); - } - - Assert.AreEqual (expected, deleteCount); - } - - [TestMethod] - public async Task OrbitClient_InsertItemsWithCategories_ShouldGetRightItemForCategory() - { - var category1 = "category1"; - var category2 = "category2"; - - var testFile1 = - new TestClassA - { - StringProperty = "test1", - IntProperty = 42 - }; - - var testFile2 = - new TestClassA - { - StringProperty = "test2", - IntProperty = 84 - }; - - await _client.Upsert(testFile1, category1); - await _client.Upsert(testFile2, category2); - - var testFile1InCategory2 = await _client.GetLatest(testFile1, category2); - var testFile2InCategory1 = await _client.GetLatest(testFile2, category1); - - Assert.IsNull(testFile1InCategory2); - Assert.IsNull(testFile2InCategory1); - - var testFile1InCategory1 = await _client.GetLatest(testFile1, category1); - var testFile2InCategory2 = await _client.GetLatest(testFile2, category2); - - Assert.IsNotNull(testFile1InCategory1); - Assert.IsNotNull(testFile2InCategory2); - } - - [TestMethod] - public async Task OrbitClient_InsertItemsWithCategories_ShouldFindCategories() - { - var category1 = "category1"; - var category2 = "category2"; - - var expectedCategories = 2; - - var testFile1 = - new TestClassA - { - StringProperty = "test1", - IntProperty = 42 - }; - - var testFile2 = - new TestClassA - { - StringProperty = "test2", - IntProperty = 84 - }; - - await _client.Upsert(testFile1, category1); - await _client.Upsert(testFile2, category2); - - var categories = (await _client.GetCategories()).ToList(); - - Assert.IsTrue(categories.Contains(category1)); - Assert.IsTrue(categories.Contains(category2)); - Assert.IsTrue(categories.Count == expectedCategories); - } - - [TestMethod] - public async Task OrbitClient_PopulateCacheAndInsertItemsWithCategories_ShouldFindCategories() - { - var category1 = "category1"; - var category2 = "category2"; - - var expectedCategories = 2; - - var testFile1 = - new TestClassA - { - StringProperty = "test1", - IntProperty = 42 - }; - - var testFile2 = - new TestClassA - { - StringProperty = "test2", - IntProperty = 84 - }; - - await _client.PopulateCache(new[] { testFile1 }, category1); - await _client.Upsert(testFile2, category2); - - var categories = (await _client.GetCategories()).ToList(); - - Assert.IsTrue(categories.Contains(category1)); - Assert.IsTrue(categories.Contains(category2)); - Assert.IsTrue(categories.Count == expectedCategories); - } - - //[TestMethod] - //public async Task OrbitClient_PopulateCacheWithSimpleItems_ShouldPopulate() - //{ - // var category1 = "category1"; - // var category2 = "category2"; - - // await _client.PopulateCache(new[] { category1, category2 }); - - // var latest = await _client.GetAllLatest(); - - // Assert.IsTrue(latest.Count() == 2); - //} - - [TestMethod] - public async Task OrbitClient_Reconcile_ShouldGetServerValue () - { - var index = 1; - - var testObjects = - new Faker() - .RuleFor(x => x.StringProperty, (f, u) => $"String_{index++}") - .RuleFor(x => x.IntProperty, (f, u) => index++) - .RuleFor(x => x.TimestampMillis, (f, u) => DateTimeOffset.Now.ToUnixTimeMilliseconds()); - - var category = "category"; - - var generatedTestObjects = testObjects.GenerateBetween(100, 100); - - var populated = await _client.PopulateCache(generatedTestObjects, category); - - for (int i = 0; i < 50; i++) - { - await _client.Upsert(generatedTestObjects[i], category); - } - - Assert.IsTrue(populated); - - index = 1; - - var generatedTestServerObjects = - testObjects - .GenerateBetween(100, 100) - .Select(x => - new ServerSyncInfo - { - Value = x, - Operation = ServerOperationType.Updated, - }) - .ToList(); - - await _client.Reconcile(generatedTestServerObjects, category); - - var latest = await _client.GetAllLatest(category); - - foreach (var obj in generatedTestServerObjects) - { - var found = latest.FirstOrDefault(x => x.StringProperty == obj.Value.StringProperty && x.IntProperty == obj.Value.IntProperty && x.TimestampMillis == obj.Value.TimestampMillis); - Assert.IsTrue(found != default); - } - - var syncQueue = await _client.GetAllLatestSyncQueue(category); - Assert.IsTrue(!syncQueue.Any()); - - var allLatest = await _client.GetAllLatest(category); - Assert.IsTrue(allLatest.Count() == 100); - } - - [TestMethod] - public async Task OrbitClient_SlamItWithMessagesConcurrently_ShouldBeOkay () - { - - var testAObjects = - new Faker () - .RuleFor (x => x.StringProperty, (f, u) => $"String_{f.IndexFaker}") - .RuleFor (x => x.IntProperty, (f, u) => f.IndexFaker); - - var testBObjects = - new Faker () - .RuleFor (x => x.StringProperty, (f, u) => $"String_{f.IndexFaker}") - .RuleFor (x => x.DoubleProperty, (f, u) => f.IndexFaker); - - var generatedTestAObjects = testAObjects.GenerateBetween (10000, 100000); - - var generatedTestBObjects = testAObjects.GenerateBetween (10000, 100000); - - Exception exception = null; - for (int i = 0; i < 10; i++) - { - try - { - var populatedATask = _client.PopulateCache (generatedTestAObjects); - var latestATask = _client.GetAllLatest (); - var populatedBTask = _client.PopulateCache (generatedTestBObjects); - var latestBTask = _client.GetAllLatest (); - - await Task.WhenAll (populatedATask, populatedBTask, latestATask, latestBTask); - } - catch (Exception ex) - { - exception = ex; - } - - } - - Assert.IsNull (exception); - } - - class TestClassA + var syncQueue = await _client.GetAllLatestSyncQueueAsync(partition); + Assert.IsTrue(!syncQueue.Any()); + + var allLatest = await _client.GetAllLatestAsync(partition); + Assert.IsTrue(allLatest.Count() == 100); + } + + [TestMethod] + [DoNotParallelize] + public async Task OrbitClient_SlamItWithMessagesConcurrently_ShouldBeOkay() + { + var testAObjects = + new Faker() + .RuleFor(x => x.StringProperty, (f, u) => $"String_{f.IndexFaker}") + .RuleFor(x => x.IntProperty, (f, u) => f.IndexFaker); + + var testBObjects = + new Faker() + .RuleFor(x => x.StringProperty, (f, u) => $"String_{f.IndexFaker}") + .RuleFor(x => x.DoubleProperty, (f, u) => f.IndexFaker); + + var generatedTestAObjects = testAObjects.GenerateBetween(1000, 10000); + + var generatedTestBObjects = testAObjects.GenerateBetween(1000, 10000); + + Exception exception = null; + for (int i = 0; i < 10; i++) { - public string StringProperty { get; set; } - - public int IntProperty { get; set; } - - public long TimestampMillis { get; set; } - } - - - class TestClassB - { - public string StringProperty { get; set; } - - public double DoubleProperty { get; set; } + try + { + var populatedATask = _client.PopulateCacheAsync(generatedTestAObjects); + var latestATask = _client.GetAllLatestAsync(); + var populatedBTask = _client.PopulateCacheAsync(generatedTestBObjects); + var latestBTask = _client.GetAllLatestAsync(); + + await Task.WhenAll(populatedATask, populatedBTask, latestATask, latestBTask); + } + catch (Exception ex) + { + exception = ex; + } } - class TestClassC - { - public int IntProperty { get; set; } - - public string DoubleProperty { get; set; } - } - - class TestClassD - { - public float FloatProperty { get; set; } - - public double DoubleProperty { get; set; } - } - - class TestClassE - { - public Guid TestClassId { get; set; } - - public IEnumerable Values { get; set; } - } - } -} + Assert.IsNull(exception); + } + + private class TestClassA + { + public string StringProperty { get; set; } + + public int IntProperty { get; set; } + + public long TimestampMillis { get; set; } + } + + private class TestClassB + { + public string StringProperty { get; set; } + + public double DoubleProperty { get; set; } + } + + private class TestClassC + { + public int IntProperty { get; set; } + + public string DoubleProperty { get; set; } + } + + private class TestClassD + { + public float FloatProperty { get; set; } + + public double DoubleProperty { get; set; } + } + + private class TestClassE + { + public Guid TestClassId { get; set; } + + public IEnumerable Values { get; set; } + } +} diff --git a/EightBot.Orbit.Tests/OrbitServerTests.cs b/EightBot.Orbit.Tests/OrbitServerTests.cs index f59517a..4e50e60 100644 --- a/EightBot.Orbit.Tests/OrbitServerTests.cs +++ b/EightBot.Orbit.Tests/OrbitServerTests.cs @@ -1,3 +1,8 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; using EightBot.Nebula.DocumentDb; using EightBot.Orbit.Server; using EightBot.Orbit.Server.Data; @@ -6,725 +11,662 @@ using Microsoft.Extensions.Logging.Debug; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -namespace EightBot.Orbit.Tests +namespace EightBot.Orbit.Tests; + +[TestClass] +public class OrbitServerTests { - [TestClass] - public class OrbitServerTests + public static readonly LoggerFactory Logger = new LoggerFactory(new[] { new DebugLoggerProvider { }, }); + + private IOrbitDataClient _orbitDataClient = null; + private IDataClient _dataClient = null; + + [TestInitialize] + public async Task Setup() { - public static readonly LoggerFactory Logger = new LoggerFactory(new[] { new DebugLoggerProvider { }}); + var databaseUri = "https://localhost:8081"; + var authKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="; + var databaseId = "EightBot.Orbit.Test"; - private IOrbitDataClient OrbitDataClient = null; - private IDataClient DataClient = null; + var documentDbLogger = Logger.CreateLogger("EightBot.Nebula.DocumentDb"); - public OrbitServerTests() - { + var comosClient = new CosmosClient(databaseUri, authKey); - } + var database = await comosClient.CreateDatabaseIfNotExistsAsync(databaseId, 400); - [TestInitialize] - public async Task Setup() + var dataClient = new DataClient(database, () => Thread.CurrentPrincipal?.Identity?.Name ?? "test") { - var databaseUri = "https://localhost:8081"; - var authKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="; - var databaseId = "EightBot.Orbit.Test"; - - var documentDbLogger = Logger.CreateLogger("EightBot.Nebula.DocumentDb"); + ThrowErrors = true, + LogError = y => documentDbLogger.LogError(y), + LogInformation = y => documentDbLogger.LogInformation(y), + }; - var comosClient = new CosmosClient(databaseUri, authKey); + await dataClient.EnsureContainerAsync(x => x.StringProperty, x => x.Pk); - var database = await comosClient.CreateDatabaseIfNotExistsAsync(databaseId, 400); + this._orbitDataClient = new OrbitCosmosDataClient(dataClient); + this._dataClient = dataClient; + } - var dataClient = new DataClient(database, () => Thread.CurrentPrincipal?.Identity?.Name ?? "test") - { - ThrowErrors = true, - LogError = y => documentDbLogger.LogError(y), - LogInformation = y => documentDbLogger.LogInformation(y) - }; + [TestCleanup] + public void Shutdown() + { + } - await dataClient.EnsureContainerAsync(x => x.StringProperty, x => x.PK); - //await dataClient.EnsureContainerAsync(x => x.StringProperty, x => x.PK); + [TestMethod] + public async Task OrbitServer_OrbitCosmosClient_Create_Update_Delete_One() + { + var count = 1; - this.OrbitDataClient = new OrbitCosmosDataClient(dataClient); - this.DataClient = dataClient; + // CREATE + var syncables = new List>(); + for (var i = 0; i < count; i++) + { + syncables.Add(new ClientSyncInfo() + { + Operation = ClientOperationType.Create, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Value = new TestClassA() { StringProperty = $"One{i}", Pk = "test", IntProperty = 100, DoubleProperty = 1.00, }, + }); } - [TestCleanup] - public void Shutdown() - { + var results = await this._orbitDataClient.Sync(syncables); - } + Assert.IsTrue(results.Count() == count); - [TestMethod] - public async Task OrbitServer_OrbitCosmosClient_Create_Update_Delete_One() - { - var count = 1; + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Created); + Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "One0"); + Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); + Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 1.00); - // CREATE - var syncables = new List>(); - for (var i = 0; i < count; i++) - { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Create, - ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - Value = new TestClassA() { StringProperty = $"One{i}", PK = "test", IntProperty = 100, DoubleProperty = 1.00 } - }); - } - - var results = await this.OrbitDataClient.Sync(syncables); - - Assert.IsTrue(results.Count() == count); - - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Created); - Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "One0"); - Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); - Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 1.00); - - // UPDATE - syncables = new List>(); - for (var i = 0; i < count; i++) + // UPDATE + syncables = new List>(); + for (var i = 0; i < count; i++) + { + syncables.Add(new ClientSyncInfo() { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Update, - ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - Value = new TestClassA() { StringProperty = $"One{i}", PK = "test", IntProperty = 100, DoubleProperty = 1.01 } - }); - } + Operation = ClientOperationType.Update, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Value = new TestClassA() { StringProperty = $"One{i}", Pk = "test", IntProperty = 100, DoubleProperty = 1.01, }, + }); + } - results = await this.OrbitDataClient.Sync(syncables); + results = await this._orbitDataClient.Sync(syncables); - Assert.IsTrue(results.Count() == count); + Assert.IsTrue(results.Count() == count); - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Updated); - Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "One0"); - Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); - Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 1.01); + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Updated); + Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "One0"); + Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); + Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 1.01); - var total = await this.DataClient.Document().WhereAsync(x => x.IntProperty == 100); + var total = await this._dataClient.Document().WhereAsync(x => x.IntProperty == 100); - Assert.IsTrue(total.Count == count); + Assert.IsTrue(total.Count == count); - // DELETE - syncables = new List>(); - for (var i = 0; i < count; i++) + // DELETE + syncables = new List>(); + for (var i = 0; i < count; i++) + { + syncables.Add(new ClientSyncInfo() { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Delete, - ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - Value = new TestClassA() { StringProperty = $"One{i}", PK = "test", IntProperty = 100, DoubleProperty = 1.02 } - }); - } + Operation = ClientOperationType.Delete, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Value = new TestClassA() { StringProperty = $"One{i}", Pk = "test", IntProperty = 100, DoubleProperty = 1.02, }, + }); + } - results = await this.OrbitDataClient.Sync(syncables); + results = await this._orbitDataClient.Sync(syncables); - Assert.IsTrue(results.Count() == count); + Assert.IsTrue(results.Count() == count); - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Deleted); - Assert.IsTrue(!String.IsNullOrWhiteSpace(results.ElementAt(0).Id)); - Assert.IsTrue(results.ElementAt(0).Value == null); - } + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Deleted); + Assert.IsTrue(!string.IsNullOrWhiteSpace(results.ElementAt(0).Id)); + Assert.IsTrue(results.ElementAt(0).Value == null); + } - [TestMethod] - public async Task OrbitServer_OrbitCosmosClient_Create_Update_Delete_OneHundred() - { - var count = 100; + [TestMethod] + public async Task OrbitServer_OrbitCosmosClient_Create_Update_Delete_OneHundred() + { + var count = 100; - // CREATE - var syncables = new List>(); - for (var i = 0; i < count; i++) - { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Create, - ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - Value = new TestClassA() { StringProperty = $"OneHundred{i}", PK = "test", IntProperty = 100, DoubleProperty = 1.00 } - }); - } - - var results = await this.OrbitDataClient.Sync(syncables); - - Assert.IsTrue(results.Count() == count); - - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Created); - Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "OneHundred0"); - Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); - Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 1.00); - - Assert.IsTrue(results.ElementAt(99).Operation == ServerOperationType.Created); - Assert.IsTrue(results.ElementAt(99).Value.StringProperty == "OneHundred99"); - Assert.IsTrue(results.ElementAt(99).Value.IntProperty == 100); - Assert.IsTrue(results.ElementAt(99).Value.DoubleProperty == 1.00); - - // UPDATE - syncables = new List>(); - for (var i = 0; i < count; i++) + // CREATE + var syncables = new List>(); + for (var i = 0; i < count; i++) + { + syncables.Add(new ClientSyncInfo() { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Create, - ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - Value = new TestClassA() { StringProperty = $"OneHundred{i}", PK = "test", IntProperty = 100, DoubleProperty = 1.01 } - }); - } + Operation = ClientOperationType.Create, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Value = new TestClassA() { StringProperty = $"OneHundred{i}", Pk = "test", IntProperty = 100, DoubleProperty = 1.00, }, + }); + } - results = await this.OrbitDataClient.Sync(syncables); + var results = await this._orbitDataClient.Sync(syncables); - Assert.IsTrue(results.Count() == count); + Assert.IsTrue(results.Count() == count); - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Updated); - Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "OneHundred0"); - Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); - Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 1.01); + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Created); + Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "OneHundred0"); + Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); + Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 1.00); - Assert.IsTrue(results.ElementAt(99).Operation == ServerOperationType.Updated); - Assert.IsTrue(results.ElementAt(99).Value.StringProperty == "OneHundred99"); - Assert.IsTrue(results.ElementAt(99).Value.IntProperty == 100); - Assert.IsTrue(results.ElementAt(99).Value.DoubleProperty == 1.01); + Assert.IsTrue(results.ElementAt(99).Operation == ServerOperationType.Created); + Assert.IsTrue(results.ElementAt(99).Value.StringProperty == "OneHundred99"); + Assert.IsTrue(results.ElementAt(99).Value.IntProperty == 100); + Assert.IsTrue(results.ElementAt(99).Value.DoubleProperty == 1.00); - var total = await this.DataClient.Document().WhereAsync(x => x.IntProperty == 100); + // UPDATE + syncables = new List>(); + for (var i = 0; i < count; i++) + { + syncables.Add(new ClientSyncInfo() + { + Operation = ClientOperationType.Create, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Value = new TestClassA() { StringProperty = $"OneHundred{i}", Pk = "test", IntProperty = 100, DoubleProperty = 1.01, }, + }); + } - Assert.IsTrue(total.Count == count); + results = await this._orbitDataClient.Sync(syncables); - // DELETE - syncables = new List>(); - for (var i = 0; i < count; i++) - { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Delete, - ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - Value = new TestClassA() { StringProperty = $"OneHundred{i}", PK = "test", IntProperty = 100, DoubleProperty = 1.02 } - }); - } + Assert.IsTrue(results.Count() == count); - results = await this.OrbitDataClient.Sync(syncables); + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Updated); + Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "OneHundred0"); + Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); + Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 1.01); - Assert.IsTrue(results.Count() == count); + Assert.IsTrue(results.ElementAt(99).Operation == ServerOperationType.Updated); + Assert.IsTrue(results.ElementAt(99).Value.StringProperty == "OneHundred99"); + Assert.IsTrue(results.ElementAt(99).Value.IntProperty == 100); + Assert.IsTrue(results.ElementAt(99).Value.DoubleProperty == 1.01); - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Deleted); - Assert.IsTrue(results.ElementAt(0).Value == null); + var total = await this._dataClient.Document().WhereAsync(x => x.IntProperty == 100); - Assert.IsTrue(results.ElementAt(99).Operation == ServerOperationType.Deleted); - Assert.IsTrue(results.ElementAt(99).Value == null); - } + Assert.IsTrue(total.Count == count); - [TestMethod] - public async Task OrbitServer_OrbitCosmosClient_Create_Update_Delete_OneThousand() + // DELETE + syncables = new List>(); + for (var i = 0; i < count; i++) { - var count = 1000; - - // CREATE - var syncables = new List>(); - for (var i = 0; i < count; i++) + syncables.Add(new ClientSyncInfo() { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Create, - ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - Value = new TestClassA() { StringProperty = $"OneThousand{i}", PK = "test", IntProperty = 100, DoubleProperty = 1.00 } - }); - } - - var results = await this.OrbitDataClient.Sync(syncables); - - Assert.IsTrue(results.Count() == count); - - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Created); - Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "OneThousand0"); - Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); - Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 1.00); - - Assert.IsTrue(results.ElementAt(999).Operation == ServerOperationType.Created); - Assert.IsTrue(results.ElementAt(999).Value.StringProperty == "OneThousand999"); - Assert.IsTrue(results.ElementAt(999).Value.IntProperty == 100); - Assert.IsTrue(results.ElementAt(999).Value.DoubleProperty == 1.00); - - // UPDATE - syncables = new List>(); - for (var i = 0; i < count; i++) - { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Create, - ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - Value = new TestClassA() { StringProperty = $"OneThousand{i}", PK = "test", IntProperty = 100, DoubleProperty = 1.01 } - }); - } - - results = await this.OrbitDataClient.Sync(syncables); + Operation = ClientOperationType.Delete, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Value = new TestClassA() { StringProperty = $"OneHundred{i}", Pk = "test", IntProperty = 100, DoubleProperty = 1.02, }, + }); + } - Assert.IsTrue(results.Count() == count); + results = await this._orbitDataClient.Sync(syncables); - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Updated); - Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "OneThousand0"); - Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); - Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 1.01); + Assert.IsTrue(results.Count() == count); - Assert.IsTrue(results.ElementAt(999).Operation == ServerOperationType.Updated); - Assert.IsTrue(results.ElementAt(999).Value.StringProperty == "OneThousand999"); - Assert.IsTrue(results.ElementAt(999).Value.IntProperty == 100); - Assert.IsTrue(results.ElementAt(999).Value.DoubleProperty == 1.01); + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Deleted); + Assert.IsTrue(results.ElementAt(0).Value == null); - var total = this.DataClient.Document().Count(x => x.IntProperty == 100); + Assert.IsTrue(results.ElementAt(99).Operation == ServerOperationType.Deleted); + Assert.IsTrue(results.ElementAt(99).Value == null); + } - Assert.IsTrue(total == count); + [TestMethod] + public async Task OrbitServer_OrbitCosmosClient_Create_Update_Delete_OneThousand() + { + var count = 1000; - // DELETE - syncables = new List>(); - for (var i = 0; i < count; i++) + // CREATE + var syncables = new List>(); + for (var i = 0; i < count; i++) + { + syncables.Add(new ClientSyncInfo() { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Delete, - ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - Value = new TestClassA() { StringProperty = $"OneThousand{i}", PK = "test", IntProperty = 100, DoubleProperty = 1.02 } - }); - } + Operation = ClientOperationType.Create, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Value = new TestClassA() { StringProperty = $"OneThousand{i}", Pk = "test", IntProperty = 100, DoubleProperty = 1.00, }, + }); + } - results = await this.OrbitDataClient.Sync(syncables); + var results = await this._orbitDataClient.Sync(syncables); - Assert.IsTrue(results.Count() == count); + Assert.IsTrue(results.Count() == count); - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Deleted); - Assert.IsTrue(results.ElementAt(0).Value == null); + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Created); + Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "OneThousand0"); + Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); + Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 1.00); - Assert.IsTrue(results.ElementAt(99).Operation == ServerOperationType.Deleted); - Assert.IsTrue(results.ElementAt(999).Value == null); - } + Assert.IsTrue(results.ElementAt(999).Operation == ServerOperationType.Created); + Assert.IsTrue(results.ElementAt(999).Value.StringProperty == "OneThousand999"); + Assert.IsTrue(results.ElementAt(999).Value.IntProperty == 100); + Assert.IsTrue(results.ElementAt(999).Value.DoubleProperty == 1.00); - [TestMethod] - public async Task OrbitServer_OrbitCosmosClient_Update_Newer() + // UPDATE + syncables = new List>(); + for (var i = 0; i < count; i++) { - var count = 1; - - // CREATE - var syncables = new List>(); - for (var i = 0; i < count; i++) + syncables.Add(new ClientSyncInfo() { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Create, - ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - Value = new TestClassA() { StringProperty = $"UpdateNewer{i}", PK = "test", IntProperty = 100, DoubleProperty = 1.00 } - }); - } + Operation = ClientOperationType.Create, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Value = new TestClassA() { StringProperty = $"OneThousand{i}", Pk = "test", IntProperty = 100, DoubleProperty = 1.01, }, + }); + } - var results = await this.OrbitDataClient.Sync(syncables); + results = await this._orbitDataClient.Sync(syncables); - Assert.IsTrue(results.Count() == count); + Assert.IsTrue(results.Count() == count); - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Created); + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Updated); + Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "OneThousand0"); + Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); + Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 1.01); - var lastupDatedTime = syncables[0].ModifiedOn + 1000; + Assert.IsTrue(results.ElementAt(999).Operation == ServerOperationType.Updated); + Assert.IsTrue(results.ElementAt(999).Value.StringProperty == "OneThousand999"); + Assert.IsTrue(results.ElementAt(999).Value.IntProperty == 100); + Assert.IsTrue(results.ElementAt(999).Value.DoubleProperty == 1.01); - // UPDATE - syncables = new List>(); - for (var i = 0; i < count; i++) - { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Update, - ModifiedOn = lastupDatedTime, - Value = new TestClassA() { StringProperty = $"UpdateNewer{i}", PK = "test", IntProperty = 100, DoubleProperty = 999.99 } - }); - } - - results = await this.OrbitDataClient.Sync(syncables); - - Assert.IsTrue(results.Count() == count); - - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Updated); - Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "UpdateNewer0"); - Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); - Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 999.99); - - // DELETE - syncables = new List>(); - for (var i = 0; i < count; i++) + var total = this._dataClient.Document().Count(x => x.IntProperty == 100); + + Assert.IsTrue(total == count); + + // DELETE + syncables = new List>(); + for (var i = 0; i < count; i++) + { + syncables.Add(new ClientSyncInfo() { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Delete, - ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - Value = new TestClassA() { StringProperty = $"UpdateNewer{i}", PK = "test", IntProperty = 100, DoubleProperty = 999.99 } - }); - } + Operation = ClientOperationType.Delete, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Value = new TestClassA() { StringProperty = $"OneThousand{i}", Pk = "test", IntProperty = 100, DoubleProperty = 1.02, }, + }); + } - results = await this.OrbitDataClient.Sync(syncables); + results = await this._orbitDataClient.Sync(syncables); - Assert.IsTrue(results.Count() == count); + Assert.IsTrue(results.Count() == count); - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Deleted); - Assert.IsTrue(results.ElementAt(0).Value == null); - } + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Deleted); + Assert.IsTrue(results.ElementAt(0).Value == null); - [TestMethod] - public async Task OrbitServer_OrbitCosmosClient_Update_Older() - { - var count = 1; + Assert.IsTrue(results.ElementAt(99).Operation == ServerOperationType.Deleted); + Assert.IsTrue(results.ElementAt(999).Value == null); + } - // CREATE - var syncables = new List>(); - for (var i = 0; i < count; i++) + [TestMethod] + public async Task OrbitServer_OrbitCosmosClient_Update_Newer() + { + var count = 1; + + // CREATE + var syncables = new List>(); + for (var i = 0; i < count; i++) + { + syncables.Add(new ClientSyncInfo() { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Create, - ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - Value = new TestClassA() { StringProperty = $"UpdateOlder{i}", PK = "test", IntProperty = 100, DoubleProperty = 1.00 } - }); - } + Operation = ClientOperationType.Create, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Value = new TestClassA() { StringProperty = $"UpdateNewer{i}", Pk = "test", IntProperty = 100, DoubleProperty = 1.00, }, + }); + } - var results = await this.OrbitDataClient.Sync(syncables); + var results = await this._orbitDataClient.Sync(syncables); - Assert.IsTrue(results.Count() == count); + Assert.IsTrue(results.Count() == count); - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Created); + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Created); - var lastupDatedTime = syncables[0].ModifiedOn - 1000; + var lastupDatedTime = syncables[0].ModifiedOn + 1000; - // UPDATE - syncables = new List>(); - for (var i = 0; i < count; i++) - { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Update, - ModifiedOn = lastupDatedTime, - Value = new TestClassA() { StringProperty = $"UpdateOlder{i}", PK = "test", IntProperty = 100, DoubleProperty = 999.99 } - }); - } - - results = await this.OrbitDataClient.Sync(syncables); - - Assert.IsTrue(results.Count() == count); - - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Updated); - Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "UpdateOlder0"); - Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); - Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 1.00); - - // DELETE - syncables = new List>(); - for (var i = 0; i < count; i++) + // UPDATE + syncables = new List>(); + for (var i = 0; i < count; i++) + { + syncables.Add(new ClientSyncInfo() { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Delete, - ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - Value = new TestClassA() { StringProperty = $"UpdateOlder{i}", PK = "test", IntProperty = 100, DoubleProperty = 999.99 } - }); - } + Operation = ClientOperationType.Update, + ModifiedOn = lastupDatedTime, + Value = new TestClassA() { StringProperty = $"UpdateNewer{i}", Pk = "test", IntProperty = 100, DoubleProperty = 999.99, }, + }); + } - results = await this.OrbitDataClient.Sync(syncables); + results = await this._orbitDataClient.Sync(syncables); - Assert.IsTrue(results.Count() == count); + Assert.IsTrue(results.Count() == count); - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Deleted); - Assert.IsTrue(results.ElementAt(0).Value == null); - } + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Updated); + Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "UpdateNewer0"); + Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); + Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 999.99); - [TestMethod] - public async Task OrbitServer_OrbitCosmosClient_Create_Empty_Id() + // DELETE + syncables = new List>(); + for (var i = 0; i < count; i++) { - var count = 1; - - var syncables = new List>(); - for (var i = 0; i < count; i++) + syncables.Add(new ClientSyncInfo() { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Update, - ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - Value = new TestClassA() { StringProperty = Guid.NewGuid().ToString(), PK = "test", IntProperty = 100, DoubleProperty = 999.99 } - }); - } - - var results = await this.OrbitDataClient.Sync(syncables); + Operation = ClientOperationType.Delete, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Value = new TestClassA() { StringProperty = $"UpdateNewer{i}", Pk = "test", IntProperty = 100, DoubleProperty = 999.99, }, + }); + } - Assert.IsTrue(results.Count() == count); + results = await this._orbitDataClient.Sync(syncables); - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Created); - Assert.IsTrue(results.ElementAt(0).Value.StringProperty.Length == 36); - Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); - Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 999.99); + Assert.IsTrue(results.Count() == count); - // DELETE - results = await this.OrbitDataClient.Sync(new List>() { new ClientSyncInfo() { Operation = ClientOperationType.Delete, Value = results.ElementAt(0).Value } }); + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Deleted); + Assert.IsTrue(results.ElementAt(0).Value == null); + } - Assert.IsTrue(results.Count() == count); + [TestMethod] + public async Task OrbitServer_OrbitCosmosClient_Update_Older() + { + var count = 1; - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Deleted); - Assert.IsTrue(results.ElementAt(0).Value == null); + // CREATE + var syncables = new List>(); + for (var i = 0; i < count; i++) + { + syncables.Add(new ClientSyncInfo() + { + Operation = ClientOperationType.Create, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Value = new TestClassA() { StringProperty = $"UpdateOlder{i}", Pk = "test", IntProperty = 100, DoubleProperty = 1.00, }, + }); } - [TestMethod] - public async Task OrbitServer_OrbitCosmosClient_Create_Guid_Empty_Id() - { - var count = 1; + var results = await this._orbitDataClient.Sync(syncables); - var syncables = new List>(); - for (var i = 0; i < count; i++) - { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Update, - ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - Value = new TestClassA() { StringProperty = Guid.Empty.ToString(), PK = "test", IntProperty = 100, DoubleProperty = 999.99 } - }); - } + Assert.IsTrue(results.Count() == count); - var results = await this.OrbitDataClient.Sync(syncables); + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Created); - Assert.IsTrue(results.Count() == count); + var lastupDatedTime = syncables[0].ModifiedOn - 1000; - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.NotModified); - Assert.IsTrue(results.ElementAt(0).Value == null); + // UPDATE + syncables = new List>(); + for (var i = 0; i < count; i++) + { + syncables.Add(new ClientSyncInfo() + { + Operation = ClientOperationType.Update, + ModifiedOn = lastupDatedTime, + Value = new TestClassA() { StringProperty = $"UpdateOlder{i}", Pk = "test", IntProperty = 100, DoubleProperty = 999.99, }, + }); } - //[TestMethod] - //public async Task OrbitServer_OrbitCosmosClient_Create_Null_Id() - //{ - // var count = 1; + results = await this._orbitDataClient.Sync(syncables); - // var syncables = new List>(); - // for (var i = 0; i < count; i++) - // { - // syncables.Add(new ClientSyncInfo() - // { - // Operation = ClientOperationType.Update, - // ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - // Value = new TestClassA() { StringProperty = null, PK = "test", IntProperty = 100, DoubleProperty = 999.99 } - // }); - // } + Assert.IsTrue(results.Count() == count); - // var results = await this.OrbitDataClient.Sync(syncables); + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Updated); + Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "UpdateOlder0"); + Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); + Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 1.00); - // Assert.IsTrue(results.Count() == count); + // DELETE + syncables = new List>(); + for (var i = 0; i < count; i++) + { + syncables.Add(new ClientSyncInfo() + { + Operation = ClientOperationType.Delete, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Value = new TestClassA() { StringProperty = $"UpdateOlder{i}", Pk = "test", IntProperty = 100, DoubleProperty = 999.99, }, + }); + } - // Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Created); - // Assert.IsTrue(results.ElementAt(0).Value.StringProperty.Length == 36); - // Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); - // Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 999.99); + results = await this._orbitDataClient.Sync(syncables); - // // DELETE - // results = await this.OrbitDataClient.Sync(new List>() { new ClientSyncInfo() { Operation = ClientOperationType.Delete, Value = results.ElementAt(0).Value } }); + Assert.IsTrue(results.Count() == count); - // Assert.IsTrue(results.Count() == count); + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Deleted); + Assert.IsTrue(results.ElementAt(0).Value == null); + } - // Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Deleted); - // Assert.IsTrue(results.ElementAt(0).Value == null); - //} + [TestMethod] + public async Task OrbitServer_OrbitCosmosClient_Create_Empty_Id() + { + var count = 1; - [TestMethod] - public async Task OrbitServer_OrbitCosmosClient_Update_NotFound() + var syncables = new List>(); + for (var i = 0; i < count; i++) { - var count = 1; - - var syncables = new List>(); - for (var i = 0; i < count; i++) + syncables.Add(new ClientSyncInfo() { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Update, - ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - Value = new TestClassA() { StringProperty = $"UpdateNotFound{i}", PK = "test", IntProperty = 100, DoubleProperty = 999.99 } - }); - } + Operation = ClientOperationType.Update, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Value = new TestClassA() { StringProperty = Guid.NewGuid().ToString(), Pk = "test", IntProperty = 100, DoubleProperty = 999.99, }, + }); + } - var results = await this.OrbitDataClient.Sync(syncables); + var results = await this._orbitDataClient.Sync(syncables); - Assert.IsTrue(results.Count() == count); + Assert.IsTrue(results.Count() == count); - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Created); - Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "UpdateNotFound0"); - Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); - Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 999.99); + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Created); + Assert.IsTrue(results.ElementAt(0).Value.StringProperty.Length == 36); + Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); + Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 999.99); - // DELETE - results = await this.OrbitDataClient.Sync(new List>() { new ClientSyncInfo() { Operation = ClientOperationType.Delete, Value = results.ElementAt(0).Value } }); + // DELETE + results = await this._orbitDataClient.Sync(new List>() { new ClientSyncInfo() { Operation = ClientOperationType.Delete, Value = results.ElementAt(0).Value, }, }); - Assert.IsTrue(results.Count() == count); + Assert.IsTrue(results.Count() == count); - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Deleted); - Assert.IsTrue(results.ElementAt(0).Value == null); - } + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Deleted); + Assert.IsTrue(results.ElementAt(0).Value == null); + } - [TestMethod] - public async Task OrbitServer_OrbitCosmosClient_Delete_NotFound() - { - var count = 1; + [TestMethod] + public async Task OrbitServer_OrbitCosmosClient_Create_Guid_Empty_Id() + { + var count = 1; - var syncables = new List>(); - for (var i = 0; i < count; i++) + var syncables = new List>(); + for (var i = 0; i < count; i++) + { + syncables.Add(new ClientSyncInfo() { - syncables.Add(new ClientSyncInfo() - { - Operation = ClientOperationType.Delete, - ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), - Value = new TestClassA() { StringProperty = $"DeleteNotFound{i}", PK = "test", IntProperty = 100, DoubleProperty = 999.99 } - }); - } + Operation = ClientOperationType.Update, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Value = new TestClassA() { StringProperty = Guid.Empty.ToString(), Pk = "test", IntProperty = 100, DoubleProperty = 999.99, }, + }); + } - var results = await this.OrbitDataClient.Sync(syncables); + var results = await this._orbitDataClient.Sync(syncables); - Assert.IsTrue(results.Count() == count); + Assert.IsTrue(results.Count() == count); - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.NotModified); - Assert.IsTrue(results.ElementAt(0).Value == null); - } + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.NotModified); + Assert.IsTrue(results.ElementAt(0).Value == null); + } + + [TestMethod] + public async Task OrbitServer_OrbitCosmosClient_Update_NotFound() + { + var count = 1; - [TestMethod] - public async Task OrbitServer_OrbitCosmosClient_Its_Complicated() + var syncables = new List>(); + for (var i = 0; i < count; i++) { - var count = 10; - - // CREATE - var syncables = new List>(); - var item1 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer0", PK = "test", IntProperty = 100, DoubleProperty = 1.00 } }; - var item2 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer1", PK = "test", IntProperty = 100, DoubleProperty = 1.00 } }; - var item3 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer2", PK = "test", IntProperty = 100, DoubleProperty = 1.00 } }; - var item4 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer3", PK = "test", IntProperty = 100, DoubleProperty = 1.00 } }; - var item5 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer4", PK = "test", IntProperty = 100, DoubleProperty = 1.00 } }; - var item6 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer5", PK = "test", IntProperty = 100, DoubleProperty = 1.00 } }; - var item7 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer6", PK = "test", IntProperty = 100, DoubleProperty = 1.00 } }; - var item8 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer7", PK = "test", IntProperty = 100, DoubleProperty = 1.00 } }; - var item9 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer8", PK = "test", IntProperty = 100, DoubleProperty = 1.00 } }; - var item10 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer9", PK = "test", IntProperty = 100, DoubleProperty = 1.00 } }; - - syncables.Add(item1); - syncables.Add(item2); - syncables.Add(item3); - syncables.Add(item4); - syncables.Add(item5); - syncables.Add(item6); - syncables.Add(item7); - syncables.Add(item8); - syncables.Add(item9); - syncables.Add(item10); - - var results = await this.OrbitDataClient.Sync(syncables); - - Assert.IsTrue(results.Count() == count); - Assert.IsTrue(results.All(x => x.Operation == ServerOperationType.Created)); - - // UPDATE - item1.ModifiedOn = item1.ModifiedOn - 1000; - item1.Value.GuidProperty = Guid.Empty; - item2.ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - item2.Value.GuidProperty = Guid.Empty; - item3.ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - item3.Value.GuidProperty = Guid.Empty; - item4.ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - item4.Value.GuidProperty = Guid.Empty; - item5.ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - item5.Value.GuidProperty = Guid.Empty; - item6.ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - item6.Value.GuidProperty = Guid.Empty; - item7.ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - item7.Value.GuidProperty = Guid.Empty; - item8.ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - item8.Value.GuidProperty = Guid.Empty; - item9.Operation = ClientOperationType.Delete; - item10.ModifiedOn = item10.ModifiedOn - 1000; - item8.Value.GuidProperty = Guid.Empty; - - results = await this.OrbitDataClient.Sync(syncables); - - Assert.IsTrue(results.Count() == count); - Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Updated); - Assert.IsTrue(results.ElementAt(0).Value.GuidProperty != Guid.Empty); - Assert.IsTrue(results.Skip(1).Take(7).All(x => x.Operation == ServerOperationType.Updated)); - Assert.IsTrue(results.Skip(1).Take(7).All(x => x.Value.GuidProperty == Guid.Empty)); - Assert.IsTrue(results.ElementAt(8).Operation == ServerOperationType.Deleted); - Assert.IsTrue(results.ElementAt(8).Value == null); - Assert.IsTrue(results.ElementAt(9).Operation == ServerOperationType.Updated); - Assert.IsTrue(results.ElementAt(9).Value.GuidProperty != Guid.Empty); - - - item1.Operation = ClientOperationType.Delete; - item2.Operation = ClientOperationType.Delete; - item3.Operation = ClientOperationType.Delete; - item4.Operation = ClientOperationType.Delete; - item5.Operation = ClientOperationType.Delete; - item6.Operation = ClientOperationType.Delete; - item7.Operation = ClientOperationType.Delete; - item8.Operation = ClientOperationType.Delete; - item9.Operation = ClientOperationType.Delete; - item10.Operation = ClientOperationType.Delete; - - results = await this.OrbitDataClient.Sync(syncables); - - Assert.IsTrue(results.Count() == count); - - Assert.IsTrue(results.Skip(0).Take(8).All(x => x.Operation == ServerOperationType.Deleted)); - Assert.IsTrue(results.ElementAt(8).Operation == ServerOperationType.NotModified); - Assert.IsTrue(results.ElementAt(9).Operation == ServerOperationType.Deleted); + syncables.Add(new ClientSyncInfo() + { + Operation = ClientOperationType.Update, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Value = new TestClassA() { StringProperty = $"UpdateNotFound{i}", Pk = "test", IntProperty = 100, DoubleProperty = 999.99, }, + }); } + var results = await this._orbitDataClient.Sync(syncables); - public class TestClassA - { - [JsonProperty("StringProperty")] - public string StringProperty { get; set; } + Assert.IsTrue(results.Count() == count); - [JsonProperty("PK")] - public string PK { get; set; } + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Created); + Assert.IsTrue(results.ElementAt(0).Value.StringProperty == "UpdateNotFound0"); + Assert.IsTrue(results.ElementAt(0).Value.IntProperty == 100); + Assert.IsTrue(results.ElementAt(0).Value.DoubleProperty == 999.99); - [JsonProperty("IntProperty")] - public int IntProperty { get; set; } + // DELETE + results = await this._orbitDataClient.Sync(new List>() { new ClientSyncInfo() { Operation = ClientOperationType.Delete, Value = results.ElementAt(0).Value, }, }); - [JsonProperty("DoubleProperty")] - public double DoubleProperty { get; set; } + Assert.IsTrue(results.Count() == count); + + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Deleted); + Assert.IsTrue(results.ElementAt(0).Value == null); + } - [JsonProperty("GuidProperty")] - public Guid GuidProperty { get; set; } = Guid.NewGuid(); + [TestMethod] + public async Task OrbitServer_OrbitCosmosClient_Delete_NotFound() + { + var count = 1; - [JsonProperty("DateTimeProperty")] - public DateTime DateTimeProperty { get; set; } = DateTime.Now; + var syncables = new List>(); + for (var i = 0; i < count; i++) + { + syncables.Add(new ClientSyncInfo() + { + Operation = ClientOperationType.Delete, + ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Value = new TestClassA() { StringProperty = $"DeleteNotFound{i}", Pk = "test", IntProperty = 100, DoubleProperty = 999.99, }, + }); } - //public class TestClassA2 - //{ - // public string StringProperty { get; set; } + var results = await this._orbitDataClient.Sync(syncables); - // public string IntProperty { get; set; } + Assert.IsTrue(results.Count() == count); - // public double DoubleProperty { get; set; } + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.NotModified); + Assert.IsTrue(results.ElementAt(0).Value == null); + } - // public Guid GuidProperty { get; set; } = Guid.NewGuid(); + [TestMethod] + public async Task OrbitServer_OrbitCosmosClient_Its_Complicated() + { + var count = 10; + + // CREATE + var syncables = new List>(); + var item1 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer0", Pk = "test", IntProperty = 100, DoubleProperty = 1.00, }, }; + var item2 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer1", Pk = "test", IntProperty = 100, DoubleProperty = 1.00, }, }; + var item3 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer2", Pk = "test", IntProperty = 100, DoubleProperty = 1.00, }, }; + var item4 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer3", Pk = "test", IntProperty = 100, DoubleProperty = 1.00, }, }; + var item5 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer4", Pk = "test", IntProperty = 100, DoubleProperty = 1.00, }, }; + var item6 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer5", Pk = "test", IntProperty = 100, DoubleProperty = 1.00, }, }; + var item7 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer6", Pk = "test", IntProperty = 100, DoubleProperty = 1.00, }, }; + var item8 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer7", Pk = "test", IntProperty = 100, DoubleProperty = 1.00, }, }; + var item9 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer8", Pk = "test", IntProperty = 100, DoubleProperty = 1.00, }, }; + var item10 = new ClientSyncInfo() { Operation = ClientOperationType.Create, ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Value = new TestClassA() { StringProperty = $"UpdateNewer9", Pk = "test", IntProperty = 100, DoubleProperty = 1.00, }, }; + + syncables.Add(item1); + syncables.Add(item2); + syncables.Add(item3); + syncables.Add(item4); + syncables.Add(item5); + syncables.Add(item6); + syncables.Add(item7); + syncables.Add(item8); + syncables.Add(item9); + syncables.Add(item10); + + var results = await this._orbitDataClient.Sync(syncables); + + Assert.IsTrue(results.Count() == count); + Assert.IsTrue(results.All(x => x.Operation == ServerOperationType.Created)); + + // UPDATE + item1.ModifiedOn = item1.ModifiedOn - 1000; + item1.Value.GuidProperty = Guid.Empty; + item2.ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + item2.Value.GuidProperty = Guid.Empty; + item3.ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + item3.Value.GuidProperty = Guid.Empty; + item4.ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + item4.Value.GuidProperty = Guid.Empty; + item5.ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + item5.Value.GuidProperty = Guid.Empty; + item6.ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + item6.Value.GuidProperty = Guid.Empty; + item7.ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + item7.Value.GuidProperty = Guid.Empty; + item8.ModifiedOn = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + item8.Value.GuidProperty = Guid.Empty; + item9.Operation = ClientOperationType.Delete; + item10.ModifiedOn = item10.ModifiedOn - 1000; + item8.Value.GuidProperty = Guid.Empty; + + results = await this._orbitDataClient.Sync(syncables); + + Assert.IsTrue(results.Count() == count); + Assert.IsTrue(results.ElementAt(0).Operation == ServerOperationType.Updated); + Assert.IsTrue(results.ElementAt(0).Value.GuidProperty != Guid.Empty); + Assert.IsTrue(results.Skip(1).Take(7).All(x => x.Operation == ServerOperationType.Updated)); + Assert.IsTrue(results.Skip(1).Take(7).All(x => x.Value.GuidProperty == Guid.Empty)); + Assert.IsTrue(results.ElementAt(8).Operation == ServerOperationType.Deleted); + Assert.IsTrue(results.ElementAt(8).Value == null); + Assert.IsTrue(results.ElementAt(9).Operation == ServerOperationType.Updated); + Assert.IsTrue(results.ElementAt(9).Value.GuidProperty != Guid.Empty); + + item1.Operation = ClientOperationType.Delete; + item2.Operation = ClientOperationType.Delete; + item3.Operation = ClientOperationType.Delete; + item4.Operation = ClientOperationType.Delete; + item5.Operation = ClientOperationType.Delete; + item6.Operation = ClientOperationType.Delete; + item7.Operation = ClientOperationType.Delete; + item8.Operation = ClientOperationType.Delete; + item9.Operation = ClientOperationType.Delete; + item10.Operation = ClientOperationType.Delete; + + results = await this._orbitDataClient.Sync(syncables); + + Assert.IsTrue(results.Count() == count); + + Assert.IsTrue(results.Skip(0).Take(8).All(x => x.Operation == ServerOperationType.Deleted)); + Assert.IsTrue(results.ElementAt(8).Operation == ServerOperationType.NotModified); + Assert.IsTrue(results.ElementAt(9).Operation == ServerOperationType.Deleted); + } - // public DateTime DateTimeProperty { get; set; } = DateTime.Now; - //} + public class TestClassA + { + [JsonProperty(nameof(StringProperty))] + public string StringProperty { get; set; } + [JsonProperty("PK")] + public string Pk { get; set; } - class TestClassB - { - public string StringProperty { get; set; } + [JsonProperty(nameof(IntProperty))] + public int IntProperty { get; set; } - public double DoubleProperty { get; set; } - } + [JsonProperty(nameof(DoubleProperty))] + public double DoubleProperty { get; set; } - class TestClassC - { - public int IntProperty { get; set; } + [JsonProperty(nameof(GuidProperty))] + public Guid GuidProperty { get; set; } = Guid.NewGuid(); - public string DoubleProperty { get; set; } - } + [JsonProperty(nameof(DateTimeProperty))] + public DateTime DateTimeProperty { get; set; } = DateTime.Now; + } - class TestClassD - { - public float FloatProperty { get; set; } + private class TestClassB + { + public string StringProperty { get; set; } - public double DoubleProperty { get; set; } - } + public double DoubleProperty { get; set; } + } + + private class TestClassC + { + public int IntProperty { get; set; } + + public string DoubleProperty { get; set; } + } + + private class TestClassD + { + public float FloatProperty { get; set; } + + public double DoubleProperty { get; set; } } } diff --git a/EightBot.Orbit.Tests/ProcessingQueueTests.cs b/EightBot.Orbit.Tests/ProcessingQueueTests.cs deleted file mode 100644 index e6d88b8..0000000 --- a/EightBot.Orbit.Tests/ProcessingQueueTests.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Threading.Tasks; -using System.Collections.Generic; -using System.Threading; -using EightBot.Orbit.Client; - -namespace EightBot.Orbit.Tests -{ - [TestClass] - public class ProcessingQueueTests - { - [TestMethod] - public async Task ProcessingQueue_QueueAction_ShouldBeSuccessful() - { - var processingQueue = new ProcessingQueue(); - - await processingQueue.Queue(() => { }); - } - - [TestMethod] - public async Task ProcessingQueue_QueueFunc_ShouldBeSuccessful() - { - var processingQueue = new ProcessingQueue(); - - var result = await processingQueue.Queue(() => { return true; }); - - Assert.IsTrue(result); - } - - [TestMethod] - public async Task ProcessingQueue_QueueMultiple_ShouldFinishInOrder() - { - var processingQueue = new ProcessingQueue(); - - var count = 0; - - var results = new List>(); - - for (int i = 0; i < 100; i++) - { - results.Add(processingQueue.Queue(() => { return Interlocked.Increment(ref count); })); - } - - await Task.WhenAll(results); - - for (int i = 1; i < results.Count; i++) - { - var resultCurr = await results[i]; - var resultPrev = await results[i - 1]; - - Assert.IsTrue(resultCurr == resultPrev + 1); - } - } - - [TestMethod] - public async Task ProcessingQueue_QueueMultipleWithDifferingProcessingTimes_ShouldFinishInOrder() - { - var processingQueue = new ProcessingQueue(); - - var count = 0; - - var results = new List>(); - - var rng = new Random(12345); - - for (int i = 0; i < 100; i++) - { - results.Add( - processingQueue - .Queue( - async () => - { - await Task.Delay(rng.Next(10, 100)); - return Interlocked.Increment(ref count); - })); - } - - await Task.WhenAll(results); - - for (int i = 1; i < results.Count; i++) - { - var resultCurr = await results[i]; - var resultPrev = await results[i - 1]; - - Assert.IsTrue(resultCurr == resultPrev + 1); - } - } - } -} diff --git a/EightBot.Orbit.sln b/EightBot.Orbit.sln index a705c83..a26d9bd 100644 --- a/EightBot.Orbit.sln +++ b/EightBot.Orbit.sln @@ -1,175 +1,157 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.28917.181 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EightBot.Orbit.Core", "EightBot.Orbit.Core\EightBot.Orbit.Core.csproj", "{2CCB41DC-F189-403D-8CD4-0F202A96B69B}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EightBot.Orbit.Client", "EightBot.Orbit.Client\EightBot.Orbit.Client.csproj", "{84113539-CD8F-4747-8125-8885AF816BD2}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EightBot.Orbit.Tests", "EightBot.Orbit.Tests\EightBot.Orbit.Tests.csproj", "{80073C86-B8B3-48D7-AB5F-44CDB0458A10}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrbitSample.Android", "OrbitSample.Android\OrbitSample.Android.csproj", "{ED6FEFE0-5484-4B0F-98BB-2E1A69E577E5}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrbitSample.iOS", "OrbitSample.iOS\OrbitSample.iOS.csproj", "{ABC89AF8-92B0-423F-8173-A5DAB0FFF977}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrbitSample", "OrbitSample\OrbitSample.csproj", "{FA37D1E6-7F75-406C-99B1-328620A4CD89}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sample", "Sample", "{67753BE6-DEEC-4538-A60F-B04109E79B26}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{9447D525-A673-4D2D-B54A-72B90C476F1A}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{C88EB3D3-4551-4980-A52B-B786BCB83E5D}" - ProjectSection(SolutionItems) = preProject - build.cake = build.cake - build.ps1 = build.ps1 - cakebuild.sh = cakebuild.sh - OrbitClient.nuspec = OrbitClient.nuspec - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EightBot.Orbit.Server", "EightBot.Orbit.Server\EightBot.Orbit.Server.csproj", "{9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EightBot.Orbit.Server.Web", "EightBot.Orbit.Server.Web\EightBot.Orbit.Server.Web.csproj", "{CB509A7B-ABFA-40A5-B087-87A737C5F1A0}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrbitSample.Server.Web", "OrbitSample.Server.Web\OrbitSample.Server.Web.csproj", "{0DD16414-FB90-4B49-81BF-27E03F232BBE}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrbitSample.Models", "OrbitSample.Models\OrbitSample.Models.csproj", "{128D369D-2458-4BB8-A976-981B2A782C92}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|iPhone = Debug|iPhone - Debug|iPhoneSimulator = Debug|iPhoneSimulator - Release|Any CPU = Release|Any CPU - Release|iPhone = Release|iPhone - Release|iPhoneSimulator = Release|iPhoneSimulator - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Debug|iPhone.Build.0 = Debug|Any CPU - {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Release|Any CPU.Build.0 = Release|Any CPU - {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Release|iPhone.ActiveCfg = Release|Any CPU - {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Release|iPhone.Build.0 = Release|Any CPU - {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {84113539-CD8F-4747-8125-8885AF816BD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {84113539-CD8F-4747-8125-8885AF816BD2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {84113539-CD8F-4747-8125-8885AF816BD2}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {84113539-CD8F-4747-8125-8885AF816BD2}.Debug|iPhone.Build.0 = Debug|Any CPU - {84113539-CD8F-4747-8125-8885AF816BD2}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {84113539-CD8F-4747-8125-8885AF816BD2}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {84113539-CD8F-4747-8125-8885AF816BD2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {84113539-CD8F-4747-8125-8885AF816BD2}.Release|Any CPU.Build.0 = Release|Any CPU - {84113539-CD8F-4747-8125-8885AF816BD2}.Release|iPhone.ActiveCfg = Release|Any CPU - {84113539-CD8F-4747-8125-8885AF816BD2}.Release|iPhone.Build.0 = Release|Any CPU - {84113539-CD8F-4747-8125-8885AF816BD2}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {84113539-CD8F-4747-8125-8885AF816BD2}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Debug|Any CPU.Build.0 = Debug|Any CPU - {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Debug|iPhone.Build.0 = Debug|Any CPU - {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Release|Any CPU.ActiveCfg = Release|Any CPU - {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Release|iPhone.ActiveCfg = Release|Any CPU - {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Release|iPhone.Build.0 = Release|Any CPU - {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {ED6FEFE0-5484-4B0F-98BB-2E1A69E577E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ED6FEFE0-5484-4B0F-98BB-2E1A69E577E5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {ED6FEFE0-5484-4B0F-98BB-2E1A69E577E5}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {ED6FEFE0-5484-4B0F-98BB-2E1A69E577E5}.Debug|iPhone.Build.0 = Debug|Any CPU - {ED6FEFE0-5484-4B0F-98BB-2E1A69E577E5}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {ED6FEFE0-5484-4B0F-98BB-2E1A69E577E5}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {ED6FEFE0-5484-4B0F-98BB-2E1A69E577E5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ED6FEFE0-5484-4B0F-98BB-2E1A69E577E5}.Release|iPhone.ActiveCfg = Release|Any CPU - {ED6FEFE0-5484-4B0F-98BB-2E1A69E577E5}.Release|iPhone.Build.0 = Release|Any CPU - {ED6FEFE0-5484-4B0F-98BB-2E1A69E577E5}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {ED6FEFE0-5484-4B0F-98BB-2E1A69E577E5}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {ABC89AF8-92B0-423F-8173-A5DAB0FFF977}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator - {ABC89AF8-92B0-423F-8173-A5DAB0FFF977}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator - {ABC89AF8-92B0-423F-8173-A5DAB0FFF977}.Debug|iPhone.ActiveCfg = Debug|iPhone - {ABC89AF8-92B0-423F-8173-A5DAB0FFF977}.Debug|iPhone.Build.0 = Debug|iPhone - {ABC89AF8-92B0-423F-8173-A5DAB0FFF977}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator - {ABC89AF8-92B0-423F-8173-A5DAB0FFF977}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator - {ABC89AF8-92B0-423F-8173-A5DAB0FFF977}.Release|Any CPU.ActiveCfg = Release|iPhoneSimulator - {ABC89AF8-92B0-423F-8173-A5DAB0FFF977}.Release|iPhone.ActiveCfg = Release|iPhoneSimulator - {ABC89AF8-92B0-423F-8173-A5DAB0FFF977}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator - {ABC89AF8-92B0-423F-8173-A5DAB0FFF977}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator - {FA37D1E6-7F75-406C-99B1-328620A4CD89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FA37D1E6-7F75-406C-99B1-328620A4CD89}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FA37D1E6-7F75-406C-99B1-328620A4CD89}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {FA37D1E6-7F75-406C-99B1-328620A4CD89}.Debug|iPhone.Build.0 = Debug|Any CPU - {FA37D1E6-7F75-406C-99B1-328620A4CD89}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {FA37D1E6-7F75-406C-99B1-328620A4CD89}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {FA37D1E6-7F75-406C-99B1-328620A4CD89}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FA37D1E6-7F75-406C-99B1-328620A4CD89}.Release|iPhone.ActiveCfg = Release|Any CPU - {FA37D1E6-7F75-406C-99B1-328620A4CD89}.Release|iPhone.Build.0 = Release|Any CPU - {FA37D1E6-7F75-406C-99B1-328620A4CD89}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {FA37D1E6-7F75-406C-99B1-328620A4CD89}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Debug|iPhone.Build.0 = Debug|Any CPU - {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Release|Any CPU.Build.0 = Release|Any CPU - {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Release|iPhone.ActiveCfg = Release|Any CPU - {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Release|iPhone.Build.0 = Release|Any CPU - {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Debug|iPhone.Build.0 = Debug|Any CPU - {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Release|Any CPU.Build.0 = Release|Any CPU - {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Release|iPhone.ActiveCfg = Release|Any CPU - {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Release|iPhone.Build.0 = Release|Any CPU - {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Debug|iPhone.Build.0 = Debug|Any CPU - {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Release|iPhone.ActiveCfg = Release|Any CPU - {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Release|iPhone.Build.0 = Release|Any CPU - {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {128D369D-2458-4BB8-A976-981B2A782C92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {128D369D-2458-4BB8-A976-981B2A782C92}.Debug|Any CPU.Build.0 = Debug|Any CPU - {128D369D-2458-4BB8-A976-981B2A782C92}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {128D369D-2458-4BB8-A976-981B2A782C92}.Debug|iPhone.Build.0 = Debug|Any CPU - {128D369D-2458-4BB8-A976-981B2A782C92}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {128D369D-2458-4BB8-A976-981B2A782C92}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {128D369D-2458-4BB8-A976-981B2A782C92}.Release|Any CPU.ActiveCfg = Release|Any CPU - {128D369D-2458-4BB8-A976-981B2A782C92}.Release|iPhone.ActiveCfg = Release|Any CPU - {128D369D-2458-4BB8-A976-981B2A782C92}.Release|iPhone.Build.0 = Release|Any CPU - {128D369D-2458-4BB8-A976-981B2A782C92}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {128D369D-2458-4BB8-A976-981B2A782C92}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {80073C86-B8B3-48D7-AB5F-44CDB0458A10} = {9447D525-A673-4D2D-B54A-72B90C476F1A} - {ED6FEFE0-5484-4B0F-98BB-2E1A69E577E5} = {67753BE6-DEEC-4538-A60F-B04109E79B26} - {ABC89AF8-92B0-423F-8173-A5DAB0FFF977} = {67753BE6-DEEC-4538-A60F-B04109E79B26} - {FA37D1E6-7F75-406C-99B1-328620A4CD89} = {67753BE6-DEEC-4538-A60F-B04109E79B26} - {0DD16414-FB90-4B49-81BF-27E03F232BBE} = {67753BE6-DEEC-4538-A60F-B04109E79B26} - {128D369D-2458-4BB8-A976-981B2A782C92} = {67753BE6-DEEC-4538-A60F-B04109E79B26} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {7A6D9CDF-8DFD-46F6-9856-A6705440C736} - EndGlobalSection -EndGlobal +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28917.181 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EightBot.Orbit.Core", "EightBot.Orbit.Core\EightBot.Orbit.Core.csproj", "{2CCB41DC-F189-403D-8CD4-0F202A96B69B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EightBot.Orbit.Client", "EightBot.Orbit.Client\EightBot.Orbit.Client.csproj", "{84113539-CD8F-4747-8125-8885AF816BD2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EightBot.Orbit.Tests", "EightBot.Orbit.Tests\EightBot.Orbit.Tests.csproj", "{80073C86-B8B3-48D7-AB5F-44CDB0458A10}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sample", "Sample", "{67753BE6-DEEC-4538-A60F-B04109E79B26}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{9447D525-A673-4D2D-B54A-72B90C476F1A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EightBot.Orbit.Server", "EightBot.Orbit.Server\EightBot.Orbit.Server.csproj", "{9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EightBot.Orbit.Server.Web", "EightBot.Orbit.Server.Web\EightBot.Orbit.Server.Web.csproj", "{CB509A7B-ABFA-40A5-B087-87A737C5F1A0}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrbitSample.Server.Web", "OrbitSample.Server.Web\OrbitSample.Server.Web.csproj", "{0DD16414-FB90-4B49-81BF-27E03F232BBE}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrbitSample.Models", "OrbitSample.Models\OrbitSample.Models.csproj", "{128D369D-2458-4BB8-A976-981B2A782C92}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrbitMauiSample", "OrbitMauiSample\OrbitMauiSample.csproj", "{64FFE069-FDA8-4664-938B-B6B265863208}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "[ Solution ]", "[ Solution ]", "{89923DA1-FA5F-416C-AD3F-CEC2A6E6C9D4}" + ProjectSection(SolutionItems) = preProject + README.md = README.md + .gitignore = .gitignore + .editorconfig = .editorconfig + .gitattributes = .gitattributes + Directory.build.props = Directory.build.props + LICENSE = LICENSE + stylecop.json = stylecop.json + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "[ Build ]", "[ Build ]", "{2A776942-0EEB-47E0-B222-481349732CDE}" + ProjectSection(SolutionItems) = preProject + .github\workflows\nuget-publish.yml = .github\workflows\nuget-publish.yml + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|iPhone = Debug|iPhone + Debug|iPhoneSimulator = Debug|iPhoneSimulator + Release|Any CPU = Release|Any CPU + Release|iPhone = Release|iPhone + Release|iPhoneSimulator = Release|iPhoneSimulator + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Debug|iPhone.Build.0 = Debug|Any CPU + {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Release|Any CPU.Build.0 = Release|Any CPU + {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Release|iPhone.ActiveCfg = Release|Any CPU + {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Release|iPhone.Build.0 = Release|Any CPU + {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {2CCB41DC-F189-403D-8CD4-0F202A96B69B}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {84113539-CD8F-4747-8125-8885AF816BD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {84113539-CD8F-4747-8125-8885AF816BD2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {84113539-CD8F-4747-8125-8885AF816BD2}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {84113539-CD8F-4747-8125-8885AF816BD2}.Debug|iPhone.Build.0 = Debug|Any CPU + {84113539-CD8F-4747-8125-8885AF816BD2}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {84113539-CD8F-4747-8125-8885AF816BD2}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {84113539-CD8F-4747-8125-8885AF816BD2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {84113539-CD8F-4747-8125-8885AF816BD2}.Release|Any CPU.Build.0 = Release|Any CPU + {84113539-CD8F-4747-8125-8885AF816BD2}.Release|iPhone.ActiveCfg = Release|Any CPU + {84113539-CD8F-4747-8125-8885AF816BD2}.Release|iPhone.Build.0 = Release|Any CPU + {84113539-CD8F-4747-8125-8885AF816BD2}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {84113539-CD8F-4747-8125-8885AF816BD2}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Debug|Any CPU.Build.0 = Debug|Any CPU + {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Debug|iPhone.Build.0 = Debug|Any CPU + {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Release|Any CPU.ActiveCfg = Release|Any CPU + {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Release|iPhone.ActiveCfg = Release|Any CPU + {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Release|iPhone.Build.0 = Release|Any CPU + {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {80073C86-B8B3-48D7-AB5F-44CDB0458A10}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Debug|iPhone.Build.0 = Debug|Any CPU + {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Release|Any CPU.Build.0 = Release|Any CPU + {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Release|iPhone.ActiveCfg = Release|Any CPU + {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Release|iPhone.Build.0 = Release|Any CPU + {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {9ED191CF-CC8A-4122-B8E5-EBA61FE12E33}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Debug|iPhone.Build.0 = Debug|Any CPU + {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Release|Any CPU.Build.0 = Release|Any CPU + {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Release|iPhone.ActiveCfg = Release|Any CPU + {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Release|iPhone.Build.0 = Release|Any CPU + {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {CB509A7B-ABFA-40A5-B087-87A737C5F1A0}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Debug|iPhone.Build.0 = Debug|Any CPU + {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Release|iPhone.ActiveCfg = Release|Any CPU + {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Release|iPhone.Build.0 = Release|Any CPU + {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {0DD16414-FB90-4B49-81BF-27E03F232BBE}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {128D369D-2458-4BB8-A976-981B2A782C92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {128D369D-2458-4BB8-A976-981B2A782C92}.Debug|Any CPU.Build.0 = Debug|Any CPU + {128D369D-2458-4BB8-A976-981B2A782C92}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {128D369D-2458-4BB8-A976-981B2A782C92}.Debug|iPhone.Build.0 = Debug|Any CPU + {128D369D-2458-4BB8-A976-981B2A782C92}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {128D369D-2458-4BB8-A976-981B2A782C92}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {128D369D-2458-4BB8-A976-981B2A782C92}.Release|Any CPU.ActiveCfg = Release|Any CPU + {128D369D-2458-4BB8-A976-981B2A782C92}.Release|iPhone.ActiveCfg = Release|Any CPU + {128D369D-2458-4BB8-A976-981B2A782C92}.Release|iPhone.Build.0 = Release|Any CPU + {128D369D-2458-4BB8-A976-981B2A782C92}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {128D369D-2458-4BB8-A976-981B2A782C92}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {64FFE069-FDA8-4664-938B-B6B265863208}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {64FFE069-FDA8-4664-938B-B6B265863208}.Debug|Any CPU.Build.0 = Debug|Any CPU + {64FFE069-FDA8-4664-938B-B6B265863208}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {64FFE069-FDA8-4664-938B-B6B265863208}.Debug|iPhone.Build.0 = Debug|Any CPU + {64FFE069-FDA8-4664-938B-B6B265863208}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {64FFE069-FDA8-4664-938B-B6B265863208}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {64FFE069-FDA8-4664-938B-B6B265863208}.Release|Any CPU.ActiveCfg = Release|Any CPU + {64FFE069-FDA8-4664-938B-B6B265863208}.Release|Any CPU.Build.0 = Release|Any CPU + {64FFE069-FDA8-4664-938B-B6B265863208}.Release|iPhone.ActiveCfg = Release|Any CPU + {64FFE069-FDA8-4664-938B-B6B265863208}.Release|iPhone.Build.0 = Release|Any CPU + {64FFE069-FDA8-4664-938B-B6B265863208}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {64FFE069-FDA8-4664-938B-B6B265863208}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {80073C86-B8B3-48D7-AB5F-44CDB0458A10} = {9447D525-A673-4D2D-B54A-72B90C476F1A} + {0DD16414-FB90-4B49-81BF-27E03F232BBE} = {67753BE6-DEEC-4538-A60F-B04109E79B26} + {128D369D-2458-4BB8-A976-981B2A782C92} = {67753BE6-DEEC-4538-A60F-B04109E79B26} + {64FFE069-FDA8-4664-938B-B6B265863208} = {67753BE6-DEEC-4538-A60F-B04109E79B26} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7A6D9CDF-8DFD-46F6-9856-A6705440C736} + EndGlobalSection +EndGlobal diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1d0b957 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Eight-Bot + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/OrbitMauiSample/App.xaml b/OrbitMauiSample/App.xaml new file mode 100644 index 0000000..5f40f52 --- /dev/null +++ b/OrbitMauiSample/App.xaml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/OrbitMauiSample/App.xaml.cs b/OrbitMauiSample/App.xaml.cs new file mode 100644 index 0000000..afa839d --- /dev/null +++ b/OrbitMauiSample/App.xaml.cs @@ -0,0 +1,14 @@ +namespace OrbitMauiSample; + +public partial class App : Application +{ + public App() + { + InitializeComponent(); + } + + protected override Window CreateWindow(IActivationState? activationState) + { + return new Window(new AppShell()); + } +} \ No newline at end of file diff --git a/OrbitMauiSample/AppShell.xaml b/OrbitMauiSample/AppShell.xaml new file mode 100644 index 0000000..c87a3e5 --- /dev/null +++ b/OrbitMauiSample/AppShell.xaml @@ -0,0 +1,14 @@ + + + + + + diff --git a/OrbitMauiSample/AppShell.xaml.cs b/OrbitMauiSample/AppShell.xaml.cs new file mode 100644 index 0000000..7c417c8 --- /dev/null +++ b/OrbitMauiSample/AppShell.xaml.cs @@ -0,0 +1,9 @@ +namespace OrbitMauiSample; + +public partial class AppShell : Shell +{ + public AppShell() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/OrbitMauiSample/GlobalXmlns.cs b/OrbitMauiSample/GlobalXmlns.cs new file mode 100644 index 0000000..0592f8d --- /dev/null +++ b/OrbitMauiSample/GlobalXmlns.cs @@ -0,0 +1,2 @@ +[assembly: XmlnsDefinition("http://schemas.microsoft.com/dotnet/maui/global", "OrbitMauiSample")] +[assembly: XmlnsDefinition("http://schemas.microsoft.com/dotnet/maui/global", "OrbitMauiSample.Pages")] \ No newline at end of file diff --git a/OrbitMauiSample/MainPage.xaml b/OrbitMauiSample/MainPage.xaml new file mode 100644 index 0000000..582014f --- /dev/null +++ b/OrbitMauiSample/MainPage.xaml @@ -0,0 +1,45 @@ + + + + + + + +