Operation IParser.Parse(string[] lines)
        {
            Operation         operation = new Operation();
            OperationResource last      = new OperationResource();

            lines = Utilities.Trim(lines);
            CurrentSection section             = CurrentSection.AHeader;
            bool           keywordsOnly        = true;
            bool           multiLineProperties = false;
            string         keyword             = "";
            string         prefix = "";

            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, ref multiLineProperties))
                    {
                        continue;
                    }

                    string msg = line;

                    // Make the keyword check - or not (depends on the section we are in; see above)
                    if (!multiLineProperties)
                    {
                        prefix = "";
                    }
                    if (keywordsOnly)
                    {
                        bool foundKeyword = ParserUtility.StartsWithKeyword(line, _keywords, out keyword);
                        if (!foundKeyword && !multiLineProperties)
                        {
                            continue;
                        }
                        if (foundKeyword)
                        {
                            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.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 "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 "GEMEINDE":
                        {
                            operation.CustomData.Add("GEMEINDE", msg);
                        }
                        break;

                        case "OBJEKT":
                            if (msg.Contains("EPN:"))
                            {
                                operation.Einsatzort.Property = ParserUtility.GetTextBetween(msg, null, "EPN");
                                operation.OperationPlan       = ParserUtility.GetTextBetween(msg, "EPN");
                            }
                            else
                            {
                                operation.Einsatzort.Property = msg;
                            }
                            break;

                        case "ABSCHNITT":
                        case "KREUZUNG":
                            operation.Einsatzort.Intersection += 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;
                        }
                    }
                    break;

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

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

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

                    case CurrentSection.EEinsatzmittel:
                    {
                        switch (prefix)
                        {
                        case "NAME":
                            last.FullName = msg;
                            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();

                            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);
        }
        Operation IParser.Parse(string[] lines)
        {
            Operation operation = new Operation();

            lines = Utilities.Trim(lines);
            foreach (var line in lines)
            {
                if (ParserUtility.StartsWithKeyword(line, _keywords, out var keyword))
                {
                    var msg = ParserUtility.GetMessageText(line, keyword);
                    switch (keyword.ToUpperInvariant())
                    {
                    case "EINSATZNUMMER":
                    {
                        operation.OperationNumber = msg;
                        break;
                    }

                    case "ORT:":
                    {
                        operation.Einsatzort.City = msg;
                        break;
                    }

                    case "STRAßE":
                    {
                        string street;
                        string streetNumber;
                        string 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 "OBJEKT":
                    {
                        operation.Einsatzort.Property = msg;
                        break;
                    }

                    case "BEMERKUNG":
                    {
                        operation.Comment = msg; break;
                    }

                    case "KOORDINATEN":
                    {
                        if (_coordinatenRegex.IsMatch(msg))
                        {
                            Match m = _coordinatenRegex.Match(msg);
                            operation.Einsatzort.GeoLatitude  = Convert.ToDouble(m.Groups[1].Value, CultureInfo.InvariantCulture);
                            operation.Einsatzort.GeoLongitude = Convert.ToDouble(m.Groups[2].Value, CultureInfo.InvariantCulture);
                        }
                        break;
                    }

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

                    case "MELDEBILD":
                    {
                        operation.Picture = msg; break;
                    }

                    case "ZIELORT":
                    {
                        break;
                    }

                    case "ZEITEN":
                    {
                        break;
                    }

                    case "EM":
                    {
                        Match alarm = Regex.Match(line, @"[1-9]{1,2}-[1-9]{2}-[1-9]{1}");
                        if (alarm.Success)
                        {
                            operation.Resources.Add(new OperationResource {
                                    FullName = alarm.Groups[0].Value
                                });
                        }
                        break;
                    }
                    }
                }
            }

            return(operation);
        }
        Operation IParser.Parse(string[] lines)
        {
            Operation operation = new Operation();

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

            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];
                try
                {
                    if (line.Length == 0)
                    {
                        continue;
                    }
                    GetSection(line.Trim(), ref section, ref keywordsOnly);
                    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();
                    }
                    switch (section)
                    {
                    case CurrentSection.ADaten:
                        switch (prefix)
                        {
                        case "EINSATZNUMMER":
                            operation.OperationNumber = msg;
                            break;

                        case "EINSATZORT":
                            operation.Einsatzort.Location = msg;
                            break;

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

                        case "ORT":
                            operation.Einsatzort.City = msg;
                            break;

                        case "BMA-NUMMER/LINIE":
                            operation.OperationPlan = msg;
                            break;

                        case "ORTSTEIL":
                            operation.CustomData["Einsatzort Ortsteil"] = msg;
                            break;

                        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 "BESONDERHEITEN":
                            operation.Comment = msg;
                            break;

                        case "EINSATZART":
                            operation.Keywords.Keyword = msg;
                            break;

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

                        case "MELDENDER":
                            operation.Messenger = msg;
                            break;
                        }
                        break;

                    case CurrentSection.CEinsatzmittel:
                        if (line.Contains("Alarmierte Einheiten"))
                        {
                            continue;
                        }
                        OperationResource resource = new OperationResource {
                            FullName = msg
                        };
                        operation.Resources.Add(resource);
                        break;

                    case CurrentSection.EFooter:
                        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);
        }
