Esempio n. 1
0
        public static ActionResult ServiceControlInstanceCount(Session session)
        {
            var instanceCount = ServiceControlInstance.Instances().Count;

            session["SCINSTANCECOUNT"] = instanceCount.ToString();
            return(ActionResult.Success);
        }
        public void ChangeConfigTests()
        {
            var logger    = new TestLogger();
            var installer = new UnattendInstaller(logger, deploymentCache);

            logger.Info("Deleting instances");
            DeleteInstance();

            logger.Info("Removing the test queue instances");
            RemoveAltMSMQQueues();

            logger.Info("Recreating the MSMQ instance");
            CreateInstanceMSMQ();

            logger.Info("Changing the URLACL");
            var msmqTestInstance = ServiceControlInstance.Instances().First(p => p.Name.Equals("Test.ServiceControl.MSMQ", StringComparison.OrdinalIgnoreCase));

            msmqTestInstance.HostName = Environment.MachineName;
            msmqTestInstance.Port     = 33338;
            installer.Update(msmqTestInstance, true);
            Assert.IsTrue(msmqTestInstance.Service.Status == ServiceControllerStatus.Running, "Update URL change failed");

            logger.Info("Changing LogPath");
            msmqTestInstance         = ServiceControlInstance.Instances().First(p => p.Name.Equals("Test.ServiceControl.MSMQ", StringComparison.OrdinalIgnoreCase));
            msmqTestInstance.LogPath = @"c:\temp\testloggingchange";
            installer.Update(msmqTestInstance, true);
            Assert.IsTrue(msmqTestInstance.Service.Status == ServiceControllerStatus.Running, "Update Logging changed failed");

            logger.Info("Updating Queue paths");
            msmqTestInstance            = ServiceControlInstance.Instances().First(p => p.Name.Equals("Test.ServiceControl.MSMQ", StringComparison.OrdinalIgnoreCase));
            msmqTestInstance.AuditQueue = "alternateAudit";
            msmqTestInstance.ErrorQueue = "alternateError";
            installer.Update(msmqTestInstance, true);
            Assert.IsTrue(msmqTestInstance.Service.Status == ServiceControllerStatus.Running, "Update Queues changed failed");
        }
Esempio n. 3
0
        protected SharedInstanceEditorViewModelValidator()
        {
            ServiceControlInstances = ServiceControlInstance.Instances();

            RuleFor(x => x.InstanceName)
            .NotEmpty()
            .MustNotContainWhitespace()
            .When(x => x.SubmitAttempted);

            RuleFor(x => x.HostName)
            .NotEmpty().When(x => x.SubmitAttempted);

            RuleFor(x => x.PortNumber)
            .NotEmpty()
            .ValidPort()
            .MustNotBeIn(x => UsedPorts(x.InstanceName))
            .WithMessage(Validations.MSG_MUST_BE_UNIQUE, "Ports")
            .When(x => x.SubmitAttempted);

            RuleFor(x => x.LogPath)
            .NotEmpty()
            .ValidPath()
            .MustNotBeIn(x => UsedPaths(x.InstanceName))
            .WithMessage(Validations.MSG_MUST_BE_UNIQUE, "Paths")
            .When(x => x.SubmitAttempted);
        }
Esempio n. 4
0
        public static bool Validate(ServiceControlInstanceMetadata instance, Func <PathInfo, bool> promptToProceed)
        {
            var validator = new PathsValidator(instance)
            {
                Instances = ServiceControlInstance.Instances().AsEnumerable <IContainInstancePaths>().ToList()
            };

            return(validator.RunValidation(true, promptToProceed));
        }
        public void DeleteInstance()
        {
            var installer = new UnattendInstaller(new TestLogger(), deploymentCache);

            foreach (var instance in ServiceControlInstance.Instances().Where(p => p.Name.StartsWith("Test.ServiceControl", StringComparison.OrdinalIgnoreCase)))
            {
                installer.Delete(instance.Name, true, true);
            }
        }
Esempio n. 6
0
        public static void Validate(ServiceControlInstance instance)
        {
            var validator = new QueueNameValidator(instance)
            {
                instances = ServiceControlInstance.Instances().Where(p => p.Name != instance.Name & p.TransportPackage.Equals(instance.TransportPackage, StringComparison.OrdinalIgnoreCase)).AsEnumerable <IContainTransportInfo>().ToList()
            };

            validator.RunValidation();
        }
