Skip to content

Commit

Permalink
V16 - Small improvements (#70)
Browse files Browse the repository at this point in the history
* Package upgrade & code cleanup

* Small improvements
  • Loading branch information
armannaj authored Dec 7, 2022
1 parent 22878e6 commit 557300b
Show file tree
Hide file tree
Showing 40 changed files with 1,585 additions and 1,626 deletions.
47 changes: 23 additions & 24 deletions PurpleExplorer/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,35 @@
using ReactiveUI;
using Splat;

namespace PurpleExplorer
namespace PurpleExplorer;

public class App : Application
{
public class App : Application
public override void Initialize()
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
AvaloniaXamlLoader.Load(this);
}

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

var suspension = new AutoSuspendHelper(ApplicationLifetime);
RxApp.SuspensionHost.CreateNewAppState = () => new AppState();
RxApp.SuspensionHost.SetupDefaultSuspendResume(new NewtonsoftJsonSuspensionDriver(appStatePath));
suspension.OnFrameworkInitializationCompleted();
var state = RxApp.SuspensionHost.GetAppState<AppState>();
var suspension = new AutoSuspendHelper(ApplicationLifetime);
RxApp.SuspensionHost.CreateNewAppState = () => new AppState();
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));
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();
}
new MainWindow { DataContext = new MainWindowViewModel() }.Show();
base.OnFrameworkInitializationCompleted();
}
}
53 changes: 27 additions & 26 deletions PurpleExplorer/Helpers/AppVersionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,35 @@
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace PurpleExplorer.Services
namespace PurpleExplorer.Helpers;

public static class AppVersionHelper
{
public static class AppVersionHelper
public static async Task<GithubRelease> GetLatestRelease()
{
public static async Task<GithubRelease> GetLatestRelease()
{
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Add("User-Agent", "Application");
var response =
await httpClient.GetAsync(
"https://api.github.com/repos/telstrapurple/PurpleExplorer/releases/latest");
var content = await response.Content.ReadAsStringAsync();
var githubRelease = JsonConvert.DeserializeObject<GithubRelease>(content);
return githubRelease;
}
}
using var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("User-Agent", "Application");
var response =
await httpClient.GetAsync(
"https://api.github.com/repos/telstrapurple/PurpleExplorer/releases/latest");
var content = await response.Content.ReadAsStringAsync();
var githubRelease = JsonConvert.DeserializeObject<GithubRelease>(content);
return githubRelease;
}
}

public class GithubRelease
{
public int id { get; set; }
public string url { get; set; }
public string html_url { get; set; }
public string tag_name { get; set; }
public string name { get; set; }
public DateTime created_at { get; set; }
public DateTime published_at { get; set; }
public string body { get; set; }
}
public class GithubRelease
{
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("url")]
public string Url { get; set; }
[JsonProperty("html_url")]
public string HtmlUrl { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("created_at")]
public DateTime CreatedAt { get; set; }
[JsonProperty("published_at")]
public DateTime PublishedAt { get; set; }
}
80 changes: 37 additions & 43 deletions PurpleExplorer/Helpers/BaseHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,53 @@
using Microsoft.Azure.ServiceBus.Primitives;
using PurpleExplorer.Models;

