302 lines
11 KiB
C#
302 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
|
|
using C4IT.API.Contracts;
|
|
using C4IT.Logging;
|
|
|
|
using C4IT_CustomerPanel.libs;
|
|
using static C4IT.Logging.cLogManager;
|
|
|
|
namespace C4IT_CustomerPanel.UserControls
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for Incidents.xaml
|
|
/// </summary>
|
|
public partial class Incidents : UserControl
|
|
{
|
|
public readonly StackPanel _incidentHead = new StackPanel();
|
|
public Dictionary<Guid, IncidentListItem> ticketCollection = new Dictionary<Guid, IncidentListItem>();
|
|
public List<Guid> unreadTickets = new List<Guid>();
|
|
|
|
private MainWindow mainWindow;
|
|
|
|
public Incidents()
|
|
{
|
|
mainWindow = MainWindow.MainInstance;
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void InitializeContracts()
|
|
{
|
|
try
|
|
{
|
|
unreadTickets = ConfigClass.LoadFromJson<List<Guid>>("UnreadTickets", "run");
|
|
}
|
|
catch { }
|
|
|
|
if (unreadTickets == null)
|
|
unreadTickets = new List<Guid>();
|
|
}
|
|
|
|
private void OnCreateNewTicketClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
if (mainWindow.ConfigSettings.GetConfig()._createNewTicketDirectLink != String.Empty)
|
|
{
|
|
Process.Start(mainWindow.ConfigSettings.GetConfig()._createNewTicketDirectLink);
|
|
}
|
|
else
|
|
{
|
|
Process.Start(mainWindow.ConfigSettings.GetMatrixServer(true) + "/wm");
|
|
}
|
|
}
|
|
|
|
private void ReadAll_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
foreach (KeyValuePair<Guid, IncidentListItem> item in ticketCollection)
|
|
{
|
|
item.Value.IsUnread = false;
|
|
}
|
|
CheckAllTicketsRead(null, null);
|
|
}
|
|
|
|
public void CheckAllTicketsRead(object sender, MouseButtonEventArgs e)
|
|
{
|
|
if (e != null)
|
|
e.Handled = true;
|
|
if (sender == null)
|
|
{
|
|
unreadTickets.Clear();
|
|
lock (mainWindow.NewContentSignals)
|
|
{
|
|
mainWindow.NewContentSignals[enumMainFunctions.Incident] = false;
|
|
mainWindow._isRedDotActive = false;
|
|
}
|
|
mainWindow.UpdateNewContentSignals();
|
|
}
|
|
else
|
|
{
|
|
Boolean allRead = true;
|
|
IncidentListItem incItem = null;
|
|
if (sender is Image)
|
|
{
|
|
Image item = (Image)sender;
|
|
incItem = (IncidentListItem)item.DataContext;
|
|
|
|
}
|
|
else if (sender is IncidentListItem)
|
|
{
|
|
incItem = (IncidentListItem)sender;
|
|
|
|
}
|
|
|
|
if (incItem != null)
|
|
{
|
|
incItem.IsUnread = false;
|
|
unreadTickets.Remove(incItem.getEOID());
|
|
|
|
foreach (KeyValuePair<Guid, IncidentListItem> inc in ticketCollection)
|
|
{
|
|
if (inc.Value.IsUnread)
|
|
{
|
|
allRead = false;
|
|
break;
|
|
}
|
|
}
|
|
if (allRead)
|
|
{
|
|
unreadTickets.Clear();
|
|
lock (mainWindow.NewContentSignals)
|
|
{
|
|
mainWindow.NewContentSignals[enumMainFunctions.Incident] = false;
|
|
mainWindow._isRedDotActive = false;
|
|
|
|
}
|
|
mainWindow.UpdateNewContentSignals();
|
|
}
|
|
}
|
|
}
|
|
|
|
ConfigClass.SaveAsJson("UnreadTickets", unreadTickets, "run");
|
|
}
|
|
|
|
public void ProcessNewTickets(List<Ticket> _tickets)
|
|
{
|
|
var newLastUpdate = mainWindow.lastUpdate;
|
|
|
|
try
|
|
{
|
|
if (_tickets != null && _tickets.Count > 0)
|
|
{
|
|
NoIncident.Visibility = Visibility.Hidden;
|
|
|
|
foreach (Ticket ti in _tickets)
|
|
{
|
|
if (ti._objectID == Guid.Empty)
|
|
continue;
|
|
|
|
if (!ticketCollection.TryGetValue(ti._objectID, out var item))
|
|
{
|
|
item = new IncidentListItem(ti)
|
|
{
|
|
Margin = new Thickness(2, 10, 2, 0),
|
|
};
|
|
item.MouseLeftButtonDown += OnTicketClicked;
|
|
item.signal.PreviewMouseDown += CheckAllTicketsRead;
|
|
ticketCollection.Add(ti._objectID, item);
|
|
}
|
|
|
|
item.TicketItem = ti;
|
|
|
|
if (ti._lastJournalEntryAction is int jText
|
|
&& staticLibs.JournalActivityAction.TryGetValue(jText, out var actionInfo)
|
|
&& actionInfo.visible)
|
|
{
|
|
item.LastJournalEntryActionText = actionInfo.JournalText;
|
|
}
|
|
else
|
|
{
|
|
item.LastJournalEntryActionText = string.Empty;
|
|
}
|
|
|
|
var ticketUpdateDate = ti._lastJournalEntryDate > DateTime.MinValue
|
|
? ti._lastJournalEntryDate
|
|
: ti._createdDate;
|
|
|
|
if (ticketUpdateDate > mainWindow.lastUpdate)
|
|
{
|
|
if (!unreadTickets.Contains(ti._objectID))
|
|
unreadTickets.Add(ti._objectID);
|
|
item.IsUnread = true;
|
|
|
|
mainWindow.NewContentSignalsInfo[enumMainFunctions.Incident] =
|
|
Properties.Resources.NewTicketInfoMessage;
|
|
|
|
if (ticketUpdateDate > newLastUpdate)
|
|
newLastUpdate = ticketUpdateDate;
|
|
}
|
|
else
|
|
{
|
|
item.IsUnread = unreadTickets.Contains(ti._objectID);
|
|
}
|
|
|
|
item.TicketType = ti._ticketType;
|
|
}
|
|
var incomingIds = new HashSet<Guid>(_tickets.Select(t => t._objectID));
|
|
var keysToRemove = ticketCollection.Keys
|
|
.Where(id => !incomingIds.Contains(id))
|
|
.ToList();
|
|
foreach (var id in keysToRemove)
|
|
{
|
|
ticketCollection.Remove(id);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ticketCollection.Clear();
|
|
NoIncident.Visibility = Visibility.Visible;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
cLogManager.LogException(e);
|
|
}
|
|
|
|
if (newLastUpdate > mainWindow.lastUpdate)
|
|
{
|
|
mainWindow.lastUpdate = newLastUpdate;
|
|
ConfigClass.SaveAsJson("LastTicketUpdate", mainWindow.lastUpdate, "run");
|
|
}
|
|
|
|
ConfigClass.SaveAsJson("UnreadTickets", unreadTickets, "run");
|
|
|
|
ticketCollection = ticketCollection
|
|
.OrderByDescending(x => x.Value.TicketItem._lastJournalEntryDate)
|
|
.ThenByDescending(x => x.Value.TicketItem._createdDate)
|
|
.ToDictionary(x => x.Key, x => x.Value);
|
|
|
|
FillIncidentGrid();
|
|
}
|
|
|
|
public void FillIncidentGrid()
|
|
{
|
|
try
|
|
{
|
|
var setNewContent = false;
|
|
|
|
_incidentHead.Children.Clear();
|
|
foreach (var item in ticketCollection)
|
|
{
|
|
if (item.Value.IsUnread)
|
|
setNewContent = true;
|
|
var control = item.Value;
|
|
control.TicketItem = control.TicketItem; // löst im Setter alle OnPropertyChanged aus
|
|
_incidentHead.Children.Add(control);
|
|
}
|
|
|
|
CanvasIncident.Content = null;
|
|
|
|
CanvasIncident.Content = _incidentHead;
|
|
|
|
if (setNewContent)
|
|
{
|
|
lock (mainWindow.NewContentSignals)
|
|
mainWindow.NewContentSignals[enumMainFunctions.Incident] = true;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogException(e);
|
|
}
|
|
}
|
|
|
|
public void OnTicketClicked(object sender, EventArgs e)
|
|
{
|
|
if (sender is FrameworkElement fe && fe.DataContext is IncidentListItem item)
|
|
{
|
|
if (!item.TicketItem._objectID.Equals(Guid.Empty))
|
|
{
|
|
try
|
|
{
|
|
string startParam;
|
|
|
|
if (mainWindow.ConfigSettings.GetConfig()._isUUX)
|
|
{
|
|
startParam = string.Format("{0}/wm/app-SelfServicePortal/notSet/preview-object/{1}/{2}/0/",
|
|
mainWindow.ConfigSettings.GetMatrixServer(true),
|
|
item.TicketItem._sysEntity,
|
|
item.TicketItem._objectID.ToString());
|
|
}
|
|
else
|
|
{
|
|
startParam = string.Format("{0}/SPS/Portal/Pages/Support/IncidentDetails.aspx?IncidentID={1}&ConsiderArchivedData=0",
|
|
mainWindow.ConfigSettings.GetMatrixServer(true),
|
|
item.TicketItem._objectID.ToString());
|
|
}
|
|
|
|
Process.Start(startParam);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// Not yet implemented
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|