Skip to content

Commit 725bb81

Browse files
authored
Merge pull request #29 from paulushub/master
SvgTestBox: Added the quick testing application for debugging issues
2 parents acf3c18 + 3eda8a0 commit 725bb81

File tree

90 files changed

+7693
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+7693
-15
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ ClientBin
102102
~$*
103103
*.dbmdl
104104
Generated_Code #added for RIA/Silverlight projects
105+
Tests/Svg-Icons
106+
Tests/Libs/Sources
105107

106108
# Backup & report files from converting an old project file to a newer
107109
# Visual Studio version. Backup files are not needed, because we have git ;-)

Docs/sample.png

-2.05 KB
Loading
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version ="1.0"?>
2+
<configuration>
3+
<runtime>
4+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5+
<dependentAssembly>
6+
<assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
7+
<bindingRedirect oldVersion="0.0.0.0-2.6.8.0" newVersion="2.6.8.0" />
8+
</dependentAssembly>
9+
<dependentAssembly>
10+
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
11+
<bindingRedirect oldVersion="0.0.0.0-2.6.8.0" newVersion="2.6.8.0" />
12+
</dependentAssembly>
13+
<dependentAssembly>
14+
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
15+
<bindingRedirect oldVersion="0.0.0.0-2.6.8.0" newVersion="2.6.8.0" />
16+
</dependentAssembly>
17+
</assemblyBinding>
18+
</runtime>
19+
</configuration>

Samples/ClipArtViewer/ClipArtViewer.csproj

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
88
<RootNamespace>ClipArtViewer</RootNamespace>
99
<AssemblyName>ClipArtViewer</AssemblyName>
10+
<AppConfig Condition="'$(TargetFramework)' == 'net40'">App.net40.config</AppConfig>
11+
<AutoUnifyAssemblyReferences Condition="'$(TargetFramework)' == 'net40'">false</AutoUnifyAssemblyReferences>
1012
</PropertyGroup>
1113
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1214
<DebugType>full</DebugType>
@@ -46,4 +48,61 @@
4648
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
4749
</None>
4850
</ItemGroup>
51+
<ItemGroup Condition=" '$(TargetFramework)' == 'net40'">
52+
<PackageReference Include="Microsoft.Bcl.Async" Version="1.0.168" />
53+
<Reference Include="ShellFileDialogs">
54+
<HintPath>..\..\Tests\Libs\net40\ShellFileDialogs.dll</HintPath>
55+
</Reference>
56+
<Reference Include="Notifications.Wpf">
57+
<HintPath>..\..\Tests\Libs\net40\Notifications.Wpf.dll</HintPath>
58+
</Reference>
59+
</ItemGroup>
60+
<ItemGroup Condition=" '$(TargetFramework)' == 'net45'">
61+
<Reference Include="ShellFileDialogs">
62+
<HintPath>..\..\Tests\Libs\net45\ShellFileDialogs.dll</HintPath>
63+
</Reference>
64+
<Reference Include="Notifications.Wpf">
65+
<HintPath>..\..\Tests\Libs\net45\Notifications.Wpf.dll</HintPath>
66+
</Reference>
67+
</ItemGroup>
68+
<ItemGroup Condition=" '$(TargetFramework)' == 'net46'">
69+
<Reference Include="ShellFileDialogs">
70+
<HintPath>..\..\Tests\Libs\net46\ShellFileDialogs.dll</HintPath>
71+
</Reference>
72+
<Reference Include="Notifications.Wpf">
73+
<HintPath>..\..\Tests\Libs\net46\Notifications.Wpf.dll</HintPath>
74+
</Reference>
75+
</ItemGroup>
76+
<ItemGroup Condition=" '$(TargetFramework)' == 'net47'">
77+
<Reference Include="ShellFileDialogs">
78+
<HintPath>..\..\Tests\Libs\net47\ShellFileDialogs.dll</HintPath>
79+
</Reference>
80+
<Reference Include="Notifications.Wpf">
81+
<HintPath>..\..\Tests\Libs\net47\Notifications.Wpf.dll</HintPath>
82+
</Reference>
83+
</ItemGroup>
84+
<ItemGroup Condition=" '$(TargetFramework)' == 'net48'">
85+
<Reference Include="ShellFileDialogs">
86+
<HintPath>..\..\Tests\Libs\net48\ShellFileDialogs.dll</HintPath>
87+
</Reference>
88+
<Reference Include="Notifications.Wpf">
89+
<HintPath>..\..\Tests\Libs\net48\Notifications.Wpf.dll</HintPath>
90+
</Reference>
91+
</ItemGroup>
92+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.0'">
93+
<Reference Include="ShellFileDialogs">
94+
<HintPath>..\..\Tests\Libs\netstandard2.1\ShellFileDialogs.dll</HintPath>
95+
</Reference>
96+
<Reference Include="Notifications.Wpf">
97+
<HintPath>..\..\Tests\Libs\netcoreapp3.0\Notifications.Wpf.dll</HintPath>
98+
</Reference>
99+
</ItemGroup>
100+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1'">
101+
<Reference Include="ShellFileDialogs">
102+
<HintPath>..\..\Tests\Libs\netstandard2.1\ShellFileDialogs.dll</HintPath>
103+
</Reference>
104+
<Reference Include="Notifications.Wpf">
105+
<HintPath>..\..\Tests\Libs\netcoreapp3.1\Notifications.Wpf.dll</HintPath>
106+
</Reference>
107+
</ItemGroup>
49108
</Project>

