diff --git a/ChatController/ChatKlassen/KontaktMessageBuilder.cs b/ChatController/ChatKlassen/KontaktMessageBuilder.cs index f3e860b..c08e849 100644 --- a/ChatController/ChatKlassen/KontaktMessageBuilder.cs +++ b/ChatController/ChatKlassen/KontaktMessageBuilder.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; @@ -30,7 +31,17 @@ namespace ChatController.ChatKlassen Posi = "Left"; } - ChatVisibility = Visibility.Visible; + if (IsHyperlink(message)) + { + HyperlinkVisibility = Visibility.Visible; + ChatVisibility = Visibility.Collapsed; + } + else { + ChatVisibility = Visibility.Visible; + HyperlinkVisibility = Visibility.Collapsed; + } + + SoundVisibility = Visibility.Collapsed; _pictureVisibility = Visibility.Collapsed; DokumentVisibility = Visibility.Collapsed; @@ -74,7 +85,7 @@ namespace ChatController.ChatKlassen ChatVisibility = Visibility.Collapsed; SoundVisibility = Visibility.Collapsed; - + HyperlinkVisibility = Visibility.Collapsed; DokumentVisibility = Visibility.Collapsed; _herunterladen = Visibility.Collapsed; } @@ -107,8 +118,65 @@ namespace ChatController.ChatKlassen ChatVisibility = Visibility.Collapsed; SoundVisibility = Visibility.Collapsed; _herunterladen = Visibility.Collapsed; + HyperlinkVisibility = Visibility.Collapsed; } + #region Hyperlink Detection + + private static readonly Regex UrlRegex = new Regex(@"(?#Protocol)(?:(?:ht|f)tp(?:s?)\:\/\/|~/|/)?(?#Username:Password)(?:\w+:\w+@)?(?#Subdomains)(?:(?:[-\w]+\.)+(?#TopLevel Domains)(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))(?#Port)(?::[\d]{1,5})?(?#Directories)(?:(?:(?:/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|/)+|\?|#)?(?#Query)(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?#Anchor)(?:#(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)?"); + + public static bool IsHyperlink(string word) + { + // First check to make sure the word has at least one of the characters we need to make a hyperlink + try + { + if (word.IndexOfAny(@":.\/".ToCharArray()) != -1) + { + if (Uri.IsWellFormedUriString(word, UriKind.Absolute)) + { + // The string is an Absolute URI + if (word.StartsWith("http://")) { + return true; + } + else + { + return false; + } + } + else if (UrlRegex.IsMatch(word)) + { + //hier der Bereich hin der die uri splittet wenn neben dem link auch text gesendet wird + + + Uri uri = new Uri(word, UriKind.RelativeOrAbsolute); + + if (!uri.IsAbsoluteUri) + { + // rebuild it it with http to turn it into an Absolute URI + uri = new Uri(@"http://" + word, UriKind.Absolute); + } + + if (uri.IsAbsoluteUri) + { + return true; + } + } + else + { + return false; + } + } + } + catch (Exception e) + { + return false; + } + + return false; + } + + #endregion + #region kram der sortiert werden muss //Alter Kram @@ -281,6 +349,7 @@ namespace ChatController.ChatKlassen public Visibility MainVisibility { get; set; } public Visibility ChatVisibility { get; set; } + public Visibility HyperlinkVisibility { get; set; } public Visibility LoadNextVisibility { get; set; } public object LoadObject { get; set; } diff --git a/ChatController/ChatMainControl.xaml b/ChatController/ChatMainControl.xaml index 28e9aa1..2fa5877 100644 --- a/ChatController/ChatMainControl.xaml +++ b/ChatController/ChatMainControl.xaml @@ -246,6 +246,17 @@ + + + + + + + + + + + diff --git a/ChatController/ChatMainControl.xaml.cs b/ChatController/ChatMainControl.xaml.cs index 6499687..12b86dc 100644 --- a/ChatController/ChatMainControl.xaml.cs +++ b/ChatController/ChatMainControl.xaml.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using System.Net; using System.Text; +using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Windows; @@ -31,8 +32,6 @@ namespace ChatController /// public partial class ChatMainControl : UserControl { - - private Chat _chat; private AktuellerKontakt _aktuellerKontakt; @@ -867,6 +866,12 @@ namespace ChatController #endregion - + #region link request + private void Hyperlink_OnRequestNavigate(object sender, RequestNavigateEventArgs e) + { + Process.Start(e.Uri.ToString()); + } + #endregion + } } diff --git a/ChatController/HauptKlassen/Chat.cs b/ChatController/HauptKlassen/Chat.cs index bc9e15f..ae69f33 100644 --- a/ChatController/HauptKlassen/Chat.cs +++ b/ChatController/HauptKlassen/Chat.cs @@ -242,6 +242,7 @@ namespace ChatController.HauptKlassen bix.BeginInit(); bix.UriSource = new Uri(link); bix.EndInit(); + return bix; } catch (Exception edf) @@ -1145,7 +1146,7 @@ namespace ChatController.HauptKlassen else if (d.GetDataPresent(DataFormats.Text)) { - string text = (String)d.GetData(DataFormats.Text); + string text = (string)d.GetData(DataFormats.StringFormat); SendMessage(text, groupOid); } diff --git a/ChatController/LoginControl.xaml.cs b/ChatController/LoginControl.xaml.cs index b7fe30d..684ea0b 100644 --- a/ChatController/LoginControl.xaml.cs +++ b/ChatController/LoginControl.xaml.cs @@ -28,7 +28,9 @@ namespace ChatController public event LoginDelegate OnLogin; - private string _dateiPfad = "ChatAnmeldeDaten.txt"; + private string _dateiPfad = "ChatAnmeldeDaten.txt"; //OwnChatX1253781 + + private string _merkeDaten = "MerkeChatTeilAnmeldeDaten.txt"; //OwnChatX1253782 public LoginControl() { @@ -40,33 +42,32 @@ namespace ChatController { try { +#if DEBUG + Cursor = Cursors.Wait; + + Login _login = new Login("4368658435", "ZMCKb-BckTt", "RuppelW", "ABXT32wgtruppeldiedup"); + + var x = _login.AnmeldevorgangDurchFuehren(); -//#if DEBUG -// Cursor = Cursors.Wait; + if (OnLogin != null) + { + AutosetDaten(); + if (Merken.IsChecked == true) + { + SpeichereDatenInDatei(); + } + else + { + LoescheGespeicherteDatei(); + } + OnLogin(x); + } -// Login _login = new Login("4368658435", "ZMCKb-BckTt", "RuppelW", "ABXT32wgtruppeldiedup"); - -// var x = _login.AnmeldevorgangDurchFuehren(); - -// if (OnLogin != null) -// { -// if (Merken.IsChecked == true) -// { -// SpeichereDatenInDatei(); -// } -// else -// { -// LoescheGespeicherteDatei(); -// } - -// OnLogin(x); -// } - -// Cursor = Cursors.Arrow; -//#else - if (!TextBoxKundennummer.Text.Equals("") && !TextBoxChatCode.Text.Equals("") && + Cursor = Cursors.Arrow; +#else + if (!TextBoxKundennummer.Text.Equals("") && !TextBoxChatCode.Text.Equals("") && !TextBoxBenutzerName.Text.Equals("") && !TextBoxPasswort.Password.Equals("")) { Cursor = Cursors.Wait; @@ -77,6 +78,7 @@ namespace ChatController if (OnLogin != null && x != null) { + AutosetDaten(); if (Merken.IsChecked == true) { SpeichereDatenInDatei(); @@ -99,13 +101,14 @@ namespace ChatController { MessageBox.Show("Bitte alle Felder ausfüllen!", "Info", MessageBoxButton.OK); } - //#endif +#endif } catch (Exception exception) { - MessageBox.Show("Fehler bei der Anmeldung!\n\n" + exception.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Asterisk); - + //MessageBox.Show("Fehler bei der Anmeldung!\n\n" + exception.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Asterisk); + MessageBox.Show("Fehler bei der Anmeldung. Bitte überprüfen Sie die Anmeldeinformationen.", "Info", MessageBoxButton.OK, MessageBoxImage.Asterisk); //throw; + Cursor = Cursors.Arrow; } } @@ -116,6 +119,31 @@ namespace ChatController { try { + if (File.Exists(_merkeDaten)) + { + List merkdaten = new List(); + using (StreamReader sr = new StreamReader(_merkeDaten, true)) + { + string line = ""; + + while ((line = sr.ReadLine()) != null) + { + var encodedTextBytes = Convert.FromBase64String(line); + + string plainText = Encoding.UTF8.GetString(encodedTextBytes); + + merkdaten.Add(plainText); + } + } + + if (merkdaten.Count == 2) + { + TextBoxKundennummer.Text = merkdaten[0]; + TextBoxChatCode.Text = merkdaten[1]; + } + } + + if (File.Exists(_dateiPfad)) { List daten = new List(); @@ -133,14 +161,42 @@ namespace ChatController } } - if(daten.Count == 5) { - TextBoxKundennummer.Text = daten[0]; - TextBoxChatCode.Text = daten[1]; - TextBoxBenutzerName.Text = daten[2]; - TextBoxPasswort.Password = daten[3]; - Merken.IsChecked = Convert.ToBoolean(daten[4]); + if(daten.Count == 3) { + + TextBoxBenutzerName.Text = daten[0]; + TextBoxPasswort.Password = daten[1]; + Merken.IsChecked = Convert.ToBoolean(daten[2]); } + } + } + catch (Exception e) + { + MessageBox.Show("Ups, da ist was schief gelaufen: \n" + e.Message, "Fehler", MessageBoxButton.OK); + } + } + //Kundenummer und ChatCode sollen Separat gespeichert werden + private void AutosetDaten() + { + try + { + if (!File.Exists(_merkeDaten)) + { + using (StreamWriter sw = new StreamWriter(_merkeDaten)) + { + + Encoding enc = new UTF8Encoding(); + var byt = enc.GetBytes(TextBoxKundennummer.Text); + var bytes = Convert.ToBase64String(byt); + + var byt2 = enc.GetBytes(TextBoxChatCode.Text); + var bytes2 = Convert.ToBase64String(byt2); + + sw.WriteLine(bytes); + sw.WriteLine(bytes2); + + File.SetAttributes(_merkeDaten, FileAttributes.ReadOnly); + } } } catch (Exception e) @@ -158,11 +214,11 @@ namespace ChatController { Encoding enc = new UTF8Encoding(); - var byt = enc.GetBytes(TextBoxKundennummer.Text); - var bytes = Convert.ToBase64String(byt); + //var byt = enc.GetBytes(TextBoxKundennummer.Text); + //var bytes = Convert.ToBase64String(byt); - var byt2 = enc.GetBytes(TextBoxChatCode.Text); - var bytes2 = Convert.ToBase64String(byt2); + //var byt2 = enc.GetBytes(TextBoxChatCode.Text); + //var bytes2 = Convert.ToBase64String(byt2); var byt3 = enc.GetBytes(TextBoxBenutzerName.Text); var bytes3 = Convert.ToBase64String(byt3); @@ -175,8 +231,8 @@ namespace ChatController var bytes5 = Convert.ToBase64String(byt5); - sw.WriteLine(bytes); - sw.WriteLine(bytes2); + //sw.WriteLine(bytes); + //sw.WriteLine(bytes2); sw.WriteLine(bytes3); sw.WriteLine(bytes4); sw.WriteLine(bytes5); @@ -197,6 +253,7 @@ namespace ChatController { if (File.Exists(_dateiPfad)) { + File.SetAttributes(_dateiPfad, FileAttributes.Normal); File.Delete(_dateiPfad); } } @@ -206,7 +263,7 @@ namespace ChatController } } - #endregion +#endregion } diff --git a/PrototypChat/.vs/PrototypChat/v15/.suo b/PrototypChat/.vs/PrototypChat/v15/.suo index 4800af4..5e85344 100644 Binary files a/PrototypChat/.vs/PrototypChat/v15/.suo and b/PrototypChat/.vs/PrototypChat/v15/.suo differ diff --git a/PrototypChat/MainWindow.xaml b/PrototypChat/MainWindow.xaml index 4a48a0f..fd3003c 100644 --- a/PrototypChat/MainWindow.xaml +++ b/PrototypChat/MainWindow.xaml @@ -6,7 +6,7 @@ xmlns:local="clr-namespace:ownChat" xmlns:cc="clr-namespace:ChatController;assembly=ChatController" mc:Ignorable="d" WindowStartupLocation="CenterScreen" - Title="ownChat Desktop" Height="700" Width="900" x:Name="MainView"> + Title="ownChat Desktop" Height="700" Width="900" x:Name="MainView" Closed="MainWindow_OnClosed"> diff --git a/PrototypChat/MainWindow.xaml.cs b/PrototypChat/MainWindow.xaml.cs index 7829aa1..ada16b0 100644 --- a/PrototypChat/MainWindow.xaml.cs +++ b/PrototypChat/MainWindow.xaml.cs @@ -110,22 +110,11 @@ namespace ownChat } } - - //private void ChatMainControl_OnClickContextMenuItem(String menuItem) - //{ - - //} - - //geht nicht - public void CloseWindow() + private void MainWindow_OnClosed(object sender, EventArgs e) { - CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (s, e) => - { - MessageBox.Show("Schließe mich jetzt "); - _emojiView = null; - })); + _emojiView = null; + Environment.Exit(0); } - } } diff --git a/PrototypChat/PrototypChat.csproj b/PrototypChat/PrototypChat.csproj index 6966914..f6f6aa2 100644 --- a/PrototypChat/PrototypChat.csproj +++ b/PrototypChat/PrototypChat.csproj @@ -65,7 +65,7 @@ true - true + false