Skip to content

Commit ea739f8

Browse files
committed
вынесен класс исключений, перевод и уточнение сообщений
1 parent 25c0e3b commit ea739f8

File tree

9 files changed

+74
-74
lines changed

9 files changed

+74
-74
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*----------------------------------------------------------
2+
This Source Code Form is subject to the terms of the
3+
Mozilla Public License, v.2.0. If a copy of the MPL
4+
was not distributed with this file, You can obtain one
5+
at http://mozilla.org/MPL/2.0/.
6+
----------------------------------------------------------*/
7+
using System;
8+
using OneScript.Exceptions;
9+
using OneScript.Localization;
10+
11+
namespace OneScript.StandardLibrary.Collections.Exceptions
12+
{
13+
public class ColumnException : RuntimeException
14+
{
15+
public ColumnException(BilingualString message, Exception innerException) : base(message,
16+
innerException)
17+
{
18+
}
19+
20+
public ColumnException(BilingualString message) : base(message)
21+
{
22+
}
23+
24+
public static ColumnException WrongColumnName()
25+
{
26+
return new ColumnException(new BilingualString(
27+
"Неверное имя колонки",
28+
"Wrong column name"));
29+
}
30+
31+
public static ColumnException WrongColumnName(string columnName)
32+
{
33+
return new ColumnException(new BilingualString(
34+
$"Неверное имя колонки '{columnName}'",
35+
$"Wrong column name '{columnName}'"));
36+
}
37+
38+
public static ColumnException DuplicatedColumnName(string columnName)
39+
{
40+
return new ColumnException(new BilingualString(
41+
$"Колонка '{columnName}' уже есть",
42+
$"Column '{columnName}' already exists"));
43+
}
44+
45+
46+
public static ColumnException ColumnsMixed(string columnName)
47+
{
48+
return new ColumnException(new BilingualString(
49+
$"Колонка '{columnName}' не может одновременно быть колонкой группировки и колонкой суммирования",
50+
$"Column '{columnName}' cannot be both grouping column and summation column"));
51+
}
52+
53+
}
54+
}

src/OneScript.StandardLibrary/Collections/ValueTable/CollectionIndexes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ This Source Code Form is subject to the terms of the
1010
using System.Linq;
1111
using OneScript.Contexts;
1212
using OneScript.Exceptions;
13+
using OneScript.StandardLibrary.Collections.Exceptions;
1314
using OneScript.StandardLibrary.Collections.Indexes;
1415
using OneScript.Types;
1516
using OneScript.Values;
1617
using ScriptEngine.Machine;
1718
using ScriptEngine.Machine.Contexts;
18-
using ScriptEngine.Types;
1919

