public void Pass_New_AllArguments()
        {
            // Setup
            var workingFolder      = Fakes.RandomString();
            var deploymentFilePath = Fakes.RandomString();
            var serverInstance     = Fakes.RandomString();
            var catalog            = Fakes.RandomString();
            var folder             = Fakes.RandomString();
            var projectName        = Fakes.RandomString();
            var projectPassword    = Fakes.RandomString();
            var eraseSensitiveInfo = Fakes.RandomBool();


            // Execute
            var deployArguments = new DeployArguments(workingFolder, deploymentFilePath, serverInstance, catalog, folder, projectName, projectPassword, eraseSensitiveInfo);

            // Assert
            Assert.Equal(workingFolder, deployArguments.WorkingFolder);
            Assert.Equal(deploymentFilePath, deployArguments.DeploymentFilePath);
            Assert.Equal(serverInstance, deployArguments.ServerInstance);
            Assert.Equal(catalog, deployArguments.Catalog);
            Assert.Equal(folder, deployArguments.Folder);
            Assert.Equal(projectName, deployArguments.ProjectName);
            Assert.Equal(projectPassword, deployArguments.ProjectPassword);
            Assert.Equal(eraseSensitiveInfo, deployArguments.EraseSensitiveInfo);
        }
Exemple #2
0
        private static void InitializeGeneratedApplication(ILogger logger, DeployArguments arguments)
        {
            // Creating a new container builder instead of using builder.Update, because of severe performance issues with the Update method.
            Plugins.ClearCache();

            logger.Trace("Loading generated plugins.");
            var stopwatch = Stopwatch.StartNew();

            var builder = new ContainerBuilder();
            builder.RegisterModule(new AutofacModuleConfiguration(
                deploymentTime: false,
                configurationArguments: arguments));

            using (var container = builder.Build())
            {
                var performanceLogger = container.Resolve<ILogProvider>().GetLogger("Performance");
                var initializers = ApplicationInitialization.GetSortedInitializers(container);

                performanceLogger.Write(stopwatch, "DeployPackages.Program: New modules and plugins registered.");
                Plugins.LogRegistrationStatistics("Initializing application", container);

                if (!initializers.Any())
                {
                    logger.Trace("No server initialization plugins.");
                } else
                {
                    foreach (var initializer in initializers)
                        ApplicationInitialization.ExecuteInitializer(container, initializer);
                }
            }

            RestartWebServer(logger);
        }
