Skip to content

Commit

Permalink
Updated sample app to use latest package version.
Browse files Browse the repository at this point in the history
Updated executor to use constructor inject for some dependencies.
  • Loading branch information
alexboia committed Mar 17, 2023
1 parent fcee93a commit 73f0e6a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,31 @@ namespace LVD.Stakhanovise.NET.Samples.FileHasher.FileProcessor.Executors
{
public class HashFileByHandleExecutor : BaseTaskExecutor<HashFileByHandle>
{
//Keep these dependency injected
private readonly ISourceFileRepository mSourceFileRepository;

private readonly IFileHashRepository mFileHashRepository;

public HashFileByHandleExecutor( ISourceFileRepository sourceFileRepository,
IFileHashRepository fileHashRepository )
{
mSourceFileRepository = sourceFileRepository
?? throw new ArgumentNullException( nameof( sourceFileRepository ) );
mFileHashRepository = fileHashRepository
?? throw new ArgumentNullException( nameof( fileHashRepository ) );
}

public override async Task ExecuteAsync( HashFileByHandle payload, ITaskExecutionContext executionContext )
{
using ( SHA256 sha256 = SHA256.Create() )
{
FileHandle fileHandle =
FileHandle fileHandle =
ResolveFileHandle( payload.HandleId );

byte[] fileContents =
byte [] fileContents =
await ReadFileAsync( fileHandle );

FileHashInfo fileHashInfo = ComputeHash( fileHandle,
FileHashInfo fileHashInfo = ComputeHash( fileHandle,
fileContents );

StoreFileHashAndNotifyCompletion( fileHashInfo );
Expand All @@ -63,19 +77,19 @@ public override async Task ExecuteAsync( HashFileByHandle payload, ITaskExecutio

private FileHandle ResolveFileHandle( Guid handleId )
{
return SourceFileRepository.ResolveFileByHandleId( handleId );
return mSourceFileRepository.ResolveFileByHandleId( handleId );
}

private async Task<byte[]> ReadFileAsync( FileHandle fileHandle )
private async Task<byte []> ReadFileAsync( FileHandle fileHandle )
{
return await File.ReadAllBytesAsync( fileHandle.Path );
}

private FileHashInfo ComputeHash( FileHandle fileHandle, byte[] fileContents )
private FileHashInfo ComputeHash( FileHandle fileHandle, byte [] fileContents )
{
using ( SHA256 sha256 = SHA256.Create() )
{
byte[] fileHash = sha256.ComputeHash( fileContents );
byte [] fileHash = sha256.ComputeHash( fileContents );
FileHashInfo fileHashInfo = new FileHashInfo( fileHandle, fileHash );

return fileHashInfo;
Expand All @@ -84,14 +98,14 @@ private FileHashInfo ComputeHash( FileHandle fileHandle, byte[] fileContents )

private void StoreFileHashAndNotifyCompletion( FileHashInfo fileHashInfo )
{
FileHashRepository.AddFileHash( fileHashInfo );
mFileHashRepository.AddFileHash( fileHashInfo );
ProcessingWatcher.NotifyFileHashed( fileHashInfo.FileHandle );
}

public ISourceFileRepository SourceFileRepository { get; set; }

public IFileHashRepository FileHashRepository { get; set; }

public IProcessingWatcher ProcessingWatcher { get; set; }
//Keep this property-injected
public IProcessingWatcher ProcessingWatcher
{
get; set;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@

<ItemGroup>
<PackageReference Include="Bogus" Version="34.0.2" />
<PackageReference Include="LVD.Stakhanovise.NET.Logging.Log4NetLogging" Version="1.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />

<PackageReference Include="LVD.Stakhanovise.NET" Version="1.0.3" />
<PackageReference Include="LVD.Stakhanovise.NET.Producer" Version="1.0.4" />
<PackageReference Include="LVD.Stakhanovise.NET.NetCoreConfigurationExtensionsBindings" Version="1.0.3" />
<PackageReference Include="LVD.Stakhanovise.NET" Version="1.0.5" />
<PackageReference Include="LVD.Stakhanovise.NET.Interfaces" Version="1.0.5" />
<PackageReference Include="LVD.Stakhanovise.NET.Producer" Version="1.0.5" />
<PackageReference Include="LVD.Stakhanovise.NET.NetCoreConfigurationExtensionsBindings" Version="1.0.5" />
<PackageReference Include="LVD.Stakhanovise.NET.Logging.Log4NetLogging" Version="1.0.5" />
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions LVD.Stakhanovise.NET/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"profiles": {
"LVD.Stakhanovise.NET": {
"commandName": "Project"
}
}
}

0 comments on commit 73f0e6a

Please sign in to comment.