<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using IonFar.SharePoint.Migration.Infrastructure;
using Microsoft.SharePoint.Client;
using Newtonsoft.Json;

namespace IonFar.SharePoint.Migration
{
    public class Migrator : IMigrator
    {
        private readonly ClientContext _clientContext;
        private readonly ILogger _logger;

        public Migrator(ClientContext clientContext, ILogger logger)
        {
            _clientContext = clientContext;
            _logger = logger;
        }

        /// <summary>
        /// Migrates all IMigrations within the given assembly.
        /// </summary>
        /// <param name="assemblyContainingMigrations">The assembly containing the migrations to run.</param>
        /// <remarks>Migrations must be decorated with a <see cref="MigrationAttribute"/></remarks>
        public void Migrate(Assembly assemblyContainingMigrations)
        {
            Migrate(assemblyContainingMigrations, name => true);
        }

        /// <summary>
        /// Migrates all IMigrations within the given assembly matching the given filter given the Type.FullName.
        /// </summary>
        /// <param name="assemblyContainingMigrations">The assembly containing the migrations to run.</param>
        /// <param name="filter">A function that accepts a Type.FullName and returns true if the given type is to be migrated, otherwise false.</param>
        /// <remarks>Migrations must be decorated with a <see cref="MigrationAttribute"/></remarks>
        public void Migrate(Assembly assemblyContainingMigrations, Func<string, bool> filter)
        {
            try
            {
                LogInfo("Starting upgrade against SharePoint instance at " + _clientContext.Url);
                var availableMigrations = GetAvailableMigrations(assemblyContainingMigrations, filter);
                var appliedMigrations = GetAppliedMigrations();<commit_msg>Write migrator version to log<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using IonFar.SharePoint.Migration.Infrastructure;
using Microsoft.SharePoint.Client;
using Newtonsoft.Json;
using System.Diagnostics;

namespace IonFar.SharePoint.Migration
{
    public class Migrator : IMigrator
    {
        private readonly ClientContext _clientContext;
        private readonly ILogger _logger;

        public Migrator(ClientContext clientContext, ILogger logger)
        {
            _clientContext = clientContext;
            _logger = logger;
        }

        /// <summary>
        /// Migrates all IMigrations within the given assembly.
        /// </summary>
        /// <param name="assemblyContainingMigrations">The assembly containing the migrations to run.</param>
        /// <remarks>Migrations must be decorated with a <see cref="MigrationAttribute"/></remarks>
        public void Migrate(Assembly assemblyContainingMigrations)
        {
            Migrate(assemblyContainingMigrations, name => true);
        }

        /// <summary>
        /// Migrates all IMigrations within the given assembly matching the given filter given the Type.FullName.
        /// </summary>
        /// <param name="assemblyContainingMigrations">The assembly containing the migrations to run.</param>
        /// <param name="filter">A function that accepts a Type.FullName and returns true if the given type is to be migrated, otherwise false.</param>
        /// <remarks>Migrations must be decorated with a <see cref="MigrationAttribute"/></remarks>
        public void Migrate(Assembly assemblyContainingMigrations, Func<string, bool> filter)
        {
            try
            {
                var assembly = Assembly.GetExecutingAssembly();
                var fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
                _logger.Information("IonFar.SharePoint.Migrator v" + fvi.FileVersion);

                LogInfo("Starting upgrade against SharePoint instance at " + _clientContext.Url);
                var availableMigrations = GetAvailableMigrations(assemblyContainingMigrations, filter);
                var appliedMigrations = GetAppliedMigrations();
{'fraction_non_alphanumeric': 0.08537455410225922, 'fraction_numerical': 0.0, 'mean_word_length': 2.7755834829443446, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 39, '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': '2391235', 'n_tokens_mistral': 1037, 'n_tokens_neox': 1028, 'n_words': 300}