Exemple #4
0
        public Operation Parse(string[] lines)
        {
            Operation operation = new Operation();

            lines = Utilities.Trim(lines);
            for (int i = 0; i < lines.Length; i++)
            {
                try
                {
                    var line = lines[i];
                    if (line.Length == 0)
                    {
                        continue;
                    }
                    string msg = line;
                    string keyword;
                    if (ParserUtility.StartsWithKeyword(line, Keywords, out keyword))
                    {
                        msg = ParserUtility.GetMessageText(line, keyword);
                    }
                    if (!string.IsNullOrWhiteSpace(keyword))
                    {
                        switch (keyword.ToUpperInvariant())
                        {
                        case "ALARMSTICHWORT":
                            operation.Keywords.Keyword = msg;
                            break;

                        case "EINSATZORT":
                            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.City = msg;
                            break;

                        case "ORTSTEIL":
                            operation.CustomData["Einsatzort Ortsteil"] = msg;
                            break;

                        case "OBJEKT":
                            operation.Einsatzort.Property = msg;
                            break;
                        }
                    }
                    else
                    {
                        operation.Comment = operation.Comment.AppendLine(line);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, "Error while parsing line '{0}'. The error message was: {1}", i, ex.Message);
                }
            }
            return(operation);
        }
        Operation IParser.Parse(string[] lines)
        {
            Operation      operation = new Operation();
            CurrentSection section   = CurrentSection.AAnfang;

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

                    case "Ortsteil": { section = CurrentSection.COrtsteil; break; }

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

                    case "Hausnummer": { section = CurrentSection.EHausnummer; break; }

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

                    case "Zusatzinfos": { section = CurrentSection.GZusatzinfos; break; }

                    case "Betroffene": { section = CurrentSection.HBetroffene; break; }

                    case "Einsatzart": { section = CurrentSection.IEinsatzart; break; }

                    case "Stichwort": { section = CurrentSection.JStichwort; break; }

                    case "Sondersignal": { section = CurrentSection.KSondersignal; break; }

                    case "Zusatzinformationen": { section = CurrentSection.LZusatzinformationen; break; }

                    case "Alarmierungen": { section = CurrentSection.MAlarmierungen; break; }

                    case "Meldende": { section = CurrentSection.NMeldende; break; }

                    case "Telefon": { section = CurrentSection.OTelefon; break; }

                    case "Ausdruck": { section = CurrentSection.PAusdruck; break; }

                    case "Referenznummer": { section = CurrentSection.QReferenznummer; break; }
                    }
                }


                switch (section)
                {
                case CurrentSection.AAnfang:
                {
                    break;
                }

                case CurrentSection.BOrt:
                {
                    operation.Einsatzort.City = ParserUtility.GetMessageText(line);
                    break;
                }

                case CurrentSection.COrtsteil:
                {
                    operation.Einsatzort.City += " " + ParserUtility.GetMessageText(line);
                    break;
                }

                case CurrentSection.DStraße:
                {
                    operation.Einsatzort.Street = ParserUtility.GetMessageText(line);
                    break;
                }

                case CurrentSection.EHausnummer:
                {
                    operation.Einsatzort.StreetNumber = ParserUtility.GetMessageText(line);
                    break;
                }

                case CurrentSection.FKoordinaten:
                {
                    break;
                }

                case CurrentSection.GZusatzinfos:
                {
                    operation.Comment = ParserUtility.GetMessageText(line);
                    break;
                }

                case CurrentSection.HBetroffene:
                {
                    operation.Comment += " " + ParserUtility.GetMessageText(line);
                    section            = CurrentSection.AAnfang;
                    break;
                }

                case CurrentSection.IEinsatzart:
                {
                    operation.Keywords.EmergencyKeyword = ParserUtility.GetMessageText(line);
                    break;
                }

                case CurrentSection.JStichwort:
                {
                    operation.Keywords.Keyword = ParserUtility.GetMessageText(line);
                    break;
                }

                case CurrentSection.KSondersignal:
                {
                    break;
                }

                case CurrentSection.LZusatzinformationen:
                {
                    operation.Picture = ParserUtility.GetMessageText(line);
                    section           = CurrentSection.AAnfang;
                    break;
                }

                case CurrentSection.MAlarmierungen:
                {
                    Match alarm = Regex.Match(line, @"((0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d ([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]) (\d{5})");
                    if (alarm.Success)
                    {
                        operation.Resources.Add(new OperationResource {
                                FullName = alarm.Groups[6].Value, Timestamp = alarm.Groups[1].Value
                            });
                    }
                    break;
                }

                case CurrentSection.NMeldende:
                {
                    operation.Messenger = ParserUtility.GetMessageText(line);
                    break;
                }

                case CurrentSection.OTelefon:
                {
                    operation.Messenger += string.Format(@" Tel.:{0}", ParserUtility.GetMessageText(line));
                    break;
                }

                case CurrentSection.PAusdruck:
                {
                    operation.Timestamp = ParserUtility.ReadFaxTimestamp(line, DateTime.Now);
                    break;
                }

                case CurrentSection.QReferenznummer:
                {
                    operation.OperationNumber = ParserUtility.GetMessageText(line);
                    break;
                }

                case CurrentSection.REnde:
                {
                    break;
                }
                }
            }

            return(operation);
        }
        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 "EINSATZNUMMER":
                            operation.OperationNumber = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.BMitteiler:
                        operation.Messenger = line.Remove(0, keyword.Length).Trim();
                        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":
                        {
                            Match zip = Regex.Match(msg, @"[0-9]{5}");
                            if (zip.Success)
                            {
                                operation.Einsatzort.ZipCode = zip.Value;
                                operation.Einsatzort.City    = msg.Replace(zip.Value, "").Trim();
                            }
                            else
                            {
                                operation.Einsatzort.City = msg;
                            }
                            break;
                        }

                        case "GEMEINDE":
                        {
                            operation.CustomData.Add("GEMEINDE", msg);
                        }
                        break;

                        case "OBJEKT":
                            if (msg.Contains("EPN:"))
                            {
                                operation.Einsatzort.Property = ParserUtility.GetTextBetween(line, null, "EPN");
                                operation.OperationPlan       = ParserUtility.GetTextBetween(line, "EPN");
                            }
                            else
                            {
                                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 "PRIO.":
                            operation.Priority = msg;
                            break;
                        }
                    }
                    break;

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

                        case "ALARMIERT":
                            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.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);
        }
        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);
        }
        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 (GetKeyword(line, 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 "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 = GetMessageText(line, keyword);
                        break;
                    }
                    operation.OperationNumber = GetMessageText(line.Substring(0, indexOf), keyword);
                    keyword = "ALARM";
                    try
                    {
                        operation.Timestamp = DateTime.Parse(GetMessageText(line.Substring(indexOf), keyword));
                    }
                    catch (FormatException)
                    {
                        operation.Timestamp = DateTime.Now;
                    }
                    break;

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

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

                case CurrentSection.EStraße:
                    string msg = 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"] = GetMessageText(line, keyword);
                    break;

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

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

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

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

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

                case CurrentSection.MHinweis:
                    operation.Comment = 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.OEnde:
                    break;
                }
            }

            return(operation);
        }
        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);
        }
        Operation IParser.Parse(string[] lines)
        {
            Operation         operation = new Operation();
            OperationResource last      = new OperationResource();

            lines = Utilities.Trim(lines);
            CurrentSection section      = CurrentSection.AHeader;
            InnerSection   inner        = InnerSection.None;
            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 || x > keyword.Length + 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:
                    {
                        if (inner == InnerSection.ENr)
                        {
                            operation.OperationNumber = msg;
                        }
                        switch (prefix)
                        {
                        case "EINSATZ-NR.":
                            inner = InnerSection.ENr;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.Einsatzmeldung:
                        switch (prefix)
                        {
                        case "STR./HAUSNR.":
                            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 "SONST. ORTSANGABE.":
                            operation.CustomData["Einsatzort Zusatz"] = (operation.CustomData["Einsatzort Zusatz"] as string).AppendLine(msg);
                            break;

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

                        case "OBJEKT-NUMMER":
                            operation.Einsatzort.Property = operation.Einsatzort.Property.AppendLine(msg);
                            break;

                        case "ORTST./GEM.":
                            operation.Einsatzort.City = msg;
                            break;

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

                        case "MELDENDER":
                            operation.Messenger = msg;
                            break;

                        case "TELEFONNUMMER":
                            operation.Messenger = operation.Messenger.AppendLine(msg);
                            break;

                        case "BEMERKUNGEN":
                            operation.Picture = msg;
                            break;
                        }
                        break;

                    case CurrentSection.Hinweise:
                    {
                        operation.Comment = operation.Comment.AppendLine(msg);
                    }
                    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);
        }
        public Operation Parse(string[] lines)
        {
            Operation operation = new Operation();
            string    date      = "";

            foreach (string line in lines)
            {
                string keyword;
                ParserUtility.StartsWithKeyword(line, _keywords, out keyword);
                string msg = ParserUtility.GetMessageText(line, keyword);

                switch (keyword)
                {
                case "Datum":
                    date = msg;
                    break;

                case "Zeit":
                    string time = msg;
                    operation.Timestamp = ParserUtility.ReadFaxTimestamp(string.Format("{0} {1}", date, time), DateTime.Now);
                    break;

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

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

                case "Bezeichnung":
                    operation.Keywords.Keyword = msg;
                    break;

                case "Strasse":
                    operation.Einsatzort.Street = msg;
                    break;

                case "Strasse Nr.":
                    operation.Einsatzort.StreetNumber = msg;
                    break;

                case "PLZ":
                    operation.Einsatzort.ZipCode = msg;
                    break;

                case "Ort":
                    operation.Einsatzort.City = msg;
                    break;

                case "Pager Meldung":
                    operation.CustomData["Pager Meldung"] = msg;
                    break;

                case "Einsatz ID":
                    operation.OperationNumber = msg;
                    break;

                case "Lat/Long":
                    string[] values = msg.Split(';');
                    operation.Einsatzort.GeoLatitude  = values[0].Trim().Replace(',', '.');
                    operation.Einsatzort.GeoLongitude = values[1].Trim().Replace(',', '.');
                    break;

                case "Beschreibung":
                    operation.Comment = msg;
                    break;
                }
            }
            return(operation);
        }
Exemple #12
0
        Operation IParser.Parse(string[] lines)
        {
            Operation      operation = new Operation();
            CurrentSection section   = CurrentSection.AAnfang;

            lines = Utilities.Trim(lines);
            foreach (string line in lines)
            {
                string keyword;
                if (GetKeyword(line.TrimStart(), out keyword))
                {
                    switch (keyword)
                    {
                    case "Einsatznr": { section = CurrentSection.BEinsatznr; break; }

                    case "EArt": { section = CurrentSection.CEArt; break; }

                    case "Stichwort": { section = CurrentSection.DStichwort; break; }

                    case "Diagnose": { section = CurrentSection.EDiagnose; break; }

                    case "Meldender": { section = CurrentSection.FMeldender; break; }

                    case "Prioritaet": { section = CurrentSection.GPriorität; break; }

                    case "Ort ": { section = CurrentSection.HOrt; break; }

                    case "Ortsteil": { section = CurrentSection.IOrtsteil; break; }

                    case "Strasse": { section = CurrentSection.JStraße; break; }

                    case "Kreuzung": { section = CurrentSection.KKreuzung; break; }

                    case "ADAC": { section = CurrentSection.MADAC; break; }

                    case "Info": { section = CurrentSection.NInfo; break; }

                    case "NRN": { section = CurrentSection.LNRN; break; }

                    case "Objektname": { section = CurrentSection.OObjektname; break; }

                    case "BMA-Nummer": { section = CurrentSection.SBMA; break; }

                    case "Routenausgabe": { section = CurrentSection.PRoutenausgabe; break; }

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

                    case "Ausdruck": { section = CurrentSection.REnde; break; }

                    case "Besonderh": { section = CurrentSection.TBesonder; break; }
                    }
                }


                switch (section)
                {
                case CurrentSection.AAnfang:
                {
                    break;
                }

                case CurrentSection.BEinsatznr:
                {
                    operation.OperationNumber = GetMessageText(line);
                    break;
                }

                case CurrentSection.CEArt:
                {
                    operation.Keywords.Keyword = GetMessageText(line);
                    break;
                }

                case CurrentSection.DStichwort:
                {
                    operation.Keywords.EmergencyKeyword = GetMessageText(line);
                    break;
                }

                case CurrentSection.EDiagnose:
                {
                    operation.Picture = GetMessageText(line);
                    break;
                }

                case CurrentSection.FMeldender:
                {
                    operation.Messenger = GetMessageText(line);
                    break;
                }

                case CurrentSection.GPriorität:
                {
                    operation.Priority = GetMessageText(line);
                    section            = CurrentSection.AAnfang;
                    break;
                }

                case CurrentSection.HOrt:
                {
                    operation.Einsatzort.City = GetMessageText(line);
                    break;
                }

                case CurrentSection.IOrtsteil:
                {
                    operation.Einsatzort.City += " - " + GetMessageText(line);
                    break;
                }

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

                case CurrentSection.KKreuzung:
                {
                    operation.Einsatzort.Intersection = GetMessageText(line);
                    break;
                }

                case CurrentSection.LNRN:
                {
                    operation.CustomData.Add("NRN", GetMessageText(line));
                    break;
                }

                case CurrentSection.MADAC:
                {
                    operation.CustomData.Add("ADAC", GetMessageText(line));
                    break;
                }

                case CurrentSection.NInfo:
                {
                    operation.Comment = GetMessageText(line);
                    break;
                }

                case CurrentSection.OObjektname:
                {
                    operation.Einsatzort.Property += GetMessageText(line);
                    operation.Einsatzort.Property  = operation.Einsatzort.Property.Trim();
                    break;
                }

                case CurrentSection.SBMA:
                {
                    operation.Einsatzort.Property += " BMA: " + GetMessageText(line);
                    operation.Einsatzort.Property  = operation.Einsatzort.Property.Trim();
                    break;
                }

                case CurrentSection.PRoutenausgabe:
                {
                    //TODO: Auswerten wenn Format bekannt ist.
                    break;
                }

                case CurrentSection.QEinsatzmittel:
                {
                    Match alarmtime = Regex.Match(line, @"(([01]?\d|2[0-3]):[0-5]\d:[0-5]\d)|(--:--:--)");
                    if (alarmtime.Success)
                    {
                        string time = alarmtime.Value;
                        string unit = line.Replace(time, "").Trim();
                        operation.Resources.Add(new OperationResource {
                                FullName = unit, Timestamp = time
                            });
                    }
                    break;
                }

                case CurrentSection.REnde:
                {
                    Match datetime = Regex.Match(line, @"[123]\d\. \w* 20\d{2}, (([01]?\d|2[0-3]):[0-5]\d)");
                    if (datetime.Success)
                    {
                        CultureInfo ci = new CultureInfo("de");
                        DateTime    timeStamp;
                        operation.Timestamp = DateTime.TryParse(datetime.Value, ci, DateTimeStyles.None, out timeStamp) ? timeStamp : DateTime.Now;
                    }
                    break;
                }

                case CurrentSection.TBesonder:
                {
                    operation.Einsatzort.Property += " Besonderheiten: " + GetMessageText(line);
                    operation.Einsatzort.Property  = operation.Einsatzort.Property.Trim();

                    section = CurrentSection.AAnfang;
                    break;
                }
                }
            }

            return(operation);
        }
Exemple #13
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 "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":
                        {
                            string zipCode = ParserUtility.ReadZipCodeFromCity(msg);
                            operation.Einsatzort.ZipCode = zipCode;
                            operation.Einsatzort.City    = ParserUtility.GetTextBetween(msg, null, "Gemeinde");
                            operation.Einsatzort.City    = operation.Einsatzort.City.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);
                            }
                            operation.CustomData["Einsatzort Gemeinde"] = ParserUtility.GetTextBetween(msg, "Gemeinde:");
                        }
                        break;

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

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

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

                        case "PLANNUMMER":
                            operation.OperationPlan = msg;
                            break;
                        }
                    }
                    break;

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

                        case "PRIORITÄT":
                            operation.Priority = msg;
                            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":
                        {
                            operation.Zielort.City = ParserUtility.GetTextBetween(msg, null, "Gemeinde");
                            // 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.Zielort.City.IndexOf('-');
                            if (dashIndex != -1)
                            {
                                // Ignore everything after the dash
                                operation.Zielort.City = operation.Einsatzort.City.Substring(0, dashIndex);
                            }
                            operation.CustomData["Zielort Gemeinde"] = ParserUtility.GetTextBetween(msg, "Gemeinde:");
                        }
                        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);
        }
        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 "E-Nr": { section = CurrentSection.BeNr; break; }

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

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

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

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

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

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

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

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

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

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


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

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

                case CurrentSection.DStraß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.EOrt:
                    operation.Einsatzort.City = ParserUtility.GetMessageText(line, keyword);
                    break;

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

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

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

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

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

                case CurrentSection.LEinsatzmittel:
                    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.MEnde:
                    break;
                }
            }

            return(operation);
        }
        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 (!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 "EINSATZNUMMER":
                            operation.OperationNumber = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.BMitteiler:
                        operation.Messenger = line.Remove(0, keyword.Length).Trim();
                        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":
                        {
                            Match zip = Regex.Match(msg, @"[0-9]{5}");
                            if (zip.Success)
                            {
                                operation.Einsatzort.ZipCode = zip.Value;
                                operation.Einsatzort.City    = msg.Replace(zip.Value, "").Trim();
                            }
                            else
                            {
                                operation.Einsatzort.City = msg;
                            }
                            break;
                        }

                        case "GEMEINDE":
                        {
                            operation.CustomData.Add("GEMEINDE", msg);
                        }
                        break;

                        case "OBJEKT":
                            if (msg.Contains("EPN:"))
                            {
                                string epn = msg.Substring(msg.IndexOf("EPN", StringComparison.Ordinal));
                                epn = GetMessageText(epn, "EPN");
                                operation.OperationPlan       = epn;
                                operation.Einsatzort.Property = msg.Substring(0, msg.IndexOf("EPN", StringComparison.Ordinal));
                            }
                            else
                            {
                                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 "PRIO.":
                            operation.Priority = msg;
                            break;
                        }
                    }
                    break;

                    case CurrentSection.EEinsatzmittel:
                    {
                        if (line.StartsWith("NAME", StringComparison.CurrentCultureIgnoreCase))
                        {
                            msg           = GetMessageText(line, "NAME");
                            last.FullName = msg;
                        }
                        else if (line.StartsWith("ALARMIERT", StringComparison.CurrentCultureIgnoreCase) && !string.IsNullOrEmpty(msg))
                        {
                            msg = GetMessageText(line, "ALARMIERT");

                            // In case that parsing the time failed, we just assume that the resource got requested right away.
                            DateTime dt;
                            // Most of the time the OCR-software reads the colon as a "1", so we check this case right here.
                            if (!DateTime.TryParseExact(msg, "dd.MM.yyyy HH1mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                            {
                                // If this is NOT the case and it was parsed correctly, try it here
                                DateTime.TryParseExact(msg, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt);
                            }

                            last.Timestamp = dt.ToString(CultureInfo.InvariantCulture);
                        }
                        else if (line.StartsWith("GEF. GERÄT", StringComparison.CurrentCultureIgnoreCase))
                        {
                            msg = GetMessageText(line, "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;

                    case CurrentSection.FBemerkung:
                    {
                        // Append with newline at the end in case that the message spans more than one line
                        operation.Comment = operation.Comment += msg + Environment.NewLine;
                    }
                    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);
        }
        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 = 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 "EINSATZ":
                            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)
                            {
                                operation.CustomData["Einsatzort Kommune"] = operation.Einsatzort.City.Substring(dashIndex).Trim();
                                // Ignore everything after the dash
                                operation.Einsatzort.City = operation.Einsatzort.City.Substring(0, dashIndex).Trim();
                            }
                        }
                        break;

                        case "ABSCHNITT":
                            operation.Zielort.Intersection = msg;
                            break;

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

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

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

                        case "ZONE":
                            operation.Einsatzort.Location = msg;
                            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 zipcode = ParserUtility.ReadZipCodeFromCity(msg);
                            operation.Zielort.ZipCode = zipcode;
                            operation.Zielort.City    = msg.Remove(0, zipcode.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 "SCHLAGW.":
                            Regex regex = new Regex("\\[(.*)]");

                            if (regex.IsMatch(msg))
                            {
                                Match match = regex.Match(msg);
                                operation.Keywords.EmergencyKeyword = match.Groups[1].Value;
                                operation.Keywords.Keyword          = msg.Replace(match.Value, "");
                            }
                            else
                            {
                                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 I":
                            operation.CustomData["Stichwort I"] = msg;
                            break;

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

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

                    case CurrentSection.FEinsatzmittel:
                    {
                        if (line.StartsWith("NAME", StringComparison.CurrentCultureIgnoreCase))
                        {
                            continue;
                        }

                        int indexEquip = line.IndexOf(":", StringComparison.Ordinal);
                        int indexTime  = line.IndexOf(":", indexEquip + 1, StringComparison.Ordinal);
                        if (line.Contains("Fehlt:"))
                        {
                            indexTime = line.IndexOf(":", indexTime + 1, StringComparison.Ordinal);
                        }

                        OperationResource resource = new OperationResource();
                        resource.FullName = line.Substring(0, indexEquip).Trim();
                        resource.RequestedEquipment.Add(line.Substring(indexEquip + 1, indexTime - indexEquip - 1).Trim());
                        resource.Timestamp = line.Substring(indexTime + 1).Trim();
                        operation.Resources.Add(resource);
                    }
                    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.HTextbausteine:
                    {
                        // 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.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);
                }
            }

            return(operation);
        }
