Merge branch 'ConnectionController' of https://sourcecode.socialcoding.bosch.com/scm/~hpl2fe/polychat into ConnectionController

This commit is contained in:
SCM6WE
2021-09-23 12:57:00 +02:00
7 changed files with 35 additions and 11 deletions

View File

@@ -145,9 +145,11 @@ namespace PolyChat
private bool isInConnections(string IP) private bool isInConnections(string IP)
{ {
if (Connections.ContainsKey(IP)) return Connections.ContainsKey(IP);
return true; }
return false; public bool IsConnected(string ip)
{
return Connections.ContainsKey(ip) && Connections[ip].IsConnected();
} }
public static string getIP() public static string getIP()
@@ -195,7 +197,6 @@ namespace PolyChat
ip = ip.Substring(0, ip.Length - 4); ip = ip.Substring(0, ip.Length - 4);
Debug.WriteLine($"-{ip}"); Debug.WriteLine($"-{ip}");
Debug.WriteLine(jsonArr); Debug.WriteLine(jsonArr);
Connect(ip);
UIController.OnIncomingConnection(ip); UIController.OnIncomingConnection(ip);
UIController.OnIncomingMessages(ip, jsonArr); UIController.OnIncomingMessages(ip, jsonArr);
} }

View File

@@ -11,6 +11,7 @@ using System.Threading.Tasks;
using Windows.UI.Core; using Windows.UI.Core;
using Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
@@ -83,7 +84,7 @@ namespace PolyChat
var result = await dialog.ShowAsync(); var result = await dialog.ShowAsync();
if (result == ContentDialogResult.Primary) if (result == ContentDialogResult.Primary)
{ {
string ip = IP.GetIPfromCode(dialog.getValue()); string ip = IP.GetIPFromCode(dialog.getValue());
Controller.Connect(ip); Controller.Connect(ip);
Partners.Add(new ChatPartner( Partners.Add(new ChatPartner(
"Connecting...", "Connecting...",
@@ -136,6 +137,7 @@ namespace PolyChat
switch (type) switch (type)
{ {
case "username": case "username":
Debug.WriteLine($"! username change for {sendingPartner.Code} -> {content}");
sendingPartner.SetName(Name); sendingPartner.SetName(Name);
break; break;
default: default:
@@ -190,6 +192,7 @@ namespace PolyChat
listViewMessages.ItemsSource = selectedPartner.Messages; listViewMessages.ItemsSource = selectedPartner.Messages;
selectedPartnerName.Text = selectedPartner.Name; selectedPartnerName.Text = selectedPartner.Name;
updateNoChatSelected(); updateNoChatSelected();
if (!Controller.IsConnected(code)) Controller.Connect(code);
} }
private void OnKeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e) private void OnKeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)

View File

@@ -1,14 +1,17 @@
using SocketIOSharp.Server.Client; using SocketIOSharp.Server.Client;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace PolyChat.Models namespace PolyChat.Models
{ {
public class ChatPartner public class ChatPartner : INotifyPropertyChanged
{ {
public string Name; public string Name;
public string Code; public string Code;
public ObservableCollection<ChatMessage> Messages; public ObservableCollection<ChatMessage> Messages;
private SocketIOSocket socketIOSocket; private SocketIOSocket socketIOSocket;
public event PropertyChangedEventHandler PropertyChanged;
public ChatPartner(string name, string code, ObservableCollection<ChatMessage> messages = null) public ChatPartner(string name, string code, ObservableCollection<ChatMessage> messages = null)
{ {
@@ -20,6 +23,11 @@ namespace PolyChat.Models
public SocketIOSocket SocketIOSocket { get => socketIOSocket; set => socketIOSocket = value; } public SocketIOSocket SocketIOSocket { get => socketIOSocket; set => socketIOSocket = value; }
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public void AddMessage(ChatMessage message) public void AddMessage(ChatMessage message)
{ {
Messages.Add(message); Messages.Add(message);
@@ -28,6 +36,7 @@ namespace PolyChat.Models
public void SetName(string name) public void SetName(string name)
{ {
Name = name; Name = name;
NotifyPropertyChanged("Name");
} }
} }
} }

View File

@@ -9,8 +9,8 @@
<Identity <Identity
Name="ee2ef4f2-e61b-497a-8f0e-9fa7c90234b1" Name="ee2ef4f2-e61b-497a-8f0e-9fa7c90234b1"
Publisher="CN=HPL2FE" Publisher="CN=PatrickMarcFelix"
Version="1.0.0.0" /> Version="0.1.0.0" />
<mp:PhoneIdentity PhoneProductId="ee2ef4f2-e61b-497a-8f0e-9fa7c90234b1" PhonePublisherId="00000000-0000-0000-0000-000000000000"/> <mp:PhoneIdentity PhoneProductId="ee2ef4f2-e61b-497a-8f0e-9fa7c90234b1" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

View File

@@ -17,7 +17,15 @@
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WindowsXamlEnableOverview>true</WindowsXamlEnableOverview> <WindowsXamlEnableOverview>true</WindowsXamlEnableOverview>
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled> <AppxPackageSigningEnabled>False</AppxPackageSigningEnabled>
<GenerateAppInstallerFile>False</GenerateAppInstallerFile>
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
<GenerateTestArtifacts>True</GenerateTestArtifacts>
<AppxBundle>Always</AppxBundle>
<AppxBundlePlatforms>x86</AppxBundlePlatforms>
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
<PackageCertificateThumbprint>6B0D12FC4E83C6F6997C60706A04799ED44B7E56</PackageCertificateThumbprint>
<AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@@ -195,6 +203,9 @@
<Version>5.0.2</Version> <Version>5.0.2</Version>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="PolyChat_TemporaryKey.pfx" />
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' "> <PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion> <VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup> </PropertyGroup>

View File

@@ -7,7 +7,7 @@ namespace PolyChat.Util
{ {
private const string REGEX_IP = @"^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$"; private const string REGEX_IP = @"^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$";
public static string GetIPfromCode(string code) public static string GetIPFromCode(string code)
{ {
return code; return code;
} }

View File

@@ -29,7 +29,7 @@ namespace PolyChat.Views
private void OnKeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e) private void OnKeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
{ {
if (!IP.ValidateIP(IP.GetIPfromCode(input.Text))) if (!IP.ValidateIP(IP.GetIPFromCode(input.Text)))
{ {
textSuccess.Visibility = Visibility.Collapsed; textSuccess.Visibility = Visibility.Collapsed;
textError.Visibility = Visibility.Visible; textError.Visibility = Visibility.Visible;