Skip to content

Commit 434f2fd

Browse files
Arne DumareyCumpsD
authored andcommitted
feat: rename OsloId to PersistentLocalId
1 parent 4a0edef commit 434f2fd

File tree

86 files changed

+1580
-788
lines changed

Some content is hidden

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

86 files changed

+1580
-788
lines changed

.paket/Paket.Restore.targets

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
<!-- make MSBuild track this file for incremental builds. -->
66
<!-- ref https://blogs.msdn.microsoft.com/msbuild/2005/09/26/how-to-ensure-changes-to-a-custom-target-file-prompt-a-rebuild/ -->
77
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
8+
9+
<DetectedMSBuildVersion>$(MSBuildVersion)</DetectedMSBuildVersion>
10+
<DetectedMSBuildVersion Condition="$(MSBuildVersion) == ''">15.0.0</DetectedMSBuildVersion>
11+
<MSBuildSupportsHashing>false</MSBuildSupportsHashing>
12+
<MSBuildSupportsHashing Condition=" '$(DetectedMSBuildVersion)' &gt; '15.8.0' ">true</MSBuildSupportsHashing>
813
<!-- Mark that this target file has been loaded. -->
914
<IsPaketRestoreTargetsFileLoaded>true</IsPaketRestoreTargetsFileLoaded>
1015
<PaketToolsPath>$(MSBuildThisFileDirectory)</PaketToolsPath>
@@ -73,37 +78,47 @@
7378
<MSBuild Projects="$(PaketToolsPath)paket.bootstrapper.proj" Targets="Restore" />
7479
</Target>
7580

81+
<!-- Official workaround for https://docs.microsoft.com/en-us/visualstudio/msbuild/getfilehash-task?view=vs-2019 -->
82+
<UsingTask TaskName="Microsoft.Build.Tasks.GetFileHash" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Condition=" '$(MSBuildSupportsHashing)' == 'true' And '$(DetectedMSBuildVersion)' &lt; '16.0.360' " />
83+
<UsingTask TaskName="Microsoft.Build.Tasks.VerifyFileHash" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Condition=" '$(MSBuildSupportsHashing)' == 'true' And '$(DetectedMSBuildVersion)' &lt; '16.0.360' " />
7684
<Target Name="PaketRestore" Condition="'$(PaketRestoreDisabled)' != 'True'" BeforeTargets="_GenerateDotnetCliToolReferenceSpecs;_GenerateProjectRestoreGraphPerFramework;_GenerateRestoreGraphWalkPerFramework;CollectPackageReferences" DependsOnTargets="PaketBootstrapping">
7785

78-
<!-- Step 1 Check if lockfile is properly restored -->
86+
<!-- Step 1 Check if lockfile is properly restored (if the hash of the lockfile and the cache-file match) -->
7987
<PropertyGroup>
8088
<PaketRestoreRequired>true</PaketRestoreRequired>
8189
<NoWarn>$(NoWarn);NU1603;NU1604;NU1605;NU1608</NoWarn>
90+
<CacheFilesExist>false</CacheFilesExist>
91+
<CacheFilesExist Condition=" Exists('$(PaketRestoreCacheFile)') And Exists('$(PaketLockFilePath)') ">true</CacheFilesExist>
8292
</PropertyGroup>
8393

