Skip to content

Commit e5a3894

Browse files
committed
Fix #144: Avoid usage of file info to not fail on long file names according to provided stack trace.
1 parent a837cae commit e5a3894

File tree

7 files changed

+66
-78
lines changed

7 files changed

+66
-78
lines changed

ResXManager.Model/FileFilter.cs

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
1-
namespace tomenglertde.ResXManager.Model
2-
{
3-
using System;
4-
using System.Diagnostics;
5-
using System.Diagnostics.CodeAnalysis;
6-
using System.Diagnostics.Contracts;
7-
using System.IO;
8-
using System.Linq;
9-
using System.Text.RegularExpressions;
10-
11-
using JetBrains.Annotations;
12-
13-
using tomenglertde.ResXManager.Infrastructure;
14-
15-
public class FileFilter : IFileFilter
16-
{
1+
namespace tomenglertde.ResXManager.Model
2+
{
3+
using System;
4+
using System.Diagnostics;
5+
using System.Diagnostics.CodeAnalysis;
6+
using System.Diagnostics.Contracts;
7+
using System.IO;
8+
using System.Linq;
9+
using System.Text.RegularExpressions;
10+
11+
using JetBrains.Annotations;
12+
13+
using tomenglertde.ResXManager.Infrastructure;
14+
15+
public class FileFilter : IFileFilter
16+
{
1717
[NotNull]
1818
[ItemNotNull]
1919
private readonly string[] _extensions;
2020
[CanBeNull]
21-
private readonly Regex _fileExclusionFilter;
22-
23-
public FileFilter([NotNull] Configuration configuration)
24-
{
25-
Contract.Requires(configuration != null);
26-
27-
_extensions = configuration.CodeReferences
28-
.Items.SelectMany(item => item.ParseExtensions())
29-
.Distinct()
30-
.ToArray();
31-
32-
_fileExclusionFilter = configuration.FileExclusionFilter.TryCreateRegex();
33-
}
34-
35-
public bool IsSourceFile(ProjectFile file)
36-
{
37-
return _extensions.Contains(file.Extension, StringComparer.OrdinalIgnoreCase);
38-
}
39-
40-
public bool IncludeFile(FileInfo fileInfo)
41-
{
42-
return _fileExclusionFilter?.IsMatch(fileInfo.FullName) != true;
43-
}
44-
45-
[ContractInvariantMethod]
46-
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")]
47-
[Conditional("CONTRACTS_FULL")]
48-
private void ObjectInvariant()
49-
{
50-
Contract.Invariant(_extensions != null);
51-
}
52-
}
21+
private readonly Regex _fileExclusionFilter;
22+
23+
public FileFilter([NotNull] Configuration configuration)
24+
{
25+
Contract.Requires(configuration != null);
26+
27+
_extensions = configuration.CodeReferences
28+
.Items.SelectMany(item => item.ParseExtensions())
29+
.Distinct()
30+
.ToArray();
31+
32+
_fileExclusionFilter = configuration.FileExclusionFilter.TryCreateRegex();
33+
}
34+
35+
public bool IsSourceFile(ProjectFile file)
36+
{
37+
return _extensions.Contains(file.Extension, StringComparer.OrdinalIgnoreCase);
38+
}
39+
40+
public bool IncludeFile(ProjectFile file)
41+
{
42+
return _fileExclusionFilter?.IsMatch(file.RelativeFilePath) != true;
43+
}
44+
45+
[ContractInvariantMethod]
46+
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")]
47+
[Conditional("CONTRACTS_FULL")]
48+
private void ObjectInvariant()
49+
{
50+
Contract.Invariant(_extensions != null);
51+
}
52+
}
5353
}

ResXManager.Model/IFileFilter.cs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,11 @@
11
namespace tomenglertde.ResXManager.Model
22
{
3-
using System.Diagnostics.Contracts;
4-
using System.IO;
5-
63
using JetBrains.Annotations;
74

8-
[ContractClass(typeof(FileFilterContract))]
95
public interface IFileFilter
106
{
117
bool IsSourceFile([NotNull] ProjectFile file);
128

13-
bool IncludeFile([NotNull] FileInfo fileInfo);
14-
}
15-
16-
[ContractClassFor(typeof(IFileFilter))]
17-
internal abstract class FileFilterContract : IFileFilter
18-
{
19-
public bool IsSourceFile(ProjectFile file)
20-
{
21-
Contract.Requires(file != null);
22-
23-
throw new System.NotImplementedException();
24-
}
25-
26-
public bool IncludeFile(FileInfo fileInfo)
27-
{
28-
Contract.Requires(fileInfo != null);
29-
30-
throw new System.NotImplementedException();
31-
}
9+
bool IncludeFile([NotNull] ProjectFile file);
3210
}
3311
}

ResXManager.Model/ResourceManagerExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public static IList<ProjectFile> GetAllSourceFiles([NotNull] this DirectoryInfo
2626
Contract.Assume(fileInfos != null);
2727

2828
var allProjectFiles = fileInfos
29-
.Where(fileFilter.IncludeFile)
3029
.Select(fileInfo => new ProjectFile(fileInfo.FullName, solutionFolder.FullName, @"<unknown>", null))
30+
.Where(fileFilter.IncludeFile)
3131
.Where(file => file.IsResourceFile() || fileFilter.IsSourceFile(file))
3232
.ToArray();
3333

ResXManager.Scripting/SourceFilesProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public bool IsSourceFile(ProjectFile file)
4444
return false;
4545
}
4646

47-
public bool IncludeFile(FileInfo fileInfo)
47+
public bool IncludeFile(ProjectFile file)
4848
{
49-
return _fileExclusionFilter?.IsMatch(fileInfo.FullName) != true;
49+
return _fileExclusionFilter?.IsMatch(file.RelativeFilePath) != true;
5050
}
5151
}
5252
}

