From 210c5c27726be7e2732baee387008bae5e89ba33 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Wed, 15 Dec 2021 12:53:25 +0100 Subject: [PATCH] Refactored publishing from received message Added AppVeyor build file --- GitVersion.yml | 6 ++ PettingZoo.Core/PettingZoo.Core.csproj | 1 + .../PettingZoo.RabbitMQ.csproj | 1 + PettingZoo.Tapeti/PettingZoo.Tapeti.csproj | 1 + PettingZoo/PettingZoo.csproj | 1 + .../UI/Tab/Publisher/PublisherViewModel.cs | 67 ++----------------- .../UI/Tab/Publisher/RawPublisherViewModel.cs | 43 +++++++++--- .../Tab/Publisher/TapetiPublisherViewModel.cs | 43 +++++++++++- appveyor.yml | 38 +++++++++++ build/UpdateVersion.ps1 | 38 +++++++++++ 10 files changed, 168 insertions(+), 71 deletions(-) create mode 100644 GitVersion.yml create mode 100644 appveyor.yml create mode 100644 build/UpdateVersion.ps1 diff --git a/GitVersion.yml b/GitVersion.yml new file mode 100644 index 0000000..7989fe4 --- /dev/null +++ b/GitVersion.yml @@ -0,0 +1,6 @@ +mode: ContinuousDeployment +branches: + master: + mode: ContinuousDelivery +ignore: + sha: [] diff --git a/PettingZoo.Core/PettingZoo.Core.csproj b/PettingZoo.Core/PettingZoo.Core.csproj index 483d761..e37010b 100644 --- a/PettingZoo.Core/PettingZoo.Core.csproj +++ b/PettingZoo.Core/PettingZoo.Core.csproj @@ -3,6 +3,7 @@ net6.0 enable + 0.1 diff --git a/PettingZoo.RabbitMQ/PettingZoo.RabbitMQ.csproj b/PettingZoo.RabbitMQ/PettingZoo.RabbitMQ.csproj index 79d0e3f..7a65453 100644 --- a/PettingZoo.RabbitMQ/PettingZoo.RabbitMQ.csproj +++ b/PettingZoo.RabbitMQ/PettingZoo.RabbitMQ.csproj @@ -3,6 +3,7 @@ net6.0 enable + 0.1 diff --git a/PettingZoo.Tapeti/PettingZoo.Tapeti.csproj b/PettingZoo.Tapeti/PettingZoo.Tapeti.csproj index 77a196f..d9b83bb 100644 --- a/PettingZoo.Tapeti/PettingZoo.Tapeti.csproj +++ b/PettingZoo.Tapeti/PettingZoo.Tapeti.csproj @@ -2,6 +2,7 @@ net6.0 + 0.1 diff --git a/PettingZoo/PettingZoo.csproj b/PettingZoo/PettingZoo.csproj index fa44a96..9ce003d 100644 --- a/PettingZoo/PettingZoo.csproj +++ b/PettingZoo/PettingZoo.csproj @@ -3,6 +3,7 @@ WinExe net6.0-windows + 0.1 true Mark van Renswoude Petting Zoo diff --git a/PettingZoo/UI/Tab/Publisher/PublisherViewModel.cs b/PettingZoo/UI/Tab/Publisher/PublisherViewModel.cs index dfab447..d25f256 100644 --- a/PettingZoo/UI/Tab/Publisher/PublisherViewModel.cs +++ b/PettingZoo/UI/Tab/Publisher/PublisherViewModel.cs @@ -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; - } } diff --git a/PettingZoo/UI/Tab/Publisher/RawPublisherViewModel.cs b/PettingZoo/UI/Tab/Publisher/RawPublisherViewModel.cs index d5d8cd3..7ad2b10 100644 --- a/PettingZoo/UI/Tab/Publisher/RawPublisherViewModel.cs +++ b/PettingZoo/UI/Tab/Publisher/RawPublisherViewModel.cs @@ -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"; } diff --git a/PettingZoo/UI/Tab/Publisher/TapetiPublisherViewModel.cs b/PettingZoo/UI/Tab/Publisher/TapetiPublisherViewModel.cs index 0252744..07c4362 100644 --- a/PettingZoo/UI/Tab/Publisher/TapetiPublisherViewModel.cs +++ b/PettingZoo/UI/Tab/Publisher/TapetiPublisherViewModel.cs @@ -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); } diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..3e03558 --- /dev/null +++ b/appveyor.yml @@ -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 \ No newline at end of file diff --git a/build/UpdateVersion.ps1 b/build/UpdateVersion.ps1 new file mode 100644 index 0000000..2a35611 --- /dev/null +++ b/build/UpdateVersion.ps1 @@ -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 "(.+?)") + { + $contents = $contents -replace "(.+?)", "$($version)" + Set-Content -Path $projectFile -Value $contents + Write-Host "Updated $($projectFile)" + } + else + { + Write-Host "No version information in $($projectFile)" + } +} \ No newline at end of file