Commit 9e83e9b9 by liulongfei

日志插件开发

parent 2c393f71
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using VIZ.Framework.Plugin;
using VIZ.TVP.Domain;
using VIZ.TVP.Plugin;
namespace VIZ.TVP.Module
{
/// <summary>
/// 日志插件生命周期
/// </summary>
public class LogPluginLifeCycle : IPluginLifeCycle
{
/// <summary>
/// 插件ID
/// </summary>
/// <remarks>
/// 插件ID不能包含点号
/// </remarks>
public const string PLUGIN_ID = PluginIDs.LOG;
/// <summary>
/// 插件显示名称
/// </summary>
public const string PLUGIN_DISPLAY_NAME = "日志";
/// <summary>
/// 注册
/// </summary>
/// <returns>插件信息</returns>
public PluginInfo Register()
{
PluginInfo info = new PluginInfo();
info.ID = PLUGIN_ID;
info.DisplayName = PLUGIN_DISPLAY_NAME;
info.HasView = true;
info.HasSettingView = false;
info.ViewInfo = new PluginViewInfo(typeof(LogView), typeof(LogViewModel));
return info;
}
/// <summary>
/// 初始化
/// </summary>
public void Initialize()
{
}
/// <summary>
/// 销毁
/// </summary>
public void Dispose()
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
namespace VIZ.TVP.Module
{
/// <summary>
/// 日志服务
/// </summary>
public interface ILogService : IService
{
/// <summary>
/// 添加日志
/// </summary>
/// <param name="log">日志</param>
void AppendLog(string log);
/// <summary>
/// 清理日志
/// </summary>
void ClearLog();
}
}
<UserControl x:Class="VIZ.TVP.Module.LogView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:VIZ.TVP.Module"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<TextBox x:Name="tb" IsReadOnly="True" AcceptsReturn="False"></TextBox>
</Grid>
</UserControl>
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;
using VIZ.Framework.Core;
namespace VIZ.TVP.Module
{
/// <summary>
/// LogView.xaml 的交互逻辑
/// </summary>
public partial class LogView : UserControl
{
public LogView()
{
InitializeComponent();
}
}
}
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
using VIZ.Framework.Plugin;
using VIZ.TVP.Domain;
namespace VIZ.TVP.Module
{
/// <summary>
/// 日志视图模型
/// </summary>
public class LogViewModel : PluginViewModelBase, ILogService
{
/// <summary>
/// 日志
/// </summary>
private static readonly ILog log = LogManager.GetLogger(typeof(LogViewModel));
/// <summary>
/// 日志视图模型
/// </summary>
public LogViewModel()
{
ApplicationDomainEx.ServiceManager.AddService(ServiceKeys.LOG_SERVICE, this);
}
// ==================================================================================
// Public Function
// ==================================================================================
/// <summary>
/// 添加日志
/// </summary>
/// <param name="log"></param>
public void AppendLog(string log)
{
WPFHelper.BeginInvoke(() =>
{
LogView view = this.GetView<LogView>();
if (view == null)
return;
view.tb.AppendText($"{log}\r\n");
});
}
/// <summary>
/// 清理日志
/// </summary>
public void ClearLog()
{
WPFHelper.BeginInvoke(() =>
{
LogView view = this.GetView<LogView>();
if (view == null)
return;
view.tb.Clear();
});
}
/// <summary>
/// 销毁
/// </summary>
public override void Dispose()
{
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment