コード例 #1
0
ファイル: EventBusiness.cs プロジェクト: tdpmendes/RadixTest
        public async Task <EventBusinessResponseVO> ProcessEvent(DeviceEventDTO dvcEvtDTO)
        {
            int    value;
            string valueType = string.Empty;

            int.TryParse(dvcEvtDTO.Valor, out value);
            if (value != 0)
            {
                valueType = "INT";
            }
            else
            {
                valueType = "STR";
            }

            ValidationResultList validatonResultList = _validator.Validate(dvcEvtDTO);

            //Seria mais elegante ter feito por filters, mas fiz assim para deixar explicito o processo
            if (validatonResultList.items.Count > 0)
            {
                return(new EventBusinessResponseVO("error",
                                                   "The request provided contain errors",
                                                   DeviceEventBusinessStatusResponse.ERROR,
                                                   validatonResultList));
            }

            DeviceEvent dvcEvt = DeviceEvent.CreateFromDTOParameters(dvcEvtDTO.Timestamp, dvcEvtDTO.Tag, dvcEvtDTO.Valor, valueType);
            await _dvcEvtRepository.Add(dvcEvt);

            return(new EventBusinessResponseVO("success",
                                               "The request was processed successfully",
                                               DeviceEventBusinessStatusResponse.SUCCESS,
                                               validatonResultList));
        }
コード例 #2
0
        private static async Task SaveEvents(List <DeviceEvent> events, Guid id, IDeviceEventRepository deviceEventRepository, IEventRepository eventRepository)
        {
            foreach (DeviceEvent newEvent in events)
            {
                newEvent.DeviceId = id;
                await deviceEventRepository.Add(newEvent);

                if (!CheckExist(eventRepository, newEvent))
                {
                    await eventRepository.Add(newEvent.Name);
                }
            }
        }