memcached+狀態模式+工廠方法使用
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+狀態模式+工廠方法使用的更多相关文章
- java-設計模式-工場方法
工廠方法: 一种创建型设计模式, 其在父类中提供一个创建对象的方法, 允许子类决定实例化对象的类型. 定义一个创建产品对象的工厂接口,将产品对象的实际创建工作推迟到具体子工厂类当中. 这满足创建型 ...
- 簡單工廠模式-之-什麼是產品線 And 抽象工廠模式-之-什麼是產品族
簡單工廠模式-之-什麼是產品線 簡單工廠模式中,有一個概念就是使用了多層次的產品結構,那麼什麼是產品結構或者說什麼是產品線? 假定我們有一個基準的產品標準Product,那麼所有繼承該基類或者傳遞基類 ...
- [實現DDD] 第11章 工廠
創建過程中須考慮一些重要細節, 否則所創建的聚合將處於不正確的狀態, 使用適當的工廠方法可以確保這一點, 而客戶端只需輸入基本的參數(通常是值對象), 另外, 工廠能更好地表達出通用語言, 使團隊成員 ...
- Flater-Provide狀態管理
參考來源:http://www.jspang.com/posts/2019/03/01/flutter-shop.html#%E7%AC%AC24%E8%8A%82%EF%BC%9Aprovide%E ...
- Win10還原成最乾淨的狀態 不必重灌
系統不穩定時我們想到的第一個選擇就是重灌,如果你的作業系統是win10將會有另外一個新選擇,就是透過程式進行還原,讓你的電腦回到剛安裝時的清爽. 工具資訊 [軟體名稱]微軟 Refresh Windo ...
- Win10還原成最乾淨的狀態
系統不穩定時我們想到的第一個選擇就是重灌,如果你的作業系統是win10將會有另外一個新選擇,就是透過程式進行還原,讓你的電腦回到剛安裝時的清爽. 工具資訊 [軟體名稱]微軟 Refresh Windo ...
- 組裝工廠設置IQC的目的
在電子組裝工廠的組織裡,一般都會有 IQC (Incoming Quality Control) 這個單位,台灣稱之為「入(進)料管控」,大陸稱之為「來料管控」,其最主要目的在攔檢所有買進材料是否符合 ...
- [Gem] AASM 狀態機
@(Ruby on Rails)[rails, gem] 1234 # AASM is a continuation of the acts-as-state-machine rails plugin ...
- 檢查RAC狀態
1.使用srvctl工具檢查RAC當前配置和狀態 $ srvctl config database -h Displays the configuration for the database. Us ...
随机推荐
- 个人作业1——四则运算题目生成程序(基于C++)
题目描述: 从<构建之法>第一章的 "程序" 例子出发,像阿超那样,花二十分钟写一个能自动生成小学四则运算题目的命令行 "软件",满足以下需求: 1 ...
- Java学习7——一些注意的地方
(学习运算符.if和switch分支.for与while与do...while循环.break和continue.递归,内容和C++没差,挑了几个注意点) 运算符 逻辑与(&)和短路与(&am ...
- 201521123051《Java程序设计》第八周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 集合与泛型综合示例 import java.util.ArrayLis ...
- 201521123114《Java程序设计》第1周学习总结
1. 本周学习总结 java语言具有:简约且简单,平台无关性,面向对象,多线程.分布性.高性能.健壮性等特点. 2. 书面作业 1.为什么java程序可以跨平台运行?执行java程序的步骤是什么? J ...
- windows消息机制与实例
windows发送窗口消息 所需工具:spy++,visual studio 2017,c#语言 技术路线:首先通过spy++获得所要操纵的窗口的句柄,函数的原型声明为: [DllImport(&qu ...
- 201521123078 《Java程序设计》第14周学习总结
1. 本周学习总结 2. 书面作业 1. MySQL数据库基本操作 建立数据库,将自己的姓名.学号作为一条记录插入.(截图,需出现自己的学号.姓名) 在自己建立的数据库上执行常见SQL语句(截图) 2 ...
- 201521123119《Java程序设计》第12周学习总结
1. 本周学习总结 Q1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doub ...
- Sublime自定义语法
以thinkphp框架的assign函数为例 在sublime\Data\Packages\PHP下 新建文件:assign.sublime-snippet 内容为 <snippet> & ...
- python之并发编程之多进程
一.共享数据 进程间通信应该尽量避免使用本节所讲的共享数据方式 from multiprocessing import Manager,Process,Lock def work(dic,mutex) ...
- Could not execute JDBC batch update; SQL [delete from role where roleId=?]; constraint [null]; neste
今天在写多个删除功能的时候出现了这么一个错误:意思是删除操作的时候,没有找到对应的外键. Cannot delete or update a parent row: a foreign key con ...