Samples/ClipArtViewer/MainWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@
144144
</TabItem>
145145
<TabItem Header="Error Logging" Height="28" Width="250" x:Name="tabLogging" IsSelected="True">
146146
<RichTextBox x:Name="txtLogger" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FontSize="12"
147-
Margin="3" IsReadOnly="True" AllowDrop="False" VerticalScrollBarVisibility="Auto"
148-
IsUndoEnabled="False" HorizontalScrollBarVisibility="Auto" AcceptsReturn="True"/>
147+
Margin="3" IsReadOnly="True" AllowDrop="False" VerticalScrollBarVisibility="Visible"
148+
IsUndoEnabled="False" HorizontalScrollBarVisibility="Visible" AcceptsReturn="True"/>
149149
</TabItem>
150150
</TabControl>
151151
</DockPanel>

Samples/ClipArtViewer/MainWindow.xaml.cs

Lines changed: 109 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
using System.Windows.Media;
99
using System.Windows.Controls;
1010
using System.Windows.Documents;
11+
using System.Windows.Interop;
1112

1213
using SVGImage.SVG;
1314

15+
using ShellFileDialogs;
16+
using Notification.Wpf;
17+
1418
namespace ClipArtViewer
1519
{
1620
/// <summary>
@@ -57,12 +61,14 @@ public List<SVGItem> Items
5761
}
5862

5963
private bool _isShown;
64+
private TextBoxTraceListener _listener;
6065

6166
public MainWindow()
6267
{
6368
InitializeComponent();
6469

6570
this.Loaded += OnMainWindowLoaded;
71+
this.Closing += OnMainWindowClosing;
6672
}
6773

6874
protected override void OnContentRendered(EventArgs e)
@@ -95,7 +101,24 @@ private void OnMainWindowLoaded(object sender, RoutedEventArgs e)
95101
{
96102
txtLogger.Document.Blocks.Clear();
97103
txtLogger.SetValue(Block.LineHeightProperty, 1.0);
98-
Trace.Listeners.Add(new TextBoxTraceListener(txtLogger));
104+
105+
if (_listener == null)
106+
{
107+
_listener = new TextBoxTraceListener(txtLogger);
108+
Trace.Listeners.Add(_listener);
109+
}
110+
111+
Trace.WriteLine("");
112+
}
113+
114+
private void OnMainWindowClosing(object sender, System.ComponentModel.CancelEventArgs e)
115+
{
116+
if (_listener != null)
117+
{
118+
Trace.Listeners.Remove(_listener);
119+
_listener.Dispose();
120+
_listener = null;
121+
}
99122
}
100123