Exemple #17
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);
        }
        Operation IParser.Parse(string[] lines)
        {
            Operation      operation = new Operation();
            CurrentSection section   = CurrentSection.ADaten;

            lines = Utilities.Trim(lines);
            bool keywordsOnly = true;

            for (int i = 0; i < lines.Length; i++)
            {
                try
                {
                    string line = lines[i];
                    if (line.Length == 0)
                    {
                        continue;
                    }
                    string keyword = "";
                    if (ParserUtility.StartsWithKeyword(line, _keywords, out keyword) && section == CurrentSection.BEinsatzmittel)
                    {
                        section      = CurrentSection.ADaten;
                        keywordsOnly = true;
                    }
                    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 (!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();
                    }

                    switch (section)
                    {
                    case CurrentSection.ADaten:
                        switch (prefix)
                        {
                        case "EINSATZBEGINN UHRZEIT/DATUM":
                            operation.Timestamp       = ParserUtility.ReadFaxTimestamp(ParserUtility.GetTextBetween(msg, null, "/"), DateTime.Now);
                            operation.OperationNumber = ParserUtility.GetTextBetween(msg, "Einsatznr.:");
                            break;

                        case "PLZ - ORT":
                            if (PlzRegex.IsMatch(msg))
                            {
                                Match result = PlzRegex.Match(msg);
                                operation.Einsatzort.ZipCode = result.Groups[1].Value;
                                operation.Einsatzort.City    = result.Groups[2].Value;
                            }
                            break;

                        case "STRASSE HNR.":
                            operation.Einsatzort.Street = msg;
                            break;

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

                        case "INFO ZUM OBJEKT":
                            operation.Comment = operation.Comment.AppendLine(msg);
                            break;

                        case "MELDERNAME":
                            operation.Messenger = msg;
                            break;

                        case "EINSATZCODE":
                            operation.Keywords.Keyword = msg;
                            break;

                        case "EINSATZTEXT":
                            operation.Picture = operation.Picture.AppendLine(msg);
                            break;
                        }
                        break;

                    case CurrentSection.BEinsatzmittel:
                        operation.Resources.Add(new OperationResource()
                        {
                            FullName = msg
                        });
                        break;

                    case CurrentSection.CLink:
                        section = CurrentSection.DEnde;
                        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);
        }
Exemple #19
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;
            NumberFormatInfo nfi          = new NumberFormatInfo {
                NumberDecimalSeparator = "."
            };

            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 "EINSATZN.":
                            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":
                        {
                            operation.Einsatzort.Street = msg;
                        }
                        break;

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

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

                        case "ORTSTEIL":
                        {
                            operation.CustomData["Einsatzort Ortsteil"] = 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 "KOORDINATE":

                            Regex r       = new Regex(@"\d+");
                            var   matches = r.Matches(line);
                            if (matches.Count > 2)
                            {
                                int          rechts = Convert.ToInt32(matches[0].Value);
                                int          hoch   = Convert.ToInt32(matches[1].Value);
                                GaussKrueger gauss  = new GaussKrueger(rechts, hoch);
                                Geographic   geo    = (Geographic)gauss;
                                operation.Einsatzort.GeoLatitude  = geo.Latitude;
                                operation.Einsatzort.GeoLongitude = geo.Longitude;
                            }
                            break;

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

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

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

                        case "SCHLAGWORT":
                            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 I":
                            operation.CustomData["Stichwort I"] = msg;
                            break;

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

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

                        case "AUSSTATTUNG":
                            // 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.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);
        }
Exemple #20
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;
                    }

                    operation.Timestamp = ParserUtility.ReadFaxTimestamp(line, operation.Timestamp);

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

                    string msg    = line;
                    string prefix = "";

                    string keyword = null;
                    if (keywordsOnly)
                    {
                        if (!ParserUtility.StartsWithKeyword(line, Keywords, out keyword))
                        {
                            continue;
                        }

                        int x = line.IndexOf(':');
                        if (x == -1)
                        {
                            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();
                    }

                    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;

                        default:
                            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;

                        default:
                            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);
                            }
                        }
                        break;

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

                        case "PLANNUMMER":
                            operation.CustomData["Einsatzort Plannummer"] = msg;
                            break;

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

                        default:
                            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;

                        default:
                            break;
                        }
                    }
                    break;

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

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

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

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

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

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

                        default:
                            break;
                        }
                    }
                    break;

                    case CurrentSection.FEinsatzmittel:
                    {
                        if (line.StartsWith("EINSATZMITTEL", StringComparison.CurrentCultureIgnoreCase))
                        {
                            msg           = ParserUtility.GetMessageText(line, "EINSATZMITTEL");
                            last.FullName = msg;
                        }
                        else if (line.StartsWith("ALARMIERT", StringComparison.CurrentCultureIgnoreCase) && !string.IsNullOrEmpty(msg))
                        {
                            msg = ParserUtility.GetMessageText(line, "Alarmiert");

                            DateTime dt = ParserUtility.TryGetTimestampFromMessage(msg, operation.Timestamp);
                            last.Timestamp = dt.ToString();
                        }
                        else if (line.StartsWith("GEFORDERTE AUSSTATTUNG", StringComparison.CurrentCultureIgnoreCase))
                        {
                            msg = ParserUtility.GetMessageText(line, "Geforderte Ausstattung");

                            if (!string.IsNullOrWhiteSpace(msg))
                            {
                                last.RequestedEquipment.Add(msg);
                            }

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

                    case CurrentSection.GBemerkung:
                    {
                        operation.Comment = operation.Comment += msg + "\n";
                    }
                    break;

                    case CurrentSection.HFooter:
                        // The footer can be ignored completely.
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, "Error while parsing line '{0}'. The error message was: {1}", i, ex.Message);
                }
            }

            operation.Comment = ParserUtility.RemoveTrailingNewline(operation.Comment);

            return(operation);
        }
        Operation IParser.Parse(string[] lines)
        {
            Operation         operation = new Operation();
            OperationResource last      = new OperationResource();

            lines = Utilities.Trim(lines);

            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:");
                            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 += msg + "\n";
                    }
                    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);
                }
            }

            // Post-processing the operation if needed
            if (!string.IsNullOrWhiteSpace(operation.Comment) && operation.Comment.EndsWith("\n"))
            {
                operation.Comment = operation.Comment.Substring(0, operation.Comment.Length - 1).Trim();
            }
            return(operation);
        }
        Operation IParser.Parse(string[] lines)
        {
            Operation      operation = new Operation();
            CurrentSection section   = CurrentSection.AAnfang;

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

                    case "AAO":
                    {
                        section = CurrentSection.BAao;
                        break;
                    }

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

                    case "Strasse":
                    {
                        section = CurrentSection.DStrasse;
                        break;
                    }

                    case "Ort":
                    {
                        section = CurrentSection.EOrt;
                        break;
                    }

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

                    case "Wer":
                    {
                        section = CurrentSection.GMeldender;
                        break;
                    }

                    case "Was":
                    {
                        section = CurrentSection.HSchlagwort;
                        break;
                    }

                    case "Wo":
                    {
                        section = CurrentSection.JZusatzinfo;
                        break;
                    }

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

                    case "Hinweistext":
                    {
                        section = CurrentSection.LHinweis;
                        break;
                    }

                    case "Einheiten":
                    {
                        section = CurrentSection.MEinheiten;
                        break;
                    }
                    }
                    if (section == CurrentSection.GMeldender || section == CurrentSection.HSchlagwort || section == CurrentSection.JZusatzinfo || section == CurrentSection.MEinheiten)
                    {
                        section = CurrentSection.ZEnde;
                    }
                    messageText = ParserUtility.GetMessageText(line, keyword);
                }

                switch (section)
                {
                case CurrentSection.AAnfang:
                {
                    operation.OperationNumber = ParserUtility.GetTextBetween(messageText, null, "am:", StringComparison.InvariantCulture);
                    string textBeteween = ParserUtility.GetTextBetween(messageText, "am:", "um", StringComparison.InvariantCulture);
                    operation.Timestamp = ParserUtility.ReadFaxTimestamp(textBeteween, DateTime.Now);
                    break;
                }

                case CurrentSection.BAao:
                {
                    operation.Keywords.Keyword = messageText;
                    break;
                }

                case CurrentSection.CEinsatzort:
                {
                    operation.Einsatzort.Location = messageText;
                    break;
                }

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

                case CurrentSection.EOrt:
                {
                    operation.Einsatzort.City = messageText;
                    break;
                }

                case CurrentSection.FObjekt:
                {
                    operation.Einsatzort.Property = messageText;
                    break;
                }

                case CurrentSection.GMeldender:
                {
                    operation.Messenger = messageText + Environment.NewLine;
                    break;
                }

                case CurrentSection.HSchlagwort:
                {
                    operation.Keywords.EmergencyKeyword = messageText;
                    break;
                }

                case CurrentSection.JZusatzinfo:
                {
                    operation.Picture = messageText + Environment.NewLine;
                    break;
                }

                case CurrentSection.KEinsatzplan:
                {
                    operation.OperationPlan = messageText;
                    break;
                }

                case CurrentSection.LHinweis:
                {
                    operation.Comment = messageText + Environment.NewLine;
                    break;
                }

                case CurrentSection.MEinheiten:
                {
                    Match match = Regex.Match(messageText, "<(.*)>");
                    if (match.Success)
                    {
                        string            value             = match.Groups[1].Value;
                        OperationResource operationResource = new OperationResource();
                        operationResource.FullName = value;
                        operation.Resources.Add(operationResource);
                    }
                    break;
                }
                }
            }
            operation.Comment   = ParserUtility.RemoveTrailingNewline(operation.Comment);
            operation.Picture   = ParserUtility.RemoveTrailingNewline(operation.Picture);
            operation.Messenger = ParserUtility.RemoveTrailingNewline(operation.Messenger);
            return(operation);
        }
