Пример #1
0
        Operation IParser.Parse(string[] lines)
        {
            var operation         = new Operation();
            var operationResource = new OperationResource();

            lines = Utilities.Trim(lines);

            CurrentSection section      = CurrentSection.AHeader;
            bool           keywordsOnly = true;

            InnerSection innerSection = InnerSection.AStraße;

            for (int i = 0; i < lines.Length; i++)
            {
                try
                {
                    string line = lines[i];
                    if (line.Length == 0)
                    {
                        continue;
                    }

                    // Try to parse the header and extract date and time if possible
                    operation.Timestamp = ReadFaxTimestamp(line, operation.Timestamp);


                    if (GetSection(line.Trim(), ref section, ref keywordsOnly))
                    {
                        continue;
                    }

                    string msg    = line;
                    string prefix = "";

                    // Make the keyword check - or not (depends on the section we are in; see above)
                    if (keywordsOnly)
                    {
                        if (!StartsWithKeyword(line, out var keyword))
                        {
                            continue;
                        }

                        int x = line.IndexOf(':');
                        if (x == -1)
                        {
                            // If there is no colon found (may happen occasionally) then simply remove the length of the keyword from the beginning
                            prefix = keyword;
                            msg    = line.Remove(0, prefix.Length).Trim();
                        }
                        else
                        {
                            prefix = line.Substring(0, x);
                            msg    = line.Substring(x + 1).Trim();
                        }

                        prefix = prefix.Trim().ToUpperInvariant();
                    }

                    // Parse each section
                    switch (section)
                    {
                    case CurrentSection.AHeader:
                    {
                        switch (prefix)
                        {
                        case "EINSATZNUMMER":
                            operation.OperationNumber = ParserUtility.GetTextBetween(msg, null, "ALARMZEIT");
                            operation.Timestamp       = ReadFaxTimestamp(ParserUtility.GetTextBetween(msg, "ALARMZEIT", null), DateTime.Now);
                            break;
                        }
                    }
                    break;

                    case CurrentSection.BMitteiler:
                    {
                        // This switch would not be necessary in this section (there is only "Name")...
                        switch (prefix)
                        {
                        case "NAME":
                            operation.Messenger = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.CEinsatzort:
                    {
                        switch (prefix)
                        {
                        case "STRAßE":
                        {
                            innerSection = InnerSection.AStraße;
                            ParserUtility.AnalyzeStreetLine(msg, out var street, out var streetNumber, out var appendix);
                            operation.CustomData["Einsatzort Zusatz"] = appendix;
                            operation.Einsatzort.Street       = street;
                            operation.Einsatzort.StreetNumber = streetNumber;
                        }
                        break;

                        case "ABSCHNITT":
                            break;

                        case "ORT":
                        {
                            innerSection = InnerSection.BOrt;
                            operation.Einsatzort.ZipCode = ReadZipCodeFromCity(msg);
                            if (string.IsNullOrWhiteSpace(operation.Einsatzort.ZipCode))
                            {
                                Logger.Instance.LogFormat(LogType.Warning, this, "Could not find a zip code for city '{0}'. Route planning may fail or yield wrong results!", operation.Einsatzort.City);
                            }

                            operation.Einsatzort.City = msg.Remove(0, operation.Einsatzort.ZipCode.Length).Trim();

                            // The City-text often contains a dash after which the administrative city appears multiple times (like "City A - City A City A").
                            // However we can (at least with google maps) omit this information without problems!
                            int dashIndex = operation.Einsatzort.City.IndexOf(" - ", StringComparison.Ordinal);
                            if (dashIndex != -1)
                            {
                                // Ignore everything after the dash
                                operation.Einsatzort.City = operation.Einsatzort.City.Substring(0, dashIndex).Trim();
                            }
                        }
                        break;

                        case "OBJEKT":
                            innerSection = InnerSection.CObjekt;
                            operation.Einsatzort.Property = msg;
                            break;

                        case "KREUZUNG":
                            operation.Einsatzort.Intersection = msg;
                            break;

                        case "STATION":
                            operation.CustomData.Add("Einsatzort Station:", msg);
                            break;

                        case "KOORDINATE":
                            Regex r       = new Regex(@"\d+");
                            var   matches = r.Matches(line);
                            if (matches.Count == 2)
                            {
                                int geoRechts = Convert.ToInt32(matches[0].Value);
                                int geoHoch   = Convert.ToInt32(matches[1].Value);
                                var geo       = GeographicCoords.FromGaussKrueger(geoRechts, geoHoch);
                                operation.Einsatzort.GeoLatitude  = geo.Latitude;
                                operation.Einsatzort.GeoLongitude = geo.Longitude;
                            }

                            break;

                        default:
                            switch (innerSection)
                            {
                            case InnerSection.AStraße:
                                //Quite dirty because of Streetnumber. Looking for better solution
                                operation.Einsatzort.Street += msg;
                                break;

                            case InnerSection.BOrt:
                                operation.Einsatzort.City += msg;
                                break;

                            case InnerSection.CObjekt:
                                operation.Einsatzort.Property += msg;
                                break;
                            }

                            break;
                        }
                    }
                    break;

                    case CurrentSection.DEinsatzgrund:
                    {
                        switch (prefix)
                        {
                        case "SCHLAGW.":
                            operation.Keywords.Keyword = msg;
                            break;

                        case "STICHWORT B":
                            operation.Keywords.B = ParserUtility.GetTextBetween(msg, null, "STICHWORT RD:");
                            operation.Keywords.R = ParserUtility.GetTextBetween(msg, "STICHWORT RD:", null);
                            break;

                        case "STICHWORT SO":
                            operation.Keywords.S = ParserUtility.GetTextBetween(msg, null, "STICHWORT TH:");
                            operation.Keywords.T = ParserUtility.GetTextBetween(msg, "STICHWORT TH:", "STICHWORT IN:");
                            operation.CustomData.Add("Stichwort IN:", ParserUtility.GetTextBetween(msg, "STICHWORT IN:", null));
                            break;

                        case "PRIO.":
                            operation.Priority = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.EEinsatzmittel:
                    {
                        switch (prefix)
                        {
                        case "EINSATZMITTELNAME":
                            operationResource.FullName = msg.Trim();
                            break;

                        case "GEF. GERÄTE":
                            // Only add to requested equipment if there is some text,
                            // otherwise the whole vehicle is the requested equipment
                            if (!string.IsNullOrWhiteSpace(msg))
                            {
                                operationResource.RequestedEquipment.Add(msg);
                            }

                            operation.Resources.Add(operationResource);
                            operationResource = new OperationResource();
                            break;
                        }
                    }
                    break;

                    case CurrentSection.FBemerkung:
                    {
                        // Append with newline at the end in case that the message spans more than one line
                        operation.Comment = operation.Comment.AppendLine(msg);
                    }
                    break;

                    case CurrentSection.GFooter:
                        // The footer can be ignored completely.
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, "Error while parsing line '{0}'. The error message was: {1}", i, ex.Message);
                }
            }

            return(operation);
        }
Пример #2
0
        Operation IParser.Parse(string[] lines)
        {
            Operation      operation = new Operation();
            CurrentSection section   = CurrentSection.Anfang;

            lines = Utilities.Trim(lines);
            string streetData  = string.Empty;
            string sectionData = string.Empty;

            foreach (var line in lines)
            {
                string keyword;

                if (ParserUtility.StartsWithKeyword(line, _keywords, out keyword))
                {
                    switch (keyword.Trim())
                    {
                    case "E-Nr": { section = CurrentSection.ENr; break; }

                    case "EINSATZORT": { section = CurrentSection.Einsatzort; break; }

                    case "STRAßE": { section = CurrentSection.Straße; break; }

                    case "ABSCHNITT": { section = CurrentSection.Abschnitt; break; }

                    case "KOORDINATEN": { section = CurrentSection.Koordinaten; break; }

                    case "ORTSTEIL/ORT":
                    case "ORTSTEIL / ORT": { section = CurrentSection.Ort; break; }

                    case "OBJEKT": { section = CurrentSection.Objekt; break; }

                    case "EINSATZPLAN": { section = CurrentSection.Einsatzplan; break; }

                    case "MELDEBILD": { section = CurrentSection.Meldebild; break; }

                    case "EINSATZSTICHWORT": { section = CurrentSection.Einsatzstichwort; break; }

                    case "HINWEIS": { section = CurrentSection.Hinweis; break; }

                    case "EINSATZMITTEL": { section = CurrentSection.Einsatzmittel; break; }

                    case "(ALARMSCHREIBEN ENDE)":
                    {
                        section = CurrentSection.Ende; break;
                    }
                    }
                }


                switch (section)
                {
                case CurrentSection.ENr:
                    string opnummer = ParserUtility.GetTextBetween(line, null, "ALARM");
                    string optime   = ParserUtility.GetTextBetween(line, "ALARM");
                    operation.OperationNumber = ParserUtility.GetMessageText(opnummer, keyword);
                    operation.Timestamp       = ParserUtility.ReadFaxTimestamp(optime, DateTime.Now);
                    break;

                case CurrentSection.Einsatzort:
                    operation.Zielort.Location = ParserUtility.GetMessageText(line, keyword);
                    break;

                case CurrentSection.Straße:
                    string msg = ParserUtility.GetMessageText(line, keyword);
                    streetData += msg;
                    break;

                case CurrentSection.Abschnitt:
                    sectionData += ParserUtility.GetMessageText(line, keyword);
                    break;

                case CurrentSection.Ort:
                    operation.Einsatzort.City = ParserUtility.GetMessageText(line, keyword);
                    if (operation.Einsatzort.City.Contains(" - "))
                    {
                        int i = operation.Einsatzort.City.IndexOf(" - ");
                        operation.Einsatzort.City = operation.Einsatzort.City.Substring(0, i).Trim();
                    }
                    break;

                case CurrentSection.Objekt:
                    operation.Einsatzort.Property += ParserUtility.GetMessageText(line, keyword);
                    break;

                case CurrentSection.Einsatzplan:
                    operation.OperationPlan = ParserUtility.GetMessageText(line, keyword);
                    break;

                case CurrentSection.Meldebild:
                    operation.Picture = operation.Picture.AppendLine(ParserUtility.GetMessageText(line, keyword));
                    break;

                case CurrentSection.Einsatzstichwort:
                    operation.Keywords.EmergencyKeyword = ParserUtility.GetMessageText(line, keyword);
                    break;

                case CurrentSection.Hinweis:
                    operation.Comment = operation.Comment.AppendLine(ParserUtility.GetMessageText(line, keyword));
                    break;

                case CurrentSection.Einsatzmittel:
                    if (line.Equals("EINSATZMITTEL: ", StringComparison.InvariantCultureIgnoreCase))
                    {
                        break;
                    }
                    OperationResource resource = new OperationResource();
                    if (line.Contains('('))
                    {
                        string tool = line.Substring(line.IndexOf("(", StringComparison.Ordinal) + 1);
                        tool = tool.Length >= 2 ? tool.Substring(0, tool.Length - 2).Trim() : String.Empty;
                        string unit = line.Substring(0, line.IndexOf("(", StringComparison.Ordinal));
                        resource.FullName = unit;
                        resource.RequestedEquipment.Add(tool);
                        operation.Resources.Add(resource);
                    }
                    break;

                case CurrentSection.Koordinaten:
                    string coords = ParserUtility.GetMessageText(line, keyword);
                    if (string.IsNullOrWhiteSpace(coords))
                    {
                        break;
                    }
                    double east  = double.Parse(coords.Split('/')[0], CultureInfo.InvariantCulture);
                    double north = double.Parse(coords.Split('/')[1], CultureInfo.InvariantCulture);
                    var    geo   = GeographicCoords.FromGaussKrueger(east, north);
                    operation.Einsatzort.GeoLatitude  = geo.Latitude;
                    operation.Einsatzort.GeoLongitude = geo.Longitude;
                    break;

                case CurrentSection.Ende:
                    break;
                }
            }
            string street, streetNumber, appendix;

            ParserUtility.AnalyzeStreetLine(streetData.Replace("1.2", ""), out street, out streetNumber, out appendix);
            operation.CustomData["Einsatzort Zusatz"] = appendix;
            operation.Einsatzort.Street       = street.Trim();
            operation.Einsatzort.StreetNumber = streetNumber;
            operation.Einsatzort.Intersection = sectionData;
            return(operation);
        }
Пример #3
0
        Operation IParser.Parse(string[] lines)
        {
            Operation         operation = new Operation();
            OperationResource last      = new OperationResource();

            lines = Utilities.Trim(lines);
            CurrentSection   section = CurrentSection.AHeader;
            bool             keywordsOnly = true;
            double           geoX = 0, geoY = 0;
            NumberFormatInfo nfi = new NumberFormatInfo {
                NumberDecimalSeparator = "."
            };

            for (int i = 0; i < lines.Length; i++)
            {
                try
                {
                    string line = lines[i];
                    if (line.Length == 0)
                    {
                        continue;
                    }
                    if (GetSection(line.Trim(), ref section, ref keywordsOnly))
                    {
                        continue;
                    }

                    string msg    = line;
                    string prefix = "";

                    // Make the keyword check - or not (depends on the section we are in; see above)
                    string keyword = "";
                    if (keywordsOnly)
                    {
                        if (!ParserUtility.StartsWithKeyword(line, _keywords, out keyword))
                        {
                            continue;
                        }

                        int x = line.IndexOf(':');
                        if (x == -1)
                        {
                            // If there is no colon found (may happen occasionally) then simply remove the length of the keyword from the beginning
                            prefix = keyword;
                            msg    = line.Remove(0, prefix.Length).Trim();
                        }
                        else
                        {
                            prefix = line.Substring(0, x);
                            msg    = line.Substring(x + 1).Trim();
                        }
                        prefix = prefix.Trim().ToUpperInvariant();
                    }

                    // Parse each section
                    switch (section)
                    {
                    case CurrentSection.AHeader:
                    {
                        switch (prefix)
                        {
                        case "EINSATZNUMMER":
                            operation.OperationNumber = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.CKoordinaten:
                        switch (prefix)
                        {
                        case "X":
                            geoX = double.Parse(msg, nfi);
                            break;

                        case "Y":
                            geoY = double.Parse(msg, nfi);
                            var geo = GeographicCoords.FromGaussKrueger(geoX, geoY);
                            operation.Einsatzort.GeoLatitude  = geo.Latitude;
                            operation.Einsatzort.GeoLongitude = geo.Longitude;
                            break;
                        }
                        break;

                    case CurrentSection.BMitteiler:
                        switch (prefix)
                        {
                        case "NAME":
                            operation.Messenger = msg;
                            break;

                        case "RUFNUMMER":
                            operation.Messenger = operation.Messenger.AppendLine(string.Format("Nr.: {0}", msg));
                            break;
                        }
                        break;

                    case CurrentSection.DEinsatzort:
                    {
                        switch (prefix)
                        {
                        case "STRAßE":
                            operation.Einsatzort.Street = msg;
                            break;

                        case "HAUS-NR.":
                            operation.Einsatzort.StreetNumber = msg;
                            break;

                        case "ORT":
                        {
                            operation.Einsatzort.ZipCode = ParserUtility.ReadZipCodeFromCity(msg);
                            if (!string.IsNullOrWhiteSpace(operation.Einsatzort.ZipCode))
                            {
                                operation.Einsatzort.City = msg.Replace(operation.Einsatzort.ZipCode, "").Trim();
                            }
                            else
                            {
                                operation.Einsatzort.City = msg;
                            }
                            // The City-text often contains a dash after which the administrative city appears multiple times (like "City A - City A City A").
                            // However we can (at least with google maps) omit this information without problems!
                            int dashIndex = operation.Einsatzort.City.IndexOf('-');
                            if (dashIndex != -1)
                            {
                                // Ignore everything after the dash
                                operation.Einsatzort.City = operation.Einsatzort.City.Substring(0, dashIndex);
                            }
                        }
                        break;

                        case "OBJEKT":
                            operation.Einsatzort.Property = msg;
                            break;

                        case "STATION":
                            operation.CustomData["Einsatzort Station"] = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.EZielort:
                    {
                        switch (prefix)
                        {
                        case "STRAßE":
                            operation.Zielort.Street = msg;
                            break;

                        case "HAUS-NR.":
                            operation.Zielort.StreetNumber = msg;
                            break;

                        case "ORT":
                            operation.Zielort.ZipCode = ParserUtility.ReadZipCodeFromCity(msg);
                            if (!string.IsNullOrWhiteSpace(operation.Zielort.ZipCode))
                            {
                                operation.Zielort.City = msg.Replace(operation.Zielort.ZipCode, "").Trim();
                            }
                            else
                            {
                                operation.Zielort.City = msg;
                            }
                            break;

                        case "OBJEKT":
                            operation.Zielort.Property = msg;
                            break;

                        case "STATION":
                            operation.CustomData["Zielort Station"] = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.FEinsatzgrund:
                    {
                        switch (prefix)
                        {
                        case "SCHLAGW.":
                            operation.Keywords.Keyword = msg;
                            break;

                        case "STICHWORT":
                            operation.Keywords.EmergencyKeyword = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.HEinsatzmittel:
                    {
                        switch (prefix)
                        {
                        case "NAME":
                            last.FullName = msg;
                            break;

                        case "GERÄT":
                            // Only add to requested equipment if there is some text,
                            // otherwise the whole vehicle is the requested equipment
                            if (!string.IsNullOrWhiteSpace(msg))
                            {
                                last.RequestedEquipment.Add(msg);
                            }
                            break;

                        case "ALARMIERT":
                            last.Timestamp = ParserUtility.TryGetTimestampFromMessage(msg, DateTime.Now).ToString();
                            operation.Resources.Add(last);
                            last = new OperationResource();
                            break;
                        }
                    }
                    break;

                    case CurrentSection.GBemerkungen:
                    {
                        operation.Picture = operation.Picture.AppendLine(msg);
                    }
                    break;

                    case CurrentSection.ZFooter:
                        // The footer can be ignored completely.
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, "Error while parsing line '{0}'. The error message was: {1}", i, ex.Message);
                }
            }
            return(operation);
        }
Пример #4
0
        Operation IParser.Parse(string[] lines)
        {
            Operation operation = new Operation();

            lines = Utilities.Trim(lines);

            CurrentSection section      = CurrentSection.AHeader;
            bool           keywordsOnly = true;

            for (int i = 0; i < lines.Length; i++)
            {
                try
                {
                    string line = lines[i];
                    if (line.Length == 0)
                    {
                        continue;
                    }

                    // Try to parse the header and extract date and time if possible
                    operation.Timestamp = ReadFaxTimestamp(line, operation.Timestamp);

                    if (GetSection(line.Trim(), ref section, ref keywordsOnly))
                    {
                        continue;
                    }

                    string msg    = line;
                    string prefix = "";

                    // Make the keyword check - or not (depends on the section we are in; see above)
                    if (keywordsOnly)
                    {
                        string keyword;
                        if (!StartsWithKeyword(line, out keyword))
                        {
                            continue;
                        }

                        int x = line.IndexOf(':');
                        if (x == -1)
                        {
                            // If there is no colon found (may happen occasionally) then simply remove the length of the keyword from the beginning
                            prefix = keyword;
                            msg    = line.Remove(0, prefix.Length).Trim();
                        }
                        else
                        {
                            prefix = line.Substring(0, x);
                            msg    = line.Substring(x + 1).Trim();
                        }

                        prefix = prefix.Trim().ToUpperInvariant();
                    }

                    // Parse each section
                    switch (section)
                    {
                    case CurrentSection.AHeader:
                    {
                        switch (prefix)
                        {
                        case "ABSENDER":
                            operation.CustomData["Absender"] = msg.Substring(0, msg.IndexOf("ALARMZEIT", StringComparison.InvariantCultureIgnoreCase));
                            String   dateString = msg.Substring(msg.IndexOf("ALARMZEIT", StringComparison.InvariantCultureIgnoreCase)).Trim().Remove(0, "ALARMZEIT".Length + 1).Trim();
                            DateTime time       = DateTime.Now;
                            DateTime.TryParse(dateString, out time);
                            operation.Timestamp = time;
                            break;

                        case "TERMIN":
                            operation.CustomData["Termin"] = msg;
                            break;

                        case "EINSATZNUMMER":
                            operation.OperationNumber = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.BMitteiler:
                    {
                        // This switch would not be necessary in this section (there is only "Name")...
                        switch (prefix)
                        {
                        case "NAME":
                            operation.Messenger = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.CEinsatzort:
                    {
                        switch (prefix)
                        {
                        case "STRAßE":
                        {
                            string street, streetNumber, appendix;
                            ParserUtility.AnalyzeStreetLine(msg, out street, out streetNumber, out appendix);
                            operation.CustomData["Einsatzort Zusatz"] = appendix;
                            operation.Einsatzort.Street       = street;
                            operation.Einsatzort.StreetNumber = streetNumber;
                        }
                        break;

                        case "ORT":
                        {
                            operation.Einsatzort.ZipCode = ParserUtility.ReadZipCodeFromCity(msg);
                            if (string.IsNullOrWhiteSpace(operation.Einsatzort.ZipCode))
                            {
                                Logger.Instance.LogFormat(LogType.Warning, this, "Could not find a zip code for city '{0}'. Route planning may fail or yield wrong results!", operation.Einsatzort.City);
                            }

                            operation.Einsatzort.City = msg.Remove(0, operation.Einsatzort.ZipCode.Length).Trim();

                            // The City-text often contains a dash after which the administrative city appears multiple times (like "City A - City A City A").
                            // However we can (at least with google maps) omit this information without problems!
                            int dashIndex = operation.Einsatzort.City.IndexOf(" - ");
                            if (dashIndex != -1)
                            {
                                // Ignore everything after the dash
                                operation.Einsatzort.City = operation.Einsatzort.City.Substring(0, dashIndex).Trim();
                            }
                        }
                        break;

                        case "ABSCHNITT":
                        case "KREUZUNG":
                            operation.Einsatzort.Intersection += msg;
                            break;

                        case "OBJEKT":
                            operation.Einsatzort.Property = msg;
                            break;

                        case "STATION":
                            operation.CustomData["Einsatzort Station"] = msg;
                            break;

                        case "KOORDINATE":
                            Regex r       = new Regex(@"[\d\.]+");
                            var   matches = r.Matches(line);
                            if (matches.Count == 2)
                            {
                                int geoRechts = Convert.ToInt32(matches[0].Value);
                                int geoHoch   = Convert.ToInt32(matches[1].Value);
                                var geo       = GeographicCoords.FromGaussKrueger(geoRechts, geoHoch);
                                operation.Einsatzort.GeoLatitude  = geo.Latitude;
                                operation.Einsatzort.GeoLongitude = geo.Longitude;
                            }
                            break;

                        case "ABTEILUNG":
                        case "ZUSTÄNDIGE ILS":

                            //These fields are currently unassigned. If required this can be done.
                            break;
                        }
                    }
                    break;

                    case CurrentSection.DZielort:
                    {
                        switch (prefix)
                        {
                        case "STRAßE":
                        {
                            string street, streetNumber, appendix;
                            ParserUtility.AnalyzeStreetLine(msg, out street, out streetNumber, out appendix);
                            operation.CustomData["Zielort Zusatz"] = appendix;
                            operation.Zielort.Street       = street;
                            operation.Zielort.StreetNumber = streetNumber;
                        }
                        break;

                        case "ORT":
                        {
                            string plz = ParserUtility.ReadZipCodeFromCity(msg);
                            operation.Zielort.ZipCode = plz;
                            operation.Zielort.City    = msg.Remove(0, plz.Length).Trim();
                        }
                        break;

                        case "OBJEKT":
                            operation.Zielort.Property = msg;
                            break;

                        case "STATION":
                            operation.CustomData["Zielort Station"] = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.EEinsatzgrund:
                    {
                        switch (prefix)
                        {
                        case "SCHLAGWORT":
                            operation.Keywords.Keyword          = msg.Substring(0, msg.IndexOf("STICHWORT", StringComparison.InvariantCultureIgnoreCase));
                            operation.Keywords.EmergencyKeyword = msg.Substring(msg.IndexOf("STICHWORT", StringComparison.InvariantCultureIgnoreCase)).Trim().Remove(0, "STICHWORT".Length + 1).Trim();
                            break;

                        case "PRIO.":
                            operation.Priority = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.FEinsatzmittel:
                    {
                        if (line.StartsWith("NAME", StringComparison.CurrentCultureIgnoreCase))
                        {
                            //Thats the line "Name : Alarmiert : Aus : AN". Should be ignored.
                        }
                        else
                        {
                            operation.Resources.Add(new OperationResource {
                                    FullName = msg.Replace(':', ' ').Trim()
                                });
                        }
                    }
                    break;

                    case CurrentSection.Objektinfo:
                        operation.CustomData["Objektinfo"] += line;
                        break;

                    case CurrentSection.GBemerkung:
                    {
                        operation.Comment = operation.Comment.AppendLine(msg);
                    }
                    break;

                    case CurrentSection.HFooter:
                        // The footer can be ignored completely.
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, "Error while parsing line '{0}'. The error message was: {1}", i, ex.Message);
                }
            }
            return(operation);
        }
Пример #5
0
        Operation IParser.Parse(string[] lines)
        {
            Operation operation = new Operation();

            lines = Utilities.Trim(lines);

            CurrentSection section      = CurrentSection.AHeader;
            bool           keywordsOnly = true;

            InnerSection innerSection = InnerSection.AStraße;

            for (int i = 0; i < lines.Length; i++)
            {
                try
                {
                    string line = lines[i];
                    if (line.Length == 0)
                    {
                        continue;
                    }

                    // Try to parse the header and extract date and time if possible
                    operation.Timestamp = ParserUtility.ReadFaxTimestamp(line, operation.Timestamp);


                    if (GetSection(line.Trim(), ref section, ref keywordsOnly))
                    {
                        continue;
                    }

                    string msg    = line;
                    string prefix = "";

                    // Make the keyword check - or not (depends on the section we are in; see above)
                    if (keywordsOnly)
                    {
                        string keyword;
                        if (!ParserUtility.StartsWithKeyword(line, Keywords, out keyword))
                        {
                            continue;
                        }

                        int x = line.IndexOf(':');
                        if (x == -1)
                        {
                            // If there is no colon found (may happen occasionally) then simply remove the length of the keyword from the beginning
                            prefix = keyword;
                            msg    = line.Remove(0, prefix.Length).Trim();
                        }
                        else
                        {
                            prefix = line.Substring(0, x);
                            msg    = line.Substring(x + 1).Trim();
                        }

                        prefix = prefix.Trim().ToUpperInvariant();
                    }

                    // Parse each section
                    switch (section)
                    {
                    case CurrentSection.AHeader:
                        //TODO: Absender unterbringen
                        break;

                    case CurrentSection.BMitteiler:
                    {
                        // This switch would not be necessary in this section (there is only "Name")...
                        switch (prefix)
                        {
                        case "NAME":
                            operation.Messenger = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.CEinsatzort:
                    {
                        switch (prefix)
                        {
                        case "STRAßE":
                        {
                            innerSection = InnerSection.AStraße;
                            string street, streetNumber, appendix;
                            ParserUtility.AnalyzeStreetLine(msg, out street, out streetNumber, out appendix);
                            operation.CustomData["Einsatzort Zusatz"] = appendix;
                            operation.Einsatzort.Street       = street;
                            operation.Einsatzort.StreetNumber = streetNumber;
                        }
                        break;

                        case "ORT":
                        {
                            innerSection = InnerSection.BOrt;
                            operation.Einsatzort.ZipCode = ParserUtility.ReadZipCodeFromCity(msg);
                            if (string.IsNullOrWhiteSpace(operation.Einsatzort.ZipCode))
                            {
                                Logger.Instance.LogFormat(LogType.Warning, this, "Could not find a zip code for city '{0}'. Route planning may fail or yield wrong results!", operation.Einsatzort.City);
                            }

                            operation.Einsatzort.City = msg.Remove(0, operation.Einsatzort.ZipCode.Length).Trim();

                            // The City-text often contains a dash after which the administrative city appears multiple times (like "City A - City A City A").
                            // However we can (at least with google maps) omit this information without problems!
                            int dashIndex = operation.Einsatzort.City.IndexOf(" - ");
                            if (dashIndex != -1)
                            {
                                // Ignore everything after the dash
                                operation.Einsatzort.City = operation.Einsatzort.City.Substring(0, dashIndex).Trim();
                            }
                        }
                        break;

                        case "OBJEKT":
                            innerSection = InnerSection.CObjekt;
                            operation.Einsatzort.Property = msg;
                            break;

                        case "KREUZUNG":
                            operation.Einsatzort.Intersection = msg;
                            break;

                        case "KOORDINATE":
                            Regex r       = new Regex(@"(\d+\.\d+)");
                            var   matches = r.Matches(line);
                            if (matches.Count == 2)
                            {
                                NumberFormatInfo nfi = new NumberFormatInfo {
                                    NumberDecimalSeparator = "."
                                };
                                double geoRechts = Convert.ToDouble(matches[0].Value, nfi);
                                double geoHoch   = Convert.ToDouble(matches[1].Value, nfi);
                                var    geo       = GeographicCoords.FromGaussKrueger(geoRechts, geoHoch);
                                operation.Einsatzort.GeoLatitude  = geo.Latitude;
                                operation.Einsatzort.GeoLongitude = geo.Longitude;
                            }
                            break;

                        default:
                            switch (innerSection)
                            {
                            case InnerSection.AStraße:
                                //Quite dirty because of Streetnumber. Looking for better solution
                                operation.Einsatzort.Street += msg;
                                break;

                            case InnerSection.BOrt:
                                operation.Einsatzort.City += msg;
                                break;

                            case InnerSection.CObjekt:
                                operation.Einsatzort.Property += msg;
                                break;
                            }
                            break;
                        }
                    }
                    break;

                    case CurrentSection.DZielort:
                        switch (prefix)
                        {
                        case "STRAßE":
                        {
                            innerSection = InnerSection.AStraße;

                            string street, streetNumber, appendix;
                            ParserUtility.AnalyzeStreetLine(msg, out street, out streetNumber, out appendix);
                            operation.CustomData["Zielort Zusatz"] = appendix;
                            operation.Zielort.Street       = street;
                            operation.Zielort.StreetNumber = streetNumber;
                        }
                        break;

                        case "ORT":
                        {
                            innerSection = InnerSection.BOrt;
                            operation.Zielort.ZipCode = ParserUtility.ReadZipCodeFromCity(msg);
                            if (string.IsNullOrWhiteSpace(operation.Zielort.ZipCode))
                            {
                                Logger.Instance.LogFormat(LogType.Warning, this, "Could not find a zip code for city '{0}'. Route planning may fail or yield wrong results!", operation.Zielort.City);
                            }

                            operation.Zielort.City = msg.Remove(0, operation.Zielort.ZipCode.Length).Trim();
                        }
                        break;

                        case "OBJEKT":
                            innerSection = InnerSection.CObjekt;
                            operation.Zielort.Property = msg;
                            break;

                        default:
                            switch (innerSection)
                            {
                            case InnerSection.AStraße:
                                //Quite dirty because of Streetnumber. Looking for better solution
                                operation.Einsatzort.Street += msg;
                                break;

                            case InnerSection.BOrt:
                                operation.Einsatzort.City += msg;
                                break;

                            case InnerSection.CObjekt:
                                operation.Einsatzort.Property += msg;
                                break;
                            }
                            break;
                        }
                        break;

                    case CurrentSection.EEinsatzgrund:
                    {
                        switch (prefix)
                        {
                        case "SCHLAGW.":
                            operation.Keywords.Keyword = msg;
                            break;

                        case "STICHWORT":
                            operation.Keywords.EmergencyKeyword = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.FEinsatzmittel:
                    {
                        operation.Resources.Add(new OperationResource {
                                FullName = msg.Substring(0, msg.LastIndexOf('('))
                            });
                    }
                    break;

                    case CurrentSection.GBemerkung:
                    {
                        // Append with newline at the end in case that the message spans more than one line
                        operation.Comment = operation.Comment.AppendLine(msg);
                    }
                    break;

                    case CurrentSection.HFooter:
                        // The footer can be ignored completely.
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, "Error while parsing line '{0}'. The error message was: {1}", i, ex.Message);
                }
            }
            return(operation);
        }
Пример #6
0
        Operation IParser.Parse(string[] lines)
        {
            Operation         operation = new Operation();
            OperationResource last      = new OperationResource();

            lines = Utilities.Trim(lines);
            CurrentSection section      = CurrentSection.AHeader;
            bool           keywordsOnly = true;

            for (int i = 0; i < lines.Length; i++)
            {
                try
                {
                    string line = lines[i];
                    if (line.Length == 0)
                    {
                        continue;
                    }
                    if (GetSection(line.Trim(), ref section, ref keywordsOnly))
                    {
                        if (section == CurrentSection.CEinsatzort)
                        {
                            Regex r       = new Regex(@"\d+");
                            var   matches = r.Matches(line);
                            if (matches.Count == 2)
                            {
                                int geoRechts = Convert.ToInt32(matches[0].Value);
                                int geoHoch   = Convert.ToInt32(matches[1].Value);
                                var geo       = GeographicCoords.FromGaussKrueger(geoRechts, geoHoch);
                                operation.Einsatzort.GeoLatitude  = geo.Latitude;
                                operation.Einsatzort.GeoLongitude = geo.Longitude;
                            }
                        }

                        continue;
                    }

                    string msg    = line;
                    string prefix = "";

                    // Make the keyword check - or not (depends on the section we are in; see above)
                    string keyword = "";
                    if (keywordsOnly)
                    {
                        if (!ParserUtility.StartsWithKeyword(line, _keywords, out keyword))
                        {
                            continue;
                        }

                        int x = line.IndexOf(':');
                        if (x == -1)
                        {
                            // If there is no colon found (may happen occasionally) then simply remove the length of the keyword from the beginning
                            prefix = keyword;
                            msg    = line.Remove(0, prefix.Length).Trim();
                        }
                        else
                        {
                            prefix = line.Substring(0, x);
                            msg    = line.Substring(x + 1).Trim();
                        }
                        prefix = prefix.Trim().ToUpperInvariant();
                    }

                    // Parse each section
                    switch (section)
                    {
                    case CurrentSection.AHeader:
                    {
                        switch (prefix)
                        {
                        case "EINSATZ-NR.":
                            operation.OperationNumber = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.BMitteiler:
                        operation.Messenger = msg;
                        break;

                    case CurrentSection.CEinsatzort:
                    {
                        switch (prefix)
                        {
                        case "STRAßE":
                        {
                            string street, streetNumber, appendix;
                            ParserUtility.AnalyzeStreetLine(msg, out street, out streetNumber, out appendix);
                            operation.CustomData["Einsatzort Zusatz"] = appendix;
                            operation.Einsatzort.Street       = street;
                            operation.Einsatzort.StreetNumber = streetNumber;
                        }
                        break;

                        case "GEMEINDE":
                        {
                            operation.Einsatzort.ZipCode = ParserUtility.ReadZipCodeFromCity(msg);
                            if (string.IsNullOrWhiteSpace(operation.Einsatzort.ZipCode))
                            {
                                Logger.Instance.LogFormat(LogType.Warning, this, "Could not find a zip code for city '{0}'. Route planning may fail or yield wrong results!", operation.Einsatzort.City);
                            }

                            operation.Einsatzort.City = msg.Remove(0, operation.Einsatzort.ZipCode.Length).Trim();

                            // The City-text often contains a dash after which the administrative city appears multiple times (like "City A - City A City A").
                            // However we can (at least with google maps) omit this information without problems!
                            int dashIndex = operation.Einsatzort.City.IndexOf(" - ");
                            if (dashIndex != -1)
                            {
                                // Ignore everything after the dash
                                operation.Einsatzort.City = operation.Einsatzort.City.Substring(0, dashIndex).Trim();
                            }
                        }
                        break;

                        case "OBJEKT":
                            operation.Einsatzort.Property = msg;
                            break;

                        case "KREUZUNG":
                            operation.Einsatzort.Intersection = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.DEinsatzgrund:
                    {
                        switch (prefix)
                        {
                        case "SCHLAGW.":
                            operation.Keywords.Keyword = msg;
                            break;

                        case "STICHWORT":
                            operation.Keywords.EmergencyKeyword = msg;
                            break;

                        case "PRIORITÄT":
                            operation.Priority = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.EEinsatzmittel:
                    {
                        switch (prefix)
                        {
                        case "NAME":
                            last.FullName = msg;
                            break;

                        case "ALARMIERT":
                            msg            = ParserUtility.GetTextBetween(msg, null, "AUS");
                            last.Timestamp = ParserUtility.TryGetTimestampFromMessage(msg, DateTime.Now).ToString();
                            break;

                        case "GEF. GERÄT":
                            // Only add to requested equipment if there is some text,
                            // otherwise the whole vehicle is the requested equipment
                            if (!string.IsNullOrWhiteSpace(msg))
                            {
                                last.RequestedEquipment.Add(msg);
                            }

                            operation.Resources.Add(last);
                            last = new OperationResource();
                            break;
                        }
                    }
                    break;

                    case CurrentSection.FBemerkung:
                    {
                        // Append with newline at the end in case that the message spans more than one line
                        operation.Picture += msg + Environment.NewLine;
                    }
                    break;

                    case CurrentSection.GHinweis:
                    {
                        // Append with newline at the end in case that the message spans more than one line
                        operation.Comment = operation.Comment.AppendLine(msg);
                    }
                    break;

                    case CurrentSection.HFooter:
                        // The footer can be ignored completely.
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, "Error while parsing line '{0}'. The error message was: {1}", i, ex.Message);
                }
            }
            return(operation);
        }
Пример #7
0
        Operation IParser.Parse(string[] lines)
        {
            Operation         operation = new Operation();
            OperationResource last      = new OperationResource();

            lines = Utilities.Trim(lines);
            int            rechts = 0, hoch = 0;
            bool           keywordsOnly = true;
            CurrentSection section      = CurrentSection.AHeader;

            for (int i = 0; i < lines.Length; i++)
            {
                try
                {
                    string line = lines[i];
                    if (line.Length == 0)
                    {
                        continue;
                    }



                    if (GetSection(line.Trim(), ref section, ref keywordsOnly))
                    {
                        continue;
                    }

                    string msg    = line;
                    string prefix = "";

                    // Make the keyword check - or not (depends on the section we are in; see above)
                    if (keywordsOnly)
                    {
                        string keyword;
                        if (!ParserUtility.StartsWithKeyword(line, Keywords, out keyword))
                        {
                            continue;
                        }

                        int x = line.IndexOf(':');
                        if (x == -1)
                        {
                            // If there is no colon found (may happen occasionally) then simply remove the length of the keyword from the beginning
                            prefix = keyword;
                            msg    = line.Remove(0, prefix.Length).Trim();
                        }
                        else
                        {
                            prefix = line.Substring(0, x);
                            msg    = line.Substring(x + 1).Trim();
                        }

                        prefix = prefix.Trim().ToUpperInvariant();
                    }

                    // Parse each section
                    switch (section)
                    {
                    case CurrentSection.AHeader:
                    {
                        switch (prefix)
                        {
                        case "ABSENDER":
                            operation.CustomData["Absender"] = msg;
                            break;

                        case "TERMIN":
                            operation.CustomData["Termin"] = msg;
                            break;

                        case "EINSATZNUMMER":
                            // Try to parse the header and extract date and time if possible
                            operation.Timestamp = ParserUtility.ReadFaxTimestamp(line, operation.Timestamp);
                            if (msg.ToUpperInvariant().Contains("ALARMZEIT"))
                            {
                                msg = msg.Substring(0, msg.ToUpperInvariant().IndexOf("ALARMZEIT")).Trim();
                            }
                            operation.OperationNumber = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.BMitteiler:
                    {
                        // This switch would not be necessary in this section (there is only "Name")...
                        switch (prefix)
                        {
                        case "NAME":
                            operation.Messenger = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.CEinsatzort:
                    {
                        switch (prefix)
                        {
                        case "STRAßE":
                        {
                            string street, streetNumber, appendix;
                            ParserUtility.AnalyzeStreetLine(msg, out street, out streetNumber, out appendix);
                            operation.CustomData["Einsatzort Zusatz"] = appendix;
                            operation.Einsatzort.Street       = street;
                            operation.Einsatzort.StreetNumber = streetNumber;
                        }
                        break;

                        case "ABSCHNITT":
                            break;

                        case "ORT":
                        {
                            operation.Einsatzort.ZipCode = ParserUtility.ReadZipCodeFromCity(msg);
                            if (string.IsNullOrWhiteSpace(operation.Einsatzort.ZipCode))
                            {
                                Logger.Instance.LogFormat(LogType.Warning, this, "Could not find a zip code for city '{0}'. Route planning may fail or yield wrong results!", operation.Einsatzort.City);
                            }

                            operation.Einsatzort.City = msg.Remove(0, operation.Einsatzort.ZipCode.Length).Trim();

                            // The City-text often contains a dash after which the administrative city appears multiple times (like "City A - City A City A").
                            // However we can (at least with google maps) omit this information without problems!
                            int dashIndex = operation.Einsatzort.City.IndexOf(" - ");
                            if (dashIndex != -1)
                            {
                                // Ignore everything after the dash
                                operation.Einsatzort.City = operation.Einsatzort.City.Substring(0, dashIndex).Trim();
                            }
                        }
                        break;

                        case "OBJEKT":
                            operation.Einsatzort.Property = msg;
                            break;

                        case "KREUZUNG":
                            operation.Einsatzort.Intersection = msg;
                            break;

                        case "STATION":
                            operation.CustomData["Einsatzort Station"] = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.EEinsatzgrund:
                    {
                        switch (prefix)
                        {
                        case "SCHLAGW.":
                            operation.Keywords.Keyword = msg;
                            break;

                        case "STICHWORT B":
                            operation.Keywords.B = ParserUtility.GetTextBetween(msg, null, "STICHWORT RD:");
                            operation.Keywords.R = ParserUtility.GetTextBetween(msg, "STICHWORT RD:", "STICHWORT ABC:");
                            operation.CustomData["Stichwort ABC"] = ParserUtility.GetTextBetween(msg, "STICHWORT ABC:");
                            break;

                        case "STICHWORT SO":
                            operation.Keywords.S = ParserUtility.GetTextBetween(msg, null, "STICHWORT TH:");
                            operation.Keywords.T = ParserUtility.GetTextBetween(msg, "STICHWORT TH:", "STICHWORT IN:");
                            operation.CustomData["Stichwort IN"] = ParserUtility.GetTextBetween(msg, "STICHWORT IN:");
                            break;

                        case "PRIO.":
                            operation.Priority = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.FEinsatzmittel:
                    {
                        switch (prefix)
                        {
                        case "EINSATZMITTELNAME":
                            last.FullName = msg.Trim();
                            break;

                        case "GEF. GERÄTE":
                            // Only add to requested equipment if there is some text,
                            // otherwise the whole vehicle is the requested equipment
                            if (!string.IsNullOrWhiteSpace(msg))
                            {
                                last.RequestedEquipment.Add(msg);
                            }
                            // This line will end the construction of this resource. Add it to the list and go to the next.
                            operation.Resources.Add(last);

                            last = new OperationResource();
                            break;
                        }
                    }
                    break;

                    case CurrentSection.GBemerkung:
                    {
                        // Append with newline at the end in case that the message spans more than one line
                        operation.Comment = operation.Comment.AppendLine(msg);
                    }
                    break;

                    case CurrentSection.HKoordinaten:
                    {
                        switch (prefix)
                        {
                        case "RECHTSWERT":
                            rechts = int.Parse(msg);
                            break;

                        case "HOCHWERT":
                            hoch = int.Parse(msg);
                            break;
                        }
                    }
                    break;

                    case CurrentSection.IFooter:
                        // The footer can be ignored completely.
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, "Error while parsing line '{0}'. The error message was: {1}", i, ex.Message);
                }
            }

            var geo = GeographicCoords.FromGaussKrueger(rechts, hoch);;

            operation.Einsatzort.GeoLatitude  = geo.Latitude;
            operation.Einsatzort.GeoLongitude = geo.Longitude;
            return(operation);
        }
Пример #8
0
        Operation IParser.Parse(string[] lines)
        {
            Operation operation = new Operation();

            lines = Utilities.Trim(lines);

            OperationResource last    = new OperationResource();
            CurrentSection    section = CurrentSection.AHeader;
            bool keywordsOnly         = true;

            InnerSection innerSection = InnerSection.AStraße;

            for (int i = 0; i < lines.Length; i++)
            {
                try
                {
                    string line = lines[i];
                    if (line.Length == 0)
                    {
                        continue;
                    }

                    // Try to parse the header and extract date and time if possible
                    operation.Timestamp = ParserUtility.ReadFaxTimestamp(line, operation.Timestamp);


                    if (GetSection(line.Trim(), ref section, ref keywordsOnly))
                    {
                        continue;
                    }

                    string msg    = line;
                    string prefix = "";

                    // Make the keyword check - or not (depends on the section we are in; see above)
                    if (keywordsOnly)
                    {
                        string keyword;
                        if (!ParserUtility.StartsWithKeyword(line, Keywords, out keyword))
                        {
                            continue;
                        }

                        int x = line.IndexOf(':');
                        if (x == -1)
                        {
                            // If there is no colon found (may happen occasionally) then simply remove the length of the keyword from the beginning
                            prefix = keyword;
                            msg    = line.Remove(0, prefix.Length).Trim();
                        }
                        else
                        {
                            prefix = line.Substring(0, x);
                            msg    = line.Substring(x + 1).Trim();
                        }

                        prefix = prefix.Trim().ToUpperInvariant();
                    }

                    // Parse each section
                    switch (section)
                    {
                    case CurrentSection.AHeader:
                    {
                        switch (prefix)
                        {
                        case "ABSENDER":
                            operation.CustomData["Absender"] = msg;
                            break;

                        case "TERMIN":
                            operation.CustomData["Termin"] = msg;
                            break;

                        case "EINSATZNUMMER":
                            operation.OperationNumber = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.BMitteiler:
                    {
                        // This switch would not be necessary in this section (there is only "Name")...
                        switch (prefix)
                        {
                        case "NAME":
                            operation.Messenger = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.CEinsatzort:
                    {
                        switch (prefix)
                        {
                        case "STRAßE":
                        {
                            innerSection = InnerSection.AStraße;
                            string street, streetNumber, appendix;
                            ParserUtility.AnalyzeStreetLine(msg, out street, out streetNumber, out appendix);
                            operation.CustomData["Einsatzort Zusatz"] = appendix;
                            operation.Einsatzort.Street       = street;
                            operation.Einsatzort.StreetNumber = streetNumber;
                        }
                        break;

                        case "ORT":
                        {
                            innerSection = InnerSection.BOrt;
                            operation.Einsatzort.ZipCode = ParserUtility.ReadZipCodeFromCity(msg);
                            if (string.IsNullOrWhiteSpace(operation.Einsatzort.ZipCode))
                            {
                                Logger.Instance.LogFormat(LogType.Warning, this, "Could not find a zip code for city '{0}'. Route planning may fail or yield wrong results!", operation.Einsatzort.City);
                            }

                            operation.Einsatzort.City = msg.Remove(0, operation.Einsatzort.ZipCode.Length).Trim();

                            // The City-text often contains a dash after which the administrative city appears multiple times (like "City A - City A City A").
                            // However we can (at least with google maps) omit this information without problems!
                            int dashIndex = operation.Einsatzort.City.IndexOf(" - ");
                            if (dashIndex != -1)
                            {
                                // Ignore everything after the dash
                                operation.Einsatzort.City = operation.Einsatzort.City.Substring(0, dashIndex).Trim();
                            }
                        }
                        break;

                        case "OBJEKT":
                            innerSection = InnerSection.CObjekt;
                            operation.Einsatzort.Property = msg;
                            break;

                        case "STATION":
                            innerSection = InnerSection.DStation;
                            operation.CustomData["Einsatzort Station"] = msg;
                            break;

                        case "KOORDINATEN":
                            Match result = r.Match(msg);
                            if (result.Success)
                            {
                                double geoX = 0, geoY = 0;
                                geoX = double.Parse(result.Groups[1].Value, CultureInfo.InvariantCulture);
                                geoY = double.Parse(result.Groups[2].Value, CultureInfo.InvariantCulture);
                                var geo = GeographicCoords.FromGaussKrueger(geoX, geoY);
                                operation.Einsatzort.GeoLatitude  = geo.Latitude;
                                operation.Einsatzort.GeoLongitude = geo.Longitude;
                            }
                            break;

                        default:
                            switch (innerSection)
                            {
                            case InnerSection.AStraße:
                                //Quite dirty because of Streetnumber. Looking for better solution
                                operation.Einsatzort.Street += msg;
                                break;

                            case InnerSection.BOrt:
                                operation.Einsatzort.City += msg;
                                break;

                            case InnerSection.CObjekt:
                                operation.Einsatzort.Property += msg;
                                break;

                            case InnerSection.DStation:
                                operation.CustomData["Einsatzort Station"] += msg;
                                break;
                            }
                            break;
                        }
                    }
                    break;

                    case CurrentSection.EEinsatzgrund:
                    {
                        switch (prefix)
                        {
                        case "SCHLAGW.":
                            operation.Keywords.Keyword = msg;
                            break;

                        case "STICHWORT B":
                            operation.Keywords.B = msg;
                            break;

                        case "STICHWORT T":
                            operation.Keywords.T = msg;
                            break;

                        case "STICHWORT S":
                            operation.Keywords.S = msg;
                            break;

                        case "STICHWORT R":
                            operation.Keywords.R = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.FEinsatzmittel:
                    {
                        switch (prefix)
                        {
                        case "NAME": last.FullName = msg.Trim();
                            break;

                        case "GEF. GERÄT":
                            // Only add to requested equipment if there is some text,
                            // otherwise the whole vehicle is the requested equipment
                            if (!string.IsNullOrWhiteSpace(msg))
                            {
                                last.RequestedEquipment.Add(msg);
                            }
                            break;

                        case "ALARMIERT":
                            last.Timestamp = ParserUtility.TryGetTimestampFromMessage(msg, DateTime.Now).ToString();
                            // This line will end the construction of this resource. Add it to the list and go to the next.
                            operation.Resources.Add(last);
                            last = new OperationResource();
                            break;
                        }
                    }
                    break;

                    case CurrentSection.GBemerkung:
                    {
                        // Append with newline at the end in case that the message spans more than one line
                        operation.Comment = operation.Comment.AppendLine(msg);
                    }
                    break;

                    case CurrentSection.HFooter:
                        // The footer can be ignored completely.
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, "Error while parsing line '{0}'. The error message was: {1}", i, ex.Message);
                }
            }
            return(operation);
        }
Пример #9
0
        Operation IParser.Parse(string[] lines)
        {
            Operation         operation = new Operation();
            OperationResource last      = new OperationResource();

            lines = Utilities.Trim(lines);
            NumberFormatInfo nfi = new NumberFormatInfo {
                NumberDecimalSeparator = "."
            };
            CurrentSection section      = CurrentSection.AHeader;
            bool           keywordsOnly = true;

            for (int i = 0; i < lines.Length; i++)
            {
                try
                {
                    string line = lines[i];
                    if (line.Length == 0)
                    {
                        continue;
                    }

                    if (GetSection(line.Trim(), ref section, ref keywordsOnly))
                    {
                        continue;
                    }
                    string msg    = line;
                    string prefix = "";

                    // Make the keyword check - or not (depends on the section we are in; see above)
                    if (keywordsOnly)
                    {
                        string keyword;
                        if (!ParserUtility.StartsWithKeyword(line, Keywords, out keyword))
                        {
                            continue;
                        }

                        int x = line.IndexOf(':');
                        if (x == -1)
                        {
                            // If there is no colon found (may happen occasionally) then simply remove the length of the keyword from the beginning
                            prefix = keyword;
                            msg    = line.Remove(0, prefix.Length).Trim();
                        }
                        else
                        {
                            prefix = line.Substring(0, x);
                            msg    = line.Substring(x + 1).Trim();
                        }

                        prefix = prefix.Trim().ToUpperInvariant();
                    }

                    // Parse each section
                    switch (section)
                    {
                    case CurrentSection.AHeader:
                    {
                        switch (prefix)
                        {
                        case "ABSENDER":
                            operation.CustomData["Absender"] = msg;
                            break;

                        case "EINSATZNUMMER":
                            operation.OperationNumber = ParserUtility.GetTextBetween(msg, null, "Alarmzeit:");
                            string timestamp = ParserUtility.GetTextBetween(msg, "Alarmzeit:");
                            operation.Timestamp = ParserUtility.ReadFaxTimestamp(timestamp, DateTime.Now);
                            break;
                        }
                    }
                    break;

                    case CurrentSection.BMitteiler:
                    {
                        // This switch would not be necessary in this section (there is only "Name")...
                        switch (prefix)
                        {
                        case "NAME":
                            operation.Messenger = msg;
                            break;

                        case "TELEFON":
                            operation.Messenger = string.Format("{0} Telefon: {1}", operation.Messenger, msg);
                            break;
                        }
                    }
                    break;

                    case CurrentSection.CEinsatzort:
                    {
                        switch (prefix)
                        {
                        case "STRAßE":
                        {
                            string street, streetNumber, appendix;
                            ParserUtility.AnalyzeStreetLine(msg, out street, out streetNumber, out appendix);
                            operation.CustomData["Einsatzort Zusatz"] = appendix;
                            operation.Einsatzort.Street       = street;
                            operation.Einsatzort.StreetNumber = streetNumber;
                        }
                        break;

                        case "ABSCHNITT":
                            operation.CustomData["Einsatzort Abschnitt"] = msg;
                            break;

                        case "ORT":
                        {
                            operation.Einsatzort.ZipCode = ParserUtility.ReadZipCodeFromCity(msg);
                            if (string.IsNullOrWhiteSpace(operation.Einsatzort.ZipCode))
                            {
                                Logger.Instance.LogFormat(LogType.Warning, this, "Could not find a zip code for city '{0}'. Route planning may fail or yield wrong results!", operation.Einsatzort.City);
                            }

                            operation.Einsatzort.City = msg.Remove(0, operation.Einsatzort.ZipCode.Length).Trim();

                            // The City-text often contains a dash after which the administrative city appears multiple times (like "City A - City A City A").
                            // However we can (at least with google maps) omit this information without problems!
                            int dashIndex = operation.Einsatzort.City.IndexOf(" - ");
                            if (dashIndex != -1)
                            {
                                // Ignore everything after the dash
                                operation.Einsatzort.City = operation.Einsatzort.City.Substring(0, dashIndex).Trim();
                            }
                        }
                        break;

                        case "OBJEKT":
                            operation.Einsatzort.Property = msg;
                            break;

                        case "KREUZUNG":
                            operation.Einsatzort.Intersection = msg;
                            break;

                        case "STATION":
                            operation.CustomData["Einsatzort Station"] = ParserUtility.GetTextBetween(msg, null, "Objektnummer");
                            operation.OperationPlan = ParserUtility.GetMessageText(ParserUtility.GetTextBetween(msg, "Objektnummer"), "");
                            break;

                        case "Einsatzort Position X":
                            geoX = double.Parse(msg, nfi);
                            break;

                        case "Einsatzort Position Y":
                            geoY = double.Parse(msg, nfi);
                            var geo = GeographicCoords.FromGaussKrueger(geoX, geoY);
                            operation.Einsatzort.GeoLatitude  = geo.Latitude;
                            operation.Einsatzort.GeoLongitude = geo.Longitude;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.DEinsatzgrund:
                    {
                        switch (prefix)
                        {
                        case "SCHLAGWORT.":
                            operation.Keywords.Keyword = msg;
                            break;

                        case "- BRAND":
                            operation.Keywords.B = msg;
                            break;

                        case "- RETTUNGSDIENST":
                            operation.Keywords.R = msg;
                            break;

                        case "- SONSTIGES":
                            operation.Keywords.S = msg;
                            break;

                        case "- THL":
                            operation.Keywords.T = msg;
                            break;

                        case "- INFO":
                            operation.CustomData["Stichwort I"] = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.EEinsatzmittel:
                    {
                        switch (prefix)
                        {
                        case "EINSATZMITTELNAME":
                            last.FullName = msg;
                            break;

                        case "GEF. GERÄTE":
                            last.RequestedEquipment.Add(msg);
                            operation.Resources.Add(last);
                            last = new OperationResource();
                            break;
                        }
                    }
                    break;

                    case CurrentSection.FBemerkung:
                    {
                        // Append with newline at the end in case that the message spans more than one line
                        operation.Comment = operation.Comment.AppendLine(msg);
                    }
                    break;

                    case CurrentSection.GFooter:
                        // The footer can be ignored completely.
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, "Error while parsing line '{0}'. The error message was: {1}", i, ex.Message);
                }
            }
            return(operation);
        }
Пример #10
0
        Operation IParser.Parse(string[] lines)
        {
            Operation      operation = new Operation();
            CurrentSection section   = CurrentSection.AAnfang;

            lines = Utilities.Trim(lines);
            foreach (var line in lines)
            {
                string keyword;
                if (ParserUtility.StartsWithKeyword(line, _keywords, out keyword))
                {
                    switch (keyword.Trim())
                    {
                    case "EINSATZNR": { section = CurrentSection.BeNr; break; }

                    case "MITTEILER": { section = CurrentSection.CMitteiler; break; }

                    case "EINSATZORT": { section = CurrentSection.DEinsatzort; break; }

                    case "STRAßE": { section = CurrentSection.EStraße; break; }

                    case "KOORDINATEN": { section = CurrentSection.Koordinaten; break; }

                    case "ABSCHNITT": { section = CurrentSection.FAbschnitt; break; }

                    case "KREUZUNG": { section = CurrentSection.GKreuzung; break; }

                    case "ORTSTEIL/ORT": { section = CurrentSection.HOrt; break; }

                    case "OBJEKT": { section = CurrentSection.JObjekt; break; }

                    case "EINSATZPLAN": { section = CurrentSection.KEinsatzplan; break; }

                    case "MELDEBILD": { section = CurrentSection.LMeldebild; break; }

                    case "HINWEIS": { section = CurrentSection.MHinweis; break; }

                    case "GEFORDERTE EINSATZMITTEL": { section = CurrentSection.NEinsatzmittel; break; }

                    case "(ALARMSCHREIBEN ENDE)": { section = CurrentSection.OEnde; break; }
                    }
                }


                switch (section)
                {
                case CurrentSection.BeNr:
                    int indexOf = line.IndexOf("ALARM", StringComparison.InvariantCultureIgnoreCase);
                    if (indexOf == -1)
                    {
                        operation.OperationNumber = ParserUtility.GetMessageText(line, keyword);
                        break;
                    }
                    operation.OperationNumber = ParserUtility.GetMessageText(line.Substring(0, indexOf), keyword);
                    keyword = "ALARM";
                    try
                    {
                        operation.Timestamp = DateTime.Parse(ParserUtility.GetMessageText(line.Substring(indexOf), keyword));
                    }
                    catch (FormatException)
                    {
                        operation.Timestamp = DateTime.Now;
                    }
                    break;

                case CurrentSection.CMitteiler:
                    operation.Messenger = ParserUtility.GetMessageText(line, keyword);
                    break;

                case CurrentSection.DEinsatzort:
                    operation.Einsatzort.Location = ParserUtility.GetMessageText(line, keyword);
                    break;

                case CurrentSection.EStraße:
                    string msg = ParserUtility.GetMessageText(line, keyword);
                    string street, streetNumber, appendix;
                    ParserUtility.AnalyzeStreetLine(msg, out street, out streetNumber, out appendix);
                    operation.CustomData["Einsatzort Zusatz"] = appendix;
                    operation.Einsatzort.Street       = street;
                    operation.Einsatzort.StreetNumber = streetNumber;
                    break;

                case CurrentSection.FAbschnitt:
                    operation.CustomData["Einsatzort Abschnitt"] = ParserUtility.GetMessageText(line, keyword);
                    break;

                case CurrentSection.GKreuzung:
                    operation.Einsatzort.Intersection = ParserUtility.GetMessageText(line, keyword);
                    break;

                case CurrentSection.HOrt:
                    operation.Einsatzort.City = ParserUtility.GetMessageText(line, keyword);
                    break;

                case CurrentSection.JObjekt:
                    operation.Einsatzort.Property = ParserUtility.GetMessageText(line, keyword);
                    break;

                case CurrentSection.KEinsatzplan:
                    operation.OperationPlan = ParserUtility.GetMessageText(line, keyword);
                    break;

                case CurrentSection.LMeldebild:
                    operation.Picture = ParserUtility.GetMessageText(line, keyword);
                    break;

                case CurrentSection.MHinweis:
                    operation.Comment = ParserUtility.GetMessageText(line, keyword);
                    break;

                case CurrentSection.NEinsatzmittel:
                    if (line.StartsWith("Geforderte Einsatzmittel", StringComparison.InvariantCultureIgnoreCase))
                    {
                        break;
                    }
                    OperationResource resource = new OperationResource();
                    if (line.Contains('('))
                    {
                        string tool = line.Substring(line.IndexOf("(", StringComparison.Ordinal) + 1);
                        tool = tool.Length >= 2 ? tool.Substring(0, tool.Length - 2).Trim() : String.Empty;
                        string unit = line.Substring(0, line.IndexOf("(", StringComparison.Ordinal));
                        resource.FullName = unit;
                        resource.RequestedEquipment.Add(tool);
                        operation.Resources.Add(resource);
                    }
                    else
                    {
                        operation.Resources.Add(new OperationResource()
                        {
                            FullName = line
                        });
                    }
                    break;

                case CurrentSection.Koordinaten:
                    string coords              = ParserUtility.GetMessageText(line, keyword).Replace("GK4", "").Replace(",", ".");
                    Regex  r                   = new Regex(@"[\d.]+");
                    var    matches             = r.Matches(coords);
                    if (matches.Count == 2)
                    {
                        var geo = GeographicCoords.FromGaussKrueger(Convert.ToDouble(matches[0].Value), Convert.ToDouble(matches[1].Value));
                        operation.Einsatzort.GeoLatitude  = geo.Latitude;
                        operation.Einsatzort.GeoLongitude = geo.Longitude;
                    }
                    break;

                case CurrentSection.OEnde:
                    break;
                }
            }

            return(operation);
        }
Пример #11
0
        Operation IParser.Parse(string[] lines)
        {
            Operation         operation = new Operation();
            OperationResource last      = new OperationResource();

            lines = Utilities.Trim(lines);
            CurrentSection section      = CurrentSection.AHeader;
            bool           keywordsOnly = true;

            for (int i = 0; i < lines.Length; i++)
            {
                try
                {
                    string line = lines[i];
                    if (line.Length == 0)
                    {
                        continue;
                    }
                    if (GetSection(line.Trim(), ref section, ref keywordsOnly))
                    {
                        continue;
                    }

                    string msg    = line;
                    string prefix = "";

                    // Make the keyword check - or not (depends on the section we are in; see above)
                    string keyword = "";
                    if (keywordsOnly)
                    {
                        if (!ParserUtility.StartsWithKeyword(line, _keywords, out keyword))
                        {
                            continue;
                        }

                        int x = line.IndexOf(':');
                        if (x == -1)
                        {
                            // If there is no colon found (may happen occasionally) then simply remove the length of the keyword from the beginning
                            prefix = keyword;
                            msg    = line.Remove(0, prefix.Length).Trim();
                        }
                        else
                        {
                            prefix = line.Substring(0, x);
                            msg    = line.Substring(x + 1).Trim();
                        }
                        prefix = prefix.Trim().ToUpperInvariant();
                    }

                    // Parse each section
                    switch (section)
                    {
                    case CurrentSection.AHeader:
                    {
                        switch (prefix)
                        {
                        case "ABSENDER":
                            operation.OperationNumber = ParserUtility.GetTextBetween(msg, "Einsatznummer:");
                            break;
                        }
                    }
                    break;

                    case CurrentSection.BEinsatzort:
                    {
                        switch (prefix)
                        {
                        case "STRASSE":
                        {
                            string street, streetNumber, appendix;
                            ParserUtility.AnalyzeStreetLine(msg, out street, out streetNumber, out appendix);
                            operation.CustomData["Einsatzort Zusatz"] = appendix;
                            operation.Einsatzort.Street       = street;
                            operation.Einsatzort.StreetNumber = streetNumber;
                        }
                        break;

                        case "ORT":
                        {
                            string zipCode = ParserUtility.ReadZipCodeFromCity(msg);
                            operation.Einsatzort.ZipCode = zipCode;
                            operation.Einsatzort.City    = msg.Replace(zipCode, "").Trim();
                            // The City-text often contains a dash after which the administrative city appears multiple times (like "City A - City A City A").
                            // However we can (at least with google maps) omit this information without problems!
                            int dashIndex = operation.Einsatzort.City.IndexOf(" - ");
                            if (dashIndex != -1)
                            {
                                // Ignore everything after the dash
                                operation.Einsatzort.City = operation.Einsatzort.City.Substring(0, dashIndex);
                            }
                        }
                        break;

                        case "OBJEKT":
                            operation.Einsatzort.Property = msg;
                            break;

                        case "STATION":
                            operation.CustomData["Einsatzort Station"] = msg;
                            break;

                        case "KREUZUNG":
                            operation.Einsatzort.Intersection = msg;
                            break;

                        case "PLANUMER":
                            operation.OperationPlan = msg;
                            break;

                        case "KOORDINATE":
                            Regex r       = new Regex(@"(\d+\.\d+)");
                            var   matches = r.Matches(line);
                            if (matches.Count == 2)
                            {
                                NumberFormatInfo nfi = new NumberFormatInfo {
                                    NumberDecimalSeparator = "."
                                };
                                double geoRechts = Convert.ToDouble(matches[0].Value, nfi);
                                double geoHoch   = Convert.ToDouble(matches[1].Value, nfi);
                                var    geo       = GeographicCoords.FromGaussKrueger(geoRechts, geoHoch);
                                operation.Einsatzort.GeoLatitude  = geo.Latitude;
                                operation.Einsatzort.GeoLongitude = geo.Longitude;
                            }
                            break;
                        }
                    }
                    break;

                    case CurrentSection.CEreignis:
                    {
                        switch (prefix)
                        {
                        case "SCHLAGWORT":
                            operation.Keywords.Keyword = msg;
                            break;

                        case "STICHWORT":
                            operation.Keywords.EmergencyKeyword = msg;
                            break;

                        case "PRIORITAT":
                        case "PRIORITÄT":
                            operation.Priority = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.DZielort:
                        switch (prefix)
                        {
                        case "STRASSE":
                        {
                            string street, streetNumber, appendix;
                            ParserUtility.AnalyzeStreetLine(msg, out street, out streetNumber, out appendix);
                            operation.CustomData["Zielort Zusatz"] = appendix;
                            operation.Zielort.Street       = street;
                            operation.Zielort.StreetNumber = streetNumber;
                        }
                        break;

                        case "ORT":
                        {
                            // The City-text often contains a dash after which the administrative city appears multiple times (like "City A - City A City A").
                            // However we can (at least with google maps) omit this information without problems!
                            int dashIndex = msg.IndexOf('-');
                            if (dashIndex != -1)
                            {
                                // Ignore everything after the dash
                                operation.Zielort.City = operation.Einsatzort.City.Substring(0, dashIndex);
                            }
                        }
                        break;

                        case "OBJEKT":
                            operation.Zielort.Property = msg;
                            break;

                        case "STATION":
                            operation.CustomData["Zielort Station"] = msg;
                            break;
                        }
                        break;

                    case CurrentSection.FEinsatzmittel:
                    {
                        string name, equip;
                        name  = ParserUtility.GetTextBetween(msg, null, ">> gefordert:");
                        equip = ParserUtility.GetTextBetween(msg, ">> gefordert:");
                        OperationResource resource = new OperationResource
                        {
                            FullName           = name,
                            RequestedEquipment = new List <string>()
                            {
                                equip
                            }
                        };
                        operation.Resources.Add(resource);
                    }
                    break;

                    case CurrentSection.EBemerkung:
                    {
                        // Append with newline at the end in case that the message spans more than one line
                        operation.Picture = operation.Picture.AppendLine(msg);
                    }
                    break;

                    case CurrentSection.GFooter:
                        // The footer can be ignored completely.
                        break;
                    }
                }
                catch (Exception ex)
                {
                    string l = lines[i];
                    Logger.Instance.LogFormat(LogType.Warning, this, "Error while parsing line '{0}'. The error message was: {1}", i, ex.Message);
                }
            }
            return(operation);
        }