コード例 #1
0
        protected override void ProcessRecord()
        {
            var details = new ServiceControlNewInstance
            {
                InstallPath             = InstallPath,
                LogPath                 = LogPath,
                DBPath                  = DBPath,
                Name                    = Name,
                DisplayName             = string.IsNullOrWhiteSpace(DisplayName) ? Name : DisplayName,
                ServiceDescription      = Description,
                ServiceAccount          = ServiceAccount,
                ServiceAccountPwd       = ServiceAccountPassword,
                HostName                = HostName,
                Port                    = Port,
                DatabaseMaintenancePort = DatabaseMaintenancePort,
                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        = ServiceControlCoreTransports.All.First(t => t.Matches(Transport)),
                SkipQueueCreation       = SkipQueueCreation
            };

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

            var installer = new UnattendServiceControlInstaller(logger, zipfolder);

            try
            {
                logger.Info("Installing Service Control instance...");
                if (installer.Add(details, PromptToProceed))
                {
                    var instance = InstanceFinder.FindServiceControlInstance(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));
            }
        }
コード例 #2
0
        protected override void BeginProcessing()
        {
            if (string.IsNullOrWhiteSpace(HostName))
            {
                WriteWarning("HostName set to default value 'localhost'");
                HostName = "localhost";
            }

            if (string.IsNullOrWhiteSpace(AuditQueue))
            {
                WriteWarning("AuditQueue set to default value 'audit'");
                AuditQueue = "audit";
            }

            if (string.IsNullOrWhiteSpace(ErrorQueue))
            {
                WriteWarning("ErrorQueue set to default value 'error'");
                ErrorQueue = "error";
            }

            if (string.IsNullOrWhiteSpace(ServiceAccount))
            {
                WriteWarning("ServiceAccount set to default value 'LocalSystem'");
                ServiceAccount = "LocalSystem";
            }

            if (ForwardAuditMessages.ToBool() & string.IsNullOrWhiteSpace(AuditLogQueue))
            {
                WriteWarning("AuditLogQueue set to default value 'audit.log'");
                ErrorLogQueue = "audit.log";
            }

            if (ForwardErrorMessages.ToBool() & string.IsNullOrWhiteSpace(ErrorLogQueue))
            {
                WriteWarning("ErrorLogQueue set to default value 'error.log'");
                ErrorLogQueue = "error.log";
            }
        }