Exemplo n.º 1
0
        public static PsServiceControl FromInstance(ServiceControlInstance instance)
        {
            var result = new PsServiceControl
            {
                Name                 = instance.Name,
                Url                  = instance.Url,
                HostName             = instance.HostName,
                Port                 = instance.Port,
                InstallPath          = instance.InstallPath,
                LogPath              = instance.LogPath,
                DBPath               = instance.DBPath,
                TransportPackage     = instance.TransportPackage,
                ConnectionString     = instance.ConnectionString,
                AuditQueue           = instance.AuditQueue,
                AuditLogQueue        = instance.AuditLogQueue,
                ErrorQueue           = instance.ErrorQueue,
                ErrorLogQueue        = instance.ErrorLogQueue,
                ForwardAuditMessages = instance.ForwardAuditMessages,
                ServiceAccount       = instance.ServiceAccount,
                Version              = instance.Version,
                ForwardErrorMessages = instance.Version < SettingsList.ForwardErrorMessages.SupportedFrom || instance.ForwardErrorMessages
            };

            return(result);
        }
        protected override void ProcessRecord()
        {
            var psPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(UnattendFile, out _, out _);

            var details = ServiceControlNewInstance.Load(psPath);

            details.ServiceAccount    = ServiceAccount;
            details.ServiceAccountPwd = Password;
            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));
            }
        }
        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));
            }
        }
Exemplo n.º 4
0
        public static PsServiceControl FromInstance(ServiceControlInstance instance)
        {
            var result = new PsServiceControl
            {
                Name     = instance.Name,
                Url      = instance.Url,
                HostName = instance.HostName,
                Port     = instance.Port,
                DatabaseMaintenancePort = instance.DatabaseMaintenancePort,
                InstallPath             = instance.InstallPath,
                LogPath = instance.LogPath,
                DBPath  = instance.DBPath,
                TransportPackageName = instance.TransportPackage.Name,
                ConnectionString     = instance.ConnectionString,
                ErrorQueue           = instance.ErrorQueue,
                ErrorLogQueue        = instance.ErrorLogQueue,
                ServiceAccount       = instance.ServiceAccount,
                Version = instance.Version,
                //TODO: Do we need the version check here?
                ForwardErrorMessages = instance.Version < ServiceControlSettings.ForwardErrorMessages.SupportedFrom || instance.ForwardErrorMessages,
                AuditQueue           = instance.AuditQueue,
                AuditLogQueue        = instance.AuditLogQueue,
                ForwardAuditMessages = instance.ForwardAuditMessages,
                AuditRetentionPeriod = instance.AuditRetentionPeriod,
                ErrorRetentionPeriod = instance.ErrorRetentionPeriod,
                RemoteInstances      = instance.RemoteInstances.Select <RemoteInstanceSetting, object>(i =>
                {
                    if (string.IsNullOrEmpty(i.QueueAddress))
                    {
                        return(new { ApiUri = i.ApiUri });
                    }
                    return(new { ApiUri = i.ApiUri, QueueAddress = i.QueueAddress });
                }).ToArray()
            };

            return(result);
        }