Ejemplo n.º 1
0
        // Если измеряемый промежуток не глубина, то парсим дату
        //
        private static DateTime ParseDateTime2(string data, string info, string unit = "s")
        {
            DateTime dateTime;

            if (DateTime.TryParse(data, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out dateTime))
            {
                return(dateTime);
            }

            var offset = Parsing.ParseDouble(data);

            if (double.TryParse(data, NumberStyles.Any, NumberFormatInfo.InvariantInfo, out offset))
            {
                var secondsSince1970 = unit?.Equals("date", StringComparison.OrdinalIgnoreCase) == true;
                if (!secondsSince1970)
                {
                    var date = Parsing.ParseDateTime(info);
                    //return date.AddSeconds(offset);
                    return(date);
                }
                return(new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(offset));
            }
            throw new ApplicationException($"Значение '{data}' не возможно представить как дату/время.");
        }
Ejemplo n.º 2
0
        // Обработка секции W
        //
        private void SectionWell()
        {
            nextLine = null;
            while (Line[0] != '~')
            {
                try {
                    var regex    = new Regex(@"^([^~][^\.]+?)\.([^\s]*)(.*?):(.*)$", RegexOptions.IgnoreCase);
                    var m        = regex.Match(Line).Groups.Cast <Group>().Skip(1).Take(4).Select(x => x.Value.Trim()).ToList();
                    var mnemonic = m[0];
                    var unit     = m[1];
                    var data     = m[2];
                    var info     = m[3];

                    switch (mnemonic)
                    {
                    case "STRT":
                        if (IsDepthUnit(unit) != null)
                        {
                            MeasuredDepthUnit       = unit;
                            StartMeasuredDepthIndex = Parsing.ParseDouble(data);
                        }
                        else
                        {
                            StartDateTimeIndex = ParseDateTime2(data, info, unit);     // тут ошибка пока-что = нужно парсить дату или секунды - хз пока
                        }
                        break;

                    case "STOP":
                        if (IsDepthUnit(unit) != null)
                        {
                            MeasuredDepthUnit      = unit;
                            StopMeasuredDepthIndex = Parsing.ParseDouble(data);
                        }
                        else
                        {
                            StopDateTimeIndex = ParseDateTime2(data, info, unit);     // тут ошибка пока-что = нужно парсить дату или секунды - хз пока
                        }
                        break;

                    case "STEP":
                        StepIncrement = Parsing.ParseDouble(data);
                        break;

                    case "NULL":
                        NullValue = Parsing.ParseDouble(data);
                        break;

                    case "SRVC":
                        ServiceCompany = data;
                        break;
                    }
                }
                catch (Exception ee) { }

                Line = ReadNextLine();
                if (String.IsNullOrEmpty(Line))
                {
                    Line = ReadNextLine();
                }
            }
            PreviousLine(Line);
        }