2019-06-06 21:30:30 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
namespace FrontEnd
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Interaction logic for MainWindow.xaml
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
|
{
|
|
|
|
|
|
public MainWindow()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
var img = new BitmapImage(new Uri(@"pack://application:,,,/Images/map.png"));
|
|
|
|
|
|
imgMap.Source = img;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-06-07 10:58:11 +00:00
|
|
|
|
private void CreateCameraMarker(Point pos, Cam cam)
|
2019-06-06 21:30:30 +00:00
|
|
|
|
{
|
2019-06-07 10:58:11 +00:00
|
|
|
|
var img = new Image
|
2019-06-06 21:30:30 +00:00
|
|
|
|
{
|
2019-06-07 10:58:11 +00:00
|
|
|
|
Source = new BitmapImage(new Uri($@"pack://application:,,,/Images/cam_{(cam.Status ? "green" : "red")}.png")),
|
2019-06-06 21:30:30 +00:00
|
|
|
|
RenderTransformOrigin = new Point(0.5, 0.5),
|
2019-06-07 10:58:11 +00:00
|
|
|
|
RenderTransform = new RotateTransform(cam.Angle),
|
2019-06-06 21:30:30 +00:00
|
|
|
|
Width = 32,
|
2019-06-07 10:58:11 +00:00
|
|
|
|
Height = 32,
|
|
|
|
|
|
Tag = cam.Ip,
|
|
|
|
|
|
ToolTip = cam.Label
|
2019-06-06 21:30:30 +00:00
|
|
|
|
};
|
2019-06-07 10:58:11 +00:00
|
|
|
|
img.MouseDown += Cam_MouseDown;
|
|
|
|
|
|
cnvMap.Children.Add(img);
|
|
|
|
|
|
Canvas.SetLeft(img, pos.X - img.Width / 2);
|
|
|
|
|
|
Canvas.SetTop(img, pos.Y - img.Height / 2);
|
2019-06-06 21:30:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Cam_MouseDown(object sender, MouseButtonEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
new StreamWindow(((Image)sender).Tag.ToString()).ShowDialog();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-06-07 10:58:11 +00:00
|
|
|
|
private void CreateClientMarker(Point pos, Client client)
|
2019-06-06 21:30:30 +00:00
|
|
|
|
{
|
|
|
|
|
|
var ellipse = new Ellipse
|
|
|
|
|
|
{
|
|
|
|
|
|
Width = 20,
|
|
|
|
|
|
Height = 20,
|
2019-06-07 10:58:11 +00:00
|
|
|
|
Fill = client.Status ? Brushes.Green : Brushes.Red,
|
|
|
|
|
|
Stroke = Brushes.Black,
|
|
|
|
|
|
StrokeThickness = 1,
|
2019-06-07 17:26:52 +00:00
|
|
|
|
ToolTip = client.Label
|
2019-06-06 21:30:30 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
cnvMap.Children.Add(ellipse);
|
|
|
|
|
|
Canvas.SetLeft(ellipse, pos.X - ellipse.Width / 2);
|
|
|
|
|
|
Canvas.SetTop(ellipse, pos.Y - ellipse.Height / 2);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
2019-06-07 10:58:11 +00:00
|
|
|
|
LoadInformation();
|
2019-06-07 17:26:52 +00:00
|
|
|
|
System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
|
|
|
|
|
|
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
|
|
|
|
|
|
dispatcherTimer.Interval = new TimeSpan(0, 0, 5);
|
|
|
|
|
|
dispatcherTimer.Start();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void dispatcherTimer_Tick(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
var selectedItem = (ListBoxItem)lstDevices.SelectedItem;
|
|
|
|
|
|
if (selectedItem != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var newSelection = from ListBoxItem item in lstDevices.Items
|
|
|
|
|
|
where selectedItem.Content.Equals(item.Content)
|
|
|
|
|
|
select item;
|
|
|
|
|
|
if (newSelection.Any())
|
|
|
|
|
|
lstDevices.SelectedItem = newSelection.First();
|
|
|
|
|
|
}
|
2019-06-07 10:58:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void LoadInformation()
|
|
|
|
|
|
{
|
|
|
|
|
|
List<Cam> cams = Task.Run(async () => { return await Communicator.GetCamsAsync(); }).Result;
|
|
|
|
|
|
List<Client> clients = Task.Run(async () => { return await Communicator.GetClientsAsync(); }).Result;
|
|
|
|
|
|
|
|
|
|
|
|
cnvMap.Children.Clear();
|
2019-06-06 21:30:30 +00:00
|
|
|
|
cnvMap.Width = imgMap.ActualWidth;
|
|
|
|
|
|
cnvMap.Height = imgMap.ActualHeight;
|
2019-06-07 10:58:11 +00:00
|
|
|
|
lstDevices.Items.Clear();
|
|
|
|
|
|
txtInfo.Clear();
|
2019-06-06 21:30:30 +00:00
|
|
|
|
|
2019-06-07 10:58:11 +00:00
|
|
|
|
foreach (var client in clients)
|
2019-06-06 21:30:30 +00:00
|
|
|
|
{
|
2019-06-07 10:58:11 +00:00
|
|
|
|
CreateClientMarker(new Point(cnvMap.Width * client.X, cnvMap.Height * client.Y), client);
|
2019-06-06 21:30:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-06-07 10:58:11 +00:00
|
|
|
|
foreach (var cam in cams)
|
2019-06-06 21:30:30 +00:00
|
|
|
|
{
|
2019-06-07 10:58:11 +00:00
|
|
|
|
CreateCameraMarker(new Point(cnvMap.Width * cam.X, cnvMap.Height * cam.Y), cam);
|
|
|
|
|
|
|
|
|
|
|
|
ListBoxItem item = new ListBoxItem
|
|
|
|
|
|
{
|
|
|
|
|
|
Tag = cam,
|
|
|
|
|
|
Content = cam.Label,
|
|
|
|
|
|
FontWeight = FontWeights.Bold
|
|
|
|
|
|
};
|
2019-06-06 21:30:30 +00:00
|
|
|
|
lstDevices.Items.Add(item);
|
2019-06-07 10:58:11 +00:00
|
|
|
|
|
|
|
|
|
|
foreach (var client in clients.Where(c => c.Id == cam.Client_Id))
|
2019-06-06 21:30:30 +00:00
|
|
|
|
{
|
2019-06-07 10:58:11 +00:00
|
|
|
|
ListBoxItem subitem = new ListBoxItem
|
|
|
|
|
|
{
|
|
|
|
|
|
Tag = client,
|
|
|
|
|
|
Content = client.Label
|
|
|
|
|
|
};
|
2019-06-06 21:30:30 +00:00
|
|
|
|
lstDevices.Items.Add(subitem);
|
2019-06-07 10:58:11 +00:00
|
|
|
|
}
|
2019-06-06 21:30:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void LstDevices_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
var selectedItem = lstDevices.SelectedItem as ListBoxItem;
|
|
|
|
|
|
if (selectedItem != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (selectedItem.Tag is Client client)
|
|
|
|
|
|
{
|
2019-06-07 10:58:11 +00:00
|
|
|
|
txtInfo.Text = client.ToString();
|
2019-06-06 21:30:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (selectedItem.Tag is Cam cam)
|
|
|
|
|
|
{
|
2019-06-07 10:58:11 +00:00
|
|
|
|
txtInfo.Text = cam.ToString();
|
2019-06-06 21:30:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-06-07 10:58:11 +00:00
|
|
|
|
|
|
|
|
|
|
private void BtnRefresh_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
LoadInformation();
|
|
|
|
|
|
}
|
2019-06-06 21:30:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|