Exemplo n.º 1
0
        public void ValidationPassesForValidTimes()
        {
            TimeValidator validator = new TimeValidator();

            Assert.IsTrue(validator.IsValid(this, "00:00"));
            Assert.IsTrue(validator.IsValid(this, "23:59"));
        }
        public FluentValidation.Results.ValidationResult Validar(ITimeService service)
        {
            TimeValidator validator = new TimeValidator(service);
            var           results   = validator.Validate(this);

            return(results);
        }
        public TimePeriod(int hours, byte minutes)
        {
            TimeValidator.ValidateHours(hours);
            TimeValidator.ValidateMinutes(minutes);

            this.TimeInSeconds = TimeToSecondHelper.Get(hours, minutes);
        }
Exemplo n.º 4
0
        public ConfigForm(Timetable tt, IPluginInterface pluginInterface)
        {
            Eto.Serialization.Xaml.XamlReader.Load(this);

            backupHandle = pluginInterface.BackupTimetable();

            this.tt = tt;
            this.pluginInterface = pluginInterface;

            heightPerHourValidator = new NumberValidator(heightPerHourTextBox, false, false, errorMessage: "Bitte eine Zahl als Höhe pro Stunde angeben!");
            startTimeValidator     = new TimeValidator(startTimeTextBox, false, errorMessage: "Bitte eine gültige Uhrzeit im Format hh:mm angeben!");
            endTimeValidator       = new TimeValidator(endTimeTextBox, false, errorMessage: "Bitte eine gültige Uhrzeit im Format hh:mm angeben!", maximum: new TimeEntry(48, 0));
            validators             = new ValidatorCollection(heightPerHourValidator, startTimeValidator, endTimeValidator);

            DropDownBind.Color <TimetableStyle>(pluginInterface.Settings, bgColorComboBox, "BgColor");
            DropDownBind.Color <TimetableStyle>(pluginInterface.Settings, stationColorComboBox, "StationColor");
            DropDownBind.Color <TimetableStyle>(pluginInterface.Settings, timeColorComboBox, "TimeColor");
            DropDownBind.Color <TimetableStyle>(pluginInterface.Settings, trainColorComboBox, "TrainColor");

            DropDownBind.Font <TimetableStyle>(stationFontComboBox, stationFontSizeComboBox, "StationFont");
            DropDownBind.Font <TimetableStyle>(timeFontComboBox, timeFontSizeComboBox, "TimeFont");
            DropDownBind.Font <TimetableStyle>(trainFontComboBox, trainFontSizeComboBox, "TrainFont");

            DropDownBind.Width <TimetableStyle>(hourTimeWidthComboBox, "HourTimeWidth");
            DropDownBind.Width <TimetableStyle>(minuteTimeWidthComboBox, "MinuteTimeWidth");
            DropDownBind.Width <TimetableStyle>(stationWidthComboBox, "StationWidth");
            DropDownBind.Width <TimetableStyle>(trainWidthComboBox, "TrainWidth");

            var styles = new Dictionary <StationLineStyle, string>()
            {
                [StationLineStyle.None]   = "Keine",
                [StationLineStyle.Normal] = "Gerade Linien",
                [StationLineStyle.Cubic]  = "Kubische Linien",
            };

            if (tt.Version == TimetableVersion.JTG2_x)
            {
                styles.Remove(StationLineStyle.Cubic);
            }
            DropDownBind.Enum <TimetableStyle, StationLineStyle>(stationLinesDropDown, "StationLines", styles);

            heightPerHourTextBox.TextBinding.AddFloatConvBinding <TimetableStyle, TextControl>(s => s.HeightPerHour);

            startTimeTextBox.TextBinding.AddTimeEntryConvBinding <TimetableStyle, TextControl>(s => s.StartTime);
            endTimeTextBox.TextBinding.AddTimeEntryConvBinding <TimetableStyle, TextControl>(s => s.EndTime);

            includeKilometreCheckBox.CheckedBinding.BindDataContext <TimetableStyle>(s => s.DisplayKilometre);
            drawStationNamesCheckBox.CheckedBinding.BindDataContext <TimetableStyle>(s => s.DrawHeader);
            stationVerticalCheckBox.CheckedBinding.BindDataContext <TimetableStyle>(s => s.StationVertical);
            multitrackCheckBox.CheckedBinding.BindDataContext <TimetableStyle>(s => s.MultiTrack);
            networkTrainsCheckBox.CheckedBinding.BindDataContext <TimetableStyle>(s => s.DrawNetworkTrains);

            networkTrainsCheckBox.Enabled = tt.Type == TimetableType.Network;

            attrs       = new TimetableStyle(tt);
            DataContext = attrs;

            this.AddCloseHandler();
        }
