Ready to test
This commit is contained in:
parent
e5df7f743e
commit
0987ee8b80
243
.editorconfig
Normal file
243
.editorconfig
Normal file
@ -0,0 +1,243 @@
|
||||
[*.cs]
|
||||
csharp_indent_block_contents = true
|
||||
csharp_indent_braces = false
|
||||
csharp_indent_case_contents = true
|
||||
csharp_indent_case_contents_when_block = true
|
||||
csharp_indent_labels = one_less_than_current
|
||||
csharp_indent_switch_labels = true
|
||||
csharp_new_line_before_catch = true
|
||||
csharp_new_line_before_else = true
|
||||
csharp_new_line_before_finally = true
|
||||
csharp_new_line_before_members_in_anonymous_types = true
|
||||
csharp_new_line_before_members_in_object_initializers = true
|
||||
csharp_new_line_before_open_brace = all
|
||||
csharp_new_line_between_query_expression_clauses = true
|
||||
csharp_prefer_braces = false
|
||||
csharp_prefer_simple_default_expression = true:warning
|
||||
csharp_prefer_simple_using_statement = true:warning
|
||||
csharp_prefer_static_local_function = true:warning
|
||||
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
|
||||
csharp_preserve_single_line_blocks = true
|
||||
csharp_preserve_single_line_statements = false
|
||||
csharp_space_after_cast = false
|
||||
csharp_space_after_colon_in_inheritance_clause = true
|
||||
csharp_space_after_comma = true
|
||||
csharp_space_after_dot = false
|
||||
csharp_space_after_keywords_in_control_flow_statements = true
|
||||
csharp_space_after_semicolon_in_for_statement = true
|
||||
csharp_space_around_binary_operators = before_and_after
|
||||
csharp_space_around_declaration_statements = false
|
||||
csharp_space_before_colon_in_inheritance_clause = true
|
||||
csharp_space_before_comma = false
|
||||
csharp_space_before_dot = false
|
||||
csharp_space_before_open_square_brackets = false
|
||||
csharp_space_before_semicolon_in_for_statement = false
|
||||
csharp_space_between_empty_square_brackets = false
|
||||
csharp_space_between_method_call_empty_parameter_list_parentheses = false
|
||||
csharp_space_between_method_call_name_and_opening_parenthesis = false
|
||||
csharp_space_between_method_call_parameter_list_parentheses = false
|
||||
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
|
||||
csharp_space_between_method_declaration_name_and_open_parenthesis = false
|
||||
csharp_space_between_method_declaration_parameter_list_parentheses = false
|
||||
csharp_space_between_parentheses = false
|
||||
csharp_space_between_square_brackets = false
|
||||
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
|
||||
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true
|
||||
csharp_style_allow_embedded_statements_on_same_line_experimental = true
|
||||
csharp_style_conditional_delegate_call = true
|
||||
csharp_style_deconstructed_variable_declaration = false
|
||||
csharp_style_expression_bodied_accessors = when_on_single_line:warning
|
||||
csharp_style_expression_bodied_constructors = when_on_single_line:warning
|
||||
csharp_style_expression_bodied_indexers = when_on_single_line:warning
|
||||
csharp_style_expression_bodied_lambdas = when_on_single_line:warning
|
||||
csharp_style_expression_bodied_local_functions = when_on_single_line:warning
|
||||
csharp_style_expression_bodied_methods = when_on_single_line:warning
|
||||
csharp_style_expression_bodied_operators = when_on_single_line:warning
|
||||
csharp_style_expression_bodied_properties = when_on_single_line:warning
|
||||
csharp_style_implicit_object_creation_when_type_is_apparent = true:warning
|
||||
csharp_style_inlined_variable_declaration = false
|
||||
csharp_style_namespace_declarations = file_scoped:warning
|
||||
csharp_style_pattern_local_over_anonymous_function = true:warning
|
||||
csharp_style_pattern_matching_over_as_with_null_check = true:warning
|
||||
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
|
||||
csharp_style_prefer_index_operator = true:warning
|
||||
csharp_style_prefer_not_pattern = true:warning
|
||||
csharp_style_prefer_null_check_over_type_check = true
|
||||
csharp_style_prefer_pattern_matching = true:warning
|
||||
csharp_style_prefer_range_operator = true:warning
|
||||
csharp_style_prefer_switch_expression = true:warning
|
||||
csharp_style_throw_expression = true
|
||||
csharp_style_unused_value_assignment_preference = discard_variable:warning
|
||||
csharp_style_unused_value_expression_statement_preference = discard_variable:warning
|
||||
csharp_style_var_elsewhere = false:warning
|
||||
csharp_style_var_for_built_in_types = false:warning
|
||||
csharp_style_var_when_type_is_apparent = false:warning
|
||||
csharp_using_directive_placement = outside_namespace
|
||||
dotnet_code_quality_unused_parameters = all
|
||||
dotnet_code_quality_unused_parameters = non_public # IDE0060: Remove unused parameter
|
||||
dotnet_code_quality.CAXXXX.api_surface = private, internal
|
||||
dotnet_diagnostic.CA1825.severity = warning # CA1823: Avoid zero-length array allocations
|
||||
dotnet_diagnostic.CA1829.severity = warning # CA1829: Use Length/Count property instead of Count() when available
|
||||
dotnet_diagnostic.CA1834.severity = warning # CA1834: Consider using 'StringBuilder.Append(char)' when applicable
|
||||
dotnet_diagnostic.IDE0001.severity = warning # IDE0001: Simplify name
|
||||
dotnet_diagnostic.IDE0002.severity = warning # Simplify (member access) - System.Version.Equals("1", "2"); Version.Equals("1", "2");
|
||||
dotnet_diagnostic.IDE0005.severity = warning # Using directive is unnecessary
|
||||
dotnet_diagnostic.IDE0047.severity = warning # IDE0047: Parentheses can be removed
|
||||
dotnet_diagnostic.IDE0060.severity = warning # IDE0060: Remove unused parameter
|
||||
dotnet_naming_rule.abstract_method_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.abstract_method_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.abstract_method_should_be_pascal_case.symbols = abstract_method
|
||||
dotnet_naming_rule.class_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.class_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.class_should_be_pascal_case.symbols = class
|
||||
dotnet_naming_rule.delegate_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.delegate_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.delegate_should_be_pascal_case.symbols = delegate
|
||||
dotnet_naming_rule.enum_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.enum_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.enum_should_be_pascal_case.symbols = enum
|
||||
dotnet_naming_rule.event_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.event_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.event_should_be_pascal_case.symbols = event
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.severity = warning
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
|
||||
dotnet_naming_rule.method_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.method_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.method_should_be_pascal_case.symbols = method
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
|
||||
dotnet_naming_rule.private_method_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.private_method_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.private_method_should_be_pascal_case.symbols = private_method
|
||||
dotnet_naming_rule.private_or_internal_field_should_be_private_of_internal_field.severity = warning
|
||||
dotnet_naming_rule.private_or_internal_field_should_be_private_of_internal_field.style = private_of_internal_field
|
||||
dotnet_naming_rule.private_or_internal_field_should_be_private_of_internal_field.symbols = private_or_internal_field
|
||||
dotnet_naming_rule.private_or_internal_static_field_should_be_private_of_internal_field.severity = warning
|
||||
dotnet_naming_rule.private_or_internal_static_field_should_be_private_of_internal_field.style = private_of_internal_field
|
||||
dotnet_naming_rule.private_or_internal_static_field_should_be_private_of_internal_field.symbols = private_or_internal_static_field
|
||||
dotnet_naming_rule.property_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.property_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.property_should_be_pascal_case.symbols = property
|
||||
dotnet_naming_rule.public_or_protected_field_should_be_private_of_internal_field.severity = warning
|
||||
dotnet_naming_rule.public_or_protected_field_should_be_private_of_internal_field.style = private_of_internal_field
|
||||
dotnet_naming_rule.public_or_protected_field_should_be_private_of_internal_field.symbols = public_or_protected_field
|
||||
dotnet_naming_rule.static_field_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.static_field_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.static_field_should_be_pascal_case.symbols = static_field
|
||||
dotnet_naming_rule.static_method_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.static_method_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.static_method_should_be_pascal_case.symbols = static_method
|
||||
dotnet_naming_rule.struct_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.struct_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.struct_should_be_pascal_case.symbols = struct
|
||||
dotnet_naming_rule.types_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
|
||||
dotnet_naming_style.begins_with_i.capitalization = pascal_case
|
||||
dotnet_naming_style.begins_with_i.required_prefix = I
|
||||
dotnet_naming_style.begins_with_i.required_suffix =
|
||||
dotnet_naming_style.begins_with_i.word_separator =
|
||||
dotnet_naming_style.pascal_case.capitalization = pascal_case
|
||||
dotnet_naming_style.pascal_case.required_prefix =
|
||||
dotnet_naming_style.pascal_case.required_suffix =
|
||||
dotnet_naming_style.pascal_case.word_separator =
|
||||
dotnet_naming_style.private_of_internal_field.capitalization = pascal_case
|
||||
dotnet_naming_style.private_of_internal_field.required_prefix = _
|
||||
dotnet_naming_style.private_of_internal_field.required_suffix =
|
||||
dotnet_naming_style.private_of_internal_field.word_separator =
|
||||
dotnet_naming_symbols.abstract_method.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.abstract_method.applicable_kinds = method
|
||||
dotnet_naming_symbols.abstract_method.required_modifiers = abstract
|
||||
dotnet_naming_symbols.class.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.class.applicable_kinds = class
|
||||
dotnet_naming_symbols.class.required_modifiers =
|
||||
dotnet_naming_symbols.delegate.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.delegate.applicable_kinds = delegate
|
||||
dotnet_naming_symbols.delegate.required_modifiers =
|
||||
dotnet_naming_symbols.enum.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.enum.applicable_kinds = enum
|
||||
dotnet_naming_symbols.enum.required_modifiers =
|
||||
dotnet_naming_symbols.event.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.event.applicable_kinds = event
|
||||
dotnet_naming_symbols.event.required_modifiers =
|
||||
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.interface.applicable_kinds = interface
|
||||
dotnet_naming_symbols.interface.required_modifiers =
|
||||
dotnet_naming_symbols.method.applicable_accessibilities = public
|
||||
dotnet_naming_symbols.method.applicable_kinds = method
|
||||
dotnet_naming_symbols.method.required_modifiers =
|
||||
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
|
||||
dotnet_naming_symbols.non_field_members.required_modifiers =
|
||||
dotnet_naming_symbols.private_method.applicable_accessibilities = private
|
||||
dotnet_naming_symbols.private_method.applicable_kinds = method
|
||||
dotnet_naming_symbols.private_method.required_modifiers =
|
||||
dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private, private_protected
|
||||
dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field
|
||||
dotnet_naming_symbols.private_or_internal_field.required_modifiers =
|
||||
dotnet_naming_symbols.private_or_internal_static_field.applicable_accessibilities = internal, private, private_protected
|
||||
dotnet_naming_symbols.private_or_internal_static_field.applicable_kinds = field
|
||||
dotnet_naming_symbols.private_or_internal_static_field.required_modifiers = static
|
||||
dotnet_naming_symbols.property.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.property.applicable_kinds = property
|
||||
dotnet_naming_symbols.property.required_modifiers =
|
||||
dotnet_naming_symbols.public_or_protected_field.applicable_accessibilities = public, protected
|
||||
dotnet_naming_symbols.public_or_protected_field.applicable_kinds = field
|
||||
dotnet_naming_symbols.public_or_protected_field.required_modifiers =
|
||||
dotnet_naming_symbols.static_field.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.static_field.applicable_kinds = field
|
||||
dotnet_naming_symbols.static_field.required_modifiers = static
|
||||
dotnet_naming_symbols.static_method.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.static_method.applicable_kinds = method
|
||||
dotnet_naming_symbols.static_method.required_modifiers = static
|
||||
dotnet_naming_symbols.struct.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.struct.applicable_kinds = struct
|
||||
dotnet_naming_symbols.struct.required_modifiers =
|
||||
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
|
||||
dotnet_naming_symbols.types.required_modifiers =
|
||||
dotnet_remove_unnecessary_suppression_exclusions = 0
|
||||
dotnet_separate_import_directive_groups = false
|
||||
dotnet_sort_system_directives_first = false
|
||||
dotnet_style_allow_multiple_blank_lines_experimental = false:warning
|
||||
dotnet_style_allow_statement_immediately_after_block_experimental = true
|
||||
dotnet_style_coalesce_expression = true
|
||||
dotnet_style_collection_initializer = true:warning
|
||||
dotnet_style_explicit_tuple_names = true:warning
|
||||
dotnet_style_namespace_match_folder = true
|
||||
dotnet_style_null_propagation = true:warning
|
||||
dotnet_style_object_initializer = true:warning
|
||||
dotnet_style_operator_placement_when_wrapping = beginning_of_line
|
||||
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
|
||||
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
|
||||
dotnet_style_parentheses_in_other_operators = never_if_unnecessary
|
||||
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
|
||||
dotnet_style_predefined_type_for_locals_parameters_members = true
|
||||
dotnet_style_predefined_type_for_member_access = true
|
||||
dotnet_style_prefer_auto_properties = true:warning
|
||||
dotnet_style_prefer_compound_assignment = true:warning
|
||||
dotnet_style_prefer_conditional_expression_over_assignment = false
|
||||
dotnet_style_prefer_conditional_expression_over_return = false
|
||||
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
|
||||
dotnet_style_qualification_for_event = false:error
|
||||
dotnet_style_qualification_for_field = false
|
||||
dotnet_style_qualification_for_method = false:error
|
||||
dotnet_style_qualification_for_property = false:error
|
||||
dotnet_style_readonly_field = true:warning
|
||||
dotnet_style_require_accessibility_modifiers = for_non_interface_members
|
||||
end_of_line = crlf
|
||||
file_header_template = unset
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = false
|
||||
root = true
|
||||
tab_width = 4
|
||||
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1822
|
||||
# https://github.com/dotnet/aspnetcore/blob/main/.editorconfig
|
||||
# https://github.com/dotnet/project-system/blob/main/.editorconfig
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -22,7 +22,6 @@ x86/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
@ -327,4 +326,4 @@ ASALocalRun/
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
.mfractor/
|
1
.vscode/format-report.json
vendored
Normal file
1
.vscode/format-report.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
[]
|
28
.vscode/launch.json
vendored
Normal file
28
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/bin/Debug/net6.0/win-x64/File-Folder-Helper.dll",
|
||||
"args": [
|
||||
"s",
|
||||
"C",
|
||||
"D:/"
|
||||
],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"console": "externalTerminal",
|
||||
"stopAtEntry": false
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach"
|
||||
}
|
||||
]
|
||||
}
|
11
.vscode/settings.json
vendored
Normal file
11
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"files.exclude": {
|
||||
"**/.git": false
|
||||
},
|
||||
"cSpell.words": [
|
||||
"ASPNETCORE",
|
||||
"Infineon",
|
||||
"Phares",
|
||||
"Serilog"
|
||||
]
|
||||
}
|
41
.vscode/tasks.json
vendored
Normal file
41
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/File-Folder-Helper.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "publish",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/File-Folder-Helper.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "watch",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"watch",
|
||||
"run",
|
||||
"--project",
|
||||
"${workspaceFolder}/File-Folder-Helper.csproj"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
34
File-Folder-Helper.csproj
Normal file
34
File-Folder-Helper.csproj
Normal file
@ -0,0 +1,34 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<LangVersion>10.0</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Serilog" Version="2.11.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
<PackageReference Include="TextCopy" Version="6.1.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Text.Json" Version="6.0.3" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="appsettings.Staging.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="appsettings.Development.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
43
Helpers/HelperDeleteEmptyDirectories.cs
Normal file
43
Helpers/HelperDeleteEmptyDirectories.cs
Normal file
@ -0,0 +1,43 @@
|
||||
namespace File_Folder_Helper.Helpers;
|
||||
|
||||
internal static class HelperDeleteEmptyDirectories
|
||||
{
|
||||
|
||||
internal static bool DeleteEmptyDirectories(string rootDirectory)
|
||||
{
|
||||
bool result;
|
||||
if (!Directory.Exists(rootDirectory))
|
||||
result = false;
|
||||
else
|
||||
{
|
||||
string[] files;
|
||||
string[] directories = Directory.GetDirectories(rootDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
if (directories.Length > 0)
|
||||
files = Array.Empty<string>();
|
||||
else
|
||||
files = Directory.GetFiles(rootDirectory, "*", SearchOption.AllDirectories);
|
||||
if (directories.Length == 0 && files.Length == 0)
|
||||
{
|
||||
result = true;
|
||||
Directory.Delete(rootDirectory);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
foreach (string directory in directories)
|
||||
{
|
||||
result = DeleteEmptyDirectories(directory);
|
||||
if (result)
|
||||
result = DeleteEmptyDirectories(directory);
|
||||
}
|
||||
if (files is null)
|
||||
{
|
||||
directories = Directory.GetDirectories(rootDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
result = directories.Length == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
44
Helpers/HelperILMerge.cs
Normal file
44
Helpers/HelperILMerge.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace File_Folder_Helper.Helpers;
|
||||
|
||||
internal static class HelperILMerge
|
||||
{
|
||||
|
||||
internal static void ILMerge(string workingDirectory)
|
||||
{
|
||||
bool result;
|
||||
ProcessStartInfo processStartInfo;
|
||||
StringBuilder stringBuilder = new();
|
||||
string[] successChecks = new string[] { "success" };
|
||||
string[] errorChecks = new string[] { "Error", "Conflict", "error:" };
|
||||
string errorFile = Path.Combine(workingDirectory, string.Concat(Path.GetFileName(workingDirectory), ".err"));
|
||||
string primaryFile = Path.Combine(workingDirectory, string.Concat(Path.GetFileName(workingDirectory), ".dll"));
|
||||
string[] dllFiles = Directory.GetFiles(workingDirectory, "*.dll", SearchOption.TopDirectoryOnly);
|
||||
FileInfo ilMerge = new(@"C:\Users\phares\AppData\Local\IFXApps\ILMerge\ILMerge.exe");
|
||||
FileInfo fileInfo = new(Path.Combine(workingDirectory, ilMerge.Name));
|
||||
if (!fileInfo.Exists)
|
||||
_ = ilMerge.CopyTo(fileInfo.FullName);
|
||||
if (fileInfo.Exists && ilMerge.LastWriteTime != fileInfo.LastWriteTime)
|
||||
_ = ilMerge.CopyTo(fileInfo.FullName, overwrite: true);
|
||||
_ = stringBuilder.Append("/allowDup /target:library /out:\"").Append(Path.GetFileNameWithoutExtension(primaryFile)).Append(".all.dll\" ");
|
||||
foreach (string dllFile in dllFiles)
|
||||
{
|
||||
if (dllFile == primaryFile)
|
||||
continue;
|
||||
_ = stringBuilder.Append('"').Append(Path.GetFileName(dllFile)).Append("\" ");
|
||||
}
|
||||
processStartInfo = new ProcessStartInfo(fileInfo.FullName, stringBuilder.ToString())
|
||||
{
|
||||
UseShellExecute = false,
|
||||
RedirectStandardError = true,
|
||||
RedirectStandardOutput = true,
|
||||
WorkingDirectory = workingDirectory,
|
||||
};
|
||||
result = HelperStart.Start(errorChecks, successChecks, processStartInfo, errorFile);
|
||||
if (result)
|
||||
{ }
|
||||
}
|
||||
|
||||
}
|
71
Helpers/HelperLogMerge.cs
Normal file
71
Helpers/HelperLogMerge.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace File_Folder_Helper.Helpers;
|
||||
|
||||
internal static class HelperLogMerge
|
||||
{
|
||||
|
||||
internal static void LogMerge(string argsZero)
|
||||
{
|
||||
int hour;
|
||||
string day;
|
||||
string logFile;
|
||||
FileInfo fileInfo;
|
||||
string[] segments;
|
||||
string checkDirectory;
|
||||
string format = "yyyyMMdd";
|
||||
string segment1 = string.Empty;
|
||||
string sourceFileNameWithoutExtension;
|
||||
List<string> lines = new();
|
||||
List<string> moveFiles = new();
|
||||
DateTime dateTime = DateTime.Now.AddMinutes(2);
|
||||
string[] sourceFiles = Directory.GetFiles(argsZero, "*.log", SearchOption.TopDirectoryOnly);
|
||||
Dictionary<string, Dictionary<int, string[]>> keyValuePairs = new();
|
||||
foreach (string sourceFile in sourceFiles)
|
||||
{
|
||||
sourceFileNameWithoutExtension = Path.GetFileNameWithoutExtension(sourceFile);
|
||||
if (sourceFileNameWithoutExtension.Split('-').Length > 2)
|
||||
continue;
|
||||
if (sourceFileNameWithoutExtension.StartsWith(dateTime.ToString(format)))
|
||||
continue;
|
||||
fileInfo = new FileInfo(sourceFile);
|
||||
if (fileInfo.Length == 0)
|
||||
moveFiles.Add(sourceFile);
|
||||
day = sourceFileNameWithoutExtension[..8];
|
||||
if (!keyValuePairs.ContainsKey(day))
|
||||
keyValuePairs.Add(day, new Dictionary<int, string[]>());
|
||||
if (sourceFileNameWithoutExtension.Substring(8, 1) == "_")
|
||||
continue;
|
||||
segments = sourceFileNameWithoutExtension.Split('_');
|
||||
if (!string.IsNullOrEmpty(segment1) && segment1 != segments[1])
|
||||
continue;
|
||||
segment1 = segments[1];
|
||||
hour = int.Parse(sourceFileNameWithoutExtension.Substring(8, 2));
|
||||
if (keyValuePairs[day].ContainsKey(hour))
|
||||
continue;
|
||||
keyValuePairs[day].Add(hour, File.ReadAllLines(sourceFile));
|
||||
moveFiles.Add(sourceFile);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(segment1))
|
||||
{
|
||||
foreach (KeyValuePair<string, Dictionary<int, string[]>> keyValuePair in keyValuePairs)
|
||||
{
|
||||
lines.Clear();
|
||||
dateTime = DateTime.ParseExact(keyValuePair.Key, format, CultureInfo.InvariantCulture);
|
||||
foreach (KeyValuePair<int, string[]> item in keyValuePair.Value.OrderBy(l => l.Key))
|
||||
lines.AddRange(item.Value);
|
||||
logFile = string.Concat(argsZero, @"\", dateTime.ToString("yyyy-MM-dd"), "_", segment1, ".log");
|
||||
File.WriteAllLines(logFile, lines);
|
||||
if (dateTime.Hour == 0 && dateTime.Minute == 0 && dateTime.Second == 0 && dateTime.Millisecond == 0)
|
||||
_ = dateTime.AddHours(23).AddMinutes(59).AddSeconds(59);
|
||||
File.SetLastWriteTime(logFile, dateTime);
|
||||
}
|
||||
checkDirectory = string.Concat(argsZero, @"\_ Merged");
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
foreach (string moveFile in moveFiles.Distinct())
|
||||
File.Move(moveFile, string.Concat(checkDirectory, @"\", Path.GetFileName(moveFile)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
50
Helpers/HelperRenameToOldMoveDeleteOld.cs
Normal file
50
Helpers/HelperRenameToOldMoveDeleteOld.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using Serilog;
|
||||
|
||||
namespace File_Folder_Helper.Helpers;
|
||||
|
||||
internal static class HelperRenameToOldMoveDeleteOldMerge
|
||||
{
|
||||
|
||||
internal static void RenameToOldMoveDeleteOld(ILogger log, string argsZero)
|
||||
{
|
||||
string checkDirectory = argsZero[0..^1];
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
log.Information(string.Concat("<", checkDirectory, "> doesn't exist!"));
|
||||
else
|
||||
{
|
||||
string renameFile;
|
||||
string destinationFile;
|
||||
List<string> deleteFiles = new();
|
||||
string[] moveFiles = Directory.GetFiles(argsZero, "*", SearchOption.TopDirectoryOnly);
|
||||
log.Information(string.Concat("<", moveFiles.Length, "> to move"));
|
||||
foreach (string moveFile in moveFiles)
|
||||
{
|
||||
destinationFile = string.Concat(checkDirectory, moveFile[argsZero.Length..]);
|
||||
if (!File.Exists(destinationFile))
|
||||
File.Move(moveFile, destinationFile);
|
||||
else
|
||||
{
|
||||
renameFile = Path.ChangeExtension(destinationFile, string.Concat(Path.GetExtension(destinationFile), ".old"));
|
||||
File.Move(destinationFile, renameFile);
|
||||
File.Move(moveFile, destinationFile);
|
||||
deleteFiles.Add(renameFile);
|
||||
}
|
||||
}
|
||||
log.Information(string.Concat("<", deleteFiles.Count, "> to delete"));
|
||||
foreach (string deleteFile in deleteFiles)
|
||||
{
|
||||
for (short i = 0; i < short.MaxValue; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(deleteFile);
|
||||
break;
|
||||
}
|
||||
catch (Exception) { }
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
182
Helpers/HelperSaveOrCopyContents.cs
Normal file
182
Helpers/HelperSaveOrCopyContents.cs
Normal file
@ -0,0 +1,182 @@
|
||||
using Serilog;
|
||||
using System.Text;
|
||||
|
||||
namespace File_Folder_Helper.Helpers;
|
||||
|
||||
internal static class HelperSaveOrCopyContents
|
||||
{
|
||||
|
||||
internal static void SaveOrCopyContents(ILogger log, string argsZero, ConsoleKey consoleKey)
|
||||
{
|
||||
SearchOption searchOption;
|
||||
bool fileNameWithoutExtension;
|
||||
bool alongSideTopDirectoryOnly = false;
|
||||
bool alongSideAllDirectories = false;
|
||||
bool clipboardTopDirectoryOnly = false;
|
||||
switch (consoleKey)
|
||||
{
|
||||
case ConsoleKey.A:
|
||||
alongSideTopDirectoryOnly = true;
|
||||
searchOption = SearchOption.TopDirectoryOnly;
|
||||
fileNameWithoutExtension = false;
|
||||
break;
|
||||
case ConsoleKey.B:
|
||||
alongSideAllDirectories = true;
|
||||
searchOption = SearchOption.AllDirectories;
|
||||
fileNameWithoutExtension = false;
|
||||
break;
|
||||
case ConsoleKey.C:
|
||||
clipboardTopDirectoryOnly = true;
|
||||
searchOption = SearchOption.TopDirectoryOnly;
|
||||
fileNameWithoutExtension = false;
|
||||
break;
|
||||
case ConsoleKey.D:
|
||||
clipboardTopDirectoryOnly = true;
|
||||
searchOption = SearchOption.AllDirectories;
|
||||
fileNameWithoutExtension = false;
|
||||
break;
|
||||
case ConsoleKey.E:
|
||||
clipboardTopDirectoryOnly = true;
|
||||
searchOption = SearchOption.TopDirectoryOnly;
|
||||
fileNameWithoutExtension = true;
|
||||
break;
|
||||
case ConsoleKey.F:
|
||||
clipboardTopDirectoryOnly = true;
|
||||
searchOption = SearchOption.AllDirectories;
|
||||
fileNameWithoutExtension = true;
|
||||
break;
|
||||
default:
|
||||
throw new Exception();
|
||||
}
|
||||
log.Information("D) Directory, F) File or B) Both?");
|
||||
ConsoleKey dfb = Console.ReadKey().Key;
|
||||
log.Information(string.Empty);
|
||||
if (dfb is not ConsoleKey.D and not ConsoleKey.F and not ConsoleKey.B)
|
||||
throw new Exception("Not valid");
|
||||
else
|
||||
{
|
||||
string fileName = dfb switch
|
||||
{
|
||||
ConsoleKey.D => "Directories",
|
||||
ConsoleKey.F => "Files",
|
||||
ConsoleKey.B => "Both",
|
||||
_ => throw new Exception(),
|
||||
};
|
||||
long now = DateTime.Now.Ticks;
|
||||
StringBuilder data = new();
|
||||
string[] dataCollection;
|
||||
string filePathAndName = string.Concat(Path.GetDirectoryName(argsZero), @"\", fileName, ".txt");
|
||||
if (alongSideTopDirectoryOnly)
|
||||
File.WriteAllText(filePathAndName, string.Empty);
|
||||
else if (alongSideAllDirectories)
|
||||
File.WriteAllText(filePathAndName, string.Concat(argsZero, Environment.NewLine, "Start", Environment.NewLine));
|
||||
switch (dfb)
|
||||
{
|
||||
case ConsoleKey.D:
|
||||
if (alongSideTopDirectoryOnly || clipboardTopDirectoryOnly)
|
||||
{
|
||||
dataCollection = Directory.GetDirectories(argsZero, "*", searchOption);
|
||||
if (!(dataCollection == null) && dataCollection.Length > 0)
|
||||
{
|
||||
foreach (string s in dataCollection)
|
||||
{
|
||||
if (fileNameWithoutExtension)
|
||||
_ = data.Append('\'').Append(Path.GetFileNameWithoutExtension(s)).Append("', ");
|
||||
else
|
||||
_ = data.AppendLine(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (alongSideAllDirectories)
|
||||
{
|
||||
dataCollection = Directory.GetDirectories(argsZero, "*", searchOption);
|
||||
if (!(dataCollection == null) && dataCollection.Length > 0)
|
||||
{
|
||||
foreach (string s in dataCollection)
|
||||
File.AppendAllText(filePathAndName, string.Concat(s.Replace(argsZero, "../"), Environment.NewLine));
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new Exception();
|
||||
break;
|
||||
case ConsoleKey.F:
|
||||
if (alongSideTopDirectoryOnly || clipboardTopDirectoryOnly)
|
||||
{
|
||||
dataCollection = Directory.GetFiles(argsZero, "*", searchOption);
|
||||
if (!(dataCollection == null) && dataCollection.Length > 0)
|
||||
{
|
||||
foreach (string s in dataCollection)
|
||||
{
|
||||
if (fileNameWithoutExtension)
|
||||
_ = data.Append('\'').Append(Path.GetFileNameWithoutExtension(s)).Append("', ");
|
||||
else
|
||||
_ = data.AppendLine(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (alongSideAllDirectories)
|
||||
{
|
||||
dataCollection = Directory.GetFiles(argsZero, "*", searchOption);
|
||||
if (!(dataCollection == null) && dataCollection.Length > 0)
|
||||
{
|
||||
foreach (string s in dataCollection)
|
||||
File.AppendAllText(filePathAndName, string.Concat(s.Replace(argsZero, "../"), Environment.NewLine));
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new Exception();
|
||||
break;
|
||||
case ConsoleKey.B:
|
||||
if (alongSideTopDirectoryOnly || clipboardTopDirectoryOnly)
|
||||
{
|
||||
dataCollection = Directory.GetFiles(argsZero, "*", searchOption);
|
||||
if (!(dataCollection == null) && dataCollection.Length > 0)
|
||||
{
|
||||
foreach (string s in dataCollection)
|
||||
{
|
||||
if (fileNameWithoutExtension)
|
||||
_ = data.Append('\'').Append(Path.GetFileNameWithoutExtension(s)).Append("', ");
|
||||
else
|
||||
_ = data.AppendLine(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (alongSideAllDirectories)
|
||||
{
|
||||
dataCollection = Directory.GetDirectories(argsZero, "*", searchOption);
|
||||
if (!(dataCollection == null) && dataCollection.Length > 0)
|
||||
{
|
||||
foreach (string s in dataCollection)
|
||||
File.AppendAllText(filePathAndName, string.Concat(s.Replace(argsZero, "../"), Environment.NewLine));
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new Exception();
|
||||
break;
|
||||
default:
|
||||
throw new Exception();
|
||||
}
|
||||
TimeSpan timeSpan = new(DateTime.Now.Ticks - now);
|
||||
log.Information(string.Concat(timeSpan.TotalSeconds, " TotalSeconds"));
|
||||
if (alongSideTopDirectoryOnly)
|
||||
{
|
||||
File.WriteAllText(filePathAndName, data.ToString());
|
||||
log.Information("Data written");
|
||||
}
|
||||
else if (clipboardTopDirectoryOnly)
|
||||
{
|
||||
TextCopy.ClipboardService.SetText(data.ToString());
|
||||
log.Information("Data stored in clipboard");
|
||||
}
|
||||
else if (alongSideAllDirectories)
|
||||
{
|
||||
File.AppendAllText(filePathAndName, "Done");
|
||||
log.Information("Data written");
|
||||
}
|
||||
else
|
||||
throw new Exception();
|
||||
log.Information("Press any key to close");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
55
Helpers/HelperStart.cs
Normal file
55
Helpers/HelperStart.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace File_Folder_Helper.Helpers;
|
||||
|
||||
internal static class HelperStart
|
||||
{
|
||||
|
||||
internal static bool Start(string[] errorChecks, string[] successChecks, ProcessStartInfo processStartInfo, string errorFile)
|
||||
{
|
||||
bool result = false;
|
||||
string standardError = string.Empty;
|
||||
string standardOutput = string.Empty;
|
||||
StringBuilder stringBuilder = new();
|
||||
Process? process = Process.Start(processStartInfo);
|
||||
long breakAfter = DateTime.Now.AddSeconds(20).Ticks;
|
||||
for (short j = 0; j < short.MaxValue; j++)
|
||||
{
|
||||
if (process is null || process.HasExited || process.WaitForExit(500) || DateTime.Now.Ticks > breakAfter)
|
||||
break;
|
||||
}
|
||||
if (process is not null && processStartInfo.RedirectStandardOutput)
|
||||
{
|
||||
_ = stringBuilder.Append(process.StandardOutput.ReadToEnd());
|
||||
standardOutput = stringBuilder.ToString();
|
||||
if (string.IsNullOrEmpty(standardOutput))
|
||||
standardOutput = string.Concat(standardOutput);
|
||||
if (!string.IsNullOrEmpty(standardOutput))
|
||||
{
|
||||
result = (from l in successChecks where standardOutput.Contains(l) select 1).Any();
|
||||
if (result)
|
||||
result = !(from l in errorChecks where standardOutput.Contains(l) select 1).Any();
|
||||
}
|
||||
}
|
||||
if (process is not null && processStartInfo.RedirectStandardError)
|
||||
{
|
||||
standardError = process.StandardError.ReadToEnd();
|
||||
if (!string.IsNullOrEmpty(standardError))
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
result = (from l in successChecks where standardError.Contains(l) select 1).Any();
|
||||
if (result)
|
||||
result = !(from l in errorChecks where standardError.Contains(l) select 1).Any();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!result)
|
||||
result = standardOutput == string.Empty && standardError == string.Empty;
|
||||
if (!result)
|
||||
File.WriteAllLines(errorFile, new string[] { standardOutput, Environment.NewLine, Environment.NewLine, standardError });
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
32
Helpers/HelperTooLong.cs
Normal file
32
Helpers/HelperTooLong.cs
Normal file
@ -0,0 +1,32 @@
|
||||
namespace File_Folder_Helper.Helpers;
|
||||
|
||||
internal static class HelperTooLong
|
||||
{
|
||||
|
||||
internal static void TooLong(string workingDirectory, bool delete)
|
||||
{
|
||||
string[] files;
|
||||
string destination;
|
||||
string? parentDirectory;
|
||||
string[] directories = Directory.GetDirectories(workingDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
for (int i = 0; i < directories.Length; i++)
|
||||
{
|
||||
if (delete)
|
||||
{
|
||||
Directory.Delete(directories[i], recursive: true);
|
||||
break;
|
||||
}
|
||||
files = Directory.GetFiles(directories[i], "*", SearchOption.TopDirectoryOnly);
|
||||
for (int f = 0; f < files.Length; f++)
|
||||
File.Delete(files[f]);
|
||||
parentDirectory = Path.GetDirectoryName(directories[i]);
|
||||
if (string.IsNullOrEmpty(parentDirectory))
|
||||
continue;
|
||||
destination = Path.Combine(parentDirectory, i.ToString());
|
||||
if (Path.GetFileName(directories[i]).Length > 3)
|
||||
Directory.Move(directories[i], destination);
|
||||
TooLong(destination, delete);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
139
Helpers/HelperZipFilesByDate.cs
Normal file
139
Helpers/HelperZipFilesByDate.cs
Normal file
@ -0,0 +1,139 @@
|
||||
using Serilog;
|
||||
using System.Globalization;
|
||||
using System.IO.Compression;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace File_Folder_Helper.Helpers;
|
||||
|
||||
internal static class HelperZipFilesByDate
|
||||
{
|
||||
|
||||
internal static void ZipFilesByDate(ILogger log, string sourceDirectory, SearchOption searchOption = SearchOption.TopDirectoryOnly, string dayFormat = "")
|
||||
{
|
||||
string key;
|
||||
bool addFile;
|
||||
string fileName;
|
||||
string[] segments;
|
||||
string[] subFiles;
|
||||
string weekOfYear;
|
||||
FileInfo fileInfo;
|
||||
DateTime creationTime;
|
||||
DateTime lastWriteTime;
|
||||
Regex regex = new("[a-zA-Z0-9]{1,}");
|
||||
DateTime dateTime = DateTime.Now.AddDays(-6);
|
||||
DateTime firstEmail = new(2019, 3, 8);
|
||||
CultureInfo cultureInfo = new("en-US");
|
||||
Calendar calendar = cultureInfo.Calendar;
|
||||
int ticksLength = dateTime.Ticks.ToString().Length;
|
||||
Dictionary<string, DateTime> weeks = new();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
dateTime = firstEmail.AddDays(i);
|
||||
weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
key = string.Concat(dateTime.ToString("yyyy"), "_Week_", weekOfYear);
|
||||
if (!weeks.ContainsKey(key))
|
||||
weeks.Add(key, dateTime);
|
||||
}
|
||||
weekOfYear = calendar.GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
string skipKey = string.Concat(DateTime.Now.ToString("yyyy"), "_Week_", weekOfYear);
|
||||
Dictionary<string, List<string>> keyValuePairs = new();
|
||||
string[] topDirectories = Directory.GetDirectories(sourceDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
if (topDirectories.Length == 0)
|
||||
topDirectories = new string[] { sourceDirectory };
|
||||
foreach (string topDirectory in topDirectories)
|
||||
{
|
||||
keyValuePairs.Clear();
|
||||
subFiles = Directory.GetFiles(topDirectory, "*", searchOption);
|
||||
foreach (string subFile in subFiles)
|
||||
{
|
||||
addFile = false;
|
||||
if (subFile.EndsWith(".zip"))
|
||||
continue;
|
||||
fileName = Path.GetFileName(subFile);
|
||||
fileInfo = new FileInfo(subFile);
|
||||
creationTime = fileInfo.CreationTime;
|
||||
if (creationTime > dateTime)
|
||||
continue;
|
||||
lastWriteTime = fileInfo.LastWriteTime;
|
||||
if (fileName.Contains(lastWriteTime.ToString("yyyyMMdd")) || fileName.Contains(lastWriteTime.ToString("yyyy-MM-dd")) ||
|
||||
fileName.Contains(creationTime.ToString("yyyyMMdd")) || fileName.Contains(creationTime.ToString("yyyy-MM-dd")) ||
|
||||
fileName.Contains(lastWriteTime.ToString("yyMMdd")) || fileName.Contains(lastWriteTime.ToString("yy-MM-dd")) ||
|
||||
fileName.Contains(creationTime.ToString("yyMMdd")) || fileName.Contains(creationTime.ToString("yy-MM-dd")) ||
|
||||
fileName.Contains(lastWriteTime.AddDays(-1).ToString("yyyyMMdd")) || fileName.Contains(lastWriteTime.AddDays(-1).ToString("yyyy-MM-dd")) ||
|
||||
fileName.Contains(creationTime.AddDays(-1).ToString("yyyyMMdd")) || fileName.Contains(creationTime.AddDays(-1).ToString("yyyy-MM-dd")) ||
|
||||
fileName.Contains(lastWriteTime.AddDays(-1).ToString("yyMMdd")) || fileName.Contains(lastWriteTime.AddDays(-1).ToString("yy-MM-dd")) ||
|
||||
fileName.Contains(creationTime.AddDays(-1).ToString("yyMMdd")) || fileName.Contains(creationTime.AddDays(-1).ToString("yy-MM-dd")))
|
||||
addFile = true;
|
||||
if (!addFile && fileName.Length > ticksLength)
|
||||
{
|
||||
MatchCollection matches = regex.Matches(fileName);
|
||||
foreach (Match match in matches.Cast<Match>())
|
||||
{
|
||||
if (match.Value.Length != ticksLength)
|
||||
continue;
|
||||
if (!long.TryParse(match.Value, out long ticks))
|
||||
continue;
|
||||
addFile = true;
|
||||
break;
|
||||
}
|
||||
if (addFile)
|
||||
break;
|
||||
}
|
||||
if (addFile)
|
||||
{
|
||||
weekOfYear = calendar.GetWeekOfYear(lastWriteTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
if (string.IsNullOrEmpty(dayFormat))
|
||||
key = string.Concat(lastWriteTime.ToString("yyyy"), "_Week_", weekOfYear);
|
||||
else
|
||||
key = string.Concat(lastWriteTime.ToString("yyyy"), "_Week_", weekOfYear, "_", lastWriteTime.ToString(dayFormat));
|
||||
if (key == skipKey)
|
||||
continue;
|
||||
if (!keyValuePairs.ContainsKey(key))
|
||||
keyValuePairs.Add(key, new List<string>());
|
||||
keyValuePairs[key].Add(subFile);
|
||||
}
|
||||
}
|
||||
foreach (KeyValuePair<string, List<string>> element in keyValuePairs)
|
||||
{
|
||||
key = string.Concat(topDirectory, @"\", element.Key, ".zip");
|
||||
if (File.Exists(key))
|
||||
{
|
||||
for (short i = 101; i < short.MaxValue; i++)
|
||||
{
|
||||
key = string.Concat(topDirectory, @"\", element.Key, "_", i, ".zip");
|
||||
if (!File.Exists(key))
|
||||
break;
|
||||
}
|
||||
}
|
||||
using ZipArchive zip = ZipFile.Open(key, ZipArchiveMode.Create);
|
||||
foreach (string file in element.Value)
|
||||
{
|
||||
_ = zip.CreateEntryFromFile(file, Path.GetFileName(file));
|
||||
File.Delete(file);
|
||||
}
|
||||
}
|
||||
subFiles = Directory.GetFiles(topDirectory, "*.zip", SearchOption.TopDirectoryOnly);
|
||||
foreach (string subFile in subFiles)
|
||||
{
|
||||
fileName = Path.GetFileNameWithoutExtension(subFile);
|
||||
segments = fileName.Split('_');
|
||||
if (segments.Length > 2)
|
||||
fileName = string.Concat(segments[0], '_', segments[1], '_', segments[2]);
|
||||
if (weeks.ContainsKey(fileName))
|
||||
{
|
||||
try
|
||||
{ File.SetLastWriteTime(subFile, weeks[fileName]); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
if (topDirectory != sourceDirectory)
|
||||
{
|
||||
try
|
||||
{ _ = HelperDeleteEmptyDirectories.DeleteEmptyDirectories(topDirectory); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
log.Information(topDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
138
Jenkinsfile
vendored
Normal file
138
Jenkinsfile
vendored
Normal file
@ -0,0 +1,138 @@
|
||||
#!/usr/bin/env groovy
|
||||
/* groovylint-disable CompileStatic, ConsecutiveStringConcatenation, DuplicateNumberLiteral, DuplicateStringLiteral, LineLength, NestedBlockDepth, NoDef, VariableTypeRequired */
|
||||
import groovy.transform.Field
|
||||
|
||||
@Field String _DDrive = 'D:/'
|
||||
@Field String _AssemblyName = '...'
|
||||
@Field String _NetVersion = 'net6.0'
|
||||
@Field String _GitCommitSeven = '...'
|
||||
@Field String _GitName = 'File-Folder-Helper'
|
||||
@Field String _WorkingDirectoryName = 'IFXApps'
|
||||
@Field String _AgentStaging = 'mestsa07ec-ecmeseaf'
|
||||
@Field String _AgentProduction = 'messa08ec-ecmeseaf'
|
||||
@Field String _DDriveNet = "${_DDrive}${_NetVersion}"
|
||||
@Field String _AgentDevelopment = 'mestsa003-meseafsvc'
|
||||
@Field String _Company = 'Infineon Technologies Americas Corp.'
|
||||
@Field String _ProgramFilesDotnet = 'C:/program files/dotnet/dotnet.exe'
|
||||
|
||||
pipeline {
|
||||
agent {
|
||||
label env.JENKINS_ENVIRONMENT == 'Development' ? _AgentDevelopment : env.JENKINS_ENVIRONMENT == 'Staging' ? _AgentStaging : env.JENKINS_ENVIRONMENT == 'Production' ? _AgentProduction : 'Else'
|
||||
}
|
||||
parameters {
|
||||
string(name: 'GIT_SERVER', defaultValue: env.JENKINS_ENVIRONMENT == 'Development' ? 'mestsa003.infineon.com' : 'mestsa07ec.ec.local', description: 'git server')
|
||||
}
|
||||
stages {
|
||||
// stage('Git') {
|
||||
// steps {
|
||||
// bat(returnStatus: true, script: 'git init')
|
||||
// bat(returnStatus: true, script: 'git remote add origin \\\\' + params.GIT_SERVER + '\\Git\\' + _GitName + '.git')
|
||||
// bat(returnStatus: true, script: 'git pull origin master')
|
||||
// }
|
||||
// }
|
||||
stage('Setup') {
|
||||
steps {
|
||||
script {
|
||||
_AssemblyName = "${env.JOB_NAME}"
|
||||
// _GitCommitSeven = '1234567'
|
||||
_GitCommitSeven = env.GIT_COMMIT.substring(0, 7)
|
||||
def files = findFiles(glob: '*.csproj')
|
||||
if (files.length != 1) {
|
||||
error("Build failed because couldn't find a *.csproj file")
|
||||
}
|
||||
echo """
|
||||
${files[0].name}
|
||||
${files[0].path}
|
||||
${files[0].directory}
|
||||
${files[0].length}
|
||||
${files[0].lastModified}
|
||||
"""
|
||||
_AssemblyName = files[0].name.split('[.]csproj')[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Info') {
|
||||
steps {
|
||||
// echo "GIT_URL_N - ${env.GIT_URL_N}"
|
||||
// echo "BRANCH_NAME ${env.BRANCH_NAME}"
|
||||
// echo "DEPLOY_VERSION ${env.DEPLOY_VERSION}"
|
||||
// echo "GIT_AUTHOR_NAME ${env.GIT_AUTHOR_NAME}"
|
||||
// echo "GIT_LOCAL_BRANCH ${env.GIT_LOCAL_BRANCH}"
|
||||
// echo "GIT_COMMITTER_EMAIL ${env.GIT_COMMITTER_EMAIL}"
|
||||
// echo "GIT_PREVIOUS_COMMIT ${env.GIT_PREVIOUS_COMMIT}"
|
||||
// echo "GIT_PREVIOUS_SUCCESSFUL_COMMIT ${env.GIT_PREVIOUS_SUCCESSFUL_COMMIT}"
|
||||
echo "_AssemblyName ${_AssemblyName}" // ...
|
||||
echo "BUILD_NUMBER ${env.BUILD_NUMBER}" // 11
|
||||
echo "GIT_BRANCH ${env.GIT_BRANCH}" // origin/master
|
||||
echo "GIT_COMMIT ${env.GIT_COMMIT}" // 73b814069f2cf0173a62a8228815a9bc9ba93c41
|
||||
echo "GIT_SERVER ${params.GIT_SERVER}" // ...
|
||||
echo "GIT_URL ${env.GIT_URL}" // D:\ProgramData\Git\....git
|
||||
echo "JENKINS_ENVIRONMENT ${env.JENKINS_ENVIRONMENT}" // 11
|
||||
echo "JENKINS_URL ${env.JENKINS_URL}" // http://localhost:8080/
|
||||
echo "JOB_NAME ${env.JOB_NAME}" // ...
|
||||
echo "WORKSPACE ${env.WORKSPACE}" // D:\.jenkins\_\...
|
||||
}
|
||||
}
|
||||
// stage('Restore') {
|
||||
// steps {
|
||||
// bat(returnStatus: true, script: 'dotnet --info')
|
||||
// }
|
||||
// }
|
||||
stage('Safe storage of app secrets') {
|
||||
steps {
|
||||
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
|
||||
'user-secrets init')
|
||||
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
|
||||
'user-secrets set "Company" "' + _Company + '"')
|
||||
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
|
||||
'user-secrets set "BuildNumber" "' + env.BUILD_NUMBER + '"')
|
||||
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
|
||||
'user-secrets set "GitCommitSeven" "' + _GitCommitSeven + '"')
|
||||
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
|
||||
'user-secrets set "WorkingDirectoryName" "' + _WorkingDirectoryName + '"')
|
||||
}
|
||||
}
|
||||
stage('Core Build') {
|
||||
steps {
|
||||
echo "Build number is ${currentBuild.number}"
|
||||
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
|
||||
'build --runtime win-x64 --self-contained --verbosity quiet')
|
||||
}
|
||||
}
|
||||
stage('Commit Id') {
|
||||
steps {
|
||||
writeFile(file: 'bin/Debug/' + _NetVersion + "/win-x64/${env.GIT_COMMIT}-${env.BUILD_NUMBER}.txt", text: "${env.GIT_URL}")
|
||||
}
|
||||
}
|
||||
stage('Package') {
|
||||
steps {
|
||||
fileOperations([fileZipOperation(folderPath: 'bin/Debug/' + _NetVersion + '/win-x64', outputFolderPath: "${_DDriveNet}/${_GitCommitSeven}-${env.BUILD_NUMBER}-${_PortNumber}-${env.JOB_NAME}-Debug")])
|
||||
fileOperations([fileCopyOperation(excludes: '', flattenFiles: true, includes: "${_AssemblyName}*", renameFiles: false, sourceCaptureExpression: '', targetLocation: "${_DDriveNet}/${_GitCommitSeven}-${env.BUILD_NUMBER}-${_PortNumber}-${env.JOB_NAME}-Debug", targetNameExpression: '')])
|
||||
}
|
||||
}
|
||||
stage('Publish') {
|
||||
steps {
|
||||
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
|
||||
'publish --configuration Release --runtime win-x64 --verbosity quiet ' +
|
||||
"--self-contained true --p:Version=6.0.202-${_GitCommitSeven}-${env.BUILD_NUMBER} -o " +
|
||||
'"' + "${_DDriveNet}/${_GitCommitSeven}-${env.BUILD_NUMBER}-${_PortNumber}-${env.JOB_NAME}" + '"')
|
||||
}
|
||||
}
|
||||
// stage('Force Fail') {
|
||||
// steps {
|
||||
// error("Build failed because of this and that..")
|
||||
// }
|
||||
// }
|
||||
}
|
||||
post {
|
||||
always {
|
||||
dir('bin') {
|
||||
deleteDir()
|
||||
}
|
||||
dir('obj') {
|
||||
deleteDir()
|
||||
}
|
||||
cleanWs()
|
||||
}
|
||||
}
|
||||
}
|
32
Models/AppSettings.cs
Normal file
32
Models/AppSettings.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace File_Folder_Helper.Models;
|
||||
|
||||
public class AppSettings
|
||||
{
|
||||
|
||||
protected string _Company;
|
||||
protected string _WorkingDirectoryName;
|
||||
public string Company => _Company;
|
||||
public string WorkingDirectoryName => _WorkingDirectoryName;
|
||||
|
||||
// public AppSettings()
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
[JsonConstructor]
|
||||
public AppSettings(string company, string workingDirectoryName)
|
||||
{
|
||||
_Company = company;
|
||||
_WorkingDirectoryName = workingDirectoryName;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
24
Models/Binder/AppSettings.cs
Normal file
24
Models/Binder/AppSettings.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace File_Folder_Helper.Models.Binder;
|
||||
|
||||
public class AppSettings
|
||||
{
|
||||
|
||||
[Display(Name = "Company"), Required] public string Company { get; set; }
|
||||
[Display(Name = "Working Directory Name"), Required] public string WorkingDirectoryName { get; set; }
|
||||
|
||||
public AppSettings()
|
||||
{
|
||||
Company = string.Empty;
|
||||
WorkingDirectoryName = string.Empty;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
25
Models/Stateless/AppSettings.cs
Normal file
25
Models/Stateless/AppSettings.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace File_Folder_Helper.Models.Stateless;
|
||||
|
||||
public abstract class AppSettings
|
||||
{
|
||||
|
||||
public static Models.AppSettings Get(IConfigurationRoot configurationRoot)
|
||||
{
|
||||
Models.AppSettings? result;
|
||||
Binder.AppSettings appSettings = configurationRoot.Get<Binder.AppSettings>();
|
||||
string json = JsonSerializer.Serialize(appSettings, new JsonSerializerOptions() { WriteIndented = true });
|
||||
result = JsonSerializer.Deserialize<Models.AppSettings>(json);
|
||||
if (result is null)
|
||||
throw new Exception(json);
|
||||
if (string.IsNullOrEmpty(result.Company))
|
||||
throw new Exception(json);
|
||||
string jsonThis = result.ToString();
|
||||
if (jsonThis != json)
|
||||
throw new Exception(json);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
167
Phares/Shared/Models/IsEnvironment.cs
Normal file
167
Phares/Shared/Models/IsEnvironment.cs
Normal file
@ -0,0 +1,167 @@
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Phares.Shared.Models;
|
||||
|
||||
public class IsEnvironment
|
||||
{
|
||||
|
||||
public enum Name
|
||||
{
|
||||
LinuxDevelopment,
|
||||
LinuxProduction,
|
||||
LinuxStaging,
|
||||
OSXDevelopment,
|
||||
OSXProduction,
|
||||
OSXStaging,
|
||||
WindowsDevelopment,
|
||||
WindowsProduction,
|
||||
WindowsStaging
|
||||
}
|
||||
|
||||
public bool DebuggerWasAttachedDuringConstructor { get; private set; }
|
||||
public bool Development { get; private set; }
|
||||
public bool Linux { get; private set; }
|
||||
public bool OSX { get; private set; }
|
||||
public bool Production { get; private set; }
|
||||
public bool Staging { get; private set; }
|
||||
public bool Windows { get; private set; }
|
||||
public string Profile { get; private set; }
|
||||
public string AppSettingsFileName { get; private set; }
|
||||
public string? ASPNetCoreEnvironment { get; private set; }
|
||||
|
||||
public IsEnvironment(string testCategory)
|
||||
{
|
||||
if (testCategory.EndsWith(".json"))
|
||||
{
|
||||
Production = testCategory == "appsettings.json";
|
||||
Staging = testCategory.EndsWith(nameof(Staging));
|
||||
OSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
|
||||
Development = testCategory.EndsWith(nameof(Development));
|
||||
Linux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
|
||||
DebuggerWasAttachedDuringConstructor = Debugger.IsAttached;
|
||||
Windows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
ASPNetCoreEnvironment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
|
||||
}
|
||||
else
|
||||
{
|
||||
DebuggerWasAttachedDuringConstructor = Debugger.IsAttached;
|
||||
OSX = !string.IsNullOrEmpty(testCategory) && testCategory.StartsWith(nameof(OSX));
|
||||
ASPNetCoreEnvironment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
|
||||
Linux = !string.IsNullOrEmpty(testCategory) && testCategory.StartsWith(nameof(Linux));
|
||||
Staging = !string.IsNullOrEmpty(testCategory) && testCategory.EndsWith(nameof(Staging));
|
||||
Windows = !string.IsNullOrEmpty(testCategory) && testCategory.StartsWith(nameof(Windows));
|
||||
Production = !string.IsNullOrEmpty(testCategory) && testCategory.EndsWith(nameof(Production));
|
||||
Development = !string.IsNullOrEmpty(testCategory) && testCategory.EndsWith(nameof(Development));
|
||||
}
|
||||
Profile = GetProfile();
|
||||
AppSettingsFileName = GetAppSettingsFileName(processesCount: null);
|
||||
}
|
||||
|
||||
public IsEnvironment(bool isDevelopment, bool isStaging, bool isProduction)
|
||||
{
|
||||
Staging = isStaging;
|
||||
Production = isProduction;
|
||||
Development = isDevelopment;
|
||||
OSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
|
||||
Linux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
|
||||
DebuggerWasAttachedDuringConstructor = Debugger.IsAttached;
|
||||
Windows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
ASPNetCoreEnvironment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
|
||||
Profile = GetProfile();
|
||||
AppSettingsFileName = GetAppSettingsFileName(processesCount: null);
|
||||
}
|
||||
|
||||
public IsEnvironment(int? processesCount, bool nullASPNetCoreEnvironmentIsDevelopment, bool nullASPNetCoreEnvironmentIsProduction)
|
||||
{
|
||||
OSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
|
||||
Linux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
|
||||
DebuggerWasAttachedDuringConstructor = Debugger.IsAttached;
|
||||
Windows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
ASPNetCoreEnvironment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
|
||||
if (nullASPNetCoreEnvironmentIsDevelopment && nullASPNetCoreEnvironmentIsProduction)
|
||||
throw new Exception();
|
||||
else if (string.IsNullOrEmpty(ASPNetCoreEnvironment) && nullASPNetCoreEnvironmentIsProduction)
|
||||
Production = true;
|
||||
else if (string.IsNullOrEmpty(ASPNetCoreEnvironment) && nullASPNetCoreEnvironmentIsDevelopment)
|
||||
Development = true;
|
||||
else if (string.IsNullOrEmpty(ASPNetCoreEnvironment) && !nullASPNetCoreEnvironmentIsDevelopment && !nullASPNetCoreEnvironmentIsProduction)
|
||||
throw new Exception();
|
||||
else
|
||||
{
|
||||
Staging = ASPNetCoreEnvironment is not null && ASPNetCoreEnvironment.EndsWith(nameof(Staging));
|
||||
Production = ASPNetCoreEnvironment is not null && ASPNetCoreEnvironment.EndsWith(nameof(Production));
|
||||
Development = ASPNetCoreEnvironment is not null && ASPNetCoreEnvironment.EndsWith(nameof(Development));
|
||||
}
|
||||
Profile = GetProfile();
|
||||
AppSettingsFileName = GetAppSettingsFileName(processesCount);
|
||||
}
|
||||
|
||||
private string GetProfile()
|
||||
{
|
||||
string result;
|
||||
if (Windows && Production)
|
||||
result = nameof(Production);
|
||||
else if (Windows && Staging)
|
||||
result = nameof(Staging);
|
||||
else if (Windows && Development)
|
||||
result = nameof(Development);
|
||||
else if (Linux && Production)
|
||||
result = nameof(Name.LinuxProduction);
|
||||
else if (Linux && Staging)
|
||||
result = nameof(Name.LinuxStaging);
|
||||
else if (Linux && Development)
|
||||
result = nameof(Name.LinuxDevelopment);
|
||||
else if (OSX && Production)
|
||||
result = nameof(Name.OSXProduction);
|
||||
else if (OSX && Staging)
|
||||
result = nameof(Name.OSXStaging);
|
||||
else if (OSX && Development)
|
||||
result = nameof(Name.OSXDevelopment);
|
||||
else
|
||||
throw new Exception();
|
||||
return result;
|
||||
}
|
||||
|
||||
private string GetAppSettingsFileName(int? processesCount)
|
||||
{
|
||||
string result;
|
||||
if (Production)
|
||||
{
|
||||
if (processesCount is null)
|
||||
result = "appsettings.json";
|
||||
else
|
||||
result = $"appsettings.{processesCount}.json";
|
||||
}
|
||||
else
|
||||
{
|
||||
string environment;
|
||||
if (Staging)
|
||||
environment = nameof(Staging);
|
||||
else if (Development)
|
||||
environment = nameof(Development);
|
||||
else
|
||||
throw new Exception();
|
||||
if (processesCount is null)
|
||||
result = $"appsettings.{environment}.json";
|
||||
else
|
||||
result = $"appsettings.{environment}.{processesCount}.json";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string GetEnvironmentName(IsEnvironment isEnvironment)
|
||||
{
|
||||
string result;
|
||||
if (isEnvironment.Windows)
|
||||
result = nameof(Windows);
|
||||
else if (isEnvironment.Linux)
|
||||
result = nameof(Linux);
|
||||
else if (isEnvironment.OSX)
|
||||
result = nameof(OSX);
|
||||
else
|
||||
throw new Exception();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
10
Phares/Shared/Models/Stateless/Methods/IMethodName.cs
Normal file
10
Phares/Shared/Models/Stateless/Methods/IMethodName.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Phares.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IMethodName
|
||||
{
|
||||
|
||||
static string? GetActualAsyncMethodName([CallerMemberName] string? name = null) => name;
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace Phares.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IWorkingDirectory
|
||||
{
|
||||
|
||||
static string GetWorkingDirectory(string? executingAssemblyName, string subDirectoryName) => WorkingDirectory.GetWorkingDirectory(executingAssemblyName, subDirectoryName);
|
||||
|
||||
}
|
50
Phares/Shared/Models/Stateless/Methods/WorkingDirectory.cs
Normal file
50
Phares/Shared/Models/Stateless/Methods/WorkingDirectory.cs
Normal file
@ -0,0 +1,50 @@
|
||||
namespace Phares.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class WorkingDirectory
|
||||
{
|
||||
|
||||
internal static string GetWorkingDirectory(string? executingAssemblyName, string subDirectoryName)
|
||||
{
|
||||
string result = string.Empty;
|
||||
if (executingAssemblyName is null)
|
||||
throw new Exception();
|
||||
string traceFile;
|
||||
List<string> directories = new();
|
||||
Environment.SpecialFolder[] specialFolders = new Environment.SpecialFolder[]
|
||||
{
|
||||
Environment.SpecialFolder.LocalApplicationData,
|
||||
Environment.SpecialFolder.ApplicationData,
|
||||
Environment.SpecialFolder.History,
|
||||
Environment.SpecialFolder.CommonApplicationData,
|
||||
Environment.SpecialFolder.InternetCache
|
||||
};
|
||||
foreach (Environment.SpecialFolder specialFolder in specialFolders)
|
||||
directories.Add(Path.Combine(Environment.GetFolderPath(specialFolder), subDirectoryName, executingAssemblyName));
|
||||
foreach (string directory in directories)
|
||||
{
|
||||
for (int i = 1; i < 3; i++)
|
||||
{
|
||||
if (i == 1)
|
||||
result = directory;
|
||||
else
|
||||
result = string.Concat("D", directory[1..]);
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(result))
|
||||
_ = Directory.CreateDirectory(result);
|
||||
traceFile = string.Concat(result, @"\", DateTime.Now.Ticks, ".txt");
|
||||
File.WriteAllText(traceFile, traceFile);
|
||||
File.Delete(traceFile);
|
||||
break;
|
||||
}
|
||||
catch (Exception) { result = string.Empty; }
|
||||
}
|
||||
if (!string.IsNullOrEmpty(result))
|
||||
break;
|
||||
}
|
||||
if (string.IsNullOrEmpty(result))
|
||||
throw new Exception("Unable to set working directory!");
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
151
Program.cs
Normal file
151
Program.cs
Normal file
@ -0,0 +1,151 @@
|
||||
using File_Folder_Helper.Models;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Phares.Shared.Models;
|
||||
using Phares.Shared.Models.Stateless.Methods;
|
||||
using Serilog;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
|
||||
namespace File_Folder_Helper;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
|
||||
public static void Secondary(List<string> args)
|
||||
{
|
||||
LoggerConfiguration loggerConfiguration = new();
|
||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables()
|
||||
.AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true);
|
||||
IConfigurationRoot configurationRoot = configurationBuilder.Build();
|
||||
AppSettings appSettings = Models.Stateless.AppSettings.Get(configurationRoot);
|
||||
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
|
||||
throw new Exception("Working directory name must have a value!");
|
||||
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
||||
Log.Logger = loggerConfiguration.CreateLogger();
|
||||
ILogger log = Log.ForContext<Program>();
|
||||
int silentIndex = args.IndexOf("s");
|
||||
if (silentIndex > -1)
|
||||
args.RemoveAt(silentIndex);
|
||||
try
|
||||
{
|
||||
int? singleCharIndex = null;
|
||||
ConsoleKey consoleKey = ConsoleKey.End;
|
||||
ConsoleKey[] consoleKeys = new ConsoleKey[]
|
||||
{
|
||||
ConsoleKey.A,
|
||||
ConsoleKey.B,
|
||||
ConsoleKey.C,
|
||||
ConsoleKey.D,
|
||||
ConsoleKey.E,
|
||||
ConsoleKey.F,
|
||||
ConsoleKey.L,
|
||||
ConsoleKey.R,
|
||||
ConsoleKey.T,
|
||||
ConsoleKey.Z,
|
||||
ConsoleKey.Delete
|
||||
};
|
||||
for (int i = 0; i < args.Count; i++)
|
||||
{
|
||||
if (args[i].Length == 1 && Enum.TryParse(args[i], out consoleKey) && consoleKeys.Contains(consoleKey))
|
||||
{
|
||||
singleCharIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (consoleKey is not ConsoleKey.End && !consoleKeys.Contains(consoleKey))
|
||||
consoleKey = ConsoleKey.End;
|
||||
if (singleCharIndex is not null)
|
||||
args.RemoveAt(singleCharIndex.Value);
|
||||
if (!args.Any())
|
||||
log.Information("Must pass a argument!");
|
||||
else if (Directory.Exists(args[0]) && File.Exists(Path.Combine(args[0], string.Concat(Path.GetFileName(args[0]), ".dll"))))
|
||||
Helpers.HelperILMerge.ILMerge(args[0]);
|
||||
else if (Directory.Exists(args[0]))
|
||||
{
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
if (consoleKeys.Contains(consoleKey))
|
||||
break;
|
||||
log.Information("A) Save (Top Directory Only),");
|
||||
log.Information("B) Save (All Directories),");
|
||||
log.Information("C) Clipboard (Top Directory Only),");
|
||||
log.Information("D) Clipboard (All Directories),");
|
||||
log.Information("E) Clipboard (Top Directory Only and File Name Without Extension),");
|
||||
log.Information("F) Clipboard (All Directories and File Name Without Extension),");
|
||||
log.Information("L) Log Merge (APC Log [0-9{8}]_*.log),");
|
||||
log.Information("R) Rename to old, copy, delete old");
|
||||
log.Information("T) Too long rename");
|
||||
log.Information("Z) Zip file(s) by date,");
|
||||
log.Information("Delete) Delete empty directories,");
|
||||
consoleKey = Console.ReadKey().Key;
|
||||
log.Information(string.Empty);
|
||||
}
|
||||
switch (consoleKey)
|
||||
{
|
||||
case ConsoleKey.A:
|
||||
case ConsoleKey.B:
|
||||
case ConsoleKey.C:
|
||||
case ConsoleKey.E:
|
||||
case ConsoleKey.F:
|
||||
Helpers.HelperSaveOrCopyContents.SaveOrCopyContents(log, args[0], consoleKey);
|
||||
break;
|
||||
case ConsoleKey.L:
|
||||
Helpers.HelperLogMerge.LogMerge(args[0]);
|
||||
break;
|
||||
case ConsoleKey.R:
|
||||
Helpers.HelperRenameToOldMoveDeleteOldMerge.RenameToOldMoveDeleteOld(log, args[0]);
|
||||
break;
|
||||
case ConsoleKey.T:
|
||||
Helpers.HelperTooLong.TooLong(args[0], delete: false);
|
||||
Helpers.HelperTooLong.TooLong(args[0], delete: true);
|
||||
break;
|
||||
case ConsoleKey.Z:
|
||||
Helpers.HelperZipFilesByDate.ZipFilesByDate(log, args[0]);
|
||||
break;
|
||||
default:
|
||||
switch (consoleKey)
|
||||
{
|
||||
case ConsoleKey.Delete:
|
||||
for (int j = 1; j < 6; j++)
|
||||
{
|
||||
if (!Helpers.HelperDeleteEmptyDirectories.DeleteEmptyDirectories(args[0]))
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Exception();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new Exception(args[0]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
|
||||
}
|
||||
if (silentIndex > -1)
|
||||
Console.WriteLine("Done. Bye");
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Done. Press 'Enter' to end");
|
||||
_ = Console.ReadLine();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
if (args is not null)
|
||||
Secondary(args.ToList());
|
||||
else
|
||||
Secondary(new List<string>());
|
||||
}
|
||||
|
||||
}
|
51
appsettings.Development.json
Normal file
51
appsettings.Development.json
Normal file
@ -0,0 +1,51 @@
|
||||
{
|
||||
"Company": "Infineon Technologies Americas Corp.",
|
||||
"Linux": {},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Log4netProvider": "Debug",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"Serilog": {
|
||||
"Using": [
|
||||
"Serilog.Sinks.Console",
|
||||
"Serilog.Sinks.File"
|
||||
],
|
||||
"MinimumLevel": "Debug",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "Debug",
|
||||
"Args": {
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}.{MethodName}) ({InstanceId}) ({RemoteIpAddress}) {Message}{NewLine}{Exception}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Console",
|
||||
"Args": {
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}.{MethodName}) ({InstanceId}) ({RemoteIpAddress}) {Message}{NewLine}{Exception}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "%workingDirectory% - Log/log-.txt",
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}.{MethodName}) ({InstanceId}) ({RemoteIpAddress}) {Message}{NewLine}{Exception}",
|
||||
"rollingInterval": "Hour"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Enrich": [
|
||||
"FromLogContext",
|
||||
"WithMachineName",
|
||||
"WithThreadId"
|
||||
],
|
||||
"Properties": {
|
||||
"Application": "Sample"
|
||||
}
|
||||
},
|
||||
"WorkingDirectoryName": "IFXApps",
|
||||
"Windows": {}
|
||||
}
|
51
appsettings.Staging.json
Normal file
51
appsettings.Staging.json
Normal file
@ -0,0 +1,51 @@
|
||||
{
|
||||
"Company": "Infineon Technologies Americas Corp.",
|
||||
"Linux": {},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Log4netProvider": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"Serilog": {
|
||||
"Using": [
|
||||
"Serilog.Sinks.Console",
|
||||
"Serilog.Sinks.File"
|
||||
],
|
||||
"MinimumLevel": "Debug",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "Debug",
|
||||
"Args": {
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}.{MethodName}) ({InstanceId}) ({RemoteIpAddress}) {Message}{NewLine}{Exception}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Console",
|
||||
"Args": {
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}.{MethodName}) ({InstanceId}) ({RemoteIpAddress}) {Message}{NewLine}{Exception}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "%workingDirectory% - Log/log-.txt",
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}.{MethodName}) ({InstanceId}) ({RemoteIpAddress}) {Message}{NewLine}{Exception}",
|
||||
"rollingInterval": "Hour"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Enrich": [
|
||||
"FromLogContext",
|
||||
"WithMachineName",
|
||||
"WithThreadId"
|
||||
],
|
||||
"Properties": {
|
||||
"Application": "Sample"
|
||||
}
|
||||
},
|
||||
"WorkingDirectoryName": "IFXApps",
|
||||
"Windows": {}
|
||||
}
|
51
appsettings.json
Normal file
51
appsettings.json
Normal file
@ -0,0 +1,51 @@
|
||||
{
|
||||
"Company": "Infineon Technologies Americas Corp.",
|
||||
"Linux": {},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Log4netProvider": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"Serilog": {
|
||||
"Using": [
|
||||
"Serilog.Sinks.Console",
|
||||
"Serilog.Sinks.File"
|
||||
],
|
||||
"MinimumLevel": "Information",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "Debug",
|
||||
"Args": {
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}.{MethodName}) ({InstanceId}) ({RemoteIpAddress}) {Message}{NewLine}{Exception}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Console",
|
||||
"Args": {
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}.{MethodName}) ({InstanceId}) ({RemoteIpAddress}) {Message}{NewLine}{Exception}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "%workingDirectory% - Log/log-.txt",
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}.{MethodName}) ({InstanceId}) ({RemoteIpAddress}) {Message}{NewLine}{Exception}",
|
||||
"rollingInterval": "Hour"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Enrich": [
|
||||
"FromLogContext",
|
||||
"WithMachineName",
|
||||
"WithThreadId"
|
||||
],
|
||||
"Properties": {
|
||||
"Application": "Sample"
|
||||
}
|
||||
},
|
||||
"WorkingDirectoryName": "IFXApps",
|
||||
"Windows": {}
|
||||
}
|
14
package.json
Normal file
14
package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"scripts": {
|
||||
"Alpha": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
"nuget-clear": "dotnet nuget locals all --clear",
|
||||
"build": "dotnet build --runtime win-x64 --self-contained",
|
||||
"build-Package-Management": "dotnet build --runtime win-x64 --self-contained --source https://packagemanagement.eu.infineon.com:4430/api/v2/",
|
||||
"build-nuget-And-Package-Management": "dotnet build --runtime win-x64 --self-contained --source https://api.nuget.org/v3/index.json --source https://packagemanagement.eu.infineon.com:4430/api/v2/",
|
||||
"build-All-Sources": "dotnet build --runtime win-x64 --self-contained --source https://api.nuget.org/v3/index.json --source https://packagemanagement.eu.infineon.com:4430/api/v2/ --source https://tfs.intra.infineon.com/tfs/ManufacturingIT/_packaging/eaf/nuget/v3/index.json --source http://192.168.0.73:5002/v3/index.json",
|
||||
"dotnet-format": "dotnet format --report .vscode --verbosity detailed --severity warn",
|
||||
"MSBuild": "\"C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/MSBuild/Current/Bin/MSBuild.exe\" /target:Build /restore:True /p:RestoreSources=https://api.nuget.org/v3/index.json%3Bhttps://packagemanagement.eu.infineon.com:4430/api/v2/%3Bhttps://tfs.intra.infineon.com/tfs/ManufacturingIT/_packaging/eaf/nuget/v3/index.json /DetailedSummary /ConsoleLoggerParameters:PerformanceSummary;ErrorsOnly; /property:Configuration=Debug;TargetFrameworkVersion=v4.8 File-Folder-Helper.csproj",
|
||||
"pull": "git pull",
|
||||
"garbage-collect": "git gc"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user