public void CreateInstanceMSMQ()
        {
            var installer    = new UnattendInstaller(new TestLogger(), deploymentCache);
            var instanceName = "Test.ServiceControl.Msmq";
            var root         = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"Test", instanceName);
            var details      = new ServiceControlInstanceMetadata
            {
                DisplayName          = instanceName.Replace(".", " "),
                Name                 = instanceName,
                ServiceDescription   = "Test SC Instance",
                DBPath               = Path.Combine(root, "Database"),
                LogPath              = Path.Combine(root, "Logs"),
                InstallPath          = Path.Combine(root, "Binaries"),
                HostName             = "localhost",
                Port                 = 33335,
                VirtualDirectory     = null,
                AuditLogQueue        = "audit.log",
                AuditQueue           = "audit",
                ForwardAuditMessages = false,
                ErrorQueue           = "error",
                ErrorLogQueue        = "error.log",
                TransportPackage     = "MSMQ",
                ReportCard           = new ReportCard()
            };

            details.Validate(s => false);
            if (details.ReportCard.HasErrors)
            {
                throw new Exception($"Validation errors:  {string.Join("\r\n", details.ReportCard.Errors)}");
            }
            Assert.DoesNotThrow(() => installer.Add(details, s => false));
        }
        protected override void ProcessRecord()
        {
            ProviderInfo provider;
            PSDriveInfo  drive;
            var          psPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(UnattendFile, out provider, out drive);

            var details = ServiceControlInstanceMetadata.Load(psPath);

            details.ServiceAccount    = ServiceAccount;
            details.ServiceAccountPwd = Password;
            var zipfolder = Path.GetDirectoryName(MyInvocation.MyCommand.Module.Path);
            var logger    = new PSLogger(Host);
            var installer = new UnattendInstaller(logger, zipfolder);

            try
            {
                logger.Info("Installing Service Control instance...");
                if (installer.Add(details, PromptToProceed))
                {
                    var instance = ServiceControlInstance.FindByName(details.Name);
                    if (instance != null)
                    {
                        WriteObject(PsServiceControl.FromInstance(instance));
                    }
                    else
                    {
                        throw new Exception("Unknown error creating instance");
                    }
                }
            }
            catch (Exception ex)
            {
                ThrowTerminatingError(new ErrorRecord(ex, null, ErrorCategory.NotSpecified, null));
            }
        }
Beispiel #3
0
        protected override void ProcessRecord()
        {
            var details = new ServiceControlInstanceMetadata
            {
                InstallPath          = InstallPath,
                LogPath              = LogPath,
                DBPath               = DBPath,
                Name                 = Name,
                DisplayName          = string.IsNullOrWhiteSpace(DisplayName) ? Name : DisplayName,
                ServiceDescription   = Description,
                ServiceAccount       = ServiceAccount,
                ServiceAccountPwd    = ServiceAccountPassword,
                HostName             = HostName,
                Port                 = Port,
                VirtualDirectory     = VirtualDirectory,
                AuditQueue           = AuditQueue,
                ErrorQueue           = ErrorQueue,
                AuditLogQueue        = string.IsNullOrWhiteSpace(AuditLogQueue) ? null : AuditLogQueue,
                ErrorLogQueue        = string.IsNullOrWhiteSpace(ErrorLogQueue) ? null : ErrorLogQueue,
                ForwardAuditMessages = ForwardAuditMessages.ToBool(),
                ForwardErrorMessages = ForwardErrorMessages.ToBool(),
                AuditRetentionPeriod = AuditRetentionPeriod,
                ErrorRetentionPeriod = ErrorRetentionPeriod,
                ConnectionString     = ConnectionString,
                TransportPackage     = Transport
            };

            var zipfolder = Path.GetDirectoryName(MyInvocation.MyCommand.Module.Path);
            var logger    = new PSLogger(Host);

            var installer = new UnattendInstaller(logger, zipfolder);

            try
            {
                logger.Info("Installing Service Control instance...");
                if (installer.Add(details, PromptToProceed))
                {
                    var instance = ServiceControlInstance.FindByName(details.Name);
                    if (instance != null)
                    {
                        WriteObject(PsServiceControl.FromInstance(instance));
                    }
                    else
                    {
                        throw new Exception("Unknown error creating instance");
                    }
                }
            }
            catch (Exception ex)
            {
                ThrowTerminatingError(new ErrorRecord(ex, null, ErrorCategory.NotSpecified, null));
            }
        }
        static void UnattendedInstall(Session session, MSILogger logger, UnattendInstaller unattendedInstaller)
        {
            logger.Info("Checking for unattended file");

            var unattendedFilePropertyValue = session["UNATTENDEDFILE"];

            if (string.IsNullOrWhiteSpace(unattendedFilePropertyValue))
            {
                return;
            }

            var serviceAccount = session["SERVICEACCOUNT"];
            var password       = session["PASSWORD"];

            logger.Info($"UNATTENDEDFILE: {unattendedFilePropertyValue}");
            var currentDirectory   = session["CURRENTDIRECTORY"];
            var unattendedFilePath = Environment.ExpandEnvironmentVariables(Path.IsPathRooted(unattendedFilePropertyValue) ? unattendedFilePropertyValue : Path.Combine(currentDirectory, unattendedFilePropertyValue));

            logger.Info($"Expanded unattended filepath to : {unattendedFilePropertyValue}");

            if (File.Exists(unattendedFilePath))
            {
                logger.Info($"File Exists : {unattendedFilePropertyValue}");
                var instanceToInstallDetails = ServiceControlInstanceMetadata.Load(unattendedFilePath);

                if (!string.IsNullOrWhiteSpace(serviceAccount))
                {
                    instanceToInstallDetails.ServiceAccount    = serviceAccount;
                    instanceToInstallDetails.ServiceAccountPwd = password;
                }
                unattendedInstaller.Add(instanceToInstallDetails, s => false);
            }
            else
            {
                logger.Error($"The specified unattended install file was not found : '{unattendedFilePath}'");
            }
        }