Exemplo n.º 5
0
        public Time(byte hours)
        {
            this.Hours = hours;

            TimeValidator.ValidateHours(this.Hours);

            this.TimeInSeconds = TimeToSecondHelper.Get(this.Hours, this.Minutes, this.Seconds);
        }
Exemplo n.º 6
0
        public override DateTime ToTime()
        {
            int year = (int)arg0.ToNumber();

            TimeValidator.ValidateYear(year);

            return(new DateTime(year, 1, 1, 0, 0, 0));
        }
Exemplo n.º 7
0
        public override DateTime ToTime()
        {
            int year = (int)arg0.ToNumber();

            TimeValidator.ValidateYear(year);

            return(Easter(year));
        }
Exemplo n.º 8
0
        public override IValidator Build()
        {
            IValidator validator = new TimeValidator();

            ConfigureValidatorMessage(validator);

            return(validator);
        }
Exemplo n.º 9
0
        public override DateTime ToTime()
        {
            int day   = (int)arg0.ToNumber();
            int month = (int)arg1.ToNumber();
            int year  = (int)arg2.ToNumber();

            TimeValidator.ValidateDate(day, month, year);
            return(new DateTime(year, month, day, 0, 0, 0));
        }
Exemplo n.º 10
0
        public void ValidationFailsForInvalidTimes()
        {
            TimeValidator validator = new TimeValidator();

            Assert.IsFalse(validator.IsValid(this, "24:00"));
            Assert.IsFalse(validator.IsValid(this, "00:60"));
            Assert.IsFalse(validator.IsValid(this, "12"));
            Assert.IsFalse(validator.IsValid(this, "23:"));
            Assert.IsFalse(validator.IsValid(this, "abc"));
            Assert.IsFalse(validator.IsValid(this, ":10"));
        }
        public TimePeriod(string timeString)
        {
            int  hours   = TimeFactory.GetHours(timeString);
            byte minutes = TimeFactory.GetMinutes(timeString);
            byte seconds = TimeFactory.GetSeconds(timeString);

            TimeValidator.ValidateHours(hours);
            TimeValidator.ValidateMinutes(minutes);
            TimeValidator.ValidateSeconds(seconds);

            this.TimeInSeconds = TimeToSecondHelper.Get(hours, minutes, seconds);
        }
Exemplo n.º 12
0
        public Time(string timeString)
        {
            this.Hours   = (byte)TimeFactory.GetHours(timeString);
            this.Minutes = TimeFactory.GetMinutes(timeString);
            this.Seconds = TimeFactory.GetSeconds(timeString);

            TimeValidator.ValidateHours(this.Hours);
            TimeValidator.ValidateMinutes(this.Minutes);
            TimeValidator.ValidateSeconds(this.Seconds);

            this.TimeInSeconds = TimeToSecondHelper.Get(this.Hours, this.Minutes, this.Seconds);
        }
