public async Task Add(SQueue queue, SMessage message) { var crmService = await getCrmService(queue.ServerName); CrmExecuteEntity entity = new CrmExecuteEntity(queue.Name, message.ID) { IsActivity = false, Attributes = new Dictionary <string, object>() { { "ms_name", message.Key }, { "ms_type", message.Type }, { "ms_data", message.Data }, { "ms_delaymessageid", message.DelayMessageID?.ToString() }, { "ms_exceptionmessage", message.ExceptionMessage }, { "ms_expectationexecutetime", message.ExpectationExecuteTime }, { "ms_extensionmessage", message.ExtensionMessage }, { "ms_lastexecutetime", message.LastExecuteTime }, { "ms_retrynumber", message.RetryNumber }, { "ms_isdead", message.IsDead }, } }; var newID = await crmService.Create(entity); message.ID = newID; }
public async Task UpdateLastExecuteTime(SQueue queue, Guid id) { //根据存储类型和服务器名称获取连接字符串 var strConn = _messageQueueConnectionFactory.CreateAllForMessageQueue(queue.StoreType, queue.ServerName); await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, false, false, strConn, async (conn, transaction) => { SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } await using (SqlCommand commond = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, Transaction = sqlTran, CommandText = string.Format(@"update {0} set [lastexecutetime]=getutcdate() where [id]=@id", queue.Name) }) { SqlParameter parameter; parameter = new SqlParameter("@id", SqlDbType.UniqueIdentifier) { Value = id }; commond.Parameters.Add(parameter); await commond.PrepareAsync(); await commond.ExecuteNonQueryAsync(); } }); }
public Form1() { InitializeComponent(); space = new XcoSpace(8000); // Example of builing a new XcoQueue with the SQueue wrapper. // To notifications are added, the first for debugging purpose, the second for keeping track of the occupancy. SQueue<Ei> unbemalteEier = new SQueue<Ei>(space, "UnbemalteEier"); unbemalteEier.queue.AddNotificationForEntryEnqueued(this.unbemalteEierCB); unbemalteEier.count.AddNotificationForEntryEnqueued(this.unbemalteEierNotifyCB); SQueue<Ei> bemalteEier = new SQueue<Ei>(space, "BemalteEier"); bemalteEier.queue.AddNotificationForEntryEnqueued(this.bemalteEierCB); bemalteEier.count.AddNotificationForEntryEnqueued(this.bemalteEierNotifyCB); SQueue<SchokoHase> schokoHasen = new SQueue<SchokoHase>(space, "SchokoHasen"); schokoHasen.queue.AddNotificationForEntryEnqueued(this.schokoHasenCB); schokoHasen.count.AddNotificationForEntryEnqueued(this.schokoHasenNotifyCB); SQueue<Nest> nester = new SQueue<Nest>(space, "Nester"); nester.queue.AddNotificationForEntryEnqueued(this.nesterCB); nester.count.AddNotificationForEntryEnqueued(this.nesterNotifyCB); SQueue<Nest> geliefert = new SQueue<Nest>(space, "Ausgeliefert"); geliefert.queue.AddNotificationForEntryEnqueued(this.ausgeliefertCB); geliefert.count.AddNotificationForEntryEnqueued(this.ausgeliefertNotifyCB); space_uri = new Uri("xco://127.0.0.1:8000"); }
/// <summary> /// 复制(潜拷贝) /// </summary> protected override void toShadowCopy(BaseData data) { if (!(data is SystemPartData)) { return; } SystemPartData mData = (SystemPartData)data; this.version = mData.version; this.serverTime = mData.serverTime; this.isBlock = mData.isBlock; this.flowStep = mData.flowStep; this.keepSave = mData.keepSave; this.clientRandomSeeds = mData.clientRandomSeeds; this.clientRandomSeedIndex = mData.clientRandomSeedIndex; this.clientOfflineWorkReceiveIndex = mData.clientOfflineWorkReceiveIndex; this.gmCommandSet = mData.gmCommandSet; this.gmType = mData.gmType; this.serverBornCode = mData.serverBornCode; this.serverStartTime = mData.serverStartTime; this.logQueue = mData.logQueue; this.nextDailyTime = mData.nextDailyTime; this.createDate = mData.createDate; this.clientRandomSeedKey = mData.clientRandomSeedKey; }
/// <summary> /// 读取字节流(简版) /// </summary> protected override void toReadBytesSimple(BytesReadStream stream) { this.id = stream.readInt(); this.price = stream.readInt(); int daysLen = stream.readLen(); if (this.days != null) { this.days.clear(); this.days.ensureCapacity(daysLen); } else { this.days = new SQueue <CountData>(); } SQueue <CountData> daysT = this.days; for (int daysI = daysLen - 1; daysI >= 0; --daysI) { CountData daysV; daysV = (CountData)stream.readDataSimpleNotNull(); daysT.offer(daysV); } }
public async Task AddToDead(SQueue queue, SMessage message) { if (!queue.IsDead) { throw new Exception(string.Format("SQueue {0}.{1} is not dead, can't be used in SMessageStoreForSQLDB.AddToDead", queue.GroupName, queue.Name)); } var crmService = await getCrmService(queue.ServerName); CrmExecuteEntity entity = new CrmExecuteEntity(queue.Name, message.ID) { IsActivity = false, Attributes = new Dictionary <string, object>() { { "ms_name", message.Key }, { "ms_type", message.Type }, { "ms_data", message.Data }, { "ms_delaymessageid", message.DelayMessageID?.ToString() }, { "ms_exceptionmessage", message.ExceptionMessage }, { "ms_expectationexecutetime", message.ExpectationExecuteTime }, { "ms_extensionmessage", message.ExtensionMessage }, { "ms_lastexecutetime", null }, { "ms_retrynumber", 0 }, { "ms_isdead", true }, } }; var newID = await crmService.Create(entity); message.ID = newID; }
public async Task AddRetry(SQueue queue, Guid id, string exceptionMessage) { var crmService = await getCrmService(queue.ServerName); CrmRetrieveSignleAttributeRequestMessage request = new CrmRetrieveSignleAttributeRequestMessage() { EntityName = queue.Name, EntityId = id, AttributeName = "ms_retrynumber" }; var response = (CrmRetrieveSignleAttributeResponseMessage)await crmService.Execute(request); var objRetry = response.Value.ToObject <int?>(); int retry = 0; if (objRetry.HasValue) { retry = objRetry.Value; } CrmExecuteEntity entity = new CrmExecuteEntity(queue.Name, id) { IsActivity = false, Attributes = new Dictionary <string, object>() { { "ms_retrynumber", retry++ }, } }; await crmService.Update(entity); }
public void TestEnqueue() { SQueue queue = new SQueue(new Node(0)); Node testNode = new Node(100); queue.Enqueue(testNode); Assert.Equal(testNode, queue.Peek().Next); }
public async Task <SQueue> QueryByCode(string groupName, bool isDead, int code) { SQueue queue = null; await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _messageQueueConnectionFactory.CreateReadForMessageQueueMain(), async (conn, transaction) => { SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } await using (SqlCommand commond = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, Transaction = sqlTran, CommandText = string.Format(@"select {0} from SQueue where [groupname]=@groupname and [code]=@code and [isdead]=@isdead", StoreHelper.GetSQueueSelectFields(string.Empty)) }) { var parameter = new SqlParameter("@groupname", SqlDbType.VarChar, 150) { Value = groupName }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@code", SqlDbType.Int) { Value = code }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@isdead", SqlDbType.Bit) { Value = isDead }; commond.Parameters.Add(parameter); await commond.PrepareAsync(); SqlDataReader reader = null; await using (reader = await commond.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { queue = new SQueue(); StoreHelper.SetSQueueSelectFields(queue, reader, string.Empty); } await reader.CloseAsync(); } } }); return(queue); }
public void TestDequeue() { Node testNode1 = new Node(100); Node testNode2 = new Node(999); SQueue queue = new SQueue(testNode1); queue.Enqueue(testNode2); Assert.True(queue.Dequeue() == testNode1 && queue.Peek() == testNode2); }
/// <summary> /// 初始化初值 /// </summary> public override void initDefault() { this.version = new SaveVersionData(); this.version.initDefault(); this.keepSave = new KeepSaveData(); this.keepSave.initDefault(); this.logQueue = new SQueue <InfoLogData>(); this.createDate = new DateData(); this.createDate.initDefault(); }
public async Task <SMessage> QueryByKeyAndBeforeExpectTime(SQueue queue, string key, DateTime expectTime) { SMessage message = null; //根据存储类型和服务器名称获取连接字符串 var strConn = _messageQueueConnectionFactory.CreateReadForMessageQueue(queue.StoreType, queue.ServerName); await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, strConn, async (conn, transaction) => { SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } await using (SqlCommand commond = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, Transaction = sqlTran, CommandText = string.Format(@"select top 1 {0} from {1} where [key]=@key and [expectationexecutetime]<@expectationexecutetime ", StoreHelper.GetSMessageSelectFields(string.Empty), queue.Name) }) { var parameter = new SqlParameter("@key", SqlDbType.VarChar, 150) { Value = key }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@expectationexecutetime", SqlDbType.DateTime) { Value = expectTime }; commond.Parameters.Add(parameter); await commond.PrepareAsync(); SqlDataReader reader = null; await using (reader = await commond.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { message = new SMessage(); StoreHelper.SetSMessageSelectFields(message, reader, string.Empty); message.Extensions[_queueName] = queue; } await reader.CloseAsync(); } } }); return(message); }
/// <summary> /// 复制(深拷贝) /// </summary> protected override void toCopy(BaseData data) { if (!(data is AuctionItemRecordData)) { return; } AuctionItemRecordData mData = (AuctionItemRecordData)data; this.id = mData.id; this.price = mData.price; if (mData.days != null) { if (this.days != null) { this.days.clear(); this.days.ensureCapacity(mData.days.size()); } else { this.days = new SQueue <CountData>(); } SQueue <CountData> daysT = this.days; if (!mData.days.isEmpty()) { CountData[] daysVValues = mData.days.getValues(); int daysVMark = mData.days.getMark(); int daysVStart = mData.days.getStart(); for (int daysVI = 0, daysVLen = mData.days.length(); daysVI < daysVLen; ++daysVI) { CountData daysV = daysVValues[(daysVI + daysVStart) & daysVMark]; CountData daysU; if (daysV != null) { daysU = (CountData)daysV.clone(); } else { daysU = null; nullObjError("daysU"); } daysT.offer(daysU); } } } else { this.days = null; nullObjError("days"); } }
public async Task <SMessage> QueryByOriginalID(SQueue queue, Guid originalMessageID, Guid listenerID) { SMessage message = null; //根据存储类型和服务器名称获取连接字符串 var strConn = _messageQueueConnectionFactory.CreateReadForMessageQueue(queue.StoreType, queue.ServerName); await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, strConn, async (conn, transaction) => { SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } await using (SqlCommand commond = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, Transaction = sqlTran, CommandText = string.Format(@"select top 1 {0} from {1} where [originalmessageid]=@originalmessageid and [listenerid]=@listenerid ", StoreHelper.GetSMessageSelectFields(string.Empty), queue.Name) }) { var parameter = new SqlParameter("@originalmessageid", SqlDbType.UniqueIdentifier) { Value = originalMessageID }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@listenerid", SqlDbType.UniqueIdentifier) { Value = listenerID }; commond.Parameters.Add(parameter); await commond.PrepareAsync(); SqlDataReader reader = null; await using (reader = await commond.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { message = new SMessage(); StoreHelper.SetSMessageSelectFields(message, reader, string.Empty); message.Extensions[_queueName] = queue; } await reader.CloseAsync(); } } }); return(message); }
static void Main(string[] args) { SQueue queue = MakeQueue(5, 50, 5); Console.WriteLine("Initial queue"); ViewQueue(queue); queue.Enqueue(queue.Dequeue()); Console.WriteLine("\nQueue after moving the front to the rear"); ViewQueue(queue); Console.ReadKey(); }
/// <summary> /// 复制(潜拷贝) /// </summary> protected override void toShadowCopy(BaseData data) { if (!(data is ChatChannelData)) { return; } ChatChannelData mData = (ChatChannelData)data; this.queue = mData.queue; }
/// <summary> /// Displays the SQueue in the console. /// </summary> /// <param name="queue">The SQueue being displayed.</param> static void ViewQueue(SQueue queue) { Node node = queue.Peek(); Console.Write("FRONT --> "); while (node != null) { Console.Write($"{node.Value} --> "); node = node.Next; } Console.Write("NULL\n"); }
/// <summary> /// Creates and populates a SQueue. /// </summary> /// <param name="start">The value of the first node in the SQueue.</param> /// <param name="end">The maximum value for the nodes generated.</param> /// <param name="step">The difference in the values of adjacent nodes.</param> /// <returns>The resulting SQueue.</returns> static SQueue MakeQueue(int start, int end, int step) { Node node = new Node(start); SQueue queue = new SQueue(node); for (int i = start + step; i <= end; i += step) { node = new Node(i); queue.Enqueue(node); } return(queue); }
/// <summary> /// 转文本输出 /// </summary> protected override void toWriteDataString(DataWriter writer) { writer.writeTabs(); writer.sb.Append("id"); writer.sb.Append(':'); writer.sb.Append(this.id); writer.writeEnter(); writer.writeTabs(); writer.sb.Append("price"); writer.sb.Append(':'); writer.sb.Append(this.price); writer.writeEnter(); writer.writeTabs(); writer.sb.Append("days"); writer.sb.Append(':'); writer.sb.Append("Queue<CountData>"); if (this.days != null) { SQueue <CountData> daysT = this.days; int daysLen = daysT.size(); writer.sb.Append('('); writer.sb.Append(daysLen); writer.sb.Append(')'); writer.writeEnter(); writer.writeLeftBrace(); for (int daysI = 0; daysI < daysLen; ++daysI) { CountData daysV = daysT.get(daysI); writer.writeTabs(); writer.sb.Append(daysI); writer.sb.Append(':'); if (daysV != null) { daysV.writeDataString(writer); } else { writer.sb.Append("CountData=null"); } writer.writeEnter(); } writer.writeRightBrace(); } else { writer.sb.Append("=null"); } writer.writeEnter(); }
/// <summary> /// 读取字节流(完整版) /// </summary> protected override void toReadBytesFull(BytesReadStream stream) { stream.startReadObj(); this.id = stream.readInt(); this.price = stream.readInt(); int daysLen = stream.readLen(); if (this.days != null) { this.days.clear(); this.days.ensureCapacity(daysLen); } else { this.days = new SQueue <CountData>(); } SQueue <CountData> daysT = this.days; for (int daysI = daysLen - 1; daysI >= 0; --daysI) { CountData daysV; BaseData daysVT = stream.readDataFullNotNull(); if (daysVT != null) { if (daysVT is CountData) { daysV = (CountData)daysVT; } else { daysV = new CountData(); if (!(daysVT.GetType().IsAssignableFrom(typeof(CountData)))) { stream.throwTypeReadError(typeof(CountData), daysVT.GetType()); } daysV.shadowCopy(daysVT); } } else { daysV = null; } daysT.offer(daysV); } stream.endReadObj(); }
/// <summary> /// 复制(潜拷贝) /// </summary> protected override void toShadowCopy(BaseData data) { if (!(data is AuctionItemRecordData)) { return; } AuctionItemRecordData mData = (AuctionItemRecordData)data; this.id = mData.id; this.price = mData.price; this.days = mData.days; }
/// <summary> /// 复制(深拷贝) /// </summary> protected override void toCopy(BaseData data) { if (!(data is ChatChannelData)) { return; } ChatChannelData mData = (ChatChannelData)data; if (mData.queue != null) { if (this.queue != null) { this.queue.clear(); this.queue.ensureCapacity(mData.queue.size()); } else { this.queue = new SQueue <RoleChatData>(); } SQueue <RoleChatData> queueT = this.queue; if (!mData.queue.isEmpty()) { RoleChatData[] queueVValues = mData.queue.getValues(); int queueVMark = mData.queue.getMark(); int queueVStart = mData.queue.getStart(); for (int queueVI = 0, queueVLen = mData.queue.length(); queueVI < queueVLen; ++queueVI) { RoleChatData queueV = queueVValues[(queueVI + queueVStart) & queueVMark]; RoleChatData queueU; if (queueV != null) { queueU = (RoleChatData)queueV.clone(); } else { queueU = null; nullObjError("queueU"); } queueT.offer(queueU); } } } else { this.queue = null; nullObjError("queue"); } }
/// <summary> /// 是否数据一致 /// </summary> protected override bool toDataEquals(BaseData data) { ChatChannelData mData = (ChatChannelData)data; if (mData.queue != null) { if (this.queue == null) { return(false); } if (this.queue.size() != mData.queue.size()) { return(false); } SQueue <RoleChatData> queueT = this.queue; SQueue <RoleChatData> queueR = mData.queue; int queueLen = queueT.size(); for (int queueI = 0; queueI < queueLen; ++queueI) { RoleChatData queueU = queueT.get(queueI); RoleChatData queueV = queueR.get(queueI); if (queueV != null) { if (queueU == null) { return(false); } if (!queueU.dataEquals(queueV)) { return(false); } } else { if (queueU != null) { return(false); } } } } else { if (this.queue != null) { return(false); } } return(true); }
public async Task UpdateLastExecuteTime(SQueue queue, Guid id) { var crmService = await getCrmService(queue.ServerName); CrmExecuteEntity entity = new CrmExecuteEntity(queue.Name, id) { IsActivity = false, Attributes = new Dictionary <string, object>() { { "ms_lastexecutetime", DateTime.UtcNow }, } }; await crmService.Update(entity); }
/// <summary> /// 为队列从DbDataReader中赋值 /// </summary> /// <param name="queue"></param> /// <param name="reader"></param> /// <param name="prefix"></param> public static void SetSQueueSelectFields(SQueue queue, DbDataReader reader, string prefix) { queue.ID = (Guid)reader[string.Format("{0}id", prefix)]; if (reader[string.Format("{0}groupname", prefix)] != DBNull.Value) { queue.GroupName = reader[string.Format("{0}groupname", prefix)].ToString(); } if (reader[string.Format("{0}interval", prefix)] != DBNull.Value) { queue.Interval = (int)reader[string.Format("{0}interval", prefix)]; } if (reader[string.Format("{0}storetype", prefix)] != DBNull.Value) { queue.StoreType = (int)reader[string.Format("{0}storetype", prefix)]; } if (reader[string.Format("{0}servername", prefix)] != DBNull.Value) { queue.ServerName = reader[string.Format("{0}servername", prefix)].ToString(); } if (reader[string.Format("{0}name", prefix)] != DBNull.Value) { queue.Name = reader[string.Format("{0}name", prefix)].ToString(); } if (reader[string.Format("{0}code", prefix)] != DBNull.Value) { queue.Code = (int)reader[string.Format("{0}code", prefix)]; } if (reader[string.Format("{0}isdead", prefix)] != DBNull.Value) { queue.IsDead = (bool)reader[string.Format("{0}isdead", prefix)]; } if (reader[string.Format("{0}createtime", prefix)] != DBNull.Value) { queue.CreateTime = (DateTime)reader[string.Format("{0}createtime", prefix)]; } if (reader[string.Format("{0}modifytime", prefix)] != DBNull.Value) { queue.ModifyTime = (DateTime)reader[string.Format("{0}modifytime", prefix)]; } }
/// <summary> /// 读取字节流(完整版) /// </summary> protected override void toReadBytesFull(BytesReadStream stream) { stream.startReadObj(); int queueLen = stream.readLen(); if (this.queue != null) { this.queue.clear(); this.queue.ensureCapacity(queueLen); } else { this.queue = new SQueue <RoleChatData>(); } SQueue <RoleChatData> queueT = this.queue; for (int queueI = queueLen - 1; queueI >= 0; --queueI) { RoleChatData queueV; BaseData queueVT = stream.readDataFullNotNull(); if (queueVT != null) { if (queueVT is RoleChatData) { queueV = (RoleChatData)queueVT; } else { queueV = new RoleChatData(); if (!(queueVT.GetType().IsAssignableFrom(typeof(RoleChatData)))) { stream.throwTypeReadError(typeof(RoleChatData), queueVT.GetType()); } queueV.shadowCopy(queueVT); } } else { queueV = null; } queueT.offer(queueV); } stream.endReadObj(); }
public async Task <SQueue> QueryById(Guid id) { SQueue queue = null; await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _messageQueueConnectionFactory.CreateReadForMessageQueueMain(), async (conn, transaction) => { SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } await using (SqlCommand commond = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, Transaction = sqlTran, CommandText = string.Format(@"select {0} from SQueue where [id]=@id", StoreHelper.GetSQueueSelectFields(string.Empty)) }) { var parameter = new SqlParameter("@id", SqlDbType.UniqueIdentifier) { Value = id }; commond.Parameters.Add(parameter); await commond.PrepareAsync(); SqlDataReader reader = null; await using (reader = await commond.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { queue = new SQueue(); StoreHelper.SetSQueueSelectFields(queue, reader, string.Empty); } await reader.CloseAsync(); } } }); return(queue); }
//* -----------------------------------------------------------------------* /// <summary>コルーチン操作キューをリストへ反映します。</summary> private void commitQueue() { while (operationQueue.Count > 0) { SQueue data = operationQueue.Dequeue(); if (data.add) { coRoutines.AddLast(data.coRoutine); } else if (data.coRoutine == null) { coRoutines.Clear(); } else { coRoutines.Remove(data.coRoutine); } } }
/// <summary> /// 回池 /// </summary> protected override void toRelease(DataPool pool) { this.version = null; this.serverTime = 0L; this.isBlock = false; this.flowStep = 0; this.keepSave = null; this.clientRandomSeeds = null; this.clientRandomSeedIndex = 0; this.clientOfflineWorkReceiveIndex = 0; this.gmCommandSet = null; this.gmType = 0; this.serverBornCode = 0; this.serverStartTime = 0L; this.logQueue = null; this.nextDailyTime = 0L; this.createDate = null; this.clientRandomSeedKey = 0; }
/// <summary> /// 转文本输出 /// </summary> protected override void toWriteDataString(DataWriter writer) { writer.writeTabs(); writer.sb.Append("queue"); writer.sb.Append(':'); writer.sb.Append("Queue<RoleChatData>"); if (this.queue != null) { SQueue <RoleChatData> queueT = this.queue; int queueLen = queueT.size(); writer.sb.Append('('); writer.sb.Append(queueLen); writer.sb.Append(')'); writer.writeEnter(); writer.writeLeftBrace(); for (int queueI = 0; queueI < queueLen; ++queueI) { RoleChatData queueV = queueT.get(queueI); writer.writeTabs(); writer.sb.Append(queueI); writer.sb.Append(':'); if (queueV != null) { queueV.writeDataString(writer); } else { writer.sb.Append("RoleChatData=null"); } writer.writeEnter(); } writer.writeRightBrace(); } else { writer.sb.Append("=null"); } writer.writeEnter(); }