void ParseFile(string projectDirectory, string filePath, ConcurrentDictionary <string, TemplateItem> templateItems) { var referencePath = PathNormalizer.MakeRelativePath(projectDirectory, filePath); DebugHelpers.WriteLine("FileNuggetFinder.ParseFile -- {0}", filePath); // Lookup any/all nuggets in the file and for each add a new template item. using var fs = I18NUtility.Retry(() => File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read), 3); using var streamReader = new StreamReader(fs); _nuggetParser.ParseString(streamReader.ReadToEnd(), delegate(string nuggetString, int pos, Nugget nugget, string iEntity) { var referenceContext = _localizationOptions.DisableReferences ? ReferenceContext.Create("Disabled references", iEntity, 0) : ReferenceContext.Create(referencePath, iEntity, pos); var fileName = Path.GetFileNameWithoutExtension(filePath); // If we have a file like "myfile.aspx.vb" then the fileName will be "myfile.aspx" resulting in split // .pot files. So remove all extensions, so that we just have the actual name to deal with. fileName = fileName.IndexOf('.') > -1 ? fileName.Split('.')[0] : fileName; AddNewTemplateItem( fileName, referenceContext, nugget, templateItems); // Done. return(null); // null means we are not modifying the entity. }); }
private static void AssertExpectedContext(int position, ReferenceContext expected, string reason) { var actual = ReferenceContext.Create(Path, Content, position); Assert.AreEqual(expected.Path, actual.Path, "Path: " + reason); Assert.AreEqual(expected.LineNumber, actual.LineNumber, "LineNumber: " + reason); Assert.AreEqual(expected.Context, actual.Context, "Context:" + reason); }
private void ParseString(string projectDirectory, string content, string context, ConcurrentDictionary <string, TemplateItem> templateItems) { // Lookup any/all nuggets in the file and for each add a new template item. _nuggetParser.ParseString(content, delegate(string nuggetString, int pos, Nugget nugget, string i_entity) { var referenceContext = ReferenceContext.Create(context, i_entity, pos); AddNewTemplateItem( referenceContext, nugget, templateItems); // Done. return(null); // null means we are not modifying the entity. }); }
private void ParseFile(string projectDirectory, string filePath, ConcurrentDictionary <string, TemplateItem> templateItems) { var referencePath = PathNormalizer.MakeRelativePath(projectDirectory, filePath); DebugHelpers.WriteLine("FileNuggetFinder.ParseFile -- {0}", filePath); // Lookup any/all nuggets in the file and for each add a new template item. using (var fs = File.OpenText(filePath)) { _nuggetParser.ParseString(fs.ReadToEnd(), delegate(string nuggetString, int pos, Nugget nugget, string i_entity) { var referenceContext = ReferenceContext.Create(referencePath, i_entity, pos); AddNewTemplateItem( referenceContext, nugget, templateItems); // Done. return(null); // null means we are not modifying the entity. }); } }