2020
namespace OneScript.StandardLibrary.Collections.ValueTable
2121
{
@@ -143,7 +143,7 @@ private static IList<IValue> BuildFieldList(IIndexCollectionSource source, strin
143143
var field = source.GetField(fieldName.Trim());
144144
if (field == null)
145145
{
146-
throw new ColumnNotFoundException(fieldName);
146+
throw ColumnException.WrongColumnName(fieldName);
147147
}
148148
fields.Add(field);
149149
}

src/OneScript.StandardLibrary/Collections/ValueTable/ColumnNotFoundException.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/OneScript.StandardLibrary/Collections/ValueTable/ValueTable.cs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This Source Code Form is subject to the terms of the
1616
using OneScript.Values;
1717
using ScriptEngine.Machine;
1818
using ScriptEngine.Machine.Contexts;
19+
using OneScript.StandardLibrary.Collections.Exceptions;
1920

2021
namespace OneScript.StandardLibrary.Collections.ValueTable
2122
{
@@ -166,7 +167,7 @@ private List<ValueTableColumn> GetProcessingColumnList(string ColumnNames, bool
166167
var Column = Columns.FindColumnByName(name);
167168

168169
if (Column == null)
169-
throw WrongColumnNameException(name);
170+
throw ColumnException.WrongColumnName(name);
170171

171172
if (processing_list.Find( x=> x.Name==name ) == null)
172173
processing_list.Add(Column);
@@ -271,7 +272,7 @@ private bool CheckFilterCriteria(ValueTableRow Row, StructureImpl Filter)
271272
{
272273
var Column = Columns.FindColumnByName(kv.Key.ToString());
273274
if (Column == null)
274-
throw WrongColumnNameException(kv.Key.ToString());
275+
throw ColumnException.WrongColumnName(kv.Key.ToString());
275276

276277
IValue current = Row.Get(Column);
277278
if (!current.StrictEquals(kv.Value))
@@ -391,7 +392,7 @@ private static void CheckMixedColumns(List<ValueTableColumn> groupColumns, List<
391392
{
392393
foreach (var groupColumn in groupColumns )
393394
if ( aggregateColumns.Find(x => x.Name==groupColumn.Name)!=null )
394-
throw ColumnsMixedException(groupColumn.Name);
395+
throw ColumnException.ColumnsMixed(groupColumn.Name);
395396
}
396397

397398
private static void CopyRowData(ValueTableRow source, ValueTableRow dest, IEnumerable<ValueTableColumn> columns)
@@ -611,7 +612,7 @@ private List<ValueTableSortRule> GetSortRules(string Columns)
611612
{
612613
string[] description = column.Trim().Split(' ');
613614
if (description.Length == 0)
614-
throw WrongColumnNameException();
615+
throw ColumnException.WrongColumnName();
615616

616617
ValueTableSortRule Desc = new ValueTableSortRule();
617618
Desc.Column = this.Columns.FindColumnByName(description[0]);
@@ -719,22 +720,6 @@ public static ValueTable Constructor()
719720
return new ValueTable();
720721
}
721722

722-
723-
private static RuntimeException WrongColumnNameException()
724-
{
725-
return new RuntimeException("Неверное имя колонки");
726-
}
727-
728-
private static RuntimeException WrongColumnNameException(string columnName)
729-
{
730-
return new RuntimeException(string.Format("Неверное имя колонки '{0}'", columnName));
731-
}
732-
733-
private static RuntimeException ColumnsMixedException(string columnName)
734-
{
735-
return new RuntimeException(string.Format("Колонка '{0}' не может одновременно быть колонкой группировки и колонкой суммирования", columnName));
736-
}
737-
738723
public string GetName(IValue field)
739724
{
740725
if (field is ValueTableColumn column)

src/OneScript.StandardLibrary/Collections/ValueTable/ValueTableColumn.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This Source Code Form is subject to the terms of the
77

88
using System;
99
using OneScript.Contexts;
10-
using OneScript.Exceptions;
10+
using OneScript.StandardLibrary.Collections.Exceptions;
1111
using OneScript.StandardLibrary.TypeDescriptions;
1212
using OneScript.Types;
1313
using ScriptEngine.Machine.Contexts;
@@ -61,7 +61,7 @@ public string Name
6161
{
6262
ValueTableColumnCollection Owner = _owner.Target as ValueTableColumnCollection;
6363
if (Owner.FindColumnByName(value) != null)
64-
throw new RuntimeException("Неверное имя колонки!");
64+
throw ColumnException.WrongColumnName();
6565

6666
if (_title == _name)
6767
_title = value;

src/OneScript.StandardLibrary/Collections/ValueTable/ValueTableColumnCollection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ This Source Code Form is subject to the terms of the
1212
using OneScript.Contexts;
1313
using OneScript.Exceptions;
1414
using OneScript.Execution;
15+
using OneScript.StandardLibrary.Collections.Exceptions;
1516
using OneScript.StandardLibrary.TypeDescriptions;
1617
using OneScript.Types;
1718
using ScriptEngine.Machine;
1819
using ScriptEngine.Machine.Contexts;
19-
using ScriptEngine.Types;
2020

2121
namespace OneScript.StandardLibrary.Collections.ValueTable
2222
{
@@ -48,7 +48,7 @@ public ValueTableColumnCollection(ValueTable owner)
4848
public ValueTableColumn Add(string name, TypeDescription type = null, string title = null, int width = 0)
4949
{
5050
if (FindColumnByName(name) != null)
51-
throw new RuntimeException("Неверное имя колонки " + name);
51+
throw ColumnException.DuplicatedColumnName(name);
5252

5353
var column = new ValueTableColumn(this, ++maxColumnId, name, title, type, width);
5454
_columns.Add(column);
@@ -69,7 +69,7 @@ public ValueTableColumn Add(string name, TypeDescription type = null, string tit
6969
public ValueTableColumn Insert(int index, string name, TypeDescription type = null, string title = null, int width = 0)
7070
{
7171
if (FindColumnByName(name) != null)
72-
throw new RuntimeException("Неверное имя колонки " + name);
72+
throw ColumnException.DuplicatedColumnName(name);
7373

7474
ValueTableColumn column = new ValueTableColumn(this, ++maxColumnId, name, title, type, width);
7575
_columns.Insert(index, column);

src/OneScript.StandardLibrary/Collections/ValueTree/ValueTreeColumn.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This Source Code Form is subject to the terms of the
66
----------------------------------------------------------*/
77

88
using OneScript.Contexts;
9-
using OneScript.Exceptions;
9+
using OneScript.StandardLibrary.Collections.Exceptions;
1010
using OneScript.StandardLibrary.TypeDescriptions;
1111
using OneScript.Types;
1212
using ScriptEngine.Machine.Contexts;
@@ -60,7 +60,7 @@ public string Name
6060
set
6161
{
6262
if (_owner.FindColumnByName(value) != null)
63-
throw new RuntimeException("Неверное имя колонки!");
63+
throw ColumnException.WrongColumnName();
6464

6565
if (_title == _name)
6666
_title = value;

src/OneScript.StandardLibrary/Collections/ValueTree/ValueTreeColumnCollection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ This Source Code Form is subject to the terms of the
1111
using OneScript.Contexts;
1212
using OneScript.Exceptions;
1313
using OneScript.Execution;
14+
using OneScript.StandardLibrary.Collections.Exceptions;
1415
using OneScript.StandardLibrary.TypeDescriptions;
1516
using OneScript.Types;
1617
using OneScript.Values;
1718
using ScriptEngine.Machine;
1819
using ScriptEngine.Machine.Contexts;
19-
using ScriptEngine.Types;
2020

2121
namespace OneScript.StandardLibrary.Collections.ValueTree
2222
{
@@ -40,7 +40,7 @@ public class ValueTreeColumnCollection : AutoContext<ValueTreeColumnCollection>,
4040
public ValueTreeColumn Add(string name, TypeDescription type = null, string title = null, int width = 0)
4141
{
4242
if (FindColumnByName(name) != null)
43-
throw new RuntimeException("Неверное имя колонки " + name);
43+
throw ColumnException.DuplicatedColumnName(name);
4444

4545
ValueTreeColumn column = new ValueTreeColumn(this, name, title, type, width);
4646
_columns.Add(column);
@@ -61,7 +61,7 @@ public ValueTreeColumn Add(string name, TypeDescription type = null, string titl
6161
public ValueTreeColumn Insert(int index, string name, TypeDescription type = null, string title = null, int width = 0)
6262
{
6363
if (FindColumnByName(name) != null)
64-
throw new RuntimeException("Неверное имя колонки " + name);
64+
throw ColumnException.DuplicatedColumnName(name);
6565

6666
ValueTreeColumn column = new ValueTreeColumn(this, name, title, type, width);
6767
_columns.Insert(index, column);

src/OneScript.StandardLibrary/Collections/ValueTree/ValueTreeRowCollection.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This Source Code Form is subject to the terms of the
1010
using OneScript.Contexts;
1111
using OneScript.Exceptions;
1212
using OneScript.Execution;
13+
using OneScript.StandardLibrary.Collections.Exceptions;
1314
using OneScript.Types;
1415
using OneScript.Values;
1516
using ScriptEngine.Machine;
@@ -361,12 +362,12 @@ private List<ValueTreeSortRule> GetSortRules(string columns)
361362
{
362363
string[] description = column.Trim().Split(' ');
363364
if (description.Length == 0)
364-
throw WrongColumnNameException();
365+
throw ColumnException.WrongColumnName();
365366

366367
ValueTreeSortRule desc = new ValueTreeSortRule();
367368
desc.Column = this.Columns.FindColumnByName(description[0]);
368369
if (desc.Column == null)
369-
throw WrongColumnNameException(description[0]);
370+
throw ColumnException.WrongColumnName(description[0]);
370371

371372
if (description.Length > 1)
372373
{
@@ -487,16 +488,5 @@ public override IValue GetIndexedValue(IValue index)
487488
{
488489
return Get((int)index.AsNumber());
489490
}
490-
491-
private static RuntimeException WrongColumnNameException()
492-
{
493-
return new RuntimeException("Неверное имя колонки");
494-
}
495-
496-
private static RuntimeException WrongColumnNameException(string columnName)
497-
{
498-
return new RuntimeException(string.Format("Неверное имя колонки '{0}'", columnName));
499-
}
500-
501491
}
502492
}

0 commit comments

Comments
 (0)