Skip to content

Commit

Permalink
Added settings (#54)
Browse files Browse the repository at this point in the history
* Added settings

- Add a config object
- Add config UI
- Update Nuget packages
- Bug fixes
- Introducing Font awesome icon

* Feature:Added support for resize the panels (#53)

* Update MainWindow.xaml

Co-authored-by: Arman <[email protected]>
Co-authored-by: Javier Camacho <[email protected]>
  • Loading branch information
3 people authored Jun 5, 2022
1 parent ee5130c commit d50838a
Show file tree
Hide file tree
Showing 23 changed files with 324 additions and 187 deletions.
3 changes: 1 addition & 2 deletions PurpleExplorer/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml" />
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml" />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Default.xaml" />
<StyleInclude Source="/Styles/Icons.xaml" />
<StyleInclude Source="/Styles/CustomStyles.xaml" />
<StyleInclude Source="/Styles/CommonStyles.xaml" />
</Application.Styles>

<Design.DataContext>
Expand Down
18 changes: 12 additions & 6 deletions PurpleExplorer/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.IO;
using Avalonia;
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
Expand All @@ -20,19 +21,24 @@ public override void Initialize()

public override void OnFrameworkInitializationCompleted()
{
Locator.CurrentMutable.Register(() => new TopicHelper(), typeof(ITopicHelper));
Locator.CurrentMutable.RegisterLazySingleton(() => new LoggingService(), typeof(ILoggingService));
Locator.CurrentMutable.Register(() => new QueueHelper(), typeof(IQueueHelper));

var appStatePath = "appstate.json";
if (!File.Exists(appStatePath))
{
File.Create(appStatePath).Close();
}

var suspension = new AutoSuspendHelper(ApplicationLifetime);
RxApp.SuspensionHost.CreateNewAppState = () => new AppState();
RxApp.SuspensionHost.SetupDefaultSuspendResume(new NewtonsoftJsonSuspensionDriver("appstate.json"));
RxApp.SuspensionHost.SetupDefaultSuspendResume(new NewtonsoftJsonSuspensionDriver(appStatePath));
suspension.OnFrameworkInitializationCompleted();
var state = RxApp.SuspensionHost.GetAppState<AppState>();

Locator.CurrentMutable.RegisterLazySingleton(() => state, typeof(IAppState));
Locator.CurrentMutable.RegisterLazySingleton(() => new LoggingService(), typeof(ILoggingService));
Locator.CurrentMutable.Register(() => new TopicHelper(state.AppSettings), typeof(ITopicHelper));
Locator.CurrentMutable.Register(() => new QueueHelper(state.AppSettings), typeof(IQueueHelper));

new MainWindow { DataContext = new MainWindowViewModel() }.Show();

base.OnFrameworkInitializationCompleted();
}
}
Expand Down
19 changes: 17 additions & 2 deletions PurpleExplorer/Helpers/ModalWindowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,28 @@ namespace PurpleExplorer.Helpers
{
public class ModalWindowHelper
{
public static async Task ShowModalWindow<T>(ViewModelBase viewModel) where T : Window, new()
{
var mainWindow = (Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)
.Windows[0];

var window = new T
{
DataContext = viewModel
};

await window.ShowDialog(mainWindow);
}

public static async Task<U> ShowModalWindow<T, U>(ViewModelBase viewModel) where T : Window, new() where U : ViewModelBase
{
var mainWindow = (Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)
.Windows[0];

T window = new T();
window.DataContext = viewModel;
var window = new T
{
DataContext = viewModel
};

await window.ShowDialog(mainWindow);
return window.DataContext as U;
Expand Down
21 changes: 13 additions & 8 deletions PurpleExplorer/Helpers/QueueHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ namespace PurpleExplorer.Helpers
{
public class QueueHelper : IQueueHelper
{
private int _maxMessageCount = 100;
private readonly AppSettings _appSettings;

public QueueHelper(AppSettings appSettings)
{
_appSettings = appSettings;
}

public async Task<IList<ServiceBusQueue>> GetQueues(string connectionString)
{
IList<ServiceBusQueue> queues = new List<ServiceBusQueue>();
var client = new ManagementClient(connectionString);
var queuesInfo = await client.GetQueuesRuntimeInfoAsync();
var queuesInfo = await client.GetQueuesRuntimeInfoAsync(_appSettings.QueueListFetchCount);
await client.CloseAsync();

await Task.WhenAll(queuesInfo.Select(async queue =>
Expand Down Expand Up @@ -54,7 +59,7 @@ public async Task SendMessage(string connectionString, string queueName, AzureMe
public async Task<IList<Message>> GetMessages(string connectionString, string queueName)
{
var receiver = new MessageReceiver(connectionString, queueName, ReceiveMode.PeekLock);
var messages = await receiver.PeekAsync(_maxMessageCount);
var messages = await receiver.PeekAsync(_appSettings.QueueMessageFetchCount);
return messages.Select(msg => new Message(msg, false)).ToList();
}

Expand All @@ -63,7 +68,7 @@ public async Task<IList<Message>> GetDlqMessages(string connectionString, string
var deadletterPath = EntityNameHelper.FormatDeadLetterPath(queueName);

var receiver = new MessageReceiver(connectionString, deadletterPath, ReceiveMode.PeekLock);
var receivedMessages = await receiver.PeekAsync(_maxMessageCount);
var receivedMessages = await receiver.PeekAsync(_appSettings.QueueMessageFetchCount);
await receiver.CloseAsync();

return receivedMessages.Select(message => new Message(message, true)).ToList();
Expand All @@ -75,7 +80,7 @@ public async Task DeadletterMessage(string connectionString, string queue, Messa

while (true)
{
var messages = await receiver.ReceiveAsync(_maxMessageCount);
var messages = await receiver.ReceiveAsync(_appSettings.QueueMessageFetchCount);
if (messages == null || messages.Count == 0)
{
break;
Expand All @@ -101,7 +106,7 @@ public async Task DeleteMessage(string connectionString, string queue,

while (true)
{
var messages = await receiver.ReceiveAsync(_maxMessageCount);
var messages = await receiver.ReceiveAsync(_appSettings.QueueMessageFetchCount);
if (messages == null || messages.Count == 0)
{
break;
Expand Down Expand Up @@ -148,7 +153,7 @@ public async Task<long> PurgeMessages(string connectionString, string queue, boo
var operationTimeout = TimeSpan.FromSeconds(5);
while (true)
{
var messages = await receiver.ReceiveAsync(_maxMessageCount, operationTimeout);
var messages = await receiver.ReceiveAsync(_appSettings.QueueMessageFetchCount, operationTimeout);
if (messages == null || messages.Count == 0)
{
break;
Expand All @@ -175,7 +180,7 @@ public async Task<long> TransferDlqMessages(string connectionString, string queu
var operationTimeout = TimeSpan.FromSeconds(5);
while (true)
{
var messages = await receiver.ReceiveAsync(_maxMessageCount, operationTimeout);
var messages = await receiver.ReceiveAsync(_appSettings.QueueMessageFetchCount, operationTimeout);
if (messages == null || messages.Count == 0)
{
break;
Expand Down
21 changes: 13 additions & 8 deletions PurpleExplorer/Helpers/TopicHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ namespace PurpleExplorer.Helpers
{
public class TopicHelper : ITopicHelper
{
private int _maxMessageCount = 100;
private readonly AppSettings _appSettings;

public TopicHelper(AppSettings appSettings)
{
_appSettings = appSettings;
}

public async Task<IList<ServiceBusTopic>> GetTopicsAndSubscriptions(string connectionString)
{
IList<ServiceBusTopic> topics = new List<ServiceBusTopic>();
var client = new ManagementClient(connectionString);
var busTopics = await client.GetTopicsAsync();
var busTopics = await client.GetTopicsAsync(_appSettings.TopicListFetchCount);
await client.CloseAsync();

await Task.WhenAll(busTopics.Select(async topic =>
Expand Down Expand Up @@ -82,7 +87,7 @@ public async Task<IList<Message>> GetMessagesBySubscription(string connectionStr
var path = EntityNameHelper.FormatSubscriptionPath(topicName, subscriptionName);

var messageReceiver = new MessageReceiver(connectionString, path, ReceiveMode.PeekLock);
var subscriptionMessages = await messageReceiver.PeekAsync(_maxMessageCount);
var subscriptionMessages = await messageReceiver.PeekAsync(_appSettings.TopicMessageFetchCount);
await messageReceiver.CloseAsync();

var result = subscriptionMessages.Select(message => new Message(message, false)).ToList();
Expand All @@ -95,7 +100,7 @@ public async Task<IList<Message>> GetDlqMessages(string connectionString, string
var deadletterPath = EntityNameHelper.FormatDeadLetterPath(path);

var receiver = new MessageReceiver(connectionString, deadletterPath, ReceiveMode.PeekLock);
var receivedMessages = await receiver.PeekAsync(_maxMessageCount);
var receivedMessages = await receiver.PeekAsync(_appSettings.TopicMessageFetchCount);
await receiver.CloseAsync();

var result = receivedMessages.Select(message => new Message(message, true)).ToList();
Expand Down Expand Up @@ -131,7 +136,7 @@ public async Task DeleteMessage(string connectionString, string topicPath, strin

while (true)
{
var messages = await receiver.ReceiveAsync(_maxMessageCount);
var messages = await receiver.ReceiveAsync(_appSettings.TopicMessageFetchCount);
if (messages == null || messages.Count == 0)
{
break;
Expand Down Expand Up @@ -159,7 +164,7 @@ public async Task<long> PurgeMessages(string connectionString, string topicPath,
var operationTimeout = TimeSpan.FromSeconds(5);
while (true)
{
var messages = await receiver.ReceiveAsync(_maxMessageCount, operationTimeout);
var messages = await receiver.ReceiveAsync(_appSettings.TopicMessageFetchCount, operationTimeout);
if (messages == null || messages.Count == 0)
{
break;
Expand Down Expand Up @@ -187,7 +192,7 @@ public async Task<long> TransferDlqMessages(string connectionString, string topi
var operationTimeout = TimeSpan.FromSeconds(5);
while (true)
{
var messages = await receiver.ReceiveAsync(_maxMessageCount, operationTimeout);
var messages = await receiver.ReceiveAsync(_appSettings.TopicMessageFetchCount, operationTimeout);
if (messages == null || messages.Count == 0)
{
break;
Expand Down Expand Up @@ -244,7 +249,7 @@ public async Task DeadletterMessage(string connectionString, string topicPath, s

while (true)
{
var messages = await receiver.ReceiveAsync(_maxMessageCount);
var messages = await receiver.ReceiveAsync(_appSettings.TopicMessageFetchCount);
if (messages == null || messages.Count == 0)
{
break;
Expand Down
10 changes: 10 additions & 0 deletions PurpleExplorer/Models/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace PurpleExplorer.Models;

public class AppSettings
{
public int QueueListFetchCount { get; set; } = 100;
public int QueueMessageFetchCount { get; set; } = 100;

public int TopicListFetchCount { get; set; } = 100;
public int TopicMessageFetchCount { get; set; } = 100;
}
14 changes: 11 additions & 3 deletions PurpleExplorer/Models/AppState.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using PurpleExplorer.ViewModels;

namespace PurpleExplorer.Models
{
[DataContract]
public class AppState: IAppState
public class AppState: ViewModelBase, IAppState
{
[DataMember] public ObservableCollection<string> SavedConnectionStrings { get; set; }
[DataMember] public ObservableCollection<SavedMessage> SavedMessages { get; set; }
[DataMember]
public ObservableCollection<string> SavedConnectionStrings { get; set; }

[DataMember]
public ObservableCollection<SavedMessage> SavedMessages { get; set; }

[DataMember]
public AppSettings AppSettings { get; set; }

public AppState()
{
SavedConnectionStrings = new ObservableCollection<string>();
SavedMessages = new ObservableCollection<SavedMessage>();
AppSettings = new AppSettings();
}
}
}
2 changes: 2 additions & 0 deletions PurpleExplorer/Models/IAppState.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Collections.ObjectModel;
using PurpleExplorer.ViewModels;

namespace PurpleExplorer.Models
{
public interface IAppState
{
public ObservableCollection<string> SavedConnectionStrings { get; set; }
public ObservableCollection<SavedMessage> SavedMessages { get; set; }
public AppSettings AppSettings { get; set; }
}
}
2 changes: 1 addition & 1 deletion PurpleExplorer/Models/ServiceBusResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void AddQueues(params ServiceBusQueue[] queues)
public override bool Equals(object? obj)
{
var comparingResource = obj as ServiceBusResource;
return Name.Equals(comparingResource.Name) && CreatedTime.Equals(comparingResource.CreatedTime);
return comparingResource != null && Name.Equals(comparingResource.Name) && CreatedTime.Equals(comparingResource.CreatedTime);
}
}
}
6 changes: 5 additions & 1 deletion PurpleExplorer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Avalonia;
using Avalonia.ReactiveUI;
using Projektanker.Icons.Avalonia;
using Projektanker.Icons.Avalonia.FontAwesome;

namespace PurpleExplorer
{
Expand All @@ -16,6 +18,8 @@ public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace()
.UseReactiveUI();
.UseReactiveUI()
.WithIcons(container => container
.Register<FontAwesomeIconProvider>());
}
}
24 changes: 19 additions & 5 deletions PurpleExplorer/PurpleExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<!--Avalonia doesen't support TrimMode=link currently,but we are working on that https://github.com/AvaloniaUI/Avalonia/issues/6892 -->
<TrimMode>copyused</TrimMode>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
</PropertyGroup>
<ItemGroup>
<Folder Include="Models\" />
Expand All @@ -14,12 +18,22 @@
<AvaloniaResource Include="Assets\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.11" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="0.10.11" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.11" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.11" />
<PackageReference Include="MessageBox.Avalonia" Version="1.7.1" />
<!--This helps with theme dll-s trimming.
If you will publish your application in self-contained mode with p:PublishTrimmed=true and it will use Fluent theme Default theme will be trimmed from the output and vice versa.
https://github.com/AvaloniaUI/Avalonia/issues/5593 -->
<TrimmableAssembly Include="Avalonia.Themes.Fluent" />
<TrimmableAssembly Include="Avalonia.Themes.Default" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.14" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.14" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.14" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.14" />
<PackageReference Include="MessageBox.Avalonia" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="5.2.0" />
<PackageReference Include="Projektanker.Icons.Avalonia" Version="5.0.1" />
<PackageReference Include="Projektanker.Icons.Avalonia.FontAwesome" Version="5.0.1" />
</ItemGroup>
<ItemGroup>
<None Update="appstate.json">
Expand Down
18 changes: 18 additions & 0 deletions PurpleExplorer/Styles/CommonStyles.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="clr-namespace:Projektanker.Icons.Avalonia;assembly=Projektanker.Icons.Avalonia">
<Style Selector="Button.topButton">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Margin" Value="1,0" />
<Setter Property="BorderThickness" Value="0,0,2,0" />
</Style>
<Style Selector="Button.topButton i|Icon">
<Setter Property="Margin" Value="0,0,1,0" />
<Setter Property="Width" Value="20" />
<Setter Property="Height" Value="20" />
</Style>
<Style Selector="Button.topButton TextBlock">
<Setter Property="Margin" Value="0,1,0,0" />
</Style>
</Styles>
12 changes: 0 additions & 12 deletions PurpleExplorer/Styles/CustomStyles.xaml

This file was deleted.

Loading

0 comments on commit d50838a

Please sign in to comment.