diff --git a/ServiceBus98.sln b/ServiceBus98.sln new file mode 100644 index 0000000..5250d86 --- /dev/null +++ b/ServiceBus98.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35825.156 d17.13 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceBus98", "ServiceBus98\ServiceBus98.csproj", "{70EC8B33-8F08-4B6D-B386-2C2747AF61F0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {70EC8B33-8F08-4B6D-B386-2C2747AF61F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {70EC8B33-8F08-4B6D-B386-2C2747AF61F0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {70EC8B33-8F08-4B6D-B386-2C2747AF61F0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {70EC8B33-8F08-4B6D-B386-2C2747AF61F0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0D27DA3B-F216-4E9A-AD54-A25935289BA6} + EndGlobalSection +EndGlobal diff --git a/ServiceBus98/App.xaml b/ServiceBus98/App.xaml new file mode 100644 index 0000000..7286576 --- /dev/null +++ b/ServiceBus98/App.xaml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/ServiceBus98/App.xaml.cs b/ServiceBus98/App.xaml.cs new file mode 100644 index 0000000..1630536 --- /dev/null +++ b/ServiceBus98/App.xaml.cs @@ -0,0 +1,13 @@ +using System.Configuration; +using System.Data; +using System.Windows; + +namespace ServiceBus98; + +/// +/// Interaction logic for App.xaml +/// +public partial class App : Application +{ +} + diff --git a/ServiceBus98/AssemblyInfo.cs b/ServiceBus98/AssemblyInfo.cs new file mode 100644 index 0000000..cc29e7f --- /dev/null +++ b/ServiceBus98/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly:ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/ServiceBus98/MainWindow.xaml b/ServiceBus98/MainWindow.xaml new file mode 100644 index 0000000..4edbfeb --- /dev/null +++ b/ServiceBus98/MainWindow.xaml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Status: Idle + + + + + diff --git a/ServiceBus98/MainWindow.xaml.cs b/ServiceBus98/MainWindow.xaml.cs new file mode 100644 index 0000000..beae5d9 --- /dev/null +++ b/ServiceBus98/MainWindow.xaml.cs @@ -0,0 +1,75 @@ +using System.Windows; +using Azure.Messaging.ServiceBus; + +namespace ServiceBus98; + +/// +/// Interaction logic for MainWindow.xaml +/// +public partial class MainWindow : Window +{ + public MainWindow() + { + InitializeComponent(); + } + + private async void Send_Click(object sender, RoutedEventArgs e) + { + if (string.IsNullOrEmpty(ConnectionString.Text)) + { + MessageBox.Show("Enter a connection string.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + + if (string.IsNullOrEmpty(QueueName.Text)) + { + MessageBox.Show("Enter a queue name.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + + if (string.IsNullOrEmpty(Message.Text)) + { + MessageBoxResult result = MessageBox.Show("You did not enter a message. Do you want to send an empty message?", "Empty Message", MessageBoxButton.YesNo, MessageBoxImage.Question); + if (result == MessageBoxResult.Cancel) + { + return; + } + } + + try + { + StatusText.Text = "Status: Sending"; + + await using ServiceBusClient serviceBusClient = new ServiceBusClient(ConnectionString.Text); + await using ServiceBusSender serviceBusSender = serviceBusClient.CreateSender(QueueName.Text); + using ServiceBusMessageBatch messageBatch = await serviceBusSender.CreateMessageBatchAsync(); + + ServiceBusMessage serviceBusMessage = new ServiceBusMessage(Message.Text ?? string.Empty) + { + ContentType = ContentType.Text ?? "text/plain" + }; + + messageBatch.TryAddMessage(serviceBusMessage); + + await serviceBusSender.SendMessagesAsync(messageBatch); + + MessageBox.Show("Message sent successfully.", "Success", MessageBoxButton.OK, MessageBoxImage.Information); + } + + catch (Exception ex) + { + string errorMessage = ex.Message; + if (ex is ServiceBusException) + { + errorMessage = $"Service Bus returned an error. Ensure that the connection string is valid and the queue exists.\n\nAdditional Details:\n{errorMessage}"; + } + + MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error); + } + + finally + { + StatusText.Text = "Status: Idle"; + } + } +} \ No newline at end of file diff --git a/ServiceBus98/MultilineTextBox9x.xaml b/ServiceBus98/MultilineTextBox9x.xaml new file mode 100644 index 0000000..598486c --- /dev/null +++ b/ServiceBus98/MultilineTextBox9x.xaml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/ServiceBus98/MultilineTextBox9x.xaml.cs b/ServiceBus98/MultilineTextBox9x.xaml.cs new file mode 100644 index 0000000..9315bd5 --- /dev/null +++ b/ServiceBus98/MultilineTextBox9x.xaml.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace ServiceBus98 +{ + /// + /// Interaction logic for MultilineTextBox9x.xaml + /// + public partial class MultilineTextBox9x : UserControl + { + public MultilineTextBox9x() + { + InitializeComponent(); + } + + public string Text + { + get => InnerTextBox.Text; + set => InnerTextBox.Text = value; + } + } +} diff --git a/ServiceBus98/ServiceBus98.csproj b/ServiceBus98/ServiceBus98.csproj new file mode 100644 index 0000000..6ad54a6 --- /dev/null +++ b/ServiceBus98/ServiceBus98.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net8.0-windows + enable + enable + true + + + + + + + diff --git a/ServiceBus98/TextBox9x.xaml b/ServiceBus98/TextBox9x.xaml new file mode 100644 index 0000000..92e3aeb --- /dev/null +++ b/ServiceBus98/TextBox9x.xaml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + diff --git a/ServiceBus98/TextBox9x.xaml.cs b/ServiceBus98/TextBox9x.xaml.cs new file mode 100644 index 0000000..6131ddf --- /dev/null +++ b/ServiceBus98/TextBox9x.xaml.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace ServiceBus98 +{ + /// + /// Interaction logic for TextBox9x.xaml + /// + public partial class TextBox9x : UserControl + { + public TextBox9x() + { + InitializeComponent(); + } + + public string Text + { + get => InnerTextBox.Text; + set => InnerTextBox.Text = value; + } + } +}