<commit_before>﻿using AutoMapper;

using Bytes2you.Validation;

using Parser.Common.Contracts;
using Parser.Data.Contracts;
using Parser.Data.Factories;
using Parser.Data.Projections;
using Parser.LogFileParser.Contracts;

namespace Parser.Data.Services.Strategies
{
    public class CombatStatisticsPersistentStorageStrategy : ICombatStatisticsPersistentStorageStrategy
    {
        private readonly IStoredCombatStatisticsProjectionRepository storedCombatStatisticsProjectionRepository;
        private readonly IBusinessTransactionFactory businessTransactionFactory;
        private readonly IMapper objectMapper;

        public CombatStatisticsPersistentStorageStrategy(IStoredCombatStatisticsProjectionRepository storedCombatStatisticsProjectionRepository, IBusinessTransactionFactory businessTransactionFactory, IMapper objectMapper)
        {
            Guard.WhenArgument(storedCombatStatisticsProjectionRepository, nameof(IStoredCombatStatisticsProjectionRepository)).IsNull().Throw();
            Guard.WhenArgument(businessTransactionFactory, nameof(IBusinessTransactionFactory)).IsNull().Throw();
            Guard.WhenArgument(objectMapper, nameof(IMapper)).IsNull().Throw();

            this.storedCombatStatisticsProjectionRepository = storedCombatStatisticsProjectionRepository;
            this.businessTransactionFactory = businessTransactionFactory;
            this.objectMapper = objectMapper;
        }

        public IFinalizedCombatStatistics StoreCombatStatistics(IFinalizedCombatStatistics finalizedCombatStatistics)
        {
            var combatStatisticsProjection = this.objectMapper.Map<StoredCombatStatisticsProjection>(finalizedCombatStatistics);

            using (var transaction = this.businessTransactionFactory.CreateBusinessTransaction())
            {
                this.storedCombatStatisticsProjectionRepository.Create(combatStatisticsProjection);

                transaction.Commit();
            }

            return finalizedCombatStatistics;
        }
    }
}<commit_msg>added Guard to CombatStatisticsPersistentStorageStrategy.StoreCombatStatistics()<commit_after>﻿using AutoMapper;

using Bytes2you.Validation;

using Parser.Common.Contracts;
using Parser.Data.Contracts;
using Parser.Data.Factories;
using Parser.Data.Projections;
using Parser.LogFileParser.Contracts;

namespace Parser.Data.Services.Strategies
{
    public class CombatStatisticsPersistentStorageStrategy : ICombatStatisticsPersistentStorageStrategy
    {
        private readonly IStoredCombatStatisticsProjectionRepository storedCombatStatisticsProjectionRepository;
        private readonly IBusinessTransactionFactory businessTransactionFactory;
        private readonly IMapper objectMapper;

        public CombatStatisticsPersistentStorageStrategy(IStoredCombatStatisticsProjectionRepository storedCombatStatisticsProjectionRepository, IBusinessTransactionFactory businessTransactionFactory, IMapper objectMapper)
        {
            Guard.WhenArgument(storedCombatStatisticsProjectionRepository, nameof(IStoredCombatStatisticsProjectionRepository)).IsNull().Throw();
            Guard.WhenArgument(businessTransactionFactory, nameof(IBusinessTransactionFactory)).IsNull().Throw();
            Guard.WhenArgument(objectMapper, nameof(IMapper)).IsNull().Throw();

            this.storedCombatStatisticsProjectionRepository = storedCombatStatisticsProjectionRepository;
            this.businessTransactionFactory = businessTransactionFactory;
            this.objectMapper = objectMapper;
        }

        public IFinalizedCombatStatistics StoreCombatStatistics(IFinalizedCombatStatistics finalizedCombatStatistics)
        {
            Guard.WhenArgument(finalizedCombatStatistics, nameof(IFinalizedCombatStatistics)).IsNull().Throw();

            var combatStatisticsProjection = this.objectMapper.Map<StoredCombatStatisticsProjection>(finalizedCombatStatistics);

            using (var transaction = this.businessTransactionFactory.CreateBusinessTransaction())
            {
                this.storedCombatStatisticsProjectionRepository.Create(combatStatisticsProjection);

                transaction.Commit();
            }

            return finalizedCombatStatistics;
        }
    }
}
{'fraction_non_alphanumeric': 0.05946201038225578, 'fraction_numerical': 0.00047192071731949034, 'mean_word_length': 4.541176470588235, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '144216', 'n_tokens_mistral': 962, 'n_tokens_neox': 939, 'n_words': 137}