101124
void ListFiles()
@@ -105,7 +128,19 @@ void ListFiles()
105128
{
106129
return;
107130
}
131+
132+
if (m_items.Count != 0)
133+
{
134+
m_items.Clear();
135+
m_filelist.Items.Refresh();
136+
}
137+
108138
string[] files = Directory.GetFiles(path, "*.svg");
139+
if (files == null || files.Length == 0)
140+
{
141+
return;
142+
}
143+
109144
foreach (string file in files)
110145
m_items.Add(new SVGItem(file));
111146

@@ -132,7 +167,15 @@ private void OnTabControlSelectionChanged(object sender, SelectionChangedEventAr
132167

133168
private void OnBrowseButtonClick(object sender, RoutedEventArgs e)
134169
{
135-
MessageBox.Show("Not implemented yet!", "ClipArtViewer", MessageBoxButton.OK, MessageBoxImage.Information);
170+
var sampleDir = Path.GetFullPath(SamplesDir);
171+
IntPtr windowHandle = new WindowInteropHelper(this).Handle;
172+
string selectedDirectory = FolderBrowserDialog.ShowDialog(windowHandle,
173+
"Select the location of the SVG files", Path.GetDirectoryName(sampleDir));
174+
if (selectedDirectory != null)
175+
{
176+
this.SvgPath = selectedDirectory;
177+
ListFiles();
178+
}
136179
}
137180
}
138181

@@ -178,7 +221,7 @@ void EnsureLoaded()
178221
return;
179222
}
180223
_isLogged = true;
181-
Trace.WriteLine("Exception Loading: " + this.FullPath);
224+
Trace.TraceError("Exception Loading: " + this.FullPath);
182225
Trace.WriteLine(ex.ToString());
183226
Trace.WriteLine(string.Empty);
184227
}
@@ -187,11 +230,22 @@ void EnsureLoaded()
187230

188231
public class TextBoxTraceListener : TraceListener
189232
{
233+
private delegate void AppendTextDelegate(string message);
234+
235+
private const string AppTitle = "ClipArtViewer";
236+
private const string AppName = "ClipArtViewer.exe";
237+
190238
private RichTextBox _textBox;
239+
private NotificationManager _notifyIcon;
240+
241+
private AppendTextDelegate _appendText;
191242

192243
public TextBoxTraceListener(RichTextBox textBox)
193244
{
194-
_textBox = textBox;
245+
_textBox = textBox;
246+
_notifyIcon = new NotificationManager();
247+
248+
_appendText = new AppendTextDelegate(AppendText);
195249
}
196250

197251
public override void Write(string message)
@@ -202,27 +256,72 @@ public override void Write(string message)
202256
}
203257
else
204258
{
205-
_textBox.Dispatcher.Invoke(new AppendTextDelegate(AppendText), message);
259+
_textBox.Dispatcher.Invoke(_appendText, message);
206260
}
207261
}
208262

209263
public override void WriteLine(string message)
210264
{
211265
if (_textBox.Dispatcher.CheckAccess())
212266
{
213-
AppendText(message);
267+
AppendText(message + Environment.NewLine);
214268
}
215269
else
216270
{
217-
_textBox.Dispatcher.Invoke(new AppendTextDelegate(AppendText), message);
271+
_textBox.Dispatcher.Invoke(_appendText, message + Environment.NewLine);
218272
}
219273
}
220274

