Skip to content

Commit eed3b85

Browse files
committed
修复了拖动启动窗口会报错的BUG;将Exception进行更具体的抛出
1 parent bbe9b91 commit eed3b85

18 files changed

+60
-54
lines changed

MapBoard.Core/IO/Csv.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public async static Task<IReadOnlyList<Feature>> ImportAsync(string path, MapLay
122122
string[] xy = line.Split(',');
123123
if (xy.Length != 2)
124124
{
125-
throw new Exception("CSV格式不正确");
125+
throw new FormatException("CSV格式不正确");
126126
}
127127

128128
if (!double.TryParse(xy[0], out double x) || !double.TryParse(xy[1], out double y))
@@ -154,7 +154,7 @@ public async static Task<IReadOnlyList<Feature>> ImportAsync(string path, MapLay
154154
case GeometryType.Point:
155155
if (part.Count != 1)
156156
{
157-
throw new Exception("若要导入为点,每一部分必须只有一个坐标");
157+
throw new FormatException("若要导入为点,每一部分必须只有一个坐标");
158158
}
159159
feature.Geometry = part[0];
160160

MapBoard.Core/IO/Gpx.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public async static Task<IReadOnlyList<Feature>> ImportToLayerAsync(string path,
104104
}
105105
else if (layer.GeometryType == GeometryType.Multipoint)
106106
{
107-
throw new Exception("多点暂不支持导入GPX");
107+
throw new NotSupportedException("多点暂不支持导入GPX");
108108
}
109109
else if (layer.GeometryType == GeometryType.Polyline)
110110
{
@@ -116,7 +116,7 @@ public async static Task<IReadOnlyList<Feature>> ImportToLayerAsync(string path,
116116
}
117117
else
118118
{
119-
throw new Exception("不支持的格式图形类型");
119+
throw new NotSupportedException("不支持的格式图形类型");
120120
}
121121
}
122122
await layer.AddFeaturesAsync(importedFeatures, FeaturesChangedSource.Import);

MapBoard.Core/IO/Gpx/Gpx.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static Gpx FromString(string gpxString)
2323
XmlElement xmlGpx = xmlDoc["gpx"];
2424
if (xmlGpx == null)
2525
{
26-
throw new Exception("没有找到gpx元素");
26+
throw new XmlException("没有找到gpx元素");
2727
}
2828
Gpx info = new Gpx(xmlGpx);
2929

MapBoard.Core/IO/Gpx/GpxPointCollection.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ public double GetSpeed(int index, int unilateralSampleCount)
104104
{
105105
if (!IsOrdered)
106106
{
107-
throw new Exception("点集合不符合时间顺序");
107+
throw new GpxException("点集合不符合时间顺序");
108108
}
109109
if (Count <= 1)
110110
{
111-
throw new Exception("集合拥有的点过少");
111+
throw new GpxException("集合拥有的点过少");
112112
}
113113

114114
int min = index - unilateralSampleCount;
@@ -168,4 +168,19 @@ public object Clone()
168168
return new GpxPointCollection(points);
169169
}
170170
}
171+
172+
public class GpxException : Exception
173+
{
174+
public GpxException()
175+
{
176+
}
177+
178+
public GpxException(string message) : base(message)
179+
{
180+
}
181+
182+
public GpxException(string message, Exception innerException) : base(message, innerException)
183+
{
184+
}
185+
}
171186
}

