Exemplo n.º 1
0
        private double PressureConvert(double psiPres, PresUnitSelection targetUnit)
        {
            Pressure initialValue = Pressure.FromPsi(psiPres);
            double   convertedValue;

            switch (targetUnit)
            {
            case PresUnitSelection.kPa:
                convertedValue = initialValue.Kilopascals;
                return(convertedValue);

            case PresUnitSelection.bar:
                convertedValue = initialValue.Bars;
                return(convertedValue);

            case PresUnitSelection.atm:
                convertedValue = initialValue.Atmospheres;
                return(convertedValue);

            case PresUnitSelection.psia:
                convertedValue = psiPres;
                return(convertedValue);

            default:
                System.Diagnostics.Trace.Assert(false, "User selected unit conversion not implemented");
                throw new NotImplementedException("User selected unit conversion not implemented");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Accepts IEnum of raw data records from selected Csv files and converts them base on user selection on view
        /// </summary>
        /// <param name="rawRecords"></param>
        /// <param name="pressureUnit"></param>
        /// <param name="tempUnit"></param>
        /// <returns>IEnumerable<IDataRecord></returns>
        public IEnumerable <IDataRecord> ConvertUnits(IEnumerable <IDataRecord> rawRecords, PresUnitSelection pressureUnit, TempUnitSelection tempUnit)
        {
            foreach (var record in rawRecords)
            {
                if (record.Pressure != null)
                {
                    double pressure = Convert.ToDouble(record.Pressure);
                    record.Pressure = PressureConvert(pressure, pressureUnit);
                }

                if (record.Temperature != null)
                {
                    double temp = Convert.ToDouble(record.Temperature);
                    record.Temperature = TempConvert(temp, tempUnit);
                }
            }

            return(rawRecords);
        }