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 ...
随机推荐
- Simulink仿真入门到精通(十一) 模块的封装
当用户编写了自定义的S函数或者使用Simulink标准库中的模块搭建子系统后,可以通过封装为其设计显示外观,追加参数对话框. 封装是构建一个以对话框为接口的交互界面的过程,它将复杂的模块逻辑关系隐藏起 ...
- 如何找回微信小程序源码?2020年微信小程序反编译最新教程 小宇子李
前言:在网上看了找回微信小程序源码很多教程,都没法正常使用.微信版本升级后,会遇到各种报错, 以及无法获取到wxss的问题.查阅各种资料,最终解决,于是贴上完整的微信小程序反编译方案与教程. 本文章仅 ...
- C# datagridview 格式化单元格内容
private void dgvBig_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (dgvB ...
- (翻译) 使用Unity进行AOP对象拦截
Unity 是一款知名的依赖注入容器( dependency injection container) ,其支持通过自定义扩展来扩充功能. 在Unity软件包内 默认包含了一个对象拦截(Interce ...
- Python之open()函数
Python内置了读写文件的函数open(). # 方法一 # 使用Python内置的open()函数,传入文件名和标示符 f = open('E:/test/driver.py', 'r', enc ...
- jmeter3.3 接口压测入门和软件下载
Jmeter3.3软件下载地址 https://download.csdn.net/download/qq_36625806/11076556 简单的使用教程 1.启动Jmeter 双击jemeter ...
- hdu1045 炮台的配置 dfs
只要炮台在同一行或者同一列,就可以互相摧毁,遇到墙则无法对墙后的炮台造成伤害,可以通过dfs搜索n*n的方格,全部搜完算一轮,计算炮台数,并保存其最大值. 其中对于t编号的炮台,位置可以计算出是(t/ ...
- 使用Jenkins与Docker持续集成与发布NetCore项目(实操篇)
使用Jenkins与Docker持续集成与发布NetCore项目(教程一) 原文地址:https://www.cnblogs.com/Jackyye/p/12588182.html 基本环境 该教程的 ...
- tf.contrib.legacy_seq2seq.basic_rnn_seq2seq 函数 example 最简单实现
tf.contrib.legacy_seq2seq.basic_rnn_seq2seq 函数 example 最简单实现 函数文档:https://www.tensorflow.org/api_doc ...
- Ceph学习笔记(2)- CRUSH数据分布算法
前言: 分布式存储系统需要让数据均匀的分布在集群中的物理设备上,同时在新设备加入,旧设备退出之后让数据重新达到平衡状态尤为重要.新设备加入后,数据要从不同的老设备中迁移过来.老设备退出后,数据迁移 ...