MES Auto Logout
如果您在车间使用MES,可能存在这种情况有人在仍然登录的情况下偶尔离开终端。如果一段时间不使用终端,我们是否可以让用户自动注销。
1 首先,我们有一条using语句:
using System.Runtime.InteropServices
2 添加2个新类。
public class IdleEventArgs : EventArgs {
private DateTime m_EventTime;
public DateTime EventTime {
get {
return m_EventTime;
}
}
public IdleEventArgs(DateTime timeOfEvent) {
m_EventTime = timeOfEvent;
}
}
public class SystemIdleTimer : Component
{
private const double INTERNAL_TIMER_INTERVAL = 550;
[Description("Event that if fired when idle state is entered.")]
public event OnEnterIdleStateEventHandler OnEnterIdleState;
public delegate void OnEnterIdleStateEventHandler(object sender, IdleEventArgs e);
[Description("Event that is fired when leaving idle state.")]
public event OnExitIdleStateEventHandler OnExitIdleState;
public delegate void OnExitIdleStateEventHandler(object sender, IdleEventArgs e);
private System.Timers.Timer ticker;
private int m_MaxIdleTime;
private object m_LockObject;
private bool m_IsIdle = false;
[Description("Maximum idle time in seconds.")]
public int MaxIdleTime {
get { return m_MaxIdleTime; }
set {
if (value == 0) {
throw new ArgumentException("MaxIdleTime must be larger then 0.");
} else {
m_MaxIdleTime = value;
}
}
}
public SystemIdleTimer()
{
m_LockObject = new object();
ticker = new System.Timers.Timer(INTERNAL_TIMER_INTERVAL);
ticker.Elapsed += InternalTickerElapsed;
}
public void Start()
public void Stop()
{
ticker.Stop();
lock (m_LockObject) {
m_IsIdle = false;
}
}
public bool IsRunning {
get { return ticker.Enabled; }
}
private void InternalTickerElapsed(object sender, System.Timers.ElapsedEventArgs e)
{
uint idleTime = Win32Wrapper.GetIdle();
if (idleTime > (MaxIdleTime * 1000)) {
if (m_IsIdle == false) {
lock (m_LockObject) {
m_IsIdle = true;
}
IdleEventArgs args = new IdleEventArgs(e.SignalTime);
if (OnEnterIdleState != null) {
OnEnterIdleState(this, args);
}
}
} else {
if (m_IsIdle) {
lock (m_LockObject) {
m_IsIdle = false;
}
IdleEventArgs args = new IdleEventArgs(e.SignalTime);
if (OnExitIdleState != null) {
OnExitIdleState(this, args);
}
}
}
}
}
public class Win32Wrapper
{
public struct LASTINPUTINFO
{
public uint cbSize;
public uint dwTime;
}
[DllImport("User32.dll")]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO lii);
public static uint GetIdle()
{
LASTINPUTINFO lii = new LASTINPUTINFO();
lii.cbSize = Convert.ToUInt32((Marshal.SizeOf(lii)));
GetLastInputInfo(ref lii);
return Convert.ToUInt32(Environment.TickCount) - lii.dwTime;
}
}
3 声明一新计时器对象的实例:
SystemIdleTimer idleTimer = new SystemIdleTimer();
4 添加事件以处理用户何时空闲以及何时返回:
private void idleTimer_OnEnterIdleState(object sender, IdleEventArgs args)
{
// This is where you put the code to deal with when the session has been detected
// as entering an idle state
MessageBox.Show("Get back to work Adam!");
idleTimer.Start();
}
private void idleTimer_OnExitIdleState(object sender, IdleEventArgs args)
{
// This is where you put the code for when the session was idle and now has
// been re-activated. You might not need this for anything, but thought
// it would be good to point out.
MessageBox.Show("Good boy");
idleTimer.Start();
}
5 在表格加载时,将这些事件连接起来,并定义不活动的秒数,也可以根据具体情况进行调整:
private void MESMenu_Load(object sender, EventArgs args)
{
idleTimer.OnEnterIdleState += new SystemIdleTimer.OnEnterIdleStateEventHandler(idleTimer_OnEnterIdleState);
idleTimer.OnExitIdleState += new SystemIdleTimer.OnExitIdleStateEventHandler(idleTimer_OnExitIdleState);
idleTimer.MaxIdleTime = 10; // Seconds
idleTimer.Start();
}
6 最后,清理要处置的对象:
public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal
// End Wizard Added Object Disposal
// Begin Custom Code Disposal
idleTimer.OnEnterIdleState -= new SystemIdleTimer.OnEnterIdleStateEventHandler(idleTimer_OnEnterIdleState);
idleTimer.OnExitIdleState -= new SystemIdleTimer.OnExitIdleStateEventHandler(idleTimer_OnExitIdleState);
idleTimer.Dispose();
// End Custom Code Disposal
}
现在您可以将此客制化保存到MES,运行它。如果10秒不移动鼠标会提醒您"Get Back To Work Adam", 只要您移动鼠标会提示"Good boy":