namespace PurpleExplorer.Helpers
{
public class BaseHelper
{
public BaseHelper()
{
}
namespace PurpleExplorer.Helpers;

protected ManagementClient GetManagementClient(ServiceBusConnectionString connectionString)
public abstract class BaseHelper
{
protected ManagementClient GetManagementClient(ServiceBusConnectionString connectionString)
{
if (connectionString.UseManagedIdentity)
{
if (connectionString.UseManagedIdentity)
{
var tokenProvider = GetTokenProvider(connectionString);
return new ManagementClient(connectionString.ConnectionString, tokenProvider);
}
else
{
return new ManagementClient(connectionString.ConnectionString);
}
var tokenProvider = GetTokenProvider(connectionString);
return new ManagementClient(connectionString.ConnectionString, tokenProvider);
}

protected TokenProvider GetTokenProvider(ServiceBusConnectionString connectionString)
else
{
if (connectionString.UseManagedIdentity)
{
return TokenProvider.CreateManagedIdentityTokenProvider();
}
else
{
throw new NotImplementedException("Unknown token provider.");
}
return new ManagementClient(connectionString.ConnectionString);
}
}

protected MessageReceiver GetMessageReceiver(ServiceBusConnectionString connectionString, string path, ReceiveMode receiveMode)
private TokenProvider GetTokenProvider(ServiceBusConnectionString connectionString)
{
if (connectionString.UseManagedIdentity)
{
return connectionString.UseManagedIdentity
? new MessageReceiver(connectionString.ConnectionString, path, GetTokenProvider(connectionString), receiveMode: receiveMode)
: new MessageReceiver(connectionString.ConnectionString, path, receiveMode);
return TokenProvider.CreateManagedIdentityTokenProvider();
}

protected TopicClient GetTopicClient(ServiceBusConnectionString connectionString, string path)
else
{
return connectionString.UseManagedIdentity
? new TopicClient(connectionString.ConnectionString, path, GetTokenProvider(connectionString))
: new TopicClient(connectionString.ConnectionString, path);
throw new NotImplementedException("Unknown token provider.");
}
}

protected QueueClient GetQueueClient(ServiceBusConnectionString connectionString, string queueName)
{
return connectionString.UseManagedIdentity
? new QueueClient(connectionString.ConnectionString, queueName, GetTokenProvider(connectionString))
: new QueueClient(connectionString.ConnectionString, queueName);
}
protected MessageReceiver GetMessageReceiver(ServiceBusConnectionString connectionString, string path, ReceiveMode receiveMode)
{
return connectionString.UseManagedIdentity
? new MessageReceiver(connectionString.ConnectionString, path, GetTokenProvider(connectionString), receiveMode: receiveMode)
: new MessageReceiver(connectionString.ConnectionString, path, receiveMode);
}
}

protected TopicClient GetTopicClient(ServiceBusConnectionString connectionString, string path)
{
return connectionString.UseManagedIdentity
? new TopicClient(connectionString.ConnectionString, path, GetTokenProvider(connectionString))
: new TopicClient(connectionString.ConnectionString, path);
}

protected QueueClient GetQueueClient(ServiceBusConnectionString connectionString, string queueName)
{
return connectionString.UseManagedIdentity
? new QueueClient(connectionString.ConnectionString, queueName, GetTokenProvider(connectionString))
: new QueueClient(connectionString.ConnectionString, queueName);
}
}
23 changes: 11 additions & 12 deletions PurpleExplorer/Helpers/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using AzureMessage = Microsoft.Azure.ServiceBus.Message;

namespace PurpleExplorer.Helpers
namespace PurpleExplorer.Helpers;

public static class Extensions
{
public static class Extensions
public static AzureMessage CloneMessage(this AzureMessage original)
{
public static AzureMessage CloneMessage(this AzureMessage original)
return new AzureMessage
{
return new AzureMessage
{
Body = original.Body,
Label = original.Label,
To = original.To,
SessionId = original.SessionId,
ContentType = original.ContentType
};
}
Body = original.Body,
Label = original.Label,
To = original.To,
SessionId = original.SessionId,
ContentType = original.ContentType
};
}
}
29 changes: 14 additions & 15 deletions PurpleExplorer/Helpers/IQueueHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
using Message = PurpleExplorer.Models.Message;
using AzureMessage = Microsoft.Azure.ServiceBus.Message;

namespace PurpleExplorer.Helpers
namespace PurpleExplorer.Helpers;

public interface IQueueHelper
{
public interface IQueueHelper
{
Task<IList<ServiceBusQueue>> GetQueues(ServiceBusConnectionString connectionString);
public Task SendMessage(ServiceBusConnectionString connectionString, string topicPath, string content);
public Task SendMessage(ServiceBusConnectionString connectionString, string topicPath, AzureMessage message);
Task<IList<Message>> GetMessages(ServiceBusConnectionString connectionString, string queueName);
Task<IList<Message>> GetDlqMessages(ServiceBusConnectionString connectionString, string queueName);
Task DeadletterMessage(ServiceBusConnectionString connectionString, string queue, Message message);
Task DeleteMessage(ServiceBusConnectionString connectionString, string queue,
Message message, bool isDlq);
Task ResubmitDlqMessage(ServiceBusConnectionString connectionString, string queue, Message message);
Task<long> PurgeMessages(ServiceBusConnectionString connectionString, string queue, bool isDlq);
Task<long> TransferDlqMessages(ServiceBusConnectionString connectionString, string queue);
}
Task<IList<ServiceBusQueue>> GetQueues(ServiceBusConnectionString connectionString);
public Task SendMessage(ServiceBusConnectionString connectionString, string topicPath, string content);
public Task SendMessage(ServiceBusConnectionString connectionString, string topicPath, AzureMessage message);
Task<IList<Message>> GetMessages(ServiceBusConnectionString connectionString, string queueName);
Task<IList<Message>> GetDlqMessages(ServiceBusConnectionString connectionString, string queueName);
Task DeadletterMessage(ServiceBusConnectionString connectionString, string queue, Message message);
Task DeleteMessage(ServiceBusConnectionString connectionString, string queue,
Message message, bool isDlq);
Task ResubmitDlqMessage(ServiceBusConnectionString connectionString, string queue, Message message);
Task<long> PurgeMessages(ServiceBusConnectionString connectionString, string queue, bool isDlq);
Task<long> TransferDlqMessages(ServiceBusConnectionString connectionString, string queue);
}
39 changes: 19 additions & 20 deletions PurpleExplorer/Helpers/ITopicHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@
using PurpleExplorer.Models;
using AzureMessage = Microsoft.Azure.ServiceBus.Message;

