Skip to content

Commit

Permalink
1. Revert Simple Controller.
Browse files Browse the repository at this point in the history
2. Added Controller for WebHook.
3. Update solution to Visual Studio Version 17 and other project infromation.
4. Update Application Insights.
  • Loading branch information
OlegoO committed Nov 9, 2022
1 parent 59fb1a4 commit 83f8ea9
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<PropertyGroup>
<Product>VirtoCommerce</Product>
<Copyright>Copyright © VirtoCommerce 2011-2020</Copyright>
<Copyright>Copyright © VirtoCommerce 2011-2022</Copyright>
<Authors>VirtoCommerce</Authors>
</PropertyGroup>
<PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions VirtoCommerce.Storefront.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29613.14
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtoCommerce.Storefront", "VirtoCommerce.Storefront\VirtoCommerce.Storefront.csproj", "{84C14E0A-0F36-4BB5-9C00-7E8FB72891C2}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,40 @@ public ApiStaticContentController(IWorkContextAccessor workContextAccessor, ISto
{
}

// POST: storefrontapi/content/reset-cache
[HttpPost("reset-cache")]
public ActionResult ResetCache([FromBody] ResetCacheModel region)
public ActionResult ResetCache([FromBody] ResetCacheEventModel webHookEvent)
{
switch (region.ContentType)
if (TryResetCacheInternal(webHookEvent?.EventBody?.FirstOrDefault()?.Type))
return Ok("OK");

return Ok("Failed");
}

// POST: storefrontapi/content/reset-cache/theme
[HttpPost("reset-cache/{region}")]
public ActionResult ResetCache([FromRoute] string region)
{
if (TryResetCacheInternal(region))
return Ok("OK");

return Ok("Failed");
}

private bool TryResetCacheInternal(string region)
{
switch (region)
{
case "theme": ThemeEngineCacheRegion.ExpireRegion();
break;
case "theme":
case "themes":
ThemeEngineCacheRegion.ExpireRegion();
return true;
case "pages":
case "blogs":
StaticContentCacheRegion.ExpireRegion();
break;
return true;
}
return Ok();
return false;
}

// POST: storefrontapi/content/pages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected void AddCurrentUser(HttpRequestMessage request)
/// <param name="request"></param>
protected void AddUserIp(HttpRequestMessage request)
{
var userIp = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
var userIp = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress.ToString();

if (!string.IsNullOrEmpty(userIp))
{
Expand Down
20 changes: 18 additions & 2 deletions VirtoCommerce.Storefront/Models/ResetCacheModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,24 @@

namespace VirtoCommerce.Storefront.Models
{
public class ResetCacheModel
/// <summary>
/// Cache Event Model For Web Hook from Virto Commmerce Platform
/// </summary>
public class ResetCacheEventModel
{
public string ContentType { get; set; }
public string EventId { get; set; }

public ResetCacheEventBodyModel[] EventBody { get; set; }
}

public class ResetCacheEventBodyModel
{
public string ObjectType { get; set; }

public string Id { get; set; }

public string Path { get; set; }

public string Type { get; set; }
}
}
10 changes: 5 additions & 5 deletions VirtoCommerce.Storefront/VirtoCommerce.Storefront.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<UserSecretsId>0cd403c4-2cd0-42b3-987a-02900f4a683e</UserSecretsId>
<Description>The storefront implementation of the Virto Commerce platform.</Description>
<PackageLicenseUrl>https://virtocommerce.com/open-source-license</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/VirtoCommerce/vc-storefront-core</PackageProjectUrl>
<RepositoryUrl>https://github.com/VirtoCommerce/vc-storefront-core</RepositoryUrl>
<PackageProjectUrl>https://github.com/VirtoCommerce/vc-storefront</PackageProjectUrl>
<RepositoryUrl>https://github.com/VirtoCommerce/vc-storefront</RepositoryUrl>

<PackageIconUrl>https://virtocommerce.com/themes/assets/logo.jpg</PackageIconUrl>
<PackageReleaseNotes></PackageReleaseNotes>
Expand Down Expand Up @@ -47,10 +47,10 @@
<PackageReference Include="FluentValidation.AspNetCore" Version="10.4.0" />

<PackageReference Include="Markdig" Version="0.30.2" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.20.0" />
<PackageReference Include="Microsoft.ApplicationInsights.PerfCounterCollector" Version="2.20.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights.PerfCounterCollector" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights.SnapshotCollector" Version="1.4.3" />
<PackageReference Include="Microsoft.ApplicationInsights.Web" Version="2.20.0" />
<PackageReference Include="Microsoft.ApplicationInsights.Web" Version="2.21.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="6.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="6.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.4" />
Expand Down

0 comments on commit 83f8ea9

Please sign in to comment.