You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.5 KiB

using ScadaTool.Helper;
using static ScadaTool.Helper.GoCSharpHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace ScadaTool.ViewModel
{
public class MainViewModel : BaseViewModel
{
public MainViewModel()
{
3 years ago
#region 图标闪烁
bool tmp = false;
var timer = new System.Timers.Timer(1000);
timer.Elapsed += new System.Timers.ElapsedEventHandler((obj, args) =>
{
icoPath = tmp == true ? "Resources/icon_red.ico" : "Resources/none.ico";
tmp = tmp == true ? false : true;
});
timer.Start();
3 years ago
#endregion
#region Command
ExitApplicationCommand = new RelayCommand((_) =>
{
return true;
}, (_) =>
{
ViewModelHelper.Instance().UpdateUI(() =>
{
Application.Current.Shutdown();
});
});
ShowWindowCommand = new RelayCommand((_) =>
{
return true;
}, (_) =>
{
ViewModelHelper.Instance().UpdateUI(() =>
{
Application.Current.MainWindow.Show();
Application.Current.MainWindow.Activate();
});
});
3 years ago
HidenApplicationCommand = new RelayCommand((_) =>
{
return true;
}, (_) =>
{
ViewModelHelper.Instance().UpdateUI(() =>
{
Application.Current.MainWindow.Hide();
});
});
// 服务
3 years ago
var isTrue = true;
StartServiceCommand = new RelayCommand((_) =>
{
3 years ago
return isTrue;
}, (_) =>
{
string result = GoCSharpHelper.Instance().GoStringToCSharpString(run());
if (result.Equals("success"))
{
3 years ago
MessageBox.Show("服务启动\n" + result);
icoPath = "Resources/icon.ico";
3 years ago
isTrue = false;
timer.Dispose();
}
else
{
3 years ago
MessageBox.Show("服务启动失败\n" + result);
}
});
#endregion
}
3 years ago
#region Go
/// <summary>
/// 引入Go项目库
/// </summary>
/// <returns></returns>
[DllImport("scadatool_go.dll", EntryPoint = "run")]
extern static GoString run();
3 years ago
#endregion
#region 属性
private string mToolTip = "服务未启动";
public string toolTip
{
get => mToolTip;
set { mToolTip = value; NotifyChanged("toolTip"); }
}
private string mIcoPath = "Resources/icon_red.ico";
public string icoPath
{
get => mIcoPath;
set { mIcoPath = value; NotifyChanged("icoPath"); }
}
public ICommand ExitApplicationCommand { get; private set; }
public ICommand ShowWindowCommand { get; private set; }
public ICommand HidenApplicationCommand { get; private set; }
public ICommand StartServiceCommand { get; private set; }
#endregion
}
}