|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Text;
|
|
|
using System.Windows.Forms;
|
|
|
using ICSharpCode.Core;
|
|
|
using Mesnac.PlugIn.View;
|
|
|
using Mesnac.Gui.Workbench;
|
|
|
using System.IO;
|
|
|
using ICSharpCode.Core;
|
|
|
using Mesnac.Core.Service;
|
|
|
using Mesnac.Basic;
|
|
|
using Mesnac.Gui.Run.Global;
|
|
|
using Mesnac.Gui.Common;
|
|
|
|
|
|
namespace Mesnac.Gui.Run.ViewContent
|
|
|
{
|
|
|
#region 通用功能定义
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 文件菜单
|
|
|
|
|
|
#region 系统工程配置
|
|
|
/// <summary>
|
|
|
/// 系统工程配置
|
|
|
/// </summary>
|
|
|
public class SysConfigCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
IViewContent frmSysConfig = null;
|
|
|
IWorkbenchWindow window = WorkbenchSingleton.Workbench.GetViewByType(typeof(FrmSysConfig));
|
|
|
if (window != null)
|
|
|
{
|
|
|
frmSysConfig = window.ViewContent;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
frmSysConfig = new FrmSysConfig();
|
|
|
}
|
|
|
WorkbenchSingleton.Workbench.ShowView(frmSysConfig);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 刷新自定义插件
|
|
|
/// <summary>
|
|
|
/// 刷新自定义插件
|
|
|
/// </summary>
|
|
|
public class RefreshPlugInCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
WorkbenchSingleton.Workbench.RefreshPlugIn();
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 全屏切换
|
|
|
/// <summary>
|
|
|
/// 全屏切换
|
|
|
/// </summary>
|
|
|
public class ToggleFullscreenCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
WorkbenchSingleton.Workbench.FullScreen = !WorkbenchSingleton.Workbench.FullScreen;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 退出应用程序
|
|
|
/// <summary>
|
|
|
/// 退出应用程序
|
|
|
/// </summary>
|
|
|
public class ExitCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
string caption = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_Caption"));
|
|
|
string msg = StringParser.Parse(ResourceService.GetString("Dialog_MessageBox_ExtAsk"));
|
|
|
DialogResult result = MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
|
if (result == DialogResult.Yes)
|
|
|
{
|
|
|
WorkbenchSingleton.Workbench.CloseFlag = false; //设置系统关闭标识
|
|
|
(WorkbenchSingleton.Workbench as System.Windows.Forms.Form).Close();
|
|
|
Application.ExitThread();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 测试命令
|
|
|
|
|
|
public class TestCommand : AbstractCommand
|
|
|
{
|
|
|
|
|
|
public override void Run()
|
|
|
{
|
|
|
LoggingService.Debug("测试命令执行..." + this.Owner.ToString());
|
|
|
LoggingService.Debug("RoleId = " + UserInfo.Instance.RoleID);
|
|
|
LoggingService.Debug("UserId = " + UserInfo.Instance.UserID);
|
|
|
LoggingService.Debug("UserName = " + UserInfo.Instance.UserName);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 测试 资源回收
|
|
|
/// <summary>
|
|
|
/// 资源回收
|
|
|
/// </summary>
|
|
|
public class ReleaseResourceCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
//System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(this.Release));
|
|
|
string[] keys = new string[WorkbenchSingleton.Workbench.ViewContentDic.Keys.Count];
|
|
|
WorkbenchSingleton.Workbench.ViewContentDic.Keys.CopyTo(keys, 0);
|
|
|
foreach (string key in keys)
|
|
|
{
|
|
|
IViewContent content = WorkbenchSingleton.Workbench.ViewContentDic[key];
|
|
|
WorkbenchSingleton.Workbench.ViewContentDic.Remove(key);
|
|
|
IWorkbenchWindow window = content.MyOwner as IWorkbenchWindow;
|
|
|
//content.IsRealClose = true;
|
|
|
//content.Dispose();
|
|
|
window.CloseWindow(true);
|
|
|
}
|
|
|
//WorkbenchSingleton.Workbench.ViewContentDic.Clear();
|
|
|
System.GC.Collect();
|
|
|
LoggingService.Debug("垃圾回收执行...");
|
|
|
LoggingService.Debug("当前组态工程ViewContent数量:" + WorkbenchSingleton.Workbench.ViewContentDic.Count);
|
|
|
}
|
|
|
|
|
|
public void Release(object obj)
|
|
|
{
|
|
|
string[] keys = new string[WorkbenchSingleton.Workbench.ViewContentDic.Keys.Count];
|
|
|
WorkbenchSingleton.Workbench.ViewContentDic.Keys.CopyTo(keys, 0);
|
|
|
foreach (string key in keys)
|
|
|
{
|
|
|
IViewContent content = WorkbenchSingleton.Workbench.ViewContentDic[key];
|
|
|
WorkbenchSingleton.Workbench.ViewContentDic.Remove(key);
|
|
|
IWorkbenchWindow window = content.MyOwner as IWorkbenchWindow;
|
|
|
content.IsRealClose = true;
|
|
|
content.Dispose();
|
|
|
window.CloseWindow(true);
|
|
|
}
|
|
|
//WorkbenchSingleton.Workbench.ViewContentDic.Clear();
|
|
|
System.GC.Collect();
|
|
|
LoggingService.Debug("垃圾回收执行...");
|
|
|
LoggingService.Debug("当前组态工程ViewContent数量:" + WorkbenchSingleton.Workbench.ViewContentDic.Count);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 菜单项启用、禁用操作(权限控制)
|
|
|
|
|
|
/// <summary>
|
|
|
/// 刷新插件、工程配置权限控制(只允许管理员操作)
|
|
|
/// </summary>
|
|
|
public class MCRunSuperConditionEvaluator : IConditionEvaluator
|
|
|
{
|
|
|
public bool IsValid(object owner, ICSharpCode.Core.Condition condition)
|
|
|
{
|
|
|
//如果是超级管理员或没经过登录(独立运行)则可用
|
|
|
if (UserInfo.Instance.RoleID == "-99" || UserInfo.Instance.RoleID == "-1")
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
}
|