* Fixed firewall rules check and improved the script the check shall be like ~ Get-NetFirewallRule -DisplayName eShopOnContainers-* -ErrorAction Stop * #1397: Replaced deprecated docker.for.win.localhost by host.docker.internal in src/.env (#1400) * Updated Readme (#1402) Fixed sentence structure in Readme. Changed "and a several" to "with several." * CatalogService: Fix issue with Status set when items list is empty (#1304) * Fix issue with Status set when items list is empty * Change method Count() call to Count property Co-authored-by: Dmytro Hridin <v-dmytro.hridin@lionbridge.com> * refactored Equals() method on ValueObject (#1316) * Fix/1403and1404 removed duplicate Key SubscriptionClientName and added app.UseAuthorization() call (#1406) * #1403 removed duplicate Key SubscriptionClientName Removed duplicate key SubscriptionClientName from Tests/Services/Application.FunctionalTests/Services/Marketing/appsettings.json and sorted its content in asc order. * #1404 Added app.UseAuthorization() call Added app.UseAuthorization() call to BasketTestsStartup, LocationsTestsStartup, and MarketingTestsStartup to fix failed unit tests IntegrationEventsScenarios.Post_update_product_price_and_catalog_and_basket_list_modified and MarketingScenarios.Set_new_user_location_and_get_location_campaign_by_user_id (see #1404) * Fix for Campaigns exception and SignalR 401 Unauthorized (#1374) * update API Gateway - /locations-api/ @ webmarketing/envoy.yaml * updated signalr services - envoy: webmarketingapigw - latest client: webmvc - service hub: ordering-signalrhub Co-authored-by: hfz-r <hafiz.roslan@hartalega.com.my> * Mis-Spelled 'client' (#1411) * fix parameter error in multiarch job (#1413) * Private readonly string changed to private const string (#1288) * fix disposing of direct instantiated objects in calalog service #1392 (#1395) * Updated version of different packages. (#1420) * for issue #1423: changed literal string "OpenIdConnect" to constant string (#1424) Co-authored-by: Jeremiah Flaga <j.flaga@arcanys.com> * Updated node-fetch package version. (#1426) * Updated node-fetch package version. * Updated node-forge version. * Fixes #1474: webspa container does not build when running docker-compose up.Updated sha hashes in packages-lock.json (#1475) * Change ReadAllBytes to ReadAllBytesAsync in PicController (#1425) Co-authored-by: edmondshtogu <edmondshtogu@gmail.com> Co-authored-by: InstanceFactory <InstanceFactory@users.noreply.github.com> Co-authored-by: Sumit Ghosh <sumit.ghosh@neudesic.com> Co-authored-by: Yosef Herskovitz <34112131+H3RSKO@users.noreply.github.com> Co-authored-by: Dmytro Hridin <dmytro.hridin@gmail.com> Co-authored-by: Dmytro Hridin <v-dmytro.hridin@lionbridge.com> Co-authored-by: André Silva <andrefilipegsilva@outlook.com> Co-authored-by: hfz-r <39443205+hfz-r@users.noreply.github.com> Co-authored-by: hfz-r <hafiz.roslan@hartalega.com.my> Co-authored-by: Majid Ali Khan Quaid <contactmakq@gmail.com> Co-authored-by: Javier Vela <fjvela@gmail.com> Co-authored-by: Facundo La Rocca <facundo_larocca@yahoo.com.ar> Co-authored-by: Nabil Sedoud <nsedoud@gmail.com> Co-authored-by: jeremiahflaga <flaga.jeremiah@gmail.com> Co-authored-by: Jeremiah Flaga <j.flaga@arcanys.com> Co-authored-by: Wojciech Rak <wojciechrak@users.noreply.github.com> Co-authored-by: Zakaria <23211915+zakaria-c@users.noreply.github.com>
115 lines
4.1 KiB
C#
115 lines
4.1 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
|
using Microsoft.EntityFrameworkCore.Storage;
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
|
using Microsoft.Extensions.Logging;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Data.Common;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services
|
|
{
|
|
public class IntegrationEventLogService : IIntegrationEventLogService,IDisposable
|
|
{
|
|
private readonly IntegrationEventLogContext _integrationEventLogContext;
|
|
private readonly DbConnection _dbConnection;
|
|
private readonly List<Type> _eventTypes;
|
|
private volatile bool disposedValue;
|
|
|
|
public IntegrationEventLogService(DbConnection dbConnection)
|
|
{
|
|
_dbConnection = dbConnection ?? throw new ArgumentNullException(nameof(dbConnection));
|
|
_integrationEventLogContext = new IntegrationEventLogContext(
|
|
new DbContextOptionsBuilder<IntegrationEventLogContext>()
|
|
.UseSqlServer(_dbConnection)
|
|
.Options);
|
|
|
|
_eventTypes = Assembly.Load(Assembly.GetEntryAssembly().FullName)
|
|
.GetTypes()
|
|
.Where(t => t.Name.EndsWith(nameof(IntegrationEvent)))
|
|
.ToList();
|
|
}
|
|
|
|
public async Task<IEnumerable<IntegrationEventLogEntry>> RetrieveEventLogsPendingToPublishAsync(Guid transactionId)
|
|
{
|
|
var tid = transactionId.ToString();
|
|
|
|
var result = await _integrationEventLogContext.IntegrationEventLogs
|
|
.Where(e => e.TransactionId == tid && e.State == EventStateEnum.NotPublished).ToListAsync();
|
|
|
|
if(result != null && result.Any()){
|
|
return result.OrderBy(o => o.CreationTime)
|
|
.Select(e => e.DeserializeJsonContent(_eventTypes.Find(t=> t.Name == e.EventTypeShortName)));
|
|
}
|
|
|
|
return new List<IntegrationEventLogEntry>();
|
|
}
|
|
|
|
public Task SaveEventAsync(IntegrationEvent @event, IDbContextTransaction transaction)
|
|
{
|
|
if (transaction == null) throw new ArgumentNullException(nameof(transaction));
|
|
|
|
var eventLogEntry = new IntegrationEventLogEntry(@event, transaction.TransactionId);
|
|
|
|
_integrationEventLogContext.Database.UseTransaction(transaction.GetDbTransaction());
|
|
_integrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry);
|
|
|
|
return _integrationEventLogContext.SaveChangesAsync();
|
|
}
|
|
|
|
public Task MarkEventAsPublishedAsync(Guid eventId)
|
|
{
|
|
return UpdateEventStatus(eventId, EventStateEnum.Published);
|
|
}
|
|
|
|
public Task MarkEventAsInProgressAsync(Guid eventId)
|
|
{
|
|
return UpdateEventStatus(eventId, EventStateEnum.InProgress);
|
|
}
|
|
|
|
public Task MarkEventAsFailedAsync(Guid eventId)
|
|
{
|
|
return UpdateEventStatus(eventId, EventStateEnum.PublishedFailed);
|
|
}
|
|
|
|
private Task UpdateEventStatus(Guid eventId, EventStateEnum status)
|
|
{
|
|
var eventLogEntry = _integrationEventLogContext.IntegrationEventLogs.Single(ie => ie.EventId == eventId);
|
|
eventLogEntry.State = status;
|
|
|
|
if(status == EventStateEnum.InProgress)
|
|
eventLogEntry.TimesSent++;
|
|
|
|
_integrationEventLogContext.IntegrationEventLogs.Update(eventLogEntry);
|
|
|
|
return _integrationEventLogContext.SaveChangesAsync();
|
|
}
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
{
|
|
if (!disposedValue)
|
|
{
|
|
if (disposing)
|
|
{
|
|
_integrationEventLogContext?.Dispose();
|
|
}
|
|
|
|
|
|
disposedValue = true;
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Dispose(disposing: true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|
|
}
|