/// <summary> /// Reduce el tamaño de las listas a la minima expresion posible, /// para asi optimizar la memoria, las transferncias por red y el /// almacenamiento en disco del estado de dispositivo. /// Este metodo es convocado automaticamente por la infraestructura /// del spine. /// </summary> public void Shrink() { FlashCounter.Shrink(); CrapReceivedCounter.Shrink(); StatesChanges.Shrink(); PERMANENTCounter.Shrink(); MAINTCounter.Shrink(); OFFLINECounter.Shrink(); CONNECTEDCounter.Shrink(); ONLINECounter.Shrink(); ONNETCounter.Shrink(); SHUTDOWNCounter.Shrink(); SYNCINGCounter.Shrink(); OUTOFSERVICECounter.Shrink(); //TransitionTrend.Shrink(); AverageConnectedTime.Shrink(); }
} // v2 //public Toolkit.TransitionTrend<ServiceStates> TransitionTrend { get; private set; } public void ResetCounters() { FlashCounter.Reset(); CrapReceivedCounter.Reset(); StatesChanges.Reset(); PERMANENTCounter.Reset(); MAINTCounter.Reset(); OFFLINECounter.Reset(); CONNECTEDCounter.Reset(); ONLINECounter.Reset(); ONNETCounter.Reset(); SHUTDOWNCounter.Reset(); SYNCINGCounter.Reset(); OUTOFSERVICECounter.Reset(); //TransitionTrend.Reset(); STrace.Debug(GetType().FullName, String.Format("DEVICE['{0}'/{1}]: Reseteando contadores.", Code, Id)); AverageConnectedTime.Reset(); RequireCommit = true; }
public async Task <JsonResult> SendSms(string batchCode, int templateId, DateTime?sendTime = null) { String sentResult = string.Empty; var resultMsg = string.Empty; if (!string.IsNullOrWhiteSpace(batchCode) && _smsTemplates.ContainsKey(templateId)) { if (sendTime != null && sendTime < DateTime.Now) { sentResult = "TimeNotAvailable"; resultMsg = "时间不能早于当前时间"; } else { var manager = new BeautyCodeManager(); var key = $"SendSms/{batchCode}"; var ts = TimeSpan.FromMinutes(1); long flashCount = await FlashCounter.GetFlashCount(_counterClient, key, ts, OperateType.Increment); if (flashCount > 0) { resultMsg = "操作过于频繁,请等1分钟重试"; sentResult = "Frequently"; } else { var isLimit = false; if (!string.Equals(_environment, "dev"))//如果是生产环境有一周只能发一次的限制 { var smsRecords = manager.GetCompanyUserSmsRecordByBatchCode(batchCode); var latestSmsRecord = smsRecords.Where(s => string.Equals(s.Status, nameof(SmsStatus.Success)) || string.Equals(s.Status, nameof(SmsStatus.PartialSuccess))).OrderByDescending(s => s.PKID).FirstOrDefault(); if (latestSmsRecord != null) { isLimit = (DateTime.Now - latestSmsRecord.CreatedDateTime).Days < 7; } } if (isLimit) { resultMsg = "一周之内只能发一次短信"; sentResult = "BeLimited"; } else { var user = HttpContext.User.Identity.Name; var codeTasks = await BeautyServicePackageManager.SelectCreateBeautyCodeTaskModels(batchCode); if (codeTasks.Any()) { var mobiles = codeTasks.Select(s => s.MobileNumber).Distinct(); if (mobiles.Any()) { string[] arg = new string[1]; arg[0] = _smsUrl; var msg = _smsTemplates[templateId]; sentResult = await manager.SendBatchSms(user, mobiles, templateId, arg, sendTime); var needSendTime = sendTime == null ? DateTime.Now : sendTime; manager.InsertCompanyUserSmsRecord(new CompanyUserSmsRecord() { Type = "ServiceCode", BatchCode = batchCode, SmsTemplateId = templateId, SmsMsg = msg, SentTime = (DateTime)needSendTime, Status = sentResult, CreatedUser = user }); } } } } } } else { resultMsg = "参数错误"; } return(Json(new { result = sentResult, msg = resultMsg })); }