1
0
mirror of synced 2024-11-21 12:23:50 +00:00

Refactored publishing from received message

Added AppVeyor build file
This commit is contained in:
Mark van Renswoude 2021-12-15 12:53:25 +01:00
parent e9de38b556
commit 210c5c2772
10 changed files with 168 additions and 71 deletions

6
GitVersion.yml Normal file
View File

@ -0,0 +1,6 @@
mode: ContinuousDeployment
branches:
master:
mode: ContinuousDelivery
ignore:
sha: []

View File

@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<Version>0.1</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<Version>0.1</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>0.1</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Version>0.1</Version>
<UseWPF>true</UseWPF>
<Authors>Mark van Renswoude</Authors>
<Product>Petting Zoo</Product>

View File

@ -134,78 +134,21 @@ namespace PettingZoo.UI.Tab.Publisher
private void SetMessageTypeControl(ReceivedMessageInfo fromReceivedMessage)
{
// TODO move to individual viewmodels?
if (IsTapetiMessage(fromReceivedMessage, out var assemblyName, out var className))
if (TapetiPublisherViewModel.IsTapetiMessage(fromReceivedMessage))
{
var tapetiPublisherViewModel = new TapetiPublisherViewModel(connection)
{
Exchange = fromReceivedMessage.Exchange,
RoutingKey = fromReceivedMessage.RoutingKey,
var tapetiPublisherViewModel = new TapetiPublisherViewModel(connection, fromReceivedMessage);
tapetiPublisherView = new TapetiPublisherView(tapetiPublisherViewModel);
AssemblyName = assemblyName,
ClassName = className,
CorrelationId = fromReceivedMessage.Properties.CorrelationId ?? "",
ReplyTo = fromReceivedMessage.Properties.ReplyTo ?? "",
Payload = Encoding.UTF8.GetString(fromReceivedMessage.Body)
};
tapetiPublisherView ??= new TapetiPublisherView(tapetiPublisherViewModel);
SetMessageTypeControl(MessageType.Tapeti);
}
else
{
var rawPublisherViewModel = new RawPublisherViewModel(connection)
{
Exchange = fromReceivedMessage.Exchange,
RoutingKey = fromReceivedMessage.RoutingKey,
CorrelationId = fromReceivedMessage.Properties.CorrelationId ?? "",
ReplyTo = fromReceivedMessage.Properties.ReplyTo ?? "",
Priority = fromReceivedMessage.Properties.Priority?.ToString() ?? "",
AppId = fromReceivedMessage.Properties.AppId ?? "",
ContentEncoding = fromReceivedMessage.Properties.ContentEncoding ?? "",
ContentType = fromReceivedMessage.Properties.ContentType ?? "",
Expiration = fromReceivedMessage.Properties.Expiration ?? "",
MessageId = fromReceivedMessage.Properties.MessageId ?? "",
Timestamp = fromReceivedMessage.Properties.Timestamp?.ToString() ?? "",
TypeProperty = fromReceivedMessage.Properties.Type ?? "",
UserId = fromReceivedMessage.Properties.UserId ?? "",
Payload = Encoding.UTF8.GetString(fromReceivedMessage.Body)
};
foreach (var header in fromReceivedMessage.Properties.Headers)
rawPublisherViewModel.Headers.Add(new RawPublisherViewModel.Header
{
Key = header.Key,
Value = header.Value
});
var rawPublisherViewModel = new RawPublisherViewModel(connection, fromReceivedMessage);
rawPublisherView = new RawPublisherView(rawPublisherViewModel);
SetMessageTypeControl(MessageType.Raw);
}
}
private static bool IsTapetiMessage(ReceivedMessageInfo receivedMessage, out string assemblyName, out string className)
{
assemblyName = "";
className = "";
if (receivedMessage.Properties.ContentType != @"application/json")
return false;
if (!receivedMessage.Properties.Headers.TryGetValue(@"classType", out var classType))
return false;
var parts = classType.Split(':');
if (parts.Length != 2)
return false;
className = parts[0];
assemblyName = parts[1];
return true;
}
}

View File

@ -191,33 +191,60 @@ namespace PettingZoo.UI.Tab.Publisher
: RawPublisherViewStrings.PropertiesExpand;
protected Header lastHeader;
protected Header LastHeader;
public RawPublisherViewModel(IConnection connection)
public RawPublisherViewModel(IConnection connection, ReceivedMessageInfo? receivedMessage = null)
{
this.connection = connection;
publishCommand = new DelegateCommand(PublishExecute, PublishCanExecute);
propertiesExpandCollapseCommand = new DelegateCommand(PropertiesExpandCollapseExecute);
if (receivedMessage != null)
{
Exchange = receivedMessage.Exchange;
RoutingKey = receivedMessage.RoutingKey;
CorrelationId = receivedMessage.Properties.CorrelationId ?? "";
ReplyTo = receivedMessage.Properties.ReplyTo ?? "";
Priority = receivedMessage.Properties.Priority?.ToString() ?? "";
AppId = receivedMessage.Properties.AppId ?? "";
ContentEncoding = receivedMessage.Properties.ContentEncoding ?? "";
ContentType = receivedMessage.Properties.ContentType ?? "";
Expiration = receivedMessage.Properties.Expiration ?? "";
MessageId = receivedMessage.Properties.MessageId ?? "";
Timestamp = receivedMessage.Properties.Timestamp?.ToString() ?? "";
TypeProperty = receivedMessage.Properties.Type ?? "";
UserId = receivedMessage.Properties.UserId ?? "";
Payload = Encoding.UTF8.GetString(receivedMessage.Body);
foreach (var header in receivedMessage.Properties.Headers)
Headers.Add(new Header
{
Key = header.Key,
Value = header.Value
});
}
AddHeader();
}
private void LastHeaderChanged(object? sender, PropertyChangedEventArgs e)
{
lastHeader.PropertyChanged -= LastHeaderChanged;
LastHeader.PropertyChanged -= LastHeaderChanged;
AddHeader();
}
[MemberNotNull(nameof(lastHeader))]
[MemberNotNull(nameof(LastHeader))]
private void AddHeader()
{
lastHeader = new Header();
lastHeader.PropertyChanged += LastHeaderChanged;
Headers.Add(lastHeader);
LastHeader = new Header();
LastHeader.PropertyChanged += LastHeaderChanged;
Headers.Add(LastHeader);
}
@ -310,7 +337,7 @@ namespace PettingZoo.UI.Tab.Publisher
{
PropertiesExpanded = true;
var capturedLastHeader = lastHeader;
var capturedLastHeader = LastHeader;
capturedLastHeader.Key = "Example";
capturedLastHeader.Value = "header";
}