Esempio n. 7
0
        public static void Validate(ServiceControlInstance instance)
        {
            var name      = instance.Name;
            var validator = new PathsValidator(instance)
            {
                Instances = ServiceControlInstance.Instances().Where(p => p.Name != name).AsEnumerable <IContainInstancePaths>().ToList()
            };

            validator.RunValidation(false);
        }
        public void UpgradeInstance()
        {
            var installer = new UnattendInstaller(new TestLogger(), deploymentCache);

            foreach (var instance in ServiceControlInstance.Instances())  //.Where(p => p.Name.StartsWith("Test.ServiceControl", StringComparison.OrdinalIgnoreCase)))
            {
                installer.Upgrade(instance, new InstanceUpgradeOptions {
                    AuditRetentionPeriod = TimeSpan.FromDays(30), ErrorRetentionPeriod = TimeSpan.FromDays(15), OverrideEnableErrorForwarding = true
                });
            }
        }
Esempio n. 9
0
        private void RefreshInstances()
        {
            if (ActiveItem != null && ActiveItem != listInstances && ActiveItem != noInstances)
            {
                return;
            }

            HasInstances = ServiceControlInstance.Instances().Any();

            if (HasInstances)
            {
                ActivateItem(listInstances);
            }
            else
            {
                ActivateItem(noInstances);
            }
        }
Esempio n. 10
0
        public void CreateAService()
        {
            var s = new WindowsServiceDetails
            {
                ImagePath         = @"C:\Program Files (x86)\Particular Software\ServiceControl\ServiceControl.exe  --serviceName=Test.SC",
                DisplayName       = "Test SC",
                Name              = "Test.SC",
                ServiceAccount    = @"NT Authority\NetworkService",
                ServiceAccountPwd = null
            };

            var existing = ServiceControlInstance.Instances().FirstOrDefault(p => p.Name == s.Name);

            if (existing != null)
            {
                ServiceControlInstance.Instances().First(p => p.Name == s.Name).Service.Delete();
            }
            WindowsServiceController.RegisterNewService(s);
            ServiceControlInstance.Instances().First(p => p.Name == s.Name).Service.Delete();
        }
