You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
189 lines
5.2 KiB
C#
189 lines
5.2 KiB
C#
using HandyControl.Data;
|
|
using Microsoft.Win32;
|
|
using Prism.Commands;
|
|
using Prism.Events;
|
|
using Prism.Mvvm;
|
|
using Prism.Regions;
|
|
using Prism.Services.Dialogs;
|
|
using StartServerWPF.Modules.Main.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Input;
|
|
|
|
|
|
namespace StartServerWPF.Modules.Main.ViewModels
|
|
{
|
|
|
|
public class LogManagementViewModel : BindableBase
|
|
{
|
|
IEventAggregator _ea;
|
|
private readonly IDialogService _dialogService;
|
|
|
|
public LogManagementViewModel(
|
|
IEventAggregator ea, IDialogService dialogService)
|
|
|
|
{
|
|
this._dialogService = dialogService;
|
|
InitInfo();
|
|
}
|
|
|
|
private string _title = "日志查看";
|
|
public string Title => _title;
|
|
|
|
public ICommand UploadCommand { get; set; }
|
|
|
|
public DelegateCommand QueryDataCommand => new(QueryData);
|
|
public DelegateCommand ResetQueryDataCommand => new(InitInfo);
|
|
public DelegateCommand HFWarningCommand => new(HFWarning);
|
|
private void InitInfo()
|
|
{
|
|
StartTime = DateTime.Today;
|
|
EndTime = DateTime.Now;
|
|
QueryData();
|
|
}
|
|
|
|
public void Refresh()
|
|
{
|
|
QueryData();
|
|
}
|
|
|
|
|
|
public void QueryData()
|
|
{
|
|
DataList = new List<LogMessageModel>();
|
|
string fileName = "";
|
|
// File.Exists("");
|
|
Task.Run(() =>
|
|
{
|
|
// var lines= File.ReadAllLines(fileName);
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
DataList.Add(new LogMessageModel()
|
|
{
|
|
AppName = "app"+i,
|
|
LogType = 1,
|
|
Message = "start",
|
|
OriginTime = DateTime.Now.AddMinutes(i),
|
|
State = "启动中"
|
|
});
|
|
}
|
|
});
|
|
}
|
|
private void HFWarning()
|
|
{
|
|
|
|
DialogParameters param = new DialogParameters();
|
|
param.Add("type", 0);
|
|
ShowEditDialog(param);
|
|
}
|
|
private void ShowEditDialog(DialogParameters param)
|
|
{
|
|
_dialogService.ShowDialog(
|
|
"HFLogDialog",
|
|
param,
|
|
new Action<IDialogResult>(result =>
|
|
{
|
|
if (result != null && result.Result == ButtonResult.OK)
|
|
{
|
|
System.Windows.MessageBox.Show("数据已保存", "提示");
|
|
Refresh();
|
|
}
|
|
}));
|
|
}
|
|
public void WriteTxt(FileStream fs)
|
|
{
|
|
try
|
|
{
|
|
// foreach (var item in _totalDataList)
|
|
{
|
|
// string mesg = item.CreateTime + "\t" + item.UserName + "\t" + item.UserId + "\t" + item.Message;
|
|
//获得字节数组
|
|
// mesg = mesg + "\n";
|
|
// byte[] data = System.Text.Encoding.Default.GetBytes(mesg);
|
|
//开始写入
|
|
// fs.Write(data, 0, data.Length);
|
|
}
|
|
//清空缓冲区、关闭流
|
|
fs.Flush();
|
|
fs.Close();
|
|
}
|
|
catch
|
|
{
|
|
Console.WriteLine("WriteError");
|
|
}
|
|
}
|
|
|
|
private DateTime _StartTime;
|
|
|
|
public DateTime StartTime
|
|
{
|
|
get => _StartTime;
|
|
set => SetProperty(ref _StartTime, value);
|
|
}
|
|
private DateTime _EndTime;
|
|
|
|
public DateTime EndTime
|
|
{
|
|
get => _EndTime;
|
|
set => SetProperty(ref _EndTime, value);
|
|
}
|
|
private List<LogMessageModel> _DataList;
|
|
|
|
public List<LogMessageModel> DataList
|
|
{
|
|
get { return _DataList; }
|
|
set { SetProperty(ref _DataList, value); }
|
|
}
|
|
///// <summary>
|
|
///// 所有数据
|
|
///// </summary>
|
|
//private List<SystemLogDTO> _totalDataList;
|
|
/// <summary>
|
|
/// 页码
|
|
/// </summary>
|
|
private int _pageIndex = 1;
|
|
|
|
/// <summary>
|
|
/// 页码
|
|
/// </summary>
|
|
public int PageIndex
|
|
{
|
|
get => _pageIndex;
|
|
set => SetProperty(ref _pageIndex, value);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 页码
|
|
/// </summary>
|
|
private int _MaxCountPage = 15;
|
|
|
|
/// <summary>
|
|
/// 页码
|
|
/// </summary>
|
|
public int MaxCountPage
|
|
{
|
|
get => _MaxCountPage;
|
|
set => SetProperty(ref _MaxCountPage, value);
|
|
}
|
|
|
|
private int countPerPage = 15;
|
|
/// <summary>
|
|
/// 页码改变命令
|
|
/// </summary>
|
|
public DelegateCommand<FunctionEventArgs<int>> PageUpdatedCmd => new(PageUpdated);
|
|
|
|
/// <summary>
|
|
/// 页码改变
|
|
/// </summary>
|
|
private void PageUpdated(FunctionEventArgs<int> info)
|
|
{
|
|
// DataList = _totalDataList.Skip((info.Info - 1) * countPerPage).Take(countPerPage).ToList();
|
|
}
|
|
|
|
}
|
|
}
|