private static void WriteBogieNode(XElement parent, string nodeName, Car.Bogie bogie) { parent.Add(new XElement(nodeName, new XElement("DefinedAxles", bogie.DefinedAxles), new XElement("FrontAxle", bogie.FrontAxle), new XElement("RearAxle", bogie.RearAxle), new XElement("Reversed", bogie.Reversed), new XElement("Object", bogie.Object) )); }
private static void WriteBogieNode(string fileName, StringBuilder builder, int bogieIndex, Car.Bogie bogie) { builder.AppendLine($"[Bogie{bogieIndex.ToString(CultureInfo.InvariantCulture)}]"); WriteKey(builder, "Object", Utilities.MakeRelativePath(fileName, bogie.Object)); if (bogie.DefinedAxles) { WriteKey(builder, "Axles", bogie.RearAxle, bogie.FrontAxle); } WriteKey(builder, "Reversed", bogie.Reversed.ToString()); }
internal BogieViewModel(Car.Bogie bogie) { CultureInfo culture = CultureInfo.InvariantCulture; DefinedAxles = bogie .ToReactivePropertyAsSynchronized(x => x.DefinedAxles) .AddTo(disposable); FrontAxle = bogie .ToReactivePropertyAsSynchronized( x => x.FrontAxle, x => x.ToString(culture), x => double.Parse(x, NumberStyles.Float, culture), ignoreValidationErrorValue: true ) .AddTo(disposable); RearAxle = bogie .ToReactivePropertyAsSynchronized( x => x.RearAxle, x => x.ToString(culture), x => double.Parse(x, NumberStyles.Float, culture), ignoreValidationErrorValue: true ) .AddTo(disposable); Reversed = bogie .ToReactivePropertyAsSynchronized(x => x.Reversed) .AddTo(disposable); Object = bogie .ToReactivePropertyAsSynchronized(x => x.Object) .AddTo(disposable); DefinedAxles.Subscribe(_ => { FrontAxle.ForceValidate(); RearAxle.ForceValidate(); }); FrontAxle.SetValidateNotifyError(x => { double front; string message; if (Utilities.TryParse(x, NumberRange.Any, out front, out message)) { double rear; if (DefinedAxles.Value && Utilities.TryParse(RearAxle.Value, NumberRange.Any, out rear) && front <= rear) { message = "RearAxleはFrontAxle未満でなければなりません。"; } } return(message); }) .Subscribe(_ => RearAxle.ForceValidate()) .AddTo(disposable); FrontAxle.ObserveHasErrors .ToReadOnlyReactivePropertySlim(mode: ReactivePropertyMode.DistinctUntilChanged) .Where(x => !x) .Subscribe(_ => FrontAxle.ForceNotify()) .AddTo(disposable); RearAxle.SetValidateNotifyError(x => { double rear; string message; if (Utilities.TryParse(x, NumberRange.Any, out rear, out message)) { double front; if (DefinedAxles.Value && Utilities.TryParse(FrontAxle.Value, NumberRange.Any, out front) && rear >= front) { message = "RearAxleはFrontAxle未満でなければなりません。"; } } return(message); }) .Subscribe(_ => FrontAxle.ForceValidate()) .AddTo(disposable); RearAxle.ObserveHasErrors .ToReadOnlyReactivePropertySlim(mode: ReactivePropertyMode.DistinctUntilChanged) .Where(x => !x) .Subscribe(_ => RearAxle.ForceNotify()) .AddTo(disposable); }