123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls.Primitives;
- using System.Windows.Data;
- using System.Windows.Input;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.UI.MVVM;
- using MECF.Framework.Common.Communications;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.OperationCenter;
- using MECF.Framework.UI.Client.ClientBase;
- using OpenSEMI.ClientBase;
- namespace MECF.Framework.UI.Client.CenterViews.Maitenances.Connections
- {
- public class ConnectionViewModel : UiViewModelBase, ISupportMultipleSystem
- {
- public string SystemName { get; set; }
- protected override void OnInitialize()
- {
- base.OnInitialize();
- }
- protected override void OnActivate()
- {
- base.OnActivate();
- }
- protected override void OnDeactivate(bool close)
- {
- base.OnDeactivate(close);
- }
- public ObservableCollection<NotifiableConnectionItem> ListConnections { get; set; }
- public ICommand ConnectCommand { get; set; }
- public ICommand DisconnectCommand { get; set; }
- public ConnectionViewModel()
- {
- ListConnections = new ObservableCollection<NotifiableConnectionItem>();
- ConnectCommand = new DelegateCommand<string>(DoConnect);
- DisconnectCommand = new DelegateCommand<string>(DoDisconnect);
- }
- private void DoConnect(string obj)
- {
- if (DialogBox.Confirm($"Are you sure you want to connect {obj}?"))
- {
- InvokeClient.Instance.Service.DoOperation($"Connection.Connect", obj);
- }
- }
- private void DoDisconnect(string obj)
- {
- if (DialogBox.Confirm($"Are you sure you want to disconnect {obj}?"))
- {
- InvokeClient.Instance.Service.DoOperation($"Connection.Disconnect", obj);
- }
- }
- protected override void Poll()
- {
- Application.Current.Dispatcher.Invoke(new Action(() =>
- {
- var connections = QueryDataClient.Instance.Service.GetData("Connection.List");
- if (connections == null)
- return;
- List<NotifiableConnectionItem> items = connections as List<NotifiableConnectionItem>;
- foreach (var item in items)
- {
- if (ListConnections.Count == 0 || (ListConnections.FirstOrDefault(x => x.Name == item.Name) == null))
- {
- ListConnections.Add(item);
- }
- else
- {
- var find = ListConnections.First(x => x.Name == item.Name);
- find.IsConnected = find.IsConnected;
- find.InvokePropertyChanged("IsConnected");
- }
- }
- InvokePropertyChanged("ListConnections");
- }));
- }
- }
- public class IoButton : ToggleButton
- {
- public static readonly DependencyProperty ONProperty;
- static IoButton()
- {
- ONProperty = DependencyProperty.Register("ON", typeof(bool), typeof(IoButton));
- }
- public bool ON
- {
- get { return (bool)GetValue(ONProperty); }
- set { SetValue(ONProperty, value); }
- }
- }
- public class BoolBackgroundConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- bool? ret = (bool?)value;
- return ret.HasValue && ret.Value ? "LightBlue" : "Transparent";
- }
- public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- return null;
- }
- }
- }
|