From 588ad7bba2f45a1a39247d6a8a7751a1c4b79a71 Mon Sep 17 00:00:00 2001 From: Waldi Date: Tue, 7 Nov 2017 11:56:29 +0100 Subject: [PATCH 1/3] Anpassungen --- ChatController/ChatMainControl.xaml | 6 +++--- ChatController/ChatMainControl.xaml.cs | 4 ++++ ChatController/HauptKlassen/Chat.cs | 2 +- PrototypChat/MainWindow.xaml.cs | 3 +++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ChatController/ChatMainControl.xaml b/ChatController/ChatMainControl.xaml index e8850f3..c044845 100644 --- a/ChatController/ChatMainControl.xaml +++ b/ChatController/ChatMainControl.xaml @@ -124,15 +124,15 @@ - + - + - + diff --git a/ChatController/ChatMainControl.xaml.cs b/ChatController/ChatMainControl.xaml.cs index 383f8a6..ff42e37 100644 --- a/ChatController/ChatMainControl.xaml.cs +++ b/ChatController/ChatMainControl.xaml.cs @@ -86,6 +86,8 @@ namespace ChatController HorcheAlleGruppenNachrichten(); LeseMessageInfoAusDatei(); + + Clientlist.Items.Refresh(); } public AktuellerKontakt GetAktuellenKontakt() @@ -1040,6 +1042,8 @@ namespace ChatController } } } + + } #endregion diff --git a/ChatController/HauptKlassen/Chat.cs b/ChatController/HauptKlassen/Chat.cs index 2c7daf2..0d2054d 100644 --- a/ChatController/HauptKlassen/Chat.cs +++ b/ChatController/HauptKlassen/Chat.cs @@ -1409,7 +1409,7 @@ namespace ChatController.HauptKlassen switch (jsonDatentyp.result) { - case "0": MessageBox.Show("Syncanforderung wurde für fünf Minuten in der Zukunft hinterlegt.", "Fehler", MessageBoxButton.OK); return true;// gebe grünes licht für Aktualieserung des Chattes / Bei Invalid access ChatMaincontroll Schließen + case "0": /*MessageBox.Show("Syncanforderung wurde für fünf Minuten in der Zukunft hinterlegt.", "Info", MessageBoxButton.OK);*/ return true;// gebe grünes licht für Aktualieserung des Chattes / Bei Invalid access ChatMaincontroll Schließen break; case "11": MessageBox.Show("Kundennummer unbekannt.\nDer Chat wird jetzt geschlossen", "Fehler", MessageBoxButton.OK); return false; //rausschmeißen ?! break; diff --git a/PrototypChat/MainWindow.xaml.cs b/PrototypChat/MainWindow.xaml.cs index de80f87..440ed65 100644 --- a/PrototypChat/MainWindow.xaml.cs +++ b/PrototypChat/MainWindow.xaml.cs @@ -117,6 +117,9 @@ namespace ownChat //// Environment.Exit(0); //LoginMaske newLogin = new LoginMaske(); //newLogin.Show(); + + ChatMainControl.SpeichereMessageInfoInDatei(); + Environment.Exit(0); } private void ChatMainControl_OnOnClose() From c6310e192349000f7704b7f68eee0ba0a99db141 Mon Sep 17 00:00:00 2001 From: Waldi Date: Thu, 9 Nov 2017 12:20:03 +0100 Subject: [PATCH 2/3] update --- ChatController/ChatMainControl.xaml.cs | 97 ++++++++++++++------------ ChatController/HauptKlassen/Chat.cs | 52 +++++++++++++- 2 files changed, 100 insertions(+), 49 deletions(-) diff --git a/ChatController/ChatMainControl.xaml.cs b/ChatController/ChatMainControl.xaml.cs index ff42e37..1a64989 100644 --- a/ChatController/ChatMainControl.xaml.cs +++ b/ChatController/ChatMainControl.xaml.cs @@ -33,7 +33,7 @@ namespace ChatController /// public partial class ChatMainControl : UserControl { - #region Vokabeln :) + #region Vokabeln private Chat _chat; private AktuellerKontakt _aktuellerKontakt; @@ -43,9 +43,7 @@ namespace ChatController private IOrderedEnumerable _Orderedmessagelist; private IOrderedEnumerable _kontaktlist; - - private readonly List _messagelist = new List(); - + private ChatDatenUebergabe _chatDaten; private bool scrollPrueferAktivieren = false; @@ -155,12 +153,15 @@ namespace ChatController doSync = _chat.DoSynchronisation(_chatDaten.ApiKey, _chatDaten.Kundennummer); if (doSync) - { + { + SpeichereMessageInfoInDatei(); var aktuelleGruppen = _chat.GruppenAktuallisieren(); var x = _chat.GroupklassenAktuallisieren(aktuelleGruppen); _kontaktlist = x; + + LeseMessageInfoAusDatei(); Dispatcher.BeginInvoke( DispatcherPriority.Normal, @@ -459,7 +460,6 @@ namespace ChatController _chat.SendMessage(Chatbox.Text, kontakt.GroupId); - //UebergebeNachrichtAnKontaktList(Chatbox.Text); Chatbox.Text = ""; if (Chatbox.Text.Equals("")) @@ -505,8 +505,6 @@ namespace ChatController } //hier bereich wie Dokumentieren - - } private void Chatbox_OnKeyDownHandler(object sender, KeyEventArgs e) @@ -527,8 +525,7 @@ namespace ChatController _chat.SendMessage(Chatbox.Text, kontakt.GroupId); - //UebergebeNachrichtAnKontaktList(Chatbox.Text); - + Chatbox.Text = ""; } @@ -551,36 +548,6 @@ namespace ChatController } } - private void UebergebeNachrichtAnKontaktList(string nachricht) - { - try - { - var aktuellerKontakt = (AktuellerKontakt)AktChatUser.Items[0]; - - foreach (var liste in _kontaktlist) - { - if (liste.GroupId == aktuellerKontakt.GroupId) - { - liste.ReceiveMs = nachricht; - - //var clientZone = TimeZoneInfo.Local; - - var x = DateTime.Now; - - //var timeformated = TimeZoneInfo.ConvertTimeToUtc(x); - - liste.TimeStamp = x; - - liste.SetzeGelesen = 0; - } - } - CollectionViewSource.GetDefaultView(Clientlist.Items).Refresh(); - } - catch (Exception e) - { - //einfach ignorieren - } - } #endregion #region Add Emoji To ChatBox @@ -1004,8 +971,8 @@ namespace ChatController } #endregion - - #region speichern sowie lesen der MessageSyncDatei / stylezwecke + + #region speichern sowie lesen der MessageSyncDatei / stylezwecke (OwnChat only) public void SpeichereMessageInfoInDatei() { List aa = new List(); @@ -1041,11 +1008,49 @@ namespace ChatController } } } - } - - + } } - + #endregion + + #region Speichern Und LEsen Der MesageSyncDatei (Bewoplaner only) + + public List UebergebeMessageInfoDatenFuerDb() + { + List < KontaktlistBuilder > aa = new List(); + + Clientlist.Items.Refresh(); + + foreach (var item in Clientlist.Items) + { + var kontakt = item as KontaktlistBuilder; + + if (kontakt != null && kontakt.SetzeGelesen == 0 && !kontakt.ReceiveMs.Equals("")) + { + aa.Add(kontakt); + } + } + + return aa; + } + + public void ErhalteMessageInfoVonDb(Dictionary liste) + { + if (liste != null) + { + foreach (var kon in _kontaktlist) + { + foreach (var item in liste) + { + if (kon.GroupId == item.Key) + { + kon.SetzeGelesen = 0; + } + } + } + } + } + + #endregion } } diff --git a/ChatController/HauptKlassen/Chat.cs b/ChatController/HauptKlassen/Chat.cs index 0d2054d..cafcfb6 100644 --- a/ChatController/HauptKlassen/Chat.cs +++ b/ChatController/HauptKlassen/Chat.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Drawing; +using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.IO; using System.Linq; @@ -19,6 +20,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using Application = System.Windows.Forms.Application; using Clipboard = System.Windows.Forms.Clipboard; +using Color = System.Drawing.Color; using ContextMenu = System.Windows.Controls.ContextMenu; using DataFormats = System.Windows.Forms.DataFormats; using Image = System.Windows.Controls.Image; @@ -950,9 +952,53 @@ namespace ChatController.HauptKlassen string filename = Path.GetFileName(file); - - SendMediaMessage(filename, kontakt.GroupId, mdatei); - + //Medium auflösung auf 80 % vom original setzen + //Image x = (Bitmap)((new ImageConverter()).ConvertFrom(mdatei)); + + // image wieder in byte[] umwandeln und übergeben + if (ImageExtensions.Contains(Path.GetExtension(filename).ToUpperInvariant())){ + var scaledImage = ScaleImage(mdatei); + + SendMediaMessage(filename, kontakt.GroupId, scaledImage); + } + else + { + SendMediaMessage(filename, kontakt.GroupId, mdatei); + } + + } + + private byte[] ScaleImage(byte[] mdatei) + { + try + { + MemoryStream ms = new MemoryStream(mdatei); + System.Drawing.Image Image = System.Drawing.Image.FromStream(ms); + + int width = (int) (Image.Width / 100 * 80); + int height = (int) (Image.Height / 100 * 80); + System.Drawing.Bitmap bmpScaled = new System.Drawing.Bitmap(Image); + + using (Graphics gr = Graphics.FromImage(Image)) + { + gr.Clear(Color.Transparent); + + // This is said to give best quality when resizing images + gr.InterpolationMode = InterpolationMode.Default; // InterpolationMode.HighQualityBicubic; + + gr.DrawImage(bmpScaled, 0, 0, width, height); + } + + ImageConverter converter = new ImageConverter(); + byte[] imageData = (byte[]) converter.ConvertTo(bmpScaled, typeof(byte[])); + + return imageData; + } + catch (Exception e) + { + MessageBox.Show(e.Message, "Fehler"); + return mdatei; + } } private static byte[] ReadFully(Stream stream) From 8188c3e428f87b1c4575035d05b43b0c50eaa89e Mon Sep 17 00:00:00 2001 From: Waldi Date: Fri, 10 Nov 2017 11:41:09 +0100 Subject: [PATCH 3/3] =?UTF-8?q?marginales=20sch=C3=B6nheits=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChatController/ChatMainControl.xaml.cs | 14 ++++++-------- ChatController/HauptKlassen/Chat.cs | 17 +++++++++++------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/ChatController/ChatMainControl.xaml.cs b/ChatController/ChatMainControl.xaml.cs index 1a64989..4663b24 100644 --- a/ChatController/ChatMainControl.xaml.cs +++ b/ChatController/ChatMainControl.xaml.cs @@ -199,11 +199,10 @@ namespace ChatController { if(Clientlist.SelectedItem != null) { - - StartWaiting(); + // StartWaiting(); Cursor = Cursors.Wait; - scrollPrueferAktivieren = false; + scrollPrueferAktivieren = false; Chat.ItemsSource = null; AktChatUser.Items.Clear(); @@ -221,24 +220,23 @@ namespace ChatController AktChatUser.Items.Add(aktuellerKontakt); _aktuellerKontakt = aktuellerKontakt; - var x = _chat.LadeChatNachrichtenVomKontakt(aktuellerKontakt); + var x = _chat.LadeChatNachrichtenVomKontakt(aktuellerKontakt); Chat.ItemsSource = x; Chat.Items.MoveCurrentToLast(); Chat.ScrollIntoView(Chat.Items.CurrentItem); - + Chat.ContextMenu = _chat.ErstelleKontextMenue(); SetContextHandler(); scrollPrueferAktivieren = true; - + HorcheAktivNachNachrichten(); Cursor = Cursors.Arrow; - EndWaiting(); + // EndWaiting(); } } - #endregion #region Context Menue diff --git a/ChatController/HauptKlassen/Chat.cs b/ChatController/HauptKlassen/Chat.cs index cafcfb6..639dce1 100644 --- a/ChatController/HauptKlassen/Chat.cs +++ b/ChatController/HauptKlassen/Chat.cs @@ -983,8 +983,8 @@ namespace ChatController.HauptKlassen { gr.Clear(Color.Transparent); - // This is said to give best quality when resizing images - gr.InterpolationMode = InterpolationMode.Default; // InterpolationMode.HighQualityBicubic; + // falls jemand mekert, muss die intergedönse erhöht werden + gr.InterpolationMode = InterpolationMode.NearestNeighbor; // InterpolationMode.HighQualityBicubic; gr.DrawImage(bmpScaled, 0, 0, width, height); } @@ -1329,7 +1329,10 @@ namespace ChatController.HauptKlassen form.StartPosition = FormStartPosition.CenterScreen; form.Size = imgbit.Size; form.MinimumSize = new Size(150,150); - form.MaximumSize = new Size(500,500); + + var width = (int)Math.Round(System.Windows.SystemParameters.PrimaryScreenWidth / 1.25); + var height = (int)Math.Round(System.Windows.SystemParameters.PrimaryScreenWidth / 2); + form.MaximumSize = new Size(width,height); form.FormBorderStyle = FormBorderStyle.Sizable; form.MaximizeBox = false; @@ -1399,7 +1402,10 @@ namespace ChatController.HauptKlassen form.StartPosition = FormStartPosition.CenterScreen; form.Size = imgbit.Size; form.MinimumSize = new Size(150,150); - form.MaximumSize = new Size(500,500); + + var width = (int)Math.Round(System.Windows.SystemParameters.PrimaryScreenWidth / 1.25); + var height = (int)Math.Round(System.Windows.SystemParameters.PrimaryScreenWidth / 2); + form.MaximumSize = new Size(width, height); form.FormBorderStyle = FormBorderStyle.Sizable; form.MaximizeBox = false; @@ -1412,8 +1418,7 @@ namespace ChatController.HauptKlassen pb.Image = imgbit; pb.SizeMode = PictureBoxSizeMode.StretchImage; - //pb.MaximumSize = new Size(500,500); - + form.Controls.Add(pb); form.ShowDialog(); }