public HttpResponseMessage ForwardCreation(SmcDto t) { try { var middlewareService = _middlewareProviderService.GetSmcMiddlewareServiceByManufacturerName(t.SmcModel.Manufacturer.Name); var convertedMessage = middlewareService.MakeSmcCreationPackageForForwarder(t); return(_forwarderSenderService.SendPost(convertedMessage).Result); } catch (Exception e) { Console.WriteLine(e); throw; } }
public void RelayOn(string serial, string token) { var meter = _meterService.GetExistingMeter(serial); var meterDto = _mapper.Map <Meter, MeterDto>(meter); var client = token != null?_servicesUtils.GetCurrentClientType(token) : ClientType.ALL; if (meter.Modem == null) { throw new BadRequestException("O medidor informado não possui modem"); } var relayOnCommandTicket = new CommandTicketDto { CommandId = Guid.NewGuid(), CommunicationStatus = CommunicationStatus.NO_INFORMATION, Attempt = 0, Status = Status.Waiting }; var relayStatusCommandTicket = new CommandTicketDto { CommandId = Guid.NewGuid(), CommunicationStatus = CommunicationStatus.NO_INFORMATION, Attempt = 0, Status = Status.Waiting }; var ticket = new TicketDto { User = client.ToString(), Serial = meter.Smc == null ? meter.Serial : meter.Smc.Serial, TicketId = Guid.NewGuid(), CommandType = CommandType.RelayOn, Interval = 18, TicketStatus = TicketStatus.Waiting }; ForwarderMessage relayOnForwarderMessage; ForwarderMessage relayStatusForwarderMessage; CommandDeviceType commandDeviceType; if (meter.Smc != null) { var smcMiddlewareService = _middlewareProviderService.GetSmcMiddlewareServiceByManufacturerName(meter.MeterModel.Manufacturer .Name); relayOnForwarderMessage = smcMiddlewareService.MakeMeterWithSmcRelayOnCommandForForwarder(meterDto, relayOnCommandTicket); relayStatusForwarderMessage = smcMiddlewareService.MakeMeterWithSmcRelayStatusCommandForForwarder(meterDto, relayStatusCommandTicket); commandDeviceType = CommandDeviceType.Smc; } else { var meterMiddlewareService = _middlewareProviderService.GetMeterMiddlewareServiceByManufacturerName(meter.MeterModel.Manufacturer .Name); relayOnForwarderMessage = meterMiddlewareService.MakeMeterRelayOnCommandForForwarder(meterDto, relayOnCommandTicket); relayStatusForwarderMessage = meterMiddlewareService.MakeMeterRelayStatusCommandForForwarder(meterDto, relayStatusCommandTicket); commandDeviceType = CommandDeviceType.Meter; } var forwarderMessageArray = new[] { relayOnForwarderMessage, relayStatusForwarderMessage }; ticket.CommandTickets.Add(relayOnCommandTicket); ticket.CommandTickets.Add(relayStatusCommandTicket); var ticketSaved = _ticketService.Create(ticket); _threadService.AddTicketToThread(ticketSaved, forwarderMessageArray, PriorityValue.MediumPriority, commandDeviceType); // Init websocket if (ticketSaved != null) { _eventHubService.ACommandQueueWasUpdatedEvent(this, new PayloadUpdateCommandQueue(ticket.Serial, 2, DateTime.Now.ToString())); _eventHubService.ACommandStatusWasUpdatedEvent(this, new PayloadUpdateCommandStatus(ticket.Serial, ticket.CommandTickets[0].Command, DateTime.Now.ToString().ToString(), ticket.CommandTickets[0].StatusCommand.ToString())); _eventHubService.AComunicationStatusWasUpdatedEvent(this, new PayloadUpdateComunicationStatus(ticket.Serial, ticket.CommandTickets[0].CommunicationStatus, DateTime.Now.ToString())); _eventHubService.ARelayStateWasChangedEvent(this, new PayloadUpdateRelayState(meterDto.Serial, meterDto.UpdatedAt, meterDto.AccountantStatus)); } // fim websocket // _threadService.AddCommand(command); }