MapBoard.Core/IO/Gpx/GpxSpeedAnalysis.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static double GetSpeed(IEnumerable<GpxPoint> points)
1414
{
1515
if (points.Any(p => p.Time == null))
1616
{
17-
throw new Exception("其中一个点的时间为空");
17+
throw new GpxException("其中一个点的时间为空");
1818
}
1919
var sortedPoints = points.OrderBy(p => p.Time);
2020
TimeSpan totalTime = sortedPoints.Last().Time - sortedPoints.First().Time;
@@ -35,7 +35,7 @@ public static double GetSpeed(GpxPoint point1, GpxPoint point2)
3535
{
3636
if (point1.Time == null || point2.Time == null)
3737
{
38-
throw new Exception("其中一个点的时间为空");
38+
throw new GpxException("其中一个点的时间为空");
3939
}
4040
return GetSpeed(point1.ToMapPoint(), point2.ToMapPoint(), TimeSpan.FromMilliseconds(Math.Abs((point1.Time - point2.Time).TotalMilliseconds)));
4141
}
@@ -195,7 +195,7 @@ public SpeedInfo(params GpxPoint[] points)
195195
}
196196
if (relatedPointList.Count < 2)
197197
{
198-
throw new Exception("点数量过少");
198+
throw new GpxException("点数量过少");
199199
}
200200
RelatedPoints = relatedPointList.ToArray();
201201
TimeSpan = maxTime - minTime;

MapBoard.Core/IO/Gpx/GpxTrack.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public static void LoadGpxTrackInfoProperties(GpxTrack info, XmlNode xml)
134134
}
135135
catch (Exception ex)
136136
{
137-
throw new Exception("解析轨迹失败", ex);
137+
throw new XmlException("解析轨迹失败", ex);
138138
}
139139
}
140140

MapBoard.Core/IO/Package.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static async Task ImportMapAsync(string path, MapLayerCollection layers,
4040
{
4141
if (layers.Any(p => p.Name == layer.Name))
4242
{
43-
throw new Exception("存在重复的图层名:" + layer.Name);
43+
throw new ArgumentException("存在重复的图层名:" + layer.Name);
4444
}
4545
}
4646
foreach (var layer in newLayers)
@@ -156,14 +156,7 @@ private static async Task ZipDirAsync(string dir, string path)
156156
{
157157
if (File.Exists(path))
158158
{
159-
try
160-
{
161-
File.Delete(path);
162-
}
163-
catch (IOException ex)
164-
{
165-
throw new Exception("无法删除已存在的文件", ex);
166-
}
159+
File.Delete(path);
167160
}
168161
await Task.Run(() =>
169162
{

MapBoard.Core/IO/Shapefile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public async static Task<ShapefileFeatureTable> CreateShapefileAsync(GeometryTyp
139139
if (fields.Any(field => !Regex.IsMatch(field.Name[0].ToString(), "[a-zA-Z]")
140140
|| !Regex.IsMatch(field.Name, "^[a-zA-Z0-9_]+$")))
141141
{
142-
throw new Exception($"字段名存在不合法");
142+
throw new ArgumentException($"字段名存在不合法");
143143
}
144144
}
145145

MapBoard.Core/MapBoard.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
</PropertyGroup>
1717

1818
<ItemGroup>
19+
<PackageReference Include="AutoMapper" Version="10.1.1" />
1920
<PackageReference Include="CsvHelper" Version="27.1.0" />
2021
<PackageReference Include="DotNetZip" Version="1.15.0" />
2122
<PackageReference Include="Esri.ArcGISRuntime" Version="100.11.0" />

MapBoard.Core/Mapping/Model/MapLayerInfo.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Esri.ArcGISRuntime.Data;
1+
using AutoMapper;
2+
using Esri.ArcGISRuntime.Data;
23
using Esri.ArcGISRuntime.Geometry;
34
using Esri.ArcGISRuntime.Mapping;
45
using FzLib.Extension;
@@ -43,13 +44,11 @@ public MapLayerInfo()
4344

4445
public MapLayerInfo(LayerInfo layer)
4546
{
46-
Name = layer.Name;
47-
TimeExtent = layer.TimeExtent;
48-
Symbols = layer.Symbols;
49-
Fields = layer.Fields;
50-
Label = layer.Label;
51-
LayerVisible = layer.LayerVisible;
52-
Group = layer.Group;
47+
new MapperConfiguration(cfg =>
48+
{
49+
cfg.CreateMap<LayerInfo, MapLayerInfo>();
50+
}).CreateMapper().Map(layer, this);
51+
5352
}
5453

5554
public override object Clone()

MapBoard.Core/Util/AttributeUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static async Task<ItemsOperationErrorCollection> CopyAttributesAsync(MapL
3131
{
3232
if (fieldTarget.Name.Equals(FieldExtension.CreateTimeField.Name))
3333
{
34-
throw new Exception("不可为“创建时间”字段赋值");
34+
throw new ArgumentException("不可为“创建时间”字段赋值");
3535
}
3636

3737
Debug.Assert(features.All(p => p.FeatureTable.Layer == layer.Layer));
@@ -150,7 +150,7 @@ public static async Task<ItemsOperationErrorCollection> SetAttributesAsync(MapLa
150150
{
151151
if (field.Name.Equals(FieldExtension.CreateTimeField.Name))
152152
{
153-
throw new Exception("不可为“创建时间”字段赋值");
153+
throw new ArgumentException("不可为“创建时间”字段赋值");
154154
}
155155

156156
Debug.Assert(features.All(p => p.FeatureTable.Layer == layer.Layer));

MapBoard.Core/Util/CoordinateTransformation.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using MapBoard.Model;
44
using System;
55
using System.Collections.Generic;
6+
using System.ComponentModel;
67
using System.Linq;
78

89
namespace MapBoard.Util
@@ -57,7 +58,7 @@ public static Geometry Transformate(Geometry geometry, CoordinateSystem source,
5758
return new Envelope(newLeftTop, newRightBottom);
5859

5960
default:
60-
throw new Exception("未知类型");
61+
throw new InvalidEnumArgumentException("未知类型");
6162
}
6263
}
6364

@@ -97,7 +98,7 @@ private static MapPoint ToWgs84(MapPoint point, CoordinateSystem source)
9798
return ChineseCoordinateTransformation.BD09ToWgs84(point);
9899
}
99100
default:
100-
throw new Exception("未知坐标系");
101+
throw new InvalidEnumArgumentException("未知坐标系");
101102
}
102103
}
103104

@@ -122,7 +123,7 @@ private static MapPoint FromWgs84(MapPoint point, CoordinateSystem target)
122123
return ChineseCoordinateTransformation.WGS84ToBD09(point);
123124
}
124125
default:
125-
throw new Exception("未知坐标系");
126+
throw new InvalidEnumArgumentException("未知坐标系");
126127
}
127128
}
128129
}