84-
<!-- Because ReadAllText is slow on osx/linux, try to find shasum and awk -->
85-
<PropertyGroup>
86-
<PaketRestoreCachedHasher Condition="'$(OS)' != 'Windows_NT' And '$(PaketRestoreCachedHasher)' == '' And Exists('/usr/bin/shasum') And Exists('/usr/bin/awk')">/usr/bin/shasum "$(PaketRestoreCacheFile)" | /usr/bin/awk '{ print $1 }'</PaketRestoreCachedHasher>
87-
<PaketRestoreLockFileHasher Condition="'$(OS)' != 'Windows_NT' And '$(PaketRestoreLockFileHash)' == '' And Exists('/usr/bin/shasum') And Exists('/usr/bin/awk')">/usr/bin/shasum "$(PaketLockFilePath)" | /usr/bin/awk '{ print $1 }'</PaketRestoreLockFileHasher>
94+
<!-- Read the hash of the lockfile -->
95+
<GetFileHash Condition=" '$(MSBuildSupportsHashing)' == 'true' And '$(CacheFilesExist)' == 'true' " Files="$(PaketLockFilePath)" Algorithm="SHA256" HashEncoding="hex" >
96+
<Output TaskParameter="Hash" PropertyName="PaketRestoreLockFileHash" />
97+
</GetFileHash>
98+
<!-- Read the hash of the cache, which is json, but a very simple key value object -->
99+
<PropertyGroup Condition=" '$(MSBuildSupportsHashing)' == 'true' And '$(CacheFilesExist)' == 'true' ">
100+
<PaketRestoreCachedContents>$([System.IO.File]::ReadAllText('$(PaketRestoreCacheFile)'))</PaketRestoreCachedContents>
101+
</PropertyGroup>
102+
<ItemGroup Condition=" '$(MSBuildSupportsHashing)' == 'true' And '$(CacheFilesExist)' == 'true' ">
103+
<!-- Parse our simple 'paket.restore.cached' json ...-->
104+
<PaketRestoreCachedSplitObject Include="$([System.Text.RegularExpressions.Regex]::Split(`$(PaketRestoreCachedContents)`, `{|}|,`))"></PaketRestoreCachedSplitObject>
105+
<!-- Keep Key, Value ItemGroup-->
106+
<PaketRestoreCachedKeyValue Include="@(PaketRestoreCachedSplitObject)"
107+
Condition=" $([System.Text.RegularExpressions.Regex]::Split(`%(Identity)`, `&quot;: &quot;`).Length) &gt; 1 ">
108+
<Key>$([System.Text.RegularExpressions.Regex]::Split(`%(Identity)`, `": "`)[0].Replace(`"`, ``).Replace(` `, ``))</Key>
109+
<Value>$([System.Text.RegularExpressions.Regex]::Split(`%(Identity)`, `": "`)[1].Replace(`"`, ``).Replace(` `, ``))</Value>
110+
</PaketRestoreCachedKeyValue>
111+
</ItemGroup>
112+
<PropertyGroup Condition=" '$(MSBuildSupportsHashing)' == 'true' And '$(CacheFilesExist)' == 'true' ">
113+
<!-- Retrieve the hashes we are interested in -->
114+
<PackagesDownloadedHash Condition=" '%(PaketRestoreCachedKeyValue.Key)' == 'packagesDownloadedHash' ">%(PaketRestoreCachedKeyValue.Value)</PackagesDownloadedHash>
115+
<ProjectsRestoredHash Condition=" '%(PaketRestoreCachedKeyValue.Key)' == 'projectsRestoredHash' ">%(PaketRestoreCachedKeyValue.Value)</ProjectsRestoredHash>
88116
</PropertyGroup>
89117

90-
<!-- If shasum and awk exist get the hashes -->
91-
<Exec StandardOutputImportance="Low" Condition=" '$(PaketRestoreCachedHasher)' != '' " Command="$(PaketRestoreCachedHasher)" ConsoleToMSBuild='true'>
92-
<Output TaskParameter="ConsoleOutput" PropertyName="PaketRestoreCachedHash" />
93-
</Exec>
94-
<Exec StandardOutputImportance="Low" Condition=" '$(PaketRestoreLockFileHasher)' != '' " Command="$(PaketRestoreLockFileHasher)" ConsoleToMSBuild='true'>
95-
<Output TaskParameter="ConsoleOutput" PropertyName="PaketRestoreLockFileHash" />
96-
</Exec>
97-
98-
<!-- Debug whats going on -->
99-
<Message Importance="low" Text="calling paket restore with targetframework=$(TargetFramework) targetframeworks=$(TargetFrameworks)" />
100-
101-
<PropertyGroup Condition="Exists('$(PaketRestoreCacheFile)') ">
102-
<!-- if no hash has been done yet fall back to just reading in the files and comparing them -->
103-
<PaketRestoreCachedHash Condition=" '$(PaketRestoreCachedHash)' == '' ">$([System.IO.File]::ReadAllText('$(PaketRestoreCacheFile)'))</PaketRestoreCachedHash>
104-
<PaketRestoreLockFileHash Condition=" '$(PaketRestoreLockFileHash)' == '' ">$([System.IO.File]::ReadAllText('$(PaketLockFilePath)'))</PaketRestoreLockFileHash>
118+
<PropertyGroup Condition=" '$(MSBuildSupportsHashing)' == 'true' And '$(CacheFilesExist)' == 'true' ">
119+
<!-- If the restire file doesn't exist we need to restore, otherwise only if hashes don't match -->
105120
<PaketRestoreRequired>true</PaketRestoreRequired>
106-
<PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '$(PaketRestoreCachedHash)' ">false</PaketRestoreRequired>
121+
<PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '$(ProjectsRestoredHash)' ">false</PaketRestoreRequired>
107122
<PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '' ">true</PaketRestoreRequired>
108123
</PropertyGroup>
109124

