Пример #1
0
        public virtual ReturnValue IsValid(List <ISensor> allSensors)
        {
            if (Id == Guid.Empty)
            {
                return(ReturnValue.False("Id is invalid"));
            }

            if (Name.IsTrimmedStringNullOrEmpty())
            {
                return(ReturnValue.False("Name should not be empty"));
            }

            if (CheckInterval <= 0)
            {
                return(ReturnValue.False("Check interval should be less than 1"));
            }

            if (IntervalType == MonitoR.Common.Constants.CheckIntervalType.Seconds)
            {
                if (CheckInterval > 59)
                {
                    return(ReturnValue.False("Check interval should be less than 59 secs"));
                }
            }
            else if (IntervalType == MonitoR.Common.Constants.CheckIntervalType.Minutes)
            {
                if (CheckInterval > 59)
                {
                    return(ReturnValue.False("Check interval should be less than 59 minutes"));
                }
            }
            else if (IntervalType == MonitoR.Common.Constants.CheckIntervalType.Hours)
            {
                if (CheckInterval > 23)
                {
                    return(ReturnValue.False("Check interval should be less than 23 hours"));
                }

                if (CheckInterval < 0)
                {
                    return(ReturnValue.False("Check interval should be greater -1 hours"));
                }
            }

            if (NotifyIfHappensAfterTimes <= 0)
            {
                return(ReturnValue.False("NotifyIfHappensAfterTimes greater than 0"));
            }

            if (allSensors != null)
            {
                foreach (var sensor in allSensors)
                {
                    if (sensor == null)
                    {
                        continue;
                    }

                    if (Id == sensor.Id)
                    {
                        continue;
                    }

                    if (Name.CaseIgnoreEquals(sensor.Name))
                    {
                        return(ReturnValue.False("Another sensor with simular name already exists"));
                    }
                }
            }

            return(ReturnValue.True());
        }