Exemplo n.º 1
0
        /// <summary>
        /// The constructor for creating a new <see cref="ResourceObject"/>
        /// </summary>
        /// <param name="emk">The filtered entry. Can be null!</param>
        /// <param name="resource">The original entry. Can't be null!</param>
        public ResourceObject(EmkResource emk, OperationResource resource)
        {
            Assertions.AssertNotNull(resource, "resource");

            Emk      = emk;
            Resource = resource;
        }
Exemplo n.º 2
0
        public void CanWriteErrorWhenSetGatewayCredentialFailedSupportsProcess()
        {
            var result = new OperationResource
            {
                ErrorInfo = new ErrorInfo {
                    Code = "Ambari Failed Code", Message = "GetAmbariUserFailed"
                },
                StatusCode = HttpStatusCode.OK,
                State      = AsyncOperationState.Failed
            };

            commandRuntimeMock.Setup(c => c.ShouldProcess(ClusterName, It.IsAny <string>())).Returns(true);

            hdinsightManagementMock.Setup(
                c =>
                c.UpdateGatewayCredential(ResourceGroupName, ClusterName,
                                          It.Is <HttpSettingsParameters>(
                                              param =>
                                              param.HttpUserEnabled && param.HttpUsername == _httpCred.UserName &&
                                              param.HttpPassword == _httpCred.Password.ConvertToString())))
            .Returns(result)
            .Verifiable();

            setcmdlet.ExecuteCmdlet();

            commandRuntimeMock.VerifyAll();
            commandRuntimeMock.Verify(
                f =>
                f.WriteError(It.Is <ErrorRecord>(
                                 record =>
                                 record.Exception.Message == $"{result.ErrorInfo.Code}: {result.ErrorInfo.Message}" &&
                                 string.IsNullOrEmpty(record.FullyQualifiedErrorId) &&
                                 record.CategoryInfo.Category == ErrorCategory.InvalidArgument)),
                Times.Once);
        }