MapBoard.Core/Util/FeatureUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ public static async Task IntervalTakePointsSimplifyAsync(MapLayerInfo layer, Fea
463463

464464
if (interval < 2)
465465
{
466-
throw new Exception("间隔不应小于2");
466+
throw new ArgumentOutOfRangeException("间隔不应小于2");
467467
}
468468
foreach (var feature in features)
469469
{
@@ -621,7 +621,7 @@ private static List<MapPoint> GetPoints(Feature feature)
621621
}
622622
if (parts.Count > 1)
623623
{
624-
throw new Exception("不支持操作拥有多个部分的要素");
624+
throw new NotSupportedException("不支持操作拥有多个部分的要素");
625625
}
626626
List<MapPoint> points = new List<MapPoint>();
627627
foreach (var part in parts)

MapBoard.Core/Util/LayerUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,12 @@ public async static Task<MapLayerInfo> UnionAsync(IEnumerable<MapLayerInfo> laye
225225
{
226226
if (layers == null || !layers.Any())
227227
{
228-
throw new Exception("图层为空");
228+
throw new ArgumentException("图层为空");
229229
}
230230
var type = layers.Select(p => p.GeometryType).Distinct();
231231
if (type.Count() != 1)
232232
{
233-
throw new Exception("图层的类型并非统一");
233+
throw new ArgumentException("图层的类型并非统一");
234234
}
235235
MapLayerInfo layer = await CreateLayerAsync(type.First(), layerCollection);
236236
List<Feature> newFeatures = new List<Feature>();

MapBoard.Core/Util/NetUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static void HttpDownload(string url, string path, int requestTimeOut, int
5555
{
5656
if (++tryTimes >= 10)
5757
{
58-
throw new Exception("尝试删除已存在的文件失败");
58+
throw new IOException("尝试删除已存在的文件失败");
5959
}
6060
Thread.Sleep(100);
6161
}

MapBoard.Model/FeatureAttribute.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using FzLib.Extension;
44
using System;
5+
using System.ComponentModel;
56
using System.Globalization;
67

78
namespace MapBoard.Model
@@ -54,7 +55,7 @@ public object Value
5455
attrValue = intValue;
5556
break;
5657
}
57-
throw new ApplicationException("输入的值超过了范围");
58+
throw new ArgumentOutOfRangeException("输入的值超过了范围");
5859
}
5960
if (value is double d)
6061
{
@@ -64,7 +65,7 @@ public object Value
6465
attrValue = intValue;
6566
break;
6667
}
67-
throw new ApplicationException("输入的值超过了范围");
68+
throw new ArgumentOutOfRangeException("输入的值超过了范围");
6869
}
6970
if (value is string str1)
7071
{
@@ -75,7 +76,7 @@ public object Value
7576
break;
7677
}
7778
}
78-
throw new ApplicationException("输入的值无法转换为整数");
79+
throw new ArgumentException("输入的值无法转换为整数");
7980
case FieldInfoType.Float:
8081
if (value == null)
8182
{
@@ -98,7 +99,7 @@ public object Value
9899
break;
99100
}
100101
}
101-
throw new ApplicationException("输入的值无法转换为小数");
102+
throw new ArgumentException("输入的值无法转换为小数");
102103
case FieldInfoType.Date:
103104
if (value == null)
104105
{
@@ -134,7 +135,7 @@ public object Value
134135
break;
135136
}
136137
}
137-
throw new ApplicationException("输入的值无法转换为日期");
138+
throw new ArgumentException("输入的值无法转换为日期");
138139
case FieldInfoType.Time:
139140
if (value == null)
140141
{
@@ -163,13 +164,13 @@ public object Value
163164
break;
164165
}
165166
}
166-
throw new ApplicationException("输入的值无法转换为日期");
167+
throw new ArgumentException("输入的值无法转换为日期");
167168
case FieldInfoType.Text:
168169
if (value is string str4)
169170
{
170171
if (str4.Length > 254)
171172
{
172-
throw new ApplicationException("输入的字符串过长");
173+
throw new ArgumentException("输入的字符串过长");
173174
}
174175
textValue = str4;
175176
attrValue = value;
@@ -186,10 +187,10 @@ public object Value
186187
break;
187188

188189
default:
189-
throw new NotSupportedException();
190+
throw new InvalidEnumArgumentException();
190191
}
191192
}
192-
catch (Exception ex)
193+
catch (ArgumentException ex)
193194
{
194195
#if !DEBUG||ERROR
195196
throw;

MapBoard.UI/UI/LayerListPanel.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ private void LayerListPanel_Loaded(object sender, RoutedEventArgs e)
311311

312312
void IDropTarget.DragOver(IDropInfo dropInfo)
313313
{
314-
if (dropInfo.TargetItem == dropInfo.Data)
314+
if (dropInfo.TargetItem == dropInfo.Data
315+
|| dropInfo.Data is IList)
315316
{
316317
return;
317318
}

MapBoard.UI/UI/SplashWindow.xaml.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,5 @@ public static void EnsureInvisiable()
6565
instance = null;
6666
}
6767

68-
protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
69-
{
70-
base.OnPreviewMouseDown(e);
71-
DragMove();
72-
}
7368
}
7469
}

0 commit comments

Comments
 (0)