Exemple #23
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);
        }
        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);
        }
        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;
                    }

                    // 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;
                            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 = 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 "PLANNUMMER":
                            operation.CustomData["Einsatzort Plannummer"] = msg;
                            break;

                        case "STATION":
                            operation.CustomData["Einsatzort Station"] = msg;
                            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 = 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 "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 I":
                            operation.CustomData["Stichwort I"] = msg;
                            break;

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

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

                    case CurrentSection.FEinsatzmittel:
                    {
                        if (line.StartsWith("NAME", StringComparison.CurrentCultureIgnoreCase))
                        {
                            msg           = GetMessageText(line, "NAME");
                            last.FullName = msg.Trim();
                        }
                        else if (line.StartsWith("ALARMIERT", StringComparison.CurrentCultureIgnoreCase) && !string.IsNullOrEmpty(msg))
                        {
                            msg = GetMessageText(line, "Alarmiert");

                            // In case that parsing the time failed, we just assume that the resource got requested right away.
                            DateTime dt;
                            // Most of the time the OCR-software reads the colon as a "1", so we check this case right here.
                            if (!DateTime.TryParseExact(msg, "dd.MM.yyyy HH1mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                            {
                                // If this is NOT the case and it was parsed correctly, try it here
                                DateTime.TryParseExact(msg, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt);
                            }

                            last.Timestamp = dt.ToString(CultureInfo.InvariantCulture);
                        }
                        else if (line.StartsWith("AUSSTATTUNG", StringComparison.CurrentCultureIgnoreCase))
                        {
                            msg = GetMessageText(line, "Ausstattung");

                            // 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;

                    case CurrentSection.GBemerkung:
                    {
                        // Append with newline at the end in case that the message spans more than one line
                        operation.Comment = operation.Comment += msg + "\n";
                    }
                    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);
                }
            }

            // Post-processing the operation if needed
            if (!string.IsNullOrWhiteSpace(operation.Comment) && operation.Comment.EndsWith("\n"))
            {
                operation.Comment = operation.Comment.Substring(0, operation.Comment.Length - 1).Trim();
            }
            return(operation);
        }
        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.CustomData["Absender"] = msg;
                            break;

                        case "FAX":
                            operation.CustomData["Fax"] = msg;
                            break;

                        case "TERMIN":
                            operation.CustomData["Termin"] = 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 "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!", msg);
                            }

                            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 = msg.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.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":
                        {
                            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!", msg);
                            }

                            operation.Zielort.City = msg.Remove(0, operation.Zielort.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 = 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.EEinsatzgrund:
                    {
                        switch (prefix)
                        {
                        case "SCHLAGW.":
                            operation.Keywords.Keyword = msg;
                            break;

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

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

                    case CurrentSection.GEinsatzmittel:
                    {
                        last.FullName = msg;
                        operation.Resources.Add(last);
                        last = new OperationResource();
                    }
                    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);
        }
Exemple #27
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)
                    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;
                        }
                    }
                    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);
        }