Exemplo n.º 3
0
        public void TestCreateDuplicateCluster()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (var context = UndoContext.Current)
            {
                context.Start();

                var client = HDInsightManagementTestUtilities.GetHDInsightManagementClient(handler);
                var resourceManagementClient = HDInsightManagementTestUtilities.GetResourceManagementClient(handler);
                var resourceGroup            = HDInsightManagementTestUtilities.CreateResourceGroup(resourceManagementClient);

                var          cluster = GetClusterSpecHelpers.GetPaasClusterSpec();
                const string dnsname = "hdisdk-clusterdupe";

                var createresponse = client.Clusters.Create(resourceGroup, dnsname, cluster);
                Assert.Equal(dnsname, createresponse.Cluster.Name);

                try
                {
                    client.Clusters.Create(resourceGroup, dnsname, cluster);
                }
                catch (CloudException ex)
                {
                    Assert.Equal(ex.Response.StatusCode, HttpStatusCode.Conflict);
                }

                OperationResource result = client.Clusters.Delete(resourceGroup, dnsname);
                Assert.Equal(result.StatusCode, HttpStatusCode.OK);
                Assert.Equal(result.State, AsyncOperationState.Succeeded);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OperationResourceData"/> class,
 /// and copies the contents of the given <see cref="OperationResource"/> to this entity.
 /// </summary>
 /// <param name="operationResource">The resource to copy its contents.</param>
 public OperationResourceData(OperationResource operationResource)
     : this()
 {
     this.FullName     = operationResource.FullName;
     this.Timestamp    = operationResource.Timestamp;
     this.EquipmentCsv = CsvHelper.ToCsvLine(operationResource.RequestedEquipment);
 }
Exemplo n.º 5
0
        public void TestCreateDataLakeClusterUsingClusterCreateParametersExtended()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (var context = UndoContext.Current)
            {
                context.Start();

                //get clients
                var client = HDInsightManagementTestUtilities.GetHDInsightManagementClient(handler);
                var resourceManagementClient = HDInsightManagementTestUtilities.GetResourceManagementClient(handler);

                //create resourcegroup
                var resourceGroup = HDInsightManagementTestUtilities.CreateResourceGroup(resourceManagementClient);

                //set variables
                const string dnsname = "hdisdk-datalake5";

                var spec = GetDataLakeClusterParametersExtended();

                var createresponse = client.Clusters.Create(resourceGroup, dnsname, spec);

                //TODO: Assert if data lake configurations are set once shefali adds GetConfigurations support
                var getresponse = client.Clusters.Get(resourceGroup, dnsname);
                Assert.Equal(createresponse.Cluster.Properties.CreatedDate, getresponse.Cluster.Properties.CreatedDate);
                Assert.Equal(createresponse.Cluster.Name, getresponse.Cluster.Name);

                OperationResource result = client.Clusters.Delete(resourceGroup, dnsname);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Determines whether or not this and the given <see cref="OperationResource"/> instance can be considered equal.
        /// </summary>
        /// <param name="other">The other instance to check.</param>
        /// <returns></returns>
        public bool IsMatch(OperationResource other)
        {
            if (other == null || string.IsNullOrWhiteSpace(other.FullName))
            {
                return(false);
            }

            return(other.FullName.Contains(SiteAlias) &&
                   other.FullName.Contains(ResourceAlias));
        }
Exemplo n.º 7
0
        internal static OperationResourceData ToData(this OperationResource operationResource)
        {
            OperationResourceData data = new OperationResourceData();

            data.FullName  = operationResource.FullName;
            data.Timestamp = operationResource.Timestamp;
            data.Equipment = CsvHelper.ToCsvLine(operationResource.RequestedEquipment);

            return(data);
        }
Exemplo n.º 8
0
        internal ResourceViewModel(OperationResource resource, EmkResource emkResource)
            : base()
        {
            Assertions.AssertNotNull(resource, "resource");

            this.Resource = resource;

            _emkResource = emkResource;
            if (_emkResource != null)
            {
                LoadIconAsync();
            }
        }
Exemplo n.º 9
0
        internal ResourceViewModel(OperationResource resource, EmkResource emkResource)
            : base()
        {
            if (resource == null && emkResource == null)
            {
                throw new InvalidOperationException(Properties.Resources.NoResourceGiven);
            }
            this.Resource = resource;

            EmkResourceItem = emkResource;
            if (EmkResourceItem != null)
            {
                LoadIconAsync();
            }
        }
Exemplo n.º 10
0
        public void IsMatch_Negative_Test()
        {
            EmkResource emk = new EmkResource()
            {
                SiteAlias     = "ABC",
                ResourceAlias = "99/9",
                DisplayName   = "99.9",
            };

            OperationResource opRes = new OperationResource()
            {
                FullName = "1.2.3 XYZ 99/9 HLF",
            };

            Assert.IsFalse(emk.IsMatch(opRes));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Gets the vehicle type or specification (RW, DLK 23/12 etc.) from the resource name.
        /// </summary>
        /// <param name="resource">The resource to get the type or specification from.</param>
        /// <returns>The type or specification string. -or- null, if none found.</returns>
        private string GetVehicleType(OperationResource resource)
        {
            // Find the type/spec name entrenched between the brackets.
            int iOpenBracket    = resource.FullName.LastIndexOf('(');
            int iClosingBracket = resource.FullName.LastIndexOf(')');

            // Check invalid conditions.
            if (iOpenBracket == -1 || iClosingBracket == -1 || (iOpenBracket > iClosingBracket))
            {
                return(null);
            }

            // Cut out the middle part "1312fghasldkjf 30/1 (DLK 23/12)" ==> "DLK 23/12".
            int start  = iOpenBracket + 1;
            int length = (iClosingBracket - 1) - iOpenBracket;

            return(resource.FullName.Substring(start, length));
        }
        public void ContainsMatch_WithInactiveOnes_Negative_Test()
        {
            EmkResourceCollection collection = new EmkResourceCollection();

            collection.Add(new EmkResource()
            {
                SiteAlias = "ABC", ResourceAlias = "77/7"
            });
            collection.Add(new EmkResource()
            {
                SiteAlias = "ABC", ResourceAlias = "88/8", IsActive = false
            });
            collection.Add(new EmkResource()
            {
                SiteAlias = "ABC", ResourceAlias = "99/9"
            });

            OperationResource opRes = new OperationResource()
            {
                FullName = "1.2.3 ABC 88/8 LF",
            };

            Assert.IsFalse(collection.ContainsMatch(opRes));
        }
        public void ContainsMatch_Positive_Test()
        {
            EmkResourceCollection collection = new EmkResourceCollection();

            collection.Add(new EmkResource()
            {
                SiteAlias = "ABC", ResourceAlias = "77/7"
            });
            collection.Add(new EmkResource()
            {
                SiteAlias = "ABC", ResourceAlias = "88/8"
            });
            collection.Add(new EmkResource()
            {
                SiteAlias = "ABC", ResourceAlias = "99/9"
            });

            OperationResource opRes = new OperationResource()
            {
                FullName = "1.2.3 ABC 88/8 LF",
            };

            Assert.IsTrue(collection.ContainsMatch(opRes));
        }
Exemplo n.º 14
0
 internal ResourceViewModel(OperationResource resource)
     : this(resource, null)
 {
 }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Examines every resource that is contained in this collection and returns a boolean value if at least
        /// one resource matches the given <see cref="OperationResource"/>.
        /// See documentation for further information.
        /// </summary>
        /// <remarks>Any given <see cref="EmkResource"/> is only considered if it has its IsActive-flag set to true.</remarks>
        /// <param name="resource">The <see cref="OperationResource"/> to check. Must not be null.</param>
        /// <returns>A boolean value indicating whether or not at least one resource matches the given <see cref="OperationResource"/>.</returns>
        public bool ContainsMatch(OperationResource resource)
        {
            Assertions.AssertNotNull(resource, "resource");

            return(Items.Any(item => item.IsActive && item.IsMatch(resource)));
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
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.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);
        }
Exemplo n.º 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;
            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);
        }
