Пример #1
0
        internal ReportCard Update(MonitoringInstance instance, bool startService)
        {
            try
            {
                instance.ReportCard = new ReportCard();
                instance.ValidateChanges();
                if (instance.ReportCard.HasErrors)
                {
                    instance.ReportCard.Status = Status.FailedValidation;
                    return(instance.ReportCard);
                }

                if (!instance.TryStopService())
                {
                    instance.ReportCard.Errors.Add("Service failed to stop");
                    instance.ReportCard.Status = Status.Failed;
                    return(instance.ReportCard);
                }

                instance.ApplyConfigChange();
                if (!instance.ReportCard.HasErrors)
                {
                    if (startService && !instance.TryStartService())
                    {
                        instance.ReportCard.Warnings.Add($"Service did not start after changes - please check configuration for {instance.Name}");
                    }
                }
                instance.ReportCard.SetStatus();
                return(instance.ReportCard);
            }
            finally
            {
                instance.Reload();
            }
        }
Пример #2
0
        internal bool Update(MonitoringInstance instance, bool startService)
        {
            instance.ReportCard = new ReportCard();
            instance.ValidateChanges();
            if (instance.ReportCard.HasErrors)
            {
                foreach (var error in instance.ReportCard.Errors)
                {
                    logger.Error(error);
                }

                return(false);
            }

            try
            {
                if (!instance.TryStopService())
                {
                    logger.Error("Service failed to stop");
                    return(false);
                }

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

                    return(false);
                }

                if (startService && !instance.TryStartService())
                {
                    logger.Error("Service failed to start after changes - please check configuration for {0}", instance.Name);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Update failed: {0}", ex.Message);
                return(false);
            }

            return(true);
        }