Merge branch 'feature/backend-refactor' into feature/files-mapping
This commit is contained in:
commit
26066ccb7f
160
.editorconfig
160
.editorconfig
@ -29,34 +29,30 @@ dotnet_style_qualification_for_method = false:silent
|
|||||||
dotnet_style_qualification_for_property = false:silent
|
dotnet_style_qualification_for_property = false:silent
|
||||||
|
|
||||||
# Language keywords vs BCL types preferences
|
# Language keywords vs BCL types preferences
|
||||||
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
|
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
|
||||||
dotnet_style_predefined_type_for_member_access = true:warning
|
dotnet_style_predefined_type_for_member_access = true:silent
|
||||||
|
|
||||||
# Parentheses preferences
|
# Parentheses preferences
|
||||||
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
|
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_binary_operators = always_for_clarity:silent
|
||||||
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
|
dotnet_style_parentheses_in_other_operators = always_for_clarity:silent
|
||||||
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
|
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
|
||||||
|
|
||||||
# Modifier preferences
|
# Modifier preferences
|
||||||
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
|
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
|
||||||
|
|
||||||
# Expression-level preferences
|
# Expression-level preferences
|
||||||
dotnet_style_coalesce_expression = true:warning
|
dotnet_style_object_initializer = true:suggestion
|
||||||
dotnet_style_collection_initializer = true:warning
|
dotnet_style_collection_initializer = true:suggestion
|
||||||
dotnet_style_explicit_tuple_names = true:warning
|
dotnet_style_explicit_tuple_names = true:suggestion
|
||||||
dotnet_style_null_propagation = true:warning
|
dotnet_style_null_propagation = true:suggestion
|
||||||
dotnet_style_object_initializer = true:warning
|
dotnet_style_coalesce_expression = true:suggestion
|
||||||
dotnet_style_operator_placement_when_wrapping = beginning_of_line
|
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent
|
||||||
dotnet_style_prefer_auto_properties = true:warning
|
dotnet_style_prefer_inferred_tuple_names = true:suggestion
|
||||||
dotnet_style_prefer_compound_assignment = true:warning
|
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
|
||||||
|
dotnet_style_prefer_auto_properties = true:silent
|
||||||
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
|
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
|
||||||
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
|
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
|
||||||
dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning
|
|
||||||
dotnet_style_prefer_inferred_tuple_names = true:warning
|
|
||||||
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
|
|
||||||
dotnet_style_prefer_simplified_boolean_expressions = true:warning
|
|
||||||
dotnet_style_prefer_simplified_interpolation = true:suggestion
|
|
||||||
|
|
||||||
# Field preferences
|
# Field preferences
|
||||||
dotnet_style_readonly_field = true:warning
|
dotnet_style_readonly_field = true:warning
|
||||||
@ -64,6 +60,13 @@ dotnet_style_readonly_field = true:warning
|
|||||||
# Parameter preferences
|
# Parameter preferences
|
||||||
dotnet_code_quality_unused_parameters = all:warning
|
dotnet_code_quality_unused_parameters = all:warning
|
||||||
|
|
||||||
|
# Suppression preferences
|
||||||
|
dotnet_remove_unnecessary_suppression_exclusions = none
|
||||||
|
|
||||||
|
# New line preferences
|
||||||
|
dotnet_style_allow_multiple_blank_lines_experimental = false
|
||||||
|
dotnet_style_allow_statement_immediately_after_block_experimental = false
|
||||||
|
|
||||||
#### C# Coding Conventions ####
|
#### C# Coding Conventions ####
|
||||||
|
|
||||||
# var preferences
|
# var preferences
|
||||||
@ -72,44 +75,48 @@ csharp_style_var_for_built_in_types = true:warning
|
|||||||
csharp_style_var_when_type_is_apparent = true:warning
|
csharp_style_var_when_type_is_apparent = true:warning
|
||||||
|
|
||||||
# Expression-bodied members
|
# Expression-bodied members
|
||||||
csharp_style_expression_bodied_accessors = when_on_single_line:suggestion
|
csharp_style_expression_bodied_methods = false:silent
|
||||||
csharp_style_expression_bodied_constructors = false:silent
|
csharp_style_expression_bodied_constructors = false:silent
|
||||||
csharp_style_expression_bodied_indexers = when_on_single_line:suggestion
|
|
||||||
csharp_style_expression_bodied_lambdas = when_on_single_line:suggestion
|
|
||||||
csharp_style_expression_bodied_local_functions = when_on_single_line:suggestion
|
|
||||||
csharp_style_expression_bodied_methods = false:suggestion
|
|
||||||
csharp_style_expression_bodied_operators = false:silent
|
csharp_style_expression_bodied_operators = false:silent
|
||||||
csharp_style_expression_bodied_properties = when_on_single_line:suggestion
|
csharp_style_expression_bodied_properties = true:silent
|
||||||
|
csharp_style_expression_bodied_indexers = true:silent
|
||||||
|
csharp_style_expression_bodied_accessors = true:silent
|
||||||
|
|
||||||
# Pattern matching preferences
|
# Pattern matching preferences
|
||||||
csharp_style_pattern_matching_over_as_with_null_check = true:warning
|
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
|
||||||
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
|
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
|
||||||
csharp_style_prefer_switch_expression = true:suggestion
|
|
||||||
|
|
||||||
# Null-checking preferences
|
# Null-checking preferences
|
||||||
csharp_style_conditional_delegate_call = true:warning
|
csharp_style_conditional_delegate_call = true:suggestion
|
||||||
|
|
||||||
# Modifier preferences
|
# Modifier preferences
|
||||||
csharp_prefer_static_local_function = true:suggestion
|
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
|
||||||
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent
|
|
||||||
|
|
||||||
# Code-block preferences
|
# Code-block preferences
|
||||||
csharp_prefer_braces = true:silent
|
csharp_prefer_braces = true:warning
|
||||||
csharp_prefer_simple_using_statement = true:suggestion
|
csharp_prefer_simple_using_statement = false:silent
|
||||||
|
csharp_style_namespace_declarations = file_scoped:warning
|
||||||
|
|
||||||
# Expression-level preferences
|
# Expression-level preferences
|
||||||
csharp_prefer_simple_default_expression = true:warning
|
csharp_prefer_simple_default_expression = false:silent
|
||||||
csharp_style_deconstructed_variable_declaration = true:warning
|
csharp_style_deconstructed_variable_declaration = true:suggestion
|
||||||
csharp_style_inlined_variable_declaration = true:warning
|
csharp_style_implicit_object_creation_when_type_is_apparent = false:suggestion
|
||||||
csharp_style_pattern_local_over_anonymous_function = true:warning
|
csharp_style_inlined_variable_declaration = true:suggestion
|
||||||
csharp_style_prefer_index_operator = true:warning
|
csharp_style_pattern_local_over_anonymous_function = true:suggestion
|
||||||
csharp_style_prefer_range_operator = true:warning
|
csharp_style_prefer_index_operator = false:suggestion
|
||||||
csharp_style_throw_expression = true:warning
|
csharp_style_prefer_null_check_over_type_check = true:suggestion
|
||||||
|
csharp_style_prefer_range_operator = false:suggestion
|
||||||
|
csharp_style_throw_expression = true:suggestion
|
||||||
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
|
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
|
||||||
csharp_style_unused_value_expression_statement_preference = discard_variable:suggestion
|
csharp_style_unused_value_expression_statement_preference = discard_variable:suggestion
|
||||||
|
|
||||||
# 'using' directive preferences
|
# 'using' directive preferences
|
||||||
csharp_using_directive_placement = outside_namespace:silent
|
csharp_using_directive_placement = outside_namespace:warning
|
||||||
|
|
||||||
|
# New line preferences
|
||||||
|
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false:silent
|
||||||
|
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:silent
|
||||||
|
csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
|
||||||
|
|
||||||
#### C# Formatting Rules ####
|
#### C# Formatting Rules ####
|
||||||
|
|
||||||
@ -126,7 +133,7 @@ csharp_new_line_between_query_expression_clauses = true
|
|||||||
csharp_indent_block_contents = true
|
csharp_indent_block_contents = true
|
||||||
csharp_indent_braces = false
|
csharp_indent_braces = false
|
||||||
csharp_indent_case_contents = true
|
csharp_indent_case_contents = true
|
||||||
csharp_indent_case_contents_when_block = false
|
csharp_indent_case_contents_when_block = true
|
||||||
csharp_indent_labels = one_less_than_current
|
csharp_indent_labels = one_less_than_current
|
||||||
csharp_indent_switch_labels = true
|
csharp_indent_switch_labels = true
|
||||||
|
|
||||||
@ -162,32 +169,32 @@ csharp_preserve_single_line_statements = true
|
|||||||
|
|
||||||
# Naming rules
|
# Naming rules
|
||||||
|
|
||||||
|
dotnet_naming_rule.private_or_internal_field_should_be_begin_with_underscore.severity = warning
|
||||||
|
dotnet_naming_rule.private_or_internal_field_should_be_begin_with_underscore.symbols = private_or_internal_field
|
||||||
|
dotnet_naming_rule.private_or_internal_field_should_be_begin_with_underscore.style = begin_with_underscore
|
||||||
|
|
||||||
dotnet_naming_rule.interface_should_be_begins_with_i.severity = warning
|
dotnet_naming_rule.interface_should_be_begins_with_i.severity = warning
|
||||||
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
|
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
|
||||||
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
|
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
|
||||||
|
|
||||||
dotnet_naming_rule.types_should_be_pascal_case.severity = warning
|
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
|
||||||
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
|
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
|
||||||
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
|
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
|
||||||
|
|
||||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = warning
|
|
||||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
|
|
||||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
|
|
||||||
|
|
||||||
# Symbol specifications
|
# Symbol specifications
|
||||||
|
|
||||||
dotnet_naming_symbols.interface.applicable_kinds = interface
|
dotnet_naming_symbols.interface.applicable_kinds = interface
|
||||||
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||||
dotnet_naming_symbols.interface.required_modifiers =
|
dotnet_naming_symbols.interface.required_modifiers =
|
||||||
|
|
||||||
|
dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field
|
||||||
|
dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private, private_protected
|
||||||
|
dotnet_naming_symbols.private_or_internal_field.required_modifiers =
|
||||||
|
|
||||||
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
|
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
|
||||||
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||||
dotnet_naming_symbols.types.required_modifiers =
|
dotnet_naming_symbols.types.required_modifiers =
|
||||||
|
|
||||||
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
|
|
||||||
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
|
||||||
dotnet_naming_symbols.non_field_members.required_modifiers =
|
|
||||||
|
|
||||||
# Naming styles
|
# Naming styles
|
||||||
|
|
||||||
dotnet_naming_style.pascal_case.required_prefix =
|
dotnet_naming_style.pascal_case.required_prefix =
|
||||||
@ -200,5 +207,58 @@ dotnet_naming_style.begins_with_i.required_suffix =
|
|||||||
dotnet_naming_style.begins_with_i.word_separator =
|
dotnet_naming_style.begins_with_i.word_separator =
|
||||||
dotnet_naming_style.begins_with_i.capitalization = pascal_case
|
dotnet_naming_style.begins_with_i.capitalization = pascal_case
|
||||||
|
|
||||||
# Default severity for analyzer diagnostics with category 'Style'
|
dotnet_naming_style.begin_with_underscore.required_prefix = _
|
||||||
dotnet_analyzer_diagnostic.category-Style.severity = silent
|
dotnet_naming_style.begin_with_underscore.required_suffix =
|
||||||
|
dotnet_naming_style.begin_with_underscore.word_separator =
|
||||||
|
dotnet_naming_style.begin_with_underscore.capitalization = camel_case
|
||||||
|
csharp_style_expression_bodied_lambdas = true:silent
|
||||||
|
csharp_style_expression_bodied_local_functions = false:silent
|
||||||
|
csharp_style_prefer_local_over_anonymous_function = true:suggestion
|
||||||
|
csharp_style_prefer_tuple_swap = true:suggestion
|
||||||
|
csharp_prefer_static_local_function = true:suggestion
|
||||||
|
csharp_style_prefer_switch_expression = true:suggestion
|
||||||
|
csharp_style_prefer_pattern_matching = true:silent
|
||||||
|
csharp_style_prefer_not_pattern = true:suggestion
|
||||||
|
csharp_style_prefer_extended_property_pattern = true:suggestion
|
||||||
|
dotnet_diagnostic.CA1001.severity = warning
|
||||||
|
dotnet_diagnostic.CA1805.severity = warning
|
||||||
|
dotnet_diagnostic.CA1841.severity = warning
|
||||||
|
|
||||||
|
[*.{cs,vb}]
|
||||||
|
dotnet_style_operator_placement_when_wrapping = beginning_of_line
|
||||||
|
tab_width = 4
|
||||||
|
indent_size = 4
|
||||||
|
end_of_line = crlf
|
||||||
|
dotnet_style_coalesce_expression = true:suggestion
|
||||||
|
dotnet_style_null_propagation = true:suggestion
|
||||||
|
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent
|
||||||
|
dotnet_style_prefer_auto_properties = true:silent
|
||||||
|
dotnet_style_object_initializer = true:suggestion
|
||||||
|
dotnet_style_collection_initializer = true:suggestion
|
||||||
|
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
|
||||||
|
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
|
||||||
|
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
|
||||||
|
dotnet_style_explicit_tuple_names = true:suggestion
|
||||||
|
dotnet_style_prefer_inferred_tuple_names = true:suggestion
|
||||||
|
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
|
||||||
|
dotnet_style_prefer_compound_assignment = true:suggestion
|
||||||
|
dotnet_style_prefer_simplified_interpolation = true:suggestion
|
||||||
|
dotnet_style_namespace_match_folder = true:suggestion
|
||||||
|
dotnet_style_readonly_field = true:warning
|
||||||
|
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
|
||||||
|
dotnet_style_predefined_type_for_member_access = true:silent
|
||||||
|
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
|
||||||
|
dotnet_style_allow_multiple_blank_lines_experimental = false:silent
|
||||||
|
dotnet_style_allow_statement_immediately_after_block_experimental = false:silent
|
||||||
|
dotnet_code_quality_unused_parameters = all:warning
|
||||||
|
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_relational_binary_operators = always_for_clarity:silent
|
||||||
|
dotnet_style_parentheses_in_other_operators = always_for_clarity:silent
|
||||||
|
dotnet_style_qualification_for_field = false:silent
|
||||||
|
dotnet_style_qualification_for_property = false:silent
|
||||||
|
dotnet_style_qualification_for_method = false:silent
|
||||||
|
dotnet_style_qualification_for_event = false:silent
|
||||||
|
dotnet_diagnostic.CA1715.severity = warning
|
||||||
|
dotnet_diagnostic.CA1716.severity = silent
|
||||||
|
dotnet_diagnostic.CA5397.severity = warning
|
@ -3,6 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
|
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||||
|
@ -85,18 +85,18 @@ public sealed class ApiDateTime : IComparable<ApiDateTime>, IComparable
|
|||||||
|
|
||||||
public static ApiDateTime Parse(string data, TimeZoneInfo tz, TenantManager tenantManager, TimeZoneConverter timeZoneConverter)
|
public static ApiDateTime Parse(string data, TimeZoneInfo tz, TenantManager tenantManager, TimeZoneConverter timeZoneConverter)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(data)) throw new ArgumentNullException(nameof(data));
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(data);
|
||||||
|
|
||||||
var offsetPart = data.Substring(data.Length - 6, 6);
|
var offsetPart = data.Substring(data.Length - 6, 6);
|
||||||
if (DateTime.TryParseExact(data, Formats, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out var dateTime))
|
if (DateTime.TryParseExact(data, Formats, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out var dateTime))
|
||||||
{
|
{
|
||||||
//Parse time
|
//Parse time
|
||||||
var tzOffset = TimeSpan.Zero;
|
var tzOffset = TimeSpan.Zero;
|
||||||
if (offsetPart.Contains(':') && TimeSpan.TryParse(offsetPart.TrimStart('+'), out tzOffset))
|
if (offsetPart.Contains(':') && TimeSpan.TryParse(offsetPart.TrimStart('+'), out tzOffset))
|
||||||
{
|
{
|
||||||
return new ApiDateTime(dateTime, tzOffset);
|
return new ApiDateTime(dateTime, tzOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.EndsWith("Z", true, CultureInfo.InvariantCulture))
|
if (!data.EndsWith("Z", true, CultureInfo.InvariantCulture))
|
||||||
{
|
{
|
||||||
if (tz == null)
|
if (tz == null)
|
||||||
@ -139,7 +139,7 @@ public sealed class ApiDateTime : IComparable<ApiDateTime>, IComparable
|
|||||||
if (value.Kind == DateTimeKind.Unspecified)
|
if (value.Kind == DateTimeKind.Unspecified)
|
||||||
{
|
{
|
||||||
value = new DateTime(value.Ticks, DateTimeKind.Utc); //Assume it's utc
|
value = new DateTime(value.Ticks, DateTimeKind.Utc); //Assume it's utc
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.Kind == DateTimeKind.Utc)
|
if (value.Kind == DateTimeKind.Utc)
|
||||||
{
|
{
|
||||||
@ -166,8 +166,8 @@ public sealed class ApiDateTime : IComparable<ApiDateTime>, IComparable
|
|||||||
private string ToRoundTripString(DateTime date, TimeSpan offset)
|
private string ToRoundTripString(DateTime date, TimeSpan offset)
|
||||||
{
|
{
|
||||||
var dateString = date.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffff", CultureInfo.InvariantCulture);
|
var dateString = date.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffff", CultureInfo.InvariantCulture);
|
||||||
var offsetString = offset.Ticks == 0
|
var offsetString = offset.Ticks == 0
|
||||||
? "Z" : ((offset < TimeSpan.Zero)
|
? "Z" : ((offset < TimeSpan.Zero)
|
||||||
? "-" : "+") + offset.ToString("hh\\:mm", CultureInfo.InvariantCulture);
|
? "-" : "+") + offset.ToString("hh\\:mm", CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
return dateString + offsetString;
|
return dateString + offsetString;
|
||||||
@ -277,9 +277,9 @@ public sealed class ApiDateTime : IComparable<ApiDateTime>, IComparable
|
|||||||
|
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
{
|
{
|
||||||
if (obj is null) return false;
|
if (obj is null) return false;
|
||||||
if (ReferenceEquals(this, obj)) return true;
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
if (!(obj is ApiDateTime)) return false;
|
if (!(obj is ApiDateTime)) return false;
|
||||||
return Equals((ApiDateTime)obj);
|
return Equals((ApiDateTime)obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,7 +369,7 @@ public class ApiDateTimeConverter : System.Text.Json.Serialization.JsonConverter
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (DateTime.TryParseExact(reader.GetString(), ApiDateTime.Formats,
|
if (DateTime.TryParseExact(reader.GetString(), ApiDateTime.Formats,
|
||||||
CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out var dateTime))
|
CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out var dateTime))
|
||||||
{
|
{
|
||||||
return new ApiDateTime(dateTime, TimeSpan.Zero);
|
return new ApiDateTime(dateTime, TimeSpan.Zero);
|
||||||
@ -377,7 +377,7 @@ public class ApiDateTimeConverter : System.Text.Json.Serialization.JsonConverter
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new ApiDateTime();
|
return new ApiDateTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
global using System;
|
global using System.ComponentModel;
|
||||||
global using System.Collections.Generic;
|
global using System.Globalization;
|
||||||
global using System.ComponentModel;
|
|
||||||
global using System.Globalization;
|
|
||||||
global using System.Linq;
|
|
||||||
global using System.Linq.Expressions;
|
global using System.Linq.Expressions;
|
||||||
global using System.Net;
|
global using System.Net;
|
||||||
global using System.Net.Http;
|
|
||||||
global using System.Reflection;
|
global using System.Reflection;
|
||||||
global using System.Runtime.Serialization;
|
global using System.Runtime.Serialization;
|
||||||
global using System.Security;
|
global using System.Security;
|
||||||
@ -14,8 +12,7 @@ global using System.Security.Claims;
|
|||||||
global using System.Text.Encodings.Web;
|
global using System.Text.Encodings.Web;
|
||||||
global using System.Text.Json;
|
global using System.Text.Json;
|
||||||
global using System.Text.Json.Serialization;
|
global using System.Text.Json.Serialization;
|
||||||
global using System.Threading;
|
|
||||||
global using System.Threading.Tasks;
|
|
||||||
global using System.Web;
|
global using System.Web;
|
||||||
global using System.Xml.Linq;
|
global using System.Xml.Linq;
|
||||||
|
|
||||||
|
@ -1,116 +1,115 @@
|
|||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* (c) Copyright Ascensio System Limited 2010-2018
|
* (c) Copyright Ascensio System Limited 2010-2018
|
||||||
*
|
*
|
||||||
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
||||||
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
||||||
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
||||||
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
||||||
*
|
*
|
||||||
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
||||||
*
|
*
|
||||||
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
||||||
*
|
*
|
||||||
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
||||||
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
||||||
*
|
*
|
||||||
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
||||||
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
||||||
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
||||||
* in every copy of the program you distribute.
|
* in every copy of the program you distribute.
|
||||||
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace ASC.Web.Api.Models;
|
namespace ASC.Web.Api.Models;
|
||||||
|
|
||||||
public class EmployeeWraper
|
public class EmployeeDto
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public string DisplayName { get; set; }
|
public string DisplayName { get; set; }
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
public string AvatarSmall { get; set; }
|
public string AvatarSmall { get; set; }
|
||||||
public string ProfileUrl { get; set; }
|
public string ProfileUrl { get; set; }
|
||||||
|
|
||||||
public static EmployeeWraper GetSample()
|
public static EmployeeDto GetSample()
|
||||||
{
|
{
|
||||||
return new EmployeeWraper
|
return new EmployeeDto
|
||||||
{
|
{
|
||||||
Id = Guid.Empty,
|
Id = Guid.Empty,
|
||||||
DisplayName = "Mike Zanyatski",
|
DisplayName = "Mike Zanyatski",
|
||||||
Title = "Manager",
|
Title = "Manager",
|
||||||
AvatarSmall = "url to small avatar",
|
AvatarSmall = "url to small avatar",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Scope]
|
[Scope]
|
||||||
public class EmployeeWraperHelper
|
public class EmployeeDtoHelper
|
||||||
{
|
{
|
||||||
protected UserPhotoManager UserPhotoManager { get; }
|
protected readonly UserPhotoManager UserPhotoManager;
|
||||||
protected UserManager UserManager { get; }
|
protected readonly UserManager UserManager;
|
||||||
|
|
||||||
private readonly ApiContext _httpContext;
|
private readonly ApiContext _httpContext;
|
||||||
private readonly DisplayUserSettingsHelper _displayUserSettingsHelper;
|
private readonly DisplayUserSettingsHelper _displayUserSettingsHelper;
|
||||||
private readonly CommonLinkUtility _commonLinkUtility;
|
private readonly CommonLinkUtility _commonLinkUtility;
|
||||||
|
|
||||||
public EmployeeWraperHelper(
|
public EmployeeDtoHelper(
|
||||||
ApiContext httpContext,
|
ApiContext httpContext,
|
||||||
DisplayUserSettingsHelper displayUserSettingsHelper,
|
DisplayUserSettingsHelper displayUserSettingsHelper,
|
||||||
UserPhotoManager userPhotoManager,
|
UserPhotoManager userPhotoManager,
|
||||||
CommonLinkUtility commonLinkUtility,
|
CommonLinkUtility commonLinkUtility,
|
||||||
UserManager userManager)
|
UserManager userManager)
|
||||||
{
|
{
|
||||||
UserPhotoManager = userPhotoManager;
|
UserPhotoManager = userPhotoManager;
|
||||||
UserManager = userManager;
|
UserManager = userManager;
|
||||||
_httpContext = httpContext;
|
_httpContext = httpContext;
|
||||||
_displayUserSettingsHelper = displayUserSettingsHelper;
|
_displayUserSettingsHelper = displayUserSettingsHelper;
|
||||||
_commonLinkUtility = commonLinkUtility;
|
_commonLinkUtility = commonLinkUtility;
|
||||||
|
}
|
||||||
}
|
|
||||||
|
public EmployeeDto Get(UserInfo userInfo)
|
||||||
public EmployeeWraper Get(UserInfo userInfo)
|
{
|
||||||
{
|
return Init(new EmployeeDto(), userInfo);
|
||||||
return Init(new EmployeeWraper(), userInfo);
|
}
|
||||||
}
|
|
||||||
|
public EmployeeDto Get(Guid userId)
|
||||||
public EmployeeWraper Get(Guid userId)
|
{
|
||||||
{
|
try
|
||||||
try
|
{
|
||||||
{
|
return Get(UserManager.GetUsers(userId));
|
||||||
return Get(UserManager.GetUsers(userId));
|
}
|
||||||
}
|
catch (Exception)
|
||||||
catch (Exception)
|
{
|
||||||
{
|
return Get(Constants.LostUser);
|
||||||
return Get(Constants.LostUser);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
protected EmployeeDto Init(EmployeeDto result, UserInfo userInfo)
|
||||||
protected EmployeeWraper Init(EmployeeWraper result, UserInfo userInfo)
|
{
|
||||||
{
|
result.Id = userInfo.Id;
|
||||||
result.Id = userInfo.Id;
|
result.DisplayName = _displayUserSettingsHelper.GetFullUserName(userInfo);
|
||||||
result.DisplayName = _displayUserSettingsHelper.GetFullUserName(userInfo);
|
|
||||||
|
if (!string.IsNullOrEmpty(userInfo.Title))
|
||||||
if (!string.IsNullOrEmpty(userInfo.Title))
|
{
|
||||||
{
|
result.Title = userInfo.Title;
|
||||||
result.Title = userInfo.Title;
|
}
|
||||||
}
|
|
||||||
|
var userInfoLM = userInfo.LastModified.GetHashCode();
|
||||||
var userInfoLM = userInfo.LastModified.GetHashCode();
|
|
||||||
|
if (_httpContext.Check("avatarSmall"))
|
||||||
if (_httpContext.Check("avatarSmall"))
|
{
|
||||||
{
|
result.AvatarSmall = UserPhotoManager.GetSmallPhotoURL(userInfo.Id, out var isdef)
|
||||||
result.AvatarSmall = UserPhotoManager.GetSmallPhotoURL(userInfo.Id, out var isdef)
|
+ (isdef ? "" : $"?_={userInfoLM}");
|
||||||
+ (isdef ? "" : $"?_={userInfoLM}");
|
}
|
||||||
}
|
|
||||||
|
if (result.Id != Guid.Empty)
|
||||||
if (result.Id != Guid.Empty)
|
{
|
||||||
{
|
var profileUrl = _commonLinkUtility.GetUserProfile(userInfo, false);
|
||||||
var profileUrl = _commonLinkUtility.GetUserProfile(userInfo, false);
|
result.ProfileUrl = _commonLinkUtility.GetFullAbsolutePath(profileUrl);
|
||||||
result.ProfileUrl = _commonLinkUtility.GetFullAbsolutePath(profileUrl);
|
}
|
||||||
}
|
|
||||||
|
return result;
|
||||||
return result;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,257 +1,257 @@
|
|||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* (c) Copyright Ascensio System Limited 2010-2018
|
* (c) Copyright Ascensio System Limited 2010-2018
|
||||||
*
|
*
|
||||||
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
||||||
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
||||||
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
||||||
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
||||||
*
|
*
|
||||||
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
||||||
*
|
*
|
||||||
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
||||||
*
|
*
|
||||||
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
||||||
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
||||||
*
|
*
|
||||||
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
||||||
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
||||||
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
||||||
* in every copy of the program you distribute.
|
* in every copy of the program you distribute.
|
||||||
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace ASC.Web.Api.Models;
|
namespace ASC.Web.Api.Models;
|
||||||
|
|
||||||
public class EmployeeWraperFull : EmployeeWraper
|
public class EmployeeFullDto : EmployeeDto
|
||||||
{
|
{
|
||||||
public string FirstName { get; set; }
|
public string FirstName { get; set; }
|
||||||
public string LastName { get; set; }
|
public string LastName { get; set; }
|
||||||
public string UserName { get; set; }
|
public string UserName { get; set; }
|
||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
public List<Contact> Contacts { get; set; }
|
public List<Contact> Contacts { get; set; }
|
||||||
public ApiDateTime Birthday { get; set; }
|
public ApiDateTime Birthday { get; set; }
|
||||||
public string Sex { get; set; }
|
public string Sex { get; set; }
|
||||||
public EmployeeStatus Status { get; set; }
|
public EmployeeStatus Status { get; set; }
|
||||||
public EmployeeActivationStatus ActivationStatus { get; set; }
|
public EmployeeActivationStatus ActivationStatus { get; set; }
|
||||||
public ApiDateTime Terminated { get; set; }
|
public ApiDateTime Terminated { get; set; }
|
||||||
public string Department { get; set; }
|
public string Department { get; set; }
|
||||||
public ApiDateTime WorkFrom { get; set; }
|
public ApiDateTime WorkFrom { get; set; }
|
||||||
public List<GroupWrapperSummary> Groups { get; set; }
|
public List<GroupSummaryDto> Groups { get; set; }
|
||||||
public string Location { get; set; }
|
public string Location { get; set; }
|
||||||
public string Notes { get; set; }
|
public string Notes { get; set; }
|
||||||
public string AvatarMax { get; set; }
|
public string AvatarMax { get; set; }
|
||||||
public string AvatarMedium { get; set; }
|
public string AvatarMedium { get; set; }
|
||||||
public string Avatar { get; set; }
|
public string Avatar { get; set; }
|
||||||
public bool IsAdmin { get; set; }
|
public bool IsAdmin { get; set; }
|
||||||
public bool IsLDAP { get; set; }
|
public bool IsLDAP { get; set; }
|
||||||
public List<string> ListAdminModules { get; set; }
|
public List<string> ListAdminModules { get; set; }
|
||||||
public bool IsOwner { get; set; }
|
public bool IsOwner { get; set; }
|
||||||
public bool IsVisitor { get; set; }
|
public bool IsVisitor { get; set; }
|
||||||
public string CultureName { get; set; }
|
public string CultureName { get; set; }
|
||||||
public string MobilePhone { get; set; }
|
public string MobilePhone { get; set; }
|
||||||
public MobilePhoneActivationStatus MobilePhoneActivationStatus { get; set; }
|
public MobilePhoneActivationStatus MobilePhoneActivationStatus { get; set; }
|
||||||
public bool IsSSO { get; set; }
|
public bool IsSSO { get; set; }
|
||||||
|
|
||||||
public new static EmployeeWraperFull GetSample()
|
public new static EmployeeFullDto GetSample()
|
||||||
{
|
{
|
||||||
return new EmployeeWraperFull
|
return new EmployeeFullDto
|
||||||
{
|
{
|
||||||
Avatar = "url to big avatar",
|
Avatar = "url to big avatar",
|
||||||
AvatarSmall = "url to small avatar",
|
AvatarSmall = "url to small avatar",
|
||||||
AvatarMax = "url to max avatar",
|
AvatarMax = "url to max avatar",
|
||||||
Contacts = new List<Contact> { Contact.GetSample() },
|
Contacts = new List<Contact> { Contact.GetSample() },
|
||||||
Email = "my@gmail.com",
|
Email = "my@gmail.com",
|
||||||
FirstName = "Mike",
|
FirstName = "Mike",
|
||||||
Id = Guid.Empty,
|
Id = Guid.Empty,
|
||||||
IsAdmin = false,
|
IsAdmin = false,
|
||||||
ListAdminModules = new List<string> { "projects", "crm" },
|
ListAdminModules = new List<string> { "projects", "crm" },
|
||||||
UserName = "Mike.Zanyatski",
|
UserName = "Mike.Zanyatski",
|
||||||
LastName = "Zanyatski",
|
LastName = "Zanyatski",
|
||||||
Title = "Manager",
|
Title = "Manager",
|
||||||
Groups = new List<GroupWrapperSummary> { GroupWrapperSummary.GetSample() },
|
Groups = new List<GroupSummaryDto> { GroupSummaryDto.GetSample() },
|
||||||
AvatarMedium = "url to medium avatar",
|
AvatarMedium = "url to medium avatar",
|
||||||
Birthday = ApiDateTime.GetSample(),
|
Birthday = ApiDateTime.GetSample(),
|
||||||
Department = "Marketing",
|
Department = "Marketing",
|
||||||
Location = "Palo Alto",
|
Location = "Palo Alto",
|
||||||
Notes = "Notes to worker",
|
Notes = "Notes to worker",
|
||||||
Sex = "male",
|
Sex = "male",
|
||||||
Status = EmployeeStatus.Active,
|
Status = EmployeeStatus.Active,
|
||||||
WorkFrom = ApiDateTime.GetSample(),
|
WorkFrom = ApiDateTime.GetSample(),
|
||||||
Terminated = ApiDateTime.GetSample(),
|
Terminated = ApiDateTime.GetSample(),
|
||||||
CultureName = "en-EN",
|
CultureName = "en-EN",
|
||||||
IsLDAP = false,
|
IsLDAP = false,
|
||||||
IsSSO = false
|
IsSSO = false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Scope]
|
[Scope]
|
||||||
public class EmployeeWraperFullHelper : EmployeeWraperHelper
|
public class EmployeeFullDtoHelper : EmployeeDtoHelper
|
||||||
{
|
{
|
||||||
private readonly ApiContext _context;
|
private readonly ApiContext _context;
|
||||||
private readonly WebItemSecurity _webItemSecurity;
|
private readonly WebItemSecurity _webItemSecurity;
|
||||||
private readonly ApiDateTimeHelper _apiDateTimeHelper;
|
private readonly ApiDateTimeHelper _apiDateTimeHelper;
|
||||||
|
|
||||||
public EmployeeWraperFullHelper(
|
public EmployeeFullDtoHelper(
|
||||||
ApiContext context,
|
ApiContext context,
|
||||||
UserManager userManager,
|
UserManager userManager,
|
||||||
UserPhotoManager userPhotoManager,
|
UserPhotoManager userPhotoManager,
|
||||||
WebItemSecurity webItemSecurity,
|
WebItemSecurity webItemSecurity,
|
||||||
CommonLinkUtility commonLinkUtility,
|
CommonLinkUtility commonLinkUtility,
|
||||||
DisplayUserSettingsHelper displayUserSettingsHelper,
|
DisplayUserSettingsHelper displayUserSettingsHelper,
|
||||||
ApiDateTimeHelper apiDateTimeHelper)
|
ApiDateTimeHelper apiDateTimeHelper)
|
||||||
: base(context, displayUserSettingsHelper, userPhotoManager, commonLinkUtility, userManager)
|
: base(context, displayUserSettingsHelper, userPhotoManager, commonLinkUtility, userManager)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
_webItemSecurity = webItemSecurity;
|
_webItemSecurity = webItemSecurity;
|
||||||
_apiDateTimeHelper = apiDateTimeHelper;
|
_apiDateTimeHelper = apiDateTimeHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Expression<Func<User, UserInfo>> GetExpression(ApiContext apiContext)
|
public static Expression<Func<User, UserInfo>> GetExpression(ApiContext apiContext)
|
||||||
{
|
{
|
||||||
if (apiContext?.Fields == null)
|
if (apiContext?.Fields == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var newExpr = Expression.New(typeof(UserInfo));
|
var newExpr = Expression.New(typeof(UserInfo));
|
||||||
|
|
||||||
//i => new UserInfo { ID = i.id }
|
//i => new UserInfo { ID = i.id }
|
||||||
var parameter = Expression.Parameter(typeof(User), "i");
|
var parameter = Expression.Parameter(typeof(User), "i");
|
||||||
var bindExprs = new List<MemberAssignment>();
|
var bindExprs = new List<MemberAssignment>();
|
||||||
|
|
||||||
if (apiContext.Check("Id"))
|
if (apiContext.Check("Id"))
|
||||||
{
|
{
|
||||||
bindExprs.Add(Expression.Bind(typeof(UserInfo).GetProperty("ID"),
|
bindExprs.Add(Expression.Bind(typeof(UserInfo).GetProperty("ID"),
|
||||||
Expression.Property(parameter, typeof(User).GetProperty("Id"))));
|
Expression.Property(parameter, typeof(User).GetProperty("Id"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
var body = Expression.MemberInit(newExpr, bindExprs);
|
var body = Expression.MemberInit(newExpr, bindExprs);
|
||||||
var lambda = Expression.Lambda<Func<User, UserInfo>>(body, parameter);
|
var lambda = Expression.Lambda<Func<User, UserInfo>>(body, parameter);
|
||||||
|
|
||||||
return lambda;
|
return lambda;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EmployeeWraperFull GetFull(UserInfo userInfo)
|
public EmployeeFullDto GetFull(UserInfo userInfo)
|
||||||
{
|
{
|
||||||
var result = new EmployeeWraperFull
|
var result = new EmployeeFullDto
|
||||||
{
|
{
|
||||||
UserName = userInfo.UserName,
|
UserName = userInfo.UserName,
|
||||||
FirstName = userInfo.FirstName,
|
FirstName = userInfo.FirstName,
|
||||||
LastName = userInfo.LastName,
|
LastName = userInfo.LastName,
|
||||||
Birthday = _apiDateTimeHelper.Get(userInfo.BirthDate),
|
Birthday = _apiDateTimeHelper.Get(userInfo.BirthDate),
|
||||||
Status = userInfo.Status,
|
Status = userInfo.Status,
|
||||||
ActivationStatus = userInfo.ActivationStatus & ~EmployeeActivationStatus.AutoGenerated,
|
ActivationStatus = userInfo.ActivationStatus & ~EmployeeActivationStatus.AutoGenerated,
|
||||||
Terminated = _apiDateTimeHelper.Get(userInfo.TerminatedDate),
|
Terminated = _apiDateTimeHelper.Get(userInfo.TerminatedDate),
|
||||||
WorkFrom = _apiDateTimeHelper.Get(userInfo.WorkFromDate),
|
WorkFrom = _apiDateTimeHelper.Get(userInfo.WorkFromDate),
|
||||||
Email = userInfo.Email,
|
Email = userInfo.Email,
|
||||||
IsVisitor = userInfo.IsVisitor(UserManager),
|
IsVisitor = userInfo.IsVisitor(UserManager),
|
||||||
IsAdmin = userInfo.IsAdmin(UserManager),
|
IsAdmin = userInfo.IsAdmin(UserManager),
|
||||||
IsOwner = userInfo.IsOwner(_context.Tenant),
|
IsOwner = userInfo.IsOwner(_context.Tenant),
|
||||||
IsLDAP = userInfo.IsLDAP(),
|
IsLDAP = userInfo.IsLDAP(),
|
||||||
IsSSO = userInfo.IsSSO()
|
IsSSO = userInfo.IsSSO()
|
||||||
};
|
};
|
||||||
|
|
||||||
Init(result, userInfo);
|
Init(result, userInfo);
|
||||||
|
|
||||||
if (userInfo.Sex.HasValue)
|
if (userInfo.Sex.HasValue)
|
||||||
{
|
{
|
||||||
result.Sex = userInfo.Sex.Value ? "male" : "female";
|
result.Sex = userInfo.Sex.Value ? "male" : "female";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(userInfo.Location))
|
if (!string.IsNullOrEmpty(userInfo.Location))
|
||||||
{
|
{
|
||||||
result.Location = userInfo.Location;
|
result.Location = userInfo.Location;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(userInfo.Notes))
|
if (!string.IsNullOrEmpty(userInfo.Notes))
|
||||||
{
|
{
|
||||||
result.Notes = userInfo.Notes;
|
result.Notes = userInfo.Notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(userInfo.MobilePhone))
|
if (!string.IsNullOrEmpty(userInfo.MobilePhone))
|
||||||
{
|
{
|
||||||
result.MobilePhone = userInfo.MobilePhone;
|
result.MobilePhone = userInfo.MobilePhone;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.MobilePhoneActivationStatus = userInfo.MobilePhoneActivationStatus;
|
result.MobilePhoneActivationStatus = userInfo.MobilePhoneActivationStatus;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(userInfo.CultureName))
|
if (!string.IsNullOrEmpty(userInfo.CultureName))
|
||||||
{
|
{
|
||||||
result.CultureName = userInfo.CultureName;
|
result.CultureName = userInfo.CultureName;
|
||||||
}
|
}
|
||||||
|
|
||||||
FillConacts(result, userInfo);
|
FillConacts(result, userInfo);
|
||||||
|
|
||||||
if (_context.Check("groups") || _context.Check("department"))
|
if (_context.Check("groups") || _context.Check("department"))
|
||||||
{
|
{
|
||||||
var groups = UserManager.GetUserGroups(userInfo.Id)
|
var groups = UserManager.GetUserGroups(userInfo.Id)
|
||||||
.Select(x => new GroupWrapperSummary(x, UserManager))
|
.Select(x => new GroupSummaryDto(x, UserManager))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
if (groups.Count > 0)
|
if (groups.Count > 0)
|
||||||
{
|
{
|
||||||
result.Groups = groups;
|
result.Groups = groups;
|
||||||
result.Department = string.Join(", ", result.Groups.Select(d => d.Name.HtmlEncode()));
|
result.Department = string.Join(", ", result.Groups.Select(d => d.Name.HtmlEncode()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.Department = "";
|
result.Department = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var userInfoLM = userInfo.LastModified.GetHashCode();
|
var userInfoLM = userInfo.LastModified.GetHashCode();
|
||||||
|
|
||||||
if (_context.Check("avatarMax"))
|
if (_context.Check("avatarMax"))
|
||||||
{
|
{
|
||||||
result.AvatarMax = UserPhotoManager.GetMaxPhotoURL(userInfo.Id, out var isdef) + (isdef ? "" : $"?_={userInfoLM}");
|
result.AvatarMax = UserPhotoManager.GetMaxPhotoURL(userInfo.Id, out var isdef) + (isdef ? "" : $"?_={userInfoLM}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_context.Check("avatarMedium"))
|
if (_context.Check("avatarMedium"))
|
||||||
{
|
{
|
||||||
result.AvatarMedium = UserPhotoManager.GetMediumPhotoURL(userInfo.Id, out var isdef) + (isdef ? "" : $"?_={userInfoLM}");
|
result.AvatarMedium = UserPhotoManager.GetMediumPhotoURL(userInfo.Id, out var isdef) + (isdef ? "" : $"?_={userInfoLM}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_context.Check("avatar"))
|
if (_context.Check("avatar"))
|
||||||
{
|
{
|
||||||
result.Avatar = UserPhotoManager.GetBigPhotoURL(userInfo.Id, out var isdef) + (isdef ? "" : $"?_={userInfoLM}");
|
result.Avatar = UserPhotoManager.GetBigPhotoURL(userInfo.Id, out var isdef) + (isdef ? "" : $"?_={userInfoLM}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_context.Check("listAdminModules"))
|
if (_context.Check("listAdminModules"))
|
||||||
{
|
{
|
||||||
var listAdminModules = userInfo.GetListAdminModules(_webItemSecurity);
|
var listAdminModules = userInfo.GetListAdminModules(_webItemSecurity);
|
||||||
if (listAdminModules.Count > 0)
|
if (listAdminModules.Count > 0)
|
||||||
{
|
{
|
||||||
result.ListAdminModules = listAdminModules;
|
result.ListAdminModules = listAdminModules;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FillConacts(EmployeeWraperFull employeeWraperFull, UserInfo userInfo)
|
private void FillConacts(EmployeeFullDto employeeWraperFull, UserInfo userInfo)
|
||||||
{
|
{
|
||||||
if (userInfo.ContactsList == null)
|
if (userInfo.ContactsList == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var contacts = new List<Contact>();
|
var contacts = new List<Contact>();
|
||||||
|
|
||||||
for (var i = 0; i < userInfo.ContactsList.Count; i += 2)
|
for (var i = 0; i < userInfo.ContactsList.Count; i += 2)
|
||||||
{
|
{
|
||||||
if (i + 1 < userInfo.ContactsList.Count)
|
if (i + 1 < userInfo.ContactsList.Count)
|
||||||
{
|
{
|
||||||
contacts.Add(new Contact(userInfo.ContactsList[i], userInfo.ContactsList[i + 1]));
|
contacts.Add(new Contact(userInfo.ContactsList[i], userInfo.ContactsList[i + 1]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contacts.Count > 0)
|
if (contacts.Count > 0)
|
||||||
{
|
{
|
||||||
employeeWraperFull.Contacts = contacts;
|
employeeWraperFull.Contacts = contacts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,54 +1,54 @@
|
|||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* (c) Copyright Ascensio System Limited 2010-2018
|
* (c) Copyright Ascensio System Limited 2010-2018
|
||||||
*
|
*
|
||||||
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
||||||
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
||||||
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
||||||
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
||||||
*
|
*
|
||||||
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
||||||
*
|
*
|
||||||
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
||||||
*
|
*
|
||||||
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
||||||
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
||||||
*
|
*
|
||||||
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
||||||
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
||||||
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
||||||
* in every copy of the program you distribute.
|
* in every copy of the program you distribute.
|
||||||
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using GroupInfo = ASC.Core.Users.GroupInfo;
|
using GroupInfo = ASC.Core.Users.GroupInfo;
|
||||||
|
|
||||||
namespace ASC.Web.Api.Models;
|
namespace ASC.Web.Api.Models;
|
||||||
|
|
||||||
public class GroupWrapperSummary
|
public class GroupSummaryDto
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string Manager { get; set; }
|
public string Manager { get; set; }
|
||||||
|
|
||||||
protected GroupWrapperSummary() { }
|
protected GroupSummaryDto() { }
|
||||||
|
|
||||||
public GroupWrapperSummary(GroupInfo group, UserManager userManager)
|
public GroupSummaryDto(GroupInfo group, UserManager userManager)
|
||||||
{
|
{
|
||||||
Id = group.ID;
|
Id = group.ID;
|
||||||
Name = group.Name;
|
Name = group.Name;
|
||||||
Manager = userManager.GetUsers(userManager.GetDepartmentManager(group.ID)).UserName;
|
Manager = userManager.GetUsers(userManager.GetDepartmentManager(group.ID)).UserName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GroupWrapperSummary GetSample()
|
public static GroupSummaryDto GetSample()
|
||||||
{
|
{
|
||||||
return new GroupWrapperSummary
|
return new GroupSummaryDto
|
||||||
{
|
{
|
||||||
Id = Guid.Empty,
|
Id = Guid.Empty,
|
||||||
Manager = "Jake.Zazhitski",
|
Manager = "Jake.Zazhitski",
|
||||||
Name = "Group Name"
|
Name = "Group Name"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,6 +12,7 @@
|
|||||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||||
<WarningsAsErrors></WarningsAsErrors>
|
<WarningsAsErrors></WarningsAsErrors>
|
||||||
<NoWarn>$(NoWarn);NU1605</NoWarn>
|
<NoWarn>$(NoWarn);NU1605</NoWarn>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
|
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
12
common/ASC.Common/ArgumentNullExceptionExtension.cs
Normal file
12
common/ASC.Common/ArgumentNullExceptionExtension.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
namespace System;
|
||||||
|
|
||||||
|
public static class ArgumentNullOrEmptyException
|
||||||
|
{
|
||||||
|
public static void ThrowIfNullOrEmpty(string argument, [CallerArgumentExpression("argument")] string? paramName = null)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(argument))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(paramName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -31,8 +31,8 @@ public static class StreamExtension
|
|||||||
|
|
||||||
public static void StreamCopyTo(this Stream srcStream, Stream dstStream, int length)
|
public static void StreamCopyTo(this Stream srcStream, Stream dstStream, int length)
|
||||||
{
|
{
|
||||||
if (srcStream == null) throw new ArgumentNullException(nameof(srcStream));
|
ArgumentNullException.ThrowIfNull(srcStream);
|
||||||
if (dstStream == null) throw new ArgumentNullException(nameof(dstStream));
|
ArgumentNullException.ThrowIfNull(dstStream);
|
||||||
|
|
||||||
var buffer = new byte[BufferSize];
|
var buffer = new byte[BufferSize];
|
||||||
int totalRead = 0;
|
int totalRead = 0;
|
||||||
|
@ -28,7 +28,7 @@ public class TempStream
|
|||||||
|
|
||||||
public Stream GetBuffered(Stream srcStream)
|
public Stream GetBuffered(Stream srcStream)
|
||||||
{
|
{
|
||||||
if (srcStream == null) throw new ArgumentNullException(nameof(srcStream));
|
ArgumentNullException.ThrowIfNull(srcStream);
|
||||||
if (!srcStream.CanSeek || srcStream.CanTimeout)
|
if (!srcStream.CanSeek || srcStream.CanTimeout)
|
||||||
{
|
{
|
||||||
//Buffer it
|
//Buffer it
|
||||||
|
@ -1,32 +1,27 @@
|
|||||||
global using System;
|
global using System.Collections;
|
||||||
global using System.Collections;
|
|
||||||
global using System.Collections.Concurrent;
|
global using System.Collections.Concurrent;
|
||||||
global using System.Collections.Generic;
|
|
||||||
global using System.Configuration;
|
global using System.Configuration;
|
||||||
global using System.Diagnostics;
|
global using System.Diagnostics;
|
||||||
global using System.Globalization;
|
global using System.Globalization;
|
||||||
global using System.IO;
|
|
||||||
global using System.Linq;
|
|
||||||
global using System.Net;
|
global using System.Net;
|
||||||
global using System.Net.Mail;
|
global using System.Net.Mail;
|
||||||
global using System.Reflection;
|
global using System.Reflection;
|
||||||
global using System.Runtime.Caching;
|
global using System.Runtime.Caching;
|
||||||
|
global using System.Runtime.CompilerServices;
|
||||||
global using System.Runtime.Loader;
|
global using System.Runtime.Loader;
|
||||||
|
global using System.Runtime.Serialization;
|
||||||
global using System.Security.Cryptography;
|
global using System.Security.Cryptography;
|
||||||
global using System.Security.Principal;
|
global using System.Security.Principal;
|
||||||
|
global using System.ServiceModel;
|
||||||
global using System.Text;
|
global using System.Text;
|
||||||
global using System.Text.RegularExpressions;
|
global using System.Text.RegularExpressions;
|
||||||
global using System.Threading;
|
|
||||||
global using System.Threading.Tasks;
|
|
||||||
global using System.Web;
|
global using System.Web;
|
||||||
global using System.Xml.Linq;
|
global using System.Xml.Linq;
|
||||||
global using System.Xml.XPath;
|
global using System.Xml.XPath;
|
||||||
global using System.ServiceModel;
|
|
||||||
global using System.Runtime.Serialization;
|
|
||||||
|
|
||||||
global using ARSoft.Tools.Net;
|
global using ARSoft.Tools.Net;
|
||||||
global using ARSoft.Tools.Net.Dns;
|
global using ARSoft.Tools.Net.Dns;
|
||||||
|
|
||||||
global using ASC.Common;
|
global using ASC.Common;
|
||||||
global using ASC.Common.Caching;
|
global using ASC.Common.Caching;
|
||||||
global using ASC.Common.DependencyInjection;
|
global using ASC.Common.DependencyInjection;
|
||||||
@ -35,26 +30,26 @@ global using ASC.Common.Security;
|
|||||||
global using ASC.Common.Security.Authorizing;
|
global using ASC.Common.Security.Authorizing;
|
||||||
global using ASC.Common.Utils;
|
global using ASC.Common.Utils;
|
||||||
global using ASC.Security.Cryptography;
|
global using ASC.Security.Cryptography;
|
||||||
|
|
||||||
global using Autofac;
|
global using Autofac;
|
||||||
global using Autofac.Configuration;
|
global using Autofac.Configuration;
|
||||||
|
|
||||||
global using AutoMapper;
|
global using AutoMapper;
|
||||||
|
|
||||||
global using Confluent.Kafka;
|
global using Confluent.Kafka;
|
||||||
global using Confluent.Kafka.Admin;
|
global using Confluent.Kafka.Admin;
|
||||||
|
|
||||||
global using Google.Protobuf;
|
global using Google.Protobuf;
|
||||||
|
|
||||||
global using JWT;
|
global using JWT;
|
||||||
global using JWT.Algorithms;
|
global using JWT.Algorithms;
|
||||||
global using JWT.Serializers;
|
global using JWT.Serializers;
|
||||||
|
|
||||||
global using log4net.Appender;
|
global using log4net.Appender;
|
||||||
global using log4net.Config;
|
global using log4net.Config;
|
||||||
global using log4net.Core;
|
global using log4net.Core;
|
||||||
global using log4net.Util;
|
global using log4net.Util;
|
||||||
|
|
||||||
global using Microsoft.AspNetCore.Cryptography.KeyDerivation;
|
global using Microsoft.AspNetCore.Cryptography.KeyDerivation;
|
||||||
global using Microsoft.AspNetCore.Http;
|
global using Microsoft.AspNetCore.Http;
|
||||||
global using Microsoft.AspNetCore.Http.Extensions;
|
global using Microsoft.AspNetCore.Http.Extensions;
|
||||||
@ -70,16 +65,16 @@ global using Microsoft.Extensions.Hosting;
|
|||||||
global using Microsoft.Extensions.Logging;
|
global using Microsoft.Extensions.Logging;
|
||||||
global using Microsoft.Extensions.Options;
|
global using Microsoft.Extensions.Options;
|
||||||
global using Microsoft.Net.Http.Headers;
|
global using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
global using Newtonsoft.Json;
|
global using Newtonsoft.Json;
|
||||||
global using Newtonsoft.Json.Serialization;
|
global using Newtonsoft.Json.Serialization;
|
||||||
|
|
||||||
global using NLog;
|
global using NLog;
|
||||||
global using NLog.Common;
|
global using NLog.Common;
|
||||||
global using NLog.Targets;
|
global using NLog.Targets;
|
||||||
|
|
||||||
global using NVelocity;
|
global using NVelocity;
|
||||||
global using NVelocity.App;
|
global using NVelocity.App;
|
||||||
global using NVelocity.Runtime.Resource.Loader;
|
global using NVelocity.Runtime.Resource.Loader;
|
||||||
|
|
||||||
global using StackExchange.Redis.Extensions.Core.Abstractions;
|
global using StackExchange.Redis.Extensions.Core.Abstractions;
|
||||||
|
@ -88,10 +88,7 @@ public class AscRandom : Random
|
|||||||
|
|
||||||
public override void NextBytes(byte[] buffer)
|
public override void NextBytes(byte[] buffer)
|
||||||
{
|
{
|
||||||
if (buffer == null)
|
ArgumentNullException.ThrowIfNull(buffer);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(buffer));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < buffer.Length; i++)
|
for (var i = 0; i < buffer.Length; i++)
|
||||||
{
|
{
|
||||||
|
@ -43,9 +43,11 @@ public class AuthorizingException : Exception
|
|||||||
if (actions == null || actions.Length == 0)
|
if (actions == null || actions.Length == 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(actions));
|
throw new ArgumentNullException(nameof(actions));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ArgumentNullException.ThrowIfNull(subject);
|
||||||
|
|
||||||
Subject = subject ?? throw new ArgumentNullException(nameof(subject));
|
Subject = subject;
|
||||||
Actions = actions;
|
Actions = actions;
|
||||||
var sactions = "";
|
var sactions = "";
|
||||||
|
|
||||||
@ -80,10 +82,8 @@ public class AuthorizingException : Exception
|
|||||||
internal static string FormatErrorMessage(ISubject subject, IAction[] actions, ISubject[] denySubjects,
|
internal static string FormatErrorMessage(ISubject subject, IAction[] actions, ISubject[] denySubjects,
|
||||||
IAction[] denyActions)
|
IAction[] denyActions)
|
||||||
{
|
{
|
||||||
if (subject == null)
|
ArgumentNullException.ThrowIfNull(subject);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(subject));
|
|
||||||
}
|
|
||||||
if (actions == null || actions.Length == 0)
|
if (actions == null || actions.Length == 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(actions));
|
throw new ArgumentNullException(nameof(actions));
|
||||||
|
@ -35,9 +35,10 @@ public class AzObjectSecurityProviderHelper
|
|||||||
private ISecurityObjectProvider _currSecObjProvider;
|
private ISecurityObjectProvider _currSecObjProvider;
|
||||||
|
|
||||||
public AzObjectSecurityProviderHelper(ISecurityObjectId objectId, ISecurityObjectProvider secObjProvider)
|
public AzObjectSecurityProviderHelper(ISecurityObjectId objectId, ISecurityObjectProvider secObjProvider)
|
||||||
{
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(objectId);
|
||||||
_currObjIdAsProvider = false;
|
_currObjIdAsProvider = false;
|
||||||
CurrentObjectId = objectId ?? throw new ArgumentNullException(nameof(objectId));
|
CurrentObjectId = objectId;
|
||||||
_currSecObjProvider = secObjProvider;
|
_currSecObjProvider = secObjProvider;
|
||||||
|
|
||||||
if (_currSecObjProvider == null && CurrentObjectId is ISecurityObjectProvider securityObjectProvider)
|
if (_currSecObjProvider == null && CurrentObjectId is ISecurityObjectProvider securityObjectProvider)
|
||||||
|
@ -45,11 +45,9 @@ public sealed class Role : IRole
|
|||||||
if (id == Guid.Empty)
|
if (id == Guid.Empty)
|
||||||
{
|
{
|
||||||
throw new ArgumentException(nameof(id));
|
throw new ArgumentException(nameof(id));
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(name))
|
|
||||||
{
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(name);
|
||||||
throw new ArgumentNullException(nameof(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
ID = id;
|
ID = id;
|
||||||
Name = name;
|
Name = name;
|
||||||
|
@ -106,40 +106,28 @@ public static class Hasher
|
|||||||
|
|
||||||
private static byte[] S2B(string str)
|
private static byte[] S2B(string str)
|
||||||
{
|
{
|
||||||
if (str == null)
|
ArgumentNullException.ThrowIfNull(str);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(str));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Encoding.UTF8.GetBytes(str);
|
return Encoding.UTF8.GetBytes(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string B2S(byte[] data)
|
private static string B2S(byte[] data)
|
||||||
{
|
{
|
||||||
if (data == null)
|
ArgumentNullException.ThrowIfNull(data);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Encoding.UTF8.GetString(data);
|
return Encoding.UTF8.GetString(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] S642B(string str)
|
private static byte[] S642B(string str)
|
||||||
{
|
{
|
||||||
if (str == null)
|
ArgumentNullException.ThrowIfNull(str);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(str));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Convert.FromBase64String(str);
|
return Convert.FromBase64String(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string B2S64(byte[] data)
|
private static string B2S64(byte[] data)
|
||||||
{
|
{
|
||||||
if (data == null)
|
ArgumentNullException.ThrowIfNull(data);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Convert.ToBase64String(data);
|
return Convert.ToBase64String(data);
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,10 @@ public class SecurityObjectId : ISecurityObjectId
|
|||||||
|
|
||||||
public SecurityObjectId(object id, Type objType)
|
public SecurityObjectId(object id, Type objType)
|
||||||
{
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(objType);
|
||||||
|
|
||||||
SecurityId = id;
|
SecurityId = id;
|
||||||
ObjectType = objType ?? throw new ArgumentNullException(nameof(objType));
|
ObjectType = objType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
|
@ -45,10 +45,7 @@ public class DnsLookup
|
|||||||
/// <returns>list of MxRecord</returns>
|
/// <returns>list of MxRecord</returns>
|
||||||
public List<MxRecord> GetDomainMxRecords(string domainName)
|
public List<MxRecord> GetDomainMxRecords(string domainName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(domainName))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(domainName);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(domainName));
|
|
||||||
}
|
|
||||||
|
|
||||||
var mxRecords = DnsResolve<MxRecord>(domainName, RecordType.Mx);
|
var mxRecords = DnsResolve<MxRecord>(domainName, RecordType.Mx);
|
||||||
|
|
||||||
@ -65,15 +62,8 @@ public class DnsLookup
|
|||||||
/// <returns>true if exists and vice versa</returns>
|
/// <returns>true if exists and vice versa</returns>
|
||||||
public bool IsDomainMxRecordExists(string domainName, string mxRecord)
|
public bool IsDomainMxRecordExists(string domainName, string mxRecord)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(domainName))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(domainName);
|
||||||
{
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(mxRecord);
|
||||||
throw new ArgumentNullException(nameof(domainName));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(mxRecord))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(mxRecord));
|
|
||||||
}
|
|
||||||
|
|
||||||
var mxDomain = DomainName.Parse(mxRecord);
|
var mxDomain = DomainName.Parse(mxRecord);
|
||||||
|
|
||||||
@ -93,14 +83,11 @@ public class DnsLookup
|
|||||||
/// <returns>true if any DNS record exists and vice versa</returns>
|
/// <returns>true if any DNS record exists and vice versa</returns>
|
||||||
public bool IsDomainExists(string domainName)
|
public bool IsDomainExists(string domainName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(domainName))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(domainName);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(domainName));
|
|
||||||
}
|
|
||||||
|
|
||||||
var dnsMessage = GetDnsMessage(domainName);
|
var dnsMessage = GetDnsMessage(domainName);
|
||||||
|
|
||||||
return dnsMessage.AnswerRecords.Count != 0;
|
return dnsMessage.AnswerRecords.Count != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -112,10 +99,7 @@ public class DnsLookup
|
|||||||
/// <returns>list of ARecord</returns>
|
/// <returns>list of ARecord</returns>
|
||||||
public List<ARecord> GetDomainARecords(string domainName)
|
public List<ARecord> GetDomainARecords(string domainName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(domainName))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(domainName);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(domainName));
|
|
||||||
}
|
|
||||||
|
|
||||||
var aRecords = DnsResolve<ARecord>(domainName, RecordType.A);
|
var aRecords = DnsResolve<ARecord>(domainName, RecordType.A);
|
||||||
|
|
||||||
@ -131,10 +115,7 @@ public class DnsLookup
|
|||||||
/// <returns>list of IPAddress</returns>
|
/// <returns>list of IPAddress</returns>
|
||||||
public List<IPAddress> GetDomainIPs(string domainName)
|
public List<IPAddress> GetDomainIPs(string domainName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(domainName))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(domainName);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(domainName));
|
|
||||||
}
|
|
||||||
|
|
||||||
var addresses = _sDnsResolver.ResolveHost(domainName);
|
var addresses = _sDnsResolver.ResolveHost(domainName);
|
||||||
|
|
||||||
@ -150,10 +131,7 @@ public class DnsLookup
|
|||||||
/// <returns>list of TxtRecord</returns>
|
/// <returns>list of TxtRecord</returns>
|
||||||
public List<TxtRecord> GetDomainTxtRecords(string domainName)
|
public List<TxtRecord> GetDomainTxtRecords(string domainName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(domainName))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(domainName);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(domainName));
|
|
||||||
}
|
|
||||||
|
|
||||||
var txtRecords = DnsResolve<TxtRecord>(domainName, RecordType.Txt);
|
var txtRecords = DnsResolve<TxtRecord>(domainName, RecordType.Txt);
|
||||||
|
|
||||||
@ -206,14 +184,9 @@ public class DnsLookup
|
|||||||
/// <returns>true if exists and vice versa</returns>
|
/// <returns>true if exists and vice versa</returns>
|
||||||
public bool IsDomainPtrRecordExists(IPAddress ipAddress, string domainName)
|
public bool IsDomainPtrRecordExists(IPAddress ipAddress, string domainName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(domainName))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(domainName);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(domainName));
|
ArgumentNullException.ThrowIfNull(ipAddress);
|
||||||
}
|
|
||||||
if (ipAddress == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(ipAddress));
|
|
||||||
}
|
|
||||||
|
|
||||||
var domain = DomainName.Parse(domainName);
|
var domain = DomainName.Parse(domainName);
|
||||||
|
|
||||||
@ -238,10 +211,7 @@ public class DnsLookup
|
|||||||
|
|
||||||
private DnsMessage GetDnsMessage(string domainName, RecordType? type = null)
|
private DnsMessage GetDnsMessage(string domainName, RecordType? type = null)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(domainName))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(domainName);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(domainName));
|
|
||||||
}
|
|
||||||
|
|
||||||
var domain = DomainName.Parse(domainName);
|
var domain = DomainName.Parse(domainName);
|
||||||
|
|
||||||
@ -257,10 +227,7 @@ public class DnsLookup
|
|||||||
|
|
||||||
private List<T> DnsResolve<T>(string domainName, RecordType type)
|
private List<T> DnsResolve<T>(string domainName, RecordType type)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(domainName))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(domainName);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(domainName));
|
|
||||||
}
|
|
||||||
|
|
||||||
var dnsMessage = GetDnsMessage(domainName, type);
|
var dnsMessage = GetDnsMessage(domainName, type);
|
||||||
|
|
||||||
|
@ -68,8 +68,9 @@ public class DisposableHttpContext : IDisposable
|
|||||||
private bool _isDisposed;
|
private bool _isDisposed;
|
||||||
|
|
||||||
public DisposableHttpContext(HttpContext ctx)
|
public DisposableHttpContext(HttpContext ctx)
|
||||||
{
|
{
|
||||||
_context = ctx ?? throw new ArgumentNullException(nameof(ctx));
|
ArgumentNullException.ThrowIfNull(ctx);
|
||||||
|
_context = ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
<Copyright>(c) Ascensio System SIA. All rights reserved</Copyright>
|
<Copyright>(c) Ascensio System SIA. All rights reserved</Copyright>
|
||||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||||
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
|
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
|
@ -78,10 +78,7 @@ public class BaseCommonLinkUtility
|
|||||||
{
|
{
|
||||||
var u = HttpContextAccessor?.HttpContext.Request.GetUrlRewriter();
|
var u = HttpContextAccessor?.HttpContext.Request.GetUrlRewriter();
|
||||||
|
|
||||||
if (u == null)
|
ArgumentNullException.ThrowIfNull(u);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(u));
|
|
||||||
}
|
|
||||||
|
|
||||||
uriBuilder = new UriBuilder(u.Scheme, LocalHost, u.Port);
|
uriBuilder = new UriBuilder(u.Scheme, LocalHost, u.Port);
|
||||||
}
|
}
|
||||||
@ -120,10 +117,7 @@ public class BaseCommonLinkUtility
|
|||||||
{
|
{
|
||||||
var u = HttpContextAccessor?.HttpContext?.Request.GetUrlRewriter();
|
var u = HttpContextAccessor?.HttpContext?.Request.GetUrlRewriter();
|
||||||
|
|
||||||
if (u == null)
|
ArgumentNullException.ThrowIfNull(u);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(u));
|
|
||||||
}
|
|
||||||
|
|
||||||
result = new UriBuilder(u.Scheme, u.Host, u.Port);
|
result = new UriBuilder(u.Scheme, u.Host, u.Port);
|
||||||
|
|
||||||
|
@ -170,10 +170,7 @@ public class BillingClient
|
|||||||
|
|
||||||
public IDictionary<string, Dictionary<string, decimal>> GetProductPriceInfo(params string[] productIds)
|
public IDictionary<string, Dictionary<string, decimal>> GetProductPriceInfo(params string[] productIds)
|
||||||
{
|
{
|
||||||
if (productIds == null)
|
ArgumentNullException.ThrowIfNull(productIds);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(productIds));
|
|
||||||
}
|
|
||||||
|
|
||||||
var parameters = productIds.Select(pid => Tuple.Create("ProductId", pid)).ToList();
|
var parameters = productIds.Select(pid => Tuple.Create("ProductId", pid)).ToList();
|
||||||
parameters.Add(Tuple.Create("PaymentSystemId", AvangatePaymentSystemId.ToString()));
|
parameters.Add(Tuple.Create("PaymentSystemId", AvangatePaymentSystemId.ToString()));
|
||||||
|
@ -153,10 +153,7 @@ public class LicenseReader
|
|||||||
|
|
||||||
private static void SaveLicense(Stream licenseStream, string path)
|
private static void SaveLicense(Stream licenseStream, string path)
|
||||||
{
|
{
|
||||||
if (licenseStream == null)
|
ArgumentNullException.ThrowIfNull(licenseStream);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(licenseStream));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (licenseStream.CanSeek)
|
if (licenseStream.CanSeek)
|
||||||
{
|
{
|
||||||
|
@ -40,7 +40,7 @@ public class TariffServiceStorage
|
|||||||
Cache.Remove(TariffService.GetTariffCacheKey(i.TenantId));
|
Cache.Remove(TariffService.GetTariffCacheKey(i.TenantId));
|
||||||
Cache.Remove(TariffService.GetBillingUrlCacheKey(i.TenantId));
|
Cache.Remove(TariffService.GetBillingUrlCacheKey(i.TenantId));
|
||||||
Cache.Remove(TariffService.GetBillingPaymentCacheKey(i.TenantId)); // clear all payments
|
Cache.Remove(TariffService.GetBillingPaymentCacheKey(i.TenantId)); // clear all payments
|
||||||
}, CacheNotifyAction.Remove);
|
}, CacheNotifyAction.Remove);
|
||||||
|
|
||||||
//TODO: Change code of WCF -> not supported in .NET standard/.Net Core
|
//TODO: Change code of WCF -> not supported in .NET standard/.Net Core
|
||||||
/*try
|
/*try
|
||||||
@ -259,10 +259,7 @@ public class TariffService : ITariffService
|
|||||||
|
|
||||||
public void SetTariff(int tenantId, Tariff tariff)
|
public void SetTariff(int tenantId, Tariff tariff)
|
||||||
{
|
{
|
||||||
if (tariff == null)
|
ArgumentNullException.ThrowIfNull(tariff);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(tariff));
|
|
||||||
}
|
|
||||||
|
|
||||||
var q = QuotaService.GetTenantQuota(tariff.QuotaId);
|
var q = QuotaService.GetTenantQuota(tariff.QuotaId);
|
||||||
if (q == null)
|
if (q == null)
|
||||||
@ -423,10 +420,8 @@ public class TariffService : ITariffService
|
|||||||
|
|
||||||
public IDictionary<string, Dictionary<string, decimal>> GetProductPriceInfo(params string[] productIds)
|
public IDictionary<string, Dictionary<string, decimal>> GetProductPriceInfo(params string[] productIds)
|
||||||
{
|
{
|
||||||
if (productIds == null)
|
ArgumentNullException.ThrowIfNull(productIds);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(productIds));
|
|
||||||
}
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var key = "biling-prices" + string.Join(",", productIds);
|
var key = "biling-prices" + string.Join(",", productIds);
|
||||||
|
@ -151,10 +151,7 @@ public class CoreSettings
|
|||||||
|
|
||||||
public void SaveSetting(string key, string value, int tenant = Tenant.DefaultTenant)
|
public void SaveSetting(string key, string value, int tenant = Tenant.DefaultTenant)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(key))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(key);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] bytes = null;
|
byte[] bytes = null;
|
||||||
if (value != null)
|
if (value != null)
|
||||||
@ -167,10 +164,7 @@ public class CoreSettings
|
|||||||
|
|
||||||
public string GetSetting(string key, int tenant = Tenant.DefaultTenant)
|
public string GetSetting(string key, int tenant = Tenant.DefaultTenant)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(key))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(key);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
var bytes = TenantService.GetTenantSettings(tenant, key);
|
var bytes = TenantService.GetTenantSettings(tenant, key);
|
||||||
|
|
||||||
|
@ -84,10 +84,7 @@ public class PaymentManager
|
|||||||
|
|
||||||
public void ActivateKey(string key)
|
public void ActivateKey(string key)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(key))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(key);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
var now = DateTime.UtcNow;
|
var now = DateTime.UtcNow;
|
||||||
var actionUrl = "/partnerapi/ActivateKey?code=" + HttpUtility.UrlEncode(key) + "&portal=" + HttpUtility.UrlEncode(_tenantManager.GetCurrentTenant().Alias);
|
var actionUrl = "/partnerapi/ActivateKey?code=" + HttpUtility.UrlEncode(key) + "&portal=" + HttpUtility.UrlEncode(_tenantManager.GetCurrentTenant().Alias);
|
||||||
|
@ -185,10 +185,7 @@ public class TenantManager
|
|||||||
|
|
||||||
public Tenant SetTenantVersion(Tenant tenant, int version)
|
public Tenant SetTenantVersion(Tenant tenant, int version)
|
||||||
{
|
{
|
||||||
if (tenant == null)
|
ArgumentNullException.ThrowIfNull(tenant);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(tenant));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tenant.Version != version)
|
if (tenant.Version != version)
|
||||||
{
|
{
|
||||||
|
@ -80,15 +80,8 @@ public class SecurityContext
|
|||||||
|
|
||||||
public string AuthenticateMe(string login, string passwordHash)
|
public string AuthenticateMe(string login, string passwordHash)
|
||||||
{
|
{
|
||||||
if (login == null)
|
ArgumentNullException.ThrowIfNull(login);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(passwordHash);
|
||||||
throw new ArgumentNullException(nameof(login));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (passwordHash == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(passwordHash));
|
|
||||||
}
|
|
||||||
|
|
||||||
var tenantid = _tenantManager.GetCurrentTenant().Id;
|
var tenantid = _tenantManager.GetCurrentTenant().Id;
|
||||||
var u = _userManager.GetUsersByPasswordHash(tenantid, login, passwordHash);
|
var u = _userManager.GetUsersByPasswordHash(tenantid, login, passwordHash);
|
||||||
@ -109,10 +102,7 @@ public class SecurityContext
|
|||||||
{
|
{
|
||||||
var request = _httpContextAccessor?.HttpContext.Request;
|
var request = _httpContextAccessor?.HttpContext.Request;
|
||||||
|
|
||||||
if (request == null)
|
ArgumentNullException.ThrowIfNull(request);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(request));
|
|
||||||
}
|
|
||||||
|
|
||||||
ipFrom = "from " + (request.Headers["X-Forwarded-For"].ToString() ?? request.GetUserHostAddress());
|
ipFrom = "from " + (request.Headers["X-Forwarded-For"].ToString() ?? request.GetUserHostAddress());
|
||||||
address = "for " + request.GetUrlRewriter();
|
address = "for " + request.GetUrlRewriter();
|
||||||
@ -170,10 +160,7 @@ public class SecurityContext
|
|||||||
{
|
{
|
||||||
var request = _httpContextAccessor?.HttpContext.Request;
|
var request = _httpContextAccessor?.HttpContext.Request;
|
||||||
|
|
||||||
if (request == null)
|
ArgumentNullException.ThrowIfNull(request);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(request));
|
|
||||||
}
|
|
||||||
|
|
||||||
address = "for " + request.GetUrlRewriter();
|
address = "for " + request.GetUrlRewriter();
|
||||||
ipFrom = "from " + (request.Headers["X-Forwarded-For"].ToString() ?? request.GetUserHostAddress());
|
ipFrom = "from " + (request.Headers["X-Forwarded-For"].ToString() ?? request.GetUserHostAddress());
|
||||||
|
@ -145,14 +145,8 @@ public class DBResourceManager : ResourceManager
|
|||||||
CultureInfo culture,
|
CultureInfo culture,
|
||||||
string filename)
|
string filename)
|
||||||
{
|
{
|
||||||
if (culture == null)
|
ArgumentNullException.ThrowIfNull(culture);
|
||||||
{
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(filename);
|
||||||
throw new ArgumentNullException(nameof(culture));
|
|
||||||
}
|
|
||||||
if (string.IsNullOrEmpty(filename))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(filename));
|
|
||||||
}
|
|
||||||
|
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_logger = option.CurrentValue;
|
_logger = option.CurrentValue;
|
||||||
|
@ -23,8 +23,6 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System.Diagnostics.Metrics;
|
|
||||||
|
|
||||||
using AutoMapper.QueryableExtensions;
|
using AutoMapper.QueryableExtensions;
|
||||||
|
|
||||||
namespace ASC.Core.Data;
|
namespace ASC.Core.Data;
|
||||||
@ -81,10 +79,7 @@ class DbQuotaService : IQuotaService
|
|||||||
|
|
||||||
public TenantQuota SaveTenantQuota(TenantQuota quota)
|
public TenantQuota SaveTenantQuota(TenantQuota quota)
|
||||||
{
|
{
|
||||||
if (quota == null)
|
ArgumentNullException.ThrowIfNull(quota);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(quota));
|
|
||||||
}
|
|
||||||
|
|
||||||
CoreDbContext.AddOrUpdate(r => r.Quotas, _mapper.Map<TenantQuota, DbQuota>(quota));
|
CoreDbContext.AddOrUpdate(r => r.Quotas, _mapper.Map<TenantQuota, DbQuota>(quota));
|
||||||
CoreDbContext.SaveChanges();
|
CoreDbContext.SaveChanges();
|
||||||
@ -111,10 +106,7 @@ class DbQuotaService : IQuotaService
|
|||||||
|
|
||||||
public void SetTenantQuotaRow(TenantQuotaRow row, bool exchange)
|
public void SetTenantQuotaRow(TenantQuotaRow row, bool exchange)
|
||||||
{
|
{
|
||||||
if (row == null)
|
ArgumentNullException.ThrowIfNull(row);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(row));
|
|
||||||
}
|
|
||||||
|
|
||||||
using var tx = CoreDbContext.Database.BeginTransaction();
|
using var tx = CoreDbContext.Database.BeginTransaction();
|
||||||
|
|
||||||
|
@ -169,10 +169,7 @@ public class DbSettingsManager
|
|||||||
|
|
||||||
public bool SaveSettingsFor<T>(T settings, int tenantId, Guid userId) where T : ISettings
|
public bool SaveSettingsFor<T>(T settings, int tenantId, Guid userId) where T : ISettings
|
||||||
{
|
{
|
||||||
if (settings == null)
|
ArgumentNullException.ThrowIfNull(settings);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(settings));
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -40,14 +40,8 @@ public class DbSubscriptionService : ISubscriptionService
|
|||||||
|
|
||||||
public string[] GetRecipients(int tenant, string sourceId, string actionId, string objectId)
|
public string[] GetRecipients(int tenant, string sourceId, string actionId, string objectId)
|
||||||
{
|
{
|
||||||
if (sourceId == null)
|
ArgumentNullException.ThrowIfNull(sourceId);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(actionId);
|
||||||
throw new ArgumentNullException(nameof(sourceId));
|
|
||||||
}
|
|
||||||
if (actionId == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(actionId));
|
|
||||||
}
|
|
||||||
|
|
||||||
var q = GetQuery(tenant, sourceId, actionId)
|
var q = GetQuery(tenant, sourceId, actionId)
|
||||||
.Where(r => r.Object == (objectId ?? string.Empty))
|
.Where(r => r.Object == (objectId ?? string.Empty))
|
||||||
@ -60,14 +54,8 @@ public class DbSubscriptionService : ISubscriptionService
|
|||||||
|
|
||||||
public IEnumerable<SubscriptionRecord> GetSubscriptions(int tenant, string sourceId, string actionId)
|
public IEnumerable<SubscriptionRecord> GetSubscriptions(int tenant, string sourceId, string actionId)
|
||||||
{
|
{
|
||||||
if (sourceId == null)
|
ArgumentNullException.ThrowIfNull(sourceId);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(actionId);
|
||||||
throw new ArgumentNullException(nameof(sourceId));
|
|
||||||
}
|
|
||||||
if (actionId == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(actionId));
|
|
||||||
}
|
|
||||||
|
|
||||||
var q = GetQuery(tenant, sourceId, actionId);
|
var q = GetQuery(tenant, sourceId, actionId);
|
||||||
|
|
||||||
@ -92,10 +80,7 @@ public class DbSubscriptionService : ISubscriptionService
|
|||||||
|
|
||||||
public SubscriptionRecord GetSubscription(int tenant, string sourceId, string actionId, string recipientId, string objectId)
|
public SubscriptionRecord GetSubscription(int tenant, string sourceId, string actionId, string recipientId, string objectId)
|
||||||
{
|
{
|
||||||
if (recipientId == null)
|
ArgumentNullException.ThrowIfNull(recipientId);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(recipientId));
|
|
||||||
}
|
|
||||||
|
|
||||||
var q = GetQuery(tenant, sourceId, actionId)
|
var q = GetQuery(tenant, sourceId, actionId)
|
||||||
.Where(r => r.Recipient == recipientId)
|
.Where(r => r.Recipient == recipientId)
|
||||||
@ -106,18 +91,9 @@ public class DbSubscriptionService : ISubscriptionService
|
|||||||
|
|
||||||
public bool IsUnsubscribe(int tenant, string sourceId, string actionId, string recipientId, string objectId)
|
public bool IsUnsubscribe(int tenant, string sourceId, string actionId, string recipientId, string objectId)
|
||||||
{
|
{
|
||||||
if (recipientId == null)
|
ArgumentNullException.ThrowIfNull(recipientId);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(sourceId);
|
||||||
throw new ArgumentNullException(nameof(recipientId));
|
ArgumentNullException.ThrowIfNull(actionId);
|
||||||
}
|
|
||||||
if (sourceId == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(sourceId));
|
|
||||||
}
|
|
||||||
if (actionId == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(actionId));
|
|
||||||
}
|
|
||||||
|
|
||||||
var q = UserDbContext.Subscriptions
|
var q = UserDbContext.Subscriptions
|
||||||
.Where(r => r.Source == sourceId &&
|
.Where(r => r.Source == sourceId &&
|
||||||
@ -140,18 +116,9 @@ public class DbSubscriptionService : ISubscriptionService
|
|||||||
|
|
||||||
public string[] GetSubscriptions(int tenant, string sourceId, string actionId, string recipientId, bool checkSubscribe)
|
public string[] GetSubscriptions(int tenant, string sourceId, string actionId, string recipientId, bool checkSubscribe)
|
||||||
{
|
{
|
||||||
if (recipientId == null)
|
ArgumentNullException.ThrowIfNull(recipientId);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(sourceId);
|
||||||
throw new ArgumentNullException(nameof(recipientId));
|
ArgumentNullException.ThrowIfNull(actionId);
|
||||||
}
|
|
||||||
if (sourceId == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(sourceId));
|
|
||||||
}
|
|
||||||
if (actionId == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(actionId));
|
|
||||||
}
|
|
||||||
|
|
||||||
var q = GetQuery(tenant, sourceId, actionId)
|
var q = GetQuery(tenant, sourceId, actionId)
|
||||||
.Where(r => r.Recipient == recipientId)
|
.Where(r => r.Recipient == recipientId)
|
||||||
@ -168,10 +135,7 @@ public class DbSubscriptionService : ISubscriptionService
|
|||||||
|
|
||||||
public void SaveSubscription(SubscriptionRecord s)
|
public void SaveSubscription(SubscriptionRecord s)
|
||||||
{
|
{
|
||||||
if (s == null)
|
ArgumentNullException.ThrowIfNull(s);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(s));
|
|
||||||
}
|
|
||||||
|
|
||||||
var subs = new Subscription
|
var subs = new Subscription
|
||||||
{
|
{
|
||||||
@ -194,15 +158,8 @@ public class DbSubscriptionService : ISubscriptionService
|
|||||||
|
|
||||||
public void RemoveSubscriptions(int tenant, string sourceId, string actionId, string objectId)
|
public void RemoveSubscriptions(int tenant, string sourceId, string actionId, string objectId)
|
||||||
{
|
{
|
||||||
if (sourceId == null)
|
ArgumentNullException.ThrowIfNull(sourceId);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(actionId);
|
||||||
throw new ArgumentNullException(nameof(sourceId));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (actionId == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(actionId));
|
|
||||||
}
|
|
||||||
|
|
||||||
using var tr = UserDbContext.Database.BeginTransaction();
|
using var tr = UserDbContext.Database.BeginTransaction();
|
||||||
var q = UserDbContext.Subscriptions
|
var q = UserDbContext.Subscriptions
|
||||||
@ -228,14 +185,8 @@ public class DbSubscriptionService : ISubscriptionService
|
|||||||
|
|
||||||
public IEnumerable<SubscriptionMethod> GetSubscriptionMethods(int tenant, string sourceId, string actionId, string recipientId)
|
public IEnumerable<SubscriptionMethod> GetSubscriptionMethods(int tenant, string sourceId, string actionId, string recipientId)
|
||||||
{
|
{
|
||||||
if (sourceId == null)
|
ArgumentNullException.ThrowIfNull(sourceId);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(actionId);
|
||||||
throw new ArgumentNullException(nameof(sourceId));
|
|
||||||
}
|
|
||||||
if (actionId == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(actionId));
|
|
||||||
}
|
|
||||||
|
|
||||||
var q = UserDbContext.SubscriptionMethods
|
var q = UserDbContext.SubscriptionMethods
|
||||||
.Where(r => r.Tenant == -1 || r.Tenant == tenant)
|
.Where(r => r.Tenant == -1 || r.Tenant == tenant)
|
||||||
@ -278,10 +229,7 @@ public class DbSubscriptionService : ISubscriptionService
|
|||||||
|
|
||||||
public void SetSubscriptionMethod(SubscriptionMethod m)
|
public void SetSubscriptionMethod(SubscriptionMethod m)
|
||||||
{
|
{
|
||||||
if (m == null)
|
ArgumentNullException.ThrowIfNull(m);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(m));
|
|
||||||
}
|
|
||||||
|
|
||||||
using var tr = UserDbContext.Database.BeginTransaction();
|
using var tr = UserDbContext.Database.BeginTransaction();
|
||||||
|
|
||||||
@ -320,14 +268,8 @@ public class DbSubscriptionService : ISubscriptionService
|
|||||||
|
|
||||||
private IQueryable<Subscription> GetQuery(int tenant, string sourceId, string actionId)
|
private IQueryable<Subscription> GetQuery(int tenant, string sourceId, string actionId)
|
||||||
{
|
{
|
||||||
if (sourceId == null)
|
ArgumentNullException.ThrowIfNull(sourceId);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(actionId);
|
||||||
throw new ArgumentNullException(nameof(sourceId));
|
|
||||||
}
|
|
||||||
if (actionId == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(actionId));
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
UserDbContext.Subscriptions
|
UserDbContext.Subscriptions
|
||||||
|
@ -114,10 +114,7 @@ public class DbTenantService : ITenantService
|
|||||||
|
|
||||||
public IEnumerable<Tenant> GetTenants(string login, string passwordHash)
|
public IEnumerable<Tenant> GetTenants(string login, string passwordHash)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(login))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(login);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(login));
|
|
||||||
}
|
|
||||||
|
|
||||||
IQueryable<TenantUserSecurity> query() => TenantsQuery()
|
IQueryable<TenantUserSecurity> query() => TenantsQuery()
|
||||||
.Where(r => r.Status == TenantStatus.Active)
|
.Where(r => r.Status == TenantStatus.Active)
|
||||||
@ -205,10 +202,7 @@ public class DbTenantService : ITenantService
|
|||||||
|
|
||||||
public Tenant GetTenant(string domain)
|
public Tenant GetTenant(string domain)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(domain))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(domain);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(domain));
|
|
||||||
}
|
|
||||||
|
|
||||||
domain = domain.ToLowerInvariant();
|
domain = domain.ToLowerInvariant();
|
||||||
|
|
||||||
@ -229,79 +223,76 @@ public class DbTenantService : ITenantService
|
|||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tenant SaveTenant(CoreSettings coreSettings, Tenant t)
|
public Tenant SaveTenant(CoreSettings coreSettings, Tenant tenant)
|
||||||
{
|
{
|
||||||
if (t == null)
|
ArgumentNullException.ThrowIfNull(tenant);
|
||||||
{
|
|
||||||
throw new ArgumentNullException("tenant");
|
|
||||||
}
|
|
||||||
|
|
||||||
using var tx = TenantDbContext.Database.BeginTransaction();
|
using var tx = TenantDbContext.Database.BeginTransaction();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(t.MappedDomain))
|
if (!string.IsNullOrEmpty(tenant.MappedDomain))
|
||||||
{
|
{
|
||||||
var baseUrl = coreSettings.GetBaseDomain(t.HostedRegion);
|
var baseUrl = coreSettings.GetBaseDomain(tenant.HostedRegion);
|
||||||
|
|
||||||
if (baseUrl != null && t.MappedDomain.EndsWith("." + baseUrl, StringComparison.InvariantCultureIgnoreCase))
|
if (baseUrl != null && tenant.MappedDomain.EndsWith("." + baseUrl, StringComparison.InvariantCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
ValidateDomain(t.MappedDomain.Substring(0, t.MappedDomain.Length - baseUrl.Length - 1), t.Id, false);
|
ValidateDomain(tenant.MappedDomain.Substring(0, tenant.MappedDomain.Length - baseUrl.Length - 1), tenant.Id, false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ValidateDomain(t.MappedDomain, t.Id, false);
|
ValidateDomain(tenant.MappedDomain, tenant.Id, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.Id == Tenant.DefaultTenant)
|
if (tenant.Id == Tenant.DefaultTenant)
|
||||||
{
|
{
|
||||||
t.Version = TenantDbContext.TenantVersion
|
tenant.Version = TenantDbContext.TenantVersion
|
||||||
.Where(r => r.DefaultVersion == 1 || r.Id == 0)
|
.Where(r => r.DefaultVersion == 1 || r.Id == 0)
|
||||||
.OrderByDescending(r => r.Id)
|
.OrderByDescending(r => r.Id)
|
||||||
.Select(r => r.Id)
|
.Select(r => r.Id)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
t.LastModified = DateTime.UtcNow;
|
tenant.LastModified = DateTime.UtcNow;
|
||||||
|
|
||||||
var tenant = _mapper.Map<Tenant, DbTenant>(t);
|
var dbTenant = _mapper.Map<Tenant, DbTenant>(tenant);
|
||||||
|
|
||||||
tenant = TenantDbContext.Tenants.Add(tenant).Entity;
|
dbTenant = TenantDbContext.Tenants.Add(dbTenant).Entity;
|
||||||
TenantDbContext.SaveChanges();
|
TenantDbContext.SaveChanges();
|
||||||
t.Id = tenant.Id;
|
tenant.Id = dbTenant.Id;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var tenant = TenantDbContext.Tenants
|
var dbTenant = TenantDbContext.Tenants
|
||||||
.Where(r => r.Id == t.Id)
|
.Where(r => r.Id == tenant.Id)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
if (tenant != null)
|
if (dbTenant != null)
|
||||||
{
|
{
|
||||||
tenant.Alias = t.Alias.ToLowerInvariant();
|
dbTenant.Alias = tenant.Alias.ToLowerInvariant();
|
||||||
tenant.MappedDomain = !string.IsNullOrEmpty(t.MappedDomain) ? t.MappedDomain.ToLowerInvariant() : null;
|
dbTenant.MappedDomain = !string.IsNullOrEmpty(tenant.MappedDomain) ? tenant.MappedDomain.ToLowerInvariant() : null;
|
||||||
tenant.Version = t.Version;
|
dbTenant.Version = tenant.Version;
|
||||||
tenant.VersionChanged = t.VersionChanged;
|
dbTenant.VersionChanged = tenant.VersionChanged;
|
||||||
tenant.Name = t.Name ?? t.Alias;
|
dbTenant.Name = tenant.Name ?? tenant.Alias;
|
||||||
tenant.Language = t.Language;
|
dbTenant.Language = tenant.Language;
|
||||||
tenant.TimeZone = t.TimeZone;
|
dbTenant.TimeZone = tenant.TimeZone;
|
||||||
tenant.TrustedDomainsRaw = t.GetTrustedDomains();
|
dbTenant.TrustedDomainsRaw = tenant.GetTrustedDomains();
|
||||||
tenant.TrustedDomainsEnabled = t.TrustedDomainsType;
|
dbTenant.TrustedDomainsEnabled = tenant.TrustedDomainsType;
|
||||||
tenant.CreationDateTime = t.CreationDateTime;
|
dbTenant.CreationDateTime = tenant.CreationDateTime;
|
||||||
tenant.Status = t.Status;
|
dbTenant.Status = tenant.Status;
|
||||||
tenant.StatusChanged = t.StatusChangeDate;
|
dbTenant.StatusChanged = tenant.StatusChangeDate;
|
||||||
tenant.PaymentId = t.PaymentId;
|
dbTenant.PaymentId = tenant.PaymentId;
|
||||||
tenant.LastModified = t.LastModified = DateTime.UtcNow;
|
dbTenant.LastModified = tenant.LastModified = DateTime.UtcNow;
|
||||||
tenant.Industry = t.Industry;
|
dbTenant.Industry = tenant.Industry;
|
||||||
tenant.Spam = t.Spam;
|
dbTenant.Spam = tenant.Spam;
|
||||||
tenant.Calls = t.Calls;
|
dbTenant.Calls = tenant.Calls;
|
||||||
}
|
}
|
||||||
|
|
||||||
TenantDbContext.SaveChanges();
|
TenantDbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(t.PartnerId) && string.IsNullOrEmpty(t.AffiliateId) && string.IsNullOrEmpty(t.Campaign))
|
if (string.IsNullOrEmpty(tenant.PartnerId) && string.IsNullOrEmpty(tenant.AffiliateId) && string.IsNullOrEmpty(tenant.Campaign))
|
||||||
{
|
{
|
||||||
var p = TenantDbContext.TenantPartner
|
var p = TenantDbContext.TenantPartner
|
||||||
.Where(r => r.TenantId == t.Id)
|
.Where(r => r.TenantId == tenant.Id)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
if (p != null)
|
if (p != null)
|
||||||
@ -313,10 +304,10 @@ public class DbTenantService : ITenantService
|
|||||||
{
|
{
|
||||||
var tenantPartner = new DbTenantPartner
|
var tenantPartner = new DbTenantPartner
|
||||||
{
|
{
|
||||||
TenantId = t.Id,
|
TenantId = tenant.Id,
|
||||||
PartnerId = t.PartnerId,
|
PartnerId = tenant.PartnerId,
|
||||||
AffiliateId = t.AffiliateId,
|
AffiliateId = tenant.AffiliateId,
|
||||||
Campaign = t.Campaign
|
Campaign = tenant.Campaign
|
||||||
};
|
};
|
||||||
|
|
||||||
TenantDbContext.TenantPartner.Add(tenantPartner);
|
TenantDbContext.TenantPartner.Add(tenantPartner);
|
||||||
@ -325,7 +316,7 @@ public class DbTenantService : ITenantService
|
|||||||
tx.Commit();
|
tx.Commit();
|
||||||
|
|
||||||
//CalculateTenantDomain(t);
|
//CalculateTenantDomain(t);
|
||||||
return t;
|
return tenant;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveTenant(int id, bool auto = false)
|
public void RemoveTenant(int id, bool auto = false)
|
||||||
|
@ -115,10 +115,7 @@ public class EFUserService : IUserService
|
|||||||
|
|
||||||
public UserInfo GetUserByPasswordHash(int tenant, string login, string passwordHash)
|
public UserInfo GetUserByPasswordHash(int tenant, string login, string passwordHash)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(login))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(login);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(login));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Guid.TryParse(login, out var userId))
|
if (Guid.TryParse(login, out var userId))
|
||||||
{
|
{
|
||||||
@ -430,10 +427,7 @@ public class EFUserService : IUserService
|
|||||||
|
|
||||||
public Group SaveGroup(int tenant, Group group)
|
public Group SaveGroup(int tenant, Group group)
|
||||||
{
|
{
|
||||||
if (group == null)
|
ArgumentNullException.ThrowIfNull(group);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(group));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (group.Id == default)
|
if (group.Id == default)
|
||||||
{
|
{
|
||||||
@ -452,10 +446,7 @@ public class EFUserService : IUserService
|
|||||||
|
|
||||||
public UserInfo SaveUser(int tenant, UserInfo user)
|
public UserInfo SaveUser(int tenant, UserInfo user)
|
||||||
{
|
{
|
||||||
if (user == null)
|
ArgumentNullException.ThrowIfNull(user);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(user));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(user.UserName))
|
if (string.IsNullOrEmpty(user.UserName))
|
||||||
{
|
{
|
||||||
@ -501,29 +492,26 @@ public class EFUserService : IUserService
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserGroupRef SaveUserGroupRef(int tenant, UserGroupRef r)
|
public UserGroupRef SaveUserGroupRef(int tenant, UserGroupRef userGroupRef)
|
||||||
{
|
{
|
||||||
if (r == null)
|
ArgumentNullException.ThrowIfNull(userGroupRef);
|
||||||
{
|
|
||||||
throw new ArgumentNullException("userGroupRef");
|
|
||||||
}
|
|
||||||
|
|
||||||
r.LastModified = DateTime.UtcNow;
|
userGroupRef.LastModified = DateTime.UtcNow;
|
||||||
r.Tenant = tenant;
|
userGroupRef.Tenant = tenant;
|
||||||
|
|
||||||
using var tr = UserDbContext.Database.BeginTransaction();
|
using var tr = UserDbContext.Database.BeginTransaction();
|
||||||
|
|
||||||
var user = GetUserQuery(tenant).FirstOrDefault(a => a.Tenant == tenant && a.Id == r.UserId);
|
var user = GetUserQuery(tenant).FirstOrDefault(a => a.Tenant == tenant && a.Id == userGroupRef.UserId);
|
||||||
if (user != null)
|
if (user != null)
|
||||||
{
|
{
|
||||||
user.LastModified = r.LastModified;
|
user.LastModified = userGroupRef.LastModified;
|
||||||
UserDbContext.AddOrUpdate(r => r.UserGroups, _mapper.Map<UserGroupRef, UserGroup>(r));
|
UserDbContext.AddOrUpdate(r => r.UserGroups, _mapper.Map<UserGroupRef, UserGroup>(userGroupRef));
|
||||||
}
|
}
|
||||||
|
|
||||||
UserDbContext.SaveChanges();
|
UserDbContext.SaveChanges();
|
||||||
tr.Commit();
|
tr.Commit();
|
||||||
|
|
||||||
return r;
|
return userGroupRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetUserPasswordHash(int tenant, Guid id, string passwordHash)
|
public void SetUserPasswordHash(int tenant, Guid id, string passwordHash)
|
||||||
|
@ -10,9 +10,9 @@ public class DbVoipCall
|
|||||||
public Guid AnsweredBy { get; set; }
|
public Guid AnsweredBy { get; set; }
|
||||||
public DateTime DialDate { get; set; }
|
public DateTime DialDate { get; set; }
|
||||||
public int DialDuration { get; set; }
|
public int DialDuration { get; set; }
|
||||||
public string RecordSid { get; set; }
|
public string Sid { get; set; }
|
||||||
public string RecordUrl { get; set; }
|
public string Uri { get; set; }
|
||||||
public int RecordDuration { get; set; }
|
public int Duration { get; set; }
|
||||||
public decimal RecordPrice { get; set; }
|
public decimal RecordPrice { get; set; }
|
||||||
public int ContactId { get; set; }
|
public int ContactId { get; set; }
|
||||||
public decimal Price { get; set; }
|
public decimal Price { get; set; }
|
||||||
@ -30,6 +30,7 @@ public static class DbVoipCallExtension
|
|||||||
|
|
||||||
return modelBuilder;
|
return modelBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void MySqlAddDbVoipCall(this ModelBuilder modelBuilder)
|
public static void MySqlAddDbVoipCall(this ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder.Entity<DbVoipCall>(entity =>
|
modelBuilder.Entity<DbVoipCall>(entity =>
|
||||||
@ -89,19 +90,19 @@ public static class DbVoipCallExtension
|
|||||||
.HasColumnName("price")
|
.HasColumnName("price")
|
||||||
.HasColumnType("decimal(10,4)");
|
.HasColumnType("decimal(10,4)");
|
||||||
|
|
||||||
entity.Property(e => e.RecordDuration).HasColumnName("record_duration");
|
entity.Property(e => e.Duration).HasColumnName("record_duration");
|
||||||
|
|
||||||
entity.Property(e => e.RecordPrice)
|
entity.Property(e => e.RecordPrice)
|
||||||
.HasColumnName("record_price")
|
.HasColumnName("record_price")
|
||||||
.HasColumnType("decimal(10,4)");
|
.HasColumnType("decimal(10,4)");
|
||||||
|
|
||||||
entity.Property(e => e.RecordSid)
|
entity.Property(e => e.Sid)
|
||||||
.HasColumnName("record_sid")
|
.HasColumnName("record_sid")
|
||||||
.HasColumnType("varchar(50)")
|
.HasColumnType("varchar(50)")
|
||||||
.HasCharSet("utf8")
|
.HasCharSet("utf8")
|
||||||
.UseCollation("utf8_general_ci");
|
.UseCollation("utf8_general_ci");
|
||||||
|
|
||||||
entity.Property(e => e.RecordUrl)
|
entity.Property(e => e.Uri)
|
||||||
.HasColumnName("record_url")
|
.HasColumnName("record_url")
|
||||||
.HasColumnType("text")
|
.HasColumnType("text")
|
||||||
.HasCharSet("utf8")
|
.HasCharSet("utf8")
|
||||||
@ -160,18 +161,18 @@ public static class DbVoipCallExtension
|
|||||||
.HasColumnType("numeric(10,4)")
|
.HasColumnType("numeric(10,4)")
|
||||||
.HasDefaultValueSql("NULL");
|
.HasDefaultValueSql("NULL");
|
||||||
|
|
||||||
entity.Property(e => e.RecordDuration).HasColumnName("record_duration");
|
entity.Property(e => e.Duration).HasColumnName("record_duration");
|
||||||
|
|
||||||
entity.Property(e => e.RecordPrice)
|
entity.Property(e => e.RecordPrice)
|
||||||
.HasColumnName("record_price")
|
.HasColumnName("record_price")
|
||||||
.HasColumnType("numeric(10,4)");
|
.HasColumnType("numeric(10,4)");
|
||||||
|
|
||||||
entity.Property(e => e.RecordSid)
|
entity.Property(e => e.Sid)
|
||||||
.HasColumnName("record_sid")
|
.HasColumnName("record_sid")
|
||||||
.HasMaxLength(50)
|
.HasMaxLength(50)
|
||||||
.HasDefaultValueSql("NULL");
|
.HasDefaultValueSql("NULL");
|
||||||
|
|
||||||
entity.Property(e => e.RecordUrl).HasColumnName("record_url");
|
entity.Property(e => e.Uri).HasColumnName("record_url");
|
||||||
|
|
||||||
entity.Property(e => e.Status).HasColumnName("status");
|
entity.Property(e => e.Status).HasColumnName("status");
|
||||||
|
|
||||||
|
@ -1,16 +1,11 @@
|
|||||||
global using System;
|
global using System.Collections;
|
||||||
global using System.Collections;
|
|
||||||
global using System.Collections.Concurrent;
|
global using System.Collections.Concurrent;
|
||||||
global using System.Collections.Generic;
|
|
||||||
global using System.Configuration;
|
global using System.Configuration;
|
||||||
global using System.Data.Common;
|
global using System.Data.Common;
|
||||||
global using System.Diagnostics;
|
global using System.Diagnostics;
|
||||||
global using System.Globalization;
|
global using System.Globalization;
|
||||||
global using System.IO;
|
|
||||||
global using System.Linq;
|
|
||||||
global using System.Linq.Expressions;
|
global using System.Linq.Expressions;
|
||||||
global using System.Net;
|
global using System.Net;
|
||||||
global using System.Net.Http;
|
|
||||||
global using System.Reflection;
|
global using System.Reflection;
|
||||||
global using System.Resources;
|
global using System.Resources;
|
||||||
global using System.Runtime.Caching;
|
global using System.Runtime.Caching;
|
||||||
@ -25,8 +20,6 @@ global using System.Text;
|
|||||||
global using System.Text.Json;
|
global using System.Text.Json;
|
||||||
global using System.Text.Json.Serialization;
|
global using System.Text.Json.Serialization;
|
||||||
global using System.Text.RegularExpressions;
|
global using System.Text.RegularExpressions;
|
||||||
global using System.Threading;
|
|
||||||
global using System.Threading.Tasks;
|
|
||||||
global using System.Web;
|
global using System.Web;
|
||||||
global using System.Xml;
|
global using System.Xml;
|
||||||
|
|
||||||
|
@ -143,51 +143,49 @@ public class HostedSolution
|
|||||||
TenantService.ValidateDomain(address);
|
TenantService.ValidateDomain(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterTenant(TenantRegistrationInfo ri, out Tenant tenant)
|
public void RegisterTenant(TenantRegistrationInfo registrationInfo, out Tenant tenant)
|
||||||
{
|
{
|
||||||
if (ri == null)
|
ArgumentNullException.ThrowIfNull(registrationInfo);
|
||||||
{
|
|
||||||
throw new ArgumentNullException("registrationInfo");
|
if (string.IsNullOrEmpty(registrationInfo.Address))
|
||||||
}
|
|
||||||
if (string.IsNullOrEmpty(ri.Address))
|
|
||||||
{
|
{
|
||||||
throw new Exception("Address can not be empty");
|
throw new Exception("Address can not be empty");
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(ri.Email))
|
if (string.IsNullOrEmpty(registrationInfo.Email))
|
||||||
{
|
{
|
||||||
throw new Exception("Account email can not be empty");
|
throw new Exception("Account email can not be empty");
|
||||||
}
|
}
|
||||||
if (ri.FirstName == null)
|
if (registrationInfo.FirstName == null)
|
||||||
{
|
{
|
||||||
throw new Exception("Account firstname can not be empty");
|
throw new Exception("Account firstname can not be empty");
|
||||||
}
|
}
|
||||||
if (ri.LastName == null)
|
if (registrationInfo.LastName == null)
|
||||||
{
|
{
|
||||||
throw new Exception("Account lastname can not be empty");
|
throw new Exception("Account lastname can not be empty");
|
||||||
}
|
}
|
||||||
if (!UserFormatter.IsValidUserName(ri.FirstName, ri.LastName))
|
if (!UserFormatter.IsValidUserName(registrationInfo.FirstName, registrationInfo.LastName))
|
||||||
{
|
{
|
||||||
throw new Exception("Incorrect firstname or lastname");
|
throw new Exception("Incorrect firstname or lastname");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(ri.PasswordHash))
|
if (string.IsNullOrEmpty(registrationInfo.PasswordHash))
|
||||||
{
|
{
|
||||||
ri.PasswordHash = Guid.NewGuid().ToString();
|
registrationInfo.PasswordHash = Guid.NewGuid().ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// create tenant
|
// create tenant
|
||||||
tenant = new Tenant(ri.Address.ToLowerInvariant())
|
tenant = new Tenant(registrationInfo.Address.ToLowerInvariant())
|
||||||
{
|
{
|
||||||
Name = ri.Name,
|
Name = registrationInfo.Name,
|
||||||
Language = ri.Culture.Name,
|
Language = registrationInfo.Culture.Name,
|
||||||
TimeZone = ri.TimeZoneInfo.Id,
|
TimeZone = registrationInfo.TimeZoneInfo.Id,
|
||||||
HostedRegion = ri.HostedRegion,
|
HostedRegion = registrationInfo.HostedRegion,
|
||||||
PartnerId = ri.PartnerId,
|
PartnerId = registrationInfo.PartnerId,
|
||||||
AffiliateId = ri.AffiliateId,
|
AffiliateId = registrationInfo.AffiliateId,
|
||||||
Campaign = ri.Campaign,
|
Campaign = registrationInfo.Campaign,
|
||||||
Industry = ri.Industry,
|
Industry = registrationInfo.Industry,
|
||||||
Spam = ri.Spam,
|
Spam = registrationInfo.Spam,
|
||||||
Calls = ri.Calls
|
Calls = registrationInfo.Calls
|
||||||
};
|
};
|
||||||
|
|
||||||
tenant = TenantService.SaveTenant(CoreSettings, tenant);
|
tenant = TenantService.SaveTenant(CoreSettings, tenant);
|
||||||
@ -195,24 +193,24 @@ public class HostedSolution
|
|||||||
// create user
|
// create user
|
||||||
var user = new UserInfo
|
var user = new UserInfo
|
||||||
{
|
{
|
||||||
UserName = ri.Email.Substring(0, ri.Email.IndexOf('@')),
|
UserName = registrationInfo.Email.Substring(0, registrationInfo.Email.IndexOf('@')),
|
||||||
LastName = ri.LastName,
|
LastName = registrationInfo.LastName,
|
||||||
FirstName = ri.FirstName,
|
FirstName = registrationInfo.FirstName,
|
||||||
Email = ri.Email,
|
Email = registrationInfo.Email,
|
||||||
MobilePhone = ri.MobilePhone,
|
MobilePhone = registrationInfo.MobilePhone,
|
||||||
WorkFromDate = TenantUtil.DateTimeNow(tenant.TimeZone),
|
WorkFromDate = TenantUtil.DateTimeNow(tenant.TimeZone),
|
||||||
ActivationStatus = ri.ActivationStatus
|
ActivationStatus = registrationInfo.ActivationStatus
|
||||||
};
|
};
|
||||||
|
|
||||||
user = UserService.SaveUser(tenant.Id, user);
|
user = UserService.SaveUser(tenant.Id, user);
|
||||||
UserService.SetUserPasswordHash(tenant.Id, user.Id, ri.PasswordHash);
|
UserService.SetUserPasswordHash(tenant.Id, user.Id, registrationInfo.PasswordHash);
|
||||||
UserService.SaveUserGroupRef(tenant.Id, new UserGroupRef(user.Id, Constants.GroupAdmin.ID, UserGroupRefType.Contains));
|
UserService.SaveUserGroupRef(tenant.Id, new UserGroupRef(user.Id, Constants.GroupAdmin.ID, UserGroupRefType.Contains));
|
||||||
|
|
||||||
// save tenant owner
|
// save tenant owner
|
||||||
tenant.OwnerId = user.Id;
|
tenant.OwnerId = user.Id;
|
||||||
tenant = TenantService.SaveTenant(CoreSettings, tenant);
|
tenant = TenantService.SaveTenant(CoreSettings, tenant);
|
||||||
|
|
||||||
SettingsManager.SaveSettings(new TenantControlPanelSettings { LimitedAccess = ri.LimitedControlPanel }, tenant.Id);
|
SettingsManager.SaveSettings(new TenantControlPanelSettings { LimitedAccess = registrationInfo.LimitedControlPanel }, tenant.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tenant SaveTenant(Tenant tenant)
|
public Tenant SaveTenant(Tenant tenant)
|
||||||
|
@ -47,10 +47,7 @@ public class SenderChannel : ISenderChannel
|
|||||||
|
|
||||||
public void SendAsync(INoticeMessage message)
|
public void SendAsync(INoticeMessage message)
|
||||||
{
|
{
|
||||||
if (message == null)
|
ArgumentNullException.ThrowIfNull(message);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(message));
|
|
||||||
}
|
|
||||||
|
|
||||||
_firstSink.ProcessMessageAsync(message);
|
_firstSink.ProcessMessageAsync(message);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class DirectSubscriptionProvider : ISubscriptionProvider
|
|||||||
|
|
||||||
public DirectSubscriptionProvider(string sourceID, SubscriptionManager subscriptionManager, IRecipientProvider recipientProvider)
|
public DirectSubscriptionProvider(string sourceID, SubscriptionManager subscriptionManager, IRecipientProvider recipientProvider)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(sourceID)) throw new ArgumentNullException(nameof(sourceID));
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(sourceID);
|
||||||
_sourceId = sourceID;
|
_sourceId = sourceID;
|
||||||
_subscriptionManager = subscriptionManager ?? throw new ArgumentNullException(nameof(subscriptionManager));
|
_subscriptionManager = subscriptionManager ?? throw new ArgumentNullException(nameof(subscriptionManager));
|
||||||
_recipientProvider = recipientProvider ?? throw new ArgumentNullException(nameof(recipientProvider));
|
_recipientProvider = recipientProvider ?? throw new ArgumentNullException(nameof(recipientProvider));
|
||||||
@ -43,40 +43,23 @@ class DirectSubscriptionProvider : ISubscriptionProvider
|
|||||||
|
|
||||||
public object GetSubscriptionRecord(INotifyAction action, IRecipient recipient, string objectID)
|
public object GetSubscriptionRecord(INotifyAction action, IRecipient recipient, string objectID)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (recipient == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
|
|
||||||
return _subscriptionManager.GetSubscriptionRecord(_sourceId, action.ID, recipient.ID, objectID);
|
return _subscriptionManager.GetSubscriptionRecord(_sourceId, action.ID, recipient.ID, objectID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string[] GetSubscriptions(INotifyAction action, IRecipient recipient, bool checkSubscribe = true)
|
public string[] GetSubscriptions(INotifyAction action, IRecipient recipient, bool checkSubscribe = true)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (recipient == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
|
|
||||||
return _subscriptionManager.GetSubscriptions(_sourceId, action.ID, recipient.ID, checkSubscribe);
|
return _subscriptionManager.GetSubscriptions(_sourceId, action.ID, recipient.ID, checkSubscribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IRecipient[] GetRecipients(INotifyAction action, string objectID)
|
public IRecipient[] GetRecipients(INotifyAction action, string objectID)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
return _subscriptionManager.GetRecipients(_sourceId, action.ID, objectID)
|
return _subscriptionManager.GetRecipients(_sourceId, action.ID, objectID)
|
||||||
.Select(r => _recipientProvider.GetRecipient(r))
|
.Select(r => _recipientProvider.GetRecipient(r))
|
||||||
@ -86,90 +69,54 @@ class DirectSubscriptionProvider : ISubscriptionProvider
|
|||||||
|
|
||||||
public string[] GetSubscriptionMethod(INotifyAction action, IRecipient recipient)
|
public string[] GetSubscriptionMethod(INotifyAction action, IRecipient recipient)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
if (recipient == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
|
|
||||||
return _subscriptionManager.GetSubscriptionMethod(_sourceId, action.ID, recipient.ID);
|
return _subscriptionManager.GetSubscriptionMethod(_sourceId, action.ID, recipient.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateSubscriptionMethod(INotifyAction action, IRecipient recipient, params string[] senderNames)
|
public void UpdateSubscriptionMethod(INotifyAction action, IRecipient recipient, params string[] senderNames)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
if (recipient == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
|
|
||||||
_subscriptionManager.UpdateSubscriptionMethod(_sourceId, action.ID, recipient.ID, senderNames);
|
_subscriptionManager.UpdateSubscriptionMethod(_sourceId, action.ID, recipient.ID, senderNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsUnsubscribe(IDirectRecipient recipient, INotifyAction action, string objectID)
|
public bool IsUnsubscribe(IDirectRecipient recipient, INotifyAction action, string objectID)
|
||||||
{
|
{
|
||||||
if (recipient == null)
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
if (action == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
return _subscriptionManager.IsUnsubscribe(_sourceId, recipient.ID, action.ID, objectID);
|
return _subscriptionManager.IsUnsubscribe(_sourceId, recipient.ID, action.ID, objectID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Subscribe(INotifyAction action, string objectID, IRecipient recipient)
|
public void Subscribe(INotifyAction action, string objectID, IRecipient recipient)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
if (recipient == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
|
|
||||||
_subscriptionManager.Subscribe(_sourceId, action.ID, objectID, recipient.ID);
|
_subscriptionManager.Subscribe(_sourceId, action.ID, objectID, recipient.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnSubscribe(INotifyAction action, string objectID, IRecipient recipient)
|
public void UnSubscribe(INotifyAction action, string objectID, IRecipient recipient)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
if (recipient == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
|
|
||||||
_subscriptionManager.Unsubscribe(_sourceId, action.ID, objectID, recipient.ID);
|
_subscriptionManager.Unsubscribe(_sourceId, action.ID, objectID, recipient.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnSubscribe(INotifyAction action)
|
public void UnSubscribe(INotifyAction action)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
_subscriptionManager.UnsubscribeAll(_sourceId, action.ID);
|
_subscriptionManager.UnsubscribeAll(_sourceId, action.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnSubscribe(INotifyAction action, string objectID)
|
public void UnSubscribe(INotifyAction action, string objectID)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
_subscriptionManager.UnsubscribeAll(_sourceId, action.ID, objectID);
|
_subscriptionManager.UnsubscribeAll(_sourceId, action.ID, objectID);
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ class InterceptorStorage
|
|||||||
|
|
||||||
public void Add(ISendInterceptor interceptor)
|
public void Add(ISendInterceptor interceptor)
|
||||||
{
|
{
|
||||||
if (interceptor == null) throw new ArgumentNullException(nameof(interceptor));
|
ArgumentNullException.ThrowIfNull(interceptor);
|
||||||
if (string.IsNullOrEmpty(interceptor.Name)) throw new ArgumentException("empty name property", nameof(interceptor));
|
if (string.IsNullOrEmpty(interceptor.Name)) throw new ArgumentException("empty name property", nameof(interceptor));
|
||||||
|
|
||||||
switch (interceptor.Lifetime)
|
switch (interceptor.Lifetime)
|
||||||
|
@ -73,15 +73,8 @@ public class NotifyEngine : INotifyEngine
|
|||||||
|
|
||||||
internal void RegisterSendMethod(Action<DateTime> method, string cron)
|
internal void RegisterSendMethod(Action<DateTime> method, string cron)
|
||||||
{
|
{
|
||||||
if (method == null)
|
ArgumentNullException.ThrowIfNull(method);
|
||||||
{
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(cron);
|
||||||
throw new ArgumentNullException(nameof(method));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(cron))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(cron));
|
|
||||||
}
|
|
||||||
|
|
||||||
var w = new SendMethodWrapper(method, cron, _logger);
|
var w = new SendMethodWrapper(method, cron, _logger);
|
||||||
lock (_sendMethods)
|
lock (_sendMethods)
|
||||||
@ -99,10 +92,7 @@ public class NotifyEngine : INotifyEngine
|
|||||||
|
|
||||||
internal void UnregisterSendMethod(Action<DateTime> method)
|
internal void UnregisterSendMethod(Action<DateTime> method)
|
||||||
{
|
{
|
||||||
if (method == null)
|
ArgumentNullException.ThrowIfNull(method);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(method));
|
|
||||||
}
|
|
||||||
|
|
||||||
lock (_sendMethods)
|
lock (_sendMethods)
|
||||||
{
|
{
|
||||||
@ -418,10 +408,7 @@ public class NotifyEngine : INotifyEngine
|
|||||||
|
|
||||||
private SendResponse CreateNoticeMessageFromNotifyRequest(NotifyRequest request, string sender, IServiceScope serviceScope, out NoticeMessage noticeMessage)
|
private SendResponse CreateNoticeMessageFromNotifyRequest(NotifyRequest request, string sender, IServiceScope serviceScope, out NoticeMessage noticeMessage)
|
||||||
{
|
{
|
||||||
if (request == null)
|
ArgumentNullException.ThrowIfNull(request);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(request));
|
|
||||||
}
|
|
||||||
|
|
||||||
var recipientProvider = request.GetRecipientsProvider(serviceScope);
|
var recipientProvider = request.GetRecipientsProvider(serviceScope);
|
||||||
var recipient = request.Recipient as IDirectRecipient;
|
var recipient = request.Recipient as IDirectRecipient;
|
||||||
|
@ -100,10 +100,7 @@ public class NotifyRequest
|
|||||||
|
|
||||||
internal NotifyRequest Split(IRecipient recipient)
|
internal NotifyRequest Split(IRecipient recipient)
|
||||||
{
|
{
|
||||||
if (recipient == null)
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
|
|
||||||
var newRequest = new NotifyRequest(NotifySource, NotifyAction, ObjectID, recipient)
|
var newRequest = new NotifyRequest(NotifySource, NotifyAction, ObjectID, recipient)
|
||||||
{
|
{
|
||||||
|
@ -37,12 +37,9 @@ public class SendInterceptorSkeleton : ISendInterceptor
|
|||||||
if (string.IsNullOrEmpty(name))
|
if (string.IsNullOrEmpty(name))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Empty name.", nameof(name));
|
throw new ArgumentException("Empty name.", nameof(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sendInterceptor == null)
|
ArgumentNullException.ThrowIfNull(sendInterceptor);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(sendInterceptor));
|
|
||||||
}
|
|
||||||
|
|
||||||
_method = sendInterceptor;
|
_method = sendInterceptor;
|
||||||
Name = name;
|
Name = name;
|
||||||
|
@ -76,7 +76,8 @@ public class NoticeMessage : INoticeMessage
|
|||||||
|
|
||||||
public void AddArgument(params ITagValue[] tagValues)
|
public void AddArgument(params ITagValue[] tagValues)
|
||||||
{
|
{
|
||||||
if (tagValues == null) throw new ArgumentNullException(nameof(tagValues));
|
ArgumentNullException.ThrowIfNull(tagValues);
|
||||||
|
|
||||||
Array.ForEach(tagValues,
|
Array.ForEach(tagValues,
|
||||||
tagValue =>
|
tagValue =>
|
||||||
{
|
{
|
||||||
|
@ -98,10 +98,7 @@ class NotifyClientImpl : INotifyClient
|
|||||||
|
|
||||||
public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, string[] senderNames, bool checkSubsciption, params ITagValue[] args)
|
public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, string[] senderNames, bool checkSubsciption, params ITagValue[] args)
|
||||||
{
|
{
|
||||||
if (recipients == null)
|
ArgumentNullException.ThrowIfNull(recipients);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(recipients));
|
|
||||||
}
|
|
||||||
|
|
||||||
BeginSingleRecipientEvent("__syspreventduplicateinterceptor");
|
BeginSingleRecipientEvent("__syspreventduplicateinterceptor");
|
||||||
|
|
||||||
@ -120,14 +117,8 @@ class NotifyClientImpl : INotifyClient
|
|||||||
|
|
||||||
private NotifyRequest CreateRequest(INotifyAction action, string objectID, IRecipient recipient, ITagValue[] args, string[] senders, bool checkSubsciption)
|
private NotifyRequest CreateRequest(INotifyAction action, string objectID, IRecipient recipient, ITagValue[] args, string[] senders, bool checkSubsciption)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
if (recipient == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
|
|
||||||
var request = new NotifyRequest(_notifySource, action, objectID, recipient)
|
var request = new NotifyRequest(_notifySource, action, objectID, recipient)
|
||||||
{
|
{
|
||||||
|
@ -41,10 +41,7 @@ public abstract class NotifySource : INotifySource
|
|||||||
|
|
||||||
protected NotifySource(string id, UserManager userManager, IRecipientProvider recipientsProvider, SubscriptionManager subscriptionManager)
|
protected NotifySource(string id, UserManager userManager, IRecipientProvider recipientsProvider, SubscriptionManager subscriptionManager)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(id))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(id);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
Id = id;
|
Id = id;
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
|
@ -52,11 +52,8 @@ public abstract class PatternFormatter : IPatternFormatter
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string[] GetTags(IPattern pattern)
|
public string[] GetTags(IPattern pattern)
|
||||||
{
|
{
|
||||||
if (pattern == null)
|
ArgumentNullException.ThrowIfNull(pattern);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(pattern));
|
|
||||||
}
|
|
||||||
|
|
||||||
var findedTags = new List<string>(SearchTags(pattern.Body));
|
var findedTags = new List<string>(SearchTags(pattern.Body));
|
||||||
Array.ForEach(SearchTags(pattern.Subject), tag => { if (!findedTags.Contains(tag)) findedTags.Add(tag); });
|
Array.ForEach(SearchTags(pattern.Subject), tag => { if (!findedTags.Contains(tag)) findedTags.Add(tag); });
|
||||||
@ -64,19 +61,10 @@ public abstract class PatternFormatter : IPatternFormatter
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void FormatMessage(INoticeMessage message, ITagValue[] tagsValues)
|
public void FormatMessage(INoticeMessage message, ITagValue[] tagsValues)
|
||||||
{
|
{
|
||||||
if (message == null)
|
ArgumentNullException.ThrowIfNull(message);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(message.Pattern);
|
||||||
throw new ArgumentNullException(nameof(message));
|
ArgumentNullException.ThrowIfNull(tagsValues);
|
||||||
}
|
|
||||||
if (message.Pattern == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentException(nameof(message));
|
|
||||||
}
|
|
||||||
if (tagsValues == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(tagsValues));
|
|
||||||
}
|
|
||||||
|
|
||||||
BeforeFormat(message, tagsValues);
|
BeforeFormat(message, tagsValues);
|
||||||
|
|
||||||
|
@ -33,10 +33,7 @@ public class TagValue : ITagValue
|
|||||||
|
|
||||||
public TagValue(string tag, object value)
|
public TagValue(string tag, object value)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(tag))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(tag);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(tag));
|
|
||||||
}
|
|
||||||
|
|
||||||
Tag = tag;
|
Tag = tag;
|
||||||
Value = value;
|
Value = value;
|
||||||
|
@ -58,10 +58,7 @@ public class RecipientProviderImpl : IRecipientProvider
|
|||||||
|
|
||||||
public virtual IRecipient[] GetGroupEntries(IRecipientsGroup group)
|
public virtual IRecipient[] GetGroupEntries(IRecipientsGroup group)
|
||||||
{
|
{
|
||||||
if (group == null)
|
ArgumentNullException.ThrowIfNull(group);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(group));
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = new List<IRecipient>();
|
var result = new List<IRecipient>();
|
||||||
if (TryParseGuid(group.ID, out var groupID))
|
if (TryParseGuid(group.ID, out var groupID))
|
||||||
@ -79,10 +76,7 @@ public class RecipientProviderImpl : IRecipientProvider
|
|||||||
|
|
||||||
public virtual IRecipientsGroup[] GetGroups(IRecipient recipient)
|
public virtual IRecipientsGroup[] GetGroups(IRecipient recipient)
|
||||||
{
|
{
|
||||||
if (recipient == null)
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = new List<IRecipientsGroup>();
|
var result = new List<IRecipientsGroup>();
|
||||||
if (TryParseGuid(recipient.ID, out var recID))
|
if (TryParseGuid(recipient.ID, out var recID))
|
||||||
@ -110,10 +104,7 @@ public class RecipientProviderImpl : IRecipientProvider
|
|||||||
|
|
||||||
public virtual string[] GetRecipientAddresses(IDirectRecipient recipient, string senderName)
|
public virtual string[] GetRecipientAddresses(IDirectRecipient recipient, string senderName)
|
||||||
{
|
{
|
||||||
if (recipient == null)
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TryParseGuid(recipient.ID, out var userID))
|
if (TryParseGuid(recipient.ID, out var userID))
|
||||||
{
|
{
|
||||||
|
@ -47,14 +47,8 @@ public class TopSubscriptionProvider : ISubscriptionProvider
|
|||||||
|
|
||||||
public virtual string[] GetSubscriptionMethod(INotifyAction action, IRecipient recipient)
|
public virtual string[] GetSubscriptionMethod(INotifyAction action, IRecipient recipient)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
if (recipient == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
|
|
||||||
var senders = _subscriptionProvider.GetSubscriptionMethod(action, recipient);
|
var senders = _subscriptionProvider.GetSubscriptionMethod(action, recipient);
|
||||||
if (senders == null || senders.Length == 0)
|
if (senders == null || senders.Length == 0)
|
||||||
@ -75,10 +69,7 @@ public class TopSubscriptionProvider : ISubscriptionProvider
|
|||||||
|
|
||||||
public virtual IRecipient[] GetRecipients(INotifyAction action, string objectID)
|
public virtual IRecipient[] GetRecipients(INotifyAction action, string objectID)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
var recipents = new List<IRecipient>(5);
|
var recipents = new List<IRecipient>(5);
|
||||||
var directRecipients = _subscriptionProvider.GetRecipients(action, objectID) ?? new IRecipient[0];
|
var directRecipients = _subscriptionProvider.GetRecipients(action, objectID) ?? new IRecipient[0];
|
||||||
@ -89,14 +80,8 @@ public class TopSubscriptionProvider : ISubscriptionProvider
|
|||||||
|
|
||||||
public virtual bool IsUnsubscribe(IDirectRecipient recipient, INotifyAction action, string objectID)
|
public virtual bool IsUnsubscribe(IDirectRecipient recipient, INotifyAction action, string objectID)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
if (recipient == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
|
|
||||||
return _subscriptionProvider.IsUnsubscribe(recipient, action, objectID);
|
return _subscriptionProvider.IsUnsubscribe(recipient, action, objectID);
|
||||||
}
|
}
|
||||||
@ -104,48 +89,30 @@ public class TopSubscriptionProvider : ISubscriptionProvider
|
|||||||
|
|
||||||
public virtual void Subscribe(INotifyAction action, string objectID, IRecipient recipient)
|
public virtual void Subscribe(INotifyAction action, string objectID, IRecipient recipient)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
if (recipient == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
|
|
||||||
_subscriptionProvider.Subscribe(action, objectID, recipient);
|
_subscriptionProvider.Subscribe(action, objectID, recipient);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void UnSubscribe(INotifyAction action, string objectID, IRecipient recipient)
|
public virtual void UnSubscribe(INotifyAction action, string objectID, IRecipient recipient)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
if (recipient == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
|
|
||||||
_subscriptionProvider.UnSubscribe(action, objectID, recipient);
|
_subscriptionProvider.UnSubscribe(action, objectID, recipient);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnSubscribe(INotifyAction action, string objectID)
|
public void UnSubscribe(INotifyAction action, string objectID)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
_subscriptionProvider.UnSubscribe(action, objectID);
|
_subscriptionProvider.UnSubscribe(action, objectID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnSubscribe(INotifyAction action)
|
public void UnSubscribe(INotifyAction action)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
_subscriptionProvider.UnSubscribe(action);
|
_subscriptionProvider.UnSubscribe(action);
|
||||||
}
|
}
|
||||||
@ -161,32 +128,17 @@ public class TopSubscriptionProvider : ISubscriptionProvider
|
|||||||
|
|
||||||
public virtual void UpdateSubscriptionMethod(INotifyAction action, IRecipient recipient, params string[] senderNames)
|
public virtual void UpdateSubscriptionMethod(INotifyAction action, IRecipient recipient, params string[] senderNames)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
throw new ArgumentNullException(nameof(action));
|
ArgumentNullException.ThrowIfNull(senderNames);
|
||||||
}
|
|
||||||
if (recipient == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
if (senderNames == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(senderNames));
|
|
||||||
}
|
|
||||||
|
|
||||||
_subscriptionProvider.UpdateSubscriptionMethod(action, recipient, senderNames);
|
_subscriptionProvider.UpdateSubscriptionMethod(action, recipient, senderNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual object GetSubscriptionRecord(INotifyAction action, IRecipient recipient, string objectID)
|
public virtual object GetSubscriptionRecord(INotifyAction action, IRecipient recipient, string objectID)
|
||||||
{
|
{
|
||||||
if (recipient == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
if (action == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
var subscriptionRecord = _subscriptionProvider.GetSubscriptionRecord(action, recipient, objectID);
|
var subscriptionRecord = _subscriptionProvider.GetSubscriptionRecord(action, recipient, objectID);
|
||||||
|
|
||||||
@ -212,14 +164,8 @@ public class TopSubscriptionProvider : ISubscriptionProvider
|
|||||||
|
|
||||||
public virtual string[] GetSubscriptions(INotifyAction action, IRecipient recipient, bool checkSubscription = true)
|
public virtual string[] GetSubscriptions(INotifyAction action, IRecipient recipient, bool checkSubscription = true)
|
||||||
{
|
{
|
||||||
if (recipient == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(recipient);
|
||||||
throw new ArgumentNullException(nameof(recipient));
|
|
||||||
}
|
|
||||||
if (action == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
var objects = new List<string>();
|
var objects = new List<string>();
|
||||||
var direct = _subscriptionProvider.GetSubscriptions(action, recipient, checkSubscription) ?? Array.Empty<string>();
|
var direct = _subscriptionProvider.GetSubscriptions(action, recipient, checkSubscription) ?? Array.Empty<string>();
|
||||||
|
@ -44,15 +44,8 @@ public class AzManager
|
|||||||
ISecurityObjectProvider securityObjProvider, out ISubject denySubject,
|
ISecurityObjectProvider securityObjProvider, out ISubject denySubject,
|
||||||
out IAction denyAction)
|
out IAction denyAction)
|
||||||
{
|
{
|
||||||
if (subject == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(subject);
|
||||||
throw new ArgumentNullException(nameof(subject));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
var acl = GetAzManagerAcl(subject, action, objectId, securityObjProvider);
|
var acl = GetAzManagerAcl(subject, action, objectId, securityObjProvider);
|
||||||
denySubject = acl.DenySubject;
|
denySubject = acl.DenySubject;
|
||||||
|
@ -35,15 +35,9 @@ class PermissionProvider : IPermissionProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Ace> GetAcl(ISubject subject, IAction action, ISecurityObjectId objectId, ISecurityObjectProvider secObjProvider)
|
public IEnumerable<Ace> GetAcl(ISubject subject, IAction action, ISecurityObjectId objectId, ISecurityObjectProvider secObjProvider)
|
||||||
{
|
{
|
||||||
if (subject == null)
|
ArgumentNullException.ThrowIfNull(subject);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
throw new ArgumentNullException(nameof(subject));
|
|
||||||
}
|
|
||||||
if (action == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
return _authorizationManager
|
return _authorizationManager
|
||||||
.GetAcesWithInherits(subject.ID, action.ID, objectId, secObjProvider)
|
.GetAcesWithInherits(subject.ID, action.ID, objectId, secObjProvider)
|
||||||
|
@ -23,8 +23,6 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using static ASC.Security.Cryptography.EmailValidationKeyProvider;
|
|
||||||
|
|
||||||
namespace ASC.Security.Cryptography;
|
namespace ASC.Security.Cryptography;
|
||||||
|
|
||||||
[Scope]
|
[Scope]
|
||||||
@ -69,10 +67,7 @@ public class EmailValidationKeyProvider
|
|||||||
|
|
||||||
public string GetEmailKey(int tenantId, string email)
|
public string GetEmailKey(int tenantId, string email)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(email))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(email);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(email));
|
|
||||||
}
|
|
||||||
|
|
||||||
email = FormatEmail(tenantId, email);
|
email = FormatEmail(tenantId, email);
|
||||||
|
|
||||||
@ -84,10 +79,7 @@ public class EmailValidationKeyProvider
|
|||||||
|
|
||||||
private string FormatEmail(int tenantId, string email)
|
private string FormatEmail(int tenantId, string email)
|
||||||
{
|
{
|
||||||
if (email == null)
|
ArgumentNullException.ThrowIfNull(email);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(email));
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -116,14 +108,8 @@ public class EmailValidationKeyProvider
|
|||||||
|
|
||||||
private ValidationResult ValidateEmailKeyInternal(string email, string key, TimeSpan validInterval)
|
private ValidationResult ValidateEmailKeyInternal(string email, string key, TimeSpan validInterval)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(email))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(email);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(key);
|
||||||
throw new ArgumentNullException(nameof(email));
|
|
||||||
}
|
|
||||||
if (key == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
email = FormatEmail(_tenantManager.GetCurrentTenant().Id, email);
|
email = FormatEmail(_tenantManager.GetCurrentTenant().Id, email);
|
||||||
var parts = key.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
|
var parts = key.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
@ -41,10 +41,7 @@ public class UserFormatter : IComparer<UserInfo>
|
|||||||
|
|
||||||
public string GetUserName(UserInfo userInfo, DisplayUserNameFormat format)
|
public string GetUserName(UserInfo userInfo, DisplayUserNameFormat format)
|
||||||
{
|
{
|
||||||
if (userInfo == null)
|
ArgumentNullException.ThrowIfNull(userInfo);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(userInfo));
|
|
||||||
}
|
|
||||||
|
|
||||||
return string.Format(GetUserDisplayFormat(format), userInfo.FirstName, userInfo.LastName);
|
return string.Format(GetUserDisplayFormat(format), userInfo.FirstName, userInfo.LastName);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<NoWarn>NU1701</NoWarn>
|
<NoWarn>NU1701</NoWarn>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -46,11 +46,8 @@ public static class ActionInvoker
|
|||||||
Action<Exception> onAttemptFailure = null,
|
Action<Exception> onAttemptFailure = null,
|
||||||
int sleepMs = 1000,
|
int sleepMs = 1000,
|
||||||
bool isSleepExponential = true)
|
bool isSleepExponential = true)
|
||||||
{
|
{
|
||||||
if (action == null)
|
ArgumentNullException.ThrowIfNull(action);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
var countAttempts = 0;
|
var countAttempts = 0;
|
||||||
while (countAttempts++ < maxAttempts)
|
while (countAttempts++ < maxAttempts)
|
||||||
|
@ -49,15 +49,10 @@ public static class EnumerableExtensions
|
|||||||
public static IEnumerable<TreeNode<TEntry>> ToTree<TEntry, TKey>(this IEnumerable<TEntry> elements,
|
public static IEnumerable<TreeNode<TEntry>> ToTree<TEntry, TKey>(this IEnumerable<TEntry> elements,
|
||||||
Func<TEntry, TKey> keySelector,
|
Func<TEntry, TKey> keySelector,
|
||||||
Func<TEntry, TKey> parentKeySelector)
|
Func<TEntry, TKey> parentKeySelector)
|
||||||
{
|
{
|
||||||
if (elements == null)
|
ArgumentNullException.ThrowIfNull(elements);
|
||||||
throw new ArgumentNullException(nameof(elements));
|
ArgumentNullException.ThrowIfNull(keySelector);
|
||||||
|
ArgumentNullException.ThrowIfNull(parentKeySelector);
|
||||||
if (keySelector == null)
|
|
||||||
throw new ArgumentNullException(nameof(keySelector));
|
|
||||||
|
|
||||||
if (parentKeySelector == null)
|
|
||||||
throw new ArgumentNullException(nameof(parentKeySelector));
|
|
||||||
|
|
||||||
var dic = elements.ToDictionary(keySelector, x => new TreeNode<TEntry>(x));
|
var dic = elements.ToDictionary(keySelector, x => new TreeNode<TEntry>(x));
|
||||||
|
|
||||||
@ -75,18 +70,17 @@ public static class EnumerableExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<IEnumerable<TEntry>> MakeParts<TEntry>(this IEnumerable<TEntry> collection, int partLength)
|
public static IEnumerable<IEnumerable<TEntry>> MakeParts<TEntry>(this IEnumerable<TEntry> collection, int partLength)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(collection);
|
||||||
|
|
||||||
|
if (partLength <= 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(partLength), partLength, "Length must be positive integer");
|
||||||
|
|
||||||
|
return MakePartsIterator(collection, partLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<IEnumerable<TEntry>> MakePartsIterator<TEntry>(this IEnumerable<TEntry> collection, int partLength)
|
||||||
{
|
{
|
||||||
if (collection == null)
|
|
||||||
throw new ArgumentNullException(nameof(collection));
|
|
||||||
|
|
||||||
if (partLength <= 0)
|
|
||||||
throw new ArgumentOutOfRangeException(nameof(partLength), partLength, "Length must be positive integer");
|
|
||||||
|
|
||||||
return MakePartsIterator(collection, partLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IEnumerable<IEnumerable<TEntry>> MakePartsIterator<TEntry>(this IEnumerable<TEntry> collection, int partLength)
|
|
||||||
{
|
|
||||||
var part = new List<TEntry>(partLength);
|
var part = new List<TEntry>(partLength);
|
||||||
|
|
||||||
foreach (var entry in collection)
|
foreach (var entry in collection)
|
||||||
|
@ -1,20 +1,14 @@
|
|||||||
global using System;
|
global using System.ComponentModel.DataAnnotations;
|
||||||
global using System.Collections.Generic;
|
|
||||||
global using System.ComponentModel.DataAnnotations;
|
|
||||||
global using System.ComponentModel.DataAnnotations.Schema;
|
global using System.ComponentModel.DataAnnotations.Schema;
|
||||||
global using System.Configuration;
|
global using System.Configuration;
|
||||||
global using System.Data;
|
global using System.Data;
|
||||||
global using System.Data.Common;
|
global using System.Data.Common;
|
||||||
global using System.Diagnostics;
|
global using System.Diagnostics;
|
||||||
global using System.IO;
|
|
||||||
global using System.Linq;
|
|
||||||
global using System.Reflection;
|
global using System.Reflection;
|
||||||
global using System.Security.Cryptography;
|
global using System.Security.Cryptography;
|
||||||
global using System.ServiceModel;
|
global using System.ServiceModel;
|
||||||
global using System.Text;
|
global using System.Text;
|
||||||
global using System.Text.RegularExpressions;
|
global using System.Text.RegularExpressions;
|
||||||
global using System.Threading;
|
|
||||||
global using System.Threading.Tasks;
|
|
||||||
global using System.Xml;
|
global using System.Xml;
|
||||||
global using System.Xml.Linq;
|
global using System.Xml.Linq;
|
||||||
global using System.Xml.XPath;
|
global using System.Xml.XPath;
|
||||||
|
@ -50,9 +50,9 @@ public class BackupPortalTask : PortalTaskBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Init(int tenantId, string fromConfigPath, string toFilePath, int limit)
|
public void Init(int tenantId, string fromConfigPath, string toFilePath, int limit)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(toFilePath))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(toFilePath);
|
||||||
throw new ArgumentNullException(nameof(toFilePath));
|
|
||||||
BackupFilePath = toFilePath;
|
BackupFilePath = toFilePath;
|
||||||
Limit = limit;
|
Limit = limit;
|
||||||
Init(tenantId, fromConfigPath);
|
Init(tenantId, fromConfigPath);
|
||||||
@ -124,24 +124,24 @@ public class BackupPortalTask : PortalTaskBase
|
|||||||
var command = connection.CreateCommand();
|
var command = connection.CreateCommand();
|
||||||
command.CommandText = "show tables";
|
command.CommandText = "show tables";
|
||||||
tables = ExecuteList(command).Select(r => Convert.ToString(r[0])).ToList();
|
tables = ExecuteList(command).Select(r => Convert.ToString(r[0])).ToList();
|
||||||
}
|
}
|
||||||
/* using (var dbManager = new DbManager("default", 100000))
|
/* using (var dbManager = new DbManager("default", 100000))
|
||||||
{
|
{
|
||||||
tables = dbManager.ExecuteList("show tables;").Select(r => Convert.ToString(r[0])).ToList();
|
tables = dbManager.ExecuteList("show tables;").Select(r => Convert.ToString(r[0])).ToList();
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
var stepscount = tables.Count * 4; // (schema + data) * (dump + zip)
|
var stepscount = tables.Count * 4; // (schema + data) * (dump + zip)
|
||||||
if (ProcessStorage)
|
if (ProcessStorage)
|
||||||
{
|
{
|
||||||
var tenants = _tenantManager.GetTenants(false).Select(r => r.Id);
|
var tenants = _tenantManager.GetTenants(false).Select(r => r.Id);
|
||||||
foreach (var t in tenants)
|
foreach (var t in tenants)
|
||||||
{
|
{
|
||||||
files.AddRange(GetFiles(t));
|
files.AddRange(GetFiles(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
stepscount += files.Count * 2 + 1;
|
stepscount += files.Count * 2 + 1;
|
||||||
Logger.Debug("files:" + files.Count);
|
Logger.Debug("files:" + files.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetStepsCount(stepscount);
|
SetStepsCount(stepscount);
|
||||||
|
|
||||||
@ -200,9 +200,9 @@ public class BackupPortalTask : PortalTaskBase
|
|||||||
|
|
||||||
private IEnumerable<BackupFileInfo> GetFiles(int tenantId)
|
private IEnumerable<BackupFileInfo> GetFiles(int tenantId)
|
||||||
{
|
{
|
||||||
var files = GetFilesToProcess(tenantId).ToList();
|
var files = GetFilesToProcess(tenantId).ToList();
|
||||||
var exclude = BackupRecordContext.Backups.AsQueryable().Where(b => b.TenantId == tenantId && b.StorageType == 0 && b.StoragePath != null).ToList();
|
var exclude = BackupRecordContext.Backups.AsQueryable().Where(b => b.TenantId == tenantId && b.StorageType == 0 && b.StoragePath != null).ToList();
|
||||||
files = files.Where(f => !exclude.Any(e => f.Path.Replace('\\', '/').Contains($"/file_{e.StoragePath}/"))).ToList();
|
files = files.Where(f => !exclude.Any(e => f.Path.Replace('\\', '/').Contains($"/file_{e.StoragePath}/"))).ToList();
|
||||||
return files;
|
return files;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -214,16 +214,16 @@ public class BackupPortalTask : PortalTaskBase
|
|||||||
Logger.DebugFormat("dump table scheme start {0}", t);
|
Logger.DebugFormat("dump table scheme start {0}", t);
|
||||||
using (var connection = DbFactory.OpenConnection())
|
using (var connection = DbFactory.OpenConnection())
|
||||||
{
|
{
|
||||||
var command = connection.CreateCommand();
|
var command = connection.CreateCommand();
|
||||||
command.CommandText = $"SHOW CREATE TABLE `{t}`";
|
command.CommandText = $"SHOW CREATE TABLE `{t}`";
|
||||||
var createScheme = ExecuteList(command);
|
var createScheme = ExecuteList(command);
|
||||||
var creates = new StringBuilder();
|
var creates = new StringBuilder();
|
||||||
creates.Append($"DROP TABLE IF EXISTS `{t}`;");
|
creates.Append($"DROP TABLE IF EXISTS `{t}`;");
|
||||||
creates.AppendLine();
|
creates.AppendLine();
|
||||||
creates.Append(createScheme
|
creates.Append(createScheme
|
||||||
.Select(r => Convert.ToString(r[1]))
|
.Select(r => Convert.ToString(r[1]))
|
||||||
.FirstOrDefault());
|
.FirstOrDefault());
|
||||||
creates.Append(';');
|
creates.Append(';');
|
||||||
|
|
||||||
var path = CrossPlatform.PathCombine(dir, t);
|
var path = CrossPlatform.PathCombine(dir, t);
|
||||||
using (var stream = File.OpenWrite(path))
|
using (var stream = File.OpenWrite(path))
|
||||||
@ -278,8 +278,8 @@ public class BackupPortalTask : PortalTaskBase
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.DebugFormat("dump table data start {0}", t);
|
Logger.DebugFormat("dump table data start {0}", t);
|
||||||
bool searchWithPrimary;
|
bool searchWithPrimary;
|
||||||
string primaryIndex;
|
string primaryIndex;
|
||||||
var primaryIndexStep = 0;
|
var primaryIndexStep = 0;
|
||||||
var primaryIndexStart = 0;
|
var primaryIndexStart = 0;
|
||||||
@ -288,8 +288,8 @@ public class BackupPortalTask : PortalTaskBase
|
|||||||
|
|
||||||
using (var connection = DbFactory.OpenConnection())
|
using (var connection = DbFactory.OpenConnection())
|
||||||
{
|
{
|
||||||
var command = connection.CreateCommand();
|
var command = connection.CreateCommand();
|
||||||
command.CommandText = string.Format($"SHOW COLUMNS FROM `{t}`");
|
command.CommandText = string.Format($"SHOW COLUMNS FROM `{t}`");
|
||||||
columns = ExecuteList(command).Select(r => "`" + Convert.ToString(r[0]) + "`").ToList();
|
columns = ExecuteList(command).Select(r => "`" + Convert.ToString(r[0]) + "`").ToList();
|
||||||
if (command.CommandText.Contains("tenants_quota") || command.CommandText.Contains("webstudio_settings"))
|
if (command.CommandText.Contains("tenants_quota") || command.CommandText.Contains("webstudio_settings"))
|
||||||
{
|
{
|
||||||
@ -299,16 +299,16 @@ public class BackupPortalTask : PortalTaskBase
|
|||||||
|
|
||||||
using (var connection = DbFactory.OpenConnection())
|
using (var connection = DbFactory.OpenConnection())
|
||||||
{
|
{
|
||||||
var command = connection.CreateCommand();
|
var command = connection.CreateCommand();
|
||||||
command.CommandText = $"select COLUMN_NAME from information_schema.`COLUMNS` where TABLE_SCHEMA = '{connection.Database}' and TABLE_NAME = '{t}' and COLUMN_KEY = 'PRI' and DATA_TYPE = 'int'";
|
command.CommandText = $"select COLUMN_NAME from information_schema.`COLUMNS` where TABLE_SCHEMA = '{connection.Database}' and TABLE_NAME = '{t}' and COLUMN_KEY = 'PRI' and DATA_TYPE = 'int'";
|
||||||
primaryIndex = ExecuteList(command).ConvertAll(r => Convert.ToString(r[0])).FirstOrDefault();
|
primaryIndex = ExecuteList(command).ConvertAll(r => Convert.ToString(r[0])).FirstOrDefault();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var connection = DbFactory.OpenConnection())
|
using (var connection = DbFactory.OpenConnection())
|
||||||
{
|
{
|
||||||
var command = connection.CreateCommand();
|
var command = connection.CreateCommand();
|
||||||
command.CommandText = $"SHOW INDEXES FROM {t} WHERE COLUMN_NAME='{primaryIndex}' AND seq_in_index=1";
|
command.CommandText = $"SHOW INDEXES FROM {t} WHERE COLUMN_NAME='{primaryIndex}' AND seq_in_index=1";
|
||||||
var isLeft = ExecuteList(command);
|
var isLeft = ExecuteList(command);
|
||||||
searchWithPrimary = isLeft.Count == 1;
|
searchWithPrimary = isLeft.Count == 1;
|
||||||
}
|
}
|
||||||
@ -316,8 +316,8 @@ public class BackupPortalTask : PortalTaskBase
|
|||||||
if (searchWithPrimary)
|
if (searchWithPrimary)
|
||||||
{
|
{
|
||||||
using var connection = DbFactory.OpenConnection();
|
using var connection = DbFactory.OpenConnection();
|
||||||
var command = connection.CreateCommand();
|
var command = connection.CreateCommand();
|
||||||
command.CommandText = $"select max({primaryIndex}), min({primaryIndex}) from {t}";
|
command.CommandText = $"select max({primaryIndex}), min({primaryIndex}) from {t}";
|
||||||
var minMax = ExecuteList(command).ConvertAll(r => new Tuple<int, int>(Convert.ToInt32(r[0]), Convert.ToInt32(r[1]))).FirstOrDefault();
|
var minMax = ExecuteList(command).ConvertAll(r => new Tuple<int, int>(Convert.ToInt32(r[0]), Convert.ToInt32(r[1]))).FirstOrDefault();
|
||||||
primaryIndexStart = minMax.Item2;
|
primaryIndexStart = minMax.Item2;
|
||||||
primaryIndexStep = (minMax.Item1 - minMax.Item2) / count;
|
primaryIndexStep = (minMax.Item1 - minMax.Item2) / count;
|
||||||
@ -397,8 +397,8 @@ public class BackupPortalTask : PortalTaskBase
|
|||||||
private void SaveToFile(string path, string t, IReadOnlyCollection<string> columns, List<object[]> data)
|
private void SaveToFile(string path, string t, IReadOnlyCollection<string> columns, List<object[]> data)
|
||||||
{
|
{
|
||||||
Logger.DebugFormat("save to file {0}", t);
|
Logger.DebugFormat("save to file {0}", t);
|
||||||
List<object[]> portion;
|
List<object[]> portion;
|
||||||
while ((portion = data.Take(BatchLimit).ToList()).Count > 0)
|
while ((portion = data.Take(BatchLimit).ToList()).Count > 0)
|
||||||
{
|
{
|
||||||
using (var sw = new StreamWriter(path, true))
|
using (var sw = new StreamWriter(path, true))
|
||||||
using (var writer = new JsonTextWriter(sw))
|
using (var writer = new JsonTextWriter(sw))
|
||||||
@ -414,9 +414,9 @@ public class BackupPortalTask : PortalTaskBase
|
|||||||
sw.Write("(");
|
sw.Write("(");
|
||||||
|
|
||||||
for (var i = 0; i < obj.Length; i++)
|
for (var i = 0; i < obj.Length; i++)
|
||||||
{
|
{
|
||||||
var value = obj[i];
|
var value = obj[i];
|
||||||
if (value is byte[] byteArray)
|
if (value is byte[] byteArray)
|
||||||
{
|
{
|
||||||
sw.Write("0x");
|
sw.Write("0x");
|
||||||
foreach (var b in byteArray)
|
foreach (var b in byteArray)
|
||||||
@ -426,8 +426,8 @@ public class BackupPortalTask : PortalTaskBase
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var ser = new JsonSerializer();
|
var ser = new JsonSerializer();
|
||||||
ser.Serialize(writer, value);
|
ser.Serialize(writer, value);
|
||||||
}
|
}
|
||||||
if (i != obj.Length - 1)
|
if (i != obj.Length - 1)
|
||||||
{
|
{
|
||||||
@ -518,9 +518,9 @@ public class BackupPortalTask : PortalTaskBase
|
|||||||
if (!WorkContext.IsMono && filePath.Length > MaxLength)
|
if (!WorkContext.IsMono && filePath.Length > MaxLength)
|
||||||
{
|
{
|
||||||
filePath = @"\\?\" + filePath;
|
filePath = @"\\?\" + filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var fileStream = await storage.GetReadStreamAsync(file.Domain, file.Path))
|
using (var fileStream = await storage.GetReadStreamAsync(file.Domain, file.Path))
|
||||||
using (var tmpFile = File.OpenWrite(filePath))
|
using (var tmpFile = File.OpenWrite(filePath))
|
||||||
{
|
{
|
||||||
await fileStream.CopyToAsync(tmpFile);
|
await fileStream.CopyToAsync(tmpFile);
|
||||||
@ -553,10 +553,10 @@ public class BackupPortalTask : PortalTaskBase
|
|||||||
|
|
||||||
private List<IGrouping<string, BackupFileInfo>> GetFilesGroup()
|
private List<IGrouping<string, BackupFileInfo>> GetFilesGroup()
|
||||||
{
|
{
|
||||||
var files = GetFilesToProcess(TenantId).ToList();
|
var files = GetFilesToProcess(TenantId).ToList();
|
||||||
var exclude = BackupRecordContext.Backups.AsQueryable().Where(b => b.TenantId == TenantId && b.StorageType == 0 && b.StoragePath != null).ToList();
|
var exclude = BackupRecordContext.Backups.AsQueryable().Where(b => b.TenantId == TenantId && b.StorageType == 0 && b.StoragePath != null).ToList();
|
||||||
|
|
||||||
files = files.Where(f => !exclude.Any(e => f.Path.Replace('\\', '/').Contains($"/file_{e.StoragePath}/"))).ToList();
|
files = files.Where(f => !exclude.Any(e => f.Path.Replace('\\', '/').Contains($"/file_{e.StoragePath}/"))).ToList();
|
||||||
|
|
||||||
return files.GroupBy(file => file.Module).ToList();
|
return files.GroupBy(file => file.Module).ToList();
|
||||||
}
|
}
|
||||||
@ -616,9 +616,9 @@ public class BackupPortalTask : PortalTaskBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
Logger.DebugFormat("end saving table {0}", table.Name);
|
Logger.DebugFormat("end saving table {0}", table.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetCurrentStepProgress((int)(++tablesProcessed * 100 / (double)tablesCount));
|
SetCurrentStepProgress((int)(++tablesProcessed * 100 / (double)tablesCount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -640,8 +640,8 @@ public class BackupPortalTask : PortalTaskBase
|
|||||||
var file1 = file;
|
var file1 = file;
|
||||||
ActionInvoker.Try(state =>
|
ActionInvoker.Try(state =>
|
||||||
{
|
{
|
||||||
var f = (BackupFileInfo)state;
|
var f = (BackupFileInfo)state;
|
||||||
using var fileStream = storage.GetReadStreamAsync(f.Domain, f.Path).Result;
|
using var fileStream = storage.GetReadStreamAsync(f.Domain, f.Path).Result;
|
||||||
writer.WriteEntry(file1.GetZipKey(), fileStream);
|
writer.WriteEntry(file1.GetZipKey(), fileStream);
|
||||||
}, file, 5, error => Logger.WarnFormat("can't backup file ({0}:{1}): {2}", file1.Module, file1.Path, error));
|
}, file, 5, error => Logger.WarnFormat("can't backup file ({0}:{1}): {2}", file1.Module, file1.Path, error));
|
||||||
|
|
||||||
|
@ -62,10 +62,7 @@ public class RestorePortalTask : PortalTaskBase
|
|||||||
|
|
||||||
public void Init(string toConfigPath, string fromFilePath, int tenantId = -1, ColumnMapper columnMapper = null, string upgradesPath = null)
|
public void Init(string toConfigPath, string fromFilePath, int tenantId = -1, ColumnMapper columnMapper = null, string upgradesPath = null)
|
||||||
{
|
{
|
||||||
if (fromFilePath == null)
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(fromFilePath);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(fromFilePath));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!File.Exists(fromFilePath))
|
if (!File.Exists(fromFilePath))
|
||||||
{
|
{
|
||||||
@ -291,8 +288,8 @@ public class RestorePortalTask : PortalTaskBase
|
|||||||
}
|
}
|
||||||
using var stream = dataReader.GetEntry(key);
|
using var stream = dataReader.GetEntry(key);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
storage.SaveAsync(file.Domain, adjustedPath, module != null ? module.PrepareData(key, stream, _columnMapper) : stream).Wait();
|
storage.SaveAsync(file.Domain, adjustedPath, module != null ? module.PrepareData(key, stream, _columnMapper) : stream).Wait();
|
||||||
}
|
}
|
||||||
catch (Exception error)
|
catch (Exception error)
|
||||||
{
|
{
|
||||||
@ -322,14 +319,14 @@ public class RestorePortalTask : PortalTaskBase
|
|||||||
|
|
||||||
private void DoDeleteStorage(IEnumerable<string> storageModules, IEnumerable<Tenant> tenants)
|
private void DoDeleteStorage(IEnumerable<string> storageModules, IEnumerable<Tenant> tenants)
|
||||||
{
|
{
|
||||||
Logger.Debug("begin delete storage");
|
Logger.Debug("begin delete storage");
|
||||||
|
|
||||||
foreach (var tenant in tenants)
|
foreach (var tenant in tenants)
|
||||||
{
|
{
|
||||||
foreach (var module in storageModules)
|
foreach (var module in storageModules)
|
||||||
{
|
{
|
||||||
var storage = StorageFactory.GetStorage(ConfigPath, tenant.Id.ToString(), module);
|
var storage = StorageFactory.GetStorage(ConfigPath, tenant.Id.ToString(), module);
|
||||||
var domains = StorageFactoryConfig.GetDomainList(ConfigPath, module).ToList();
|
var domains = StorageFactoryConfig.GetDomainList(ConfigPath, module).ToList();
|
||||||
|
|
||||||
domains.Add(string.Empty); //instead storage.DeleteFiles("\\", "*.*", true);
|
domains.Add(string.Empty); //instead storage.DeleteFiles("\\", "*.*", true);
|
||||||
|
|
||||||
@ -337,10 +334,10 @@ public class RestorePortalTask : PortalTaskBase
|
|||||||
{
|
{
|
||||||
ActionInvoker.Try(
|
ActionInvoker.Try(
|
||||||
state =>
|
state =>
|
||||||
{
|
{
|
||||||
if (storage.IsDirectoryAsync((string)state).Result)
|
if (storage.IsDirectoryAsync((string)state).Result)
|
||||||
{
|
{
|
||||||
storage.DeleteFilesAsync((string)state, "\\", "*.*", true).Wait();
|
storage.DeleteFilesAsync((string)state, "\\", "*.*", true).Wait();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
domain,
|
domain,
|
||||||
@ -381,10 +378,10 @@ public class RestorePortalTask : PortalTaskBase
|
|||||||
"where id = '{2}'",
|
"where id = '{2}'",
|
||||||
(int)TenantStatus.Active,
|
(int)TenantStatus.Active,
|
||||||
DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"),
|
DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||||
tenantId);
|
tenantId);
|
||||||
|
|
||||||
var command = connection.CreateCommand().WithTimeout(120);
|
var command = connection.CreateCommand().WithTimeout(120);
|
||||||
command.CommandText = commandText;
|
command.CommandText = commandText;
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
global using System;
|
global using System.Globalization;
|
||||||
global using System.Collections.Generic;
|
|
||||||
global using System.Globalization;
|
|
||||||
global using System.Security.Cryptography;
|
global using System.Security.Cryptography;
|
||||||
global using System.Text;
|
global using System.Text;
|
||||||
|
|
||||||
@ -19,5 +17,4 @@ global using ASC.Web.Studio.Core.Notify;
|
|||||||
global using Microsoft.AspNetCore.Http;
|
global using Microsoft.AspNetCore.Http;
|
||||||
global using Microsoft.Extensions.DependencyInjection;
|
global using Microsoft.Extensions.DependencyInjection;
|
||||||
global using Microsoft.Extensions.Options;
|
global using Microsoft.Extensions.Options;
|
||||||
global using Microsoft.Extensions.Primitives;
|
global using Microsoft.Extensions.Primitives;
|
||||||
|
|
@ -3,6 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
|
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||||
|
@ -71,26 +71,23 @@ public abstract class BaseStorage : IDataStore
|
|||||||
return DomainsExpires.ContainsKey(domain) ? DomainsExpires[domain] : DomainsExpires[string.Empty];
|
return DomainsExpires.ContainsKey(domain) ? DomainsExpires[domain] : DomainsExpires[string.Empty];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<Uri> GetUriAsync(string path)
|
public Task<Uri> GetUriAsync(string path)
|
||||||
{
|
{
|
||||||
return GetUriAsync(string.Empty, path);
|
return GetUriAsync(string.Empty, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<Uri> GetUriAsync(string domain, string path)
|
public Task<Uri> GetUriAsync(string domain, string path)
|
||||||
{
|
{
|
||||||
return GetPreSignedUriAsync(domain, path, TimeSpan.MaxValue, null);
|
return GetPreSignedUriAsync(domain, path, TimeSpan.MaxValue, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<Uri> GetPreSignedUriAsync(string domain, string path, TimeSpan expire, IEnumerable<string> headers)
|
public Task<Uri> GetPreSignedUriAsync(string domain, string path, TimeSpan expire, IEnumerable<string> headers)
|
||||||
{
|
{
|
||||||
if (path == null)
|
ArgumentNullException.ThrowIfNull(path);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(Tenant) && IsSupportInternalUri)
|
if (string.IsNullOrEmpty(Tenant) && IsSupportInternalUri)
|
||||||
{
|
{
|
||||||
return GetInternalUriAsync(domain, path, expire, headers);
|
return GetInternalUriAsync(domain, path, expire, headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
var headerAttr = string.Empty;
|
var headerAttr = string.Empty;
|
||||||
@ -109,16 +106,16 @@ public abstract class BaseStorage : IDataStore
|
|||||||
{
|
{
|
||||||
var expireString = expire.TotalMinutes.ToString(CultureInfo.InvariantCulture);
|
var expireString = expire.TotalMinutes.ToString(CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
int currentTenantId;
|
int currentTenantId;
|
||||||
var currentTenant = TenantManager.GetCurrentTenant(false);
|
var currentTenant = TenantManager.GetCurrentTenant(false);
|
||||||
if (currentTenant != null)
|
if (currentTenant != null)
|
||||||
{
|
{
|
||||||
currentTenantId = currentTenant.Id;
|
currentTenantId = currentTenant.Id;
|
||||||
}
|
}
|
||||||
else if (!TenantPath.TryGetTenant(Tenant, out currentTenantId))
|
else if (!TenantPath.TryGetTenant(Tenant, out currentTenantId))
|
||||||
{
|
{
|
||||||
currentTenantId = 0;
|
currentTenantId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var auth = TemailValidationKeyProvider.GetEmailKey(currentTenantId, path.Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar) + "." + headerAttr + "." + expireString);
|
var auth = TemailValidationKeyProvider.GetEmailKey(currentTenantId, path.Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar) + "." + headerAttr + "." + expireString);
|
||||||
query = $"{(path.IndexOf('?') >= 0 ? "&" : "?")}{Constants.QueryExpire}={expireString}&{Constants.QueryAuth}={auth}";
|
query = $"{(path.IndexOf('?') >= 0 ? "&" : "?")}{Constants.QueryExpire}={expireString}&{Constants.QueryAuth}={auth}";
|
||||||
@ -139,169 +136,169 @@ public abstract class BaseStorage : IDataStore
|
|||||||
new MonoUri(virtualPath, virtualPath.LocalPath.TrimEnd('/') + EnsureLeadingSlash(path.Replace('\\', '/')) + query) :
|
new MonoUri(virtualPath, virtualPath.LocalPath.TrimEnd('/') + EnsureLeadingSlash(path.Replace('\\', '/')) + query) :
|
||||||
new MonoUri(virtualPath.ToString().TrimEnd('/') + EnsureLeadingSlash(path.Replace('\\', '/')) + query, UriKind.Relative);
|
new MonoUri(virtualPath.ToString().TrimEnd('/') + EnsureLeadingSlash(path.Replace('\\', '/')) + query, UriKind.Relative);
|
||||||
|
|
||||||
return Task.FromResult<Uri>(uri);
|
return Task.FromResult<Uri>(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Task<Uri> GetInternalUriAsync(string domain, string path, TimeSpan expire, IEnumerable<string> headers)
|
public virtual Task<Uri> GetInternalUriAsync(string domain, string path, TimeSpan expire, IEnumerable<string> headers)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Task<Stream> GetReadStreamAsync(string domain, string path);
|
public abstract Task<Stream> GetReadStreamAsync(string domain, string path);
|
||||||
|
|
||||||
public abstract Task<Stream> GetReadStreamAsync(string domain, string path, int offset);
|
public abstract Task<Stream> GetReadStreamAsync(string domain, string path, int offset);
|
||||||
|
|
||||||
public abstract Task<Uri> SaveAsync(string domain, string path, Stream stream);
|
public abstract Task<Uri> SaveAsync(string domain, string path, Stream stream);
|
||||||
public abstract Task<Uri> SaveAsync(string domain, string path, Stream stream, ACL acl);
|
public abstract Task<Uri> SaveAsync(string domain, string path, Stream stream, ACL acl);
|
||||||
|
|
||||||
public Task<Uri> SaveAsync(string domain, string path, Stream stream, string attachmentFileName)
|
public Task<Uri> SaveAsync(string domain, string path, Stream stream, string attachmentFileName)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(attachmentFileName))
|
if (!string.IsNullOrEmpty(attachmentFileName))
|
||||||
{
|
{
|
||||||
return SaveWithAutoAttachmentAsync(domain, path, stream, attachmentFileName);
|
return SaveWithAutoAttachmentAsync(domain, path, stream, attachmentFileName);
|
||||||
}
|
}
|
||||||
return SaveAsync(domain, path, stream);
|
return SaveAsync(domain, path, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Task<Uri> SaveWithAutoAttachmentAsync(string domain, string path, Stream stream, string attachmentFileName);
|
protected abstract Task<Uri> SaveWithAutoAttachmentAsync(string domain, string path, Stream stream, string attachmentFileName);
|
||||||
|
|
||||||
|
|
||||||
public abstract Task<Uri> SaveAsync(string domain, string path, Stream stream, string contentType,
|
public abstract Task<Uri> SaveAsync(string domain, string path, Stream stream, string contentType,
|
||||||
string contentDisposition);
|
string contentDisposition);
|
||||||
public abstract Task<Uri> SaveAsync(string domain, string path, Stream stream, string contentEncoding, int cacheDays);
|
public abstract Task<Uri> SaveAsync(string domain, string path, Stream stream, string contentEncoding, int cacheDays);
|
||||||
|
|
||||||
#region chunking
|
#region chunking
|
||||||
|
|
||||||
public virtual Task<string> InitiateChunkedUploadAsync(string domain, string path)
|
public virtual Task<string> InitiateChunkedUploadAsync(string domain, string path)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Task<string> UploadChunkAsync(string domain, string path, string uploadId, Stream stream, long defaultChunkSize, int chunkNumber, long chunkLength)
|
public virtual Task<string> UploadChunkAsync(string domain, string path, string uploadId, Stream stream, long defaultChunkSize, int chunkNumber, long chunkLength)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Task<Uri> FinalizeChunkedUploadAsync(string domain, string path, string uploadId, Dictionary<int, string> eTags)
|
public virtual Task<Uri> FinalizeChunkedUploadAsync(string domain, string path, string uploadId, Dictionary<int, string> eTags)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Task AbortChunkedUploadAsync(string domain, string path, string uploadId)
|
public virtual Task AbortChunkedUploadAsync(string domain, string path, string uploadId)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public abstract Task DeleteAsync(string domain, string path);
|
public abstract Task DeleteAsync(string domain, string path);
|
||||||
public abstract Task DeleteFilesAsync(string domain, string folderPath, string pattern, bool recursive);
|
public abstract Task DeleteFilesAsync(string domain, string folderPath, string pattern, bool recursive);
|
||||||
public abstract Task DeleteFilesAsync(string domain, List<string> paths);
|
public abstract Task DeleteFilesAsync(string domain, List<string> paths);
|
||||||
public abstract Task DeleteFilesAsync(string domain, string folderPath, DateTime fromDate, DateTime toDate);
|
public abstract Task DeleteFilesAsync(string domain, string folderPath, DateTime fromDate, DateTime toDate);
|
||||||
public abstract Task MoveDirectoryAsync(string srcdomain, string srcdir, string newdomain, string newdir);
|
public abstract Task MoveDirectoryAsync(string srcdomain, string srcdir, string newdomain, string newdir);
|
||||||
public abstract Task<Uri> MoveAsync(string srcdomain, string srcpath, string newdomain, string newpath, bool quotaCheckFileSize = true);
|
public abstract Task<Uri> MoveAsync(string srcdomain, string srcpath, string newdomain, string newpath, bool quotaCheckFileSize = true);
|
||||||
public abstract Task<Uri> SaveTempAsync(string domain, out string assignedPath, Stream stream);
|
public abstract Task<Uri> SaveTempAsync(string domain, out string assignedPath, Stream stream);
|
||||||
public abstract IAsyncEnumerable<string> ListDirectoriesRelativeAsync(string domain, string path, bool recursive);
|
public abstract IAsyncEnumerable<string> ListDirectoriesRelativeAsync(string domain, string path, bool recursive);
|
||||||
public abstract IAsyncEnumerable<string> ListFilesRelativeAsync(string domain, string path, string pattern, bool recursive);
|
public abstract IAsyncEnumerable<string> ListFilesRelativeAsync(string domain, string path, string pattern, bool recursive);
|
||||||
|
|
||||||
public abstract Task<bool> IsFileAsync(string domain, string path);
|
public abstract Task<bool> IsFileAsync(string domain, string path);
|
||||||
public abstract Task<bool> IsDirectoryAsync(string domain, string path);
|
public abstract Task<bool> IsDirectoryAsync(string domain, string path);
|
||||||
public abstract Task DeleteDirectoryAsync(string domain, string path);
|
public abstract Task DeleteDirectoryAsync(string domain, string path);
|
||||||
public abstract Task<long> GetFileSizeAsync(string domain, string path);
|
public abstract Task<long> GetFileSizeAsync(string domain, string path);
|
||||||
public abstract Task<long> GetDirectorySizeAsync(string domain, string path);
|
public abstract Task<long> GetDirectorySizeAsync(string domain, string path);
|
||||||
public abstract Task<long> ResetQuotaAsync(string domain);
|
public abstract Task<long> ResetQuotaAsync(string domain);
|
||||||
public abstract Task<long> GetUsedQuotaAsync(string domain);
|
public abstract Task<long> GetUsedQuotaAsync(string domain);
|
||||||
public abstract Task<Uri> CopyAsync(string srcdomain, string path, string newdomain, string newpath);
|
public abstract Task<Uri> CopyAsync(string srcdomain, string path, string newdomain, string newpath);
|
||||||
public abstract Task CopyDirectoryAsync(string srcdomain, string dir, string newdomain, string newdir);
|
public abstract Task CopyDirectoryAsync(string srcdomain, string dir, string newdomain, string newdir);
|
||||||
|
|
||||||
public Task<Stream> GetReadStreamAsync(string path)
|
public Task<Stream> GetReadStreamAsync(string path)
|
||||||
{
|
{
|
||||||
return GetReadStreamAsync(string.Empty, path);
|
return GetReadStreamAsync(string.Empty, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<Uri> SaveAsync(string path, Stream stream, string attachmentFileName)
|
public Task<Uri> SaveAsync(string path, Stream stream, string attachmentFileName)
|
||||||
{
|
{
|
||||||
return SaveAsync(string.Empty, path, stream, attachmentFileName);
|
return SaveAsync(string.Empty, path, stream, attachmentFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<Uri> SaveAsync(string path, Stream stream)
|
public Task<Uri> SaveAsync(string path, Stream stream)
|
||||||
{
|
{
|
||||||
return SaveAsync(string.Empty, path, stream);
|
return SaveAsync(string.Empty, path, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteAsync(string path)
|
public async Task DeleteAsync(string path)
|
||||||
{
|
{
|
||||||
await DeleteAsync(string.Empty, path);
|
await DeleteAsync(string.Empty, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteFilesAsync(string folderPath, string pattern, bool recursive)
|
public async Task DeleteFilesAsync(string folderPath, string pattern, bool recursive)
|
||||||
{
|
{
|
||||||
await DeleteFilesAsync(string.Empty, folderPath, pattern, recursive);
|
await DeleteFilesAsync(string.Empty, folderPath, pattern, recursive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<Uri> MoveAsync(string srcpath, string newdomain, string newpath)
|
public Task<Uri> MoveAsync(string srcpath, string newdomain, string newpath)
|
||||||
{
|
{
|
||||||
return MoveAsync(string.Empty, srcpath, newdomain, newpath);
|
return MoveAsync(string.Empty, srcpath, newdomain, newpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<Uri> SaveTempAsync(out string assignedPath, Stream stream)
|
public Task<Uri> SaveTempAsync(out string assignedPath, Stream stream)
|
||||||
{
|
{
|
||||||
return SaveTempAsync(string.Empty, out assignedPath, stream);
|
return SaveTempAsync(string.Empty, out assignedPath, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IAsyncEnumerable<string> ListDirectoriesRelativeAsync(string path, bool recursive)
|
public IAsyncEnumerable<string> ListDirectoriesRelativeAsync(string path, bool recursive)
|
||||||
{
|
{
|
||||||
return ListDirectoriesRelativeAsync(string.Empty, path, recursive);
|
return ListDirectoriesRelativeAsync(string.Empty, path, recursive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IAsyncEnumerable<Uri> ListFilesAsync(string path, string pattern, bool recursive)
|
public IAsyncEnumerable<Uri> ListFilesAsync(string path, string pattern, bool recursive)
|
||||||
{
|
{
|
||||||
return ListFilesAsync(string.Empty, path, pattern, recursive);
|
return ListFilesAsync(string.Empty, path, pattern, recursive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async IAsyncEnumerable<Uri> ListFilesAsync(string domain, string path, string pattern, bool recursive)
|
public async IAsyncEnumerable<Uri> ListFilesAsync(string domain, string path, string pattern, bool recursive)
|
||||||
{
|
{
|
||||||
var filePaths = ListFilesRelativeAsync(domain, path, pattern, recursive);
|
var filePaths = ListFilesRelativeAsync(domain, path, pattern, recursive);
|
||||||
|
|
||||||
await foreach(var paths in filePaths)
|
await foreach (var paths in filePaths)
|
||||||
{
|
{
|
||||||
yield return await GetUriAsync(domain, CrossPlatform.PathCombine(PathUtils.Normalize(path), paths));
|
yield return await GetUriAsync(domain, CrossPlatform.PathCombine(PathUtils.Normalize(path), paths));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<bool> IsFileAsync(string path)
|
|
||||||
{
|
|
||||||
return IsFileAsync(string.Empty, path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<bool> IsDirectoryAsync(string path)
|
public Task<bool> IsFileAsync(string path)
|
||||||
{
|
{
|
||||||
return IsDirectoryAsync(string.Empty, path);
|
return IsFileAsync(string.Empty, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteDirectoryAsync(string path)
|
public Task<bool> IsDirectoryAsync(string path)
|
||||||
{
|
{
|
||||||
await DeleteDirectoryAsync(string.Empty, path);
|
return IsDirectoryAsync(string.Empty, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<long> GetFileSizeAsync(string path)
|
public async Task DeleteDirectoryAsync(string path)
|
||||||
{
|
{
|
||||||
return GetFileSizeAsync(string.Empty, path);
|
await DeleteDirectoryAsync(string.Empty, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<long> GetDirectorySizeAsync(string path)
|
public Task<long> GetFileSizeAsync(string path)
|
||||||
{
|
{
|
||||||
return GetDirectorySizeAsync(string.Empty, path);
|
return GetFileSizeAsync(string.Empty, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<Uri> CopyAsync(string path, string newdomain, string newpath)
|
public Task<long> GetDirectorySizeAsync(string path)
|
||||||
{
|
{
|
||||||
return CopyAsync(string.Empty, path, newdomain, newpath);
|
return GetDirectorySizeAsync(string.Empty, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CopyDirectoryAsync(string dir, string newdomain, string newdir)
|
public Task<Uri> CopyAsync(string path, string newdomain, string newpath)
|
||||||
{
|
{
|
||||||
await CopyDirectoryAsync(string.Empty, dir, newdomain, newdir);
|
return CopyAsync(string.Empty, path, newdomain, newpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task CopyDirectoryAsync(string dir, string newdomain, string newdir)
|
||||||
|
{
|
||||||
|
await CopyDirectoryAsync(string.Empty, dir, newdomain, newdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IDataStore Configure(string tenant, Handler handlerConfig, Module moduleConfig, IDictionary<string, string> props)
|
public virtual IDataStore Configure(string tenant, Handler handlerConfig, Module moduleConfig, IDictionary<string, string> props)
|
||||||
@ -316,13 +313,13 @@ public abstract class BaseStorage : IDataStore
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Task<string> SavePrivateAsync(string domain, string path, Stream stream, DateTime expires);
|
public abstract Task<string> SavePrivateAsync(string domain, string path, Stream stream, DateTime expires);
|
||||||
public abstract Task DeleteExpiredAsync(string domain, string path, TimeSpan oldThreshold);
|
public abstract Task DeleteExpiredAsync(string domain, string path, TimeSpan oldThreshold);
|
||||||
|
|
||||||
public abstract string GetUploadForm(string domain, string directoryPath, string redirectTo, long maxUploadSize,
|
public abstract string GetUploadForm(string domain, string directoryPath, string redirectTo, long maxUploadSize,
|
||||||
string contentType, string contentDisposition, string submitLabel);
|
string contentType, string contentDisposition, string submitLabel);
|
||||||
|
|
||||||
public abstract Task<string> GetUploadedUrlAsync(string domain, string directoryPath);
|
public abstract Task<string> GetUploadedUrlAsync(string domain, string directoryPath);
|
||||||
public abstract string GetUploadUrl();
|
public abstract string GetUploadUrl();
|
||||||
|
|
||||||
public abstract string GetPostParams(string domain, string directoryPath, long maxUploadSize, string contentType,
|
public abstract string GetPostParams(string domain, string directoryPath, long maxUploadSize, string contentType,
|
||||||
|
@ -55,25 +55,10 @@ public class CrossModuleTransferUtility
|
|||||||
|
|
||||||
public Task CopyFileAsync(string srcDomain, string srcPath, string destDomain, string destPath)
|
public Task CopyFileAsync(string srcDomain, string srcPath, string destDomain, string destPath)
|
||||||
{
|
{
|
||||||
if (srcDomain == null)
|
ArgumentNullException.ThrowIfNull(srcDomain);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(srcPath);
|
||||||
throw new ArgumentNullException(nameof(srcDomain));
|
ArgumentNullException.ThrowIfNull(destDomain);
|
||||||
}
|
ArgumentNullException.ThrowIfNull(destPath);
|
||||||
|
|
||||||
if (srcPath == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(srcPath));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (destDomain == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(destDomain));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (destPath == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(destPath));
|
|
||||||
}
|
|
||||||
|
|
||||||
return InternalCopyFileAsync(srcDomain, srcPath, destDomain, destPath);
|
return InternalCopyFileAsync(srcDomain, srcPath, destDomain, destPath);
|
||||||
}
|
}
|
||||||
|
@ -82,27 +82,21 @@ public class DiscDataStore : BaseStorage
|
|||||||
|
|
||||||
public string GetPhysicalPath(string domain, string path)
|
public string GetPhysicalPath(string domain, string path)
|
||||||
{
|
{
|
||||||
if (path == null)
|
ArgumentNullException.ThrowIfNull(path);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
var pathMap = GetPath(domain);
|
var pathMap = GetPath(domain);
|
||||||
|
|
||||||
return (pathMap.PhysicalPath + EnsureLeadingSlash(path)).Replace('\\', '/');
|
return (pathMap.PhysicalPath + EnsureLeadingSlash(path)).Replace('\\', '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<Stream> GetReadStreamAsync(string domain, string path)
|
public override Task<Stream> GetReadStreamAsync(string domain, string path)
|
||||||
{
|
{
|
||||||
return Task.FromResult(GetReadStream(domain, path, true));
|
return Task.FromResult(GetReadStream(domain, path, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream GetReadStream(string domain, string path, bool withDecription)
|
public Stream GetReadStream(string domain, string path, bool withDecription)
|
||||||
{
|
{
|
||||||
if (path == null)
|
ArgumentNullException.ThrowIfNull(path);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
var target = GetTarget(domain, path);
|
var target = GetTarget(domain, path);
|
||||||
|
|
||||||
@ -116,10 +110,7 @@ public class DiscDataStore : BaseStorage
|
|||||||
|
|
||||||
public override Task<Stream> GetReadStreamAsync(string domain, string path, int offset)
|
public override Task<Stream> GetReadStreamAsync(string domain, string path, int offset)
|
||||||
{
|
{
|
||||||
if (path == null)
|
ArgumentNullException.ThrowIfNull(path);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
var target = GetTarget(domain, path);
|
var target = GetTarget(domain, path);
|
||||||
|
|
||||||
@ -131,24 +122,24 @@ public class DiscDataStore : BaseStorage
|
|||||||
stream.Seek(offset, SeekOrigin.Begin);
|
stream.Seek(offset, SeekOrigin.Begin);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.FromResult(stream);
|
return Task.FromResult(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new FileNotFoundException("File not found", Path.GetFullPath(target));
|
throw new FileNotFoundException("File not found", Path.GetFullPath(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override Task<Uri> SaveAsync(string domain, string path, Stream stream, string contentType, string contentDisposition)
|
public override Task<Uri> SaveAsync(string domain, string path, Stream stream, string contentType, string contentDisposition)
|
||||||
{
|
{
|
||||||
return SaveAsync(domain, path, stream);
|
return SaveAsync(domain, path, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<Uri> SaveAsync(string domain, string path, Stream stream, string contentEncoding, int cacheDays)
|
public override Task<Uri> SaveAsync(string domain, string path, Stream stream, string contentEncoding, int cacheDays)
|
||||||
{
|
{
|
||||||
return SaveAsync(domain, path, stream);
|
return SaveAsync(domain, path, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<Uri> SaveAsync(string domain, string path, Stream stream)
|
public override Task<Uri> SaveAsync(string domain, string path, Stream stream)
|
||||||
{
|
{
|
||||||
Logger.Debug("Save " + path);
|
Logger.Debug("Save " + path);
|
||||||
|
|
||||||
@ -158,23 +149,16 @@ public class DiscDataStore : BaseStorage
|
|||||||
QuotaController.QuotaUsedCheck(buffered.Length);
|
QuotaController.QuotaUsedCheck(buffered.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path == null)
|
ArgumentNullException.ThrowIfNull(path);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(stream);
|
||||||
throw new ArgumentNullException(nameof(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buffered == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(stream));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Try seek to start
|
//Try seek to start
|
||||||
return InternalSaveAsync(domain, path, buffered);
|
return InternalSaveAsync(domain, path, buffered);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Uri> InternalSaveAsync(string domain, string path, Stream buffered)
|
private async Task<Uri> InternalSaveAsync(string domain, string path, Stream buffered)
|
||||||
{
|
{
|
||||||
//Try seek to start
|
//Try seek to start
|
||||||
if (buffered.CanSeek)
|
if (buffered.CanSeek)
|
||||||
{
|
{
|
||||||
buffered.Seek(0, SeekOrigin.Begin);
|
buffered.Seek(0, SeekOrigin.Begin);
|
||||||
@ -195,7 +179,7 @@ public class DiscDataStore : BaseStorage
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
using var fs = File.Open(target, FileMode.Create);
|
using var fs = File.Open(target, FileMode.Create);
|
||||||
await buffered.CopyToAsync(fs);
|
await buffered.CopyToAsync(fs);
|
||||||
fslen = fs.Length;
|
fslen = fs.Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,30 +187,30 @@ public class DiscDataStore : BaseStorage
|
|||||||
|
|
||||||
_crypt.EncryptFile(target);
|
_crypt.EncryptFile(target);
|
||||||
|
|
||||||
return await GetUriAsync(domain, path);
|
return await GetUriAsync(domain, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<Uri> SaveAsync(string domain, string path, Stream stream, ACL acl)
|
public override Task<Uri> SaveAsync(string domain, string path, Stream stream, ACL acl)
|
||||||
{
|
{
|
||||||
return SaveAsync(domain, path, stream);
|
return SaveAsync(domain, path, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region chunking
|
#region chunking
|
||||||
|
|
||||||
public override async Task<string> UploadChunkAsync(string domain, string path, string uploadId, Stream stream, long defaultChunkSize, int chunkNumber, long chunkLength)
|
public override async Task<string> UploadChunkAsync(string domain, string path, string uploadId, Stream stream, long defaultChunkSize, int chunkNumber, long chunkLength)
|
||||||
{
|
{
|
||||||
var target = GetTarget(domain, path);
|
var target = GetTarget(domain, path);
|
||||||
var mode = chunkNumber == 0 ? FileMode.Create : FileMode.Append;
|
var mode = chunkNumber == 0 ? FileMode.Create : FileMode.Append;
|
||||||
|
|
||||||
using (var fs = new FileStream(target, mode))
|
using (var fs = new FileStream(target, mode))
|
||||||
{
|
{
|
||||||
await stream.CopyToAsync(fs);
|
await stream.CopyToAsync(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return string.Format("{0}_{1}", chunkNumber, uploadId);
|
return string.Format("{0}_{1}", chunkNumber, uploadId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<Uri> FinalizeChunkedUploadAsync(string domain, string path, string uploadId, Dictionary<int, string> eTags)
|
public override Task<Uri> FinalizeChunkedUploadAsync(string domain, string path, string uploadId, Dictionary<int, string> eTags)
|
||||||
{
|
{
|
||||||
var target = GetTarget(domain, path);
|
var target = GetTarget(domain, path);
|
||||||
|
|
||||||
@ -243,27 +227,24 @@ public class DiscDataStore : BaseStorage
|
|||||||
|
|
||||||
_crypt.EncryptFile(target);
|
_crypt.EncryptFile(target);
|
||||||
|
|
||||||
return GetUriAsync(domain, path);
|
return GetUriAsync(domain, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task AbortChunkedUploadAsync(string domain, string path, string uploadId)
|
public override Task AbortChunkedUploadAsync(string domain, string path, string uploadId)
|
||||||
{
|
{
|
||||||
var target = GetTarget(domain, path);
|
var target = GetTarget(domain, path);
|
||||||
if (File.Exists(target))
|
if (File.Exists(target))
|
||||||
{
|
{
|
||||||
File.Delete(target);
|
File.Delete(target);
|
||||||
}
|
}
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public override Task DeleteAsync(string domain, string path)
|
public override Task DeleteAsync(string domain, string path)
|
||||||
{
|
{
|
||||||
if (path == null)
|
ArgumentNullException.ThrowIfNull(path);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
var target = GetTarget(domain, path);
|
var target = GetTarget(domain, path);
|
||||||
|
|
||||||
@ -273,7 +254,7 @@ public class DiscDataStore : BaseStorage
|
|||||||
File.Delete(target);
|
File.Delete(target);
|
||||||
|
|
||||||
QuotaUsedDelete(domain, size);
|
QuotaUsedDelete(domain, size);
|
||||||
return Task.CompletedTask; ;
|
return Task.CompletedTask; ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -281,12 +262,9 @@ public class DiscDataStore : BaseStorage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task DeleteFilesAsync(string domain, List<string> paths)
|
public override Task DeleteFilesAsync(string domain, List<string> paths)
|
||||||
{
|
{
|
||||||
if (paths == null)
|
ArgumentNullException.ThrowIfNull(paths);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(paths));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var path in paths)
|
foreach (var path in paths)
|
||||||
{
|
{
|
||||||
@ -303,15 +281,12 @@ public class DiscDataStore : BaseStorage
|
|||||||
QuotaUsedDelete(domain, size);
|
QuotaUsedDelete(domain, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task DeleteFilesAsync(string domain, string folderPath, string pattern, bool recursive)
|
public override Task DeleteFilesAsync(string domain, string folderPath, string pattern, bool recursive)
|
||||||
{
|
{
|
||||||
if (folderPath == null)
|
ArgumentNullException.ThrowIfNull(folderPath);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(folderPath));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return dirs
|
//Return dirs
|
||||||
var targetDir = GetTarget(domain, folderPath);
|
var targetDir = GetTarget(domain, folderPath);
|
||||||
@ -324,20 +299,17 @@ public class DiscDataStore : BaseStorage
|
|||||||
File.Delete(entry);
|
File.Delete(entry);
|
||||||
QuotaUsedDelete(domain, size);
|
QuotaUsedDelete(domain, size);
|
||||||
}
|
}
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new DirectoryNotFoundException($"Directory '{targetDir}' not found");
|
throw new DirectoryNotFoundException($"Directory '{targetDir}' not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task DeleteFilesAsync(string domain, string folderPath, DateTime fromDate, DateTime toDate)
|
public override Task DeleteFilesAsync(string domain, string folderPath, DateTime fromDate, DateTime toDate)
|
||||||
{
|
{
|
||||||
if (folderPath == null)
|
ArgumentNullException.ThrowIfNull(folderPath);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(folderPath));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return dirs
|
//Return dirs
|
||||||
var targetDir = GetTarget(domain, folderPath);
|
var targetDir = GetTarget(domain, folderPath);
|
||||||
@ -357,13 +329,13 @@ public class DiscDataStore : BaseStorage
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new DirectoryNotFoundException($"Directory '{targetDir}' not found");
|
throw new DirectoryNotFoundException($"Directory '{targetDir}' not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task MoveDirectoryAsync(string srcdomain, string srcdir, string newdomain, string newdir)
|
public override Task MoveDirectoryAsync(string srcdomain, string srcdir, string newdomain, string newdir)
|
||||||
{
|
{
|
||||||
var target = GetTarget(srcdomain, srcdir);
|
var target = GetTarget(srcdomain, srcdir);
|
||||||
var newtarget = GetTarget(newdomain, newdir);
|
var newtarget = GetTarget(newdomain, newdir);
|
||||||
@ -376,20 +348,13 @@ public class DiscDataStore : BaseStorage
|
|||||||
|
|
||||||
Directory.Move(target, newtarget);
|
Directory.Move(target, newtarget);
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<Uri> MoveAsync(string srcdomain, string srcpath, string newdomain, string newpath, bool quotaCheckFileSize = true)
|
public override Task<Uri> MoveAsync(string srcdomain, string srcpath, string newdomain, string newpath, bool quotaCheckFileSize = true)
|
||||||
{
|
{
|
||||||
if (srcpath == null)
|
ArgumentNullException.ThrowIfNull(srcpath);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(newpath);
|
||||||
throw new ArgumentNullException(nameof(srcpath));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newpath == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(srcpath));
|
|
||||||
}
|
|
||||||
|
|
||||||
var target = GetTarget(srcdomain, srcpath);
|
var target = GetTarget(srcdomain, srcpath);
|
||||||
var newtarget = GetTarget(newdomain, newpath);
|
var newtarget = GetTarget(newdomain, newpath);
|
||||||
@ -418,15 +383,12 @@ public class DiscDataStore : BaseStorage
|
|||||||
{
|
{
|
||||||
throw new FileNotFoundException("File not found", Path.GetFullPath(target));
|
throw new FileNotFoundException("File not found", Path.GetFullPath(target));
|
||||||
}
|
}
|
||||||
return GetUriAsync(newdomain, newpath);
|
return GetUriAsync(newdomain, newpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<bool> IsDirectoryAsync(string domain, string path)
|
public override Task<bool> IsDirectoryAsync(string domain, string path)
|
||||||
{
|
{
|
||||||
if (path == null)
|
ArgumentNullException.ThrowIfNull(path);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return dirs
|
//Return dirs
|
||||||
var targetDir = GetTarget(domain, path);
|
var targetDir = GetTarget(domain, path);
|
||||||
@ -434,15 +396,12 @@ public class DiscDataStore : BaseStorage
|
|||||||
{
|
{
|
||||||
targetDir += Path.DirectorySeparatorChar;
|
targetDir += Path.DirectorySeparatorChar;
|
||||||
}
|
}
|
||||||
return Task.FromResult(!string.IsNullOrEmpty(targetDir) && Directory.Exists(targetDir));
|
return Task.FromResult(!string.IsNullOrEmpty(targetDir) && Directory.Exists(targetDir));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task DeleteDirectoryAsync(string domain, string path)
|
public override Task DeleteDirectoryAsync(string domain, string path)
|
||||||
{
|
{
|
||||||
if (path == null)
|
ArgumentNullException.ThrowIfNull(path);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return dirs
|
//Return dirs
|
||||||
var targetDir = GetTarget(domain, path);
|
var targetDir = GetTarget(domain, path);
|
||||||
@ -452,12 +411,12 @@ public class DiscDataStore : BaseStorage
|
|||||||
throw new Exception("targetDir is null");
|
throw new Exception("targetDir is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!targetDir.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
if (!targetDir.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||||
{
|
{
|
||||||
targetDir += Path.DirectorySeparatorChar;
|
targetDir += Path.DirectorySeparatorChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Directory.Exists(targetDir)) return Task.CompletedTask;
|
if (!Directory.Exists(targetDir)) return Task.CompletedTask;
|
||||||
|
|
||||||
var entries = Directory.GetFiles(targetDir, "*.*", SearchOption.AllDirectories);
|
var entries = Directory.GetFiles(targetDir, "*.*", SearchOption.AllDirectories);
|
||||||
var size = entries.Select(entry => _crypt.GetFileSize(entry)).Sum();
|
var size = entries.Select(entry => _crypt.GetFileSize(entry)).Sum();
|
||||||
@ -469,59 +428,56 @@ public class DiscDataStore : BaseStorage
|
|||||||
Directory.Delete(targetDir, true);
|
Directory.Delete(targetDir, true);
|
||||||
|
|
||||||
QuotaUsedDelete(domain, size);
|
QuotaUsedDelete(domain, size);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<long> GetFileSizeAsync(string domain, string path)
|
public override Task<long> GetFileSizeAsync(string domain, string path)
|
||||||
{
|
{
|
||||||
var target = GetTarget(domain, path);
|
var target = GetTarget(domain, path);
|
||||||
|
|
||||||
if (File.Exists(target))
|
if (File.Exists(target))
|
||||||
{
|
{
|
||||||
return Task.FromResult(_crypt.GetFileSize(target));
|
return Task.FromResult(_crypt.GetFileSize(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new FileNotFoundException("file not found " + target);
|
throw new FileNotFoundException("file not found " + target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<long> GetDirectorySizeAsync(string domain, string path)
|
public override Task<long> GetDirectorySizeAsync(string domain, string path)
|
||||||
{
|
{
|
||||||
var target = GetTarget(domain, path);
|
var target = GetTarget(domain, path);
|
||||||
|
|
||||||
if (Directory.Exists(target))
|
if (Directory.Exists(target))
|
||||||
{
|
{
|
||||||
return Task.FromResult(Directory.GetFiles(target, "*.*", SearchOption.AllDirectories)
|
return Task.FromResult(Directory.GetFiles(target, "*.*", SearchOption.AllDirectories)
|
||||||
.Select(entry => _crypt.GetFileSize(entry))
|
.Select(entry => _crypt.GetFileSize(entry))
|
||||||
.Sum());
|
.Sum());
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new FileNotFoundException("directory not found " + target);
|
throw new FileNotFoundException("directory not found " + target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<Uri> SaveTempAsync(string domain, out string assignedPath, Stream stream)
|
public override Task<Uri> SaveTempAsync(string domain, out string assignedPath, Stream stream)
|
||||||
{
|
{
|
||||||
assignedPath = Guid.NewGuid().ToString();
|
assignedPath = Guid.NewGuid().ToString();
|
||||||
return SaveAsync(domain, assignedPath, stream);
|
return SaveAsync(domain, assignedPath, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<string> SavePrivateAsync(string domain, string path, Stream stream, DateTime expires)
|
public override async Task<string> SavePrivateAsync(string domain, string path, Stream stream, DateTime expires)
|
||||||
{
|
{
|
||||||
var result = await SaveAsync(domain, path, stream);
|
var result = await SaveAsync(domain, path, stream);
|
||||||
return result.ToString();
|
return result.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task DeleteExpiredAsync(string domain, string folderPath, TimeSpan oldThreshold)
|
public override Task DeleteExpiredAsync(string domain, string folderPath, TimeSpan oldThreshold)
|
||||||
{
|
{
|
||||||
if (folderPath == null)
|
ArgumentNullException.ThrowIfNull(folderPath);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(folderPath));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return dirs
|
//Return dirs
|
||||||
var targetDir = GetTarget(domain, folderPath);
|
var targetDir = GetTarget(domain, folderPath);
|
||||||
if (!Directory.Exists(targetDir))
|
if (!Directory.Exists(targetDir))
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
var entries = Directory.GetFiles(targetDir, "*.*", SearchOption.TopDirectoryOnly);
|
var entries = Directory.GetFiles(targetDir, "*.*", SearchOption.TopDirectoryOnly);
|
||||||
@ -537,7 +493,7 @@ public class DiscDataStore : BaseStorage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string GetUploadForm(string domain, string directoryPath, string redirectTo, long maxUploadSize, string contentType, string contentDisposition, string submitLabel)
|
public override string GetUploadForm(string domain, string directoryPath, string redirectTo, long maxUploadSize, string contentType, string contentDisposition, string submitLabel)
|
||||||
@ -545,7 +501,7 @@ public class DiscDataStore : BaseStorage
|
|||||||
throw new NotSupportedException("This operation supported only on s3 storage");
|
throw new NotSupportedException("This operation supported only on s3 storage");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<string> GetUploadedUrlAsync(string domain, string directoryPath)
|
public override Task<string> GetUploadedUrlAsync(string domain, string directoryPath)
|
||||||
{
|
{
|
||||||
throw new NotSupportedException("This operation supported only on s3 storage");
|
throw new NotSupportedException("This operation supported only on s3 storage");
|
||||||
}
|
}
|
||||||
@ -560,12 +516,9 @@ public class DiscDataStore : BaseStorage
|
|||||||
throw new NotSupportedException("This operation supported only on s3 storage");
|
throw new NotSupportedException("This operation supported only on s3 storage");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IAsyncEnumerable<string> ListDirectoriesRelativeAsync(string domain, string path, bool recursive)
|
public override IAsyncEnumerable<string> ListDirectoriesRelativeAsync(string domain, string path, bool recursive)
|
||||||
{
|
{
|
||||||
if (path == null)
|
ArgumentNullException.ThrowIfNull(path);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return dirs
|
//Return dirs
|
||||||
var targetDir = GetTarget(domain, path);
|
var targetDir = GetTarget(domain, path);
|
||||||
@ -577,20 +530,17 @@ public class DiscDataStore : BaseStorage
|
|||||||
if (Directory.Exists(targetDir))
|
if (Directory.Exists(targetDir))
|
||||||
{
|
{
|
||||||
var entries = Directory.GetDirectories(targetDir, "*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
|
var entries = Directory.GetDirectories(targetDir, "*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
|
||||||
var tmp = Array.ConvertAll(
|
var tmp = Array.ConvertAll(
|
||||||
entries,
|
entries,
|
||||||
x => x.Substring(targetDir.Length));
|
x => x.Substring(targetDir.Length));
|
||||||
return tmp.ToAsyncEnumerable();
|
return tmp.ToAsyncEnumerable();
|
||||||
}
|
}
|
||||||
return AsyncEnumerable.Empty<string>();
|
return AsyncEnumerable.Empty<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IAsyncEnumerable<string> ListFilesRelativeAsync(string domain, string path, string pattern, bool recursive)
|
public override IAsyncEnumerable<string> ListFilesRelativeAsync(string domain, string path, string pattern, bool recursive)
|
||||||
{
|
{
|
||||||
if (path == null)
|
ArgumentNullException.ThrowIfNull(path);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return dirs
|
//Return dirs
|
||||||
var targetDir = GetTarget(domain, path);
|
var targetDir = GetTarget(domain, path);
|
||||||
@ -602,39 +552,36 @@ public class DiscDataStore : BaseStorage
|
|||||||
if (Directory.Exists(targetDir))
|
if (Directory.Exists(targetDir))
|
||||||
{
|
{
|
||||||
var entries = Directory.GetFiles(targetDir, pattern, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
|
var entries = Directory.GetFiles(targetDir, pattern, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
|
||||||
var tmp = Array.ConvertAll(
|
var tmp = Array.ConvertAll(
|
||||||
entries,
|
entries,
|
||||||
x => x.Substring(targetDir.Length));
|
x => x.Substring(targetDir.Length));
|
||||||
return tmp.ToAsyncEnumerable();
|
return tmp.ToAsyncEnumerable();
|
||||||
}
|
}
|
||||||
return AsyncEnumerable.Empty<string>();
|
return AsyncEnumerable.Empty<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<bool> IsFileAsync(string domain, string path)
|
public override Task<bool> IsFileAsync(string domain, string path)
|
||||||
{
|
{
|
||||||
if (path == null)
|
ArgumentNullException.ThrowIfNull(path);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return dirs
|
//Return dirs
|
||||||
var target = GetTarget(domain, path);
|
var target = GetTarget(domain, path);
|
||||||
var result = File.Exists(target);
|
var result = File.Exists(target);
|
||||||
return Task.FromResult(result);
|
return Task.FromResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<long> ResetQuotaAsync(string domain)
|
public override async Task<long> ResetQuotaAsync(string domain)
|
||||||
{
|
{
|
||||||
if (QuotaController != null)
|
if (QuotaController != null)
|
||||||
{
|
{
|
||||||
var size = await GetUsedQuotaAsync(domain);
|
var size = await GetUsedQuotaAsync(domain);
|
||||||
QuotaController.QuotaUsedSet(Modulename, domain, DataList.GetData(domain), size);
|
QuotaController.QuotaUsedSet(Modulename, domain, DataList.GetData(domain), size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<long> GetUsedQuotaAsync(string domain)
|
public override Task<long> GetUsedQuotaAsync(string domain)
|
||||||
{
|
{
|
||||||
var target = GetTarget(domain, string.Empty);
|
var target = GetTarget(domain, string.Empty);
|
||||||
long size = 0;
|
long size = 0;
|
||||||
@ -644,20 +591,13 @@ public class DiscDataStore : BaseStorage
|
|||||||
var entries = Directory.GetFiles(target, "*.*", SearchOption.AllDirectories);
|
var entries = Directory.GetFiles(target, "*.*", SearchOption.AllDirectories);
|
||||||
size = entries.Select(entry => _crypt.GetFileSize(entry)).Sum();
|
size = entries.Select(entry => _crypt.GetFileSize(entry)).Sum();
|
||||||
}
|
}
|
||||||
return Task.FromResult(size);
|
return Task.FromResult(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<Uri> CopyAsync(string srcdomain, string srcpath, string newdomain, string newpath)
|
public override Task<Uri> CopyAsync(string srcdomain, string srcpath, string newdomain, string newpath)
|
||||||
{
|
{
|
||||||
if (srcpath == null)
|
ArgumentNullException.ThrowIfNull(srcpath);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(newpath);
|
||||||
throw new ArgumentNullException(nameof(srcpath));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newpath == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(srcpath));
|
|
||||||
}
|
|
||||||
|
|
||||||
var target = GetTarget(srcdomain, srcpath);
|
var target = GetTarget(srcdomain, srcpath);
|
||||||
var newtarget = GetTarget(newdomain, newpath);
|
var newtarget = GetTarget(newdomain, newpath);
|
||||||
@ -678,10 +618,10 @@ public class DiscDataStore : BaseStorage
|
|||||||
{
|
{
|
||||||
throw new FileNotFoundException("File not found", Path.GetFullPath(target));
|
throw new FileNotFoundException("File not found", Path.GetFullPath(target));
|
||||||
}
|
}
|
||||||
return GetUriAsync(newdomain, newpath);
|
return GetUriAsync(newdomain, newpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task CopyDirectoryAsync(string srcdomain, string srcdir, string newdomain, string newdir)
|
public override Task CopyDirectoryAsync(string srcdomain, string srcdir, string newdomain, string newdir)
|
||||||
{
|
{
|
||||||
var target = GetTarget(srcdomain, srcdir);
|
var target = GetTarget(srcdomain, srcdir);
|
||||||
var newtarget = GetTarget(newdomain, newdir);
|
var newtarget = GetTarget(newdomain, newdir);
|
||||||
@ -690,7 +630,7 @@ public class DiscDataStore : BaseStorage
|
|||||||
var diTarget = new DirectoryInfo(newtarget);
|
var diTarget = new DirectoryInfo(newtarget);
|
||||||
|
|
||||||
CopyAll(diSource, diTarget, newdomain);
|
CopyAll(diSource, diTarget, newdomain);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -701,10 +641,7 @@ public class DiscDataStore : BaseStorage
|
|||||||
|
|
||||||
public Stream GetWriteStream(string domain, string path, FileMode fileMode)
|
public Stream GetWriteStream(string domain, string path, FileMode fileMode)
|
||||||
{
|
{
|
||||||
if (path == null)
|
ArgumentNullException.ThrowIfNull(path);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
var target = GetTarget(domain, path);
|
var target = GetTarget(domain, path);
|
||||||
CreateDirectory(target);
|
CreateDirectory(target);
|
||||||
@ -714,10 +651,7 @@ public class DiscDataStore : BaseStorage
|
|||||||
|
|
||||||
public void Decrypt(string domain, string path)
|
public void Decrypt(string domain, string path)
|
||||||
{
|
{
|
||||||
if (path == null)
|
ArgumentNullException.ThrowIfNull(path);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
var target = GetTarget(domain, path);
|
var target = GetTarget(domain, path);
|
||||||
|
|
||||||
@ -731,10 +665,10 @@ public class DiscDataStore : BaseStorage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Task<Uri> SaveWithAutoAttachmentAsync(string domain, string path, Stream stream, string attachmentFileName)
|
protected override Task<Uri> SaveWithAutoAttachmentAsync(string domain, string path, Stream stream, string attachmentFileName)
|
||||||
{
|
{
|
||||||
return SaveAsync(domain, path, stream);
|
return SaveAsync(domain, path, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CopyAll(DirectoryInfo source, DirectoryInfo target, string newdomain)
|
private void CopyAll(DirectoryInfo source, DirectoryInfo target, string newdomain)
|
||||||
{
|
{
|
||||||
@ -765,7 +699,7 @@ public class DiscDataStore : BaseStorage
|
|||||||
{
|
{
|
||||||
if (domain != null && _mappedPaths.TryGetValue(domain, out var value))
|
if (domain != null && _mappedPaths.TryGetValue(domain, out var value))
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _mappedPaths[string.Empty].AppendDomain(domain);
|
return _mappedPaths[string.Empty].AppendDomain(domain);
|
||||||
@ -802,10 +736,7 @@ public class DiscDataStore : BaseStorage
|
|||||||
|
|
||||||
public void Encrypt(string domain, string path)
|
public void Encrypt(string domain, string path)
|
||||||
{
|
{
|
||||||
if (path == null)
|
ArgumentNullException.ThrowIfNull(path);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
var target = GetTarget(domain, path);
|
var target = GetTarget(domain, path);
|
||||||
|
|
||||||
|
@ -1,19 +1,12 @@
|
|||||||
global using System;
|
global using System.Collections.Concurrent;
|
||||||
global using System.Collections.Concurrent;
|
|
||||||
global using System.Collections.Generic;
|
|
||||||
global using System.Globalization;
|
global using System.Globalization;
|
||||||
global using System.IO;
|
|
||||||
global using System.Linq;
|
|
||||||
global using System.Net;
|
global using System.Net;
|
||||||
global using System.Net.Http;
|
|
||||||
global using System.Runtime.Serialization;
|
global using System.Runtime.Serialization;
|
||||||
global using System.Security.Cryptography;
|
global using System.Security.Cryptography;
|
||||||
global using System.ServiceModel;
|
global using System.ServiceModel;
|
||||||
global using System.Text;
|
global using System.Text;
|
||||||
global using System.Text.Json;
|
global using System.Text.Json;
|
||||||
global using System.Text.Json.Serialization;
|
global using System.Text.Json.Serialization;
|
||||||
global using System.Threading;
|
|
||||||
global using System.Threading.Tasks;
|
|
||||||
global using System.Web;
|
global using System.Web;
|
||||||
|
|
||||||
global using Amazon;
|
global using Amazon;
|
||||||
|
@ -29,10 +29,7 @@ public static class TenantPath
|
|||||||
{
|
{
|
||||||
public static string CreatePath(string tenant)
|
public static string CreatePath(string tenant)
|
||||||
{
|
{
|
||||||
if (tenant == null)
|
ArgumentNullException.ThrowIfNull(tenant);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(tenant));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (long.TryParse(tenant, NumberStyles.Integer, CultureInfo.InvariantCulture, out var tenantId))
|
if (long.TryParse(tenant, NumberStyles.Integer, CultureInfo.InvariantCulture, out var tenantId))
|
||||||
{
|
{
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<NoWarn>NU1701</NoWarn>
|
<NoWarn>NU1701</NoWarn>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
global using System;
|
global using System.Data;
|
||||||
global using System.Collections.Generic;
|
|
||||||
global using System.Data;
|
|
||||||
global using System.Diagnostics;
|
global using System.Diagnostics;
|
||||||
global using System.Globalization;
|
global using System.Globalization;
|
||||||
global using System.IO;
|
|
||||||
global using System.Linq;
|
|
||||||
global using System.Net;
|
global using System.Net;
|
||||||
global using System.Net.Http;
|
|
||||||
global using System.Net.Http.Headers;
|
global using System.Net.Http.Headers;
|
||||||
global using System.Reflection;
|
global using System.Reflection;
|
||||||
global using System.Runtime.Serialization;
|
global using System.Runtime.Serialization;
|
||||||
@ -14,8 +9,6 @@ global using System.Security.Cryptography.Pkcs;
|
|||||||
global using System.Security.Cryptography.X509Certificates;
|
global using System.Security.Cryptography.X509Certificates;
|
||||||
global using System.Text;
|
global using System.Text;
|
||||||
global using System.Text.Json.Serialization;
|
global using System.Text.Json.Serialization;
|
||||||
global using System.Threading;
|
|
||||||
global using System.Threading.Tasks;
|
|
||||||
global using System.Web;
|
global using System.Web;
|
||||||
global using System.Xml.Linq;
|
global using System.Xml.Linq;
|
||||||
global using System.Xml.XPath;
|
global using System.Xml.XPath;
|
||||||
|
@ -107,20 +107,9 @@ public class OAuth20TokenHelper
|
|||||||
var clientSecret = loginProvider.ClientSecret;
|
var clientSecret = loginProvider.ClientSecret;
|
||||||
var redirectUri = loginProvider.RedirectUri;
|
var redirectUri = loginProvider.RedirectUri;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(authCode))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(authCode);
|
||||||
{
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(clientID);
|
||||||
throw new ArgumentNullException(nameof(authCode));
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(clientSecret);
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(clientID))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(clientID));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(clientSecret))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(clientSecret));
|
|
||||||
}
|
|
||||||
|
|
||||||
var data = $"code={HttpUtility.UrlEncode(authCode)}&client_id={HttpUtility.UrlEncode(clientID)}&client_secret={HttpUtility.UrlEncode(clientSecret)}";
|
var data = $"code={HttpUtility.UrlEncode(authCode)}&client_id={HttpUtility.UrlEncode(clientID)}&client_secret={HttpUtility.UrlEncode(clientSecret)}";
|
||||||
|
|
||||||
|
@ -31,10 +31,7 @@ public static class RequestHelper
|
|||||||
|
|
||||||
public static string PerformRequest(string uri, string contentType = "", string method = "GET", string body = "", Dictionary<string, string> headers = null, int timeout = 30000)
|
public static string PerformRequest(string uri, string contentType = "", string method = "GET", string body = "", Dictionary<string, string> headers = null, int timeout = 30000)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(uri))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(uri);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(uri));
|
|
||||||
}
|
|
||||||
|
|
||||||
var request = new HttpRequestMessage();
|
var request = new HttpRequestMessage();
|
||||||
request.RequestUri = new Uri(uri);
|
request.RequestUri = new Uri(uri);
|
||||||
|
@ -73,20 +73,9 @@ public class DocuSignLoginProvider : Consumer, IOAuthProvider
|
|||||||
|
|
||||||
public OAuth20Token GetAccessToken(string authCode)
|
public OAuth20Token GetAccessToken(string authCode)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(authCode))
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(authCode);
|
||||||
{
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(ClientID);
|
||||||
throw new ArgumentNullException(nameof(authCode));
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(ClientSecret);
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(ClientID))
|
|
||||||
{
|
|
||||||
throw new ArgumentException(nameof(ClientID));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(ClientSecret))
|
|
||||||
{
|
|
||||||
throw new ArgumentException(nameof(ClientSecret));
|
|
||||||
}
|
|
||||||
|
|
||||||
var data = $"grant_type=authorization_code&code={authCode}";
|
var data = $"grant_type=authorization_code&code={authCode}";
|
||||||
var headers = new Dictionary<string, string> { { "Authorization", AuthHeader } };
|
var headers = new Dictionary<string, string> { { "Authorization", AuthHeader } };
|
||||||
|
@ -204,10 +204,7 @@ public class LoginProfile
|
|||||||
|
|
||||||
public static bool HasProfile(HttpRequest request)
|
public static bool HasProfile(HttpRequest request)
|
||||||
{
|
{
|
||||||
if (request == null)
|
ArgumentNullException.ThrowIfNull(request);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(request));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Uri(request.GetDisplayUrl()).HasProfile();
|
return new Uri(request.GetDisplayUrl()).HasProfile();
|
||||||
}
|
}
|
||||||
@ -239,10 +236,7 @@ public class LoginProfile
|
|||||||
|
|
||||||
internal void SetField(string name, string value)
|
internal void SetField(string name, string value)
|
||||||
{
|
{
|
||||||
if (name == null)
|
ArgumentNullException.ThrowIfNull(name);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(value))
|
if (!string.IsNullOrEmpty(value))
|
||||||
{
|
{
|
||||||
@ -328,10 +322,7 @@ public class LoginProfile
|
|||||||
|
|
||||||
internal void FromSerializedString(string serialized)
|
internal void FromSerializedString(string serialized)
|
||||||
{
|
{
|
||||||
if (serialized == null)
|
ArgumentNullException.ThrowIfNull(serialized);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(serialized));
|
|
||||||
}
|
|
||||||
|
|
||||||
_fields = serialized.Split(PairSeparator).ToDictionary(x => x.Split(KeyValueSeparator)[0], y => y.Split(KeyValueSeparator)[1]);
|
_fields = serialized.Split(PairSeparator).ToDictionary(x => x.Split(KeyValueSeparator)[0], y => y.Split(KeyValueSeparator)[1]);
|
||||||
}
|
}
|
||||||
@ -355,10 +346,7 @@ public class LoginProfile
|
|||||||
|
|
||||||
protected LoginProfile(Signature signature, InstanceCrypto instanceCrypto, SerializationInfo info) : this(signature, instanceCrypto)
|
protected LoginProfile(Signature signature, InstanceCrypto instanceCrypto, SerializationInfo info) : this(signature, instanceCrypto)
|
||||||
{
|
{
|
||||||
if (info == null)
|
ArgumentNullException.ThrowIfNull(info);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(info));
|
|
||||||
}
|
|
||||||
|
|
||||||
var transformed = (string)info.GetValue(QueryParamName, typeof(string));
|
var transformed = (string)info.GetValue(QueryParamName, typeof(string));
|
||||||
FromTransport(transformed);
|
FromTransport(transformed);
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
<ApplicationIcon />
|
<ApplicationIcon />
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<StartupObject />
|
<StartupObject />
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||||
|
@ -1,26 +1,23 @@
|
|||||||
global using System;
|
global using System.Data;
|
||||||
global using System.Collections.Generic;
|
|
||||||
global using System.Data;
|
|
||||||
global using System.Linq;
|
|
||||||
|
|
||||||
global using ASC.Common;
|
global using ASC.Common;
|
||||||
|
global using ASC.Common.Mapping;
|
||||||
global using ASC.Core;
|
global using ASC.Core;
|
||||||
global using ASC.Core.Common.EF;
|
global using ASC.Core.Common.EF;
|
||||||
global using ASC.Feed.Models;
|
|
||||||
global using ASC.Core.Common.EF.Model;
|
global using ASC.Core.Common.EF.Model;
|
||||||
global using ASC.Core.Tenants;
|
global using ASC.Core.Tenants;
|
||||||
global using ASC.Core.Users;
|
global using ASC.Core.Users;
|
||||||
global using ASC.Common.Mapping;
|
|
||||||
global using ASC.Feed.Mapping;
|
|
||||||
global using ASC.Feed.Data;
|
|
||||||
global using ASC.Feed.Core;
|
global using ASC.Feed.Core;
|
||||||
|
global using ASC.Feed.Data;
|
||||||
global using AutoMapper;
|
global using ASC.Feed.Mapping;
|
||||||
|
global using ASC.Feed.Models;
|
||||||
|
|
||||||
global using Autofac;
|
global using Autofac;
|
||||||
|
|
||||||
|
global using AutoMapper;
|
||||||
|
|
||||||
global using Microsoft.EntityFrameworkCore;
|
global using Microsoft.EntityFrameworkCore;
|
||||||
global using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
global using Microsoft.EntityFrameworkCore.Infrastructure;
|
global using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
global using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
global using Newtonsoft.Json;
|
global using Newtonsoft.Json;
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
<ApplicationIcon />
|
<ApplicationIcon />
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<StartupObject />
|
<StartupObject />
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
global using System;
|
global using System.Net;
|
||||||
global using System.Collections.Generic;
|
|
||||||
global using System.Linq;
|
|
||||||
global using System.Net;
|
|
||||||
global using System.Net.Sockets;
|
global using System.Net.Sockets;
|
||||||
global using System.Runtime.Serialization;
|
global using System.Runtime.Serialization;
|
||||||
global using System.Web;
|
global using System.Web;
|
||||||
|
|
||||||
global using ASC.Common;
|
global using ASC.Common;
|
||||||
global using ASC.Common.Caching;
|
global using ASC.Common.Caching;
|
||||||
global using ASC.Common.Logging;
|
global using ASC.Common.Logging;
|
||||||
@ -15,11 +12,11 @@ global using ASC.Core.Common.EF;
|
|||||||
global using ASC.Core.Common.EF.Context;
|
global using ASC.Core.Common.EF.Context;
|
||||||
global using ASC.Core.Common.EF.Model;
|
global using ASC.Core.Common.EF.Model;
|
||||||
global using ASC.Core.Common.Settings;
|
global using ASC.Core.Common.Settings;
|
||||||
|
|
||||||
|
global using AutoMapper;
|
||||||
|
global using AutoMapper.QueryableExtensions;
|
||||||
|
|
||||||
global using Microsoft.AspNetCore.Http;
|
global using Microsoft.AspNetCore.Http;
|
||||||
global using Microsoft.AspNetCore.Http.Extensions;
|
global using Microsoft.AspNetCore.Http.Extensions;
|
||||||
global using Microsoft.Extensions.Configuration;
|
global using Microsoft.Extensions.Configuration;
|
||||||
global using Microsoft.Extensions.Options;
|
global using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
global using AutoMapper;
|
|
||||||
global using AutoMapper.QueryableExtensions;
|
|
@ -5,6 +5,7 @@
|
|||||||
<ApplicationIcon />
|
<ApplicationIcon />
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<StartupObject />
|
<StartupObject />
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||||
|
@ -1,33 +1,29 @@
|
|||||||
global using System;
|
global using System.Web;
|
||||||
global using System.Collections.Generic;
|
|
||||||
global using System.Linq;
|
|
||||||
global using System.Threading;
|
|
||||||
global using System.Web;
|
|
||||||
|
|
||||||
global using ASC.Common;
|
global using ASC.Common;
|
||||||
global using ASC.Common.Logging;
|
global using ASC.Common.Logging;
|
||||||
global using ASC.Common.Mapping;
|
global using ASC.Common.Mapping;
|
||||||
global using ASC.Core;
|
global using ASC.Core;
|
||||||
global using ASC.Core.Common.EF;
|
global using ASC.Core.Common.EF;
|
||||||
global using ASC.Core.Common.EF.Model;
|
global using ASC.Core.Common.EF.Model;
|
||||||
global using ASC.MessagingSystem.Mapping;
|
|
||||||
global using ASC.MessagingSystem.Core;
|
global using ASC.MessagingSystem.Core;
|
||||||
global using ASC.MessagingSystem.Core.Sender;
|
global using ASC.MessagingSystem.Core.Sender;
|
||||||
global using ASC.MessagingSystem.Data;
|
global using ASC.MessagingSystem.Data;
|
||||||
|
global using ASC.MessagingSystem.Mapping;
|
||||||
global using ASC.MessagingSystem.Models;
|
global using ASC.MessagingSystem.Models;
|
||||||
|
|
||||||
|
global using AutoMapper;
|
||||||
|
|
||||||
global using Microsoft.AspNetCore.Http;
|
global using Microsoft.AspNetCore.Http;
|
||||||
global using Microsoft.EntityFrameworkCore;
|
global using Microsoft.EntityFrameworkCore;
|
||||||
global using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
global using Microsoft.EntityFrameworkCore.Metadata;
|
|
||||||
global using Microsoft.EntityFrameworkCore.Infrastructure;
|
global using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
global using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
global using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
global using Microsoft.Extensions.Configuration;
|
global using Microsoft.Extensions.Configuration;
|
||||||
global using Microsoft.Extensions.DependencyInjection;
|
global using Microsoft.Extensions.DependencyInjection;
|
||||||
global using Microsoft.Extensions.Options;
|
global using Microsoft.Extensions.Options;
|
||||||
global using Microsoft.Extensions.Primitives;
|
global using Microsoft.Extensions.Primitives;
|
||||||
|
|
||||||
global using AutoMapper;
|
|
||||||
|
|
||||||
global using Newtonsoft.Json;
|
global using Newtonsoft.Json;
|
||||||
|
|
||||||
global using UAParser;
|
global using UAParser;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
<Product>ASC.Notify.Textile</Product>
|
<Product>ASC.Notify.Textile</Product>
|
||||||
<Copyright>(c) Ascensio System SIA. All rights reserved</Copyright>
|
<Copyright>(c) Ascensio System SIA. All rights reserved</Copyright>
|
||||||
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
|
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
global using System;
|
global using System.Reflection;
|
||||||
global using System.IO;
|
|
||||||
global using System.Linq;
|
|
||||||
global using System.Reflection;
|
|
||||||
global using System.Text;
|
global using System.Text;
|
||||||
global using System.Text.RegularExpressions;
|
global using System.Text.RegularExpressions;
|
||||||
global using System.Web;
|
global using System.Web;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
<Copyright>(c) Ascensio System SIA. All rights reserved</Copyright>
|
<Copyright>(c) Ascensio System SIA. All rights reserved</Copyright>
|
||||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||||
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
|
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
namespace Textile
|
namespace Textile;
|
||||||
|
|
||||||
|
public class BlockModifier
|
||||||
{
|
{
|
||||||
public class BlockModifier
|
protected BlockModifier()
|
||||||
{
|
{
|
||||||
protected BlockModifier()
|
}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual string ModifyLine(string line)
|
public virtual string ModifyLine(string line)
|
||||||
{
|
{
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual string Conclude(string line)
|
public virtual string Conclude(string line)
|
||||||
{
|
{
|
||||||
return line;
|
return line;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
namespace Textile
|
namespace Textile;
|
||||||
|
|
||||||
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
|
||||||
|
public sealed class BlockModifierAttribute : Attribute
|
||||||
{
|
{
|
||||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
|
public BlockModifierAttribute()
|
||||||
public sealed class BlockModifierAttribute : Attribute
|
|
||||||
{
|
{
|
||||||
public BlockModifierAttribute()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,142 +10,141 @@
|
|||||||
// You must not remove this notice, or any other, from this software.
|
// You must not remove this notice, or any other, from this software.
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace Textile.Blocks
|
namespace Textile.Blocks;
|
||||||
{
|
|
||||||
public static class BlockAttributesParser
|
|
||||||
{
|
|
||||||
public static StyleReader Styler { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
public static class BlockAttributesParser
|
||||||
///
|
{
|
||||||
/// </summary>
|
public static StyleReader Styler { get; set; }
|
||||||
/// <param name="input"></param>
|
|
||||||
/// <returns></returns>
|
/// <summary>
|
||||||
static public string ParseBlockAttributes(string input)
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
static public string ParseBlockAttributes(string input)
|
||||||
|
{
|
||||||
|
return ParseBlockAttributes(input, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input"></param>
|
||||||
|
/// <param name="element"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
static public string ParseBlockAttributes(string input, string element)
|
||||||
|
{
|
||||||
|
var style = string.Empty;
|
||||||
|
var cssClass = string.Empty;
|
||||||
|
var lang = string.Empty;
|
||||||
|
var colspan = string.Empty;
|
||||||
|
var rowspan = string.Empty;
|
||||||
|
var id = string.Empty;
|
||||||
|
|
||||||
|
if (Styler != null)
|
||||||
{
|
{
|
||||||
return ParseBlockAttributes(input, "");
|
style = GetStyle(element, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
if (input.Length == 0)
|
||||||
///
|
return style.Length > 0 ? " style=\"" + style + "\"" : "";
|
||||||
/// </summary>
|
|
||||||
/// <param name="input"></param>
|
|
||||||
/// <param name="element"></param>
|
Match m;
|
||||||
/// <returns></returns>
|
var matched = input;
|
||||||
static public string ParseBlockAttributes(string input, string element)
|
if (element == "td")
|
||||||
{
|
{
|
||||||
var style = string.Empty;
|
// column span
|
||||||
var cssClass = string.Empty;
|
m = Regex.Match(matched, @"\\(\d+)");
|
||||||
var lang = string.Empty;
|
|
||||||
var colspan = string.Empty;
|
|
||||||
var rowspan = string.Empty;
|
|
||||||
var id = string.Empty;
|
|
||||||
|
|
||||||
if (Styler != null)
|
|
||||||
{
|
|
||||||
style = GetStyle(element, style);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.Length == 0)
|
|
||||||
return style.Length > 0 ? " style=\"" + style + "\"" : "";
|
|
||||||
|
|
||||||
|
|
||||||
Match m;
|
|
||||||
var matched = input;
|
|
||||||
if (element == "td")
|
|
||||||
{
|
|
||||||
// column span
|
|
||||||
m = Regex.Match(matched, @"\\(\d+)");
|
|
||||||
if (m.Success)
|
|
||||||
colspan = m.Groups[1].Value;
|
|
||||||
// row span
|
|
||||||
m = Regex.Match(matched, @"/(\d+)");
|
|
||||||
if (m.Success)
|
|
||||||
rowspan = m.Groups[1].Value;
|
|
||||||
// vertical align
|
|
||||||
m = Regex.Match(matched, @"(" + Globals.VerticalAlignPattern + @")");
|
|
||||||
if (m.Success)
|
|
||||||
style += "vertical-align:" + Globals.VerticalAlign[m.Captures[0].Value] + ";";
|
|
||||||
}
|
|
||||||
|
|
||||||
// First, match custom styles
|
|
||||||
m = Regex.Match(matched, @"\{([^}]*)\}");
|
|
||||||
if (m.Success)
|
if (m.Success)
|
||||||
{
|
colspan = m.Groups[1].Value;
|
||||||
style += m.Groups[1].Value + ";";
|
// row span
|
||||||
matched = matched.Replace(m.ToString(), "");
|
m = Regex.Match(matched, @"/(\d+)");
|
||||||
}
|
|
||||||
|
|
||||||
// Then match the language
|
|
||||||
m = Regex.Match(matched, @"\[([^()]+)\]");
|
|
||||||
if (m.Success)
|
if (m.Success)
|
||||||
{
|
rowspan = m.Groups[1].Value;
|
||||||
lang = m.Groups[1].Value;
|
// vertical align
|
||||||
matched = matched.Replace(m.ToString(), "");
|
m = Regex.Match(matched, @"(" + Globals.VerticalAlignPattern + @")");
|
||||||
}
|
if (m.Success)
|
||||||
|
style += "vertical-align:" + Globals.VerticalAlign[m.Captures[0].Value] + ";";
|
||||||
|
}
|
||||||
|
|
||||||
// Match classes and IDs after that
|
// First, match custom styles
|
||||||
m = Regex.Match(matched, @"\(([^()]+)\)");
|
m = Regex.Match(matched, @"\{([^}]*)\}");
|
||||||
|
if (m.Success)
|
||||||
|
{
|
||||||
|
style += m.Groups[1].Value + ";";
|
||||||
|
matched = matched.Replace(m.ToString(), "");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then match the language
|
||||||
|
m = Regex.Match(matched, @"\[([^()]+)\]");
|
||||||
|
if (m.Success)
|
||||||
|
{
|
||||||
|
lang = m.Groups[1].Value;
|
||||||
|
matched = matched.Replace(m.ToString(), "");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Match classes and IDs after that
|
||||||
|
m = Regex.Match(matched, @"\(([^()]+)\)");
|
||||||
|
if (m.Success)
|
||||||
|
{
|
||||||
|
cssClass = m.Groups[1].Value;
|
||||||
|
matched = matched.Replace(m.ToString(), "");
|
||||||
|
|
||||||
|
// Separate the public class and the ID
|
||||||
|
m = Regex.Match(cssClass, @"^(.*)#(.*)$");
|
||||||
if (m.Success)
|
if (m.Success)
|
||||||
{
|
{
|
||||||
cssClass = m.Groups[1].Value;
|
cssClass = m.Groups[1].Value;
|
||||||
matched = matched.Replace(m.ToString(), "");
|
id = m.Groups[2].Value;
|
||||||
|
|
||||||
// Separate the public class and the ID
|
|
||||||
m = Regex.Match(cssClass, @"^(.*)#(.*)$");
|
|
||||||
if (m.Success)
|
|
||||||
{
|
|
||||||
cssClass = m.Groups[1].Value;
|
|
||||||
id = m.Groups[2].Value;
|
|
||||||
}
|
|
||||||
if (Styler != null && !string.IsNullOrEmpty(cssClass))
|
|
||||||
{
|
|
||||||
style = GetStyle("." + cssClass, style);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (Styler != null && !string.IsNullOrEmpty(cssClass))
|
||||||
// Get the padding on the left
|
|
||||||
m = Regex.Match(matched, @"([(]+)");
|
|
||||||
if (m.Success)
|
|
||||||
{
|
{
|
||||||
style += "padding-left:" + m.Groups[1].Length + "em;";
|
style = GetStyle("." + cssClass, style);
|
||||||
matched = matched.Replace(m.ToString(), "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the padding on the right
|
|
||||||
m = Regex.Match(matched, @"([)]+)");
|
|
||||||
if (m.Success)
|
|
||||||
{
|
|
||||||
style += "padding-right:" + m.Groups[1].Length + "em;";
|
|
||||||
matched = matched.Replace(m.ToString(), "");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the text alignment
|
|
||||||
m = Regex.Match(matched, "(" + Globals.HorizontalAlignPattern + ")");
|
|
||||||
if (m.Success)
|
|
||||||
style += "text-align:" + Globals.HorizontalAlign[m.Groups[1].Value] + ";";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return
|
|
||||||
(style.Length > 0 ? " style=\"" + style + "\"" : "") +
|
|
||||||
(cssClass.Length > 0 ? " class=\"" + cssClass + "\"" : "") +
|
|
||||||
(lang.Length > 0 ? " lang=\"" + lang + "\"" : "") +
|
|
||||||
(id.Length > 0 ? " id=\"" + id + "\"" : "") +
|
|
||||||
(colspan.Length > 0 ? " colspan=\"" + colspan + "\"" : "") +
|
|
||||||
(rowspan.Length > 0 ? " rowspan=\"" + rowspan + "\"" : "")
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetStyle(string element, string style)
|
// Get the padding on the left
|
||||||
|
m = Regex.Match(matched, @"([(]+)");
|
||||||
|
if (m.Success)
|
||||||
{
|
{
|
||||||
var styled = Styler.GetStyle(element);
|
style += "padding-left:" + m.Groups[1].Length + "em;";
|
||||||
if (!string.IsNullOrEmpty(styled))
|
matched = matched.Replace(m.ToString(), "");
|
||||||
{
|
|
||||||
style += styled;
|
|
||||||
}
|
|
||||||
return style;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the padding on the right
|
||||||
|
m = Regex.Match(matched, @"([)]+)");
|
||||||
|
if (m.Success)
|
||||||
|
{
|
||||||
|
style += "padding-right:" + m.Groups[1].Length + "em;";
|
||||||
|
matched = matched.Replace(m.ToString(), "");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the text alignment
|
||||||
|
m = Regex.Match(matched, "(" + Globals.HorizontalAlignPattern + ")");
|
||||||
|
if (m.Success)
|
||||||
|
style += "text-align:" + Globals.HorizontalAlign[m.Groups[1].Value] + ";";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return
|
||||||
|
(style.Length > 0 ? " style=\"" + style + "\"" : "") +
|
||||||
|
(cssClass.Length > 0 ? " class=\"" + cssClass + "\"" : "") +
|
||||||
|
(lang.Length > 0 ? " lang=\"" + lang + "\"" : "") +
|
||||||
|
(id.Length > 0 ? " id=\"" + id + "\"" : "") +
|
||||||
|
(colspan.Length > 0 ? " colspan=\"" + colspan + "\"" : "") +
|
||||||
|
(rowspan.Length > 0 ? " rowspan=\"" + rowspan + "\"" : "")
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetStyle(string element, string style)
|
||||||
|
{
|
||||||
|
var styled = Styler.GetStyle(element);
|
||||||
|
if (!string.IsNullOrEmpty(styled))
|
||||||
|
{
|
||||||
|
style += styled;
|
||||||
|
}
|
||||||
|
return style;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
namespace Textile.Blocks
|
namespace Textile.Blocks;
|
||||||
|
|
||||||
|
public class BoldPhraseBlockModifier : PhraseBlockModifier
|
||||||
{
|
{
|
||||||
public class BoldPhraseBlockModifier : PhraseBlockModifier
|
public override string ModifyLine(string line)
|
||||||
{
|
{
|
||||||
public override string ModifyLine(string line)
|
return PhraseModifierFormat(line, @"\*\*", "b");
|
||||||
{
|
|
||||||
return PhraseModifierFormat(line, @"\*\*", "b");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
namespace Textile.Blocks
|
namespace Textile.Blocks;
|
||||||
{
|
|
||||||
public class CapitalsBlockModifier : BlockModifier
|
|
||||||
{
|
|
||||||
public override string ModifyLine(string line)
|
|
||||||
{
|
|
||||||
var me = new MatchEvaluator(CapitalsFormatMatchEvaluator);
|
|
||||||
line = Regex.Replace(line, @"(?<=^|\s|" + Globals.PunctuationPattern + @")(?<caps>[A-Z][A-Z0-9]+)(?=$|\s|" + Globals.PunctuationPattern + @")", me);
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string CapitalsFormatMatchEvaluator(Match m)
|
public class CapitalsBlockModifier : BlockModifier
|
||||||
{
|
{
|
||||||
return @"<span class=""caps"">" + m.Groups["caps"].Value + @"</span>";
|
public override string ModifyLine(string line)
|
||||||
}
|
{
|
||||||
|
var me = new MatchEvaluator(CapitalsFormatMatchEvaluator);
|
||||||
|
line = Regex.Replace(line, @"(?<=^|\s|" + Globals.PunctuationPattern + @")(?<caps>[A-Z][A-Z0-9]+)(?=$|\s|" + Globals.PunctuationPattern + @")", me);
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string CapitalsFormatMatchEvaluator(Match m)
|
||||||
|
{
|
||||||
|
return @"<span class=""caps"">" + m.Groups["caps"].Value + @"</span>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
namespace Textile.Blocks
|
namespace Textile.Blocks;
|
||||||
|
|
||||||
|
public class CitePhraseBlockModifier : PhraseBlockModifier
|
||||||
{
|
{
|
||||||
public class CitePhraseBlockModifier : PhraseBlockModifier
|
public override string ModifyLine(string line)
|
||||||
{
|
{
|
||||||
public override string ModifyLine(string line)
|
return PhraseModifierFormat(line, @"\?\?", "cite");
|
||||||
{
|
|
||||||
return PhraseModifierFormat(line, @"\?\?", "cite");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,47 +10,46 @@
|
|||||||
// You must not remove this notice, or any other, from this software.
|
// You must not remove this notice, or any other, from this software.
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace Textile.Blocks
|
namespace Textile.Blocks;
|
||||||
|
|
||||||
|
public class CodeBlockModifier : BlockModifier
|
||||||
{
|
{
|
||||||
public class CodeBlockModifier : BlockModifier
|
public override string ModifyLine(string line)
|
||||||
{
|
{
|
||||||
public override string ModifyLine(string line)
|
// Replace "@...@" zones with "<code>" tags.
|
||||||
{
|
var me = new MatchEvaluator(CodeFormatMatchEvaluator);
|
||||||
// Replace "@...@" zones with "<code>" tags.
|
line = Regex.Replace(line,
|
||||||
var me = new MatchEvaluator(CodeFormatMatchEvaluator);
|
@"(?<before>^|([\s\([{]))" + // before
|
||||||
line = Regex.Replace(line,
|
"@" +
|
||||||
@"(?<before>^|([\s\([{]))" + // before
|
@"(\|(?<lang>\w+)\|)?" + // lang
|
||||||
"@" +
|
"(?<code>[^@]+)" + // code
|
||||||
@"(\|(?<lang>\w+)\|)?" + // lang
|
"@" +
|
||||||
"(?<code>[^@]+)" + // code
|
@"(?<after>$|([\]}])|(?=" + Globals.PunctuationPattern + @"{1,2}|\s|$))", // after
|
||||||
"@" +
|
me);
|
||||||
@"(?<after>$|([\]}])|(?=" + Globals.PunctuationPattern + @"{1,2}|\s|$))", // after
|
// Encode the contents of the "<code>" tags so that we don't
|
||||||
me);
|
// generate formatting out of it.
|
||||||
// Encode the contents of the "<code>" tags so that we don't
|
line = NoTextileEncoder.EncodeNoTextileZones(line,
|
||||||
// generate formatting out of it.
|
@"(?<=(^|\s)<code(" + Globals.HtmlAttributesPattern + @")>)",
|
||||||
line = NoTextileEncoder.EncodeNoTextileZones(line,
|
@"(?=</code>)");
|
||||||
@"(?<=(^|\s)<code(" + Globals.HtmlAttributesPattern + @")>)",
|
return line;
|
||||||
@"(?=</code>)");
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string Conclude(string line)
|
|
||||||
{
|
|
||||||
// Recode everything except "<" and ">";
|
|
||||||
line = NoTextileEncoder.DecodeNoTextileZones(line,
|
|
||||||
@"(?<=(^|\s)<code(" + Globals.HtmlAttributesPattern + @")>)",
|
|
||||||
@"(?=</code>)",
|
|
||||||
new string[] { "<", ">" });
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string CodeFormatMatchEvaluator(Match m)
|
|
||||||
{
|
|
||||||
var res = m.Groups["before"].Value + "<code";
|
|
||||||
if (m.Groups["lang"].Length > 0)
|
|
||||||
res += " language=\"" + m.Groups["lang"].Value + "\"";
|
|
||||||
res += ">" + m.Groups["code"].Value + "</code>" + m.Groups["after"].Value;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public override string Conclude(string line)
|
||||||
|
{
|
||||||
|
// Recode everything except "<" and ">";
|
||||||
|
line = NoTextileEncoder.DecodeNoTextileZones(line,
|
||||||
|
@"(?<=(^|\s)<code(" + Globals.HtmlAttributesPattern + @")>)",
|
||||||
|
@"(?=</code>)",
|
||||||
|
new string[] { "<", ">" });
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string CodeFormatMatchEvaluator(Match m)
|
||||||
|
{
|
||||||
|
var res = m.Groups["before"].Value + "<code";
|
||||||
|
if (m.Groups["lang"].Length > 0)
|
||||||
|
res += " language=\"" + m.Groups["lang"].Value + "\"";
|
||||||
|
res += ">" + m.Groups["code"].Value + "</code>" + m.Groups["after"].Value;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,9 @@
|
|||||||
namespace Textile.Blocks
|
namespace Textile.Blocks;
|
||||||
|
|
||||||
|
public class DeletedPhraseBlockModifier : PhraseBlockModifier
|
||||||
{
|
{
|
||||||
public class DeletedPhraseBlockModifier : PhraseBlockModifier
|
public override string ModifyLine(string line)
|
||||||
{
|
{
|
||||||
public override string ModifyLine(string line)
|
return PhraseModifierFormat(line, @"\-", "del");
|
||||||
{
|
|
||||||
return PhraseModifierFormat(line, @"\-", "del");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
namespace Textile.Blocks
|
namespace Textile.Blocks;
|
||||||
|
|
||||||
|
public class EmphasisPhraseBlockModifier : PhraseBlockModifier
|
||||||
{
|
{
|
||||||
public class EmphasisPhraseBlockModifier : PhraseBlockModifier
|
public override string ModifyLine(string line)
|
||||||
{
|
{
|
||||||
public override string ModifyLine(string line)
|
return PhraseModifierFormat(line, @"_", "em");
|
||||||
{
|
|
||||||
return PhraseModifierFormat(line, @"_", "em");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,13 +10,12 @@
|
|||||||
// You must not remove this notice, or any other, from this software.
|
// You must not remove this notice, or any other, from this software.
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace Textile.Blocks
|
namespace Textile.Blocks;
|
||||||
|
|
||||||
|
public class FootNoteReferenceBlockModifier : BlockModifier
|
||||||
{
|
{
|
||||||
public class FootNoteReferenceBlockModifier : BlockModifier
|
public override string ModifyLine(string line)
|
||||||
{
|
{
|
||||||
public override string ModifyLine(string line)
|
return Regex.Replace(line, @"\b\[([0-9]+)\](\W)", "<sup><a href=\"#fn$1\">$1</a></sup>$2");
|
||||||
{
|
|
||||||
return Regex.Replace(line, @"\b\[([0-9]+)\](\W)", "<sup><a href=\"#fn$1\">$1</a></sup>$2");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,79 +10,78 @@
|
|||||||
// You must not remove this notice, or any other, from this software.
|
// You must not remove this notice, or any other, from this software.
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace Textile.Blocks
|
namespace Textile.Blocks;
|
||||||
|
|
||||||
|
public class GlyphBlockModifier : BlockModifier
|
||||||
{
|
{
|
||||||
public class GlyphBlockModifier : BlockModifier
|
public override string ModifyLine(string line)
|
||||||
{
|
{
|
||||||
public override string ModifyLine(string line)
|
line = Regex.Replace(line, "\"\\z", "\" ");
|
||||||
|
|
||||||
|
// fix: hackish
|
||||||
|
string[,] glyphs = {
|
||||||
|
{ @"([^\s[{(>_*])?\'(?(1)|(\s|s\b|" + Globals.PunctuationPattern + @"))", "$1’$2" }, // single closing
|
||||||
|
{ @"\'", "‘" }, // single opening
|
||||||
|
{ @"([^\s[{(>_*])?""(?(1)|(\s|" + Globals.PunctuationPattern + @"))", "$1”$2" }, // double closing
|
||||||
|
{ @"""", "“" }, // double opening
|
||||||
|
{ @"\b( )?\.{3}", "$1…" }, // ellipsis
|
||||||
|
{ @"\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])", "<acronym title=\"$2\">$1</acronym>" }, // 3+ uppercase acronym
|
||||||
|
{ @"(\s)?--(\s)?", "$1—$2" }, // em dash
|
||||||
|
{ @"\s-\s", " – " }, // en dash
|
||||||
|
{ @"(\d+)( )?x( )?(\d+)", "$1$2×$3$4" }, // dimension sign
|
||||||
|
{ @"\b ?[([](TM|tm)[])]", "™" }, // trademark
|
||||||
|
{ @"\b ?[([](R|r)[])]", "®" }, // registered
|
||||||
|
{ @"\b ?[([](C|c)[])]", "©" } // copyright
|
||||||
|
};
|
||||||
|
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
|
if (!Regex.IsMatch(line, "<.*>"))
|
||||||
{
|
{
|
||||||
line = Regex.Replace(line, "\"\\z", "\" ");
|
// If no HTML, do a simple search & replace.
|
||||||
|
for (var i = 0; i < glyphs.GetLength(0); ++i)
|
||||||
// fix: hackish
|
|
||||||
string[,] glyphs = {
|
|
||||||
{ @"([^\s[{(>_*])?\'(?(1)|(\s|s\b|" + Globals.PunctuationPattern + @"))", "$1’$2" }, // single closing
|
|
||||||
{ @"\'", "‘" }, // single opening
|
|
||||||
{ @"([^\s[{(>_*])?""(?(1)|(\s|" + Globals.PunctuationPattern + @"))", "$1”$2" }, // double closing
|
|
||||||
{ @"""", "“" }, // double opening
|
|
||||||
{ @"\b( )?\.{3}", "$1…" }, // ellipsis
|
|
||||||
{ @"\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])", "<acronym title=\"$2\">$1</acronym>" }, // 3+ uppercase acronym
|
|
||||||
{ @"(\s)?--(\s)?", "$1—$2" }, // em dash
|
|
||||||
{ @"\s-\s", " – " }, // en dash
|
|
||||||
{ @"(\d+)( )?x( )?(\d+)", "$1$2×$3$4" }, // dimension sign
|
|
||||||
{ @"\b ?[([](TM|tm)[])]", "™" }, // trademark
|
|
||||||
{ @"\b ?[([](R|r)[])]", "®" }, // registered
|
|
||||||
{ @"\b ?[([](C|c)[])]", "©" } // copyright
|
|
||||||
};
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
|
|
||||||
if (!Regex.IsMatch(line, "<.*>"))
|
|
||||||
{
|
{
|
||||||
// If no HTML, do a simple search & replace.
|
line = Regex.Replace(line, glyphs[i, 0], glyphs[i, 1]);
|
||||||
for (var i = 0; i < glyphs.GetLength(0); ++i)
|
|
||||||
{
|
|
||||||
line = Regex.Replace(line, glyphs[i, 0], glyphs[i, 1]);
|
|
||||||
}
|
|
||||||
sb.Append(line);
|
|
||||||
}
|
}
|
||||||
else
|
sb.Append(line);
|
||||||
{
|
|
||||||
var splits = Regex.Split(line, "(<.*?>)");
|
|
||||||
var offtags = "code|pre|notextile";
|
|
||||||
var codepre = false;
|
|
||||||
|
|
||||||
foreach (var split in splits)
|
|
||||||
{
|
|
||||||
var modifiedSplit = split;
|
|
||||||
if (modifiedSplit.Length == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (Regex.IsMatch(modifiedSplit, @"<(" + offtags + ")>"))
|
|
||||||
codepre = true;
|
|
||||||
if (Regex.IsMatch(modifiedSplit, @"<\/(" + offtags + ")>"))
|
|
||||||
codepre = false;
|
|
||||||
|
|
||||||
if (!Regex.IsMatch(modifiedSplit, "<.*>") && !codepre)
|
|
||||||
{
|
|
||||||
for (var i = 0; i < glyphs.GetLength(0); ++i)
|
|
||||||
{
|
|
||||||
modifiedSplit = Regex.Replace(modifiedSplit, glyphs[i, 0], glyphs[i, 1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// do htmlspecial if between <code>
|
|
||||||
if (codepre)
|
|
||||||
{
|
|
||||||
//TODO: htmlspecialchars(line)
|
|
||||||
//line = Regex.Replace(line, @"<(\/?" + offtags + ")>", "<$1>");
|
|
||||||
//line = line.Replace("&#", "&#");
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.Append(modifiedSplit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var splits = Regex.Split(line, "(<.*?>)");
|
||||||
|
var offtags = "code|pre|notextile";
|
||||||
|
var codepre = false;
|
||||||
|
|
||||||
|
foreach (var split in splits)
|
||||||
|
{
|
||||||
|
var modifiedSplit = split;
|
||||||
|
if (modifiedSplit.Length == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (Regex.IsMatch(modifiedSplit, @"<(" + offtags + ")>"))
|
||||||
|
codepre = true;
|
||||||
|
if (Regex.IsMatch(modifiedSplit, @"<\/(" + offtags + ")>"))
|
||||||
|
codepre = false;
|
||||||
|
|
||||||
|
if (!Regex.IsMatch(modifiedSplit, "<.*>") && !codepre)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < glyphs.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
modifiedSplit = Regex.Replace(modifiedSplit, glyphs[i, 0], glyphs[i, 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// do htmlspecial if between <code>
|
||||||
|
if (codepre)
|
||||||
|
{
|
||||||
|
//TODO: htmlspecialchars(line)
|
||||||
|
//line = Regex.Replace(line, @"<(\/?" + offtags + ")>", "<$1>");
|
||||||
|
//line = line.Replace("&#", "&#");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append(modifiedSplit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,46 +11,45 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
namespace Textile.Blocks
|
namespace Textile.Blocks;
|
||||||
|
|
||||||
|
public class HyperLinkBlockModifier : BlockModifier
|
||||||
{
|
{
|
||||||
public class HyperLinkBlockModifier : BlockModifier
|
private readonly string _rel = string.Empty;
|
||||||
|
|
||||||
|
public override string ModifyLine(string line)
|
||||||
{
|
{
|
||||||
private readonly string m_rel = string.Empty;
|
line = Regex.Replace(line,
|
||||||
|
@"(?<pre>[\s[{(]|" + Globals.PunctuationPattern + @")?" + // $pre
|
||||||
|
"\"" + // start
|
||||||
|
Globals.BlockModifiersPattern + // attributes
|
||||||
|
"(?<text>[\\w\\W]+?)" + // text
|
||||||
|
@"\s?" +
|
||||||
|
@"(?:\((?<title>[^)]+)\)(?=""))?" + // title
|
||||||
|
"\":" +
|
||||||
|
@"""(?<url>\S+[^""]+)""" + // url
|
||||||
|
@"(?<slash>\/)?" + // slash
|
||||||
|
@"(?<post>[^\w\/;]*)" + // post
|
||||||
|
@"(?=\s|$)",
|
||||||
|
new MatchEvaluator(HyperLinksFormatMatchEvaluator));
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
public override string ModifyLine(string line)
|
private string HyperLinksFormatMatchEvaluator(Match m)
|
||||||
{
|
{
|
||||||
line = Regex.Replace(line,
|
//TODO: check the URL
|
||||||
@"(?<pre>[\s[{(]|" + Globals.PunctuationPattern + @")?" + // $pre
|
var atts = BlockAttributesParser.ParseBlockAttributes(m.Groups["atts"].Value, "a");
|
||||||
"\"" + // start
|
if (m.Groups["title"].Length > 0)
|
||||||
Globals.BlockModifiersPattern + // attributes
|
atts += " title=\"" + m.Groups["title"].Value + "\"";
|
||||||
"(?<text>[\\w\\W]+?)" + // text
|
var linkText = m.Groups["text"].Value.Trim(' ');
|
||||||
@"\s?" +
|
|
||||||
@"(?:\((?<title>[^)]+)\)(?=""))?" + // title
|
|
||||||
"\":" +
|
|
||||||
@"""(?<url>\S+[^""]+)""" + // url
|
|
||||||
@"(?<slash>\/)?" + // slash
|
|
||||||
@"(?<post>[^\w\/;]*)" + // post
|
|
||||||
@"(?=\s|$)",
|
|
||||||
new MatchEvaluator(HyperLinksFormatMatchEvaluator));
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string HyperLinksFormatMatchEvaluator(Match m)
|
var str = m.Groups["pre"].Value + "<a ";
|
||||||
{
|
if (!string.IsNullOrEmpty(_rel))
|
||||||
//TODO: check the URL
|
str += "ref=\"" + _rel + "\" ";
|
||||||
var atts = BlockAttributesParser.ParseBlockAttributes(m.Groups["atts"].Value, "a");
|
str += "href=\"" +
|
||||||
if (m.Groups["title"].Length > 0)
|
m.Groups["url"].Value + m.Groups["slash"].Value + "\"" +
|
||||||
atts += " title=\"" + m.Groups["title"].Value + "\"";
|
atts +
|
||||||
var linkText = m.Groups["text"].Value.Trim(' ');
|
">" + linkText + "</a>" + m.Groups["post"].Value;
|
||||||
|
return str;
|
||||||
var str = m.Groups["pre"].Value + "<a ";
|
|
||||||
if (!string.IsNullOrEmpty(m_rel))
|
|
||||||
str += "ref=\"" + m_rel + "\" ";
|
|
||||||
str += "href=\"" +
|
|
||||||
m.Groups["url"].Value + m.Groups["slash"].Value + "\"" +
|
|
||||||
atts +
|
|
||||||
">" + linkText + "</a>" + m.Groups["post"].Value;
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,60 +10,59 @@
|
|||||||
// You must not remove this notice, or any other, from this software.
|
// You must not remove this notice, or any other, from this software.
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace Textile.Blocks
|
namespace Textile.Blocks;
|
||||||
|
|
||||||
|
public class ImageBlockModifier : BlockModifier
|
||||||
{
|
{
|
||||||
public class ImageBlockModifier : BlockModifier
|
public override string ModifyLine(string line)
|
||||||
{
|
{
|
||||||
public override string ModifyLine(string line)
|
line = Regex.Replace(line,
|
||||||
|
@"\!" + // opening !
|
||||||
|
@"(?<algn>\<|\=|\>)?" + // optional alignment atts
|
||||||
|
Globals.BlockModifiersPattern + // optional style, public class atts
|
||||||
|
@"(?:\. )?" + // optional dot-space
|
||||||
|
@"(?<url>[^\s(!]+)" + // presume this is the src
|
||||||
|
@"\s?" + // optional space
|
||||||
|
@"(?:\((?<title>([^\)]+))\))?" +// optional title
|
||||||
|
@"\!" + // closing
|
||||||
|
@"(?::(?<href>(\S+)))?" + // optional href
|
||||||
|
@"(?=\s|\.|,|;|\)|\||$)", // lookahead: space or simple punctuation or end of string
|
||||||
|
new MatchEvaluator(ImageFormatMatchEvaluator)
|
||||||
|
);
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
string ImageFormatMatchEvaluator(Match m)
|
||||||
|
{
|
||||||
|
var atts = BlockAttributesParser.ParseBlockAttributes(m.Groups["atts"].Value, "img");
|
||||||
|
if (m.Groups["algn"].Length > 0)
|
||||||
|
atts += " align=\"" + Globals.ImageAlign[m.Groups["algn"].Value] + "\"";
|
||||||
|
if (m.Groups["title"].Length > 0)
|
||||||
{
|
{
|
||||||
line = Regex.Replace(line,
|
atts += " title=\"" + m.Groups["title"].Value + "\"";
|
||||||
@"\!" + // opening !
|
atts += " alt=\"" + m.Groups["title"].Value + "\"";
|
||||||
@"(?<algn>\<|\=|\>)?" + // optional alignment atts
|
}
|
||||||
Globals.BlockModifiersPattern + // optional style, public class atts
|
else
|
||||||
@"(?:\. )?" + // optional dot-space
|
{
|
||||||
@"(?<url>[^\s(!]+)" + // presume this is the src
|
atts += " alt=\"\"";
|
||||||
@"\s?" + // optional space
|
}
|
||||||
@"(?:\((?<title>([^\)]+))\))?" +// optional title
|
// Get Image Size?
|
||||||
@"\!" + // closing
|
|
||||||
@"(?::(?<href>(\S+)))?" + // optional href
|
var res = "<img src=\"" + m.Groups["url"].Value + "\"" + atts + " />";
|
||||||
@"(?=\s|\.|,|;|\)|\||$)", // lookahead: space or simple punctuation or end of string
|
|
||||||
new MatchEvaluator(ImageFormatMatchEvaluator)
|
if (m.Groups["href"].Length > 0)
|
||||||
);
|
{
|
||||||
return line;
|
var href = m.Groups["href"].Value;
|
||||||
|
var end = string.Empty;
|
||||||
|
var endMatch = Regex.Match(href, @"(.*)(?<end>\.|,|;|\))$");
|
||||||
|
if (m.Success && !string.IsNullOrEmpty(endMatch.Groups["end"].Value))
|
||||||
|
{
|
||||||
|
href = href[0..^1];
|
||||||
|
end = endMatch.Groups["end"].Value;
|
||||||
|
}
|
||||||
|
res = "<a href=\"" + Globals.EncodeHTMLLink(href) + "\">" + res + "</a>" + end;
|
||||||
}
|
}
|
||||||
|
|
||||||
string ImageFormatMatchEvaluator(Match m)
|
return res;
|
||||||
{
|
|
||||||
var atts = BlockAttributesParser.ParseBlockAttributes(m.Groups["atts"].Value, "img");
|
|
||||||
if (m.Groups["algn"].Length > 0)
|
|
||||||
atts += " align=\"" + Globals.ImageAlign[m.Groups["algn"].Value] + "\"";
|
|
||||||
if (m.Groups["title"].Length > 0)
|
|
||||||
{
|
|
||||||
atts += " title=\"" + m.Groups["title"].Value + "\"";
|
|
||||||
atts += " alt=\"" + m.Groups["title"].Value + "\"";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
atts += " alt=\"\"";
|
|
||||||
}
|
|
||||||
// Get Image Size?
|
|
||||||
|
|
||||||
var res = "<img src=\"" + m.Groups["url"].Value + "\"" + atts + " />";
|
|
||||||
|
|
||||||
if (m.Groups["href"].Length > 0)
|
|
||||||
{
|
|
||||||
var href = m.Groups["href"].Value;
|
|
||||||
var end = string.Empty;
|
|
||||||
var endMatch = Regex.Match(href, @"(.*)(?<end>\.|,|;|\))$");
|
|
||||||
if (m.Success && !string.IsNullOrEmpty(endMatch.Groups["end"].Value))
|
|
||||||
{
|
|
||||||
href = href[0..^1];
|
|
||||||
end = endMatch.Groups["end"].Value;
|
|
||||||
}
|
|
||||||
res = "<a href=\"" + Globals.EncodeHTMLLink(href) + "\">" + res + "</a>" + end;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
namespace Textile.Blocks
|
namespace Textile.Blocks;
|
||||||
|
|
||||||
|
public class InsertedPhraseBlockModifier : PhraseBlockModifier
|
||||||
{
|
{
|
||||||
public class InsertedPhraseBlockModifier : PhraseBlockModifier
|
public override string ModifyLine(string line)
|
||||||
{
|
{
|
||||||
public override string ModifyLine(string line)
|
return PhraseModifierFormat(line, @"\+", "ins");
|
||||||
{
|
|
||||||
return PhraseModifierFormat(line, @"\+", "ins");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
namespace Textile.Blocks
|
namespace Textile.Blocks;
|
||||||
|
|
||||||
|
public class ItalicPhraseBlockModifier : PhraseBlockModifier
|
||||||
{
|
{
|
||||||
public class ItalicPhraseBlockModifier : PhraseBlockModifier
|
public override string ModifyLine(string line)
|
||||||
{
|
{
|
||||||
public override string ModifyLine(string line)
|
return PhraseModifierFormat(line, @"__", "i");
|
||||||
{
|
|
||||||
return PhraseModifierFormat(line, @"__", "i");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,22 +11,21 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
namespace Textile.Blocks
|
namespace Textile.Blocks;
|
||||||
{
|
|
||||||
public class NoTextileBlockModifier : BlockModifier
|
|
||||||
{
|
|
||||||
public override string ModifyLine(string line)
|
|
||||||
{
|
|
||||||
line = NoTextileEncoder.EncodeNoTextileZones(line, @"(?<=^|\s)<notextile>", @"</notextile>(?=(\s|$)?)");
|
|
||||||
line = NoTextileEncoder.EncodeNoTextileZones(line, @"==", @"==");
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string Conclude(string line)
|
public class NoTextileBlockModifier : BlockModifier
|
||||||
{
|
{
|
||||||
line = NoTextileEncoder.DecodeNoTextileZones(line, @"(?<=^|\s)<notextile>", @"</notextile>(?=(\s|$)?)");
|
public override string ModifyLine(string line)
|
||||||
line = NoTextileEncoder.DecodeNoTextileZones(line, @"==", @"==");
|
{
|
||||||
return line;
|
line = NoTextileEncoder.EncodeNoTextileZones(line, @"(?<=^|\s)<notextile>", @"</notextile>(?=(\s|$)?)");
|
||||||
}
|
line = NoTextileEncoder.EncodeNoTextileZones(line, @"==", @"==");
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Conclude(string line)
|
||||||
|
{
|
||||||
|
line = NoTextileEncoder.DecodeNoTextileZones(line, @"(?<=^|\s)<notextile>", @"</notextile>(?=(\s|$)?)");
|
||||||
|
line = NoTextileEncoder.DecodeNoTextileZones(line, @"==", @"==");
|
||||||
|
return line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user