diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..f07a33b
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,278 @@
+###############################
+# Core EditorConfig Options #
+###############################
+
+root=true
+
+# All files
+[*]
+indent_style=space
+trim_trailing_whitespace=true
+
+# Code files
+[*.{asax,ascx,aspx,cs,csx,cshtml,css,htm,html,js,json,jsx,master,razor,resjson,skin,ts,tsx,vb,vbx}]
+indent_size=4
+insert_final_newline=true
+charset=utf-8-bom
+
+# Xml files
+[*.{appxmanifest,build,config,csproj,dbml,discomap,dtd,jsproj,lsproj,njsproj,nuspec,proj,props,resw,resx,StyleCop,targets,tasks,vbproj,xaml,xamlx,xml,xoml,xsd}]
+indent_size=2
+tab_width=2
+
+###############################
+# .NET Coding Conventions #
+###############################
+
+[*.{cs,vb}]
+# Organize usings
+dotnet_sort_system_directives_first=true
+dotnet_separate_import_directive_groups=false
+
+# this. preferences
+dotnet_style_qualification_for_field=false:hint
+dotnet_style_qualification_for_property=false:hint
+dotnet_style_qualification_for_method=false:hint
+dotnet_style_qualification_for_event=false:hint
+
+# Language keywords vs BCL types preferences
+dotnet_style_predefined_type_for_locals_parameters_members=true:hint
+dotnet_style_predefined_type_for_member_access=false:hint
+
+# Parentheses preferences
+dotnet_style_parentheses_in_arithmetic_binary_operators=always_for_clarity:silent
+dotnet_style_parentheses_in_relational_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
+
+# Modifier preferences
+dotnet_style_require_accessibility_modifiers=for_non_interface_members:hint
+dotnet_style_readonly_field=true:suggestion
+
+# Expression-level preferences
+dotnet_style_object_initializer=true:suggestion
+dotnet_style_collection_initializer=true:suggestion
+dotnet_style_explicit_tuple_names=true:suggestion
+dotnet_style_null_propagation=true:suggestion
+dotnet_style_coalesce_expression=true:suggestion
+dotnet_style_prefer_is_null_check_over_reference_equality_method=true:silent
+dotnet_style_prefer_inferred_tuple_names=true:suggestion
+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:silent
+dotnet_style_prefer_conditional_expression_over_return=true:silent
+dotnet_style_prefer_compound_assignment=true:suggestion
+
+###############################
+# Naming Conventions #
+###############################
+
+# Naming rules
+
+dotnet_naming_rule.interface_should_be_begins_with_i.severity=suggestion
+dotnet_naming_rule.interface_should_be_begins_with_i.symbols=interface
+dotnet_naming_rule.interface_should_be_begins_with_i.style=begins_with_i
+
+dotnet_naming_rule.types_should_be_pascal_case.severity=suggestion
+dotnet_naming_rule.types_should_be_pascal_case.symbols=types
+dotnet_naming_rule.types_should_be_pascal_case.style=pascal_case
+
+dotnet_naming_rule.non_field_members_should_be_pascal_case.severity=suggestion
+dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols=non_field_members
+dotnet_naming_rule.non_field_members_should_be_pascal_case.style=pascal_case
+
+dotnet_naming_rule.private_or_internal_field_should_be_begins_with__.severity=suggestion
+dotnet_naming_rule.private_or_internal_field_should_be_begins_with__.symbols=private_or_internal_field
+dotnet_naming_rule.private_or_internal_field_should_be_begins_with__.style=begins_with__
+
+dotnet_naming_rule.private_or_internal_static_field_should_be_begins_with__.severity=suggestion
+dotnet_naming_rule.private_or_internal_static_field_should_be_begins_with__.symbols=private_or_internal_static_field
+dotnet_naming_rule.private_or_internal_static_field_should_be_begins_with__.style=begins_with__
+
+dotnet_naming_rule.constant_fields_should_be_pascal_case.severity=suggestion
+dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols=constant_fields
+dotnet_naming_rule.constant_fields_should_be_pascal_case.style=pascal_case
+
+# Symbol specifications
+
+dotnet_naming_symbols.interface.applicable_kinds=interface
+dotnet_naming_symbols.interface.applicable_accessibilities=public, internal, private, protected, protected_internal
+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
+dotnet_naming_symbols.private_or_internal_field.required_modifiers=
+
+dotnet_naming_symbols.private_or_internal_static_field.applicable_kinds=field
+dotnet_naming_symbols.private_or_internal_static_field.applicable_accessibilities=internal, private
+dotnet_naming_symbols.private_or_internal_static_field.required_modifiers=static
+
+dotnet_naming_symbols.types.applicable_kinds=class, struct, interface, enum
+dotnet_naming_symbols.types.applicable_accessibilities=public, internal, private, protected, protected_internal
+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
+dotnet_naming_symbols.non_field_members.required_modifiers=
+
+dotnet_naming_symbols.constant_fields.applicable_kinds=field
+dotnet_naming_symbols.constant_fields.applicable_accessibilities=*
+dotnet_naming_symbols.constant_fields.required_modifiers=const
+
+# Naming styles
+
+dotnet_naming_style.pascal_case.required_prefix=
+dotnet_naming_style.pascal_case.required_suffix=
+dotnet_naming_style.pascal_case.word_separator=
+dotnet_naming_style.pascal_case.capitalization=pascal_case
+
+dotnet_naming_style.begins_with_i.required_prefix=I
+dotnet_naming_style.begins_with_i.required_suffix=
+dotnet_naming_style.begins_with_i.word_separator=
+dotnet_naming_style.begins_with_i.capitalization=pascal_case
+
+dotnet_naming_style.begins_with__.required_prefix=_
+dotnet_naming_style.begins_with__.required_suffix=
+dotnet_naming_style.begins_with__.word_separator=
+dotnet_naming_style.begins_with__.capitalization=camel_case
+
+
+###############################
+# C# Code Style Rules #
+###############################
+
+[*.cs]
+# var preferences
+csharp_style_var_for_built_in_types=false:hint
+csharp_style_var_when_type_is_apparent=true:hint
+csharp_style_var_elsewhere=false:hint
+
+# Expression-bodied members
+csharp_style_expression_bodied_methods=false:silent
+csharp_style_expression_bodied_constructors=false:silent
+csharp_style_expression_bodied_operators=false:silent
+csharp_style_expression_bodied_properties=true:silent
+csharp_style_expression_bodied_indexers=true:silent
+csharp_style_expression_bodied_accessors=true:silent
+csharp_style_expression_bodied_lambdas=true:silent
+csharp_style_expression_bodied_local_functions=false:silent
+
+# Pattern-matching preferences
+csharp_style_pattern_matching_over_is_with_cast_check=true:suggestion
+csharp_style_pattern_matching_over_as_with_null_check=true:suggestion
+csharp_style_prefer_switch_expression=true:suggestion
+
+# Null-checking preferences
+csharp_style_throw_expression=true:suggestion
+csharp_style_conditional_delegate_call=true:suggestion
+
+# 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
+
+# Expression-level preferences
+csharp_prefer_braces=true:silent
+csharp_style_deconstructed_variable_declaration=true:suggestion
+csharp_prefer_simple_default_expression=true:suggestion
+csharp_prefer_simple_using_statement=true:suggestion
+csharp_style_pattern_local_over_anonymous_function=true:suggestion
+csharp_style_inlined_variable_declaration=true:suggestion
+csharp_style_prefer_index_operator=true:suggestion
+csharp_style_prefer_range_operator=true:suggestion
+csharp_style_unused_value_assignment_preference=discard_variable:suggestion
+csharp_style_unused_value_expression_statement_preference=discard_variable:silent
+
+# 'using' directive preferences
+csharp_using_directive_placement=outside_namespace:silent
+
+###############################
+# C# Code Quality Rules #
+###############################
+
+# Parameter preferences
+dotnet_code_quality_unused_parameters=all:suggestion
+
+###############################
+# C# Formatting Rules #
+###############################
+
+# New line preferences
+csharp_new_line_before_open_brace=all
+csharp_new_line_before_else=true
+csharp_new_line_before_catch=true
+csharp_new_line_before_finally=true
+csharp_new_line_before_members_in_object_initializers=false
+csharp_new_line_before_members_in_anonymous_types=true
+csharp_new_line_between_query_expression_clauses=true
+
+# Indentation preferences
+csharp_indent_block_contents=true
+csharp_indent_braces=false
+csharp_indent_case_contents_when_block=true
+csharp_indent_case_contents=true
+csharp_indent_switch_labels=true
+csharp_indent_labels=flush_left
+
+# Space preferences
+csharp_space_after_cast=false
+csharp_space_after_keywords_in_control_flow_statements=true
+csharp_space_between_method_call_parameter_list_parentheses=false
+csharp_space_between_method_declaration_parameter_list_parentheses=false
+csharp_space_between_parentheses=false
+csharp_space_before_colon_in_inheritance_clause=true
+csharp_space_after_colon_in_inheritance_clause=true
+csharp_space_around_binary_operators=before_and_after
+csharp_space_between_method_declaration_empty_parameter_list_parentheses=false
+csharp_space_between_method_call_name_and_opening_parenthesis=false
+csharp_space_between_method_call_empty_parameter_list_parentheses=false
+csharp_space_after_comma=true
+csharp_space_after_dot=false
+csharp_space_after_semicolon_in_for_statement=true
+csharp_space_around_declaration_statements=false
+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_declaration_name_and_open_parenthesis=false
+csharp_space_between_square_brackets=false
+
+# Wrapping preferences
+csharp_preserve_single_line_statements=true
+csharp_preserve_single_line_blocks=true
+
+###############################
+# Resharper specifics #
+###############################
+
+# ReSharper properties
+resharper_csharp_insert_final_newline=true
+resharper_csharp_max_line_length=200
+resharper_csharp_use_indent_from_vs=true
+resharper_css_use_indent_from_vs=true
+resharper_html_use_indent_from_vs=true
+resharper_js_max_line_length=200
+resharper_js_use_indent_from_vs=true
+resharper_keep_existing_declaration_block_arrangement=true
+resharper_keep_existing_embedded_block_arrangement=false
+resharper_keep_existing_enum_arrangement=false
+resharper_max_attribute_length_for_same_line=200
+resharper_place_accessorholder_attribute_on_same_line=false
+resharper_place_field_attribute_on_same_line=false
+resharper_space_within_single_line_array_initializer_braces=true
+resharper_xmldoc_max_line_length=200
+resharper_xmldoc_use_indent_from_vs=true
+resharper_xml_blank_line_after_pi=false
+resharper_xml_max_line_length=200
+resharper_xml_use_indent_from_vs=true
+
+# ReSharper inspection severities
+resharper_comment_typo_highlighting=hint
+resharper_identifier_typo_highlighting=hint
+resharper_markup_attribute_typo_highlighting=hint
+resharper_markup_text_typo_highlighting=hint
+resharper_mvc_partial_view_not_resolved_highlighting=warning
+resharper_mvc_template_not_resolved_highlighting=hint
+resharper_mvc_view_not_resolved_highlighting=warning
+resharper_redundant_base_qualifier_highlighting=warning
+resharper_string_literal_typo_highlighting=hint
diff --git a/Epinova.InRiverConnector.sln b/Epinova.InRiverConnector.sln
index ba7a45e..0a25686 100644
--- a/Epinova.InRiverConnector.sln
+++ b/Epinova.InRiverConnector.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.26430.15
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29418.71
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EpiserverAdapter", "src\EpiserverAdapter\EpiserverAdapter.csproj", "{F6FC6A0D-D026-4FC3-873C-19AF480821D5}"
EndProject
@@ -15,6 +15,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EpiserverAdapterTests", "te
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EpiserverRestApi", "EpiserverRestApi\EpiserverRestApi.csproj", "{36C58EE9-57CD-4EC6-A600-F689A8F4B22B}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{7A7A4228-2651-4ADA-8099-0A83CC0B8453}"
+ ProjectSection(SolutionItems) = preProject
+ .editorconfig = .editorconfig
+ .gitignore = .gitignore
+ License.txt = License.txt
+ README.md = README.md
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
diff --git a/Epinova.InRiverConnector.sln.DotSettings b/Epinova.InRiverConnector.sln.DotSettings
index 8d8bfed..a7077b6 100644
--- a/Epinova.InRiverConnector.sln.DotSettings
+++ b/Epinova.InRiverConnector.sln.DotSettings
@@ -1,34 +1,7 @@
-
- True
- HINT
- HINT
- HINT
- WARNING
- HINT
- WARNING
<?xml version="1.0" encoding="utf-16"?><Profile name="Silent"><AspOptimizeRegisterDirectives>False</AspOptimizeRegisterDirectives><HtmlReformatCode>True</HtmlReformatCode><CSArrangeThisQualifier>True</CSArrangeThisQualifier><CSRemoveCodeRedundancies>False</CSRemoveCodeRedundancies><CSUseAutoProperty>False</CSUseAutoProperty><CSMakeFieldReadonly>False</CSMakeFieldReadonly><CSUseVar><BehavourStyle>CAN_CHANGE_TO_EXPLICIT</BehavourStyle><LocalVariableStyle>ALWAYS_EXPLICIT</LocalVariableStyle><ForeachVariableStyle>ALWAYS_EXPLICIT</ForeachVariableStyle></CSUseVar><CSUpdateFileHeader>False</CSUpdateFileHeader><VBOptimizeImports>True</VBOptimizeImports><VBShortenReferences>True</VBShortenReferences><JsInsertSemicolon>True</JsInsertSemicolon><JsReformatCode>True</JsReformatCode><CssReformatCode>True</CssReformatCode><XMLReformatCode>True</XMLReformatCode><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName /></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><VBReformatCode>True</VBReformatCode><CSReformatCode>True</CSReformatCode><CSReorderTypeMembers>True</CSReorderTypeMembers><CSEnforceVarKeywordUsageSettings>True</CSEnforceVarKeywordUsageSettings><CSCodeStyleAttributes ArrangeTypeAccessModifier="False" ArrangeTypeMemberAccessModifier="False" SortModifiers="False" RemoveRedundantParentheses="False" AddMissingParentheses="False" ArrangeBraces="False" ArrangeAttributes="False" ArrangeArgumentsStyle="False" ArrangeCodeBodyStyle="False" ArrangeVarStyle="True" /></Profile>
- Silent
Silent
- UseClrName
- 200
- NEVER
- False
- NEVER
- True
- False
- 200
- False
- False
- False
- 200
- False
- 200
False
- 2
- 2
- False
- 200
<?xml version="1.0" encoding="utf-16"?>
<Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns">
<TypePattern Priority="0" DisplayName="COM interfaces or structs">
@@ -45,160 +18,8 @@
</Or>
</TypePattern.Match>
</TypePattern>
- <TypePattern Priority="0" DisplayName="NUnit Test Fixtures" RemoveRegions="AllExceptGenerated">
- <TypePattern.Match>
- <And>
- <Kind Is="Class" />
- <Or>
- <HasAttribute Name="NUnit.Framework.TestFixtureAttribute" Inherited="True" />
- <HasAttribute Name="NUnit.Framework.TestCaseFixtureAttribute" Inherited="True" />
- </Or>
- </And>
- </TypePattern.Match>
- <Entry DisplayName="Static Fields and Constants">
- <Entry.Match>
- <Or>
- <Kind Is="Constant" />
- <And>
- <Kind Is="Field" />
- <Static />
- </And>
- </Or>
- </Entry.Match>
- <Entry.SortBy>
- <Kind Is="Member" />
- <Name Is="Enter Pattern Here" />
- </Entry.SortBy>
- </Entry>
- <Entry DisplayName="Public Delegates" Priority="100">
- <Entry.Match>
- <And>
- <Access Is="Public" />
- <Kind Is="Delegate" />
- </And>
- </Entry.Match>
- <Entry.SortBy>
- <Name />
- </Entry.SortBy>
- </Entry>
- <Entry DisplayName="Public Enums" Priority="100">
- <Entry.Match>
- <And>
- <Access Is="Public" />
- <Kind Is="Enum" />
- </And>
- </Entry.Match>
- <Entry.SortBy>
- <Name />
- </Entry.SortBy>
- </Entry>
- <Entry DisplayName="Fields">
- <Entry.Match>
- <And>
- <Kind Is="Field" />
- <Not>
- <Static />
- </Not>
- </And>
- </Entry.Match>
- <Entry.SortBy>
- <Readonly />
- <Name />
- </Entry.SortBy>
- </Entry>
- <Entry DisplayName="Constructors">
- <Entry.Match>
- <Kind Is="Constructor" />
- </Entry.Match>
- <Entry.SortBy>
- <Static />
- </Entry.SortBy>
- </Entry>
- <Entry DisplayName="Properties, Indexers" Priority="100">
- <Entry.Match>
- <Or>
- <Kind Is="Property" />
- <Kind Is="Indexer" />
- </Or>
- </Entry.Match>
- <Entry.SortBy>
- <Static />
- <Access />
- <Name Is="Enter Pattern Here" />
- </Entry.SortBy>
- </Entry>
- <Entry DisplayName="Interface Implementations" Priority="100">
- <Entry.Match>
- <And>
- <Kind Is="Member" />
- <ImplementsInterface />
- </And>
- </Entry.Match>
- <Entry.SortBy>
- <ImplementsInterface Name="IDisposable" />
- <Name Is="Enter Pattern Here" />
- </Entry.SortBy>
- </Entry>
- <Region Name="Setup/Teardown">
- <Entry DisplayName="Setup/Teardown Methods" Priority="100">
- <Entry.Match>
- <And>
- <Kind Is="Method" />
- <Or>
- <HasAttribute Name="NUnit.Framework.SetUpAttribute" Inherited="True" />
- <HasAttribute Name="NUnit.Framework.TearDownAttribute" Inherited="True" />
- <HasAttribute Name="NUnit.Framework.FixtureSetUpAttribute" Inherited="True" />
- <HasAttribute Name="NUnit.Framework.FixtureTearDownAttribute" Inherited="True" />
- <HasAttribute Name="NUnit.Framework.TestFixtureSetUpAttribute" Inherited="True" />
- <HasAttribute Name="NUnit.Framework.TestFixtureTearDownAttribute" Inherited="True" />
- <HasAttribute Name="NUnit.Framework.OneTimeSetUpAttribute" />
- <HasAttribute Name="NUnit.Framework.OneTimeTearDownAttribute" />
- </Or>
- </And>
- </Entry.Match>
- <Entry.SortBy>
- <Name Is="Enter Pattern Here" />
- </Entry.SortBy>
- </Entry>
- </Region>
- <Entry DisplayName="Test Methods">
- <Entry.Match>
- <And>
- <Kind Is="Method" />
- <Or>
- <HasAttribute Name="NUnit.Framework.TestAttribute" />
- <HasAttribute Name="NUnit.Framework.TestCaseAttribute" />
- </Or>
- </And>
- </Entry.Match>
- <Entry.SortBy>
- <Name />
- </Entry.SortBy>
- </Entry>
- <Entry DisplayName="All other members">
- <Entry.SortBy>
- <Access />
- <Static />
- <Virtual />
- <Name Is="Enter Pattern Here" />
- </Entry.SortBy>
- </Entry>
- <Region Name="Nested type: ${0}">
- <Region.GroupBy>
- <Name Is="Enter Pattern Here" />
- </Region.GroupBy>
- <Entry DisplayName="Nested Types">
- <Entry.Match>
- <Kind Is="Type" />
- </Entry.Match>
- <Entry.SortBy>
- <Name Is="Enter Pattern Here" />
- </Entry.SortBy>
- </Entry>
- </Region>
- </TypePattern>
<TypePattern Priority="0" DisplayName="Default Pattern" RemoveRegions="AllExceptGenerated">
- <Entry DisplayName="Public Delegates" Priority="100">
+ <Entry Priority="100" DisplayName="Public Delegates">
<Entry.Match>
<And>
<Access Is="Public" />
@@ -209,7 +30,7 @@
<Name />
</Entry.SortBy>
</Entry>
- <Entry DisplayName="Public Enums" Priority="100">
+ <Entry Priority="100" DisplayName="Public Enums">
<Entry.Match>
<And>
<Access Is="Public" />
@@ -257,7 +78,7 @@
<Static />
</Entry.SortBy>
</Entry>
- <Entry DisplayName="Properties, Indexers" Priority="100">
+ <Entry Priority="100" DisplayName="Properties, Indexers">
<Entry.Match>
<Or>
<Kind Is="Property" />
@@ -270,7 +91,7 @@
<Name Is="Enter Pattern Here" />
</Entry.SortBy>
</Entry>
- <Entry DisplayName="Interface Implementations" Priority="100">
+ <Entry Priority="100" DisplayName="Interface Implementations">
<Entry.Match>
<And>
<Kind Is="Member" />
@@ -290,38 +111,20 @@
<Name Is="Enter Pattern Here" />
</Entry.SortBy>
</Entry>
- <Region Name="Nested type: ${0}">
- <Region.GroupBy>
+ <Entry DisplayName="Nested Types">
+ <Entry.Match>
+ <Kind Is="Type" />
+ </Entry.Match>
+ <Entry.SortBy>
<Name Is="Enter Pattern Here" />
- </Region.GroupBy>
- <Entry DisplayName="Nested Types">
- <Entry.Match>
- <Kind Is="Type" />
- </Entry.Match>
- <Entry.SortBy>
- <Name Is="Enter Pattern Here" />
- </Entry.SortBy>
- </Entry>
- </Region>
+ </Entry.SortBy>
+ </Entry>
</TypePattern>
</Patterns>
- UseVarWhenEvident
- UseVarWhenEvident
- UseVarWhenEvident
- ID
- UI
- True
- True
- True
- True
- True
- True
+ <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" />
+ <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" />
True
- True
- True
- True
- True
- True
- True
Integration, Manual
- True
\ No newline at end of file
+ True
+ True
+
diff --git a/EpiserverRestApi/App_Start/FilterConfig.cs b/EpiserverRestApi/App_Start/FilterConfig.cs
index 220f990..2dde5ad 100644
--- a/EpiserverRestApi/App_Start/FilterConfig.cs
+++ b/EpiserverRestApi/App_Start/FilterConfig.cs
@@ -1,5 +1,4 @@
-using System.Web;
-using System.Web.Mvc;
+using System.Web.Mvc;
namespace EpiserverRestApi
{
diff --git a/EpiserverRestApi/App_Start/RouteConfig.cs b/EpiserverRestApi/App_Start/RouteConfig.cs
index 24dd621..af409fd 100644
--- a/EpiserverRestApi/App_Start/RouteConfig.cs
+++ b/EpiserverRestApi/App_Start/RouteConfig.cs
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using System.Web.Mvc;
+using System.Web.Mvc;
using System.Web.Routing;
namespace EpiserverRestApi
diff --git a/EpiserverRestApi/App_Start/WebApiConfig.cs b/EpiserverRestApi/App_Start/WebApiConfig.cs
index 1b043af..6a9d193 100644
--- a/EpiserverRestApi/App_Start/WebApiConfig.cs
+++ b/EpiserverRestApi/App_Start/WebApiConfig.cs
@@ -1,7 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web.Http;
+using System.Web.Http;
namespace EpiserverRestApi
{
diff --git a/EpiserverRestApi/ChannelDataController.cs b/EpiserverRestApi/ChannelDataController.cs
index a0fb9fd..274e62d 100644
--- a/EpiserverRestApi/ChannelDataController.cs
+++ b/EpiserverRestApi/ChannelDataController.cs
@@ -16,9 +16,9 @@ public class ChannelDataController : ApiController
[Route("GetVariations/{nodeName}")]
public IEnumerable GetVariations(string nodeName)
{
- authenticate();
+ Authenticate();
- int channelId = int.Parse(ConfigurationManager.AppSettings["channelId"]);
+ int channelId = Int32.Parse(ConfigurationManager.AppSettings["channelId"]);
Entity node = RemoteManager.ChannelService.GetEntitiesForChannelAndEntityType(channelId, "ChannelNode")
.FirstOrDefault(x => x.DisplayName.Data.ToString().Equals(nodeName, StringComparison.InvariantCultureIgnoreCase));
if (node == null)
@@ -28,12 +28,13 @@ public IEnumerable GetVariations(string nodeName)
.Select(x => x.Name);
}
- private void authenticate()
+ private static void Authenticate()
{
- AuthenticationTicket ticket = RemoteManager.Authenticate(ConfigurationManager.AppSettings["authenticationUrl"], ConfigurationManager.AppSettings["username"], ConfigurationManager.AppSettings["password"]);
+ AuthenticationTicket ticket = RemoteManager.Authenticate(ConfigurationManager.AppSettings["authenticationUrl"], ConfigurationManager.AppSettings["username"],
+ ConfigurationManager.AppSettings["password"]);
// Initialize RemoteManager
RemoteManager.CreateInstance(ConfigurationManager.AppSettings["authenticationUrl"], ticket);
}
}
-}
\ No newline at end of file
+}
diff --git a/EpiserverRestApi/EpiserverRestApi.csproj b/EpiserverRestApi/EpiserverRestApi.csproj
index 3834395..88dffab 100644
--- a/EpiserverRestApi/EpiserverRestApi.csproj
+++ b/EpiserverRestApi/EpiserverRestApi.csproj
@@ -1,6 +1,6 @@
-
+
Debug
@@ -23,8 +23,6 @@
-
-
true
@@ -49,9 +47,12 @@
False
..\lib\inRiver.Remoting.dll
+
+ ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll
+
-
- ..\packages\structuremap.web.4.0.0.315\lib\net40\StructureMap.Web.dll
+
+ ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll
@@ -64,12 +65,15 @@
+
+ ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll
+
..\packages\System.Security.AccessControl.4.4.0\lib\net461\System.Security.AccessControl.dll
-
- ..\packages\System.Security.Cryptography.Xml.4.4.0\lib\net461\System.Security.Cryptography.Xml.dll
+
+ ..\packages\System.Security.Cryptography.Xml.4.4.2\lib\net461\System.Security.Cryptography.Xml.dll
..\packages\System.Security.Permissions.4.4.0\lib\net461\System.Security.Permissions.dll
@@ -86,6 +90,30 @@
+
+ ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll
+
+
+ ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll
+
+
+ ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll
+
+
+ ..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll
+
+
+ ..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll
+
+
+ ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll
+
+
+ ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll
+
+
+ ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll
+
@@ -97,49 +125,13 @@
True
..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll
-
- ..\packages\Newtonsoft.Json.11.0.1\lib\net45\Newtonsoft.Json.dll
-
-
- ..\packages\Microsoft.AspNet.WebApi.Client.5.2.4\lib\net45\System.Net.Http.Formatting.dll
-
-
- True
- ..\packages\Microsoft.AspNet.WebPages.3.2.4\lib\net45\System.Web.Helpers.dll
-
-
- ..\packages\Microsoft.AspNet.WebApi.Core.5.2.4\lib\net45\System.Web.Http.dll
-
-
- ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.4\lib\net45\System.Web.Http.WebHost.dll
-
-
- True
- ..\packages\Microsoft.AspNet.Mvc.5.2.4\lib\net45\System.Web.Mvc.dll
-
..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll
-
- True
- ..\packages\Microsoft.AspNet.Razor.3.2.4\lib\net45\System.Web.Razor.dll
-
-
- True
- ..\packages\Microsoft.AspNet.WebPages.3.2.4\lib\net45\System.Web.WebPages.dll
-
-
- True
- ..\packages\Microsoft.AspNet.WebPages.3.2.4\lib\net45\System.Web.WebPages.Deployment.dll
-
-
- True
- ..\packages\Microsoft.AspNet.WebPages.3.2.4\lib\net45\System.Web.WebPages.Razor.dll
-
True
..\packages\WebGrease.1.6.0\lib\WebGrease.dll
@@ -149,11 +141,6 @@
..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll
-
-
- ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll
-
-
@@ -167,7 +154,9 @@
-
+
+ Designer
+
Web.config
@@ -175,9 +164,7 @@
Web.config
-
-
-
+
@@ -215,16 +202,4 @@
-
-
- This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
-
-
-
\ No newline at end of file
diff --git a/EpiserverRestApi/Global.asax.cs b/EpiserverRestApi/Global.asax.cs
index bdf5864..0720ba7 100644
--- a/EpiserverRestApi/Global.asax.cs
+++ b/EpiserverRestApi/Global.asax.cs
@@ -1,24 +1,16 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
+using System.Web;
using System.Web.Http;
-using System.Web.Mvc;
-using System.Web.Optimization;
using System.Web.Routing;
namespace EpiserverRestApi
{
- public class WebApiApplication : System.Web.HttpApplication
+ public class WebApiApplication : HttpApplication
{
protected void Application_Start()
{
-
GlobalConfiguration.Configure(WebApiConfig.Register);
-
+
RouteConfig.RegisterRoutes(RouteTable.Routes);
-
}
-
}
}
diff --git a/EpiserverRestApi/Properties/AssemblyInfo.cs b/EpiserverRestApi/Properties/AssemblyInfo.cs
index c5b91ee..f6c64fe 100644
--- a/EpiserverRestApi/Properties/AssemblyInfo.cs
+++ b/EpiserverRestApi/Properties/AssemblyInfo.cs
@@ -1,10 +1,6 @@
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
[assembly: AssemblyTitle("EpiserverRestApi")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
@@ -13,23 +9,7 @@
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9335fc88-0142-4f65-bd11-dcfad7f7fbe3")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Revision and Build Numbers
-// by using the '*' as shown below:
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyVersion("1.4.0.0")]
+[assembly: AssemblyFileVersion("1.4.0.0")]
diff --git a/EpiserverRestApi/Web.Debug.config b/EpiserverRestApi/Web.Debug.config
index d7712aa..5d488d4 100644
--- a/EpiserverRestApi/Web.Debug.config
+++ b/EpiserverRestApi/Web.Debug.config
@@ -27,4 +27,4 @@
-->
-
+
\ No newline at end of file
diff --git a/EpiserverRestApi/Web.Release.config b/EpiserverRestApi/Web.Release.config
index 28a4d5f..602152c 100644
--- a/EpiserverRestApi/Web.Release.config
+++ b/EpiserverRestApi/Web.Release.config
@@ -28,4 +28,4 @@
-->
-
+
\ No newline at end of file
diff --git a/EpiserverRestApi/Web.config b/EpiserverRestApi/Web.config
index 48861b3..754f835 100644
--- a/EpiserverRestApi/Web.config
+++ b/EpiserverRestApi/Web.config
@@ -9,10 +9,10 @@
-
-
-
-
+
+
+
+
@@ -23,7 +23,8 @@
-
+
@@ -34,7 +35,7 @@
-
+
@@ -44,18 +45,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
@@ -90,18 +79,35 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
\ No newline at end of file
diff --git a/EpiserverRestApi/packages.config b/EpiserverRestApi/packages.config
index 806b934..4bd7f07 100644
--- a/EpiserverRestApi/packages.config
+++ b/EpiserverRestApi/packages.config
@@ -1,26 +1,25 @@
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
+
-
+
diff --git a/EpiserverRestApi/test.txt b/EpiserverRestApi/test.txt
deleted file mode 100644
index 30d74d2..0000000
--- a/EpiserverRestApi/test.txt
+++ /dev/null
@@ -1 +0,0 @@
-test
\ No newline at end of file
diff --git a/lib/Newtonsoft.Json.dll b/lib/Newtonsoft.Json.dll
deleted file mode 100644
index b7ef414..0000000
Binary files a/lib/Newtonsoft.Json.dll and /dev/null differ
diff --git a/lib/System.Net.Http.Formatting.dll b/lib/System.Net.Http.Formatting.dll
deleted file mode 100644
index 3b76acd..0000000
Binary files a/lib/System.Net.Http.Formatting.dll and /dev/null differ
diff --git a/lib/System.Web.Http.WebHost.dll b/lib/System.Web.Http.WebHost.dll
deleted file mode 100644
index 4f2b581..0000000
Binary files a/lib/System.Web.Http.WebHost.dll and /dev/null differ
diff --git a/lib/System.Web.Http.dll b/lib/System.Web.Http.dll
deleted file mode 100644
index e1dbdd1..0000000
Binary files a/lib/System.Web.Http.dll and /dev/null differ
diff --git a/src/EpiserverAdapter/AsyncHelper.cs b/src/EpiserverAdapter/AsyncHelper.cs
new file mode 100644
index 0000000..eb14a9a
--- /dev/null
+++ b/src/EpiserverAdapter/AsyncHelper.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Epinova.InRiverConnector.EpiserverAdapter
+{
+ internal static class AsyncHelper
+ {
+ private static readonly TaskFactory TaskFactory = new
+ TaskFactory(CancellationToken.None,
+ TaskCreationOptions.None,
+ TaskContinuationOptions.None,
+ TaskScheduler.Default);
+
+ public static TResult RunSync(Func> func)
+ => TaskFactory
+ .StartNew(func)
+ .Unwrap()
+ .GetAwaiter()
+ .GetResult();
+
+ public static void RunSync(Func func)
+ => TaskFactory
+ .StartNew(func)
+ .Unwrap()
+ .GetAwaiter()
+ .GetResult();
+ }
+}
diff --git a/src/EpiserverAdapter/CatalogCodeGenerator.cs b/src/EpiserverAdapter/CatalogCodeGenerator.cs
index 92f6f52..4aba9ed 100644
--- a/src/EpiserverAdapter/CatalogCodeGenerator.cs
+++ b/src/EpiserverAdapter/CatalogCodeGenerator.cs
@@ -14,12 +14,17 @@ public CatalogCodeGenerator(IConfiguration config, IEntityService entityService)
_entityService = entityService;
}
+ public string GetAssociationKey(string entityCode, string parentCode, string associationName)
+ {
+ return $"{entityCode}_{parentCode}_{associationName}";
+ }
+
public string GetEpiserverCode(int entityId)
{
if (entityId == 0)
return null;
- var entity = _entityService.GetEntity(entityId, LoadLevel.DataOnly);
+ Entity entity = _entityService.GetEntity(entityId, LoadLevel.DataOnly);
return GetEpiserverCode(entity);
}
@@ -33,12 +38,12 @@ public string GetEpiserverCode(Entity entity)
if (entity.LoadLevel < LoadLevel.DataOnly)
entity = _entityService.GetEntity(entity.Id, LoadLevel.DataOnly);
- var entityTypeId = entity.EntityType.Id;
-
+ string entityTypeId = entity.EntityType.Id;
+
if (_config.EpiCodeMapping.ContainsKey(entityTypeId))
{
- var mappedCodeFieldId = _config.EpiCodeMapping[entityTypeId];
- var mappedCodeField = entity.Fields.FirstOrDefault(x => x.FieldType.Id == mappedCodeFieldId);
+ string mappedCodeFieldId = _config.EpiCodeMapping[entityTypeId];
+ Field mappedCodeField = entity.Fields.FirstOrDefault(x => x.FieldType.Id == mappedCodeFieldId);
if (mappedCodeField != null)
return GetPrefixedValue(mappedCodeField.Data);
}
@@ -46,6 +51,11 @@ public string GetEpiserverCode(Entity entity)
return GetPrefixedValue(entity.Id);
}
+ public string GetPrefixedCode(string skuCode)
+ {
+ return GetPrefixedValue(skuCode);
+ }
+
public string GetRelationName(string skuId, string parentCode)
{
return $"{_config.ChannelIdPrefix}_{skuId}_{parentCode}";
@@ -56,19 +66,9 @@ public string GetRelationName(int entityId, int parentEntityId)
return $"{_config.ChannelIdPrefix}_{entityId}_{parentEntityId}";
}
- public string GetPrefixedCode(string skuCode)
- {
- return GetPrefixedValue(skuCode);
- }
-
private string GetPrefixedValue(object data)
{
return $"{_config.ChannelIdPrefix}{data}";
}
-
- public string GetAssociationKey(string entityCode, string parentCode, string associationName)
- {
- return $"{entityCode}_{parentCode}_{associationName}";
- }
}
-}
\ No newline at end of file
+}
diff --git a/src/EpiserverAdapter/CatalogElementContainer.cs b/src/EpiserverAdapter/CatalogElementContainer.cs
index a0febc5..53d59ca 100644
--- a/src/EpiserverAdapter/CatalogElementContainer.cs
+++ b/src/EpiserverAdapter/CatalogElementContainer.cs
@@ -5,6 +5,11 @@ namespace Epinova.InRiverConnector.EpiserverAdapter
{
public class CatalogElementContainer
{
+ private readonly List _addedAssociations;
+ private readonly List _addedEntities;
+ private readonly List _addedNodes;
+ private readonly List _addedRelations;
+
public CatalogElementContainer()
{
Nodes = new List();
@@ -18,25 +23,20 @@ public CatalogElementContainer()
_addedAssociations = new List();
}
- private readonly List _addedEntities;
- private readonly List _addedNodes;
- private readonly List _addedRelations;
- private readonly List _addedAssociations;
-
- public List Nodes { get; }
+ public List Associations { get; set; }
public List Entries { get; }
+ public List Nodes { get; }
public List Relations { get; set; }
- public List Associations { get; set; }
- public void AddRelation(XElement relation, string relationName)
+ public void AddAssociation(XElement association, string associationKey)
{
- Relations.Add(relation);
- _addedRelations.Add(relationName);
+ Associations.Add(association);
+ _addedAssociations.Add(associationKey);
}
- public bool HasRelation(string relationName)
+ public void AddAssociationKey(string associationKey)
{
- return _addedRelations.Contains(relationName);
+ _addedAssociations.Add(associationKey);
}
public void AddEntry(XElement entry, string entryCode)
@@ -45,36 +45,36 @@ public void AddEntry(XElement entry, string entryCode)
_addedEntities.Add(entryCode);
}
- public bool HasEntry(string entryCode)
- {
- return _addedEntities.Contains(entryCode);
- }
-
public void AddNode(XElement node, string nodeCode)
{
Nodes.Add(node);
_addedNodes.Add(nodeCode);
}
- public bool HasNode(string nodeCode)
+ public void AddRelation(XElement relation, string relationName)
{
- return _addedNodes.Contains(nodeCode);
+ Relations.Add(relation);
+ _addedRelations.Add(relationName);
}
- public void AddAssociationKey(string associationKey)
+ public bool HasAssociation(string associationKey)
{
- _addedAssociations.Add(associationKey);
+ return _addedAssociations.Contains(associationKey);
}
- public void AddAssociation(XElement association, string associationKey)
+ public bool HasEntry(string entryCode)
{
- Associations.Add(association);
- _addedAssociations.Add(associationKey);
+ return _addedEntities.Contains(entryCode);
}
- public bool HasAssociation(string associationKey)
+ public bool HasNode(string nodeCode)
{
- return _addedAssociations.Contains(associationKey);
+ return _addedNodes.Contains(nodeCode);
+ }
+
+ public bool HasRelation(string relationName)
+ {
+ return _addedRelations.Contains(relationName);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/EpiserverAdapter/ChannelPublisher.cs b/src/EpiserverAdapter/ChannelPublisher.cs
index 602448b..11d3e81 100644
--- a/src/EpiserverAdapter/ChannelPublisher.cs
+++ b/src/EpiserverAdapter/ChannelPublisher.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Threading.Tasks;
using System.Xml.Linq;
using Epinova.InRiverConnector.EpiserverAdapter.Communication;
using Epinova.InRiverConnector.EpiserverAdapter.Helpers;
@@ -52,7 +53,7 @@ public ChannelPublisher(IConfiguration config,
_catalogCodeGenerator = catalogCodeGenerator;
}
- public ConnectorEvent ChannelEntityAdded(Entity channel, int entityId)
+ public async Task ChannelEntityAddedAsync(Entity channel, int entityId)
{
ConnectorEvent connectorEvent =
ConnectorEventHelper.InitiateEvent(_config, ConnectorEventType.ChannelEntityAdded, $"Received entity added for entity {entityId} in channel {channel.DisplayName}", 0);
@@ -79,28 +80,28 @@ public ConnectorEvent ChannelEntityAdded(Entity channel, int entityId)
structureEntities.AddRange(childLinks);
- PublishEntities(channel, connectorEvent, structureEntities);
+ await PublishEntitiesAsync(channel, connectorEvent, structureEntities);
string channelName = _mappingHelper.GetNameForEntity(channel, 100);
- _epiApi.ImportUpdateCompleted(channelName, ImportUpdateCompletedEventType.EntityAdded, true);
+ await _epiApi.ImportUpdateCompletedAsync(channelName, ImportUpdateCompletedEventType.EntityAdded, true);
return connectorEvent;
}
- public ConnectorEvent ChannelEntityDeleted(Entity channel, Entity deletedEntity)
+ public async Task ChannelEntityDeletedAsync(Entity channel, Entity deletedEntity)
{
string channelName = _mappingHelper.GetNameForEntity(channel, 100);
ConnectorEvent connectorEvent = ConnectorEventHelper.InitiateEvent(_config,
ConnectorEventType.ChannelEntityDeleted,
$"Received entity deleted for entity {deletedEntity.Id} in channel {channelName}.", 0);
- Delete(channel, deletedEntity);
+ await DeleteAsync(channel, deletedEntity);
- _epiApi.DeleteCompleted(channelName, DeleteCompletedEventType.EntitiyDeleted);
+ await _epiApi.DeleteCompletedAsync(channelName, DeleteCompletedEventType.EntitiyDeleted);
return connectorEvent;
}
- public ConnectorEvent ChannelEntityUpdated(Entity channel, int entityId, string data)
+ public async Task ChannelEntityUpdatedAsync(Entity channel, int entityId, string data)
{
ConnectorEvent connectorEvent = ConnectorEventHelper.InitiateEvent(_config, ConnectorEventType.ChannelEntityUpdated,
$"Received entity update for entity {entityId} in channel {channel.DisplayName}", 0);
@@ -112,12 +113,12 @@ public ConnectorEvent ChannelEntityUpdated(Entity channel, int entityId, string
return connectorEvent;
string folderDateTime = DateTime.Now.ToString(Constants.PublicationFolderNameTimeComponent);
- var resourceIncluded = false;
+ bool resourceIncluded = false;
List structureEntities = _entityService.GetStructureEntitiesForEntityInChannel(_config.ChannelId, entityId);
if (updatedEntity.EntityType.Id.Equals("Resource"))
{
- resourceIncluded = HandleResourceUpdate(updatedEntity, folderDateTime);
+ resourceIncluded = await HandleResourceUpdateAsync(updatedEntity, folderDateTime);
}
else
{
@@ -125,11 +126,11 @@ public ConnectorEvent ChannelEntityUpdated(Entity channel, int entityId, string
if (updatedEntity.EntityType.Id.Equals("Item") && data != null && data.Split(',').Contains("SKUs"))
{
- HandleSkuUpdate(entityId, channel, connectorEvent, structureEntities, out resourceIncluded);
+ resourceIncluded = await HandleSkuUpdateAsync(entityId, channel, connectorEvent, structureEntities);
}
else if (updatedEntity.EntityType.Id.Equals("ChannelNode"))
{
- HandleChannelNodeUpdate(channel, structureEntities, connectorEvent);
+ await HandleChannelNodeUpdateAsync(channel, structureEntities, connectorEvent);
return connectorEvent;
}
@@ -139,16 +140,16 @@ public ConnectorEvent ChannelEntityUpdated(Entity channel, int entityId, string
IntegrationLogger.Write(LogLevel.Debug, "Starting automatic import!");
- _epiApi.ImportCatalog(catalogDocumentName);
- _epiApi.NotifyEpiserverPostImport(catalogDocumentName);
+ await _epiApi.ImportCatalogAsync(catalogDocumentName);
+ await _epiApi.NotifyEpiserverPostImportAsync(catalogDocumentName);
}
string channelName = _mappingHelper.GetNameForEntity(channel, 100);
- _epiApi.ImportUpdateCompleted(channelName, ImportUpdateCompletedEventType.EntityUpdated, resourceIncluded);
+ await _epiApi.ImportUpdateCompletedAsync(channelName, ImportUpdateCompletedEventType.EntityUpdated, resourceIncluded);
return connectorEvent;
}
- public ConnectorEvent ChannelLinkAdded(Entity channel, int sourceEntityId, int targetEntityId, string linkTypeId, int? linkEntityId)
+ public async Task ChannelLinkAddedAsync(Entity channel, int sourceEntityId, int targetEntityId, string linkTypeId, int? linkEntityId)
{
ConnectorEvent connectorEvent = ConnectorEventHelper.InitiateEvent(_config, ConnectorEventType.ChannelLinkAdded,
$"Received link added for sourceEntityId {sourceEntityId} and targetEntityId {targetEntityId} in channel {channel.DisplayName}", 0);
@@ -165,10 +166,10 @@ public ConnectorEvent ChannelLinkAdded(Entity channel, int sourceEntityId, int t
parentIds.Reverse();
parentIds.RemoveAt(0);
- for (var i = 0; i < parentIds.Count - 1; i++)
+ for (int i = 0; i < parentIds.Count - 1; i++)
{
- int entityId = int.Parse(parentIds[i]);
- int parentId = int.Parse(parentIds[i + 1]);
+ int entityId = Int32.Parse(parentIds[i]);
+ int parentId = Int32.Parse(parentIds[i + 1]);
structureEntities.AddRange(RemoteManager.ChannelService.GetAllStructureEntitiesForEntityWithParentInChannel(channel.Id, entityId, parentId));
}
@@ -180,8 +181,6 @@ public ConnectorEvent ChannelLinkAdded(Entity channel, int sourceEntityId, int t
structureEntities.AddRange(RemoteManager.ChannelService.GetAllChannelStructureEntitiesFromPath(targetEntityPath));
}
-
-
// Remove duplicates
structureEntities = structureEntities.GroupBy(x => x.EntityId).Select(x => x.First()).ToList();
@@ -190,15 +189,15 @@ public ConnectorEvent ChannelLinkAdded(Entity channel, int sourceEntityId, int t
ConnectorEventHelper.UpdateEvent(connectorEvent, "Done fetching channel entities", 10);
- PublishEntities(channel, connectorEvent, structureEntities);
+ await PublishEntitiesAsync(channel, connectorEvent, structureEntities);
string channelName = _mappingHelper.GetNameForEntity(channel, 100);
- _epiApi.ImportUpdateCompleted(channelName, ImportUpdateCompletedEventType.LinkAdded, true);
+ await _epiApi.ImportUpdateCompletedAsync(channelName, ImportUpdateCompletedEventType.LinkAdded, true);
return connectorEvent;
}
- public ConnectorEvent ChannelLinkDeleted(Entity channel, int sourceEntityId, int targetEntityId, string linkTypeId, int? linkEntityId)
+ public async Task ChannelLinkDeletedAsync(Entity channel, int sourceEntityId, int targetEntityId, string linkTypeId, int? linkEntityId)
{
ConnectorEvent connectorEvent = ConnectorEventHelper.InitiateEvent(_config, ConnectorEventType.ChannelLinkDeleted,
$"Received link deleted for sourceEntityId {sourceEntityId} and targetEntityId {targetEntityId} in channel {channel.DisplayName.Data}", 0);
@@ -208,20 +207,20 @@ public ConnectorEvent ChannelLinkDeleted(Entity channel, int sourceEntityId, int
if (removalTarget.EntityType.Id == "Resource")
{
- DeleteResourceLink(removalTarget, removalSource);
+ await DeleteResourceLinkAsync(removalTarget, removalSource);
}
else
{
- DeleteLink(removalSource, removalTarget, linkTypeId);
+ await DeleteLinkAsync(removalSource, removalTarget, linkTypeId);
}
string channelName = _mappingHelper.GetNameForEntity(channel, 100);
- _epiApi.DeleteCompleted(channelName, DeleteCompletedEventType.LinkDeleted);
+ await _epiApi.DeleteCompletedAsync(channelName, DeleteCompletedEventType.LinkDeleted);
return connectorEvent;
}
- public ConnectorEvent ChannelLinkUpdated(Entity channel, int sourceEntityId, int targetEntityId, string linkTypeId, int? linkEntityId)
+ public async Task ChannelLinkUpdatedAsync(Entity channel, int sourceEntityId, int targetEntityId, string linkTypeId, int? linkEntityId)
{
List targetEntityStructure = _entityService.GetEntityInChannelWithParent(_config.ChannelId, targetEntityId, sourceEntityId);
@@ -234,8 +233,8 @@ public ConnectorEvent ChannelLinkUpdated(Entity channel, int sourceEntityId, int
$"Received link deleted for sourceEntityId {sourceEntityId} and targetEntityId {targetEntityId} in channel {channel.DisplayName.Data}", 0);
Entity removalTarget = _entityService.GetEntity(targetEntityId, LoadLevel.DataAndLinks);
Entity removalSource = _entityService.GetEntity(sourceEntityId, LoadLevel.DataAndLinks);
- DeleteLink(removalSource, removalTarget, linkTypeId, true);
- _epiApi.DeleteCompleted(channelName, DeleteCompletedEventType.LinkDeleted);
+ await DeleteLinkAsync(removalSource, removalTarget, linkTypeId, true);
+ await _epiApi.DeleteCompletedAsync(channelName, DeleteCompletedEventType.LinkDeleted);
return deleteEvent;
}
@@ -254,15 +253,14 @@ public ConnectorEvent ChannelLinkUpdated(Entity channel, int sourceEntityId, int
ConnectorEventHelper.UpdateEvent(connectorEvent, "Done fetching channel entities", 10);
- PublishEntities(channel, connectorEvent, structureEntities);
-
+ await PublishEntitiesAsync(channel, connectorEvent, structureEntities);
- _epiApi.ImportUpdateCompleted(channelName, ImportUpdateCompletedEventType.LinkUpdated, true);
+ await _epiApi.ImportUpdateCompletedAsync(channelName, ImportUpdateCompletedEventType.LinkUpdated, true);
return connectorEvent;
}
- public ConnectorEvent Publish(Entity channel)
+ public async Task PublishAsync(Entity channel)
{
ConnectorEvent publishEvent = ConnectorEventHelper.InitiateEvent(_config, ConnectorEventType.Publish, $"Publish started for channel: {channel.DisplayName.Data}", 0);
ConnectorEventHelper.UpdateEvent(publishEvent, "Fetching all channel entities...", 1);
@@ -271,7 +269,7 @@ public ConnectorEvent Publish(Entity channel)
ConnectorEventHelper.UpdateEvent(publishEvent, "Fetched all channel entities. Generating catalog.xml...", 10);
- CatalogElementContainer epiElements = _catalogDocumentFactory.GetEPiElements(channelStructureEntities);
+ CatalogElementContainer epiElements = await _catalogDocumentFactory.GetEPiElementsAsync(channelStructureEntities);
XElement metaClasses = _catalogElementFactory.GetMetaClassesFromFieldSets();
XElement associationTypes = _catalogDocumentFactory.GetAssociationTypes();
@@ -281,51 +279,51 @@ public ConnectorEvent Publish(Entity channel)
List resourceEntities = RemoteManager.ChannelService.GetAllChannelStructureEntitiesForTypeFromPath(channel.Id.ToString(), "Resource");
- PubilshToEpiserver(publishEvent, catalogDocument, resourceEntities, channel);
+ await PublishToEpiserverAsync(publishEvent, catalogDocument, resourceEntities, channel);
return publishEvent;
}
- internal void PublishEntities(Entity channel, ConnectorEvent connectorEvent, List structureEntities)
+ internal async Task PublishEntitiesAsync(Entity channel, ConnectorEvent connectorEvent, List structureEntities)
{
ConnectorEventHelper.UpdateEvent(connectorEvent, "Generating catalog.xml...", 11);
- CatalogElementContainer epiElements = _catalogDocumentFactory.GetEPiElements(structureEntities);
+ CatalogElementContainer epiElements = await _catalogDocumentFactory.GetEPiElementsAsync(structureEntities);
XDocument catalogDocument = _catalogDocumentFactory.CreateImportDocument(channel, null, null, epiElements);
LogCatalogProperties(epiElements);
- PubilshToEpiserver(connectorEvent, catalogDocument, structureEntities, channel);
+ await PublishToEpiserverAsync(connectorEvent, catalogDocument, structureEntities, channel);
}
private static void LogCatalogProperties(CatalogElementContainer epiElements)
{
- IntegrationLogger.Write(LogLevel.Information, $"Catalog saved with the following: " +
+ IntegrationLogger.Write(LogLevel.Information, "Catalog saved with the following: " +
$"Nodes: {epiElements.Nodes.Count}. " +
$"Entries: {epiElements.Entries.Count}. " +
$"Relations: {epiElements.Relations.Count}. " +
$"Associations: {epiElements.Associations.Count}. ");
}
- private void Delete(Entity channelEntity, Entity deletedEntity)
+ private async Task DeleteAsync(Entity channelEntity, Entity deletedEntity)
{
switch (deletedEntity.EntityType.Id)
{
case "Resource":
Guid resourceGuid = EpiserverEntryIdentifier.EntityIdToGuid(deletedEntity.Id);
- _epiApi.DeleteResource(resourceGuid);
+ await _epiApi.DeleteResourceAsync(resourceGuid);
break;
case "Channel":
- _epiApi.DeleteCatalog(deletedEntity.Id);
+ await _epiApi.DeleteCatalogAsync(deletedEntity.Id);
break;
case "ChannelNode":
- _epiApi.DeleteCatalogNode(deletedEntity, channelEntity.Id);
+ await _epiApi.DeleteCatalogNodeAsync(deletedEntity, channelEntity.Id);
break;
case "Item":
if ((_config.ItemsToSkus && _config.UseThreeLevelsInCommerce) || !_config.ItemsToSkus)
{
- _epiApi.DeleteCatalogEntry(deletedEntity);
+ await _epiApi.DeleteCatalogEntryAsync(deletedEntity);
}
if (_config.ItemsToSkus)
@@ -343,17 +341,17 @@ private void Delete(Entity channelEntity, Entity deletedEntity)
}
}
- _epiApi.DeleteSkus(entitiesToDelete);
+ await _epiApi.DeleteSkusAsync(entitiesToDelete);
}
break;
default:
- _epiApi.DeleteCatalogEntry(deletedEntity);
+ await _epiApi.DeleteCatalogEntryAsync(deletedEntity);
break;
}
}
- private void DeleteLink(Entity removalSource, Entity removalTarget, string linkTypeId, bool overrideIsRelation = false)
+ private async Task DeleteLinkAsync(Entity removalSource, Entity removalTarget, string linkTypeId, bool overrideIsRelation = false)
{
bool isRelation = _mappingHelper.IsRelation(linkTypeId) || overrideIsRelation;
@@ -366,26 +364,25 @@ private void DeleteLink(Entity removalSource, Entity removalTarget, string linkT
string sourceCode = _catalogCodeGenerator.GetEpiserverCode(removalSource);
string targetCode = _catalogCodeGenerator.GetEpiserverCode(removalTarget);
- _epiApi.DeleteLink(sourceCode, targetCode, isRelation);
+ await _epiApi.DeleteLinkAsync(sourceCode, targetCode, isRelation);
}
- private void DeleteResourceLink(Entity removedResource, Entity removalTarget)
+ private async Task DeleteResourceLinkAsync(Entity removedResource, Entity removalTarget)
{
Guid resourceGuid = EpiserverEntryIdentifier.EntityIdToGuid(removedResource.Id);
string targetCode = _catalogCodeGenerator.GetEpiserverCode(removalTarget);
- _epiApi.DeleteLink(resourceGuid, targetCode);
+ await _epiApi.DeleteLinkAsync(resourceGuid, targetCode);
}
- private void HandleChannelNodeUpdate(Entity channel, List structureEntities, ConnectorEvent entityUpdatedConnectorEvent)
+ private async Task HandleChannelNodeUpdateAsync(Entity channel, List structureEntities, ConnectorEvent entityUpdatedConnectorEvent)
{
- PublishEntities(channel, entityUpdatedConnectorEvent, structureEntities);
- _epiApi.ImportUpdateCompleted(_pimFieldAdapter.GetDisplayName(channel, 100), ImportUpdateCompletedEventType.EntityUpdated, true);
+ await PublishEntitiesAsync(channel, entityUpdatedConnectorEvent, structureEntities);
+ await _epiApi.ImportUpdateCompletedAsync(_pimFieldAdapter.GetDisplayName(channel, 100), ImportUpdateCompletedEventType.EntityUpdated, true);
}
- private bool HandleResourceUpdate(Entity updatedEntity, string folderDateTime)
+ private async Task HandleResourceUpdateAsync(Entity updatedEntity, string folderDateTime)
{
- var resourceIncluded = false;
XDocument resourceDocument = _resourceElementFactory.HandleResourceUpdate(updatedEntity, folderDateTime);
string resourcesBasePath = Path.Combine(_config.ResourcesRootPath, folderDateTime);
_documentFileHelper.SaveDocument(resourceDocument, resourcesBasePath);
@@ -395,56 +392,55 @@ private bool HandleResourceUpdate(Entity updatedEntity, string folderDateTime)
string baseFilePath = Path.Combine(_config.ResourcesRootPath, folderDateTime);
string resourceXmlPath = Path.Combine(baseFilePath, "Resources.xml");
- _epiApi.ImportResources(resourceXmlPath, baseFilePath);
+ await _epiApi.ImportResourcesAsync(resourceXmlPath, baseFilePath);
- _epiApi.NotifyEpiserverPostImport(resourceXmlPath);
- resourceIncluded = true;
+ await _epiApi.NotifyEpiserverPostImportAsync(resourceXmlPath);
- return resourceIncluded;
+ return true;
}
- private void HandleSkuUpdate(int entityId,
+ private async Task HandleSkuUpdateAsync(int entityId,
Entity channelEntity,
ConnectorEvent connectorEvent,
- List structureEntities,
- out bool resourceIncluded)
+ List structureEntities)
{
- resourceIncluded = false;
+ bool resourceIncluded = false;
Field currentField = RemoteManager.DataService.GetField(entityId, "SKUs");
List fieldHistory = RemoteManager.DataService.GetFieldHistory(entityId, "SKUs");
Field previousField = fieldHistory.FirstOrDefault(f => f.Revision == currentField.Revision - 1);
- string oldXml = string.Empty;
- if (previousField != null && previousField.Data != null)
+ string oldXml = String.Empty;
+ if (previousField?.Data != null)
{
- oldXml = (string) previousField.Data;
+ oldXml = (string)previousField.Data;
}
- string newXml = string.Empty;
+ string newXml = String.Empty;
if (currentField.Data != null)
{
- newXml = (string) currentField.Data;
+ newXml = (string)currentField.Data;
}
- List skusToDelete, skusToAdd;
- PimFieldAdapter.CompareAndParseSkuXmls(oldXml, newXml, out skusToAdd, out skusToDelete);
+ PimFieldAdapter.CompareAndParseSkuXmls(oldXml, newXml, out List skusToAdd, out List skusToDelete);
foreach (XElement skuToDelete in skusToDelete)
{
- string skuId = skuToDelete.Attribute("id").Value;
- _epiApi.DeleteSku(skuId);
+ string skuId = skuToDelete.Attribute("id")?.Value;
+ await _epiApi.DeleteSkuAsync(skuId);
}
if (skusToAdd.Count > 0)
{
- PublishEntities(channelEntity, connectorEvent, structureEntities);
+ await PublishEntitiesAsync(channelEntity, connectorEvent, structureEntities);
resourceIncluded = true;
}
+
+ return resourceIncluded;
}
- private void PubilshToEpiserver(ConnectorEvent connectorEvent,
+ private async Task PublishToEpiserverAsync(ConnectorEvent connectorEvent,
XDocument catalogDocument,
List structureEntitiesToGetResourcesFor,
Entity channelEntity)
@@ -461,22 +457,22 @@ private void PubilshToEpiserver(ConnectorEvent connectorEvent,
ConnectorEventHelper.UpdateEvent(connectorEvent, "Done generating/saving Resource.xml, sending Catalog.xml to EPiServer...", 50);
- _epiApi.ImportCatalog(savedCatalogDocument);
+ await _epiApi.ImportCatalogAsync(savedCatalogDocument);
ConnectorEventHelper.UpdateEvent(connectorEvent, "Done sending Catalog.xml to EPiServer", 75);
- _epiApi.NotifyEpiserverPostImport(savedCatalogDocument);
+ await _epiApi.NotifyEpiserverPostImportAsync(savedCatalogDocument);
ConnectorEventHelper.UpdateEvent(connectorEvent, "Sending Resources to EPiServer...", 76);
- _epiApi.ImportResources(resourceDocumentPath, resourcesBasePath);
+ await _epiApi.ImportResourcesAsync(resourceDocumentPath, resourcesBasePath);
ConnectorEventHelper.UpdateEvent(connectorEvent, "Done sending Resources to EPiServer...", 99);
- _epiApi.NotifyEpiserverPostImport(resourceDocumentPath);
+ await _epiApi.NotifyEpiserverPostImportAsync(resourceDocumentPath);
string channelName = _mappingHelper.GetNameForEntity(channelEntity, 100);
- _epiApi.ImportUpdateCompleted(channelName, ImportUpdateCompletedEventType.Publish, true);
+ await _epiApi.ImportUpdateCompletedAsync(channelName, ImportUpdateCompletedEventType.Publish, true);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/EpiserverAdapter/Communication/EpiApi.cs b/src/EpiserverAdapter/Communication/EpiApi.cs
index f2a4c51..a5d2715 100644
--- a/src/EpiserverAdapter/Communication/EpiApi.cs
+++ b/src/EpiserverAdapter/Communication/EpiApi.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
-using Epinova.InRiverConnector.EpiserverAdapter.Helpers;
using Epinova.InRiverConnector.Interfaces;
using Epinova.InRiverConnector.Interfaces.Enums;
using inRiver.Integration.Logging;
@@ -23,16 +22,14 @@ static EpiApi()
Semaphore = new SemaphoreSlim(1, 1);
}
- public EpiApi(IConfiguration config,
- CatalogCodeGenerator catalogCodeGenerator,
- PimFieldAdapter pimFieldAdapter)
+ public EpiApi(IConfiguration config, CatalogCodeGenerator catalogCodeGenerator)
{
_config = config;
_catalogCodeGenerator = catalogCodeGenerator;
_httpClient = new HttpClientInvoker(config);
}
- public async Task DeleteLink(string sourceCode, string targetCode, bool isRelation)
+ public async Task DeleteLinkAsync(string sourceCode, string targetCode, bool isRelation)
{
await ExecuteWithinLockAsync(
() =>
@@ -45,7 +42,7 @@ await ExecuteWithinLockAsync(
);
}
- public async Task DeleteLink(Guid resourceGuid, string targetCode)
+ public async Task DeleteLinkAsync(Guid resourceGuid, string targetCode)
{
await ExecuteWithinLockAsync(
() =>
@@ -57,7 +54,7 @@ await ExecuteWithinLockAsync(
);
}
- public async Task DeleteResource(Guid resourceGuid)
+ public async Task DeleteResourceAsync(Guid resourceGuid)
{
await ExecuteWithinLockAsync(
() =>
@@ -66,7 +63,7 @@ await ExecuteWithinLockAsync(
);
}
- internal async Task DeleteCatalog(int catalogId)
+ internal async Task DeleteCatalogAsync(int catalogId)
{
await ExecuteWithinLockAsync(
() =>
@@ -74,7 +71,7 @@ await ExecuteWithinLockAsync(
);
}
- internal async Task DeleteCatalogEntry(Entity entity)
+ internal async Task DeleteCatalogEntryAsync(Entity entity)
{
string code = _catalogCodeGenerator.GetEpiserverCode(entity);
await ExecuteWithinLockAsync(
@@ -83,7 +80,7 @@ await ExecuteWithinLockAsync(
);
}
- internal async Task DeleteCatalogNode(Entity catalogNode, int catalogId)
+ internal async Task DeleteCatalogNodeAsync(Entity catalogNode, int catalogId)
{
await ExecuteWithinLockAsync(
() =>
@@ -92,7 +89,7 @@ await ExecuteWithinLockAsync(
);
}
- internal async Task DeleteCompleted(string catalogName, DeleteCompletedEventType eventType)
+ internal async Task DeleteCompletedAsync(string catalogName, DeleteCompletedEventType eventType)
{
await ExecuteWithinLockAsync(
() =>
@@ -104,7 +101,7 @@ await ExecuteWithinLockAsync(
);
}
- internal async Task DeleteSku(string skuId)
+ internal async Task DeleteSkuAsync(string skuId)
{
await ExecuteWithinLockAsync(
() =>
@@ -112,7 +109,7 @@ await ExecuteWithinLockAsync(
);
}
- internal async Task DeleteSkus(List skuIds)
+ internal async Task DeleteSkusAsync(List skuIds)
{
await ExecuteWithinLockAsync(
() =>
@@ -120,7 +117,7 @@ await ExecuteWithinLockAsync(
);
}
- internal async Task ImportCatalog(string filePath)
+ internal async Task ImportCatalogAsync(string filePath)
{
await ExecuteWithinLockAsync(
() =>
@@ -129,7 +126,7 @@ await ExecuteWithinLockAsync(
);
}
- internal async Task ImportResources(string resourceDocumentFilePath, string baseFilePath)
+ internal async Task ImportResourcesAsync(string resourceDocumentFilePath, string baseFilePath)
{
var importer = new ResourceImporter(_config, _httpClient);
await ExecuteWithinLockAsync(
@@ -138,8 +135,7 @@ await ExecuteWithinLockAsync(
);
}
- internal async Task ImportUpdateCompleted(string catalogName, ImportUpdateCompletedEventType eventType,
- bool resourceIncluded)
+ internal async Task ImportUpdateCompletedAsync(string catalogName, ImportUpdateCompletedEventType eventType, bool resourceIncluded)
{
var data = new ImportUpdateCompletedData
{
@@ -153,7 +149,7 @@ await ExecuteWithinLockAsync(
);
}
- internal async Task MoveNodeToRootIfNeeded(int entityId)
+ internal async Task MoveNodeToRootIfNeededAsync(int entityId)
{
string entryNodeId = _catalogCodeGenerator.GetEpiserverCode(entityId);
await ExecuteWithinLockAsync(
@@ -162,9 +158,9 @@ await ExecuteWithinLockAsync(
);
}
- internal async Task NotifyEpiserverPostImport(string filepath)
+ internal async Task NotifyEpiserverPostImportAsync(string filepath)
{
- if (string.IsNullOrEmpty(_config.HttpPostUrl))
+ if (String.IsNullOrEmpty(_config.HttpPostUrl))
return;
await ExecuteWithinLockAsync(
@@ -194,4 +190,4 @@ private async Task ExecuteWithinLockAsync(Func action,
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/EpiserverAdapter/ConfigDefaults.cs b/src/EpiserverAdapter/ConfigDefaults.cs
index 0b0f699..11c936f 100644
--- a/src/EpiserverAdapter/ConfigDefaults.cs
+++ b/src/EpiserverAdapter/ConfigDefaults.cs
@@ -2,17 +2,17 @@
{
public class ConfigDefaults
{
+ public static string CvlData = "Keys|Values|KeysAndValues";
+ public static string EpiApiKey = "SomeGreatKey123";
+ public static string EpiEndpoint = "https://www.example.com/inriverapi/InriverDataImport/";
+ public static string EpiTimeout = "1";
public static string ExportEntities = "Product,Item,ChannelNode";
public static string ForceIncludeLinkedContent = "False";
+ public static string ItemToSkus = "false";
+ public static string LanguageMapping = "enen-us";
public static string PublishFolder = @"C:\temp\Publish\Epi";
- public static string ResourcesPublishFolder = @"C:\temp\Publish\Epi\Resources";
public static string ResourceConfiguration = "Preview";
- public static string LanguageMapping = "enen-us";
- public static string ItemToSkus = "false";
- public static string CvlData = "Keys|Values|KeysAndValues";
+ public static string ResourcesPublishFolder = @"C:\temp\Publish\Epi\Resources";
public static string UseThreeLevelsinCommerce = "false";
- public static string EpiEndpoint = "https://www.example.com/inriverapi/InriverDataImport/";
- public static string EpiApiKey = "SomeGreatKey123";
- public static string EpiTimeout = "1";
}
-}
\ No newline at end of file
+}
diff --git a/src/EpiserverAdapter/ConfigKeys.cs b/src/EpiserverAdapter/ConfigKeys.cs
index c3f1199..9b17c84 100644
--- a/src/EpiserverAdapter/ConfigKeys.cs
+++ b/src/EpiserverAdapter/ConfigKeys.cs
@@ -2,26 +2,26 @@
{
public class ConfigKeys
{
- public static string EpiTimeout = "EPI_RESTTIMEOUT";
+ public static string BatchSize = "BATCH_SIZE";
+ public static string BundleTypes = "BUNDLE_ENTITYTYPES";
+ public static string ChannelId = "CHANNEL_ID";
+ public static string CvlData = "CVL_DATA";
+ public static string DynamicPackageTypes = "DYNAMIC_PACKAGE_ENTITYTYPES";
public static string EpiApiKey = "EPI_APIKEY";
+ public static string EpiCodeFields = "EPI_CODE_FIELDS";
public static string EpiEndpoint = "EPI_ENDPOINT_URL";
+ public static string EpiNameFields = "EPI_NAME_FIELDS";
+ public static string EpiTimeout = "EPI_RESTTIMEOUT";
+ public static string ExcludeFields = "EXCLUDE_FIELDS";
public static string ExportEntities = "EXPORT_ENTITIES";
- public static string ChannelId = "CHANNEL_ID";
- public static string PublishFolder = "PUBLISH_FOLDER";
+ public static string ForceIncludeLinkedContent = "FORCE_INCLUDE_LINKED_CONTENT";
public static string HttpPostUrl = "HTTP_POST_URL";
+ public static string ItemToSkus = "ITEM_TO_SKUs";
public static string LanguageMapping = "LANGUAGE_MAPPING";
- public static string EpiNameFields = "EPI_NAME_FIELDS";
+ public static string PackageTypes = "PACKAGE_ENTITYTYPES";
+ public static string PublishFolder = "PUBLISH_FOLDER";
+ public static string ResourceConfiguration = "RESOURCE_CONFIGURATION";
public static string ResourcesPublishFolder = "PUBLISH_FOLDER_RESOURCES";
public static string UseThreeLevelsInCommerce = "USE_THREE_LEVELS_IN_COMMERCE";
- public static string EpiCodeFields = "EPI_CODE_FIELDS";
- public static string ResourceConfiguration = "RESOURCE_CONFIGURATION";
- public static string ItemToSkus = "ITEM_TO_SKUs";
- public static string BatchSize = "BATCH_SIZE";
- public static string BundleTypes = "BUNDLE_ENTITYTYPES";
- public static string PackageTypes = "PACKAGE_ENTITYTYPES";
- public static string DynamicPackageTypes = "DYNAMIC_PACKAGE_ENTITYTYPES";
- public static string ExcludeFields = "EXCLUDE_FIELDS";
- public static string CvlData = "CVL_DATA";
- public static string ForceIncludeLinkedContent = "FORCE_INCLUDE_LINKED_CONTENT";
}
-}
\ No newline at end of file
+}
diff --git a/src/EpiserverAdapter/Configuration.cs b/src/EpiserverAdapter/Configuration.cs
index 57d534c..1e84d88 100644
--- a/src/EpiserverAdapter/Configuration.cs
+++ b/src/EpiserverAdapter/Configuration.cs
@@ -13,28 +13,28 @@ namespace Epinova.InRiverConnector.EpiserverAdapter
{
public class Configuration : IConfiguration
{
- private readonly Dictionary _settings;
-
private readonly List _epiFieldsIninRiver;
- private bool? _useThreeLevelsInCommerce;
- private CultureInfo _channelDefaultLanguage;
+ private readonly Dictionary _settings;
+ private int _batchsize;
private string _channelDefaultCurrency;
+ private CultureInfo _channelDefaultLanguage;
private string _channelWeightBase;
private Dictionary _epiCodeMapping;
- private Dictionary _resourceConfiugExtensions;
- private Dictionary _languageMapping;
private Dictionary _epiNameMapping;
+ private HashSet _excludedFields;
+ private List _exportEnabledEntityTypes;
private List _exportEnabledLinkTypes;
private bool _itemsToSkus;
- private HashSet _excludedFields;
- private int _batchsize;
+ private Dictionary _languageMapping;
+ private Dictionary _resourceConfiugExtensions;
+ private bool? _useThreeLevelsInCommerce;
public Configuration(string id)
{
_settings = RemoteManager.UtilityService.GetConnector(id).Settings;
var settingsValidator = new SettingsValidator(_settings);
settingsValidator.ValidateSettings();
-
+
Id = id;
Endpoints = new EndpointCollection(EpiEndpoint);
LinkTypes = new List(RemoteManager.ModelService.GetAllLinkTypes());
@@ -42,118 +42,216 @@ public Configuration(string id)
_epiFieldsIninRiver = new List { "startdate", "enddate", "displaytemplate", "seodescription", "seokeywords", "seotitle", "seouri", "skus" };
}
- public int EpiRestTimeout => int.Parse(_settings[ConfigKeys.EpiTimeout]);
- public string EpiApiKey => _settings[ConfigKeys.EpiApiKey];
- public string EpiEndpoint => _settings[ConfigKeys.EpiEndpoint];
- public bool ForceIncludeLinkedContent => bool.Parse(_settings[ConfigKeys.ForceIncludeLinkedContent]);
-
- public EndpointCollection Endpoints { get; set; }
+ public static string CVLKeyDelimiter => "||";
public static string OriginalDisplayConfiguration => "Original";
- public static string CVLKeyDelimiter => "||";
- public string Id { get; }
+ public CVLDataMode ActiveCVLDataMode => !_settings.ContainsKey(ConfigKeys.CvlData) ? CVLDataMode.Undefined : StringToCVLDataMode(_settings[ConfigKeys.CvlData]);
- public List LinkTypes { get; set; }
+ public LinkType[] AssociationLinkTypes
+ {
+ get
+ {
+ if (_exportEnabledLinkTypes != null)
+ return _exportEnabledLinkTypes.ToArray();
- public int ChannelId
+ _exportEnabledLinkTypes = new List();
+ List allLinkTypes = RemoteManager.ModelService.GetAllLinkTypes();
+
+ LinkType productItemLink = allLinkTypes.Where(x => x.SourceEntityTypeId.Equals("Product") && x.TargetEntityTypeId.Equals("Item"))
+ .OrderBy(l => l.Index)
+ .FirstOrDefault();
+
+ foreach (LinkType linkType in allLinkTypes)
+ {
+ if (linkType.TargetEntityTypeId == "Specification")
+ continue;
+
+ if (linkType.IsProductItemLink() && linkType.Id == productItemLink?.Id)
+ continue;
+
+ if (linkType.SourceEntityTypeIsChannelNode())
+ continue;
+
+ if (BundleEntityTypes.Contains(linkType.SourceEntityTypeId) ||
+ PackageEntityTypes.Contains(linkType.SourceEntityTypeId))
+ continue;
+
+ if (ExportEnabledEntityTypes.Any(x => x.Id == linkType.SourceEntityTypeId) &&
+ ExportEnabledEntityTypes.Any(x => x.Id == linkType.TargetEntityTypeId))
+ {
+ _exportEnabledLinkTypes.Add(linkType);
+ }
+ }
+
+ IntegrationLogger.Write(LogLevel.Debug, $"ExportEnabledLinkTypes: {string.Join(",", _exportEnabledLinkTypes)}.");
+
+ return _exportEnabledLinkTypes.ToArray();
+ }
+ }
+
+ public int BatchSize
{
get
{
- if (!_settings.ContainsKey(ConfigKeys.ChannelId))
+ if (!_settings.ContainsKey(ConfigKeys.BatchSize))
+ return Int32.MaxValue;
+
+ string value = _settings[ConfigKeys.BatchSize];
+
+ if (!Int32.TryParse(value, out _batchsize) || value == "0")
{
- return 0;
+ _batchsize = Int32.MaxValue;
}
- return int.Parse(_settings[ConfigKeys.ChannelId]);
+ return _batchsize;
}
}
-
- public string PublicationsRootPath => !_settings.ContainsKey(ConfigKeys.PublishFolder) ?
- @"C:\temp\Publish\Epi" :
- _settings[ConfigKeys.PublishFolder];
- private List _exportEnabledEntityTypes;
- public List ExportEnabledEntityTypes
+ public string[] BundleEntityTypes => SplitString(ConfigKeys.BundleTypes);
+
+ public string ChannelDefaultCurrency
{
get
{
- if (_exportEnabledEntityTypes != null)
- return _exportEnabledEntityTypes;
+ if (String.IsNullOrEmpty(_channelDefaultCurrency))
+ {
+ _channelDefaultCurrency = "USD";
+ }
- if (!_settings.ContainsKey(ConfigKeys.ExportEntities))
- throw new Exception($"Need to add exportable entities (config value {ConfigKeys.ExportEntities}. Default value is: {ConfigDefaults.ExportEntities}.");
+ return _channelDefaultCurrency;
+ }
- var list = _settings[ConfigKeys.ExportEntities].Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries).ToList();
- var allEntityTypes = RemoteManager.ModelService.GetAllEntityTypes();
- _exportEnabledEntityTypes = allEntityTypes.Where(x => list.Contains(x.Id)).ToList();
- IntegrationLogger.Write(LogLevel.Debug, $"ExportEnabledEntityTypes: {string.Join(",", _exportEnabledEntityTypes)}.");
+ set => _channelDefaultCurrency = value;
+ }
- return _exportEnabledEntityTypes;
+ public CultureInfo ChannelDefaultLanguage
+ {
+ get => _channelDefaultLanguage ?? (_channelDefaultLanguage = new CultureInfo("en-us"));
+ set => _channelDefaultLanguage = value;
+ }
+
+
+ public string ChannelDefaultWeightBase
+ {
+ get
+ {
+ if (String.IsNullOrEmpty(_channelWeightBase))
+ {
+ _channelWeightBase = "kg";
+ }
+
+ return _channelWeightBase;
}
+ set => _channelWeightBase = value;
}
- public string HttpPostUrl
+ public int ChannelId
{
get
{
- if (!_settings.ContainsKey(ConfigKeys.HttpPostUrl))
+ if (!_settings.ContainsKey(ConfigKeys.ChannelId))
{
- return null;
+ return 0;
}
- return _settings[ConfigKeys.HttpPostUrl];
+ return Int32.Parse(_settings[ConfigKeys.ChannelId]);
}
}
- public Dictionary LanguageMapping
+ public string ChannelIdPrefix { get; set; } = String.Empty;
+ public string[] DynamicPackageEntityTypes => SplitString(ConfigKeys.DynamicPackageTypes);
+ public EndpointCollection Endpoints { get; set; }
+ public string EpiApiKey => _settings[ConfigKeys.EpiApiKey];
+
+ public Dictionary EpiCodeMapping
{
get
{
- if (_languageMapping != null)
- return _languageMapping;
+ if (_epiCodeMapping != null)
+ return _epiCodeMapping;
- if (!_settings.ContainsKey(ConfigKeys.LanguageMapping))
+ _epiCodeMapping = new Dictionary();
+
+ if (!_settings.ContainsKey(ConfigKeys.EpiCodeFields))
{
- return new Dictionary();
+ return _epiCodeMapping;
}
- string mappingXml = _settings[ConfigKeys.LanguageMapping];
+ string rawValue = _settings[ConfigKeys.EpiCodeFields];
- _languageMapping = new Dictionary();
+ if (String.IsNullOrEmpty(rawValue))
+ return _epiCodeMapping;
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(mappingXml);
+ List fieldTypes = RemoteManager.ModelService.GetAllFieldTypes();
- List allLanguages = RemoteManager.UtilityService.GetAllLanguages();
+ string[] values = rawValue.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- if (doc.DocumentElement == null)
- return _languageMapping;
+ foreach (string val in values)
+ {
+ FieldType fieldType = fieldTypes.FirstOrDefault(x => x.Id.Equals(val, StringComparison.InvariantCultureIgnoreCase));
+ if (fieldType != null && !_epiCodeMapping.ContainsKey(fieldType.EntityTypeId))
+ {
+ _epiCodeMapping.Add(fieldType.EntityTypeId, fieldType.Id);
+ }
+ }
- foreach (XmlNode languageNode in doc.DocumentElement)
+ return _epiCodeMapping;
+ }
+ }
+
+ public string EpiEndpoint => _settings[ConfigKeys.EpiEndpoint];
+
+ public HashSet EPiFieldsIninRiver
+ {
+ get
+ {
+ if (_excludedFields != null)
{
- XmlElement epiLanguage = languageNode["epi"];
- XmlElement inriverLanguage = languageNode["inriver"];
+ return _excludedFields;
+ }
- if (epiLanguage != null && inriverLanguage != null)
+ if (!_settings.ContainsKey(ConfigKeys.ExcludeFields) || String.IsNullOrEmpty(_settings[ConfigKeys.ExcludeFields]))
+ {
+ var excludedFieldTypes = new HashSet();
+ foreach (string baseField in _epiFieldsIninRiver)
{
- var episerverCulture = new CultureInfo(epiLanguage.InnerText);
- var pimCulture = new CultureInfo(inriverLanguage.InnerText);
-
- if (!allLanguages.Exists(ci => ci.LCID == pimCulture.LCID))
+ foreach (EntityType entityType in ExportEnabledEntityTypes)
{
- throw new Exception($"ERROR: Mapping Language incorrect, {inriverLanguage.InnerText} is not a valid pim culture info");
+ excludedFieldTypes.Add(entityType.Id.ToLower() + baseField);
}
+ }
- _languageMapping.Add(episerverCulture, pimCulture);
+ excludedFieldTypes.Add("skus");
+
+ _excludedFields = excludedFieldTypes;
+ return _excludedFields;
+ }
+ else
+ {
+ var excludedFieldTypes = new HashSet();
+ foreach (string baseField in _epiFieldsIninRiver)
+ {
+ foreach (EntityType entityType in ExportEnabledEntityTypes)
+ {
+ excludedFieldTypes.Add(entityType.Id.ToLower() + baseField);
+ }
}
- else
+
+ excludedFieldTypes.Add("skus");
+
+ string[] fields = _settings[ConfigKeys.ExcludeFields].Split(',');
+ foreach (string field in fields)
{
- throw new Exception("ERROR: Mapping language is missing.");
+ if (!excludedFieldTypes.Contains(field.ToLower()))
+ {
+ excludedFieldTypes.Add(field.ToLower());
+ }
}
- }
- return _languageMapping;
+ _excludedFields = excludedFieldTypes;
+ return _excludedFields;
+ }
}
}
@@ -168,22 +266,22 @@ public Dictionary EpiNameMapping
if (!_settings.ContainsKey(ConfigKeys.EpiNameFields))
return _epiNameMapping;
-
- var value = _settings[ConfigKeys.EpiNameFields];
- if (string.IsNullOrEmpty(value))
+ string value = _settings[ConfigKeys.EpiNameFields];
+
+ if (String.IsNullOrEmpty(value))
return _epiNameMapping;
List fieldTypes = RemoteManager.ModelService.GetAllFieldTypes();
- var values = value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
+ string[] values = value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- foreach (var val in values)
+ foreach (string val in values)
{
- if (string.IsNullOrEmpty(val))
+ if (String.IsNullOrEmpty(val))
continue;
- var fieldType = fieldTypes.FirstOrDefault(fT => fT.Id.Equals(val, StringComparison.InvariantCultureIgnoreCase));
+ FieldType fieldType = fieldTypes.FirstOrDefault(fT => fT.Id.Equals(val, StringComparison.InvariantCultureIgnoreCase));
if (fieldType != null && !_epiNameMapping.ContainsKey(fieldType.EntityTypeId))
{
@@ -195,114 +293,112 @@ public Dictionary EpiNameMapping
}
}
- public string ResourcesRootPath
+ public int EpiRestTimeout => Int32.Parse(_settings[ConfigKeys.EpiTimeout]);
+
+ public List ExportEnabledEntityTypes
{
get
{
- if (!_settings.ContainsKey(ConfigKeys.ResourcesPublishFolder))
- {
- return @"C:\temp\Publish\Epi\Resources";
- }
+ if (_exportEnabledEntityTypes != null)
+ return _exportEnabledEntityTypes;
- return _settings[ConfigKeys.ResourcesPublishFolder];
+ if (!_settings.ContainsKey(ConfigKeys.ExportEntities))
+ throw new Exception($"Need to add exportable entities (config value {ConfigKeys.ExportEntities}. Default value is: {ConfigDefaults.ExportEntities}.");
+
+ List list = _settings[ConfigKeys.ExportEntities].Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
+ List allEntityTypes = RemoteManager.ModelService.GetAllEntityTypes();
+ _exportEnabledEntityTypes = allEntityTypes.Where(x => list.Contains(x.Id)).ToList();
+ IntegrationLogger.Write(LogLevel.Debug, $"ExportEnabledEntityTypes: {string.Join(",", _exportEnabledEntityTypes)}.");
+
+ return _exportEnabledEntityTypes;
}
}
- public bool UseThreeLevelsInCommerce
+ public bool ForceIncludeLinkedContent => bool.Parse(_settings[ConfigKeys.ForceIncludeLinkedContent]);
+
+ public string HttpPostUrl
{
get
{
- if (_useThreeLevelsInCommerce != null)
- return (bool) _useThreeLevelsInCommerce;
-
- if (!_settings.ContainsKey(ConfigKeys.UseThreeLevelsInCommerce))
+ if (!_settings.ContainsKey(ConfigKeys.HttpPostUrl))
{
- _useThreeLevelsInCommerce = false;
- return _useThreeLevelsInCommerce.Value;
+ return null;
}
- var value = _settings[ConfigKeys.UseThreeLevelsInCommerce];
-
- _useThreeLevelsInCommerce = !string.IsNullOrEmpty(value) && bool.Parse(value);
-
- return (bool)_useThreeLevelsInCommerce;
+ return _settings[ConfigKeys.HttpPostUrl];
}
}
- public CultureInfo ChannelDefaultLanguage
- {
- get => _channelDefaultLanguage ?? (_channelDefaultLanguage = new CultureInfo("en-us"));
- set => _channelDefaultLanguage = value;
- }
+ public string Id { get; }
- public string ChannelDefaultCurrency
+ public bool ItemsToSkus
{
get
{
- if (string.IsNullOrEmpty(_channelDefaultCurrency))
+ string value = _settings[ConfigKeys.ItemToSkus];
+ if (!Boolean.TryParse(value, out _itemsToSkus))
{
- _channelDefaultCurrency = "USD";
+ _itemsToSkus = false;
}
-
- return _channelDefaultCurrency;
- }
- set => _channelDefaultCurrency = value;
+ return _itemsToSkus;
+ }
}
- public Dictionary EpiCodeMapping
+ public Dictionary LanguageMapping
{
get
{
- if (_epiCodeMapping != null)
- return _epiCodeMapping;
-
- _epiCodeMapping = new Dictionary();
+ if (_languageMapping != null)
+ return _languageMapping;
- if (!_settings.ContainsKey(ConfigKeys.EpiCodeFields))
+ if (!_settings.ContainsKey(ConfigKeys.LanguageMapping))
{
- return _epiCodeMapping;
+ return new Dictionary();
}
- var rawValue = _settings[ConfigKeys.EpiCodeFields];
+ string mappingXml = _settings[ConfigKeys.LanguageMapping];
- if (string.IsNullOrEmpty(rawValue))
- return _epiCodeMapping;
+ _languageMapping = new Dictionary();
- var fieldTypes = RemoteManager.ModelService.GetAllFieldTypes();
+ var doc = new XmlDocument();
+ doc.LoadXml(mappingXml);
+
+ List allLanguages = RemoteManager.UtilityService.GetAllLanguages();
- var values = rawValue.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
+ if (doc.DocumentElement == null)
+ return _languageMapping;
- foreach (var val in values)
+ foreach (XmlNode languageNode in doc.DocumentElement)
{
- var fieldType = fieldTypes.FirstOrDefault(x => x.Id.Equals(val, StringComparison.InvariantCultureIgnoreCase));
- if (fieldType != null && !_epiCodeMapping.ContainsKey(fieldType.EntityTypeId))
- {
- _epiCodeMapping.Add(fieldType.EntityTypeId, fieldType.Id);
- }
- }
+ XmlElement epiLanguage = languageNode["epi"];
+ XmlElement inriverLanguage = languageNode["inriver"];
- return _epiCodeMapping;
- }
- }
+ if (epiLanguage != null && inriverLanguage != null)
+ {
+ var episerverCulture = new CultureInfo(epiLanguage.InnerText);
+ var pimCulture = new CultureInfo(inriverLanguage.InnerText);
-
+ if (!allLanguages.Exists(ci => ci.LCID == pimCulture.LCID))
+ {
+ throw new Exception($"ERROR: Mapping Language incorrect, {inriverLanguage.InnerText} is not a valid pim culture info");
+ }
- public string ChannelDefaultWeightBase
- {
- get
- {
- if (string.IsNullOrEmpty(_channelWeightBase))
- {
- _channelWeightBase = "kg";
+ _languageMapping.Add(episerverCulture, pimCulture);
+ }
+ else
+ {
+ throw new Exception("ERROR: Mapping language is missing.");
+ }
}
- return _channelWeightBase;
+ return _languageMapping;
}
- set => _channelWeightBase = value;
}
- public string ChannelIdPrefix { get; set; } = string.Empty;
+ public List LinkTypes { get; set; }
+ public string[] PackageEntityTypes => SplitString(ConfigKeys.PackageTypes);
+ public string PublicationsRootPath => !_settings.ContainsKey(ConfigKeys.PublishFolder) ? @"C:\temp\Publish\Epi" : _settings[ConfigKeys.PublishFolder];
public string[] ResourceConfigurations
{
@@ -313,166 +409,80 @@ public string[] ResourceConfigurations
return new string[0];
}
- var resourceConfWithExt = ParseResourceConfig(_settings[ConfigKeys.ResourceConfiguration]);
+ Dictionary resourceConfWithExt = ParseResourceConfig(_settings[ConfigKeys.ResourceConfiguration]);
return resourceConfWithExt.Keys.ToArray();
}
}
- public Dictionary ResourceConfiugurationExtensions => _resourceConfiugExtensions ??
- (_resourceConfiugExtensions = ParseResourceConfig(_settings[ConfigKeys.ResourceConfiguration]));
+ public Dictionary ResourceConfiugurationExtensions => _resourceConfiugExtensions ??
+ (_resourceConfiugExtensions = ParseResourceConfig(_settings[ConfigKeys.ResourceConfiguration]));
- public LinkType[] AssociationLinkTypes
+ public string ResourcesRootPath
{
get
{
- if (_exportEnabledLinkTypes != null)
- return _exportEnabledLinkTypes.ToArray();
-
- _exportEnabledLinkTypes = new List();
- List allLinkTypes = RemoteManager.ModelService.GetAllLinkTypes();
-
- var productItemLink = allLinkTypes.Where(x => x.SourceEntityTypeId.Equals("Product") && x.TargetEntityTypeId.Equals("Item"))
- .OrderBy(l => l.Index)
- .FirstOrDefault();
-
- foreach (var linkType in allLinkTypes)
+ if (!_settings.ContainsKey(ConfigKeys.ResourcesPublishFolder))
{
- if (linkType.TargetEntityTypeId == "Specification")
- continue;
-
- if (linkType.IsProductItemLink() && linkType.Id == productItemLink?.Id)
- continue;
-
- if (linkType.SourceEntityTypeIsChannelNode())
- continue;
-
- if (BundleEntityTypes.Contains(linkType.SourceEntityTypeId) ||
- PackageEntityTypes.Contains(linkType.SourceEntityTypeId))
- continue;
-
- if (ExportEnabledEntityTypes.Any(x => x.Id == linkType.SourceEntityTypeId) &&
- ExportEnabledEntityTypes.Any(x => x.Id == linkType.TargetEntityTypeId))
- {
- _exportEnabledLinkTypes.Add(linkType);
- }
+ return @"C:\temp\Publish\Epi\Resources";
}
- IntegrationLogger.Write(LogLevel.Debug, $"ExportEnabledLinkTypes: {string.Join(",", _exportEnabledLinkTypes)}.");
-
- return _exportEnabledLinkTypes.ToArray();
+ return _settings[ConfigKeys.ResourcesPublishFolder];
}
}
- public bool ItemsToSkus
+ public bool UseThreeLevelsInCommerce
{
get
{
- var value = _settings[ConfigKeys.ItemToSkus];
- if (!bool.TryParse(value, out _itemsToSkus))
+ if (_useThreeLevelsInCommerce != null)
+ return (bool)_useThreeLevelsInCommerce;
+
+ if (!_settings.ContainsKey(ConfigKeys.UseThreeLevelsInCommerce))
{
- _itemsToSkus = false;
+ _useThreeLevelsInCommerce = false;
+ return _useThreeLevelsInCommerce.Value;
}
- return _itemsToSkus;
+ string value = _settings[ConfigKeys.UseThreeLevelsInCommerce];
+
+ _useThreeLevelsInCommerce = !String.IsNullOrEmpty(value) && bool.Parse(value);
+
+ return (bool)_useThreeLevelsInCommerce;
}
}
- public int BatchSize
+ private static Dictionary ParseResourceConfig(string setting)
{
- get
+ var settingsDictionary = new Dictionary();
+ if (String.IsNullOrEmpty(setting))
{
- if (!_settings.ContainsKey(ConfigKeys.BatchSize))
- return int.MaxValue;
-
- var value = _settings[ConfigKeys.BatchSize];
-
- if (!int.TryParse(value, out _batchsize) || value == "0")
- {
- _batchsize = int.MaxValue;
- }
-
- return _batchsize;
+ return settingsDictionary;
}
- }
- public string[] BundleEntityTypes => SplitString(ConfigKeys.BundleTypes);
- public string[] PackageEntityTypes => SplitString(ConfigKeys.PackageTypes);
- public string[] DynamicPackageEntityTypes => SplitString(ConfigKeys.DynamicPackageTypes);
+ setting = setting.Replace(" ", String.Empty);
- public HashSet EPiFieldsIninRiver
- {
- get
- {
- if (_excludedFields != null)
- {
- return _excludedFields;
- }
+ string[] resouceConfs = setting.Split(',');
- if (!_settings.ContainsKey(ConfigKeys.ExcludeFields) || string.IsNullOrEmpty(_settings[ConfigKeys.ExcludeFields]))
+ foreach (string resouceConf in resouceConfs)
+ {
+ if (resouceConf.Contains(':'))
{
- HashSet excludedFieldTypes = new HashSet();
- foreach (string baseField in _epiFieldsIninRiver)
- {
- foreach (var entityType in ExportEnabledEntityTypes)
- {
- excludedFieldTypes.Add(entityType.Id.ToLower() + baseField);
- }
- }
-
- excludedFieldTypes.Add("skus");
+ string[] parts = resouceConf.Split(':');
- _excludedFields = excludedFieldTypes;
- return _excludedFields;
+ settingsDictionary.Add(parts[0], parts[1]);
}
else
{
- HashSet excludedFieldTypes = new HashSet();
- foreach (string baseField in _epiFieldsIninRiver)
- {
- foreach (var entityType in ExportEnabledEntityTypes)
- {
- excludedFieldTypes.Add(entityType.Id.ToLower() + baseField);
- }
- }
-
- excludedFieldTypes.Add("skus");
-
- var fields = _settings[ConfigKeys.ExcludeFields].Split(',');
- foreach (string field in fields)
- {
- if (!excludedFieldTypes.Contains(field.ToLower()))
- {
- excludedFieldTypes.Add(field.ToLower());
- }
- }
-
- _excludedFields = excludedFieldTypes;
- return _excludedFields;
+ settingsDictionary.Add(resouceConf, String.Empty);
}
}
- }
-
- public CVLDataMode ActiveCVLDataMode => !_settings.ContainsKey(ConfigKeys.CvlData) ? CVLDataMode.Undefined : StringToCVLDataMode(_settings[ConfigKeys.CvlData]);
- private string[] SplitString(string settingKey)
- {
- if(!_settings.ContainsKey(settingKey))
- return new string[0];
-
- var setting = _settings[settingKey];
-
- if (string.IsNullOrEmpty(setting))
- return new string[0];
-
- setting = setting.Replace(" ", string.Empty);
- return setting.Split(',');
+ return settingsDictionary;
}
private static CVLDataMode StringToCVLDataMode(string str)
{
- CVLDataMode mode;
-
- if (!Enum.TryParse(str, out mode))
+ if (!Enum.TryParse(str, out CVLDataMode mode))
{
IntegrationLogger.Write(LogLevel.Error, $"Could not parse CVLDataMode for string {str}");
}
@@ -480,33 +490,18 @@ private static CVLDataMode StringToCVLDataMode(string str)
return mode;
}
- private Dictionary ParseResourceConfig(string setting)
+ private string[] SplitString(string settingKey)
{
- Dictionary settingsDictionary = new Dictionary();
- if (string.IsNullOrEmpty(setting))
- {
- return settingsDictionary;
- }
-
- setting = setting.Replace(" ", string.Empty);
+ if (!_settings.ContainsKey(settingKey))
+ return new string[0];
- var resouceConfs = setting.Split(',');
-
- foreach (var resouceConf in resouceConfs)
- {
- if (resouceConf.Contains(':'))
- {
- var parts = resouceConf.Split(':');
+ string setting = _settings[settingKey];
- settingsDictionary.Add(parts[0], parts[1]);
- }
- else
- {
- settingsDictionary.Add(resouceConf, string.Empty);
- }
- }
+ if (String.IsNullOrEmpty(setting))
+ return new string[0];
- return settingsDictionary;
+ setting = setting.Replace(" ", String.Empty);
+ return setting.Split(',');
}
}
}
diff --git a/src/EpiserverAdapter/Constants.cs b/src/EpiserverAdapter/Constants.cs
index d7159cc..37af4bd 100644
--- a/src/EpiserverAdapter/Constants.cs
+++ b/src/EpiserverAdapter/Constants.cs
@@ -3,8 +3,7 @@
public static class Constants
{
public static string CatalogExportFilename = "Catalog.xml";
- public static string ResourceExportFilename = "Resources.xml";
-
public static string PublicationFolderNameTimeComponent = "yyyyMMdd-HHmmss.fff";
+ public static string ResourceExportFilename = "Resources.xml";
}
-}
\ No newline at end of file
+}
diff --git a/src/EpiserverAdapter/CvlUpdater.cs b/src/EpiserverAdapter/CvlUpdater.cs
index c1665cd..ee905c0 100644
--- a/src/EpiserverAdapter/CvlUpdater.cs
+++ b/src/EpiserverAdapter/CvlUpdater.cs
@@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Threading.Tasks;
+using System.Xml.Linq;
using Epinova.InRiverConnector.EpiserverAdapter.Communication;
using Epinova.InRiverConnector.EpiserverAdapter.Helpers;
using Epinova.InRiverConnector.EpiserverAdapter.XmlFactories;
@@ -16,15 +18,12 @@ namespace Epinova.InRiverConnector.EpiserverAdapter
{
public class CvlUpdater
{
- private readonly IConfiguration _config;
private readonly CatalogDocumentFactory _catalogDocumentFactory;
- private readonly EpiApi _epiApi;
+ private readonly IConfiguration _config;
private readonly DocumentFileHelper _documentFileHelper;
+ private readonly EpiApi _epiApi;
- public CvlUpdater(IConfiguration config,
- CatalogDocumentFactory catalogDocumentFactory,
- EpiApi epiApi,
- DocumentFileHelper documentFileHelper)
+ public CvlUpdater(IConfiguration config, CatalogDocumentFactory catalogDocumentFactory, EpiApi epiApi, DocumentFileHelper documentFileHelper)
{
_config = config;
_catalogDocumentFactory = catalogDocumentFactory;
@@ -32,37 +31,37 @@ public CvlUpdater(IConfiguration config,
_documentFileHelper = documentFileHelper;
}
- public ConnectorEvent CVLValueUpdated(Entity channel, string cvlId, string cvlValueKey)
+ public async Task CVLValueUpdatedAsync(Entity channel, string cvlId, string cvlValueKey)
{
- var connectorEvent = ConnectorEventHelper.InitiateEvent(_config,
- ConnectorEventType.CVLValueUpdated,
- $"CVL value updated, updating values in channel: {channel.DisplayName.Data}", 0);
+ ConnectorEvent connectorEvent = ConnectorEventHelper.InitiateEvent(_config,
+ ConnectorEventType.CVLValueUpdated,
+ $"CVL value updated, updating values in channel: {channel.DisplayName.Data}", 0);
+
+ IEnumerable cvlFieldTypes = RemoteManager.ModelService.GetAllFieldTypes().Where(x => x.CVLId == cvlId);
- var cvlFieldTypes = RemoteManager.ModelService.GetAllFieldTypes().Where(x => x.CVLId == cvlId);
-
- var criterias = cvlFieldTypes.Select(cvlFieldType => new Criteria
+ List criteria = cvlFieldTypes.Select(cvlFieldType => new Criteria
{
FieldTypeId = cvlFieldType.Id,
Value = cvlValueKey,
Operator = Operator.Equal
}).ToList();
- var query = new Query { Criteria = criterias, Join = Join.Or };
- var entities = RemoteManager.DataService.Search(query, LoadLevel.DataOnly);
+ var query = new Query { Criteria = criteria, Join = Join.Or };
+ List entities = RemoteManager.DataService.Search(query, LoadLevel.DataOnly);
IntegrationLogger.Write(LogLevel.Debug, $"Found {entities.Count} entities with the CVL {cvlId} to update. Value-key to update: {cvlValueKey}.");
- var updateDocument = _catalogDocumentFactory.CreateUpdateDocument(channel, entities);
- var folderDateTime = DateTime.Now.ToString(Constants.PublicationFolderNameTimeComponent);
+ XDocument updateDocument = _catalogDocumentFactory.CreateUpdateDocument(channel, entities);
+ string folderDateTime = DateTime.Now.ToString(Constants.PublicationFolderNameTimeComponent);
- var savedCatalogDocument = _documentFileHelper.SaveCatalogDocument(channel, updateDocument, folderDateTime);
+ string savedCatalogDocument = _documentFileHelper.SaveCatalogDocument(channel, updateDocument, folderDateTime);
- _epiApi.ImportCatalog(savedCatalogDocument);
+ await _epiApi.ImportCatalogAsync(savedCatalogDocument);
ConnectorEventHelper.UpdateEvent(connectorEvent, "Done sending Catalog.xml to EPiServer", 75);
- _epiApi.NotifyEpiserverPostImport(Path.Combine(_config.PublicationsRootPath, folderDateTime, savedCatalogDocument));
+ await _epiApi.NotifyEpiserverPostImportAsync(Path.Combine(_config.PublicationsRootPath, folderDateTime, savedCatalogDocument));
return connectorEvent;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/EpiserverAdapter/EndpointCollection.cs b/src/EpiserverAdapter/EndpointCollection.cs
index 663cae9..05c82f9 100644
--- a/src/EpiserverAdapter/EndpointCollection.cs
+++ b/src/EpiserverAdapter/EndpointCollection.cs
@@ -9,16 +9,16 @@ public EndpointCollection(string baseUrl)
_baseUrl = baseUrl;
}
- public string ImportResources => _baseUrl + "ImportResources";
- public string IsImporting => _baseUrl + "IsImporting";
+ public string CheckAndMoveNodeIfNeeded => _baseUrl + "MoveNodeToRootIfNeeded";
public string DeleteCatalog => _baseUrl + "DeleteCatalog";
- public string DeleteCatalogNode => _baseUrl + "DeleteCatalogNode";
public string DeleteCatalogEntry => _baseUrl + "DeleteCatalogEntry";
- public string CheckAndMoveNodeIfNeeded => _baseUrl + "MoveNodeToRootIfNeeded";
- public string ImportCatalogXml => _baseUrl + "ImportCatalogXml";
- public string ImportUpdateCompleted => _baseUrl + "ImportUpdateCompleted";
+ public string DeleteCatalogNode => _baseUrl + "DeleteCatalogNode";
public string DeleteCompleted => _baseUrl + "DeleteCompleted";
- public string DeleteResource => _baseUrl + "DeleteResource";
public string DeleteLink => _baseUrl + "DeleteLink";
+ public string DeleteResource => _baseUrl + "DeleteResource";
+ public string ImportCatalogXml => _baseUrl + "ImportCatalogXml";
+ public string ImportResources => _baseUrl + "ImportResources";
+ public string ImportUpdateCompleted => _baseUrl + "ImportUpdateCompleted";
+ public string IsImporting => _baseUrl + "IsImporting";
}
-}
\ No newline at end of file
+}
diff --git a/src/EpiserverAdapter/EntityService.cs b/src/EpiserverAdapter/EntityService.cs
index 4861115..75ee91f 100644
--- a/src/EpiserverAdapter/EntityService.cs
+++ b/src/EpiserverAdapter/EntityService.cs
@@ -9,8 +9,12 @@ namespace Epinova.InRiverConnector.EpiserverAdapter
{
public class EntityService : IEntityService
{
+ private readonly Dictionary _cachedParentEntities;
private readonly IConfiguration _config;
private readonly EpiMappingHelper _mappingHelper;
+ private List _allResourceStructureEntities;
+
+ private Dictionary> _cachedChannelNodeStructureEntities;
///
/// Very simple local cache of all entities. FlushCache() empties the list. GetEntity should retrieve from this list if possible, to
@@ -18,119 +22,121 @@ public class EntityService : IEntityService
///
private List _cachedEntities;
- private Dictionary> _cachedChannelNodeStructureEntities;
- private List _allResourceStructureEntities;
- private Dictionary _cachedParentEntities;
-
public EntityService(IConfiguration config, EpiMappingHelper mappingHelper)
{
_config = config;
_mappingHelper = mappingHelper;
-
_cachedEntities = new List();
_cachedChannelNodeStructureEntities = new Dictionary>();
_cachedParentEntities = new Dictionary();
}
- public Entity GetEntity(int id, LoadLevel loadLevel)
+ public void FlushCache()
{
- var existingEntity = _cachedEntities.FirstOrDefault(x => x.Id == id);
-
- if (existingEntity != null && loadLevel <= existingEntity.LoadLevel)
- return existingEntity;
-
- var fetchedEntity = RemoteManager.DataService.GetEntity(id, loadLevel);
-
- if (existingEntity != null)
- _cachedEntities.Remove(existingEntity);
+ _cachedEntities = new List();
+ _cachedChannelNodeStructureEntities = new Dictionary>();
+ _allResourceStructureEntities = null;
+ }
- _cachedEntities.Add(fetchedEntity);
+ public List GetAllResourceLocations(int resourceEntityId)
+ {
+ if (_allResourceStructureEntities == null)
+ _allResourceStructureEntities = RemoteManager.ChannelService.GetAllChannelStructureEntitiesForType(_config.ChannelId, "Resource");
- return fetchedEntity;
+ return _allResourceStructureEntities.Where(x => x.EntityId == resourceEntityId).ToList();
}
public List GetAllStructureEntitiesInChannel(List entityTypes)
{
- List result = new List();
+ var result = new List();
foreach (EntityType entityType in entityTypes)
{
List response = RemoteManager.ChannelService.GetAllChannelStructureEntitiesForType(_config.ChannelId, entityType.Id);
result.AddRange(response);
}
- return _config.ForceIncludeLinkedContent ?
- result.ToList() :
- result.Where(x => FilterLinkedContentNotBelongingToChannelNode(x, result)).ToList();
+ return _config.ForceIncludeLinkedContent ? result.ToList() : result.Where(x => FilterLinkedContentNotBelongingToChannelNode(x, result)).ToList();
}
- public List GetAllResourceLocations(int resourceEntityId)
+ public List GetChannelNodeStructureEntitiesInPath(string path)
{
- if(_allResourceStructureEntities == null)
- _allResourceStructureEntities = RemoteManager.ChannelService.GetAllChannelStructureEntitiesForType(_config.ChannelId, "Resource");
+ if (_cachedChannelNodeStructureEntities.ContainsKey(path))
+ return _cachedChannelNodeStructureEntities[path];
- return _allResourceStructureEntities.Where(x => x.EntityId == resourceEntityId).ToList();
+ List structureEntities = RemoteManager.ChannelService.GetAllChannelStructureEntitiesForTypeInPath(path, "ChannelNode");
+ _cachedChannelNodeStructureEntities.Add(path, structureEntities);
+ return structureEntities;
}
- public List GetEntityInChannelWithParent(int channelId, int entityId, int parentId)
+ public List GetChildrenEntitiesInChannel(int entityId, string path)
{
var result = new List();
- var response = RemoteManager.ChannelService.GetAllStructureEntitiesForEntityWithParentInChannel(channelId, entityId, parentId);
- if (response.Any())
+ if (!String.IsNullOrEmpty(path))
{
- result.AddRange(response);
+ List response = RemoteManager.ChannelService.GetChannelStructureChildrenFromPath(entityId, path);
+ if (response.Any())
+ {
+ result.AddRange(response);
+ }
}
return result;
}
- public string GetTargetEntityPath(int targetEntityId, List channelEntities, int? parentId = null)
+ public Entity GetEntity(int id, LoadLevel loadLevel)
{
- StructureEntity targetStructureEntity = new StructureEntity();
+ Entity existingEntity = _cachedEntities.FirstOrDefault(x => x.Id == id);
- if (parentId == null)
- {
- targetStructureEntity = channelEntities.Find(i => i.EntityId.Equals(targetEntityId));
- }
- else
- {
- targetStructureEntity = channelEntities.Find(i => i.EntityId.Equals(targetEntityId) && i.ParentId.Equals(parentId));
- }
+ if (existingEntity != null && loadLevel <= existingEntity.LoadLevel)
+ return existingEntity;
+ Entity fetchedEntity = RemoteManager.DataService.GetEntity(id, loadLevel);
- string path = string.Empty;
+ if (existingEntity != null)
+ _cachedEntities.Remove(existingEntity);
- if (targetStructureEntity != null)
- {
- path = targetStructureEntity.Path;
- }
+ _cachedEntities.Add(fetchedEntity);
- return path;
+ return fetchedEntity;
}
- public List GetChildrenEntitiesInChannel(int entityId, string path)
+ public List GetEntityInChannelWithParent(int channelId, int entityId, int parentId)
{
var result = new List();
- if (!string.IsNullOrEmpty(path))
+ List response = RemoteManager.ChannelService.GetAllStructureEntitiesForEntityWithParentInChannel(channelId, entityId, parentId);
+ if (response.Any())
{
- var response = RemoteManager.ChannelService.GetChannelStructureChildrenFromPath(entityId, path);
- if (response.Any())
- {
- result.AddRange(response);
- }
+ result.AddRange(response);
}
return result;
}
- public List GetStructureEntitiesForEntityInChannel(int channelId, int entityId)
+
+ public Entity GetParentProduct(StructureEntity itemStructureEntity)
{
- return RemoteManager.ChannelService.GetAllStructureEntitiesForEntityInChannel(channelId, entityId);
+ int entityId = itemStructureEntity.EntityId;
+
+ if (_cachedParentEntities.ContainsKey(entityId))
+ return _cachedParentEntities[entityId];
+
+ List inboundLinks = RemoteManager.DataService.GetInboundLinksForEntity(entityId);
+ Link relationLink = inboundLinks.OrderBy(x => x.Index)
+ .FirstOrDefault(x => _mappingHelper.IsRelation(x.LinkType));
+
+ if (relationLink == null)
+ return null;
+
+ Entity parent = GetEntity(relationLink.Source.Id, LoadLevel.DataOnly);
+ _cachedParentEntities.Add(entityId, parent);
+
+ return parent;
}
public StructureEntity GetParentStructureEntity(int channelId, int sourceEntityId, int targetEntityId, List channelEntities)
{
- var targetStructureEntity = channelEntities.Find(i => i.EntityId.Equals(targetEntityId) && i.ParentId.Equals(sourceEntityId));
- var structureEntities = RemoteManager.ChannelService.GetAllStructureEntitiesForEntityInChannel(channelId, sourceEntityId);
+ StructureEntity targetStructureEntity = channelEntities.Find(i => i.EntityId.Equals(targetEntityId) && i.ParentId.Equals(sourceEntityId));
+ List structureEntities = RemoteManager.ChannelService.GetAllStructureEntitiesForEntityInChannel(channelId, sourceEntityId);
if (targetStructureEntity == null || !structureEntities.Any())
{
@@ -144,44 +150,35 @@ public StructureEntity GetParentStructureEntity(int channelId, int sourceEntityI
return structureEntities.Find(i => i.Path.Equals(parentPath) && i.EntityId.Equals(sourceEntityId));
}
- public List GetChannelNodeStructureEntitiesInPath(string path)
+ public List GetStructureEntitiesForEntityInChannel(int channelId, int entityId)
{
- if (_cachedChannelNodeStructureEntities.ContainsKey(path))
- return _cachedChannelNodeStructureEntities[path];
-
- var structureEntities = RemoteManager.ChannelService.GetAllChannelStructureEntitiesForTypeInPath(path, "ChannelNode");
- _cachedChannelNodeStructureEntities.Add(path, structureEntities);
- return structureEntities;
+ return RemoteManager.ChannelService.GetAllStructureEntitiesForEntityInChannel(channelId, entityId);
}
-
- public Entity GetParentProduct(StructureEntity itemStructureEntity)
+ public string GetTargetEntityPath(int targetEntityId, List channelEntities, int? parentId = null)
{
- var entityId = itemStructureEntity.EntityId;
-
- if (_cachedParentEntities.ContainsKey(entityId))
- return _cachedParentEntities[entityId];
+ StructureEntity targetStructureEntity = parentId == null
+ ? channelEntities.Find(i => i.EntityId.Equals(targetEntityId))
+ : channelEntities.Find(i => i.EntityId.Equals(targetEntityId) && i.ParentId.Equals(parentId));
- var inboundLinks = RemoteManager.DataService.GetInboundLinksForEntity(entityId);
- var relationLink = inboundLinks.OrderBy(x => x.Index)
- .FirstOrDefault(x => _mappingHelper.IsRelation(x.LinkType));
+ string path = String.Empty;
- if (relationLink == null)
- return null;
-
- var parent = GetEntity(relationLink.Source.Id, LoadLevel.DataOnly);
- _cachedParentEntities.Add(entityId, parent);
+ if (targetStructureEntity != null)
+ {
+ path = targetStructureEntity.Path;
+ }
- return parent;
+ return path;
}
- public void FlushCache()
+ private bool BelongsInChannel(StructureEntity arg)
{
- _cachedEntities = new List();
- _cachedChannelNodeStructureEntities = new Dictionary>();
- _allResourceStructureEntities = null;
+ bool isRelation = _mappingHelper.IsRelation(arg.LinkTypeIdFromParent);
+ bool isChannelNodeLink = _mappingHelper.IsChannelNodeLink(arg.LinkTypeIdFromParent);
+
+ return isRelation || isChannelNodeLink;
}
-
+
///
/// Tells you whether or not a structure entity belongs in the channel, based on it's links.
@@ -192,16 +189,8 @@ public void FlushCache()
/// Everything in the channel.
private bool FilterLinkedContentNotBelongingToChannelNode(StructureEntity structureEntity, List allStructureEntities)
{
- var sameEntityStructureEntities = allStructureEntities.Where(x => x.EntityId == structureEntity.EntityId);
+ IEnumerable sameEntityStructureEntities = allStructureEntities.Where(x => x.EntityId == structureEntity.EntityId);
return sameEntityStructureEntities.Any(BelongsInChannel);
}
-
- private bool BelongsInChannel(StructureEntity arg)
- {
- var isRelation = _mappingHelper.IsRelation(arg.LinkTypeIdFromParent);
- var isChannelNodeLink = _mappingHelper.IsChannelNodeLink(arg.LinkTypeIdFromParent);
-
- return isRelation || isChannelNodeLink;
- }
}
-}
\ No newline at end of file
+}
diff --git a/src/EpiserverAdapter/Enums/CVLDataMode.cs b/src/EpiserverAdapter/Enums/CVLDataMode.cs
index b18822e..36b86de 100644
--- a/src/EpiserverAdapter/Enums/CVLDataMode.cs
+++ b/src/EpiserverAdapter/Enums/CVLDataMode.cs
@@ -7,4 +7,4 @@ public enum CVLDataMode
Values,
KeysAndValues
}
-}
\ No newline at end of file
+}
diff --git a/src/EpiserverAdapter/EpiserverAdapter.cs b/src/EpiserverAdapter/EpiserverAdapter.cs
index e9e2cf9..7e455d7 100644
--- a/src/EpiserverAdapter/EpiserverAdapter.cs
+++ b/src/EpiserverAdapter/EpiserverAdapter.cs
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Reflection;
+using System.Threading.Tasks;
using Epinova.InRiverConnector.EpiserverAdapter.Communication;
using Epinova.InRiverConnector.EpiserverAdapter.Helpers;
using Epinova.InRiverConnector.EpiserverAdapter.XmlFactories;
@@ -17,20 +18,142 @@ namespace Epinova.InRiverConnector.EpiserverAdapter
{
public class EpiserverAdapter : ServerListener, IOutboundConnector, IChannelListener, ICVLListener
{
- private bool _started;
- private IConfiguration _config;
- private EpiApi _epiApi;
- private CatalogElementFactory _catalogElementFactory;
+ private CatalogCodeGenerator _catalogCodeGenerator;
private CatalogDocumentFactory _catalogDocumentFactory;
+ private CatalogElementFactory _catalogElementFactory;
private ChannelHelper _channelHelper;
- private ResourceElementFactory _resourceElementFactory;
- private EpiMappingHelper _epiMappingHelper;
- private CatalogCodeGenerator _catalogCodeGenerator;
- private ChannelPublisher _publisher;
- private PimFieldAdapter _pimFieldAdapter;
- private IEntityService _entityService;
+ private IConfiguration _config;
private CvlUpdater _cvlUpdater;
private DocumentFileHelper _documentFileHelper;
+ private IEntityService _entityService;
+ private EpiApi _epiApi;
+ private EpiMappingHelper _epiMappingHelper;
+ private PimFieldAdapter _pimFieldAdapter;
+ private ChannelPublisher _publisher;
+ private ResourceElementFactory _resourceElementFactory;
+
+ public new bool IsStarted { get; private set; }
+
+ public void AssortmentCopiedInChannel(int channelId, int assortmentId, int targetId, string targetType)
+ {
+ }
+
+ public void ChannelEntityAdded(int channelId, int entityId)
+ {
+ DoWithInitCheck(channelId, ConnectorEventType.ChannelEntityAdded, channel => _publisher.ChannelEntityAddedAsync(channel, entityId));
+ }
+
+ public void ChannelEntityDeleted(int channelId, Entity deletedEntity)
+ {
+ DoWithInitCheck(channelId, ConnectorEventType.ChannelEntityDeleted, channel => _publisher.ChannelEntityDeletedAsync(channel, deletedEntity));
+ }
+
+ public void ChannelEntityFieldSetUpdated(int channelId, int entityId, string fieldSetId)
+ {
+ ChannelEntityUpdated(channelId, entityId, null);
+ }
+
+ public void ChannelEntitySpecificationFieldAdded(int channelId, int entityId, string fieldName)
+ {
+ ChannelEntityUpdated(channelId, entityId, null);
+ }
+
+ public void ChannelEntitySpecificationFieldUpdated(int channelId, int entityId, string fieldName)
+ {
+ ChannelEntityUpdated(channelId, entityId, null);
+ }
+
+ public void ChannelEntityUpdated(int channelId, int entityId, string data)
+ {
+ DoWithInitCheck(channelId, ConnectorEventType.ChannelEntityUpdated, channel =>
+ {
+ if (channel.Id == entityId)
+ {
+ ConnectorEvent connectorEvent = ConnectorEventHelper.InitiateEvent(_config, ConnectorEventType.ChannelEntityUpdated, "Updated Entity is the Channel, no action required", 100);
+ return connectorEvent;
+ }
+
+ return AsyncHelper.RunSync(() => _publisher.ChannelEntityUpdatedAsync(channel, entityId, data));
+ });
+ }
+
+ public void ChannelLinkAdded(int channelId, int sourceEntityId, int targetEntityId, string linkTypeId, int? linkEntityId)
+ {
+ DoWithInitCheck(channelId, ConnectorEventType.ChannelLinkAdded, channel => _publisher.ChannelLinkAddedAsync(channel, sourceEntityId, targetEntityId, linkTypeId, linkEntityId));
+ }
+
+ public void ChannelLinkDeleted(int channelId, int sourceEntityId, int targetEntityId, string linkTypeId, int? linkEntityId)
+ {
+ DoWithInitCheck(channelId, ConnectorEventType.ChannelLinkDeleted,
+ channel => _publisher.ChannelLinkDeletedAsync(channel, sourceEntityId, targetEntityId, linkTypeId, linkEntityId)
+ );
+ }
+
+ public void ChannelLinkUpdated(int channelId, int sourceEntityId, int targetEntityId, string linkTypeId, int? linkEntityId)
+ {
+ DoWithInitCheck(channelId, ConnectorEventType.ChannelLinkUpdated, channel =>
+ _publisher.ChannelLinkUpdatedAsync(channel, sourceEntityId, targetEntityId, linkTypeId, linkEntityId)
+ );
+ }
+
+ public void Publish(int channelId)
+ {
+ DoWithInitCheck(channelId, ConnectorEventType.Publish, channelEntity => _publisher.PublishAsync(channelEntity));
+ }
+
+ public void Synchronize(int channelId)
+ {
+ }
+
+ public void UnPublish(int channelId)
+ {
+ if (channelId != _config.ChannelId)
+ return;
+
+ IntegrationLogger.Write(LogLevel.Information, $"Unpublish on channel: {channelId} called. No action taken.");
+ }
+
+ public void CVLValueCreated(string cvlId, string cvlValueKey)
+ {
+ }
+
+ public void CVLValueDeleted(string cvlId, string cvlValueKey)
+ {
+ }
+
+ public void CVLValueDeletedAll(string cvlId)
+ {
+ }
+
+ public void CVLValueUpdated(string cvlId, string cvlValueKey)
+ {
+ DoWithInitCheck(_config.ChannelId, ConnectorEventType.CVLValueUpdated, channelEntity => _cvlUpdater.CVLValueUpdatedAsync(channelEntity, cvlId, cvlValueKey));
+ }
+
+ public new void InitConfigurationSettings()
+ {
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.PublishFolder, ConfigDefaults.PublishFolder);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.ResourcesPublishFolder, ConfigDefaults.ResourcesPublishFolder);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.ResourceConfiguration, ConfigDefaults.ResourceConfiguration);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.LanguageMapping, ConfigDefaults.LanguageMapping);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.ItemToSkus, ConfigDefaults.ItemToSkus);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.CvlData, ConfigDefaults.CvlData);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.BundleTypes, String.Empty);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.PackageTypes, String.Empty);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.DynamicPackageTypes, String.Empty);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.ChannelId, "123");
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.EpiCodeFields, String.Empty);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.ExcludeFields, String.Empty);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.EpiNameFields, String.Empty);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.UseThreeLevelsInCommerce, ConfigDefaults.UseThreeLevelsinCommerce);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.HttpPostUrl, String.Empty);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.EpiEndpoint, ConfigDefaults.EpiEndpoint);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.EpiApiKey, ConfigDefaults.EpiApiKey);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.EpiTimeout, ConfigDefaults.EpiTimeout);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.ExportEntities, ConfigDefaults.ExportEntities);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.BatchSize, String.Empty);
+ ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.ForceIncludeLinkedContent, ConfigDefaults.ForceIncludeLinkedContent);
+ }
public new void Start()
{
@@ -45,7 +168,7 @@ public class EpiserverAdapter : ServerListener, IOutboundConnector, IChannelList
Entity channel = RemoteManager.DataService.GetEntity(_config.ChannelId, LoadLevel.Shallow);
if (channel == null || channel.EntityType.Id != "Channel")
{
- _started = false;
+ IsStarted = false;
ConnectorEventHelper.UpdateEvent(startEvent, "Channel id is not valid: Entity with given ID is not a channel, or doesn't exist. Unable to start", -1, true);
return;
}
@@ -54,32 +177,32 @@ public class EpiserverAdapter : ServerListener, IOutboundConnector, IChannelList
_epiMappingHelper = new EpiMappingHelper(_config, _pimFieldAdapter);
_entityService = new EntityService(_config, _epiMappingHelper);
_catalogCodeGenerator = new CatalogCodeGenerator(_config, _entityService);
- _epiApi = new EpiApi(_config, _catalogCodeGenerator, _pimFieldAdapter);
+ _epiApi = new EpiApi(_config, _catalogCodeGenerator);
_catalogElementFactory = new CatalogElementFactory(_config, _epiMappingHelper, _catalogCodeGenerator, _pimFieldAdapter);
_channelHelper = new ChannelHelper(_config, _entityService);
_catalogDocumentFactory = new CatalogDocumentFactory(_config, _epiApi, _catalogElementFactory, _epiMappingHelper, _channelHelper, _catalogCodeGenerator, _entityService);
_resourceElementFactory = new ResourceElementFactory(_catalogElementFactory, _epiMappingHelper, _catalogCodeGenerator, _config, _entityService);
-
+
_documentFileHelper = new DocumentFileHelper(_config, _channelHelper);
_cvlUpdater = new CvlUpdater(_config, _catalogDocumentFactory, _epiApi, _documentFileHelper);
- _publisher = new ChannelPublisher(_config,
- _catalogDocumentFactory,
- _catalogElementFactory,
- _resourceElementFactory,
- _epiApi,
- _epiMappingHelper,
- _documentFileHelper,
- _pimFieldAdapter,
- _entityService,
- _catalogCodeGenerator);
+ _publisher = new ChannelPublisher(_config,
+ _catalogDocumentFactory,
+ _catalogElementFactory,
+ _resourceElementFactory,
+ _epiApi,
+ _epiMappingHelper,
+ _documentFileHelper,
+ _pimFieldAdapter,
+ _entityService,
+ _catalogCodeGenerator);
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainAssemblyResolve;
InitConnector();
base.Start();
- _started = true;
+ IsStarted = true;
ConnectorEventHelper.UpdateEvent(startEvent, "Connector has started", 100);
}
catch (Exception ex)
@@ -93,8 +216,8 @@ public class EpiserverAdapter : ServerListener, IOutboundConnector, IChannelList
public new void Stop()
{
base.Stop();
- var connectorEvent = ConnectorEventHelper.InitiateEvent(_config, ConnectorEventType.Stop, "Connector is stopping", 0);
- _started = false;
+ ConnectorEvent connectorEvent = ConnectorEventHelper.InitiateEvent(_config, ConnectorEventType.Stop, "Connector is stopping", 0);
+ IsStarted = false;
_epiApi = null;
_catalogElementFactory = null;
_catalogDocumentFactory = null;
@@ -111,139 +234,45 @@ public class EpiserverAdapter : ServerListener, IOutboundConnector, IChannelList
ConnectorEventHelper.UpdateEvent(connectorEvent, "Connector has stopped.", 100);
}
- public new void InitConfigurationSettings()
- {
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.PublishFolder, ConfigDefaults.PublishFolder);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.ResourcesPublishFolder, ConfigDefaults.ResourcesPublishFolder);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.ResourceConfiguration, ConfigDefaults.ResourceConfiguration);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.LanguageMapping, ConfigDefaults.LanguageMapping);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.ItemToSkus, ConfigDefaults.ItemToSkus);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.CvlData, ConfigDefaults.CvlData);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.BundleTypes, string.Empty);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.PackageTypes, string.Empty);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.DynamicPackageTypes, string.Empty);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.ChannelId, "123");
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.EpiCodeFields, string.Empty);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.ExcludeFields, string.Empty);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.EpiNameFields, string.Empty);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.UseThreeLevelsInCommerce, ConfigDefaults.UseThreeLevelsinCommerce);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.HttpPostUrl, string.Empty);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.EpiEndpoint, ConfigDefaults.EpiEndpoint);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.EpiApiKey, ConfigDefaults.EpiApiKey);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.EpiTimeout, ConfigDefaults.EpiTimeout);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.ExportEntities, ConfigDefaults.ExportEntities);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.BatchSize, string.Empty);
- ConfigurationManager.Instance.SetConnectorSetting(Id, ConfigKeys.ForceIncludeLinkedContent, ConfigDefaults.ForceIncludeLinkedContent);
- }
-
- public new bool IsStarted => _started;
-
- public void Publish(int channelId)
- {
- DoWithInitCheck(channelId, ConnectorEventType.Publish, channelEntity => _publisher.Publish(channelEntity));
- }
-
- public void UnPublish(int channelId)
+ private Assembly CurrentDomainAssemblyResolve(object sender, ResolveEventArgs args)
{
- if (channelId != _config.ChannelId)
- return;
+ string folderPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
+ if (folderPath == null)
+ return null;
- IntegrationLogger.Write(LogLevel.Information, $"Unpublish on channel: {channelId} called. No action taken.");
- }
+ int ix = folderPath.LastIndexOf("\\", StringComparison.Ordinal);
+ if (ix == -1)
+ {
+ return null;
+ }
- public void Synchronize(int channelId)
- {
- }
+ folderPath = folderPath.Substring(0, ix);
+ string assemblyPath = Path.Combine(folderPath, new AssemblyName(args.Name).Name + ".dll");
- public void ChannelEntityAdded(int channelId, int entityId)
- {
- DoWithInitCheck(channelId, ConnectorEventType.ChannelEntityAdded, channel => _publisher.ChannelEntityAdded(channel, entityId));
- }
-
- public void ChannelEntityUpdated(int channelId, int entityId, string data)
- {
- DoWithInitCheck(channelId, ConnectorEventType.ChannelEntityUpdated, channel =>
+ if (File.Exists(assemblyPath) == false)
{
- if (channel.Id == entityId)
+ assemblyPath = Path.Combine(folderPath + "\\OutboundConnectors\\", new AssemblyName(args.Name).Name + ".dll");
+ if (File.Exists(assemblyPath) == false)
{
- var connectorEvent = ConnectorEventHelper.InitiateEvent(_config, ConnectorEventType.ChannelEntityUpdated, "Updated Entity is the Channel, no action required", 100);
- return connectorEvent;
+ return null;
}
+ }
- return _publisher.ChannelEntityUpdated(channel, entityId, data);
- });
- }
-
- public void ChannelEntityDeleted(int channelId, Entity deletedEntity)
- {
- DoWithInitCheck(channelId, ConnectorEventType.ChannelEntityDeleted, channel => _publisher.ChannelEntityDeleted(channel, deletedEntity));
- }
-
- public void ChannelEntityFieldSetUpdated(int channelId, int entityId, string fieldSetId)
- {
- ChannelEntityUpdated(channelId, entityId, null);
- }
-
- public void ChannelEntitySpecificationFieldAdded(int channelId, int entityId, string fieldName)
- {
- ChannelEntityUpdated(channelId, entityId, null);
- }
-
- public void ChannelEntitySpecificationFieldUpdated(int channelId, int entityId, string fieldName)
- {
- ChannelEntityUpdated(channelId, entityId, null);
- }
-
- public void ChannelLinkAdded(int channelId, int sourceEntityId, int targetEntityId, string linkTypeId, int? linkEntityId)
- {
- DoWithInitCheck(channelId, ConnectorEventType.ChannelLinkAdded,
- channel => _publisher.ChannelLinkAdded(channel, sourceEntityId, targetEntityId, linkTypeId, linkEntityId));
- }
-
- public void ChannelLinkDeleted(int channelId, int sourceEntityId, int targetEntityId, string linkTypeId, int? linkEntityId)
- {
- DoWithInitCheck(channelId, ConnectorEventType.ChannelLinkDeleted,
- channel => _publisher.ChannelLinkDeleted(channel, sourceEntityId, targetEntityId, linkTypeId, linkEntityId)
- );
- }
-
- public void ChannelLinkUpdated(int channelId, int sourceEntityId, int targetEntityId, string linkTypeId, int? linkEntityId)
- {
- DoWithInitCheck(channelId, ConnectorEventType.ChannelLinkUpdated, channel =>
- _publisher.ChannelLinkUpdated(channel, sourceEntityId, targetEntityId, linkTypeId, linkEntityId)
- );
+ Assembly assembly = Assembly.LoadFrom(assemblyPath);
+ return assembly;
}
- public void AssortmentCopiedInChannel(int channelId, int assortmentId, int targetId, string targetType)
+ private void DoWithInitCheck(int channelId, ConnectorEventType eventType, Func> thingsToDo)
{
-
+ DoWithInitCheck(channelId, eventType, x => AsyncHelper.RunSync(() => thingsToDo(x)));
}
- private void InitConnector()
- {
- try
- {
- var directoryInfo = Directory.CreateDirectory(_config.PublicationsRootPath);
-
- var accessCheckerFileName = "Access_check";
- var filename = Path.Combine(directoryInfo.FullName, accessCheckerFileName);
-
- File.WriteAllText(filename, "Access-checker");
- File.Delete(filename);
- }
- catch (Exception ex)
- {
- IntegrationLogger.Write(LogLevel.Error, $"Attempt to write to {_config.PublicationsRootPath} failed.", ex);
- throw;
- }
- }
-
private void DoWithInitCheck(int channelId, ConnectorEventType eventType, Func thingsToDo)
{
if (channelId != _config.ChannelId)
return;
- var channelEntity = _channelHelper.InitiateChannelConfiguration(channelId);
+ Entity channelEntity = _channelHelper.InitiateChannelConfiguration(channelId);
if (channelEntity == null)
{
ConnectorEventHelper.InitiateEvent(_config, eventType, $"Failed perform {eventType}. Could not find the channel.", -1, true);
@@ -252,12 +281,12 @@ private void DoWithInitCheck(int channelId, ConnectorEventType eventType, Func _cvlUpdater.CVLValueUpdated(channelEntity, cvlId, cvlValueKey));
- }
-
- public void CVLValueDeleted(string cvlId, string cvlValueKey)
- {
- }
-
- public void CVLValueDeletedAll(string cvlId)
- {
- }
-
- private Assembly CurrentDomainAssemblyResolve(object sender, ResolveEventArgs args)
+ private void InitConnector()
{
- string folderPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
- if (folderPath == null)
- return null;
-
- int ix = folderPath.LastIndexOf("\\", StringComparison.Ordinal);
- if (ix == -1)
+ try
{
- return null;
- }
+ DirectoryInfo directoryInfo = Directory.CreateDirectory(_config.PublicationsRootPath);
- folderPath = folderPath.Substring(0, ix);
- string assemblyPath = Path.Combine(folderPath, new AssemblyName(args.Name).Name + ".dll");
+ const string accessCheckerFileName = "Access_check";
+ string filename = Path.Combine(directoryInfo.FullName, accessCheckerFileName);
- if (File.Exists(assemblyPath) == false)
+ File.WriteAllText(filename, "Access-checker");
+ File.Delete(filename);
+ }
+ catch (Exception ex)
{
- assemblyPath = Path.Combine(folderPath + "\\OutboundConnectors\\", new AssemblyName(args.Name).Name + ".dll");
- if (File.Exists(assemblyPath) == false)
- {
- return null;
- }
+ IntegrationLogger.Write(LogLevel.Error, $"Attempt to write to {_config.PublicationsRootPath} failed.", ex);
+ throw;
}
-
- Assembly assembly = Assembly.LoadFrom(assemblyPath);
- return assembly;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/EpiserverAdapter/EpiserverAdapter.csproj b/src/EpiserverAdapter/EpiserverAdapter.csproj
index 66e9ebf..b3416d5 100644
--- a/src/EpiserverAdapter/EpiserverAdapter.csproj
+++ b/src/EpiserverAdapter/EpiserverAdapter.csproj
@@ -44,8 +44,8 @@
-
- ..\..\lib\System.Net.Http.Formatting.dll
+
+ ..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll
@@ -58,6 +58,7 @@
+
@@ -102,11 +103,4 @@
-
\ No newline at end of file
diff --git a/src/EpiserverAdapter/Extensions.cs b/src/EpiserverAdapter/Extensions.cs
index 50c072d..1934945 100644
--- a/src/EpiserverAdapter/Extensions.cs
+++ b/src/EpiserverAdapter/Extensions.cs
@@ -4,24 +4,24 @@ namespace Epinova.InRiverConnector.EpiserverAdapter
{
internal static class Extensions
{
- internal static bool IsItem(this StructureEntity structureEntity)
- {
- return structureEntity.Type == "Item";
- }
-
internal static bool IsChannelNode(this StructureEntity structureEntity)
{
return structureEntity.Type == "ChannelNode";
}
- internal static bool SourceEntityTypeIsChannelNode(this LinkType linkType)
+ internal static bool IsItem(this StructureEntity structureEntity)
{
- return linkType.SourceEntityTypeId == "ChannelNode";
+ return structureEntity.Type == "Item";
}
internal static bool IsProductItemLink(this LinkType linkType)
{
return linkType.SourceEntityTypeId == "Product" && linkType.TargetEntityTypeId == "Item";
}
+
+ internal static bool SourceEntityTypeIsChannelNode(this LinkType linkType)
+ {
+ return linkType.SourceEntityTypeId == "ChannelNode";
+ }
}
-}
\ No newline at end of file
+}
diff --git a/src/EpiserverAdapter/FieldNames.cs b/src/EpiserverAdapter/FieldNames.cs
index 7fa556e..fb3df3e 100644
--- a/src/EpiserverAdapter/FieldNames.cs
+++ b/src/EpiserverAdapter/FieldNames.cs
@@ -2,10 +2,10 @@
{
public static class FieldNames
{
- public static string ResourceMimeType = "ResourceMimeType";
public static string EPiCommonField = "EPiMetaFieldName";
- public static string SKUFieldName = "SKUs";
- public static string SKUData = "Data";
public static string ResourceFileId = "ResourceFileId";
+ public static string ResourceMimeType = "ResourceMimeType";
+ public static string SKUData = "Data";
+ public static string SKUFieldName = "SKUs";
}
-}
\ No newline at end of file
+}
diff --git a/src/EpiserverAdapter/Helpers/ChannelHelper.cs b/src/EpiserverAdapter/Helpers/ChannelHelper.cs
index 9a65ce3..cdea339 100644
--- a/src/EpiserverAdapter/Helpers/ChannelHelper.cs
+++ b/src/EpiserverAdapter/Helpers/ChannelHelper.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Security.Cryptography;
@@ -21,18 +22,15 @@ public ChannelHelper(IConfiguration config, IEntityService entityService)
_entityService = entityService;
}
-
- public Entity InitiateChannelConfiguration(int channelId)
+ public string GetChannelDefaultWeightBase(Entity channel)
{
- Entity channel = _entityService.GetEntity(channelId, LoadLevel.DataOnly);
- if (channel == null)
+ Field defaultWeightBaseField = channel.Fields.FirstOrDefault(f => f.FieldType.Id.ToLower().Contains("channeldefaultweightbase"));
+ if (defaultWeightBaseField == null || defaultWeightBaseField.IsEmpty())
{
- IntegrationLogger.Write(LogLevel.Error, "Could not find channel");
- return null;
+ return "lbs";
}
- UpdateChannelSettings(channel);
- return channel;
+ return defaultWeightBaseField.Data.ToString();
}
public Guid GetChannelGuid(Entity channel)
@@ -43,7 +41,7 @@ public Guid GetChannelGuid(Entity channel)
{
if (channel.DisplayName.FieldType.DataType.Equals(DataType.LocaleString))
{
- var cultureInfo = _config.LanguageMapping[_config.ChannelDefaultLanguage];
+ CultureInfo cultureInfo = _config.LanguageMapping[_config.ChannelDefaultLanguage];
value = ((LocaleString)channel.DisplayName.Data)[cultureInfo];
}
else
@@ -51,7 +49,7 @@ public Guid GetChannelGuid(Entity channel)
value = channel.DisplayName.Data.ToString();
}
- if (string.IsNullOrEmpty(value))
+ if (String.IsNullOrEmpty(value))
{
value = channel.Id.ToString(CultureInfo.InvariantCulture);
}
@@ -62,20 +60,6 @@ public Guid GetChannelGuid(Entity channel)
return new Guid(data);
}
- public Entity GetParentChannelNode(StructureEntity structureEntity)
- {
- var channelNodesInPath = _entityService.GetChannelNodeStructureEntitiesInPath(structureEntity.Path);
- var entity = channelNodesInPath.LastOrDefault();
- return entity != null ? _entityService.GetEntity(entity.EntityId, LoadLevel.DataOnly) : null;
- }
-
- public bool ItemHasParentInChannel(StructureEntity itemStructureEntity)
- {
- var parentProduct = _entityService.GetParentProduct(itemStructureEntity);
- var parentEntityStructureEntities = RemoteManager.ChannelService.GetAllStructureEntitiesForEntityInChannel(_config.ChannelId, parentProduct.Id);
- return parentEntityStructureEntities != null && parentEntityStructureEntities.Any();
- }
-
public string GetChannelIdentifier(Entity channelEntity)
{
string channelIdentifier = channelEntity.Id.ToString(CultureInfo.InvariantCulture);
@@ -86,28 +70,33 @@ public string GetChannelIdentifier(Entity channelEntity)
return channelIdentifier;
}
-
- private string GetChannelPrefix(Entity channel)
+ public Entity GetParentChannelNode(StructureEntity structureEntity)
{
- Field channelPrefixField = channel.Fields.FirstOrDefault(f => f.FieldType.Id.ToLower().Contains("channelprefix"));
- if (channelPrefixField == null || channelPrefixField.IsEmpty())
- {
- return string.Empty;
- }
-
- return channelPrefixField.Data.ToString();
+ List channelNodesInPath = _entityService.GetChannelNodeStructureEntitiesInPath(structureEntity.Path);
+ StructureEntity entity = channelNodesInPath.LastOrDefault();
+ return entity != null ? _entityService.GetEntity(entity.EntityId, LoadLevel.DataOnly) : null;
}
- private CultureInfo GetChannelDefaultLanguage(Entity channel)
+
+ public Entity InitiateChannelConfiguration(int channelId)
{
- Field defaultLanguageField = channel.Fields.FirstOrDefault(f => f.FieldType.Id.ToLower().Contains("channeldefaultlanguage"));
- if (defaultLanguageField == null || defaultLanguageField.IsEmpty())
+ Entity channel = _entityService.GetEntity(channelId, LoadLevel.DataOnly);
+ if (channel == null)
{
- return new CultureInfo("en-us");
+ IntegrationLogger.Write(LogLevel.Error, "Could not find channel");
+ return null;
}
- return new CultureInfo(defaultLanguageField.Data.ToString());
+ UpdateChannelSettings(channel);
+ return channel;
+ }
+
+ public bool ItemHasParentInChannel(StructureEntity itemStructureEntity)
+ {
+ Entity parentProduct = _entityService.GetParentProduct(itemStructureEntity);
+ List parentEntityStructureEntities = RemoteManager.ChannelService.GetAllStructureEntitiesForEntityInChannel(_config.ChannelId, parentProduct.Id);
+ return parentEntityStructureEntities != null && parentEntityStructureEntities.Any();
}
private string GetChannelDefaultCurrency(Entity channel)
@@ -121,15 +110,27 @@ private string GetChannelDefaultCurrency(Entity channel)
return defaultCurrencyField.Data.ToString();
}
- public string GetChannelDefaultWeightBase(Entity channel)
+ private CultureInfo GetChannelDefaultLanguage(Entity channel)
{
- Field defaultWeightBaseField = channel.Fields.FirstOrDefault(f => f.FieldType.Id.ToLower().Contains("channeldefaultweightbase"));
- if (defaultWeightBaseField == null || defaultWeightBaseField.IsEmpty())
+ Field defaultLanguageField = channel.Fields.FirstOrDefault(f => f.FieldType.Id.ToLower().Contains("channeldefaultlanguage"));
+ if (defaultLanguageField == null || defaultLanguageField.IsEmpty())
{
- return "lbs";
+ return new CultureInfo("en-us");
}
- return defaultWeightBaseField.Data.ToString();
+ return new CultureInfo(defaultLanguageField.Data.ToString());
+ }
+
+
+ private string GetChannelPrefix(Entity channel)
+ {
+ Field channelPrefixField = channel.Fields.FirstOrDefault(f => f.FieldType.Id.ToLower().Contains("channelprefix"));
+ if (channelPrefixField == null || channelPrefixField.IsEmpty())
+ {
+ return String.Empty;
+ }
+
+ return channelPrefixField.Data.ToString();
}
private void UpdateChannelSettings(Entity channel)
@@ -140,4 +141,4 @@ private void UpdateChannelSettings(Entity channel)
_config.ChannelIdPrefix = GetChannelPrefix(channel);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/EpiserverAdapter/Helpers/ConnectorEventHelper.cs b/src/EpiserverAdapter/Helpers/ConnectorEventHelper.cs
index 192c61f..d46ea30 100644
--- a/src/EpiserverAdapter/Helpers/ConnectorEventHelper.cs
+++ b/src/EpiserverAdapter/Helpers/ConnectorEventHelper.cs
@@ -76,4 +76,4 @@ internal static ConnectorEvent UpdateEvent(ConnectorEvent connectorEvent, string
return connectorEvent;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/EpiserverAdapter/Helpers/DocumentFileHelper.cs b/src/EpiserverAdapter/Helpers/DocumentFileHelper.cs
index f6459b1..073b5e2 100644
--- a/src/EpiserverAdapter/Helpers/DocumentFileHelper.cs
+++ b/src/EpiserverAdapter/Helpers/DocumentFileHelper.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
-using System.IO.Packaging;
using System.Linq;
using System.Xml.Linq;
using inRiver.Integration.Logging;
@@ -13,8 +12,8 @@ namespace Epinova.InRiverConnector.EpiserverAdapter.Helpers
{
public class DocumentFileHelper
{
- private readonly IConfiguration _config;
private readonly ChannelHelper _channelHelper;
+ private readonly IConfiguration _config;
public DocumentFileHelper(IConfiguration config, ChannelHelper channelHelper)
{
@@ -22,23 +21,21 @@ public DocumentFileHelper(IConfiguration config, ChannelHelper channelHelper)
_channelHelper = channelHelper;
}
- public string SaveDocument(XDocument doc, string path)
+ public static void CopyStream(FileStream inputStream, Stream outputStream)
{
- if (!Directory.Exists(path))
+ const long maxBufferSize = 4096;
+ long bufferSize = inputStream.Length < maxBufferSize ? inputStream.Length : maxBufferSize;
+ var buffer = new byte[bufferSize];
+ int bytesRead;
+ while ((bytesRead = inputStream.Read(buffer, 0, buffer.Length)) != 0)
{
- Directory.CreateDirectory(path);
+ outputStream.Write(buffer, 0, bytesRead);
}
-
- var filePath = Path.Combine(path, Constants.ResourceExportFilename);
-
- IntegrationLogger.Write(LogLevel.Information, $"Saving document to path {filePath}.");
- doc.Save(filePath);
- return filePath;
}
public string SaveCatalogDocument(Entity channel, XDocument doc, string folderNameTimestampComponent)
{
- var dirPath = Path.Combine(_config.PublicationsRootPath, folderNameTimestampComponent);
+ string dirPath = Path.Combine(_config.PublicationsRootPath, folderNameTimestampComponent);
if (!Directory.Exists(dirPath))
{
@@ -55,75 +52,42 @@ public string SaveCatalogDocument(Entity channel, XDocument doc, string folderNa
IntegrationLogger.Write(LogLevel.Error, "Fail to verify the document: ", exception);
}
- var filePath = Path.Combine(dirPath, Constants.CatalogExportFilename);
+ string filePath = Path.Combine(dirPath, Constants.CatalogExportFilename);
- var channelIdentifier = _channelHelper.GetChannelIdentifier(channel);
+ string channelIdentifier = _channelHelper.GetChannelIdentifier(channel);
IntegrationLogger.Write(LogLevel.Information, $"Saving verified document to path {filePath} for channel: {channelIdentifier}");
doc.Save(filePath);
return filePath;
}
-
- public static void CopyStream(FileStream inputStream, Stream outputStream)
- {
- const long MaxbuffertSize = 4096;
- long bufferSize = inputStream.Length < MaxbuffertSize ? inputStream.Length : MaxbuffertSize;
- byte[] buffer = new byte[bufferSize];
- int bytesRead;
- while ((bytesRead = inputStream.Read(buffer, 0, buffer.Length)) != 0)
- {
- outputStream.Write(buffer, 0, bytesRead);
- }
- }
-
- private XDocument VerifyAndCorrectDocument(XDocument doc)
- {
- var unwantedEntityTypes = CreateUnwantedEntityTypeList();
- XDocument result = new XDocument(doc);
- XElement root = result.Root;
- if (root == null)
- {
- throw new Exception("Can't verify the Catalog.cml as it's empty.");
- }
- var entryElements = root.Descendants("Entry");
- var codesToBeRemoved = new List();
- foreach (XElement entryElement in entryElements)
+ public string SaveDocument(XDocument doc, string path)
+ {
+ if (!Directory.Exists(path))
{
- var code = entryElement.Elements("Code").First().Value;
- var metaClassName = entryElement.Elements("MetaData")
- .Elements("MetaClass")
- .Elements("Name")
- .First().Value;
-
- if (!unwantedEntityTypes.Contains(metaClassName))
- continue;
-
- IntegrationLogger.Write(LogLevel.Debug, $"Code {code} will be removed as it has wrong metaclass name ({metaClassName})");
- codesToBeRemoved.Add(code);
+ Directory.CreateDirectory(path);
}
- foreach (var code in codesToBeRemoved)
- {
- root.Descendants("Entry").Where(x => x.Element("Code")?.Value == code).Remove();
- }
+ string filePath = Path.Combine(path, Constants.ResourceExportFilename);
- return result;
+ IntegrationLogger.Write(LogLevel.Information, $"Saving document to path {filePath}.");
+ doc.Save(filePath);
+ return filePath;
}
private List CreateUnwantedEntityTypeList()
{
- List typeIds = new List
- {
- "Channel",
- "Assortment",
- "Resource",
- "Task",
- "Section",
- "Publication"
- };
-
- List result = new List();
+ var typeIds = new List
+ {
+ "Channel",
+ "Assortment",
+ "Resource",
+ "Task",
+ "Section",
+ "Publication"
+ };
+
+ var result = new List();
foreach (string typeId in typeIds)
{
List