Exemple #3
0
        private static void GenerateApplication(ILogger logger, DeployArguments arguments)
        {
            logger.Trace("Loading plugins.");
            var stopwatch = Stopwatch.StartNew();

            var builder = new ContainerBuilder();

            builder.RegisterModule(new AutofacModuleConfiguration(
                                       deploymentTime: true,
                                       configurationArguments: arguments));

            using (var container = builder.Build())
            {
                var performanceLogger = container.Resolve <ILogProvider>().GetLogger("Performance");
                performanceLogger.Write(stopwatch, "DeployPackages.Program: Modules and plugins registered.");
                Plugins.LogRegistrationStatistics("Generating application", container);

                if (arguments.Debug)
                {
                    container.Resolve <DomGeneratorOptions>().Debug = true;
                }

                container.Resolve <ApplicationGenerator>().ExecuteGenerators(arguments.DeployDatabaseOnly);
            }
        }
        public void Publish(string WorkingFolder)
        {
            var deployArguments = new DeployArguments(
                WorkingFolder,
                string.IsNullOrWhiteSpace(DeploymentFilePath) ? null : DeploymentFilePath,
                string.IsNullOrWhiteSpace(ServerInstance) ? null : ServerInstance,
                string.IsNullOrWhiteSpace(Catalog) ? null : Catalog,
                string.IsNullOrWhiteSpace(Folder) ? null : Folder,
                string.IsNullOrWhiteSpace(ProjectName) ? null : ProjectName,
                string.IsNullOrWhiteSpace(ProjectPassword) ? null : ProjectPassword,
                EraseSensitiveInfo,
                string.IsNullOrWhiteSpace(ServerInstanceUserID) ? null : ServerInstanceUserID,
                string.IsNullOrWhiteSpace(ServerInstancePassword) ? null : ServerInstancePassword
                );

            _deployer = _deployer ?? new Deployer();

            try
            {
                _deployer.Deploy(deployArguments);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
        }
Exemple #5
0
        private static void InitialCleanup(ILogger logger, DeployArguments arguments)
        {
            // Warning to backup obsolete folders:

            var obsoleteFolders = new string[]
            {
                Path.Combine(Paths.RhetosServerRootPath, "DslScripts"),
                Path.Combine(Paths.RhetosServerRootPath, "DataMigration")
            };
            var obsoleteFolder = obsoleteFolders.FirstOrDefault(folder => Directory.Exists(folder));

            if (obsoleteFolder != null)
            {
                throw new UserException("Please backup all Rhetos server folders and delete obsolete folder '" + obsoleteFolder + "'. It is no longer used.");
            }

            // Delete obsolete generated files:

            var deleteObsoleteFiles = new string[]
            {
                Path.Combine(Paths.BinFolder, "ServerDom.cs"),
                Path.Combine(Paths.BinFolder, "ServerDom.dll"),
                Path.Combine(Paths.BinFolder, "ServerDom.pdb")
            };
            var filesUtility = new FilesUtility(DeploymentUtility.InitializationLogProvider);

            foreach (var path in deleteObsoleteFiles)
            {
                if (File.Exists(path))
                {
                    logger.Info($"Deleting obsolete file '{path}'.");
                    filesUtility.SafeDeleteFile(path);
                }
            }

            // Backup and delete generated files:

            if (!arguments.DeployDatabaseOnly)
            {
                logger.Trace("Moving old generated files to cache.");
                new GeneratedFilesCache(DeploymentUtility.InitializationLogProvider).MoveGeneratedFilesToCache();
                filesUtility.SafeCreateDirectory(Paths.GeneratedFolder);
            }
            else
            {
                var missingFile = Paths.DomAssemblyFiles.FirstOrDefault(f => !File.Exists(f));
                if (missingFile != null)
                {
                    throw new UserException($"'/DatabaseOnly' switch cannot be used if the server have not been deployed successfully before. Run a regular deployment instead. Missing '{missingFile}'.");
                }

                logger.Info("Skipped deleting old generated files (DeployDatabaseOnly).");
            }
        }
 public KeepSynchronizedRecomputeOnDeploy(
     GenericRepositories genericRepositories,
     ILogProvider logProvider,
     CurrentKeepSynchronizedMetadata currentKeepSynchronizedMetadata,
     DeployArguments deployArguments)
 {
     _genericRepositories = genericRepositories;
     _performanceLogger   = logProvider.GetLogger("Performance");
     _logger = logProvider.GetLogger("KeepSynchronizedRecomputeOnDeploy");
     _currentKeepSynchronizedMetadata = currentKeepSynchronizedMetadata;
     _deployArguments = deployArguments;
 }
Exemple #7
0
        private static void DownloadPackages(ILogger logger, DeployArguments arguments)
        {
            if (!arguments.DeployDatabaseOnly)
            {
                logger.Trace("Getting packages.");
                var config = new DeploymentConfiguration(DeploymentUtility.InitializationLogProvider);
                var packageDownloaderOptions = new PackageDownloaderOptions { IgnorePackageDependencies = arguments.IgnorePackageDependencies };
                var packageDownloader = new PackageDownloader(config, DeploymentUtility.InitializationLogProvider, packageDownloaderOptions);
                var packages = packageDownloader.GetPackages();

                InstalledPackages.Save(packages);
            }
            else
                logger.Info("Skipped download packages (DeployDatabaseOnly).");
        }
 public AutofacModuleConfiguration(bool deploymentTime, DeployArguments configurationArguments)
 {
     _deploymentTime         = deploymentTime;
     _configurationArguments = configurationArguments;
 }
Exemple #9
0
        public static int Main(string[] args)
        {
            ILogger logger = new ConsoleLogger("DeployPackages"); // Using the simplest logger outside of try-catch block.
            string oldCurrentDirectory = null;
            DeployArguments arguments = null;

            try
            {
                logger = DeploymentUtility.InitializationLogProvider.GetLogger("DeployPackages"); // Setting the final log provider inside the try-catch block, so that the simple ConsoleLogger can be used (see above) in case of an initialization error.

                arguments = new DeployArguments(args);
                if (arguments.Help)
                    return 1;

                if (arguments.StartPaused)
                {
                    if (!Environment.UserInteractive)
                        throw new Rhetos.UserException("DeployPackages parameter 'StartPaused' must not be set, because the application is executed in a non-interactive environment.");

                    // Use for debugging (Attach to Process)
                    Console.WriteLine("Press any key to continue . . .");
                    Console.ReadKey(true);
                }

                Paths.InitializeRhetosServerRootPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ".."));

                oldCurrentDirectory = Directory.GetCurrentDirectory();
                Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

                InitialCleanup(logger, arguments);
                DownloadPackages(logger, arguments);
                GenerateApplication(logger, arguments);
                InitializeGeneratedApplication(logger, arguments);
                logger.Trace("Done.");
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());

                string typeLoadReport = CsUtility.ReportTypeLoadException(ex);
                if (typeLoadReport != null)
                    logger.Error(typeLoadReport);

                if (Environment.UserInteractive)
                {
                    PrintSummary(ex);
                    if (arguments != null && !arguments.NoPauseOnError)
                    {
                        Console.WriteLine("Press any key to continue . . .  (use /NoPause switch to avoid pause on error)");
                        Console.ReadKey(true);
                    }
                }

                return 1;
            }
            finally
            {
                if (oldCurrentDirectory != null && Directory.Exists(oldCurrentDirectory))
                    Directory.SetCurrentDirectory(oldCurrentDirectory);
            }

            return 0;
        }