diff --git a/PolyChat/Controller.cs b/PolyChat/Controller.cs
index 8a48a6d..5088c48 100644
--- a/PolyChat/Controller.cs
+++ b/PolyChat/Controller.cs
@@ -8,6 +8,10 @@ using SocketIOSharp.Server.Client;
namespace PolyChat
{
+
+ // 10.1.211.26 Marc
+ // 10.1.218.90 Felix
+ // 10.4.141.77 Pat
class Controller
{
// Constants
@@ -28,10 +32,6 @@ namespace PolyChat
UIController = uiController;
OwnIP = getIP();
Serve();
-
- //Connect("10.1.211.26"); // Marc
- //Connect("10.1.218.90"); // Felix
- //Connect("10.4.141.77"); // Pat
}
public void Connect(string ip)
@@ -43,9 +43,7 @@ namespace PolyChat
private void Serve()
{
Debug.WriteLine("--- Controller.Serve ---");
- SocketIOServer server = new SocketIOServer(new SocketIOServerOption(
- PORT
- ));
+ SocketIOServer server = new SocketIOServer(new SocketIOServerOption(PORT));
server.Start();
Debug.WriteLine("Port " + server.Option.Port);
Debug.WriteLine("Path " + server.Option.Path);
@@ -95,7 +93,7 @@ namespace PolyChat
Connections.Remove(IP);
UIController.OnChatPartnerDeleted(IP);
if(!wasConnected)
- UIController.ShowConnectionError(IP, $"Connection to {IP} failed...");
+ UIController.ShowConnectionError("Connection close", IP, $"Connection to {IP} failed...");
}
public string getIP()
diff --git a/PolyChat/MainPage.xaml.cs b/PolyChat/MainPage.xaml.cs
index 0dc0f43..1eccd36 100644
--- a/PolyChat/MainPage.xaml.cs
+++ b/PolyChat/MainPage.xaml.cs
@@ -36,21 +36,31 @@ namespace PolyChat
updateSendButtonEnabled();
}
- public async void ShowConnectionError(string code, string message)
+ public async void ShowConnectionError(string code, string heading, string message)
{
- await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
+ await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
- ConnectionFailedDialog dialog = new ConnectionFailedDialog(message);
- var result = await dialog.ShowAsync();
- if (result == ContentDialogResult.Primary)
- {
- Controller.Connect(code);
- Partners.Add(new ChatPartner(
- "Connecting...",
- code
- ));
- updateNoChatsPlaceholder();
- }
+ Dialog dialog = new Dialog(
+ Dialog.TYPE_ERROR,
+ heading,
+ message,
+ new DialogButton(
+ "Retry",
+ () =>
+ {
+ Controller.Connect(code);
+ Partners.Add(new ChatPartner(
+ "Connecting...",
+ code
+ ));
+ updateNoChatsPlaceholder();
+ }
+ ),
+ new DialogButton(
+ "Ignore",
+ () => { /* do nothing */ }
+ )
+ );
});
}
@@ -58,7 +68,7 @@ namespace PolyChat
public void OnSendMessage(object sender = null, RoutedEventArgs e = null)
{
- selectedPartner.AddMessage(new ChatMessage(username, "message" , inputSend.Text));
+ selectedPartner.AddMessage(new ChatMessage(username, "message", inputSend.Text));
Controller.SendMessage(selectedPartner.Code, "message", inputSend.Text);
// clear input
inputSend.Text = "";
diff --git a/PolyChat/Models/DialogButton.cs b/PolyChat/Models/DialogButton.cs
new file mode 100644
index 0000000..959e5c2
--- /dev/null
+++ b/PolyChat/Models/DialogButton.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PolyChat.Models
+{
+ public class DialogButton
+ {
+ public string Text;
+ public Action Action;
+
+ public DialogButton(string text, Action action)
+ {
+ Text = text;
+ Action = action;
+ }
+ }
+}
diff --git a/PolyChat/PolyChat.csproj b/PolyChat/PolyChat.csproj
index 3f479cf..418a809 100644
--- a/PolyChat/PolyChat.csproj
+++ b/PolyChat/PolyChat.csproj
@@ -119,6 +119,7 @@
App.xaml
+
@@ -130,8 +131,8 @@
-
- ConnectionFailedDialog.xaml
+
+ Dialog.xaml
EditUsernameDialog.xaml
@@ -164,7 +165,7 @@
MSBuild:Compile
Designer
-
+
MSBuild:Compile
Designer
diff --git a/PolyChat/Views/ConnectionFailedDialog.xaml.cs b/PolyChat/Views/ConnectionFailedDialog.xaml.cs
deleted file mode 100644
index 1c09a8f..0000000
--- a/PolyChat/Views/ConnectionFailedDialog.xaml.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using PolyChat.Models;
-using PolyChat.Util;
-using System;
-using System.Collections.ObjectModel;
-using System.Linq;
-using Windows.UI.Popups;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Controls;
-using Windows.UI.Xaml.Media;
-
-// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
-
-namespace PolyChat.Views
-{
- ///
- /// An empty page that can be used on its own or navigated to within a Frame.
- ///
- public sealed partial class ConnectionFailedDialog : ContentDialog
- {
- public ConnectionFailedDialog(string message)
- {
- this.InitializeComponent();
- textError.Text = message;
- }
- }
-}
diff --git a/PolyChat/Views/ConnectionFailedDialog.xaml b/PolyChat/Views/Dialog.xaml
similarity index 59%
rename from PolyChat/Views/ConnectionFailedDialog.xaml
rename to PolyChat/Views/Dialog.xaml
index fa8916e..bc60eb8 100644
--- a/PolyChat/Views/ConnectionFailedDialog.xaml
+++ b/PolyChat/Views/Dialog.xaml
@@ -1,17 +1,20 @@
-
-
+
+
diff --git a/PolyChat/Views/Dialog.xaml.cs b/PolyChat/Views/Dialog.xaml.cs
new file mode 100644
index 0000000..f342693
--- /dev/null
+++ b/PolyChat/Views/Dialog.xaml.cs
@@ -0,0 +1,70 @@
+using PolyChat.Models;
+using PolyChat.Util;
+using System;
+using System.Collections.ObjectModel;
+using System.Linq;
+using Windows.Foundation;
+using Windows.UI.Core;
+using Windows.UI.Popups;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Media;
+
+// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
+
+namespace PolyChat.Views
+{
+ ///
+ /// An empty page that can be used on its own or navigated to within a Frame.
+ ///
+ public sealed partial class Dialog : ContentDialog
+ {
+ public const string TYPE_ERROR = "error";
+ public const string TYPE_SUCCESS = "success";
+ private Action Primary;
+ private Action Secondary;
+ public Dialog(string type, string header, string message, DialogButton primary, DialogButton secondary)
+ {
+ this.InitializeComponent();
+ Title = header;
+ setType(type, message);
+ PrimaryButtonText = primary.Text;
+ SecondaryButtonText = secondary.Text;
+ // TODO: use event handlers and asign actions here
+ Primary = primary.Action;
+ Secondary = secondary.Action;
+ // show
+ ShowDialogAsync();
+ }
+
+ private void setType(string type, string message)
+ {
+ switch (type)
+ {
+ case TYPE_ERROR:
+ textError.Text = message;
+ textError.Visibility = Visibility.Visible;
+ break;
+ case TYPE_SUCCESS:
+ textSuccess.Text = message;
+ textSuccess.Visibility = Visibility.Visible;
+ break;
+ }
+ }
+
+ private async void ShowDialogAsync()
+ {
+ await ShowAsync();
+ }
+
+ private void OnPrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
+ {
+ Primary();
+ }
+
+ private void OnSecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
+ {
+ Secondary();
+ }
+ }
+}