@@ -116,7 +131,10 @@
116131
</PropertyGroup>
117132

118133
<!-- Do a global restore if required -->
134+
<Warning Text="This version of MSBuild (we assume '$(DetectedMSBuildVersion)' or older) doesn't support GetFileHash, so paket fast restore is disabled." Condition=" '$(MSBuildSupportsHashing)' != 'true' " />
135+
<Error Text="Stop build because of PAKET_ERROR_ON_MSBUILD_EXEC and we always call the bootstrapper" Condition=" '$(PAKET_ERROR_ON_MSBUILD_EXEC)' == 'true' AND '$(PaketBootstrapperStyle)' == 'classic' AND Exists('$(PaketBootStrapperExePath)') AND !(Exists('$(PaketExePath)'))" />
119136
<Exec Command='$(PaketBootStrapperCommand)' Condition=" '$(PaketBootstrapperStyle)' == 'classic' AND Exists('$(PaketBootStrapperExePath)') AND !(Exists('$(PaketExePath)'))" ContinueOnError="false" />
137+
<Error Text="Stop build because of PAKET_ERROR_ON_MSBUILD_EXEC and we need a full restore (hashes don't match)" Condition=" '$(PAKET_ERROR_ON_MSBUILD_EXEC)' == 'true' AND '$(PaketRestoreRequired)' == 'true' AND '$(PaketDisableGlobalRestore)' != 'true'" />
120138
<Exec Command='$(PaketCommand) restore' Condition=" '$(PaketRestoreRequired)' == 'true' AND '$(PaketDisableGlobalRestore)' != 'true' " ContinueOnError="false" />
121139

122140
<!-- Step 2 Detect project specific changes -->
@@ -126,7 +144,7 @@
126144
<MyTargetFrameworks Condition="'$(TargetFrameworks)' != '' AND '$(TargetFramework)' == '' " Include="$(TargetFrameworks)"></MyTargetFrameworks>
127145
<PaketResolvedFilePaths Include="@(MyTargetFrameworks -> '$(PaketIntermediateOutputPath)\$(MSBuildProjectFile).%(Identity).paket.resolved')"></PaketResolvedFilePaths>
128146
</ItemGroup>
129-
<Message Importance="low" Text="MyTargetFrameworks=@(MyTargetFrameworks) PaketResolvedFilePaths=@(PaketResolvedFilePaths)" />
147+
130148
<PropertyGroup>
131149
<PaketReferencesCachedFilePath>$(PaketIntermediateOutputPath)\$(MSBuildProjectFile).paket.references.cached</PaketReferencesCachedFilePath>
132150
<!-- MyProject.fsproj.paket.references has the highest precedence -->
@@ -163,6 +181,7 @@
163181

164182
<!-- Step 3 Restore project specific stuff if required -->
165183
<Message Condition=" '$(PaketRestoreRequired)' == 'true' " Importance="low" Text="Detected a change ('$(PaketRestoreRequiredReason)') in the project file '$(MSBuildProjectFullPath)', calling paket restore" />
184+
<Error Text="Stop build because of PAKET_ERROR_ON_MSBUILD_EXEC and we detected a change ('$(PaketRestoreRequiredReason)') in the project file '$(MSBuildProjectFullPath)'" Condition=" '$(PAKET_ERROR_ON_MSBUILD_EXEC)' == 'true' AND '$(PaketRestoreRequired)' == 'true' " />
166185
<Exec Command='$(PaketCommand) restore --project "$(MSBuildProjectFullPath)" --output-path "$(PaketIntermediateOutputPath)" --target-framework "$(TargetFrameworks)"' Condition=" '$(PaketRestoreRequired)' == 'true' AND '$(TargetFramework)' == '' " ContinueOnError="false" />
167186
<Exec Command='$(PaketCommand) restore --project "$(MSBuildProjectFullPath)" --output-path "$(PaketIntermediateOutputPath)" --target-framework "$(TargetFramework)"' Condition=" '$(PaketRestoreRequired)' == 'true' AND '$(TargetFramework)' != '' " ContinueOnError="false" />
168187

@@ -224,8 +243,6 @@
224243
<Target Name="PaketDisableDirectPack" AfterTargets="_IntermediatePack" BeforeTargets="GenerateNuspec" Condition="('$(IsPackable)' == '' Or '$(IsPackable)' == 'true') And Exists('$(PaketIntermediateOutputPath)/$(MSBuildProjectFile).references')" >
225244
<PropertyGroup>
226245
<ContinuePackingAfterGeneratingNuspec>false</ContinuePackingAfterGeneratingNuspec>
227-
<DetectedMSBuildVersion>$(MSBuildVersion)</DetectedMSBuildVersion>
228-
<DetectedMSBuildVersion Condition="$(MSBuildVersion) == ''">15.8.0</DetectedMSBuildVersion>
229246
</PropertyGroup>
230247
</Target>
231248

