Ejemplo n.º 1
0
        public TicketDto Update(CommandTicketDto commandTicket)
        {
            var command = _commandTicketRepository.GetById(commandTicket.CommandId);

            if (command == null)
            {
                throw new BadRequestException("Comando não cadastrado");
            }
            var ticket   = _ticketRepository.GetById(command.Ticket.TicketId);
            var commandT = ticket.CommandTickets.Find(c => c.CommandId == commandTicket.CommandId);

            commandT.UpdateValues(_mapper.Map <CommandTicketDto, CommandTicket>(commandTicket));
            ticket.UpdateValues(command);
            //Init websocket
            if (commandT.Status == Status.Finished)
            {
                _eventHubService.ACommandQueueWasUpdatedEvent(this,
                                                              new PayloadUpdateCommandQueue(ticket.Serial, -1, command.UpdatedAt.ToString()));
            }

            _eventHubService.ACommandStatusWasUpdatedEvent(this,
                                                           new PayloadUpdateCommandStatus(ticket.Serial, command.Command, command.UpdatedAt.ToString(),
                                                                                          command.StatusCommand.ToString()));

            _eventHubService.AComunicationStatusWasUpdatedEvent(this,
                                                                new PayloadUpdateComunicationStatus(ticket.Serial, commandTicket.CommunicationStatus, command.UpdatedAt.ToString()));
            //end websocket
            return(_mapper.Map <Ticket, TicketDto>(_ticketRepository.Update(ticket)));
        }
Ejemplo n.º 2
0
        public void GetRelay(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 commandTicket = 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.RelayStatus,
                Interval     = 18,
                TicketStatus = TicketStatus.Waiting
            };
            ForwarderMessage  relayStatusForwarderMessage;
            CommandDeviceType commandDeviceType;

            if (meter.Smc != null)
            {
                var smcMiddlewareService =
                    _middlewareProviderService.GetSmcMiddlewareServiceByManufacturerName(meter.MeterModel.Manufacturer
                                                                                         .Name);
                relayStatusForwarderMessage =
                    smcMiddlewareService.MakeMeterWithSmcRelayStatusCommandForForwarder(meterDto, commandTicket);
                commandDeviceType = CommandDeviceType.Smc;
            }
            else
            {
                var meterMiddlewareService =
                    _middlewareProviderService.GetMeterMiddlewareServiceByManufacturerName(meter.MeterModel.Manufacturer
                                                                                           .Name);
                relayStatusForwarderMessage =
                    meterMiddlewareService.MakeMeterRelayStatusCommandForForwarder(meterDto, commandTicket);
                commandDeviceType = CommandDeviceType.Meter;
            }
            ticket.CommandTickets.Add(commandTicket);
            var ticketSaved = _ticketService.Create(ticket);

            _threadService.AddTicketToThread(ticketSaved, relayStatusForwarderMessage, PriorityValue.MediumPriority,
                                             commandDeviceType);
            _eventHubService.ACommandQueueWasUpdatedEvent(this, new PayloadUpdateCommandQueue(ticket.Serial, 1, 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));
        }
Ejemplo n.º 3
0
        public TicketDto Create(CommandTicketDto commandTicket, string serial)
        {
            var ticket = new TicketDto
            {
                User        = "******", Serial = serial, TicketId = commandTicket.CommandId,
                InitialDate = commandTicket.InitialDate, TicketStatus = TicketStatus.Executing
            };

            ticket.CommandTickets.Add(commandTicket);
            return(_mapper.Map <Ticket, TicketDto>(_ticketRepository.Save(_mapper.Map <TicketDto, Ticket>(ticket))));;
        }
Ejemplo n.º 4
0
        public ForwarderMessage MakeMeterRelayStatusCommandForForwarder(MeterDto meterDto,
                                                                        CommandTicketDto commandTicketDto)
        {
            var forwarderMessage = new ForwarderMessage
            {
                MessageContent = "", //todo
                Uri            = _middlewares.EletraSmi.BaseUrl
                                 + _middlewares.EletraSmi.Meters.SubRoute
                                 + _middlewares.EletraSmi.Meters.RelayStatus
                                 + "?serialMeter=" + meterDto.Serial
                                 + "&commandId=" + commandTicketDto.CommandId,
                CommandId = commandTicketDto.CommandId
            };

            return(forwarderMessage);
        }
Ejemplo n.º 5
0
        public TicketDto AddCommand(CommandTicketDto commandTicket)
        {
            var ticket = GetByTicketId(commandTicket.CommandId);

            if (ticket == null)
            {
                throw new BadRequestException("Ticket não cadastrado");
            }
            ticket.CommandTickets.Add(commandTicket);
            //Init websocket
            _eventHubService.ACommandQueueWasUpdatedEvent(this, new PayloadUpdateCommandQueue(ticket.Serial, 1, commandTicket.UpdatedAt));
            _eventHubService.ACommandStatusWasUpdatedEvent(this, new PayloadUpdateCommandStatus(ticket.Serial, commandTicket.Command, commandTicket.UpdatedAt.ToString(), commandTicket.StatusCommand.ToString()));
            _eventHubService.AComunicationStatusWasUpdatedEvent(this, new PayloadUpdateComunicationStatus(ticket.Serial, commandTicket.CommunicationStatus, commandTicket.UpdatedAt.ToString()));
            //end Websocket
            return(_mapper.Map <Ticket, TicketDto>(_ticketRepository.Update(_mapper.Map <TicketDto, Ticket>(ticket))));;
        }
Ejemplo n.º 6
0
 public ForwarderMessage MakeMeterWithSmcRelayStatusCommandForForwarder(MeterDto meterDto,
                                                                        CommandTicketDto commandTicketDto)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 7
0
 public ForwarderMessage MakeMeterRelayOffCommandForForwarder(MeterDto meterDto,
                                                              CommandTicketDto commandTicketDto)
 {
     throw new System.NotImplementedException();
 }