Example #1
0
        public static void Main(string[] args)
        {
            IServiceCollection serviceCollection = new ServiceCollection();

            Bootstrapper.ConfigureServices(serviceCollection);

            var test          = serviceCollection.BuildServiceProvider();
            var loggerFactory = test.GetRequiredService <ILoggerFactory>();
            var logger        = loggerFactory.CreateLogger <Program>();

            Migrator migrator;

            switch (args[0])
            {
            case "upgrade":
                var database   = new Database(args[1], args[2], args[3], args[4]);
                var dbfolder   = new DBFolder();
                var validator  = new Validator();
                var dbVersions = database.GetDBState();
                validator.ValidateVersions(dbfolder.allVersions, dbVersions);
                var differ   = new VersionDiff();
                var diff     = differ.Diff(dbfolder.GetVersionsUpTo(args[5]), dbVersions);
                var diffText = differ.DiffText(diff);
                logger.LogInformation(diffText);
                System.Console.ReadKey();
                migrator = new Migrator(database, dbfolder);
                migrator.Upgrade(diff);
                System.Console.ReadKey();
                break;

            case "rollback":
                var database1   = new Database(args[2], args[3], args[4], args[5]);
                var dbVersions1 = database1.GetDBState();
                var dbfolder1   = new DBFolder();
                var validator1  = new Validator();
                validator1.ValidateVersions(dbfolder1.allVersions, dbVersions1);
                var differ1 = new VersionDiff();
                var diff1   = differ1.Diff(dbVersions1, dbfolder1.GetVersionsUpTo(args[1]));
                dbfolder1.AddRollbacks(diff1);
                var diffText1 = differ1.DiffText(diff1);
                logger.LogInformation(diffText1);
                System.Console.ReadKey();
                migrator = new Migrator(database1, dbfolder1);
                migrator.Rollback(diff1);
                System.Console.ReadKey();
                break;

            case "validate":
                var database2   = new Database(args[1], args[2], args[3], args[4]);
                var dbVersions2 = database2.GetDBState();
                var dbfolder2   = new DBFolder();
                var validator2  = new Validator();
                validator2.ValidateVersions(dbfolder2.allVersions, dbVersions2);
                System.Console.ReadKey();
                break;

            default:
                break;
            }
        }
Example #2
0
        public void No_diff_test()
        {
            var differ = new VersionDiff();

            var diff = differ.Diff(Folder(), Database());

            Assert.AreEqual(0, diff.Count);
        }
        public void Test()
        {
            var versionDiff = new VersionDiff();

            var actualDiff   = versionDiff.Diff(Folder(), Database());
            var expectedDiff = ExpectedDiff();

            CollectionAssert.AreEqual(expectedDiff, actualDiff, new DBVersionComparer());
        }
