Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            Printf("Welcome!");

            Repository repository;
            FileManager fileManager = new FileManager();

            try
            {
                repository = new Repository(RepositoryPath);
            }
            catch (RepositoryNotFoundException)
            {
                Printf("Repository path is not correct");
                Logger.Instance.Log(string.Format("Repository path is not correct: {0}", RepositoryPath));
                repository = null;
            }

            if (repository != null)
            {
                StartDeploying(repository, fileManager);
            }
            else
            {
                Printf("Generating Zip");
                fileManager.GenerateZip(ZipFilePath, TmpPath, null, null, "UNK", "UNK");
            }

            Printf("End");
            Console.In.ReadLine();
        }
Exemplo n.º 2
0
        private static void StartDeploying(Repository repository, FileManager fileManager)
        {
            Commit commitOlder = null;
            Commit commitNewer = null;
            string olderVersion = "UNK";
            string newerVersion = "UNK";

            bool wrongInput = true;
            while (wrongInput)
            {
                Console.Out.Write("Older version: ");
                olderVersion = Console.In.ReadLine();
                Console.Out.Write("Newer version: ");
                newerVersion = Console.In.ReadLine();

                Tag tagOlder = repository.Tags.FirstOrDefault(x => x.Name == olderVersion);
                Tag tagNewer = repository.Tags.FirstOrDefault(x => x.Name == newerVersion);

                if (tagOlder == null || tagNewer == null)
                {
                    if (tagOlder == null)
                    {
                        Printf("Invalid older tag");
                    }
                    if (tagNewer == null)
                    {
                        Printf("Invalid newer tag");
                    }
                }
                else
                {
                    commitOlder = tagOlder.Target as Commit;
                    commitNewer = tagNewer.Target as Commit;

                    if (commitOlder == null || commitNewer == null)
                    {
                        if (commitOlder == null)
                        {
                            Printf("Older tag does not point to commit");
                        }
                        if (commitNewer == null)
                        {
                            Printf("Newer tag does not point to commit");
                        }
                    }
                    else
                    {
                        if (commitOlder.Author.When >= commitNewer.Author.When)
                        {
                            Printf("Wrong timing");
                        }
                        else
                        {
                            wrongInput = false;
                        }
                    }
                }
            }

            TreeChanges changes = repository.Diff.Compare<TreeChanges>(commitOlder.Tree, commitNewer.Tree);

            PrintChanges(changes);
            LogChanges(changes);

            List<TreeEntryChanges> filesToBeBackedUp = new List<TreeEntryChanges>();
            filesToBeBackedUp.AddRange(changes.Modified);
            filesToBeBackedUp.AddRange(changes.Deleted);
            filesToBeBackedUp.AddRange(changes.Renamed);

            List<TreeEntryChanges> filesToBeDeployed = new List<TreeEntryChanges>();
            filesToBeDeployed.AddRange(changes.Added);
            filesToBeDeployed.AddRange(changes.Modified);
            filesToBeDeployed.AddRange(changes.Renamed);

            string backUpPath = string.Format("{0}{1}", TmpPath, "backup\\");
            string deployPath = string.Format("{0}{1}", TmpPath, "deploy\\");
            fileManager.CreateTmpFolder(TmpPath);

            BundleCreationResult backupResult;
            BundleCreationResult deployResult;
            BundleCreationResult rollBackResult;
            BundleCreationResult deployPackResult;

            Printf("Creating backup");
            backupResult = fileManager.CreateBackUp(ServerPath, backUpPath, filesToBeBackedUp);
            PrintResult("Creating backup", backupResult);

            if (backupResult == BundleCreationResult.Succes)
            {
                Printf("Creating deploy pack");
                deployPackResult = fileManager.CreateDeployPack(BaseRepositoryPath, deployPath, filesToBeDeployed);
                PrintResult("Creating deploy pack", deployPackResult);

                if (deployPackResult == BundleCreationResult.Succes)
                {
                    Printf("Deploying files");
                    deployResult = fileManager.DeployFiles(deployPath, ServerPath, changes, BaseRepositoryPath);
                    PrintResult("Deploying files", deployResult);

                    if (deployResult == BundleCreationResult.Fail)
                    {
                        Printf("Rolling back");
                        rollBackResult = fileManager.RollBack(backUpPath, ServerPath, changes);
                        PrintResult("Rolling back", rollBackResult);
                    }
                }
            }

            Printf("Generating Zip");
            fileManager.GenerateZip(ZipFilePath, TmpPath, filesToBeBackedUp, filesToBeDeployed, olderVersion.Replace(".", "_"), newerVersion.Replace(".", "_"));

            fileManager.DeleteTmpFolder(TmpPath);
            repository.Dispose();
        }