Warnung bei 500er Fehlern anstatt von zig einzelnen Fehlermeldungen
This commit is contained in:
@@ -149,6 +149,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="ownchat_favicon.ico" />
|
||||
<Resource Include="Ressourcen\warning-exclamation-mark.png" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="Resources\oC-favico_NewMessage.ico" />
|
||||
<Content Include="Resources\ownchat_favicon.ico" />
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
<Setter Property="Template" Value="{StaticResource ContactListBoxTemplate}" />
|
||||
</Style>
|
||||
|
||||
<!-- Kontaktliste -->
|
||||
<Style x:Key="ContactListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
|
||||
<Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorLevel=1, AncestorType={x:Type ItemsControl}, Mode=FindAncestor}}" />
|
||||
<Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorLevel=1, AncestorType={x:Type ItemsControl}, Mode=FindAncestor}}" />
|
||||
@@ -210,29 +211,20 @@
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ListBox x:Name="AktChatUserList" HorizontalAlignment="Left" Margin="0" Grid.Row="0" Background="Transparent" BorderBrush="Transparent" VerticalAlignment="Bottom" ItemTemplate="{DynamicResource DataTemplate2}" MouseDoubleClick="AktChatUser_OnMouseDoubleClick" >
|
||||
<ListBox.Resources>
|
||||
<DataTemplate x:Key="DataTemplate2" DataType="chatKlassen:Contact">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="50"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="10*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Grid.Row="0" HorizontalAlignment="Left" Background="Transparent" VerticalAlignment="Center" Height="50" PreviewMouseDown="CurrentContactImage_OnMouseDoubleClick">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="50" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Ellipse Width='40' Height='40' VerticalAlignment="Center" RenderOptions.BitmapScalingMode="HighQuality">
|
||||
<Ellipse.Fill >
|
||||
<ImageBrush ImageSource='{Binding Image}' Stretch="UniformToFill"/>
|
||||
</Ellipse.Fill>
|
||||
</Ellipse>
|
||||
|
||||
<TextBlock Grid.Column="1" Margin="8" Text="{Binding Path=Name, FallbackValue=FirstName}" FontSize="16" Foreground="{Binding AccentColorBrush}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.Resources>
|
||||
</ListBox>
|
||||
<Ellipse Width='40' Height='40' VerticalAlignment="Center" RenderOptions.BitmapScalingMode="HighQuality">
|
||||
<Ellipse.Fill >
|
||||
<ImageBrush ImageSource='{Binding Path=ThreadExceptionImageSource, UpdateSourceTrigger=PropertyChanged}' Stretch="UniformToFill"/>
|
||||
</Ellipse.Fill>
|
||||
</Ellipse>
|
||||
|
||||
<TextBlock Grid.Column="1" VerticalAlignment="Center" Margin="8" TextWrapping="Wrap" Text="{Binding CurrentContactInformationString}" FontSize="16" Foreground="{Binding CurrencContactInfoForeground}" />
|
||||
</Grid>
|
||||
|
||||
<ListBox x:Name="ChatListBox" ItemsSource="{Binding CurrentChatMessages, UpdateSourceTrigger=PropertyChanged}"
|
||||
HorizontalAlignment="Stretch" ScrollViewer.CanContentScroll="False" VerticalAlignment="Stretch" Grid.Row="1"
|
||||
@@ -366,7 +358,8 @@
|
||||
Margin="2"
|
||||
VerticalAlignment="Stretch"
|
||||
GotFocus="Chatbox_OnGotFocus"
|
||||
KeyDown="Chatbox_OnKeyDownHandler">
|
||||
KeyDown="Chatbox_OnKeyDownHandler"
|
||||
TextChanged="Chatbox_OnTextChanged">
|
||||
<TextBox.Resources>
|
||||
<Style TargetType="{x:Type Border}">
|
||||
<Setter Property="CornerRadius" Value="2"/>
|
||||
|
||||
@@ -14,6 +14,7 @@ using System.Windows.Data;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Threading;
|
||||
using ChatController.Annotations;
|
||||
@@ -43,6 +44,33 @@ namespace ChatController
|
||||
|
||||
private readonly Dictionary<int, SyncFileInfoStruct> _GroupId2DateTime = new Dictionary<int, SyncFileInfoStruct>();
|
||||
|
||||
private string _ThreadExceptionMessage;
|
||||
|
||||
public string ThreadExceptionMessage
|
||||
{
|
||||
get => _ThreadExceptionMessage;
|
||||
|
||||
set
|
||||
{
|
||||
if(!Equals(_ThreadExceptionMessage, value))
|
||||
{
|
||||
_ThreadExceptionMessage = value;
|
||||
OnPropertyChanged(nameof(ThreadExceptionMessage));
|
||||
OnPropertyChanged(nameof(CurrentContactInformationString));
|
||||
OnPropertyChanged(nameof(CurrencContactInfoForeground));
|
||||
OnPropertyChanged(nameof(ThreadExceptionImageSource));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ImageSource _ThreadExceptionImageSource;
|
||||
|
||||
public ImageSource ThreadExceptionImageSource => ThreadExceptionMessage != null ? _ThreadExceptionImageSource : CurrentContact?.Image;
|
||||
|
||||
public SolidColorBrush CurrencContactInfoForeground => ThreadExceptionMessage != null ? new SolidColorBrush(Color.FromRgb(185, 65, 0)) : CurrentContact?.AccentColorBrush ?? new SolidColorBrush(Colors.Transparent);
|
||||
|
||||
public string CurrentContactInformationString => ThreadExceptionMessage ?? CurrentContact?.Name;
|
||||
|
||||
private Window _ContainingWindow;
|
||||
|
||||
public Window ContainingWindow
|
||||
@@ -79,6 +107,9 @@ namespace ChatController
|
||||
OnPropertyChanged(nameof(CurrentContact));
|
||||
OnPropertyChanged(nameof(ChatMessageInputGridVisibility));
|
||||
OnPropertyChanged(nameof(CurrentChatMessages));
|
||||
OnPropertyChanged(nameof(CurrentContactInformationString));
|
||||
OnPropertyChanged(nameof(CurrencContactInfoForeground));
|
||||
OnPropertyChanged(nameof(ThreadExceptionImageSource));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,6 +152,8 @@ namespace ChatController
|
||||
public ChatMainControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_ThreadExceptionImageSource = new BitmapImage(new Uri("pack://application:,,,/ChatController;component/Ressourcen/warning-exclamation-mark.png", UriKind.Absolute));
|
||||
|
||||
DataContext = this;
|
||||
|
||||
@@ -140,11 +173,24 @@ namespace ChatController
|
||||
public void InitMitChatdaten(ChatDatenUebergabe cdu)
|
||||
{
|
||||
_Chat = new Chat(cdu, exception => {
|
||||
this.Dispatch(() => {
|
||||
EndWaiting();
|
||||
MessageBox.Show($"Fehler: {exception.Message}", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
this.Dispatch(
|
||||
() => {
|
||||
EndWaiting();
|
||||
|
||||
MessageBox.Show($"Fehler: {exception.Message}", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
});
|
||||
},
|
||||
exception => {
|
||||
this.Dispatch(
|
||||
() => {
|
||||
if(exception == null)
|
||||
{
|
||||
ThreadExceptionMessage = null;
|
||||
}
|
||||
|
||||
ThreadExceptionMessage = exception?.Message?.Contains("500") ?? false ? "ownChat ist vorrübergehend nicht verfügbar. Bitte versuchen Sie es später noch einmal." : null;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
_ContactList = _Chat.AddContacts();
|
||||
OnPropertyChanged(nameof(ContactList));
|
||||
@@ -235,10 +281,13 @@ namespace ChatController
|
||||
ReloadGruppen.Visibility = Visibility.Visible;
|
||||
_IsDesktopVersion = false;
|
||||
}
|
||||
|
||||
private void AktChatUser_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||
|
||||
private void CurrentContactImage_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
_Chat.ShowProfilePicture(_CurrentContact);
|
||||
if(e.ClickCount == 2)
|
||||
{
|
||||
_Chat.ShowProfilePicture(_CurrentContact);
|
||||
}
|
||||
}
|
||||
|
||||
private void Clientlist_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
@@ -262,8 +311,6 @@ namespace ChatController
|
||||
Cursor = Cursors.Wait;
|
||||
_ScrollPrueferAktivieren = false;
|
||||
|
||||
AktChatUserList.Items.Clear();
|
||||
|
||||
if (pContact.HasUnreadMessages)
|
||||
{
|
||||
pContact.HasUnreadMessages = false;
|
||||
@@ -280,7 +327,6 @@ namespace ChatController
|
||||
ContainingWindow.Icon = Utils.GetImageSourceFromIcon(Resource.ownchat_favicon);
|
||||
}
|
||||
|
||||
AktChatUserList.Items.Add(currentContact);
|
||||
CurrentContact = currentContact;
|
||||
|
||||
if(Clientlist.Items.Contains(pContact))
|
||||
@@ -368,8 +414,7 @@ namespace ChatController
|
||||
|
||||
private void PasteOnClick(object sender, RoutedEventArgs routedEventArgs)
|
||||
{
|
||||
var kontakt = (Contact)AktChatUserList.Items[0];
|
||||
_Chat.Paste(kontakt.GroupId,this);
|
||||
_Chat.Paste(CurrentContact.GroupId,this);
|
||||
}
|
||||
|
||||
private void CopyOnClick(object sender, RoutedEventArgs routedEventArgs)
|
||||
@@ -468,9 +513,8 @@ namespace ChatController
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
//prüfe ob dokumentation erlaubt
|
||||
var kontakt = (Contact)AktChatUserList.Items[0];
|
||||
if(kontakt.UserIdManage == null && ChatListBox.ContextMenu.Items.Count > 3)
|
||||
// Prüfe, ob Dokumentation erlaubt
|
||||
if(CurrentContact.UserIdManage == null && ChatListBox.ContextMenu.Items.Count > 3)
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[3];
|
||||
@@ -492,7 +536,7 @@ namespace ChatController
|
||||
|
||||
private void MediaButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (AktChatUserList.Items.Count > 0)
|
||||
if(CurrentContact != null)
|
||||
{
|
||||
var fileToOpen = _Chat.OpenFile();
|
||||
|
||||
@@ -510,7 +554,7 @@ namespace ChatController
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(filePath))
|
||||
{
|
||||
//_Chat.AddNewFile(filePath, fileToOpen, CurrentContact.GroupId);
|
||||
_Chat.AddNewFile(filePath, fileToOpen, CurrentContact.GroupId);
|
||||
|
||||
OnPropertyChanged(nameof(CurrentChatMessages));
|
||||
|
||||
@@ -534,7 +578,7 @@ namespace ChatController
|
||||
|
||||
private void SendButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!AktChatUserList.Items.IsEmpty && !string.IsNullOrEmpty(Chatbox.Text))
|
||||
if(CurrentContact != null && !string.IsNullOrEmpty(Chatbox.Text))
|
||||
{
|
||||
_Chat.AddNewMessage(Chatbox.Text, CurrentContact.GroupId);
|
||||
|
||||
@@ -564,7 +608,7 @@ namespace ChatController
|
||||
{
|
||||
if (e.Key == Key.Return)
|
||||
{
|
||||
if (!AktChatUserList.Items.IsEmpty && !string.IsNullOrEmpty(Chatbox.Text))
|
||||
if(CurrentContact != null && !string.IsNullOrEmpty(Chatbox.Text))
|
||||
{
|
||||
_Chat.AddNewMessage(Chatbox.Text, CurrentContact.GroupId);
|
||||
|
||||
@@ -646,7 +690,7 @@ namespace ChatController
|
||||
{
|
||||
EmojisListeningThreadTimer?.Stop();
|
||||
EmojisListeningThreadTimer = null;
|
||||
InitListeningThread((Contact)AktChatUserList.Items[0]);
|
||||
InitListeningThread(CurrentContact);
|
||||
}
|
||||
|
||||
public Timer EmojisListeningThreadTimer;
|
||||
@@ -656,7 +700,7 @@ namespace ChatController
|
||||
{
|
||||
GlobalListeningThreadtimer = new Timer();
|
||||
GlobalListeningThreadtimer.Tick += GlobalListeningThreadTimerTickEvent;
|
||||
GlobalListeningThreadtimer.Interval = 2000;
|
||||
GlobalListeningThreadtimer.Interval = 10000;
|
||||
GlobalListeningThreadtimer.Start();
|
||||
}
|
||||
|
||||
@@ -677,13 +721,6 @@ namespace ChatController
|
||||
{
|
||||
var contacts = _Chat.NeueGroupklassenKontakte().ToList();
|
||||
|
||||
Contact currentContact = null;
|
||||
|
||||
if (AktChatUserList.HasItems)
|
||||
{
|
||||
currentContact = (Contact) AktChatUserList.Items[0];
|
||||
}
|
||||
|
||||
foreach (var contact in _ContactList)
|
||||
{
|
||||
foreach (var newContact in contacts)
|
||||
@@ -696,15 +733,17 @@ namespace ChatController
|
||||
contact.ReceivedMessage = newContact.ReceivedMessage;
|
||||
contact.TimeStamp = newContact.TimeStamp;
|
||||
|
||||
// TODO: Prüfen, ob die App im Hintergrund oder minimiert ist
|
||||
if (Clientlist.SelectedItem != null && !((Contact)Clientlist.SelectedItem).GroupId.Equals(newContact.GroupId) || Clientlist.SelectedItem == null || _IsInBackground)
|
||||
var selectedContact = (Contact) Clientlist.SelectedItem;
|
||||
var userOid = _Chat.ChatDaten.LoggedInUser.Response.User.Oid;
|
||||
|
||||
if (selectedContact != null && !selectedContact.GroupId.Equals(newContact.GroupId) || selectedContact == null || _IsInBackground && userOid != contact?.ReceivedMessage?.UserId)
|
||||
{
|
||||
ContainingWindow.Icon = Utils.GetImageSourceFromIcon(Resource.oC_favico_NewMessage);
|
||||
ShowNotification(newContact.Name, newContact.ReceivedMessage, newContact.GroupId);
|
||||
}
|
||||
|
||||
// Wenn der momentan ausgewählte Kontakt der aktuelle Kontakt in der Schleife ist, werden die Nachrichten nicht als ungelesen angezeigt, sonst schon.
|
||||
if (currentContact != null && newContact.GroupId == currentContact.GroupId)
|
||||
if (CurrentContact != null && newContact.GroupId == CurrentContact.GroupId)
|
||||
{
|
||||
contact.HasUnreadMessages = false;
|
||||
}
|
||||
@@ -737,7 +776,7 @@ namespace ChatController
|
||||
{
|
||||
EmojisListeningThreadTimer = new Timer {Tag = currentContact};
|
||||
EmojisListeningThreadTimer.Tick += ListeningThreadTimerTickEvent;
|
||||
EmojisListeningThreadTimer.Interval = 2000;
|
||||
EmojisListeningThreadTimer.Interval = 10000;
|
||||
EmojisListeningThreadTimer.Start();
|
||||
}
|
||||
|
||||
@@ -1052,14 +1091,7 @@ namespace ChatController
|
||||
// Wird im BeWoPlaner benutzt
|
||||
public Contact GetCurrentContact()
|
||||
{
|
||||
if(AktChatUserList != null && AktChatUserList.Items.Count > 0)
|
||||
{
|
||||
var contact = (Contact) AktChatUserList.Items[0];
|
||||
|
||||
return contact.UserIdManage == null ? null : contact;
|
||||
}
|
||||
|
||||
return null;
|
||||
return CurrentContact?.UserIdManage != null ? CurrentContact : null;
|
||||
}
|
||||
|
||||
// Wird im BeWoPlaner benutzt
|
||||
@@ -1107,5 +1139,13 @@ namespace ChatController
|
||||
var view = (CollectionView)CollectionViewSource.GetDefaultView(Clientlist.ItemsSource);
|
||||
view.Filter = UserFilter;
|
||||
}
|
||||
|
||||
private void Chatbox_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(Chatbox.Text))
|
||||
{
|
||||
Chatbox.Height = 25;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace ChatController.HauptKlassen
|
||||
public class Chat
|
||||
{
|
||||
public Action<Exception> ExceptionCallback { get; set; }
|
||||
public Action<Exception> ThreadExceptionCallback { get; set; }
|
||||
|
||||
private readonly List<Contact> _Contacts = new List<Contact>();
|
||||
|
||||
@@ -49,10 +50,11 @@ namespace ChatController.HauptKlassen
|
||||
|
||||
public long LastTimeStamp { get; set; }
|
||||
|
||||
public Chat(ChatDatenUebergabe chatDaten, Action<Exception> exceptionCallback)
|
||||
public Chat(ChatDatenUebergabe chatDaten, Action<Exception> exceptionCallback, Action<Exception> threadExceptionCallback)
|
||||
{
|
||||
ChatDaten = chatDaten;
|
||||
ExceptionCallback = exceptionCallback;
|
||||
ThreadExceptionCallback = threadExceptionCallback;
|
||||
}
|
||||
|
||||
// WebRequest
|
||||
@@ -82,14 +84,7 @@ namespace ChatController.HauptKlassen
|
||||
{
|
||||
try
|
||||
{
|
||||
var bitmapImage = new BitmapImage();
|
||||
|
||||
bitmapImage.BeginInit();
|
||||
bitmapImage.UriSource = new Uri(pUri);
|
||||
bitmapImage.CacheOption = BitmapCacheOption.OnDemand;
|
||||
bitmapImage.EndInit();
|
||||
|
||||
return bitmapImage;
|
||||
return DownloadImageWithRestRequest(pUri);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@@ -98,6 +93,38 @@ namespace ChatController.HauptKlassen
|
||||
}
|
||||
}
|
||||
|
||||
private ImageSource DownloadImageWithRestRequest(string uri)
|
||||
{
|
||||
Bitmap bitmap = null;
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(uri))
|
||||
{
|
||||
var client = new RestClient(uri);
|
||||
|
||||
var request = new RestRequest(Method.GET)
|
||||
{
|
||||
ResponseWriter = responseStream =>
|
||||
{
|
||||
try
|
||||
{
|
||||
bitmap = new Bitmap(responseStream);
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
request.AddHeader(Constants.Token, ChatDaten.AuthToken);
|
||||
request.AddHeader(Constants.CustomerId, ChatDaten.Kundennummer);
|
||||
|
||||
client.DownloadData(request);
|
||||
}
|
||||
|
||||
return bitmap != null ? Utils.ImageSourceForBitmap(bitmap) : null;
|
||||
}
|
||||
|
||||
// WebRequest
|
||||
private void LoadMessagesFromServer(long pGroupId)
|
||||
{
|
||||
@@ -131,10 +158,12 @@ namespace ChatController.HauptKlassen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ThreadExceptionCallback?.Invoke(null);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
ExceptionCallback?.Invoke(exception);
|
||||
ThreadExceptionCallback?.Invoke(exception);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,11 +350,12 @@ namespace ChatController.HauptKlassen
|
||||
|
||||
var messageCounter = JsonConvert.DeserializeObject<MessageCounter>(responseFromServer);
|
||||
|
||||
ThreadExceptionCallback?.Invoke(null);
|
||||
return messageCounter.MessageCount;
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
ExceptionCallback?.Invoke(exception);
|
||||
ThreadExceptionCallback?.Invoke(exception);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -521,7 +551,7 @@ namespace ChatController.HauptKlassen
|
||||
{
|
||||
var openFileDialog = new OpenFileDialog
|
||||
{
|
||||
Filter = Resource.OpenFileDialogFilter_Test //Resource.OpenFileDialogFilter_DocumentsAndImages
|
||||
Filter = Resource.OpenFileDialogFilter_Test
|
||||
};
|
||||
|
||||
var result = openFileDialog.ShowDialog();
|
||||
|
||||
@@ -90,6 +90,13 @@ namespace ChatController
|
||||
DataContext = this;
|
||||
|
||||
LeseDateiFallsVorhanden();
|
||||
|
||||
#if DEBUG
|
||||
_Kundennummer = "4368658436";
|
||||
_ChatCode = "ZMCKb-BckTt";
|
||||
_Benutzername = "muellerp";
|
||||
Password = "F5aTk9Co47JFJCWB2Z7Y";
|
||||
#endif
|
||||
}
|
||||
|
||||
private void AnmeldenButton_OnClick(object sender, RoutedEventArgs e)
|
||||
|
||||
BIN
ChatController/Ressourcen/warning-exclamation-mark.png
Normal file
BIN
ChatController/Ressourcen/warning-exclamation-mark.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 677 B |
Reference in New Issue
Block a user