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;} }
}

memcached+狀態模式+工廠方法使用的更多相关文章

  1. java-設計模式-工場方法

      工廠方法: 一种创建型设计模式, 其在父类中提供一个创建对象的方法, 允许子类决定实例化对象的类型. 定义一个创建产品对象的工厂接口,将产品对象的实际创建工作推迟到具体子工厂类当中. 这满足创建型 ...

  2. 簡單工廠模式-之-什麼是產品線 And 抽象工廠模式-之-什麼是產品族

    簡單工廠模式-之-什麼是產品線 簡單工廠模式中,有一個概念就是使用了多層次的產品結構,那麼什麼是產品結構或者說什麼是產品線? 假定我們有一個基準的產品標準Product,那麼所有繼承該基類或者傳遞基類 ...

  3. [實現DDD] 第11章 工廠

    創建過程中須考慮一些重要細節, 否則所創建的聚合將處於不正確的狀態, 使用適當的工廠方法可以確保這一點, 而客戶端只需輸入基本的參數(通常是值對象), 另外, 工廠能更好地表達出通用語言, 使團隊成員 ...

  4. Flater-Provide狀態管理

    參考來源:http://www.jspang.com/posts/2019/03/01/flutter-shop.html#%E7%AC%AC24%E8%8A%82%EF%BC%9Aprovide%E ...

  5. Win10還原成最乾淨的狀態 不必重灌

    系統不穩定時我們想到的第一個選擇就是重灌,如果你的作業系統是win10將會有另外一個新選擇,就是透過程式進行還原,讓你的電腦回到剛安裝時的清爽. 工具資訊 [軟體名稱]微軟 Refresh Windo ...

  6. Win10還原成最乾淨的狀態

    系統不穩定時我們想到的第一個選擇就是重灌,如果你的作業系統是win10將會有另外一個新選擇,就是透過程式進行還原,讓你的電腦回到剛安裝時的清爽. 工具資訊 [軟體名稱]微軟 Refresh Windo ...

  7. 組裝工廠設置IQC的目的

    在電子組裝工廠的組織裡,一般都會有 IQC (Incoming Quality Control) 這個單位,台灣稱之為「入(進)料管控」,大陸稱之為「來料管控」,其最主要目的在攔檢所有買進材料是否符合 ...

  8. [Gem] AASM 狀態機

    @(Ruby on Rails)[rails, gem] 1234 # AASM is a continuation of the acts-as-state-machine rails plugin ...

  9. 檢查RAC狀態

    1.使用srvctl工具檢查RAC當前配置和狀態 $ srvctl config database -h Displays the configuration for the database. Us ...

随机推荐

  1. 团队作业8——Beta 阶段冲刺5th day

    一.当天站立式会议 二.每个人的工作 (1)昨天已完成的工作(具体在表格中) 支付功能测试 (2)今天计划完成的工作(具体如下) 完善订单功能 (3)工作中遇到的困难(在表格中) 成员 昨天已完成的工 ...

  2. Swing-文本输入组件(一)

    Swing控件中,能够实现用户输入的有JTextField.JPasswordField.JTextArea和JTextPane.下面分别进行介绍. JTextField 最简单的文本控件,常见的登陆 ...

  3. Swing-setBorder()用法-入门

    注:本文内容转自:Swing编程边框(Border)的用法总结.内容根据笔者理解稍有整理. 函数说明: public void setBorder(Border border) 设置此组件的边框.Bo ...

  4. Java-高效地使用Exception-实践

    注:本文翻译自Exceptional practices,共分为3节.该文章从实践的角度非常透彻地解释了为什么要处理异常,以及如何处理异常.这些都是那些只会介绍trycatchfinally语法的教材 ...

  5. 201521123018 《Java程序设计》第12周学习总结

    1. 本章学习总结 你对于本章知识的学习总结 2. 书面作业 将Student对象(属性:int id, String name,int age,double grade)写入文件student.da ...

  6. 201521123030 《Java程序设计》 第10周学习总结

    1. 本周学习总结 2. 书面作业 本次PTA作业题集异常.多线程 1.finally 题目4-2 1.1 截图你的提交结果(出现学号) 1.2 4-2中finally中捕获异常需要注意什么? 在fi ...

  7. eclipse中svn插件在线安装方式

    SVN插件地址:http://subclipse.tigris.org/update_1.8.x 第一步:eclipse>Help菜单>Install New Software- 第二步: ...

  8. Java通过链表实现队列

    class LinkedQueue<T> { /** * 队列大小,由构造函数初始化 */ private int maxSize; /** * 队头 */ private Node fr ...

  9. 嵌入系统squashfs挂载常见问题总结

    由于squahsfs的一些优点,嵌入系统常常直接使用squashfs作为initrd挂载到/dev/ram,作为rootfs.这里对常见的一些问题进行一些分析. 1. kernel启动出现错误 RAM ...

  10. 使用Pano2VR 切割图片

    图片转换好之后得到一组立方体面片.