首页 技术 正文
技术 2022年11月16日
0 收藏 554 点赞 2,602 浏览 4039 个字
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace memcached
{
public interface IStates
{
bool PreProduction(Context context,string FlowNo); //上機
bool PostProduction(Context context, string FlowNo);//下機
bool MaterialImput(Context context, string FlowNo);//物料錄入
} public class Context
{
public Context(IStates state)
{
this.currentState = state;
} private string FlowNo; public string flowno {
get { return FlowNo; }
set { FlowNo = value; }
} private IStates currentState;
public IStates CurrentState
{
//set
//{
// currentState = value;
//} get { return currentState; }
set { currentState = value; }
} /// <summary>
/// 执行動作
/// </summary>
public virtual bool PreProduction() { return this.currentState.PreProduction(this, flowno); }
public virtual bool PostProduction() { return this.currentState.PostProduction(this,flowno); }
public virtual bool MaterialImput() { return this.currentState.MaterialImput(this,flowno); }
} /// <summary>
/// 空閒
/// </summary>
public class OpenState : IStates
{
public bool PreProduction(Context context,string flowno)
{
Console.WriteLine("FLOW卡上機成功");
AMemcached.cache.Replace(flowno, "Opening");
return true; } public bool PostProduction(Context context, string flowno)
{
Console.WriteLine("FLOW卡還未物料錄入,無法下機");
return false;
} public bool MaterialImput(Context context,string flowno)
{
Console.WriteLine("FLOW卡未上機不能進行物料錄入");
return false;
}
} /// <summary>
/// 完成
/// </summary>
public class CloseState : IStates
{
public bool PreProduction(Context context,string flowno)
{
Console.WriteLine("FLOW卡正在上機中,無法重複上機");
return false;
} public bool PostProduction(Context context, string flowno)
{
Console.WriteLine("物料已錄入,成功下機");
//context.CurrentState = new OpenState();
AMemcached.cache.Replace(flowno, "OpenState");
var stateq = AMemcached.cache.Get(flowno);
return true;
} public bool MaterialImput(Context context, string flowno)
{
Console.WriteLine("物料已錄入,無法重複錄入");
return false;
}
} /// <summary>
/// 生產中
/// </summary>
public class Opening : IStates
{
public bool PreProduction(Context context,string flowno)
{
Console.WriteLine("FLOW卡正在上機中,無法重複上機");
return false;
} public bool PostProduction(Context context, string flowno)
{
Console.WriteLine("物料還未錄入,無法下機");
return false;
} public bool MaterialImput(Context context, string flowno)
{
Console.WriteLine("FLOW已上機,物料成功錄入");
// context.CurrentState = new CloseState();
AMemcached.cache.Replace(flowno, "CloseState");
var stateq = AMemcached.cache.Get(flowno);
return true;
}
}
}
using Memcached.ClientLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace memcached
{
class Program
{
static void Main(string[] args)
{
var state = AMemcached.cache.Get(DJ);
Context check = new Context(Activator.CreateInstance(Type.GetType("memcached"+"."+ state)) as IStates);
check.flowno = DJ;
check.PreProduction();//上機 var states = AMemcached.cache.Get(DJ);
check = new Context(Activator.CreateInstance(Type.GetType("memcached" + "." + states)) as IStates);
check.flowno = DJ;
check.PostProduction();//下機 var statee = AMemcached.cache.Get(DJ);
check = new Context(Activator.CreateInstance(Type.GetType("memcached" + "." + statee)) as IStates);
check.flowno = DJ;
check.MaterialImput();//物料錄入 Console.ReadKey();
}
} public class AMemcached
{
public static MemcachedClient cache;
static AMemcached()
{
string[] servers = { "192.168.1.18:11211" };
//初始化池
SockIOPool pool = SockIOPool.GetInstance();
//设置服务器列表
pool.SetServers(servers);
//各服务器之间负载均衡的设置比例
pool.SetWeights(new int[] { });
//初始化时创建连接数
pool.InitConnections = ;
//最小连接数
pool.MinConnections = ;
//最大连接数
pool.MaxConnections = ;
//连接的最大空闲时间,下面设置为6个小时(单位ms),超过这个设置时间,连接会被释放掉
pool.MaxIdle = * * * ;
//socket连接的超时时间,下面设置表示不超时(单位ms),即一直保持链接状态
pool.SocketConnectTimeout = ;
//通讯的超市时间,下面设置为3秒(单位ms),.Net版本没有实现
pool.SocketTimeout = * ;
//维护线程的间隔激活时间,下面设置为30秒(单位s),设置为0时表示不启用维护线程
pool.MaintenanceSleep = ;
//设置SocktIO池的故障标志
pool.Failover = true;
//是否对TCP/IP通讯使用nalgle算法,.net版本没有实现
pool.Nagle = false;
//socket单次任务的最大时间(单位ms),超过这个时间socket会被强行中端掉,当前任务失败。
pool.MaxBusy = * ;
pool.Initialize();
cache = new MemcachedClient();
//是否启用压缩数据:如果启用了压缩,数据压缩长于门槛的数据将被储存在压缩的形式
cache.EnableCompression = false;
//压缩设置,超过指定大小的都压缩
//cache.CompressionThreshold = 1024 * 1024;
}
} [Serializable]
public class MpsFlowData
{
public string productno { get; set; }
public string seqno { get; set; }
public string keyno { get; set; }
public string state { get; set;} }
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,487
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,487
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289