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 ...
随机推荐
- scrapy中间件中使用selenium切换ip
scrapy抓取一些需要js加载页面时一般要么是通过接口直接获取数据,要么是js加载,但是我通过selenium也可以获取动态页面 但是有个问题,容易给反爬,因为在scrapy中间件mid中使用sel ...
- python基础学习day7
基础数据类型的补充:编码的进阶 str capitalize() 首字母(第一个单词)大写,其余变小写 s1 = 'I LIVE YOU' print(s1.capitalize()) >> ...
- SyntaxError: unexpected character after line continuation character
SyntaxError: unexpected character after line continuation character 待解决问题:在运行.py文件时报错SyntaxError: un ...
- 【SpringBoot基础系列-实战】如何指定 bean 最先加载(应用篇)
[基础系列-实战]如何指定 bean 最先加载(应用篇) 在日常的业务开发中,绝大多数我们都是不关注 bean 的加载顺序,然而如果在某些场景下,当我们希望某个 bean 优于其他的 bean 被实例 ...
- 谈谈一些逻辑相同,性能差异却很大的sql
总结写在前面: 1. 本篇讲述了三个例子,其本质都是揭示了若对索引字段做函数操作,可能会破坏索引值的有序性,由此优化器就决定放弃走树搜索功能. 2. 由第1点提供了一个优化思路,即我们能否避免或转化s ...
- File判断功能(新手)
//导入的一个类.import java.io.File;/* File判断功能*///创建的一个类.public class zylx3 { //公共静态的主方法. public static vo ...
- 2018 巅峰极客CTF misc writeup
flows 拿到一个pcap包,用wireshark打开,发现是USB协议,尝试在kali下使用tshark提取,提取失败,发现异常.回到wireshark分析数据.在其中一个数据包中发现了tip 把 ...
- MySQL windows中的存储备份
数据备份对于经常在运维部署方面的工作者来说,是一件相对简单的事情,都可以通过某一个SQL工具进行备份,但是如果在项目运行当中,我们需要对数据进行实时,或者是每隔一星期,一个月,等等进行数据的备份,这样 ...
- Peek和Pop功能开发(3D Touch开发之一)
1.哪些设备支持3D Touch iPhone 6s/Plus.iPhone 7s/Plus.iPhone 8s/Plus.iPhone X (系统必须是iOS9或者更新的版本) 2.怎么实现Peek ...
- Flutter 实现不同样式(有样式) 的TextField (可自定义),类似微博#话题#、@用户,(给TextField加TextSpan)
描述 先上效果图 在项目中,有 @ 和 话题功能,需要在编辑时即可回显,但是官方原生的TextField不支持对部分文字定义不同的样式,所以封装了一个. 注意:这不是富文本插件,不支持在输入框中显示图 ...