Beispiel #1
0
        public SniffInfo Sniff(string nativeFilePath, Language suggestedSourceLanguage, Codepage suggestedCodepage,
                               INativeTextLocationMessageReporter messageReporter, ISettingsGroup settingsGroup)
        {
            try
            {
                var input = File.ReadAllText(nativeFilePath);
                JToken.Parse(input);
            }
            catch (JsonException e)
            {
                messageReporter.ReportMessage(this, nativeFilePath,
                                              ErrorLevel.Error, JsonFileTypeResources.Invalid_Json_Format, e.Message);

                return(new SniffInfo {
                    IsSupported = false
                });
            }
            catch (Exception)
            {
                messageReporter.ReportMessage(this, nativeFilePath,
                                              ErrorLevel.Error, JsonFileTypeResources.Json_Could_Not_Be_Validated, string.Empty);

                return(new SniffInfo {
                    IsSupported = false
                });
            }

            return(new SniffInfo {
                IsSupported = true
            });
        }
Beispiel #2
0
        public SniffInfo Sniff(string nativeFilePath, Language suggestedSourceLanguage, Codepage suggestedCodepage,
                               INativeTextLocationMessageReporter messageReporter, ISettingsGroup settingsGroup)
        {
            try
            {
                using (var reader = _yamlFactory.CreateYamlTextReader(nativeFilePath))
                {
                    while (reader.Read())
                    {
                    }
                }
            }
            catch (YamlException e)
            {
                messageReporter.ReportMessage(this, nativeFilePath,
                                              ErrorLevel.Error, YamlFileTypeResources.Invalid_Yaml_Format + "(" + e.Message + ")", e.Message);

                return(new SniffInfo {
                    IsSupported = false
                });
            }
            catch (Exception e)
            {
                messageReporter.ReportMessage(this, nativeFilePath,
                                              ErrorLevel.Error, YamlFileTypeResources.Yaml_Could_Not_Be_Validated, e.Message);

                return(new SniffInfo {
                    IsSupported = false
                });
            }

            return(new SniffInfo {
                IsSupported = true
            });
        }
        public void Sniff_WhenEndIsInvalid_ShouldReportExpectedPattern()
        {
            // Arrange
            var testString = @"
#: a comment
msgid ""The msgid text""
msgstr ""The msgstr text""

msgid ""The msgid text""
";
            var testee     = CreateTestee(testString);

            A.CallTo(() => _lineValidationSessionMock.IsValid(A <string> .Ignored)).Returns(true);
            A.CallTo(() => _lineValidationSessionMock.IsValid(MarkerLines.EndOfFile)).Returns(false);
            A.CallTo(() => _lineValidationSessionMock.NextExpectedLineDescription).Returns("msgstr");

            // Act
            testee.Sniff(TestFilePath, _testLanguage, _testCodepage, _messageReporterMock, _settingsGroupMock);

            // Assert
            A.CallTo(() => _messageReporterMock.ReportMessage(
                         testee,
                         TestFilePath,
                         ErrorLevel.Error,
                         A <string> .That.Contains("msgstr"),
                         A <string> .Ignored
                         )).MustHaveHappened();
        }
        public SniffInfo Sniff(string nativeFilePath, Language suggestedSourceLanguage, Codepage suggestedCodepage,
                               INativeTextLocationMessageReporter messageReporter, ISettingsGroup settingsGroup)
        {
            SniffInfo fileInfo = new SniffInfo();

            using (StreamReader _reader = new StreamReader(nativeFilePath))
            {
                if (_reader.ReadLine().StartsWith("[Version="))
                {
                    fileInfo.IsSupported = true;
                }
                else
                {
                    fileInfo.IsSupported = false;
                    messageReporter.ReportMessage(this, nativeFilePath,
                                                  ErrorLevel.Error, StringResources.Sniffer_Message,
                                                  StringResources.Sniffer_Location);
                }
            }

            return(fileInfo);
        }
        public SniffInfo Sniff(string nativeFilePath, Language suggestedSourceLanguage, Codepage suggestedCodepage,
                               INativeTextLocationMessageReporter messageReporter, ISettingsGroup settingsGroup)
        {
            var lineValidationSession = _lineParser.StartLineValidationSession();

            using (var extendedStreamReader = _fileHelper.GetExtendedStreamReader(nativeFilePath))
            {
                string currentLine;
                while ((currentLine = extendedStreamReader.ReadLineWithEofLine()) != null)
                {
                    var isValidLine = lineValidationSession.IsValid(currentLine);

                    if (isValidLine)
                    {
                        continue;
                    }

                    var message = string.Format(
                        PoFileTypeResources.Sniffer_Unexpected_Line,
                        extendedStreamReader.CurrentLineNumber + ": " + currentLine,
                        lineValidationSession.NextExpectedLineDescription);

                    messageReporter.ReportMessage(this, nativeFilePath,
                                                  ErrorLevel.Error, message,
                                                  extendedStreamReader.CurrentLineNumber + ": " + currentLine);

                    return(new SniffInfo {
                        IsSupported = false
                    });
                }
            }

            return(new SniffInfo {
                IsSupported = true
            });
        }