221-
private delegate void AppendTextDelegate(string message);
222-
223275
private void AppendText(string message)
224276
{
225-
_textBox.AppendText(message + Environment.NewLine);
277+
if (_textBox == null || message == null)
278+
{
279+
return;
280+
}
281+
282+
if (message.StartsWith(AppName, StringComparison.OrdinalIgnoreCase))
283+
{
284+
message = message.Remove(0, AppName.Length + 1);
285+
}
286+
287+
if (message.StartsWith("Error", StringComparison.OrdinalIgnoreCase))
288+
{
289+
_textBox.AppendText(message);
290+
if (_notifyIcon != null)
291+
{
292+
_notifyIcon.Show(AppTitle, "There is an error, see the Error Logging page for more information.",
293+
NotificationType.Error, "", TimeSpan.FromSeconds(5));
294+
}
295+
}
296+
else if (message.StartsWith("Warn", StringComparison.OrdinalIgnoreCase))
297+
{
298+
_textBox.AppendText(message);
299+
if (_notifyIcon != null)
300+
{
301+
_notifyIcon.Show(AppTitle, "There is a warning, see the Error Logging page for more information.",
302+
NotificationType.Warning, "", TimeSpan.FromSeconds(5));
303+
}
304+
}
305+
else
306+
{
307+
_textBox.AppendText(message);
308+
}
309+
310+
_textBox.ScrollToEnd();
311+
}
312+
313+
protected override void Dispose(bool disposing)
314+
{
315+
if (_notifyIcon != null)
316+
{
317+
//_notifyIcon.Visible = false;
318+
_notifyIcon.Close();
319+
}
320+
321+
_textBox = null;
322+
_notifyIcon = null;
323+
324+
base.Dispose(disposing);
226325
}
227326
}
228327
}

Samples/ClipArtViewer/app.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8" ?>
22
<configuration>
3-
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
3+
</configuration>

Source/SVGImage.sln

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example", "..\Samples\Examp
1313
EndProject
1414
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomBrushesExample", "..\Samples\CustomBrushesExample\CustomBrushesExample.csproj", "{8E3019C1-ED7D-4F06-AFF3-141E54ED8D34}"
1515
EndProject
16-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClipArtViewer", "..\Samples\ClipArtViewer\ClipArtViewer.csproj", "{16D74531-7F85-4384-BF5A-3C0A9A5D4F3E}"
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClipArtViewer", "..\Samples\ClipArtViewer\ClipArtViewer.csproj", "{16D74531-7F85-4384-BF5A-3C0A9A5D4F3E}"
17+
EndProject
18+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{8AD25703-6E13-4420-95AB-9270E9CB1B63}"
19+
EndProject
20+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SvgTestBox", "..\Tests\SvgTestBox\SvgTestBox.csproj", "{934C43F7-0C7D-4DB7-A79D-A304CFC9A053}"
1721
EndProject
1822
Global
1923
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -41,6 +45,10 @@ Global
4145
{16D74531-7F85-4384-BF5A-3C0A9A5D4F3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
4246
{16D74531-7F85-4384-BF5A-3C0A9A5D4F3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
4347
{16D74531-7F85-4384-BF5A-3C0A9A5D4F3E}.Release|Any CPU.Build.0 = Release|Any CPU
48+
{934C43F7-0C7D-4DB7-A79D-A304CFC9A053}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49+
{934C43F7-0C7D-4DB7-A79D-A304CFC9A053}.Debug|Any CPU.Build.0 = Debug|Any CPU
50+
{934C43F7-0C7D-4DB7-A79D-A304CFC9A053}.Release|Any CPU.ActiveCfg = Release|Any CPU
51+
{934C43F7-0C7D-4DB7-A79D-A304CFC9A053}.Release|Any CPU.Build.0 = Release|Any CPU
4452
EndGlobalSection
4553
GlobalSection(SolutionProperties) = preSolution
4654
HideSolutionNode = FALSE
@@ -49,6 +57,7 @@ Global
4957
{B90648B8-0235-4891-B902-FC3D8797686D} = {7584CC1F-793C-4C14-B47F-33A8D20E740D}
5058
{8E3019C1-ED7D-4F06-AFF3-141E54ED8D34} = {7584CC1F-793C-4C14-B47F-33A8D20E740D}
5159
{16D74531-7F85-4384-BF5A-3C0A9A5D4F3E} = {7584CC1F-793C-4C14-B47F-33A8D20E740D}
60+
{934C43F7-0C7D-4DB7-A79D-A304CFC9A053} = {8AD25703-6E13-4420-95AB-9270E9CB1B63}
5261
EndGlobalSection
5362
GlobalSection(ExtensibilityGlobals) = postSolution
5463
SolutionGuid = {299F3503-8850-481B-BB27-017B8485B0F6}
Binary file not shown.
30.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)