namespace PurpleExplorer.Helpers
namespace PurpleExplorer.Helpers;

public interface ITopicHelper
{
public interface ITopicHelper
{
public Task<NamespaceInfo> GetNamespaceInfo(ServiceBusConnectionString connectionString);
public Task<IList<ServiceBusTopic>> GetTopicsAndSubscriptions(ServiceBusConnectionString connectionString);
public Task<ServiceBusTopic> GetTopic(ServiceBusConnectionString connectionString, string topicPath, bool retrieveSubscriptions);
public Task<IList<ServiceBusSubscription>> GetSubscriptions(ServiceBusConnectionString connectionString, string topicPath);
public Task<ServiceBusSubscription> GetSubscription(ServiceBusConnectionString connectionString, string topicPath, string subscriptionName);
public Task<IList<Message>> GetDlqMessages(ServiceBusConnectionString connectionString, string topic, string subscription);
public Task<IList<Models.Message>> GetMessagesBySubscription(ServiceBusConnectionString connectionString, string topicName, string subscriptionName);
public Task SendMessage(ServiceBusConnectionString connectionString, string topicPath, string content);
public Task SendMessage(ServiceBusConnectionString connectionString, string topicPath, AzureMessage message);
public Task DeleteMessage(ServiceBusConnectionString connectionString, string topicPath, string subscriptionPath, Message message, bool isDlq);
public Task<long> PurgeMessages(ServiceBusConnectionString connectionString, string topicPath, string subscriptionPath, bool isDlq);
public Task<long> TransferDlqMessages(ServiceBusConnectionString connectionString, string topicPath, string subscriptionPath);
public Task ResubmitDlqMessage(ServiceBusConnectionString connectionString, string topicPath, string subscriptionPath,
Message message);
public Task DeadletterMessage(ServiceBusConnectionString connectionString, string topicPath, string subscriptionPath,
Message message);
}
public Task<NamespaceInfo> GetNamespaceInfo(ServiceBusConnectionString connectionString);
public Task<IList<ServiceBusTopic>> GetTopicsAndSubscriptions(ServiceBusConnectionString connectionString);
public Task<ServiceBusTopic> GetTopic(ServiceBusConnectionString connectionString, string topicPath, bool retrieveSubscriptions);
public Task<IList<ServiceBusSubscription>> GetSubscriptions(ServiceBusConnectionString connectionString, string topicPath);
public Task<ServiceBusSubscription> GetSubscription(ServiceBusConnectionString connectionString, string topicPath, string subscriptionName);
public Task<IList<Message>> GetDlqMessages(ServiceBusConnectionString connectionString, string topic, string subscription);
public Task<IList<Models.Message>> GetMessagesBySubscription(ServiceBusConnectionString connectionString, string topicName, string subscriptionName);
public Task SendMessage(ServiceBusConnectionString connectionString, string topicPath, string content);
public Task SendMessage(ServiceBusConnectionString connectionString, string topicPath, AzureMessage message);
public Task DeleteMessage(ServiceBusConnectionString connectionString, string topicPath, string subscriptionPath, Message message, bool isDlq);
public Task<long> PurgeMessages(ServiceBusConnectionString connectionString, string topicPath, string subscriptionPath, bool isDlq);
public Task<long> TransferDlqMessages(ServiceBusConnectionString connectionString, string topicPath, string subscriptionPath);
public Task ResubmitDlqMessage(ServiceBusConnectionString connectionString, string topicPath, string subscriptionPath,
Message message);
public Task DeadletterMessage(ServiceBusConnectionString connectionString, string topicPath, string subscriptionPath,
Message message);
}
Loading

0 comments on commit 557300b

Please sign in to comment.