7 更新了OnEnterIdleState逻辑以调用LogOut,LogOut只是获取对按钮的引用并单击它:
private void idleTimer_OnEnterIdleState(object sender, IdleEventArgs args)
{
// This is where you put the code to deal with when the session has been detected
// as entering an idle state
this.LogOut();
idleTimer.Start();
}
private void LogOut()
{
EpiButton btnLogOut = (EpiButton)csm.GetNativeControlReference("a2f6e795-4ab3-4121-bce4-e1d5f0881b0a");
btnLogOut.PerformClick();
} // LogOut()
如果这个博客对您有帮助,请帮忙给评论,谢谢!
如果您正在看这个并且意识到自己想要类似的东西,请联系我,谢谢!
MES Auto Logout的更多相关文章
- 关于linux系统安全配置脚本
本脚本是第二次更新,已经大量应用在某大型媒体网站体系中,加入了之前没有想到的一些安全设置.使用方法将其复制,保存为一个shell文件,比如security.sh.将其上传到Linux服务器上,执行sh ...
- RZ10
设定一些系统参数 例如在生成table maintenance的时候 由于表格结构复杂 导致生成维护程序时 超出了默认的内存限制 这时候可以通过RZ10 修改 zzta/dynpro_area ...
- linux运维安全工具集合[持续更新中..]
lynis 安全漏洞检测工具 https://cisofy.com/download/lynis/ https://cisofy.com/files/lynis-2.2.0.tar.gz ...
- Linux的系统安全设置Shell脚本
#!/bin/sh # desc: setup linux system security # powered by www.lvtao.net #account setup passwd -l xf ...
- I fullly understand why can not set "auto commit off" in sqlserver
This is xxxxx Because MES guy mistaken , the data was wrong and made system error then. After that I ...
- C++11特性——变量部分(using类型别名、constexpr常量表达式、auto类型推断、nullptr空指针等)
#include <iostream> using namespace std; int main() { using cullptr = const unsigned long long ...
- overflow:hidden与margin:0 auto之间的冲突
相对于父容器水平居中的代码margin:0 auto与overflow:hidden之间存在冲突.当这两个属性同时应用在一个DIV上时,在chrome浏览器中将无法居中.至于为啥我也不明白.
- Android Auto开发之一《开始学习Auto 》
共同学习,共同进步, 转载请注明出处.欢迎微信交流:sfssqs,申请注明"Android Car"字样 ================= =================== ...
- width:100%;与width:auto;的区别
<div> <p>1111</p> </div> div{ width:980px; background-color: #ccc; height:30 ...
随机推荐
- R中的Regex
Description grep.grepl.regexpr.gregexpr和regexec在字符向量的每个元素中搜索与参数模式匹配的参数:它们在结果的格式和详细程度上有所不同. sub和gsub分 ...
- Vue2.0 【第二季】第9节 Component 标签
目录 Vue2.0 [第二季]第9节 Component 标签 第9节 Component 标签 1.我们先在构造器外部定义三个不同的组件,分别是componentA,componentB和compo ...
- [POI2017]bzoj4726 Sadota?
题目描述 离线题库请 题目描述 某个公司有\(n\)个人, 上下级关系构成了一个有根树.其中有个人是叛徒(这个人不知道是谁).对于一个人, 如果他 下属(直接或者间接, 不包括他自己)中叛徒占的比例超 ...
- S3C2440A特殊寄存器
S3C2440A特殊寄存器 特殊寄存器有: 输入输出端口 存储器控制器 NANDFLASH 看门狗定时器 时钟和电源管理 PWM定时器 UART USB设备 中断控制器 DMA LCD控制器 RTC ...
- PostgreSQL查询表以及字段的备注
目录 查询所有表名称以及字段含义 查看所有表名 查看表名和备注 查看特定表名备注 查看特定表名字段 查询所有表名称以及字段含义 select c.relname 表名,cast(obj_descrip ...
- win10环境下如何修改Python pip的更新源?
1.在window的文件夹窗口输入 : %APPDATA%2.在弹出的路径中新建pip文件夹,然后到pip文件夹里面去新建个pip.ini文件,然后再里面输入内容 [global] timeout = ...
- WEB应用之httpd基础入门(一)
前文我们聊了下http协议web服务的一些常识和httpd服务器软件三种响应模型的简单介绍,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/12515075.ht ...
- Vysor Pro1.9.3破解,连接 USB 数据线在电脑上远程控制 Android 手机平板/同步显示画面
Vysor PRO 破解方法 1.下载Vysor Pro, Vysor Pro下载地址 ,chrome版需要挂梯子. 下载后,能连接,但是清晰度太低,能使用的功能也很少,下面我们就开始来破解它. ...
- 【简说Python WEB】pyechart在flask中的应用
个人笔记总结,可读性不高.只为自己总结用.怕日后忘记. 这里用到了tushare,pandas等python组件. pyechart的案例 c = ( Bar() .add_xaxis([" ...
- Spring03——有关于 Spring AOP 的总结
本文将为各位带来 Spring 的另一个重点知识点 -- Spring AOP.关注我的公众号「Java面典」,每天 10:24 和你一起了解更多 Java 相关知识点. 什么是 AOP 面向切面编程 ...