Ejemplo n.º 1
0
        /// <summary>
        /// Return value may be null, or the path may not exist.
        /// </summary>
        public string FullPath(SimulatorType Type, AppOptions Option)
        {
            var simPath = Option.SimulatorPaths[Type];

            return(ExceptionHelpers.DefaultIfThrows(
                       () => Path.GetFullPath(Path.Combine(simPath, relativePath)),
                       null));
        }
Ejemplo n.º 2
0
 public void DefaultIfThrowsTest()
 {
     Assert.AreEqual(2, ExceptionHelpers.DefaultIfThrows(() => 1 + 1));
     Assert.AreEqual(null, ExceptionHelpers.DefaultIfThrows(() =>
     {
         if ("".Length == 0)
         {
             throw new ArgumentException();
         }
         return("abc");
     }));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Overrides the brake settings of CalculatorData.
        /// </summary>
        /// <exception cref="RunwayTooShortException"></exception>
        /// <exception cref="Exception"></exception>
        public static LandingReport LandingReport(CalculatorData d)
        {
            var p = d.Parameters;
            var t = d.Table;

            var all = t.AllBrakes().Select(b =>
            {
                return(ExceptionHelpers.DefaultIfThrows(() =>
                {
                    var dis = LandingDistanceMeter(d, null, b);
                    return new ReportRow()
                    {
                        BrakeSetting = b,
                        RequiredDistanceMeter = RoundToInt(dis),
                        RemainingDistanceMeter = RoundToInt(p.RwyLengthMeter - dis)
                    };
                }, null));
            }).ToList();

            var selected = all[p.BrakeIndex];

            if (selected == null)
            {
                throw new Exception("Unexpected error occurred.");
            }
            if (selected.RemainingDistanceMeter < 0)
            {
                throw new RunwayTooShortException();
            }

            return(new LandingReport()
            {
                SelectedBrake = selected,
                AllBrakes = all
            });
        }
Ejemplo n.º 4
0
 // Returns null if not valid.
 private TOReport.DataRow TryValidateResult(double oat, double rwyRequired)
 {
     return(ExceptionHelpers.DefaultIfThrows(() => ValidateResult(oat, rwyRequired)));
 }