Skip to content

Commit c196812

Browse files
committed
Parsing exception handled
1 parent c097e9a commit c196812

5 files changed

Lines changed: 98 additions & 13 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
8+
namespace XamlPathDataParser.DataContext.PathDataItems
9+
{
10+
public class PathDataItemFillRule : IPathDataItem
11+
{
12+
13+
public int FillRule { get; set; }
14+
15+
public PathDataItemFillRule()
16+
{ }
17+
18+
public PathDataItemFillRule(string Data)
19+
{
20+
21+
if ((Data+"").ToUpper() == "F1")
22+
{
23+
FillRule = 1;
24+
}
25+
else
26+
{
27+
FillRule = 0;
28+
}
29+
}
30+
31+
32+
}
33+
}

XamlPathDataParser/MainWindow.xaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232

3333
<Grid.Resources>
3434

35+
<DataTemplate DataType="{x:Type localData:PathDataItemFillRule}">
36+
<StackPanel Orientation="Horizontal">
37+
<TextBlock Text="Fill" Style="{StaticResource ListTitle}" VerticalAlignment="Center"></TextBlock>
38+
<StackPanel>
39+
<TextBlock Text="Rule" HorizontalAlignment="Center"></TextBlock>
40+
<TextBox Text="{Binding FillRule}"></TextBox>
41+
</StackPanel>
42+
</StackPanel>
43+
</DataTemplate>
44+
3545
<DataTemplate DataType="{x:Type localData:PathDataItemMove}">
3646
<StackPanel Orientation="Horizontal">
3747
<TextBlock Text="Move" Style="{StaticResource ListTitle}" VerticalAlignment="Center"></TextBlock>

XamlPathDataParser/MainWindow.xaml.cs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
63
using System.Windows;
74
using System.Windows.Controls;
8-
using System.Windows.Data;
9-
using System.Windows.Documents;
105
using System.Windows.Input;
116
using System.Windows.Media;
12-
using System.Windows.Media.Imaging;
13-
using System.Windows.Navigation;
14-
using System.Windows.Shapes;
157
using XamlPathDataParser.DataContext.PathDataItems;
168

179
namespace XamlPathDataParser
@@ -31,8 +23,14 @@ public MainWindow()
3123

3224
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
3325
{
26+
TextBox tb = (sender as TextBox);
3427

35-
string ParsedDataText = (sender as TextBox).Text;
28+
tb.Background = Brushes.White;
29+
30+
try
31+
{
32+
33+
string ParsedDataText = tb.Text;
3634

3735
var ParsedDataItems = Parser.PathDataParser.ParseData(ParsedDataText);
3836

@@ -41,7 +39,7 @@ private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
4139

4240
if (dc.PathDataItems == null)
4341
{
44-
dc.PathDataItems = new System.Collections.ObjectModel.ObservableCollection<DataContext.PathDataItems.IPathDataItem>();
42+
dc.PathDataItems = new System.Collections.ObjectModel.ObservableCollection<IPathDataItem>();
4543
}
4644
else
4745
{
@@ -60,6 +58,11 @@ private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
6058
FirstPath.Data = Geometry.Parse(ParsedDataText);
6159

6260
DrawSecondPath(ParsedDataItems);
61+
}
62+
catch (Exception)
63+
{
64+
tb.Background = new SolidColorBrush(Color.FromArgb(20,255,0,0));
65+
}
6366

6467
}
6568

@@ -82,8 +85,18 @@ private void DrawSecondPath(IEnumerable<IPathDataItem> ParsedDataItems, int high
8285
foreach (var item in ParsedDataItems)
8386
{
8487
index++;
85-
86-
if (item is PathDataItemClose)
88+
if (item is PathDataItemFillRule)
89+
{
90+
if ((item as PathDataItemFillRule).FillRule == 0)
91+
{
92+
SecondPathGeometry.FillRule = FillRule.EvenOdd;
93+
}
94+
else
95+
{
96+
SecondPathGeometry.FillRule = FillRule.Nonzero;
97+
}
98+
}
99+
else if (item is PathDataItemClose)
87100
{
88101
pathGeometryFigure = new PathFigure();
89102
pathGeometryFigures.Add(pathGeometryFigure);

XamlPathDataParser/Parser/PathDataParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ public static IEnumerable<IPathDataItem> ParseData(string DataString)
3232
if (string.IsNullOrWhiteSpace(mydataItem))
3333
continue;
3434

35-
if (mydataItem == "F1" || mydataItem == "F2")
35+
if (mydataItem == "F0" || mydataItem == "F1")
3636
{
3737
// sot supported so far
38+
yield return new PathDataItemFillRule(mydataItem);
3839
continue;
3940
}
4041

XamlPathDataParser/XamlPathDataParser.csproj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@
1313
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
1414
<WarningLevel>4</WarningLevel>
1515
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
16+
<PublishUrl>publish\</PublishUrl>
17+
<Install>true</Install>
18+
<InstallFrom>Disk</InstallFrom>
19+
<UpdateEnabled>false</UpdateEnabled>
20+
<UpdateMode>Foreground</UpdateMode>
21+
<UpdateInterval>7</UpdateInterval>
22+
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
23+
<UpdatePeriodically>false</UpdatePeriodically>
24+
<UpdateRequired>false</UpdateRequired>
25+
<MapFileExtensions>true</MapFileExtensions>
26+
<ApplicationRevision>0</ApplicationRevision>
27+
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
28+
<IsWebBootstrapper>false</IsWebBootstrapper>
29+
<UseApplicationTrust>false</UseApplicationTrust>
30+
<BootstrapperEnabled>true</BootstrapperEnabled>
1631
</PropertyGroup>
1732
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1833
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -65,6 +80,7 @@
6580
<Compile Include="DataContext\PathDataItems\IPathDataItem.cs" />
6681
<Compile Include="DataContext\PathDataItems\PathDataItemCubicBezierCurve.cs" />
6782
<Compile Include="DataContext\PathDataItems\PathDataItemEllipticalArc.cs" />
83+
<Compile Include="DataContext\PathDataItems\PathDataItemFillRule.cs" />
6884
<Compile Include="DataContext\PathDataItems\PathDataItemQuadraticBezierCurve.cs" />
6985
<Compile Include="DataContext\PathDataItems\PathDataItemSmoothCubicBezierCurve.cs" />
7086
<Compile Include="DataContext\PathDataItems\PathDataItemSmoothQuadraticBezierCurve.cs" />
@@ -106,5 +122,17 @@
106122
<ItemGroup>
107123
<None Include="App.config" />
108124
</ItemGroup>
125+
<ItemGroup>
126+
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
127+
<Visible>False</Visible>
128+
<ProductName>Microsoft .NET Framework 4.6.1 %28x86 e x64%29</ProductName>
129+
<Install>true</Install>
130+
</BootstrapperPackage>
131+
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
132+
<Visible>False</Visible>
133+
<ProductName>.NET Framework 3.5 SP1</ProductName>
134+
<Install>false</Install>
135+
</BootstrapperPackage>
136+
</ItemGroup>
109137
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
110138
</Project>

0 commit comments

Comments
 (0)