<commit_before>﻿using Neptuo;
using Neptuo.Activators;
using Neptuo.Migrations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;

namespace Money.Bootstrap
{
    internal abstract class UpgradeServiceBase : IUpgradeService
    {
        private readonly IFactory<ApplicationDataContainer> storageContainerFactory;
        private readonly int currentVersion;

        public UpgradeServiceBase(IFactory<ApplicationDataContainer> storageContainerFactory, int currentVersion)
        {
            Ensure.NotNull(storageContainerFactory, "storageContainerFactory");
            this.storageContainerFactory = storageContainerFactory;
        }

        public bool IsRequired()
        {
            return this.currentVersion > GetCurrentVersion();
        }

        public async Task UpgradeAsync(IUpgradeContext context)
        {
            int currentVersion = GetCurrentVersion();
            if (this.currentVersion <= currentVersion)
                return;

            context.TotalSteps(this.currentVersion - currentVersion);
            await Task.Delay(500);

            await UpgradeOverrideAsync(context, currentVersion);

            ApplicationDataContainer migrationContainer = GetMigrationContainer();
            migrationContainer.Values["Version"] = this.currentVersion;
        }

        protected abstract Task UpgradeOverrideAsync(IUpgradeContext context, int currentVersion);

        private ApplicationDataContainer GetMigrationContainer()
        {
            ApplicationDataContainer root = storageContainerFactory.Create();

            ApplicationDataContainer migrationContainer;
            if (!root.Containers.TryGetValue("Migration", out migrationContainer))
                migrationContainer = root.CreateContainer("Migration", ApplicationDataCreateDisposition.Always);

            return migrationContainer;
        }

        private int GetCurrentVersion()
        {
            ApplicationDataContainer migrationContainer = GetMigrationContainer();
            int currentVersion = (int?)migrationContainer.Values["Version"] ?? 0;
            return currentVersion;
        }

    }
}
<commit_msg>#128 - Fix passing in current version.<commit_after>﻿using Neptuo;
using Neptuo.Activators;
using Neptuo.Migrations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;

namespace Money.Bootstrap
{
    internal abstract class UpgradeServiceBase : IUpgradeService
    {
        private readonly IFactory<ApplicationDataContainer> storageContainerFactory;
        private readonly int currentVersion;

        public UpgradeServiceBase(IFactory<ApplicationDataContainer> storageContainerFactory, int currentVersion)
        {
            Ensure.NotNull(storageContainerFactory, "storageContainerFactory");
            Ensure.Positive(currentVersion, "currentVersion");
            this.storageContainerFactory = storageContainerFactory;
            this.currentVersion = currentVersion;
        }

        public bool IsRequired()
        {
            return this.currentVersion > GetCurrentVersion();
        }

        public async Task UpgradeAsync(IUpgradeContext context)
        {
            int currentVersion = GetCurrentVersion();
            if (this.currentVersion <= currentVersion)
                return;

            context.TotalSteps(this.currentVersion - currentVersion);
            await Task.Delay(500);

            await UpgradeOverrideAsync(context, currentVersion);

            ApplicationDataContainer migrationContainer = GetMigrationContainer();
            migrationContainer.Values["Version"] = this.currentVersion;
        }

        protected abstract Task UpgradeOverrideAsync(IUpgradeContext context, int currentVersion);

        private ApplicationDataContainer GetMigrationContainer()
        {
            ApplicationDataContainer root = storageContainerFactory.Create();

            ApplicationDataContainer migrationContainer;
            if (!root.Containers.TryGetValue("Migration", out migrationContainer))
                migrationContainer = root.CreateContainer("Migration", ApplicationDataCreateDisposition.Always);

            return migrationContainer;
        }

        private int GetCurrentVersion()
        {
            ApplicationDataContainer migrationContainer = GetMigrationContainer();
            int currentVersion = (int?)migrationContainer.Values["Version"] ?? 0;
            return currentVersion;
        }

    }
}

{'fraction_non_alphanumeric': 0.06925749023013461, 'fraction_numerical': 0.0023881893182805037, 'mean_word_length': 2.9308873720136517, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5624735', 'n_tokens_mistral': 1016, 'n_tokens_neox': 1004, 'n_words': 225}