Skip to content

Commit

Permalink
- removed "useTcps" checkbox. user should enter tcps:// in form instead
Browse files Browse the repository at this point in the history
- added presets function to publish / subscribe
- added example.json for presets
  • Loading branch information
GyroGearl00se committed Jul 20, 2024
1 parent a83c0d8 commit 876d148
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 195 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,5 @@ MigrationBackup/
# Fody - auto-generated XML schema
FodyWeavers.xsd

presets/*
!presets/.keep

trustedca/*
!trustedca/.keep
91 changes: 73 additions & 18 deletions Components/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@
@inject SolaceSubscribeService SubscribeService
@inject Blazored.Toast.Services.IToastService toastService
@implements IDisposable
@inject PresetService PresetService

<h3>Solace PubSub+</h3>

<div class="form-container">
<div class="form-section">
<h4>Publish Message</h4>
<div class="form-group">
<label>Select Preset</label>
<select class="form-select-sm" @onchange="LoadPresetPublish">
<option value="">Select a preset</option>
@foreach (var preset in presets)
{
<option value="@preset.Name">@preset.Name</option>
}
</select>
</div>
<div class="form-group">
<div class="input-with-checkbox">
<div class="input-container">
<label>Hostname:Port</label>
<input @bind="publishHost" name="publishHost" autocomplete="on" placeholder="tcps://broker.domain:55443" />
</div>
<div class="checkbox-container">
<input type="checkbox" @bind="publishUseTcps" id="publishUseTcps" />
<label for="publishUseTcps">TCPS</label>
</div>
<div class="checkbox-container">
<input type="checkbox" @bind="publishSslVerify" id="publishSslVerify" />
<label for="publishSslVerify">SSL Verify</label>
Expand Down Expand Up @@ -52,16 +59,22 @@

<div class="form-section">
<h4>Subscribe to Topic</h4>
<div class="form-group">
<label>Select Preset</label>
<select class="form-select-sm" @onchange="LoadPresetSubscribe">
<option value="">Select a preset</option>
@foreach (var preset in presets)
{
<option value="@preset.Name">@preset.Name</option>
}
</select>
</div>
<div class="form-group">
<div class="input-with-checkbox">
<div class="input-container">
<label>Hostname:Port</label>
<input @bind="subscribeHost" name="subscribeHost" autocomplete="on" placeholder="tcps://broker.domain:55443" />
</div>
<div class="checkbox-container">
<input type="checkbox" @bind="subscribeUseTcps" id="subscribeUseTcps" />
<label for="subscribeUseTcps">TCPS</label>
</div>
<div class="checkbox-container">
<input type="checkbox" @bind="subscribeSslVerify" id="subscribeSslVerify" />
<label for="subscribeSslVerify">SSL Verify</label>
Expand Down Expand Up @@ -105,33 +118,76 @@
private string publishPassword;
private string publishTopic;
private string publishMessage;
private bool publishUseTcps = true;
private bool publishSslVerify = true;
private string subscribeHost;
private string subscribeVpnName;
private string subscribeUsername;
private string subscribePassword;
private string subscribeTopic;
private bool subscribeSslVerify = true;
private bool subscribeUseTcps = true;
private string selectedPresetName;
private string presetName;
private List<PresetModel> presets = new List<PresetModel>();

private List<string> messages = new List<string>();

private string FormatHost(string host, bool useTcps)
protected override async Task OnInitializedAsync()
{
presets = await PresetService.GetPresetsAsync();
}

private async Task LoadPresetPublish(ChangeEventArgs e)
{
if (useTcps && !host.StartsWith("tcps://"))
selectedPresetName = e.Value?.ToString();
Console.WriteLine($"Selected Preset Name: {selectedPresetName}");
if (!string.IsNullOrEmpty(selectedPresetName))
{
return "tcps://" + host;
var preset = presets.FirstOrDefault(p => p.Name == selectedPresetName);
if (preset != null)
{
publishHost = preset.Host;
publishVpnName = preset.VpnName;
publishUsername = preset.Username;
publishTopic = preset.Topic;

Console.WriteLine($"Loaded Preset: {preset.Name}");
}
else
{
Console.WriteLine($"Preset with name '{selectedPresetName}' not found.");
}
}
}

private async Task LoadPresetSubscribe(ChangeEventArgs e)
{
selectedPresetName = e.Value?.ToString();
Console.WriteLine($"Selected Preset Name: {selectedPresetName}");
if (!string.IsNullOrEmpty(selectedPresetName))
{
var preset = presets.FirstOrDefault(p => p.Name == selectedPresetName);
if (preset != null)
{
subscribeHost = preset.Host;
subscribeVpnName = preset.VpnName;
subscribeUsername = preset.Username;
subscribeTopic = preset.Topic;

Console.WriteLine($"Loaded Preset: {preset.Name}");
}
else
{
Console.WriteLine($"Preset with name '{selectedPresetName}' not found.");
}
}
return host;
}


private void ConnectAndPublish()
{
try
{
string formattedHost = FormatHost(publishHost, publishUseTcps);
PublishService.PublishMessage(formattedHost, publishVpnName, publishUsername, publishPassword, publishTopic, publishMessage, publishSslVerify);
PublishService.PublishMessage(publishHost, publishVpnName, publishUsername, publishPassword, publishTopic, publishMessage, publishSslVerify);
toastService.ShowSuccess("Successfully published message");
}
catch (SolaceSystems.Solclient.Messaging.OperationErrorException ex)
Expand All @@ -144,8 +200,7 @@
{
try
{
string formattedHost = FormatHost(subscribeHost, subscribeUseTcps);
SubscribeService.SubscribeToTopic(formattedHost, subscribeVpnName, subscribeUsername, subscribePassword, subscribeTopic, subscribeSslVerify, message =>
SubscribeService.SubscribeToTopic(subscribeHost, subscribeVpnName, subscribeUsername, subscribePassword, subscribeTopic, subscribeSslVerify, message =>
{
InvokeAsync(() =>
{
Expand Down
145 changes: 3 additions & 142 deletions Components/Pages/QueueBrowser.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
@inject Blazored.Toast.Services.IToastService toastService
@inject NavigationManager Navigation
@inject PresetService PresetService
@inject IModalService ModalService
@inject IJSRuntime JsRuntime

<Layout>
<Title>Queue Browser</Title>
Expand All @@ -22,9 +20,6 @@
<option value="@preset.Name">@preset.Name</option>
}
</select>
<button class="btn btn-secondary" @onclick="ShowSavePresetModal">Save Preset</button>
<button class="btn btn-secondary" @onclick="DeletePreset">Delete Preset</button>

</div>

<div class="overlay" style="display: @(isDeleting ? "block" : "none")">
Expand All @@ -45,10 +40,6 @@
<label>Hostname:Port</label>
<input @bind="host" name="host" autocomplete="on" placeholder="tcps://broker.domain:55443" />
</div>
<div class="checkbox-container">
<input type="checkbox" @bind="useTcps" id="useTcps" />
<label for="useTcps">TCPS</label>
</div>
<div class="checkbox-container">
<input type="checkbox" @bind="sslVerify" id="sslVerify" />
<label for="sslVerify">SSL Verify</label>
Expand Down Expand Up @@ -84,7 +75,7 @@
RowOverlayBackground="Background.Transparent"
DetailRowStartsVisible="false"
Filterable
FilterMethod="DataGridFilterMethod.Contains"
FilterMethod="DataGridFilterMethod.StartsWith"
ShowPager
ShowPageSizes
PagerPosition="DataGridPagerPosition.TopAndBottom"
Expand Down Expand Up @@ -144,68 +135,8 @@
</div>
</DetailRowTemplate>
</DataGrid>

<Modal @ref="savePresetModal">
<ModalContent Centered Background="Background.Dark">
<ModalHeader>
<ModalTitle>Save Preset</ModalTitle>
<CloseButton Clicked="HideSavePresetModal" />
</ModalHeader>
<ModalBody>
<Field>
<Validation Validator="ValidationRule.IsNotEmpty">
<FieldLabel>Preset Name</FieldLabel>
<TextEdit @bind-Text="@presetName" Placeholder="Enter preset name...">
<Feedback>
<ValidationNone>Please enter a valid preset name</ValidationNone>
<ValidationError>Please enter a valid preset name</ValidationError>
</Feedback>
</TextEdit>
</Validation>
</Field>
<Field>
<Validation Validator="ValidationRule.IsNotEmpty">
<FieldLabel>Host</FieldLabel>
<TextEdit @bind-Text="@host" Placeholder="Enter host...">
<Feedback>
<ValidationNone>Please enter a valid host</ValidationNone>
<ValidationError>Please enter a valid host</ValidationError>
</Feedback>
</TextEdit>
</Validation>
</Field>
<Field>
<Validation Validator="ValidationRule.IsNotEmpty">
<FieldLabel>VPN Name</FieldLabel>
<TextEdit @bind-Text="@vpnName" Placeholder="Enter VPN name...">
<Feedback>
<ValidationNone>Please enter a valid VPN name</ValidationNone>
<ValidationError>Please enter a valid VPN name</ValidationError>
</Feedback>
</TextEdit>
</Validation>
</Field>
<Field>
<FieldLabel>Username</FieldLabel>
<TextEdit @bind-Text="@username" Placeholder="Enter username..." />
</Field>
<Field>
<FieldLabel>Queue Name</FieldLabel>
<TextEdit @bind-Text="@queueName" Placeholder="Enter queue name..." />
</Field>

</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="HideSavePresetModal">Cancel</Button>
<Button Color="Color.Primary" Clicked="SavePreset">Save</Button>
</ModalFooter>
</ModalContent>
</Modal>

</Layout>



@code {
private string host;
private string vpnName;
Expand All @@ -214,33 +145,21 @@
private string queueName;
private int maxMessages = 50;
private bool sslVerify = true;
private bool useTcps = true;
private List<MessageDetails> messages = new List<MessageDetails>();
private DataGrid<MessageDetails> dataGrid;
private string selectedPresetName;
private Modal savePresetModal;
private string presetName;
private List<PresetModel> presets = new List<PresetModel>();

private bool isBrowsing = false;

private string FormatHost(string host, bool useTcps)
{
if (useTcps && !host.StartsWith("tcps://"))
{
return "tcps://" + host;
}
return host;
}

private async Task BrowseQueueAsync()
{
Logger.LogInformation("BrowseQueue method called.");
try
{
string formattedHost = FormatHost(host, useTcps);
isBrowsing = true;
messages = await QueueBrowserService.BrowseQueueAsync(formattedHost, vpnName, username, password, queueName, sslVerify, maxMessages);
messages = await QueueBrowserService.BrowseQueueAsync(host, vpnName, username, password, queueName, sslVerify, maxMessages);
Logger.LogInformation("Messages retrieved: {count}", messages.Count);
}
catch (SolaceSystems.Solclient.Messaging.OperationErrorException ex)
Expand All @@ -263,10 +182,9 @@
{
try
{
string formattedHost = FormatHost(host, useTcps);
isDeleting = true;
deletingMessageId = adMessageId.ToString();
await QueueBrowserService.DeleteMessage(formattedHost, vpnName, username, password, queueName, sslVerify, adMessageId);
await QueueBrowserService.DeleteMessage(host, vpnName, username, password, queueName, sslVerify, adMessageId);
toastService.ShowSuccess("Deleting message with ID: " + deletingMessageId);
await BrowseQueueAsync();
}
Expand Down Expand Up @@ -342,61 +260,4 @@
}
}
}
private void ShowSavePresetModal()
{
presetName = "";
savePresetModal.Show();
}

private void HideSavePresetModal()
{
savePresetModal.Hide();
}

private async Task SavePreset()
{
var existingPreset = presets.FirstOrDefault(p => p.Name == presetName);

if (existingPreset != null)
{
if (await JsRuntime.InvokeAsync<bool>("confirm", $"A preset with the name '{presetName}' already exists. Do you want to overwrite it?"))
{
existingPreset.Host = host;
existingPreset.VpnName = vpnName;
existingPreset.Username = username;
existingPreset.QueueName = queueName;

await PresetService.SavePresetAsync(existingPreset);
presets = await PresetService.GetPresetsAsync();
toastService.ShowSuccess("Preset overwritten successfully");
}
}
else
{
var newPreset = new PresetModel
{
Name = presetName,
Host = host,
VpnName = vpnName,
Username = username,
QueueName = queueName
};

await PresetService.SavePresetAsync(newPreset);
presets = await PresetService.GetPresetsAsync();
toastService.ShowSuccess("Preset saved successfully");
}

savePresetModal.Hide();
}

private async Task DeletePreset()
{
if (await JsRuntime.InvokeAsync<bool>("confirm", $"Deleting '{selectedPresetName}' Are you sure ?"))
{
await PresetService.DeletePresetAsync(selectedPresetName);
presets = await PresetService.GetPresetsAsync();
toastService.ShowSuccess("Deleted Preset successfully");
}
}
}
Loading

0 comments on commit 876d148

Please sign in to comment.