Esempio n. 11
0
        public static ActionResult ServiceControlUnattendedRemoval(Session session)
        {
            var logger = new MSILogger(session);
            var removeInstancesPropertyValue = session["REMOVEALLINSTANCESANDDATA"];

            if (string.IsNullOrWhiteSpace(removeInstancesPropertyValue))
            {
                return(ActionResult.NotExecuted);
            }

            switch (removeInstancesPropertyValue.ToUpper())
            {
            case "YES":
            case "TRUE":
                break;

            default:
                return(ActionResult.NotExecuted);
            }

            if (ServiceControlInstance.Instances().Count == 0)
            {
                return(ActionResult.Success);
            }

            var unattendedInstaller = new UnattendInstaller(logger, session["APPDIR"]);

            foreach (var instance in ServiceControlInstance.Instances())
            {
                try
                {
                    unattendedInstaller.Delete(instance.Name, true, true);
                }
                catch (Exception ex)
                {
                    logger.Error($"Error thrown when removing instance {instance.Name} - {ex}");
                }
            }
            return(ActionResult.Success);
        }
        public InstanceAddViewModel()
        {
            DisplayName = "Add new instance";

            SelectDestinationPath = new SelectPathCommand(p => DestinationPath = p, isFolderPicker: true, defaultPath: DestinationPath);
            SelectDatabasePath    = new SelectPathCommand(p => DatabasePath = p, isFolderPicker: true, defaultPath: DatabasePath);
            SelectLogPath         = new SelectPathCommand(p => LogPath = p, isFolderPicker: true, defaultPath: LogPath);

            var serviceControlInstances = ServiceControlInstance.Instances();

            if (!serviceControlInstances.Any())
            {
                InstanceName = "Particular.ServiceControl";
                PortNumber   = "33333";
            }
            else
            {
                var i = 0;
                while (true)
                {
                    InstanceName = $"Particular.ServiceControl.{++i}";
                    if (!serviceControlInstances.Any(p => p.Name.Equals(InstanceName, StringComparison.OrdinalIgnoreCase)))
                    {
                        break;
                    }
                }
            }

            AuditRetention           = SettingConstants.AuditRetentionPeriodDefaultInHoursForUI;
            ErrorRetention           = SettingConstants.ErrorRetentionPeriodDefaultInDaysForUI;
            Description              = "A ServiceControl Instance";
            HostName                 = "localhost";
            AuditQueueName           = "audit";
            AuditForwardingQueueName = "audit.log";
            ErrorQueueName           = "error";
            ErrorForwardingQueueName = "error.log";
            ErrorForwarding          = ErrorForwardingOptions.First(p => !p.Value); //Default to Off.
            UseSystemAccount         = true;
        }
        private void RefreshInstances()
        {
            var currentInstances = ServiceControlInstance.Instances();

            var addedInstances   = currentInstances.Where(i => Instances.All(i2 => i2.Name != i.Name)).ToList();
            var removedInstances = Instances.Where(i => currentInstances.All(i2 => i2.Name != i.Name)).ToList();

            foreach (var item in addedInstances)
            {
                Instances.Add(instanceDetailsFunc(item));
            }

            foreach (var item in removedInstances)
            {
                Instances.Remove(item);
            }

            foreach (var instance in Instances)
            {
                instance.ServiceControlInstance.Reload();
            }
            // Existing instances are updated in the InstanceDetailsViewModel
        }
        static void UpgradeInstances(Session session, ServiceControlZipInfo zipInfo, MSILogger logger, UnattendInstaller unattendedInstaller)
        {
            var options = new InstanceUpgradeOptions();

            var upgradeInstancesPropertyValue = session["UPGRADEINSTANCES"];

            if (string.IsNullOrWhiteSpace(upgradeInstancesPropertyValue))
            {
                return;
            }
            upgradeInstancesPropertyValue = upgradeInstancesPropertyValue.Trim();

            var forwardErrorMessagesPropertyValue = session["FORWARDERRORMESSAGES"];

            try
            {
                options.OverrideEnableErrorForwarding = bool.Parse(forwardErrorMessagesPropertyValue);
            }
            catch
            {
                options.OverrideEnableErrorForwarding = null;
            }

            var auditRetentionPeriodPropertyValue = session["AUDITRETENTIONPERIOD"];

            try
            {
                options.AuditRetentionPeriod = TimeSpan.Parse(auditRetentionPeriodPropertyValue);
            }
            catch
            {
                options.AuditRetentionPeriod = null;
            }

            var errorRetentionPeriodPropertyValue = session["ERRORRETENTIONPERIOD"];

            try
            {
                options.ErrorRetentionPeriod = TimeSpan.Parse(errorRetentionPeriodPropertyValue);
            }
            catch
            {
                options.ErrorRetentionPeriod = null;
            }

            //determine what to upgrade
            var instancesToUpgrade = new List <ServiceControlInstance>();

            if (upgradeInstancesPropertyValue.Equals("*", StringComparison.OrdinalIgnoreCase) || upgradeInstancesPropertyValue.Equals("ALL", StringComparison.OrdinalIgnoreCase))
            {
                instancesToUpgrade.AddRange(ServiceControlInstance.Instances());
            }
            else
            {
                var candidates = upgradeInstancesPropertyValue.Replace(" ", String.Empty).Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                instancesToUpgrade.AddRange(ServiceControlInstance.Instances().Where(instance => candidates.Contains(instance.Name, StringComparer.OrdinalIgnoreCase)));
            }

            // do upgrades
            foreach (var instance in instancesToUpgrade)
            {
                if (zipInfo.Version > instance.Version)
                {
                    if (!instance.AppSettingExists(SettingsList.ForwardErrorMessages.Name) & !options.OverrideEnableErrorForwarding.Value)
                    {
                        logger.Warn($"Unattend upgrade {instance.Name} to {zipInfo.Version} not attempted. FORWARDERRORMESSAGES MSI parameter was required because appsettings needed a value for '{SettingsList.ForwardErrorMessages.Name}'");
                        continue;
                    }


                    if (!options.AuditRetentionPeriod.HasValue)
                    {
                        if (!instance.AppSettingExists(SettingsList.AuditRetentionPeriod.Name))
                        {
                            //Try migration first
                            if (instance.AppSettingExists(SettingsList.HoursToKeepMessagesBeforeExpiring.Name))
                            {
                                var i = instance.ReadAppSetting(SettingsList.HoursToKeepMessagesBeforeExpiring.Name, -1);
                                if (i > 0)
                                {
                                    options.AuditRetentionPeriod = TimeSpan.FromHours(i);
                                }
                            }
                            else
                            {
                                logger.Warn($"Unattend upgrade {instance.Name} to {zipInfo.Version} not attempted. AUDITRETENTIONPERIOD MSI parameter was required because appsettings needed a value for '{SettingsList.AuditRetentionPeriod.Name}'");
                                continue;
                            }
                        }
                    }

                    if (!instance.AppSettingExists(SettingsList.ErrorRetentionPeriod.Name) & !options.ErrorRetentionPeriod.HasValue)
                    {
                        logger.Warn($"Unattend upgrade {instance.Name} to {zipInfo.Version} not attempted. ERRORRETENTIONPERIOD MSI parameter was required because appsettings needed a value for '{SettingsList.ErrorRetentionPeriod.Name}'");
                        continue;
                    }

                    if (!unattendedInstaller.Upgrade(instance, options))
                    {
                        logger.Warn($"Failed to upgrade {instance.Name} to {zipInfo.Version}");
                    }
                }
            }
        }
Esempio n. 15
0
 protected override void ProcessRecord()
 {
     WriteObject(ServiceControlInstance.Instances().Select(PsServiceControl.FromInstance), true);
 }