private async Task Add(object arg)
        {
            viewModel.SubmitAttempted = true;
            if (!viewModel.ValidationTemplate.Validate())
            {
                viewModel.NotifyOfPropertyChange(string.Empty);
                viewModel.SubmitAttempted = false;
                windowManager.ScrollFirstErrorIntoView(viewModel);

                return;
            }

            viewModel.InProgress = true;

            var instanceMetadata = new MonitoringNewInstance
            {
                DisplayName        = viewModel.InstanceName,
                Name               = viewModel.InstanceName.Replace(' ', '.'),
                ServiceDescription = viewModel.Description,
                InstallPath        = viewModel.DestinationPath,
                LogPath            = viewModel.LogPath,
                HostName           = viewModel.HostName,
                Port               = Convert.ToInt32(viewModel.PortNumber),
                ErrorQueue         = viewModel.ErrorQueueName,
                TransportPackage   = viewModel.SelectedTransport.Name,
                ConnectionString   = viewModel.ConnectionString,
                ServiceAccount     = viewModel.ServiceAccount,
                ServiceAccountPwd  = viewModel.Password
            };

            using (var progress = viewModel.GetProgressObject("ADDING INSTANCE"))
            {
                var reportCard = await Task.Run(() => installer.Add(instanceMetadata, progress, PromptToProceed));

                if (reportCard.HasErrors || reportCard.HasWarnings)
                {
                    windowManager.ShowActionReport(reportCard, "ISSUES ADDING INSTANCE", "Could not add new instance because of the following errors:", "There were some warnings while adding the instance:");
                    return;
                }

                if (reportCard.CancelRequested)
                {
                    return;
                }
            }

            viewModel.TryClose(true);

            eventAggregator.PublishOnUIThread(new RefreshInstances());
        }
        protected override void ProcessRecord()
        {
            var details = new MonitoringNewInstance
            {
                InstallPath        = InstallPath,
                LogPath            = LogPath,
                Name               = Name,
                DisplayName        = string.IsNullOrWhiteSpace(DisplayName) ? Name : DisplayName,
                ServiceDescription = Description,
                ServiceAccount     = ServiceAccount,
                ServiceAccountPwd  = ServiceAccountPassword,
                HostName           = HostName,
                Port               = Port,
                ErrorQueue         = ErrorQueue,
                ConnectionString   = ConnectionString,
                TransportPackage   = MonitoringTransports.All.First(t => t.Matches(Transport)),
                SkipQueueCreation  = SkipQueueCreation
            };

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

            var installer = new UnattendMonitoringInstaller(logger, zipfolder);

            try
            {
                logger.Info("Installing Monitoring instance...");
                if (installer.Add(details, PromptToProceed))
                {
                    var instance = InstanceFinder.FindMonitoringInstance(details.Name);
                    if (instance != null)
                    {
                        WriteObject(PsMonitoringService.FromInstance(instance));
                    }
                    else
                    {
                        throw new Exception("Unknown error creating instance");
                    }
                }
            }
            catch (Exception ex)
            {
                ThrowTerminatingError(new ErrorRecord(ex, null, ErrorCategory.NotSpecified, null));
            }
        }
Exemplo n.º 3
0
        internal ReportCard Add(MonitoringNewInstance details, IProgress <ProgressDetails> progress, Func <PathInfo, bool> promptToProceed)
        {
            ZipInfo.ValidateZip();

            var instanceInstaller = details;

            instanceInstaller.ReportCard = new ReportCard();

            //Validation
            instanceInstaller.Validate(promptToProceed);
            if (instanceInstaller.ReportCard.HasErrors || instanceInstaller.ReportCard.CancelRequested)
            {
                instanceInstaller.ReportCard.Status = Status.FailedValidation;
                return(instanceInstaller.ReportCard);
            }

            progress.Report(3, 9, "Copying files...");
            instanceInstaller.CopyFiles(ZipInfo.FilePath);
            progress.Report(4, 9, "Writing configurations...");
            instanceInstaller.WriteConfigurationFile();
            progress.Report(5, 9, "Registering URL ACLs...");
            instanceInstaller.RegisterUrlAcl();
            progress.Report(6, 9, "Creating queues...");
            instanceInstaller.SetupInstance();

            if (!instanceInstaller.ReportCard.HasErrors)
            {
                progress.Report(7, 9, "Registering service...");
                instanceInstaller.RegisterService();
                //Post Installation
                progress.Report(8, 9, "Starting service...");
                var instance = InstanceFinder.FindMonitoringInstance(instanceInstaller.Name);
                if (!instance.TryStartService())
                {
                    instanceInstaller.ReportCard.Warnings.Add($"New instance did not startup - please check configuration for {instance.Name}");
                }
            }

            instanceInstaller.ReportCard.SetStatus();
            return(instanceInstaller.ReportCard);
        }
Exemplo n.º 4
0
        public bool Add(MonitoringNewInstance details, Func <PathInfo, bool> promptToProceed)
        {
            ZipInfo.ValidateZip();

            var checkLicenseResult = CheckLicenseIsValid();

            if (!checkLicenseResult.Valid)
            {
                logger.Error($"Install aborted - {checkLicenseResult.Message}");
                return(false);
            }

            var instanceInstaller = details;

            instanceInstaller.ReportCard = new ReportCard();

            //Validation
            instanceInstaller.Validate(promptToProceed);
            if (instanceInstaller.ReportCard.HasErrors)
            {
                foreach (var error in instanceInstaller.ReportCard.Errors)
                {
                    logger.Error(error);
                }

                return(false);
            }

            try
            {
                instanceInstaller.CopyFiles(ZipInfo.FilePath);
                instanceInstaller.WriteConfigurationFile();
                instanceInstaller.RegisterUrlAcl();
                instanceInstaller.SetupInstance();
                instanceInstaller.RegisterService();
                foreach (var warning in instanceInstaller.ReportCard.Warnings)
                {
                    logger.Warn(warning);
                }

                if (instanceInstaller.ReportCard.HasErrors)
                {
                    foreach (var error in instanceInstaller.ReportCard.Errors)
                    {
                        logger.Error(error);
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                return(false);
            }

            //Post Installation
            var instance = InstanceFinder.FindMonitoringInstance(instanceInstaller.Name);

            if (!instance.TryStartService())
            {
                logger.Warn("The service failed to start");
            }

            return(true);
        }