@@ -255,6 +272,7 @@
255272
<_NuspecFiles Include="$(AdjustedNuspecOutputPath)\*.$(PackageVersion.Split(`+`)[0]).nuspec"/>
256273
</ItemGroup>
257274

275+
<Error Text="Error Because of PAKET_ERROR_ON_MSBUILD_EXEC (not calling fix-nuspecs)" Condition=" '$(PAKET_ERROR_ON_MSBUILD_EXEC)' == 'true' " />
258276
<Exec Condition="@(_NuspecFiles) != ''" Command='$(PaketCommand) fix-nuspecs files "@(_NuspecFiles)" project-file "$(PaketProjectFile)" ' />
259277
<Error Condition="@(_NuspecFiles) == ''" Text='Could not find nuspec files in "$(AdjustedNuspecOutputPath)" (Version: "$(PackageVersion)"), therefore we cannot call "paket fix-nuspecs" and have to error out!' />
260278

src/BuildingRegistry.Api.CrabImport/CrabImport/IdempotentCommandHandlerModuleProcessor.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public IdempotentCommandHandlerModuleProcessor(
3030
Func<IStreamStore> getStreamStore,
3131
EventMapping eventMapping,
3232
EventSerializer eventSerializer,
33-
IOsloIdGenerator osloIdGenerator,
33+
IPersistentLocalIdGenerator persistentLocalIdGenerator,
3434
BuildingProvenanceFactory provenanceFactory)
3535
{
3636
_logger = logger;
@@ -43,7 +43,7 @@ public IdempotentCommandHandlerModuleProcessor(
4343
getStreamStore,
4444
eventMapping,
4545
eventSerializer,
46-
osloIdGenerator,
46+
persistentLocalIdGenerator,
4747
provenanceFactory);
4848
}
4949

@@ -119,16 +119,16 @@ public async Task<CommandMessage> Process(
119119
message = commandSubaddressPositionMessage;
120120
break;
121121

122-
case AssignOsloIdForCrabTerrainObjectId command:
123-
var commandAssignOsloId = new CommandMessage<AssignOsloIdForCrabTerrainObjectId>(command.CreateCommandId(), command, metadata);
124-
await _buildingCommandHandlerModule.AssignOsloIdForCrabTerrainObjectId(commandAssignOsloId, cancellationToken);
125-
message = commandAssignOsloId;
122+
case AssignPersistentLocalIdForCrabTerrainObjectId command:
123+
var commandAssignPersistentLocalId = new CommandMessage<AssignPersistentLocalIdForCrabTerrainObjectId>(command.CreateCommandId(), command, metadata);
124+
await _buildingCommandHandlerModule.AssignPersistentLocalIdForCrabTerrainObjectId(commandAssignPersistentLocalId, cancellationToken);
125+
message = commandAssignPersistentLocalId;
126126
break;
127127

128-
case RequestOsloIdsForCrabTerrainObjectId command:
129-
var commandRequestOsloId = new CommandMessage<RequestOsloIdsForCrabTerrainObjectId>(command.CreateCommandId(), command, metadata);
130-
await _buildingCommandHandlerModule.RequestOsloIdsForCrabTerrainObjectId(commandRequestOsloId, cancellationToken);
131-
message = commandRequestOsloId;
128+
case RequestPersistentLocalIdsForCrabTerrainObjectId command:
129+
var commandRequestPersistentLocalId = new CommandMessage<RequestPersistentLocalIdsForCrabTerrainObjectId>(command.CreateCommandId(), command, metadata);
130+
await _buildingCommandHandlerModule.RequestPersistentLocalIdsForCrabTerrainObjectId(commandRequestPersistentLocalId, cancellationToken);
131+
message = commandRequestPersistentLocalId;
132132
break;
133133

134134
case ImportReaddressingHouseNumberFromCrab command:

src/BuildingRegistry.Api.CrabImport/Infrastructure/Modules/ApiModule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ protected override void Load(ContainerBuilder containerBuilder)
8787
}));
8888

8989
containerBuilder
90-
.RegisterType<SqlOsloIdGenerator>()
91-
.As<IOsloIdGenerator>();
90+
.RegisterType<SqlPersistentLocalIdGenerator>()
91+
.As<IPersistentLocalIdGenerator>();
9292