Example #4
0
        public void Load_Folder_Test()
        {
            var path     = Path.Combine(Path.GetDirectoryName(typeof(Validator).GetTypeInfo().Assembly.Location), "TestDBFolderStructure");
            var dbFolder = new DBFolder(path);

            var differ = new VersionDiff();

            var diff = differ.Diff(dbFolder.allVersions, Folder());

            Assert.AreEqual(0, diff.Count);
        }
        public void Diff_found_test()
        {
            var differ = new VersionDiff();

            var diff = differ.Diff(Folder(), Database());

            Assert.AreEqual(1, diff.Count);
            Assert.AreEqual(ExpectedDiff().First().Name, diff.First().Name);

            Assert.AreEqual(1, diff.First().Features.Count);
            Assert.AreEqual(ExpectedDiff().First().Features.First().Name, diff.First().Features.First().Name);

            Assert.AreEqual(1, diff.First().Features.First().UpgradeScripts.Count);
            Assert.AreEqual(ExpectedDiff().First().Features.First().Name, diff.First().Features.First().Name);
        }
        /// <summary>
        ///     Executes the comparison
        /// </summary>
        public override void ExecuteWork()
        {
            Dictionary otherVersion = DictionaryByVersion(Commit);

            // Compare the two dictionaries and mark the differences
            if (otherVersion != null)
            {
                VersionDiff versionDiff = new VersionDiff();
                Comparer.ensureGuidDictionary(Dictionary, otherVersion);
                Comparer.compareDictionary(Dictionary, otherVersion, versionDiff);
                versionDiff.MarkVersionChanges(Dictionary);
            }
            else
            {
                MessageBox.Show("Cannot open file, please see log file (GUI.Log) for more information",
                                "Cannot open file", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #7
0
        /// <summary>
        ///     Compares the files
        /// </summary>
        public override void ExecuteWork()
        {
            // Open the dictionary but do not store it in the EFS System
            const bool        allowErrors       = true;
            OpenFileOperation openFileOperation = new OpenFileOperation(OtherFilePath, null, allowErrors, false);

            openFileOperation.ExecuteWork();

            // Compare the files
            if (openFileOperation.Dictionary != null)
            {
                VersionDiff versionDiff = new VersionDiff();
                Comparer.ensureGuidDictionary(Dictionary, openFileOperation.Dictionary);
                Comparer.compareDictionary(Dictionary, openFileOperation.Dictionary, versionDiff);
                versionDiff.MarkVersionChanges(Dictionary);
            }
            else
            {
                MessageBox.Show("Cannot open file, please see log file (GUI.Log) for more information",
                                "Cannot open file", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        ///     Performs the job as a background task
        /// </summary>
        public override void ExecuteWork()
        {
            // Retrieve the hash tag
            if (LastCommit != null)
            {
                Repository repository = GetRepository();

                string dictionaryDirectory = Path.GetDirectoryName(Dictionary.FilePath);
                if (dictionaryDirectory != null)
                {
                    dictionaryDirectory = dictionaryDirectory.Substring(RepositoryPath.Length + 1,
                                                                        dictionaryDirectory.Length - RepositoryPath.Length - 1);

                    History history = Dictionary.EFSSystem.History;
                    if (history.Commit(LastCommit.Sha) == null)
                    {
                        // Processes all commits until the one that has been selected
                        Dictionary currentVersion  = Dictionary;
                        Dictionary previousVersion = null;
                        Commit     previousCommit  = null;
                        Commit     commitToRefer   = null;
                        foreach (Commit commit in repository.Commits)
                        {
                            // Always compare the current version with the first commit in the repository
                            // since changes may have been applied to the current version
                            if (previousVersion == null || !history.CommitExists(commit.Sha))
                            {
                                if (previousCommit == null)
                                {
                                    if (previousVersion != Dictionary && currentVersion != previousVersion)
                                    {
                                        CleanUpDictionary(previousVersion);
                                    }
                                    previousVersion = currentVersion;
                                }
                                else
                                {
                                    previousVersion = DictionaryByVersion(previousCommit);
                                    Comparer.ensureGuidDictionary(previousVersion, currentVersion);
                                }

                                bool changesAvailable = true;
                                if (commitToRefer != null)
                                {
                                    changesAvailable = false;
                                    TreeChanges changes = repository.Diff.Compare(commit.Tree, commitToRefer.Tree);
                                    foreach (TreeEntryChanges entry in changes.Modified)
                                    {
                                        if (entry.Path.StartsWith(dictionaryDirectory))
                                        {
                                            changesAvailable = true;
                                            break;
                                        }
                                    }
                                }

                                if (changesAvailable)
                                {
                                    if (commitToRefer != null)
                                    {
                                        string message = commitToRefer.Message.Trim();
                                        if (message.Length > 132)
                                        {
                                            message = message.Substring(0, 132) + "...";
                                        }
                                        Dialog.UpdateMessage("Processing " + message + " (" + commitToRefer.Sha + ")");
                                    }
                                    else
                                    {
                                        Dialog.UpdateMessage("Processing current version...");
                                    }

                                    currentVersion = DictionaryByVersion(commit);

                                    if (currentVersion != null)
                                    {
                                        VersionDiff versionDiff = new VersionDiff();
                                        if (commitToRefer != null)
                                        {
                                            versionDiff.setCommitter(commitToRefer.Author.Name);
                                            versionDiff.setDate(commitToRefer.Author.When.ToString());
                                            versionDiff.setHash(commitToRefer.Sha);
                                            versionDiff.setMessage(commitToRefer.Message);
                                        }

                                        Comparer.ensureGuidDictionary(previousVersion, currentVersion);
                                        Comparer.compareDictionary(previousVersion, currentVersion, versionDiff);
                                        history.AppendOrReplaceCommit(versionDiff);
                                        history.save();
                                    }
                                    else
                                    {
                                        DialogResult result =
                                            MessageBox.Show(
                                                "Cannot open file for commit\n" + commit.MessageShort + " (" + commit.Sha +
                                                ")\nplease see log file (GUI.Log) for more information.\nPress OK to continue.",
                                                "Cannot open file", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                                        if (result == DialogResult.OK)
                                        {
                                            // Stick back to the previous version to continue the process
                                            currentVersion = previousVersion;
                                        }
                                        else
                                        {
                                            // Stop the process
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    currentVersion = previousVersion;
                                }

                                previousCommit = null;
                            }
                            else
                            {
                                previousCommit = commit;
                            }

                            if (commit == LastCommit)
                            {
                                break;
                            }

                            commitToRefer = commit;
                        }
                    }
                    history.UpdateBlame();
                }
            }
        }