Exemplo n.º 1
0
        public HttpResponseMessage Post([FromBody] DeviceTrafficLog deviceTrafficInfo)
        {
            return(ActionWarpper.Process(deviceTrafficInfo, OperationCodes.ADVTFLOG, () =>
            {
                var repo = RepositoryManager.GetRepository <IDeviceTrafficLogRepository>();
                repo.Insert(deviceTrafficInfo);

                return Request.CreateResponse(HttpStatusCode.OK, deviceTrafficInfo);
            }, this));
        }
Exemplo n.º 2
0
        public HttpResponseMessage Put(int id, [FromBody] DeviceTrafficLog deviceTrafficInfo)
        {
            return(ActionWarpper.Process(deviceTrafficInfo, OperationCodes.MDVTFLOG, () =>
            {
                deviceTrafficInfo.TrafficID = id;
                var repo = RepositoryManager.GetRepository <IDeviceTrafficLogRepository>();
                repo.Update(deviceTrafficInfo);

                return Request.CreateResponse(HttpStatusCode.OK);
            }, this));
        }
Exemplo n.º 3
0
        public IList <DeviceTrafficLog> QueryNewTrafficLogs(DeviceController device)
        {
            var operation = new WebSocketOperation(device.Code.ToInt32());
            var getDeviceTrafficLogRequest = new GetDeviceTrafficLogRequest()
            {
                Token     = operation.Token,
                BeginTime = new DateTime(2016, 1, 1),
                EndTime   = new DateTime(2099, 12, 31),
            };

            string rawRequest  = DataContractSerializationHelper.Serialize(getDeviceTrafficLogRequest);
            var    rawResponse = operation.Execute(rawRequest);

            var response = DataContractSerializationHelper.Deserialize <GetDeviceTrafficLogResponse>(rawResponse);

            Log.InfoFormat("GetDeviceTrafficLogResponse from device id:{0}, result ={1}", device.DeviceID, response.ResultType);

            if (response.ResultType != ResultType.OK)
            {
                throw new Exception(string.Format("GetDeviceTrafficLogResponse from device id:{0} fails", device.DeviceID));
            }

            var deviceTrafficLogs = new List <DeviceTrafficLog>();

            foreach (var rawlog in response.Logs)
            {
                var log = new DeviceTrafficLog()
                {
                    DeviceID         = device.DeviceID,
                    DeviceUserID     = rawlog.UserId,
                    DeviceCode       = device.Code,
                    DeviceType       = device.Model,
                    DeviceSN         = device.SN,
                    RecordType       = rawlog.AccessLogType.ToString(),
                    RecordTime       = rawlog.CreateTime,
                    RecordUploadTime = DateTime.Now,
                    Remark           = rawlog.Message,
                };

                if (rawlog.CheckInOptions.Any())
                {
                    log.AuthenticationType = 0;
                    rawlog.CheckInOptions.ForEach(option => log.AuthenticationType += (int)option);
                }

                deviceTrafficLogs.Add(log);
            }

            return(deviceTrafficLogs);
        }
Exemplo n.º 4
0
        private void SendSms(DeviceTrafficLog log, List <String> accounts)
        {
            try
            {
                var sysConfigRepo = RepositoryManager.GetRepository <ISysConfigRepository>();
                foreach (var account in accounts)
                {
                    string        msg            = sysConfigRepo.GetConfigValueByName("DeviceAlarmJobSms_Body");
                    UcpaasMessage messageService = new UcpaasMessage();
                    bool          sendSuccess    = messageService.SendMessage(account, msg);

                    Log.InfoFormat("send sms to {0}, result: {1}", account, sendSuccess);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
Exemplo n.º 5
0
 private void SendEmail(DeviceTrafficLog log, List <String> accounts)
 {
     try
     {
         foreach (var account in accounts)
         {
             var    m       = new SmtpConfig();
             var    mFrom   = new MailAddress(emailTemplate.FromAddress, emailTemplate.FromAccountDisplayName, Encoding.UTF8);
             var    mTo     = new MailAddress(account, account, Encoding.UTF8);
             string subject = emailTemplate.Subject;
             string body    = emailTemplate.Body;
             string res     = SmtpMail.MailTo(m, mFrom, mTo, subject, body);
             Log.InfoFormat("send email to {0}, result:{1}", account, res);
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex);
     }
 }
Exemplo n.º 6
0
 public bool IsIOMessage(DeviceTrafficLog deviceTrafficLogInfo)
 {
     return(IOMessages.Any(x => x == deviceTrafficLogInfo.Remark));
 }