9393
containerBuilder.Populate(_services);
9494
}

src/BuildingRegistry.Api.CrabImport/Infrastructure/SequenceContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace BuildingRegistry.Api.CrabImport.Infrastructure
99

1010
public class SequenceContext : DbContext
1111
{
12-
public const string BuildingOsloIdSequenceName = "BuildingOsloIds";
12+
public const string BuildingPersistentLocalIdSequenceName = "BuildingPersistentLocalIdSequence";
1313

1414
public SequenceContext() { }
1515

src/BuildingRegistry.Api.CrabImport/Infrastructure/SqlOsloIdGenerator.cs renamed to src/BuildingRegistry.Api.CrabImport/Infrastructure/SqlPersistentLocalIdGenerator.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ namespace BuildingRegistry.Api.CrabImport.Infrastructure
55
using Microsoft.EntityFrameworkCore;
66
using ValueObjects;
77

8-
public class SqlOsloIdGenerator : IOsloIdGenerator
8+
public class SqlPersistentLocalIdGenerator : IPersistentLocalIdGenerator
99
{
1010
private readonly SequenceContext _context;
1111

12-
public SqlOsloIdGenerator(SequenceContext context)
12+
public SqlPersistentLocalIdGenerator(SequenceContext context)
1313
{
1414
_context = context;
1515
}
1616

17-
public OsloId GenerateNextOsloId()
17+
public PersistentLocalId GenerateNextPersistentLocalId()
1818
{
19-
var sqlStatement = $"SELECT NEXT VALUE FOR {Schema.Sequence}.{SequenceContext.BuildingOsloIdSequenceName}";
19+
var sqlStatement = $"SELECT NEXT VALUE FOR {Schema.Sequence}.{SequenceContext.BuildingPersistentLocalIdSequenceName}";
2020

2121
int nextNumber;
2222
using (var command = _context.Database.GetDbConnection().CreateCommand())
@@ -29,7 +29,7 @@ public OsloId GenerateNextOsloId()
2929
command.Connection.Close();
3030
}
3131

32-
return new OsloId(nextNumber);
32+
return new PersistentLocalId(nextNumber);
3333
}
3434
}
3535
}

src/BuildingRegistry.Api.CrabImport/Migrations/20190226091148_Initial.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public partial class Initial : Migration
1010
protected override void Up(MigrationBuilder migrationBuilder)
1111
{
1212
migrationBuilder.Sql($@"
13-
CREATE SEQUENCE {Schema.Sequence}.{SequenceContext.BuildingOsloIdSequenceName}
13+
CREATE SEQUENCE {Schema.Sequence}.{SequenceContext.BuildingPersistentLocalIdSequenceName}
1414
AS int
1515
START WITH 30000000
1616
INCREMENT BY 1
@@ -23,7 +23,7 @@ NO CACHE
2323

2424
protected override void Down(MigrationBuilder migrationBuilder)
2525
{
26-
migrationBuilder.Sql($@"DROP SEQUENCE {Schema.Sequence}.{SequenceContext.BuildingOsloIdSequenceName};");
26+
migrationBuilder.Sql($@"DROP SEQUENCE {Schema.Sequence}.{SequenceContext.BuildingPersistentLocalIdSequenceName};");
2727
}
2828
}
2929
}

src/BuildingRegistry.Api.Extract/Extracts/BuildingRegistryExtractBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static IEnumerable<ExtractFile> CreateBuildingFiles(ExtractContext contex
1717
.BuildingExtract
1818
.AsNoTracking()
1919
.Where(m => m.IsComplete)
20-
.OrderBy(m => m.OsloId);
20+
.OrderBy(m => m.PersistentLocalId);
2121

2222
yield return ExtractBuilder.CreateDbfFile<BuildingExtractItem, BuildingDbaseRecord>(
2323
ExtractController.BuildingZipName,

src/BuildingRegistry.Api.Extract/Extracts/BuildingUnitRegistryExtractBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static IEnumerable<ExtractFile> CreateBuildingUnitFiles(ExtractContext co
1717
.BuildingUnitExtract
1818
.AsNoTracking()
1919
.Where(m => m.IsComplete)
20-
.OrderBy(m => m.OsloId);
20+
.OrderBy(m => m.PersistentLocalId);
2121

2222
yield return ExtractBuilder.CreateDbfFile<BuildingUnitExtractItem, BuildingUnitDbaseRecord>(
2323
ExtractController.BuildingUnitZipName,

0 commit comments

Comments
 (0)