Skip to content

Commit

Permalink
v2.5.7
Browse files Browse the repository at this point in the history
- *Fixed:* Corrected issue introduced in version `2.5.5` where some strings were being incorrectly converted to a guid.
  • Loading branch information
chullybun committed Jun 28, 2024
1 parent e578e59 commit f35f808
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Represents the **NuGet** versions.

## v2.5.7
- *Fixed:* Corrected issue introduced in version `2.5.5` where some strings were being incorrectly converted to a guid.

## v2.5.6
- *Fixed:* Release build and publish; version `2.5.5` was not published correctly.

Expand Down
2 changes: 1 addition & 1 deletion Common.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2.5.6</Version>
<Version>2.5.7</Version>
<LangVersion>preview</LangVersion>
<Authors>Avanade</Authors>
<Company>Avanade</Company>
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,17 @@ Demo:
- { FirstName: Wendy, LastName: Jones, Gender: F, Birthday: 1985-03-18 }
```

Runtime values can be used within the YAML using the value lookup notation; this notation is `^(Key)`. This will either reference the [`DataParserArgs`](./src/DbEx/Migration/Data/DataParserArgs.cs) `Parameters` property using the specified key. There are two special parameters, being `UserName` and `DateTimeNow`, that reference the same named `DataParserArgs` properties. Where not found the extended notation `^(Namespace.Type.Property.Method().etc, AssemblyName)` is used. Where the `AssemblyName` is not specified then the default `mscorlib` is assumed. The `System` root namespace is optional, i.e. it will be attempted by default. The initial property or method for a `Type` must be `static`, in that the `Type` will not be instantiated. Example as follows. These parameters (`Name=Value` pairs) can also be command-line specified.
Runtime values can be used within the YAML using the value lookup notation; this notation is `^(Key)`. This will either reference the [`DataParserArgs`](./src/DbEx/Migration/Data/DataParserArgs.cs) `Parameters` property using the specified key. There are two special parameters, being `UserName` and `DateTimeNow`, that reference the same named `DataParserArgs` properties. An additional special parameter being `GuidNew`, that results in a `Guid.NewGuid`. Where not found the extended notation `^(Namespace.Type.Property.Method().etc, AssemblyName)` is used. Where the `AssemblyName` is not specified then the default `mscorlib` is assumed. The `System` root namespace is optional, i.e. it will be attempted by default. The initial property or method for a `Type` must be `static`, in that the `Type` will not be instantiated. These parameters (`Name=Value` pairs) can also be command-line specified.

Additionally, a column can be set with a guid representation of an integer where specified using shorthand notation; i.e. replace `^n` values where `n` is an integer with a guid equivalent; e.g. `^1` will be converted to `00000001-0000-0000-0000-000000000000`. The `DataParserArgs.ReplaceShorthandGuids` had been added to control this behavior (defaults to `true`).

Example as follows.

``` yaml
Demo:
- Person:
- { FirstName: Wendy, Username: ^(System.Security.Principal.WindowsIdentity.GetCurrent().Name,System.Security.Principal.Windows), Birthday: ^(DateTimeNow) }
- { FirstName: Wendy, Username: ^(Beef.ExecutionContext.EnvironmentUsername,Beef.Core), Birthday: ^(DateTime.UtcNow) }
- { PersonId: ^1, FirstName: Wendy, Username: ^(System.Security.Principal.WindowsIdentity.GetCurrent().Name,System.Security.Principal.Windows), Birthday: ^(DateTimeNow) }
- { PersonId: ^2, FirstName: Wendy, Username: ^(Beef.ExecutionContext.EnvironmentUsername,Beef.Core), Birthday: ^(DateTime.UtcNow) }
```

Advanced capabilities, such as nested YAML/JSON can be specified to represent hierarchical relationships (see `contact->addresses` within test [`data.yaml`](./tests/DbEx.Test.Console/Data/Data.yaml) and related [`TableNameMappings`](./tests/DbEx.Test.Console/Program.cs) to map to the correct underlying database table). [`DataConfig`](./src/Dbex/Migration/Data/DataConfig.cs) can also be specified using the `*` schema to control the behaviour within the context of a YAML/JSON file as demonstrated by the test [`ContactType.json`](./tests/DbEx.Test.Console/Data/ContactType.json).
Expand Down
3 changes: 2 additions & 1 deletion src/DbEx/Migration/Data/DataParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ private async Task ParseTableJsonAsync(List<DataTable> tables, DataRow? parent,
{
case "UserName": return ParserArgs.UserName;
case "DateTimeNow": return ParserArgs.DateTimeNow;
case "GuidNew": return Guid.NewGuid();
default:
if (ParserArgs.Parameters.TryGetValue(key, out object? dval))
return dval;
Expand All @@ -317,7 +318,7 @@ private async Task ParseTableJsonAsync(List<DataTable> tables, DataRow? parent,

throw new DataParserException(msg);
}
else if (ParserArgs.ReplaceShorthandGuids && int.TryParse(value[1..], out var i))
else if (ParserArgs.ReplaceShorthandGuids && value.StartsWith('^') && int.TryParse(value[1..], out var i))
return new Guid(i, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
else
return value;
Expand Down

0 comments on commit f35f808

Please sign in to comment.