Exemplo n.º 20
0
        Operation IParser.Parse(string[] lines)
        {
            var operation         = new Operation();
            var operationResource = new OperationResource();

            lines = Utilities.Trim(lines);

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

            InnerSection innerSection = InnerSection.AStraße;

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

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


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

                    string msg    = line;
                    string prefix = "";

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

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

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

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

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

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

                        case "ABSCHNITT":
                            break;

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

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

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

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

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

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

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

                            break;

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

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

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

                            break;
                        }
                    }
                    break;

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

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

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

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

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

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

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

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

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

            return(operation);
        }
        public AzureHDInsightRuntimeScriptActionOperationResource(RuntimeScriptAction runtimeScriptAction, OperationResource operationResource)
            : base(runtimeScriptAction)
        {
            if (operationResource.ErrorInfo != null)
            {
                ErrorMessage = operationResource.ErrorInfo.Message;
            }

            OperationState = operationResource.State.ToString();
        }
        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);
        }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
        Operation IParser.Parse(string[] lines)
        {
            Operation operation = new Operation();

            lines = Utilities.Trim(lines);
            CurrentSection section = CurrentSection.AHeader;

            for (int index = 0; index < lines.Length; index++)
            {
                string line = lines[index];
                if (line.ToUpper().StartsWith("ALARMPLAN"))
                {
                    String temp = line.Substring(line.ToUpper().IndexOf("EINSATZNUMMER", StringComparison.Ordinal)).Trim();
                    temp = temp.Substring(temp.IndexOf(" ", StringComparison.Ordinal)).Trim();
                    operation.OperationNumber = temp.Substring(0, temp.IndexOf(" ", StringComparison.Ordinal)).Trim();
                    section = CurrentSection.BBody;
                }
                else if (line.ToUpper().StartsWith("PLZ ORT"))
                {
                    operation.Einsatzort.City = GetMessageText(line, "PLZ ORT");
                }
                else if (line.ToUpper().StartsWith("STRASSE"))
                {
                    operation.Einsatzort.Street = GetMessageText(line, "STRASSE");
                }
                else if (line.ToUpper().StartsWith("OBJEKT"))
                {
                    operation.Einsatzort.Property = GetMessageText(line, "OBJEKT");
                }
                else if (line.ToUpper().StartsWith("TELEFON"))
                {
                    operation.Messenger = GetMessageText(line, "TELEFON");
                }
                else if (line.ToUpper().StartsWith("MELDUNG INFO"))
                {
                    operation.Comment = GetMessageText(line, "MELDUNG INFO");
                }
                else if (line.ToUpper().StartsWith("EINSATZART"))
                {
                    operation.Keywords.Keyword = GetMessageText(line, "EINSATZART");
                }
                else if (line.ToUpper().StartsWith("STICHWORT"))
                {
                    operation.Keywords.EmergencyKeyword = GetMessageText(line, "STICHWORT");
                }
                else if (line.ToUpper().StartsWith("ANFAHRT"))
                {
                    section = CurrentSection.CAnfahrt;
                    continue;
                }
                else if (line.ToUpper().StartsWith("BETEILIGTE EINSATZMITTEL"))
                {
                    section = CurrentSection.DEinsatzMittel;
                    continue;
                }
                else if (line.ToUpper().StartsWith("AP"))
                {
                    section = CurrentSection.EFooter;
                }
                switch (section)
                {
                case CurrentSection.CAnfahrt:
                    if (line.Contains("PLZ"))
                    {
                        operation.OperationPlan = line.Substring(0, line.ToUpper().IndexOf("PLZ", StringComparison.Ordinal));
                        String temp = line.Substring(line.ToUpper().IndexOf("PLZ", StringComparison.Ordinal));
                        if (temp.Contains(" "))
                        {
                            temp = temp.Substring(temp.IndexOf(" ", StringComparison.Ordinal));
                        }
                        operation.Einsatzort.ZipCode = temp.Trim();
                    }
                    else
                    {
                        operation.OperationPlan = line;
                    }
                    //Only the first line is interesting ;)
                    section = CurrentSection.BBody;
                    break;

                case CurrentSection.DEinsatzMittel:
                    if (line.ToUpper().Contains("FAHRZEUG"))
                    {
                        continue;
                    }

                    Regex timeStamp = new Regex("\\d\\d:\\d\\d:\\d\\d");
                    line = timeStamp.Replace(line, "").Trim();
                    OperationResource resource = new OperationResource {
                        FullName = line
                    };
                    operation.Resources.Add(resource);
                    break;

                case CurrentSection.EFooter:
                    return(operation);
                }
            }
            return(operation);
        }
Exemplo n.º 25
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;

            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);
        }
Exemplo n.º 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);
        }
        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);
        }
Exemplo n.º 29
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;

            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);
        }
Exemplo n.º 30
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);
        }