Exemplo n.º 13
0
        public void InserirTime()
        {
            var validator = new TimeValidator();
            var result    = validator.validate(ListarTimes);

            if (result.IsValid)
            {
                else
                {
                    throw new Exception(result.Erros.FirstOrDefault().ToString());
                }
            }
Exemplo n.º 14
0
        public void SetElementValue(decimal newValue, TimeVariableType type)
        {
            switch (type)
            {
            case TimeVariableType.Year:
            {
                TimeValidator.ValidateYear((int)newValue);
                ChangeYear((int)newValue);     // special method considering leap years
                break;
            }

            case TimeVariableType.Month:
            {
                TimeValidator.ValidateMonth((int)newValue);
                TimeValidator.ValidateDay(value.Day, (int)newValue, value.Day);
                value = new DateTime(value.Year, (int)newValue, value.Day);
                break;
            }

            case TimeVariableType.Day:
            {
                TimeValidator.ValidateDay(value.Day, value.Month, (int)newValue);
                value = new DateTime(value.Year, value.Month, (int)newValue);
                break;
            }

            case TimeVariableType.Hour:
            {
                TimeValidator.ValidateHour((int)newValue);
                TimeSpan ts = new TimeSpan((int)newValue, value.Minute, value.Second);
                value = value.Date + ts;
                break;
            }

            case TimeVariableType.Minute:
            {
                TimeValidator.ValidateMinute((int)newValue);
                TimeSpan ts = new TimeSpan(value.Hour, (int)newValue, value.Second);
                value = value.Date + ts;
                break;
            }

            case TimeVariableType.Second:
            {
                TimeValidator.ValidateSecond((int)newValue);
                TimeSpan ts = new TimeSpan(value.Hour, value.Minute, (int)newValue);
                value = value.Date + ts;
                break;
            }
            }
        }
Exemplo n.º 15
0
        public override DateTime ToTime()
        {
            int years   = (int)year.ToYear();
            int months  = (int)month;
            int days    = (int)day.ToDay();
            int hours   = (int)clock.ToHour();
            int minutes = (int)clock.ToMinute();
            int seconds = (int)clock.ToSecond();

            TimeValidator.ValidateDate(days, months, years);
            TimeValidator.ValidateClock(hours, minutes, seconds);

            return(new DateTime(years, months, days, hours, minutes, seconds));
        }
Exemplo n.º 16
0
        public void InserirTime(Time timao)
        {
            var validator = new TimeValidator();
            var validRes  = validator.Validate(timao);

            if (validRes.IsValid)
            {
                listaTimes.Add(timao);
            }
            else
            {
                throw new Exception(validRes.Errors.FirstOrDefault().ToString());
            }
        }
Exemplo n.º 17
0
        public override DateTime ToTime()
        {
            int hour   = (int)arg0.ToNumber();
            int minute = (int)arg1.ToNumber();

            TimeValidator.ValidateHour(hour);
            TimeValidator.ValidateMinute(minute);

            DateTime s  = DateTime.Now.AddDays(1);
            TimeSpan ts = new TimeSpan(hour, minute, 0);

            s = s.Date + ts;
            return(s);
        }
Exemplo n.º 18
0
        public override DateTime ToTime()
        {
            int hour   = (int)arg0.ToNumber();
            int minute = (int)arg1.ToNumber();
            int second = (int)arg2.ToNumber();

            TimeValidator.ValidateHour(hour);
            TimeValidator.ValidateMinute(minute);
            TimeValidator.ValidateSecond(second);

            DateTime s  = DateTime.Now;
            TimeSpan ts = new TimeSpan(hour, minute, second);

            s = s.Date + ts;
            return(s);
        }
Exemplo n.º 19
0
        public override DateTime ToTime()
        {
            DateTime dtime = time.ToTime();

            int hours   = (int)clock.ToHour();
            int minutes = (int)clock.ToMinute();
            int seconds = (int)clock.ToSecond();

            TimeValidator.ValidateClock(hours, minutes, seconds);

            TimeSpan ts = new TimeSpan(hours, minutes, seconds);

            dtime = dtime.Date + ts;

            return(dtime);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Create a new dialog to edit (= discard + create new) the given train link.
        /// </summary>
        /// <param name="link">Link object that is used as blueprint. Note: The referenced object will not be mutated!</param>
        /// <param name="tt">Current timetable instance.</param>
        public TrainLinkEditDialog(TrainLink link, Timetable tt)
        {
            if (tt.Type == TimetableType.Network && tt.Version.CompareTo(TimetableVersion.Extended_FPL2) < 0)
            {
                throw new TimetableTypeNotSupportedException("train links");
            }

            Eto.Serialization.Xaml.XamlReader.Load(this);

            differenceValidator = new TimeValidator(differenceTextBox, false, errorMessage: T._("Bitte die Verschiebung als Zeitangabe angeben!"));
            offsetValidator     = new TimeValidator(startOffsetTextBox, false, errorMessage: T._("Bitte die Startverschiebung als Zeitangabe angeben!"));
            countValidator      = new NumberValidator(countTextBox, false, true, allowNegative: false, errorMessage: T._("Bitte eine gültige Anzahl >0 neuer Züge eingeben!"));
            changeValidator     = new NumberValidator(changeTextBox, false, true, errorMessage: T._("Bitte eine gültige Veränderung der Zugnummer eingeben!"));

            origLink = link;
            train    = link.ParentTrain;
            this.tt  = tt;

            startOffsetTextBox.Text = link.TimeOffset.ToTimeString();
            differenceTextBox.Text  = link.TimeDifference.ToTimeString();
            countTextBox.Text       = link.TrainCount.ToString();

            switch (link.TrainNamingScheme)
            {
            case AutoTrainNameGen atnc:
                autoTrainNameTableLayout.Visible = true;
                changeTextBox.Text = atnc.Increment.ToString();
                nameTextBox.Text   = atnc.BaseTrainName.FullName;
                break;

            case SpecialTrainNameGen stnc:
                specialTrainNameTableLayout.Visible = true;
                specialNameGridView.AddColumn((SpecialNameEntry spn) => spn.RowNumber.ToString(), "");
                specialNameGridView.AddColumn((SpecialNameEntry spn) => spn.Name, T._("Zugname"), true);

                var ds = new SpecialNameEntry[stnc.Names.Length];
                for (int i = 0; i < stnc.Names.Length; i++)
                {
                    ds[i] = new SpecialNameEntry(i + 1, stnc.Names[i]);
                }
                specialNameGridView.DataStore = ds;
                break;

            default:
                throw new NotSupportedException("Not Implemented: Name calculator not supported!");
            }
        }
Exemplo n.º 21
0
 public void Setup()
 {
     _validator = new TimeValidator();
 }
 public void IfCorrectInput_DoesNotThrowExceptions(string data)
 {
     TimeValidator.Validate(data);
 }
        public TimePeriod(int hours)
        {
            TimeValidator.ValidateHours(hours);

            this.TimeInSeconds = TimeToSecondHelper.Get(hours);
        }
 public void IfIncorrectInput_ThrowExceptions(string data)
 {
     Assert.Throws <ArgumentException>(() => TimeValidator.Validate(data));
 }
        public string ValidationMsg()
        {
            // If we have no text to validate...
            if (String.IsNullOrEmpty(_attachedTextControl.Text.Trim()))
            {
                if (_required)
                {
                    return("Please enter a value into " + _nomenclature);
                }
                return(String.Empty);
            }
            // If we got here then there is text to validate
            if (_attachedTextControl.Text == _originalText)
            {
                // Assume the original text is in the proper validation style
                if (_validationStyle == ValidationStyle.NoOriginalValue)
                {
                    return("Please enter a different value into " + _nomenclature);
                }
                return(String.Empty);
            }
            // Okay, we have something to validate and its not the original value...
            string        returnMsg = String.Empty;
            TextValidator validator;
            string        errSuffix = " into " + _nomenclature;

            switch (_validationStyle)
            {
            case ValidationStyle.NoValidation:
                returnMsg = String.Empty;
                break;

            case ValidationStyle.DateAny:
                validator = new DateValidator(DateStyle.DontCare);
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;

            case ValidationStyle.DateFuture:
                validator = new DateValidator(DateStyle.Future);
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;

            case ValidationStyle.DatePast:
                validator = new DateValidator(DateStyle.Past);
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;

            case ValidationStyle.DigitsOnly:
                validator = new DigitsValidator(DigitStyle.DigitsOnly);
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;

            case ValidationStyle.DigitsNotZero:
                validator = new DigitsValidator(DigitStyle.DigitsNotZero);
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;

            case ValidationStyle.Money:
                validator = new DigitsValidator(DigitStyle.Money);
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;

            case ValidationStyle.MoneyNotZero:
                validator = new DigitsValidator(DigitStyle.MoneyNotZero);
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;

            case ValidationStyle.Percentage:
                validator = new DigitsValidator(DigitStyle.Percentage);
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;

            case ValidationStyle.PercentageNotZero:
                validator = new DigitsValidator(DigitStyle.PercentageNotZero);
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;

            case ValidationStyle.PhoneNumber:
                validator = new PhoneNumberValidator();
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;

            case ValidationStyle.EmailAddr:
                validator = new PureTextValidator(PureTextStyle.EmailAddress);
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;

            case ValidationStyle.StateAbbreviation:
                validator = new PureTextValidator(PureTextStyle.StateAbbreviation);
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;

            case ValidationStyle.NoWhiteSpace:
                validator = new PureTextValidator(PureTextStyle.NoWhiteSpace);
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;

            case ValidationStyle.NoPunctuation:
                validator = new PureTextValidator(PureTextStyle.NoPunctuation);
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;

            case ValidationStyle.NoWhiteSpaceAndNoPunct:
                validator = new PureTextValidator(PureTextStyle.NoWhiteSpaceAndNoPunct);
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;

            case ValidationStyle.SSN:
                validator = new SSNValidator();
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;

            case ValidationStyle.Time:
                validator = new TimeValidator();
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;

            case ValidationStyle.ZipPlus4:
                validator = new ZipCodeValidator();
                returnMsg = validator.Validate(_attachedTextControl.Text);
                if (returnMsg.Length > 0)
                {
                    returnMsg = returnMsg + errSuffix;
                }
                break;
            }

            return(returnMsg);
        }