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 ...
随机推荐
- 团队作业8——第七天(beta阶段)
一.Daily Scrum Meeting照片 二.燃尽图 三.项目进展 学号 成员 贡献比 201421123001 廖婷婷 16% 201421123002 翁珊 17% 201421123004 ...
- 团队作业4——第一次项目冲刺(Alpha版本)4.22
团队作业4--第一次项目冲刺(Alpha版本) Day one: 会议照片 由于团队中的组员今天不在学校,所以我们的站立会议提前一天展开. 项目进展 由于今天是Alpha版本项目冲刺的第一天,所以没有 ...
- 201521123042 《Java程序设计》 第10周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常与多线程相关内容. 上周总结了异常,这周主要总结多线程. 2. 书面作业 本次PTA作业题集异常.多线程 1.finally 题 ...
- smarty文件夹,第一个smarty实例总结
主要是libs里面的smarty类,和init.inc.php配置文件 剩下的是php文件夹.模板文件夹,临时文件夹.缓存文件夹.配置文件夹.插件文件夹 调用main文件夹中的php文件,通过 ...
- 用Beautifulsoup 来爬取贴吧图片
import urllib.request import bs4 import re import os url="https://tieba.baidu.com/p/1988291937? ...
- headfirst设计模式(3)—装饰者模式
序 好久没写设计模式了,自从写了两篇之后,就放弃治疗了,主要还是工作太忙了啊(借口,都是借口),过完年以后一直填坑,填了好几个月,总算是稳定下来了,可以打打酱油了. 为什么又重新开始写设计模式呢?学习 ...
- 导航栏 .active激活
参考 :使用angularjs写一个导航栏控制器 1.点击其中一个li其他的class不影响 2.点击其中一个li其他的class影响 <!DOCTYPE html> <html l ...
- 逆向实用干货分享,Hook技术第一讲,之Hook Windows API
逆向实用干货分享,Hook技术第一讲,之Hook Windows API 作者:IBinary出处:http://www.cnblogs.com/iBinary/版权所有,欢迎保留原文链接进行转载:) ...
- 调用惯例Calling Convention (或者说:调用约定)
调用惯例影响执行效率,参数的传递方式以及栈清除的方式. 调用惯例 参数传递顺序 谁负责清除参数 参数是否使用暂存器 register 从左到右 被调用者 是 pascal 从左到右 被调用者 否 ...
- 替换应用程序DLL动态库的详细方法步骤 (gts.dll为例)
在C++ builder编译器IDE软件下 1.View -Project Manageer --找到需要替换的x.dll(gts.dll)对应的x.lib(gts.lib),然后Remove2.Pr ...