Exemple #28
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 "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 "ORTSTEIL":
                        {
                            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 = msg.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 "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);
        }
        Operation IParser.Parse(string[] lines)
        {
            Operation         operation = new Operation();
            OperationResource last      = 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 = 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 "ALARM":
                            operation.Timestamp = ParserUtility.ReadFaxTimestamp(msg, DateTime.Now);
                            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;

                        case "RUFNUMMER":
                            if (operation.Messenger != null)
                            {
                                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 "ABSCHNITT":
                            operation.Einsatzort.Intersection = msg;
                            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 "EINSATZPLANNUMMER":
                            operation.OperationPlan = msg;
                            break;

                        case "STATION":
                            innerSection = InnerSection.DStation;
                            operation.CustomData["Einsatzort Station"] = 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;

                            case InnerSection.DStation:
                                operation.CustomData["Einsatzort Station"] += 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;

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

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

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

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

                            case InnerSection.DStation:
                                operation.CustomData["Zielort Station"] += 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:
                    {
                        switch (prefix)
                        {
                        case "NAME":
                            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);
                            }
                            break;

                        case "ALARMIERT":
                            // Only add to requested equipment if there is some text,
                            // otherwise the whole vehicle is the requested equipment
                            if (!string.IsNullOrWhiteSpace(msg))
                            {
                                last.Timestamp = msg;
                            }
                            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);
        }