View File

@ -114,11 +114,52 @@ namespace PettingZoo.UI.Tab.Publisher
public ICommand PublishCommand => publishCommand;
public TapetiPublisherViewModel(IConnection connection)
public static bool IsTapetiMessage(ReceivedMessageInfo receivedMessage)
{
return IsTapetiMessage(receivedMessage, out _, out _);
}
public static bool IsTapetiMessage(ReceivedMessageInfo receivedMessage, out string assemblyName, out string className)
{
assemblyName = "";
className = "";
if (receivedMessage.Properties.ContentType != @"application/json")
return false;
if (!receivedMessage.Properties.Headers.TryGetValue(@"classType", out var classType))
return false;
var parts = classType.Split(':');
if (parts.Length != 2)
return false;
className = parts[0];
assemblyName = parts[1];
return true;
}
public TapetiPublisherViewModel(IConnection connection, ReceivedMessageInfo? receivedMessage = null)
{
this.connection = connection;
publishCommand = new DelegateCommand(PublishExecute, PublishCanExecute);
if (receivedMessage == null)
return;
Exchange = receivedMessage.Exchange;
RoutingKey = receivedMessage.RoutingKey;
AssemblyName = assemblyName;
ClassName = className;
CorrelationId = receivedMessage.Properties.CorrelationId ?? "";
ReplyTo = receivedMessage.Properties.ReplyTo ?? "";
Payload = Encoding.UTF8.GetString(receivedMessage.Body);
}

38
appveyor.yml Normal file
View File

@ -0,0 +1,38 @@
image: Visual Studio 2022
install:
- choco install gitversion.portable -pre -y
before_build:
- ps: gitversion /l console /output buildserver
- ps: build\UpdateVersion.ps1
after_build:
# Create PettingZoo release
- cmd: dotnet publish -c Release -r win-x64 --self-contained=true -o publish\x64\selfcontained PettingZoo\PettingZoo.csproj
- cmd: dotnet publish -c Release -r win-x64 --self-contained=false -o publish\x64 PettingZoo\PettingZoo.csproj
- cmd: copy publish\x64\selfcontained\PettingZoo.exe publish\x64
- cmd: rmdir /s /q publish\x64\selfcontained
- cmd: 7z a output\PettingZoo-x64-%GitVersion_NuGetVersion%.zip %APPVEYOR_BUILD_FOLDER%\publish\x64\*
# Push artifacts
- ps: Get-ChildItem output\*.zip | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
build:
project: PettingZoo.sln
platform:
- Any CPU
configuration:
- Release
deploy:
- provider: GitHub
auth_token:
secure: dWOConKg3VTPvd9DmWOOKiX1SJCalaqKInuk9GlKQOZX2s+Bia49J7q+AHO8wFj7
artifact: /PettingZoo-.*\.zip/
draft: false
prerelease: false
on:
APPVEYOR_REPO_TAG: true

38
build/UpdateVersion.ps1 Normal file
View File

@ -0,0 +1,38 @@
# For debugging purposes
if (-not (Test-Path env:APPVEYOR_BUILD_FOLDER))
{
Write-Host "Warning: APPVEYOR_BUILD_FOLDER environment variable not set"
$env:APPVEYOR_BUILD_FOLDER = "P:\PettingZoo"
}
if (-not (Test-Path env:GitVersion_MajorMinorPatch))
{
Write-Host "Warning: GitVersion_MajorMinorPatch environment variable not set"
$env:GitVersion_MajorMinorPatch = "0.0.1"
}
if (-not (Test-Path env:GitVersion_CommitsSinceVersionSource))
{
Write-Host "Warning: GitVersion_CommitsSinceVersionSource environment variable not set"
$env:GitVersion_CommitsSinceVersionSource = "42"
}
$version = "$($env:GitVersion_MajorMinorPatch).$($env:GitVersion_CommitsSinceVersionSource)"
Write-Host "Updating version to $($version) for projects in $($env:APPVEYOR_BUILD_FOLDER)"
$projectFiles = Get-ChildItem $env:APPVEYOR_BUILD_FOLDER -Recurse *.csproj | Select -ExpandProperty FullName
foreach ($projectFile in $projectFiles)
{
$contents = Get-Content -Path $projectFile
if ($contents -match "<Version>(.+?)</Version>")
{
$contents = $contents -replace "<Version>(.+?)</Version>", "<Version>$($version)</Version>"
Set-Content -Path $projectFile -Value $contents
Write-Host "Updated $($projectFile)"
}
else
{
Write-Host "No version information in $($projectFile)"
}
}