ResXManager.VSIX/DteSourceFilesProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private IEnumerable<DteProjectFile> DteSourceFiles
5454
{
5555
var fileFilter = new FileFilter(_configuration);
5656

57-
return GetProjectFiles().Where(p => fileFilter.IncludeFile(new FileInfo(p.FilePath)) && (p.IsResourceFile() || fileFilter.IsSourceFile(p)));
57+
return GetProjectFiles().Where(p => fileFilter.IncludeFile(p) && (p.IsResourceFile() || fileFilter.IsSourceFile(p)));
5858
}
5959
}
6060

ResXManager.View/Visuals/ResourceView.xaml.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public partial class ResourceView
3636
private readonly Configuration _configuration;
3737
[NotNull]
3838
private readonly ResourceViewModel _resourceViewModel;
39+
[NotNull]
40+
private readonly ITracer _tracer;
3941

4042
[ImportingConstructor]
4143
public ResourceView([NotNull] ExportProvider exportProvider)
@@ -45,6 +47,7 @@ public ResourceView([NotNull] ExportProvider exportProvider)
4547
_resourceManager = exportProvider.GetExportedValue<ResourceManager>();
4648
_resourceViewModel = exportProvider.GetExportedValue<ResourceViewModel>();
4749
_configuration = exportProvider.GetExportedValue<Configuration>();
50+
_tracer = exportProvider.GetExportedValue<ITracer>();
4851

4952
try
5053
{
@@ -205,9 +208,9 @@ private void CommandConverter_Error([NotNull] object sender, [NotNull] ErrorEven
205208
if (ex == null)
206209
return;
207210

208-
var text = ex is ImportException ? ex.Message : ex.ToString();
211+
MessageBox.Show(ex.Message, Properties.Resources.Title);
209212

210-
MessageBox.Show(text, Properties.Resources.Title);
213+
_tracer.TraceError(ex.ToString());
211214
}
212215

213216
private class ExportParameters : IExportParameters

ResXManager.View/Visuals/ResourceViewModel.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,14 @@ private void Reload(bool forceFindCodeReferences)
527527
[Throttled(typeof(DispatcherThrottle), (int)DispatcherPriority.ContextIdle)]
528528
private void BeginFindCodeReferences()
529529
{
530-
BeginFindCodeReferences(_sourceFilesProvider.SourceFiles);
530+
try
531+
{
532+
BeginFindCodeReferences(_sourceFilesProvider.SourceFiles);
533+
}
534+
catch (Exception ex)
535+
{
536+
_tracer.TraceError(ex.ToString());
537+
}
531538
}
532539

533540
private void BeginFindCodeReferences([NotNull, ItemNotNull] IList<ProjectFile> allSourceFiles)

0 commit comments

Comments
 (0)