Exemple #30
0
        public Operation Parse(string[] lines)
        {
            Operation operation = new Operation();

            operation.CustomData["Meldungen"] = string.Empty;
            operation.CustomData["Anfahrt"]   = string.Empty;
            operation.CustomData["Hydranten"] = string.Empty;
            lines = Utilities.Trim(lines);
            CurrentSection section = CurrentSection.Header;
            string         line;

            for (int i = 0; i < lines.Length; i++)
            {
                try
                {
                    line = lines[i];
                    if (line.Length == 0)
                    {
                        continue;
                    }
                    string msg = line;
                    string keyword;
                    if (ParserUtility.StartsWithKeyword(line, Keywords, out keyword))
                    {
                        msg = ParserUtility.GetMessageText(line, keyword);
                    }
                    if (!string.IsNullOrWhiteSpace(keyword))
                    {
                        switch (keyword.ToUpperInvariant())
                        {
                        case "GEMEINDE":
                            section = CurrentSection.Einsatzinfos;
                            Match match = Regex.Match(msg, @"\d{5}");
                            if (match.Success)
                            {
                                string zip = match.Value;
                                operation.Einsatzort.City    = msg.Replace(zip, "").Trim();
                                operation.Einsatzort.ZipCode = zip;
                            }
                            else
                            {
                                operation.Einsatzort.City = msg;
                            }
                            break;

                        case "ORTSTEIL":
                            operation.CustomData["Ortsteil"] = msg;
                            break;

                        case "STRASSE":
                            operation.Einsatzort.Street = msg;
                            break;

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

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

                        case "OBJEKTHINWEIS":
                            operation.Comment = msg;
                            break;

                        case "EINATZPLAN-NR.":
                            operation.OperationPlan = msg;
                            break;

                        case "HINWEIS":
                            operation.Comment = operation.Comment.AppendLine(msg);
                            break;

                        case "MELDENDER":
                            operation.Messenger = msg;
                            break;

                        case "ALTER":
                            operation.CustomData["Alter"] = msg;
                            break;

                        case "EINSATZART":
                            operation.Keywords.Keyword = msg;
                            break;

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

                        case "MELDUNGEN":
                            section = CurrentSection.Meldungen;
                            break;

                        case "BEMERKUNG":
                            section           = CurrentSection.Bemerkung;
                            operation.Comment = operation.Comment.AppendLine(msg);
                            break;

                        case "ANFAHRTSVORSCHLAG VON HAUPTWACHE":
                            section = CurrentSection.Anfahrt;
                            break;

                        case "BETEILIGTE EINSATZMITTEL":
                            section = CurrentSection.Einsatzmittel;
                            break;

                        case "HYDRANT VOR HAUSNUMMER":
                            section = CurrentSection.Hydranten;
                            break;
                        }
                    }
                    else
                    {
                        switch (section)
                        {
                        case CurrentSection.Meldungen:
                            operation.CustomData["Meldungen"] = (operation.CustomData["Meldungen"] as string).AppendLine(msg);
                            break;

                        case CurrentSection.Bemerkung:
                            operation.Comment = operation.Comment.AppendLine(msg);
                            break;

                        case CurrentSection.Anfahrt:
                            operation.CustomData["Anfahrt"] = (operation.CustomData["Anfahrt"] as string).AppendLine(msg);
                            break;

                        case CurrentSection.Einsatzmittel:
                            Match result = Regex.Match(msg, @"\d{3}(\.\d{2}){2}");
                            if (result.Success)
                            {
                                operation.Resources.Add(new OperationResource
                                {
                                    FullName = result.Value
                                });
                            }
                            break;

                        case CurrentSection.Hydranten:
                            operation.CustomData["Hydranten"] = (operation.CustomData["Hydranten"] as string).AppendLine(msg);
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, "Error while parsing line '{0}'. The error message was: {1}", i, ex.Message);
                }
            }

            //The last line contains sometimes informations about the alarmtime, operationnumber,... here I try(!) to get them.
            line = lines[lines.Length - 1];
            try
            {
                Match    result = Regex.Match(line, @"(0[1-9]|[12][0-9]|3[01])[- /.] ?(0[1-9]|1[012])[- /.] ?(19|20)\d\d");
                DateTime date   = DateTime.Now;
                if (result.Success)
                {
                    DateTime.TryParse(result.Value.Replace(" ", ""), out date);
                }
                operation.Timestamp = ParserUtility.ReadFaxTimestamp(line, date);
                result = Regex.Match(line, @"\d{10}");
                if (result.Success)
                {
                    operation.OperationNumber = result.Value;
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.LogFormat(LogType.Warning, this, "Error while parsing line '{0}'. The error message was: {1}", lines.Length - 1, ex.Message);
            }
            return(operation);
        }