public static SMessage DeleteSMessage(SMessage smessage) { LiteDatabase db = null; try { ConnectionString cn = ldbConfig.ldbSMessageConnectionString; db = new LiteDatabase(cn); LiteCollection <SMessage> dbSMessage = db.GetCollection <SMessage>("SMessage"); //dbSMessage.Delete(Query.EQ("Id", smessage.Id)); //LiteCollection<SMessage> lst=dbSMessage.Where(x => x.Id == smessage.Id).ToList<SMessage>(); SMessage sm = dbSMessage.FindById(smessage.Id); if (sm != null) { sm.IsDeleted = 1; } dbSMessage.Update(sm); //List<SMessage> lst = dbSMessage.FindAll().Where(x => x.IsDeleted != 1).ToList<SMessage>(); return(sm); } catch (Exception ex) { DBHelper.LogFile(ex); return(null); } }
private SMessage GetDicObj(RMessage m) { string name; if (!m.Parameters.TryGetValue("name", out name)) { throw new ShareMemoryException("Message 中缺少参数 \"name\", 应通过 \"name\" 参数指定要访问的 Dictionary 的 名字 。"); } string key; if (!m.Parameters.TryGetValue("key", out key)) { throw new ShareMemoryException("Message 中缺少参数 \"key\", 应通过 \"key\" 参数指定要取的值的 键 。"); } byte[] b = this.mm.GetDicObj(name, key); SMessage sMsg = new SMessage(); if (b != null) { sMsg.Content = new MemoryStream(b); sMsg.ContentLength = b.Length; } return(sMsg); }
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 void Send(SMessage message) { account = new Account() //暂时写死 { UserId = "E1035V", PassWord = "******", Ip = "api01.monyun.cn:7901" }; Message msg = initMessage(); msg.Mobile = message.Mobile.Trim(); msg.Content = message.Content.Trim(); msg.ExNo = ""; msg.CustId = message.CustId; msg.ExData = ""; msg.SvrType = message.SvrType; //提交 var strResult = submit(msg, 1); Logger.Info(strResult); // 根据返回内容判断是否正确? //{"result":0,"msgid":5635184289429894454,"custid":"c333333"} var response = JsonConvert.DeserializeObject <JsonResult>(strResult); if (response == null || response.result != 0) { throw new Abp.UI.UserFriendlyException($"发送短信码失败:{response.result}"); } }
public bool TryDe <T>(out T value) { SMessage m = new SMessage(); m.Parameters.Add(new Para("method", "Dequeue")); m.Parameters.Add(new Para("name", this.name)); RMessage rMsg = this.rpc.Send(m); Type t = typeof(T); if (rMsg.ContentLength == 0) { value = default(T); return(false); } byte[] b = new byte[rMsg.ContentLength]; Util.Read(rMsg.Content, b); DeSerializer deSerializer = new DeSerializer(); value = deSerializer.DeSerialize <T>(b); return(true); }
/// <summary> /// 生成短信码 /// </summary> /// <param name="mobile">手机号</param> /// <param name="validateType">验证类型</param> /// <returns></returns> public SMessage Build(string mobile, ValidateType validateType) { var now = DateTime.Now.AddMinutes(-1); // 一分钟内, 无需重新生成, 仍然用原来的 var data = _validateDataRepository.FirstOrDefault(d => d.Mobile == mobile && d.ValidateType == validateType && d.CreationTime >= now); if (data == null) { data = CreateValidateData(mobile, validateType); } data.SendNum += 1; // 生成一次,相当于发送一次了 _validateDataRepository.Update(data); SMessage message = new SMessage() { Mobile = mobile, Content = GenerateContent(data.ValidateCode), CustId = validateType.ToString(), }; CurrentUnitOfWork.SaveChanges(); return(message); }
private SMessage SetDicObj(RMessage m) { string name; if (!m.Parameters.TryGetValue("name", out name)) { throw new ShareMemoryException("Message 中缺少参数 \"name\", 应通过 \"name\" 参数指定要访问的 Dictionary 的 名字 。"); } string key; if (!m.Parameters.TryGetValue("key", out key)) { throw new ShareMemoryException("Message 中缺少参数 \"key\", 应通过 \"key\" 参数指定要存的值的 键 。"); } if (m.Content == null) { throw new ShareMemoryException("Message 中缺少 Content , 应通过 Content 传递要放到 Dictionary 里的 对象 的 序列化数据 。"); } byte[] b = new byte[m.ContentLength]; Read(m.Content, b); this.mm.SetDicObj(name, key, b); SMessage sMsg = new SMessage(); return(sMsg); }
private void btnTest_Click(object sender, EventArgs e) { try { RPC rpc = new RPC("127.0.0.1", 9527); SMessage m = new SMessage(); m.Parameters.Add(new Para("id", "001")); m.Parameters.Add(new Para("name", "小明")); RMessage rMsg; using (Stream s = File.Open("timg.jpg", FileMode.Open, FileAccess.Read)) { m.Content = s; m.ContentLength = s.Length; rMsg = rpc.Send(m); } WriteMsg(rMsg); } catch (Exception ex) { WriteMsg(ex.ToString()); } }
public async Task ExecuteResultAsync(ActionContext context) { context.HttpContext.Response.ContentType = format; context.HttpContext.Response.Headers.Add("Content-disposition", "attachment;filename=" + WebUtility.UrlEncode(fileName)); byte[] bytes = new byte[1024]; stream.Position = 0; while (true) { int count = await stream.ReadAsync(bytes, 0, bytes.Length); await context.HttpContext.Response.Body.WriteAsync(bytes, 0, count); if (count < bytes.Length) { break; } } ///log Guid guid = Guid.NewGuid(); var message = new SMessage() { Key = $"{"Common"}-{"ExcelExportLog"}-{guid}", Type = "ExcelExportLog", Data = JsonSerializerHelper.Serializer(new { Id = guid, CreateBy = userName, CreateOn = DateTime.UtcNow, FileName = fileName, FileSize = stream.Length, CreateBranch = branchCode }), ExpectationExecuteTime = DateTime.UtcNow, RetryNumber = 0, IsDead = false }; await message.Add(); }
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 void Set(string key, object value) { if (key == null) { throw new ShareMemoryClientException("参数 key 不能为 null 。"); } if (value == null) { throw new ShareMemoryClientException("参数 value 不能为 null 。"); } SMessage m = new SMessage(); Serializer serializer = new Serializer(); byte[] b = serializer.Serialize(value); m.Parameters.Add(new Para("method", "SetDicObj")); m.Parameters.Add(new Para("name", this.name)); m.Parameters.Add(new Para("key", key)); m.Content = new MemoryStream(b); m.ContentLength = b.Length; this.rpc.Send(m); }
public bool TryGet <T>(string key, out T value) { if (key == null) { throw new ShareMemoryClientException("参数 key 不能为 null 。"); } SMessage m = new SMessage(); m.Parameters.Add(new Para("method", "GetDicObj")); m.Parameters.Add(new Para("name", this.name)); m.Parameters.Add(new Para("key", key)); RMessage rMsg = this.rpc.Send(m); Type t = typeof(T); if (rMsg.ContentLength == 0) { value = default(T); return(false); } byte[] b = new byte[rMsg.ContentLength]; Util.Read(rMsg.Content, b); DeSerializer deSerializer = new DeSerializer(); value = deSerializer.DeSerialize <T>(b); return(true); }
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); }
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); }
public async Task Do(SMessageData messageData) { SMessage message = new SMessage() { Key = messageData.Key, Type = messageData.Type, Data = messageData.Data, ExpectationExecuteTime = messageData.ExpectationExecuteTime }; await message.Add(); }
public SMessage DeleteSMessage([FromBody] SMessage message) //[FromBody] SMessage message { try { return(SMessageUtility.DeleteSMessage(message)); } catch (Exception e) { LogManager.SetCommonLog(e.Message.ToString()); return(null); } }
public ISMessageOperationContext Create(SMessage message, Dictionary <string, object> parameters) { SMessageOperationContext context = new SMessageOperationContext() { MessageId = message.ID, MessageType = message.Type, MessageKey = message.Key, MessageData = message.Data, Parameters = parameters }; return(context); }
// Update is called once per frame void Update() { if (this.readQueue.Count == 0) { return; } SMessage sMessage = this.readQueue.Dequeue(); if (sMessage != null) { EventManager.Instance.Call("EVENT.NET.MESSAGE", sMessage); } }
void on_recv_tcp_cmd(byte[] tcp_data, int start, int data_len) { var out_header = new byte[PackTools.PACK_LENGTH]; Array.Copy(tcp_data, out_header, out_header.Length); var header = PackTools.UnPackObject(out_header); var out_msg = new byte[data_len]; Array.Copy(tcp_data, start, out_msg, 0, data_len); SMessage message = new SMessage(header, out_msg); this.readQueue.Enqueue(message); }
public void Remove(string key) { if (key == null) { throw new ShareMemoryClientException("参数 key 不能为 null 。"); } SMessage m = new SMessage(); m.Parameters.Add(new Para("method", "RemoveDicObj")); m.Parameters.Add(new Para("name", this.name)); m.Parameters.Add(new Para("key", key)); this.rpc.Send(m); }
/// <summary> /// 委托实现:发送邮件 /// </summary> /// <param name="msg"></param> /// <returns></returns> bool delegate_SendMail(MessageEntity msg) { try { SMessage.SendMail(msg); DBOperate.SaveMessageLog(msg, Enum_MessageType.Mail.ToString(), null); SLog.WriteLogWithDefaultTime(msg.EMails + "发送成功"); return(msg.IsSended); } catch (Exception ex) { DBOperate.SaveMessageLog(msg, Enum_MessageType.Mail.ToString(), ex.Message); SLog.WriteLogWithDefaultTime(string.Format("发送失败:{0} 出现问题:{1}", msg.EMails, ex.Message)); return(false); } }
private SMessage TryLock(RMessage m) { string name; if (!m.Parameters.TryGetValue("name", out name)) { throw new ShareMemoryException("Message 中缺少参数 \"name\", 应通过 \"name\" 参数指定要创建的 Lock 的名字 。"); } string lockId = this.mm.TryLock(name); SMessage sMsg = new SMessage(); if (lockId != null) { sMsg.Parameters.Add(new Para("lockId", lockId)); } return(sMsg); }
public void UnLock(string lockName, string lockId) { if (lockName == null) { throw new ShareMemoryClientException("参数 lockName 不能为 null 。"); } if (lockId == null) { throw new ShareMemoryClientException("参数 lockId 不能为 null 。"); } SMessage m = new SMessage(); m.Parameters.Add(new Para("method", "UnLock")); m.Parameters.Add(new Para("name", lockName)); m.Parameters.Add(new Para("lockId", lockId)); this.rpc.Send(m); }
private SMessage Dequeue(RMessage m) { string name; if (!m.Parameters.TryGetValue("name", out name)) { throw new ShareMemoryException("Message 中缺少参数 \"name\", 应通过 \"name\" 参数指定要访问的 Queue 的 名字 。"); } byte[] b = this.mm.Dequeue(name); SMessage sMsg = new SMessage(); if (b != null) { sMsg.Content = new MemoryStream(b); sMsg.ContentLength = b.Length; } return(sMsg); }
public void En(object value) { if (value == null) { throw new ShareMemoryClientException("参数 value 不能为 null 。"); } SMessage m = new SMessage(); Serializer serializer = new Serializer(); byte[] b = serializer.Serialize(value); m.Parameters.Add(new Para("method", "Enqueue")); m.Parameters.Add(new Para("name", this.name)); m.Content = new MemoryStream(b); m.ContentLength = b.Length; this.rpc.Send(m); }
// Start is called before the first frame update void Start() { // var obj = new object[] // { // new char[] // { // 'a', // '增', // '怕', // '%' // }, // }; LogTool.Instance.ToStringAll(BitConverter.GetBytes((Int16)(50))); ClientHeader header = new ClientHeader(); SerializableStructAttribute[] objects = (SerializableStructAttribute[])header.GetType() .GetCustomAttributes(typeof(SerializableStructAttribute), false); foreach (var VARIABLE in objects) { Debug.Log(VARIABLE); } EventManager.Instance.AddEventAction("EVENT.NET.MESSAGE", (msg) => { SMessage m = msg as SMessage; print(m.Header.MessageID); EventManager.Instance.Call($"EVENT.NET.MESSAGE.{m.Header.MessageID}", 1.5); }); // // var bs = NetPackData.pack_all(obj); //// //// LogTool.Instance.ToStringAll((byte)('a')); //// LogTool.Instance.ToStringAll(BitConverter.GetBytes(false)); //// LogTool.Instance.ToStringAll(bs); // // var obj_oo = NetUnPackData.unpack_all(bs); // LogTool.Instance.ToStringAll(obj_oo); // .Instance.LogBytes(bs); }
private SMessage RemoveDicObj(RMessage m) { string name; if (!m.Parameters.TryGetValue("name", out name)) { throw new ShareMemoryException("Message 中缺少参数 \"name\", 应通过 \"name\" 参数指定要访问的 Dictionary 的 名字 。"); } string key; if (!m.Parameters.TryGetValue("key", out key)) { throw new ShareMemoryException("Message 中缺少参数 \"key\", 应通过 \"key\" 参数指定要取的值的 键 。"); } this.mm.RemoveDicObj(name, key); SMessage sMsg = new SMessage(); return(sMsg); }
private SMessage UnLock(RMessage m) { string name; if (!m.Parameters.TryGetValue("name", out name)) { throw new ShareMemoryException("Message 中缺少参数 \"name\", 应通过 \"name\" 参数指定要解锁的 Lock 的名字 。"); } string lockId; if (!m.Parameters.TryGetValue("lockId", out lockId)) { throw new ShareMemoryException("Message 中缺少参数 \"lockId\", 应通过 \"lockId\" 参数指定要解锁的 Lock 的 lockId 。"); } this.mm.UnLock(name, lockId); SMessage sMsg = new SMessage(); return(sMsg); }
public SMessage SendSMessage([FromBody] SMessage message) //[FromBody] SMessage message { NowDateTime ndt = new NowDateTime(); try { //SMessage message = new SMessage(); //message.SenderUserId = 493619; //message.SendToUserId = 0; //message.SenderUserDesc = "محمد رضا ابراهیمی"; message.CreatedDateTime = ndt.Now; message.CreatedDateTimeFa = ndt.NowDateTimeFa; message.Id = Guid.NewGuid().ToString(); //message.Message = "شماره شاسی صحیح نیست "+(new Random()).Next(); return(SMessageUtility.SendSMessage(message)); } catch (Exception e) { LogManager.SetCommonLog(e.Message.ToString()); return(null); } }
public static SMessage SendSMessage(SMessage _smessage) { LiteDatabase db = null; try { NowDateTime _ndt = new NowDateTime(); _smessage.CreatedDateTimeFa = _ndt.NowDateTimeFa; _smessage.CreatedDateTime = _ndt.NowTime; ConnectionString cn = ldbConfig.ldbSMessageConnectionString; db = new LiteDatabase(cn); LiteCollection <SMessage> dbSMessage = db.GetCollection <SMessage>("SMessage"); dbSMessage.Insert(_smessage); //List <SMessage> lst = dbSMessage.FindAll().Where(x => x.IsDeleted != 1).ToList<SMessage>(); SMessage sm = dbSMessage.FindById(_smessage.Id); return(sm); } catch (Exception ex) { DBHelper.LogFile(ex); return(null); } }
private MessageBase ParseParameterToMessage(string message, object parameter, out short id) { MessageBase msgToSend = null; if (parameter == null) { id = DispatchEMessageId; EMessage emsg = new EMessage (); emsg.message = message; msgToSend = emsg; } else if (parameter is int) { id = DispatchIMessageId; IMessage imsg = new IMessage (); imsg.message = message; imsg.parameter = (int)parameter; msgToSend = imsg; } else if (parameter is float) { id = DispatchFMessageId; FMessage fmsg = new FMessage (); fmsg.message = message; fmsg.parameter = (float)parameter; msgToSend = fmsg; } else if (parameter is string) { id = DispatchSMessageId; SMessage smsg = new SMessage (); smsg.message = message; smsg.parameter = parameter as string; msgToSend = smsg; } else if (parameter is Vector3) { id = DispatchVMessageId; VMessage vmsg = new VMessage (); vmsg.message = message; vmsg.parameter = (Vector3)parameter; msgToSend = vmsg; } else if (parameter is Quaternion) { id = DispatchQMessageId; QMessage qmsg = new QMessage (); qmsg.message = message; qmsg.parameter = (Quaternion)parameter; msgToSend = qmsg; } else { id = -1; Debug.LogError ("Can't dispatch a non RPCable parameter"); } return msgToSend; }
public void receiveMessage(SMessage m) { //Console.WriteLine(m.ToString()); switch (m.header) { case "game": { Network.receiveGameMessage(m.from, m.message); } break; case "tell": { GUI.showTell(m.from, m.message); } break; case "startgame": { var ss = m.message.Split(','); GameConnection c = new GameConnection(ss[0], ss[1] == "home"); Network.addGameConnection(ss[0], c); CentralShitterModule.newGame(c); } break; case "error": { Console.WriteLine("Error: {0}", m.message); } break; default: { System.Console.WriteLine("borked message: " + m.ToString()); } break; } }