mirror of
https://github.com/openziti/desktop-edge-win.git
synced 2026-10-14 00:29:48 +00:00
189 lines
5.5 KiB
C#
189 lines
5.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using ZitiDesktopEdge.Models;
|
|
using ZitiDesktopEdge.ServiceClient;
|
|
|
|
using NLog;
|
|
|
|
namespace ZitiDesktopEdge {
|
|
/// <summary>
|
|
/// Interaction logic for IdentityDetails.xaml
|
|
/// </summary>
|
|
public partial class IdentityDetails:UserControl {
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
private bool _isAttached = true;
|
|
public delegate void Forgot(ZitiIdentity forgotten);
|
|
public event Forgot OnForgot;
|
|
public delegate void ErrorOccurred(string message);
|
|
public event ErrorOccurred OnError;
|
|
public delegate void Detched(MouseButtonEventArgs e);
|
|
public event Detched OnDetach;
|
|
public double MainHeight = 500;
|
|
public string filter = "";
|
|
|
|
private List<ZitiIdentity> identities {
|
|
get {
|
|
return (List<ZitiIdentity>)Application.Current.Properties["Identities"];
|
|
}
|
|
}
|
|
|
|
private ZitiIdentity _identity;
|
|
|
|
public ZitiIdentity Identity {
|
|
get {
|
|
return _identity;
|
|
}
|
|
set {
|
|
_identity = value;
|
|
this.IdDetailToggle.Enabled = _identity.IsEnabled;
|
|
UpdateView();
|
|
IdentityArea.Opacity = 1.0;
|
|
IdentityArea.Visibility = Visibility.Visible;
|
|
this.Visibility = Visibility.Visible;
|
|
}
|
|
}
|
|
|
|
public IdentityItem SelectedIdentity { get; set; }
|
|
|
|
private void Window_MouseDown(object sender, MouseButtonEventArgs e) {
|
|
if (e.ChangedButton == MouseButton.Left) {
|
|
_isAttached = false;
|
|
OnDetach(e);
|
|
}
|
|
}
|
|
|
|
|
|
public bool IsAttached {
|
|
get {
|
|
return _isAttached;
|
|
}
|
|
set {
|
|
_isAttached = value;
|
|
if (_isAttached) {
|
|
Arrow.Visibility = Visibility.Visible;
|
|
ConfirmArrow.Visibility = Visibility.Visible;
|
|
} else {
|
|
Arrow.Visibility = Visibility.Collapsed;
|
|
ConfirmArrow.Visibility = Visibility.Collapsed;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void UpdateView() {
|
|
IdDetailName.Text = _identity.Name;
|
|
IdDetailName.ToolTip = _identity.Name;
|
|
IdDetailToggle.Enabled = _identity.IsEnabled;
|
|
IdentityName.Value = _identity.Name;
|
|
IdentityNetwork.Value = _identity.ControllerUrl;
|
|
IdentityEnrollment.Value = _identity.Status;
|
|
IdentityStatus.Value = _identity.IsEnabled ? "active" : "disabled";
|
|
ServiceList.Children.Clear();
|
|
if (_identity.Services.Count>0) {
|
|
Filter.Visibility = Visibility.Visible;
|
|
FilterLabel.Visibility = Visibility.Visible;
|
|
foreach(var zitiSvc in _identity.Services.OrderBy(s => s.Name.ToLower())) {
|
|
if (zitiSvc.Name.ToLower().IndexOf(filter)>=0||zitiSvc.Url.ToLower().IndexOf(filter)>=0) {
|
|
Logger.Debug("painting: " + zitiSvc.Name);
|
|
ServiceInfo editor = new ServiceInfo();
|
|
editor.Label = zitiSvc.Name;
|
|
editor.Value = zitiSvc.Url;
|
|
editor.Warning = zitiSvc.Warning;
|
|
editor.IsLocked = true;
|
|
ServiceList.Children.Add(editor);
|
|
}
|
|
}
|
|
double newHeight = MainHeight - 300;
|
|
ServiceRow.Height = new GridLength((double)newHeight);
|
|
MainDetailScroll.MaxHeight = newHeight;
|
|
MainDetailScroll.Height = newHeight;
|
|
MainDetailScroll.Visibility = Visibility.Visible;
|
|
ServiceTitle.Content = _identity.Services.Count + " SERVICES";
|
|
} else {
|
|
Filter.Visibility = Visibility.Collapsed;
|
|
FilterLabel.Visibility = Visibility.Collapsed;
|
|
ServiceRow.Height = new GridLength((double)0.0);
|
|
MainDetailScroll.Visibility = Visibility.Collapsed;
|
|
ServiceTitle.Content = "NO SERVICES AVAILABLE";
|
|
}
|
|
}
|
|
|
|
async private void IdToggle(bool on) {
|
|
DataClient client = (DataClient)Application.Current.Properties["ServiceClient"];
|
|
await client.IdentityOnOffAsync(_identity.Fingerprint, on);
|
|
SelectedIdentity.ToggleSwitch.Enabled = on;
|
|
_identity.IsEnabled = on;
|
|
IdentityStatus.Value = _identity.IsEnabled ? "active" : "disabled";
|
|
}
|
|
|
|
public IdentityDetails() {
|
|
InitializeComponent();
|
|
}
|
|
private void HideMenu(object sender, MouseButtonEventArgs e) {
|
|
this.Visibility = Visibility.Collapsed;
|
|
}
|
|
|
|
public void SetHeight(double height) {
|
|
MainDetailScroll.Height = height;
|
|
}
|
|
|
|
private void ForgetIdentity(object sender, MouseButtonEventArgs e) {
|
|
if (this.Visibility==Visibility.Visible) {
|
|
ConfirmView.Visibility = Visibility.Visible;
|
|
}
|
|
}
|
|
|
|
private void CancelConfirmButton_Click(object sender, RoutedEventArgs e) {
|
|
ConfirmView.Visibility = Visibility.Collapsed;
|
|
}
|
|
|
|
async private void ConfirmButton_Click(object sender, RoutedEventArgs e) {
|
|
this.Visibility = Visibility.Collapsed;
|
|
DataClient client = (DataClient)Application.Current.Properties["ServiceClient"];
|
|
try {
|
|
await client.RemoveIdentityAsync(_identity.Fingerprint);
|
|
|
|
ZitiIdentity forgotten = new ZitiIdentity();
|
|
foreach (var id in identities) {
|
|
if (id.Fingerprint == _identity.Fingerprint) {
|
|
forgotten = id;
|
|
identities.Remove(id);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (OnForgot != null) {
|
|
OnForgot(forgotten);
|
|
}
|
|
} catch (DataStructures.ServiceException se) {
|
|
OnError(se.Message);
|
|
} catch (Exception ex) {
|
|
OnError(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void FilterServices(object sender, KeyEventArgs e) {
|
|
if (e.Key == Key.Return) {
|
|
DoFilter();
|
|
}
|
|
}
|
|
|
|
private void DoFilter() {
|
|
filter = Filter.Text.ToLower().Trim();
|
|
UpdateView();
|
|
}
|
|
|
|
private void FilterClicked(object sender, MouseButtonEventArgs e) {
|
|
DoFilter();
|
|
}
|
|
|
|
private void FilterBlur(object sender, RoutedEventArgs e) {
|
|
DoFilter();
|
|
}
|
|
}
|
|
}
|