Example #1
0
 public void InteractHold()
 {
     CustomLogger.Log(nameof(TestInteractable), "Continued interacting with this object...");
 }
Example #2
0
        /// <summary>
        /// Sends checking signal to vehicle and enqueue the result using RabbitMQ.
        /// </summary>
        /// <param name="vid">Vehicle Id.</param>
        public List <VehicleTransModel> PingVehiclesInQueue(int vid)
        {
            try
            {
                var vehicleTransList = new List <VehicleTransModel>();

                // 1- ping vehicles and get signal statuses back.
                var vehiclesSignalStatuses =
                    vid != 0
                        ? _genericsVehicleDbContextRepo.GetAll().Where(v => v.CustomerId != null && v.Id == vid)
                        : _genericsVehicleDbContextRepo.GetAll().Where(v => v.CustomerId != null);

                // 2- post to DB.
                foreach (var v in vehiclesSignalStatuses)
                {
                    var vse = _vehiclePingStatusRepository.GenerateSignal();

                    _genericsVehicleTransDbContextRepo.Add(new VehicleStatusTrans
                    {
                        PingTime  = DateTime.Now,
                        Status    = vse.ToString(),
                        VehicleId = v.Id
                    });
                    _genericsVehicleTransDbContextRepo.SaveChanges();
                    // Prepare object for UI.
                    vehicleTransList.Add(new VehicleTransModel
                    {
                        VehicleId   = v.Id,
                        VehicleCode = v.Code,
                        VehicleRegistrationNumber = v.RegNumber,
                        CustomerId   = v.CustomerId,
                        CustomerName = _genericsCustomerDbContextRepo.Find(v.CustomerId).Name,
                        Status       = vse.ToString()
                    });
                }

                // Publish list to EventBus queue.
                _serviceBusQueue.Publish("Vehicle_VehicleStatusTrans", vehicleTransList);

                return(vehicleTransList);
            }
            catch (NullReferenceException nullExp)
            {
                _logger.Log(LogLevel.Error, nullExp.Message, nullExp.Source);
                throw;
            }
            catch (ObjectDisposedException objectDisponseExp)
            {
                _logger.Log(LogLevel.Error, objectDisponseExp.Message, objectDisponseExp.Source);
                throw;
            }
            catch (NotSupportedException notSuppExp)
            {
                _logger.Log(LogLevel.Error, notSuppExp.Message, notSuppExp.Source);
                throw;
            }
            catch (Exception exp)
            {
                _logger.Log(LogLevel.Error, exp.Message, exp.Source);
                throw;
            }
        }
Example #3
0
 public void InteractStart()
 {
     CustomLogger.Log(nameof(TestInteractable), "Started interacting with this object...");
 }
Example #4
0
        public async Task TakeEventsAndPostAsList(Token token)
        {
            CustomLogger.Log("infoLog", "Rozpoczęto zadanie z Poznania.");
            var dateFrom = DateHelper.GetEventDateFromString(DateFrom);
            var dateTo   = DateHelper.GetEventDateFromString(DateTo);

            var cityId = await EventerApiService.GetCityId(token, "Poznań");

            var allEventerEvents = await EventerApiService.GetEvents(token, cityId);

            var poznanEventsToAdd  = new List <PoznanApiEvent>();
            var poznanEventsToPost = new List <EventPostItem>();

            var poznanEvents = await GetEventsFromPoznanApi();

            foreach (var @event in poznanEvents.Event)
            {
                var latestEventVersion = @event.EventVersion.Last();
                var latestVersion      = latestEventVersion.Version.Last();
                var latestAddress      = @event.EventAddress.Last();

                var poznanEventDate = DateHelper.GetEventDateFromString(@event.EventDate);

                if (!(poznanEventDate >= dateFrom && poznanEventDate <= dateTo))
                {
                    continue;
                }

                if (allEventerEvents.Any(x => x.EventName.Equals(latestVersion.EventName) &&
                                         x.EventDate == poznanEventDate &&
                                         x.EventLocalization.Equals(latestAddress.EventLocalization)))
                {
                    continue;
                }

                if (poznanEventsToAdd.Contains(@event))
                {
                    continue;
                }

                poznanEventsToAdd.Add(@event);
            }

            foreach (var @event in poznanEventsToAdd)
            {
                var latestEventVersion = @event.EventVersion.Last();
                var latestVersion      = latestEventVersion.Version.Last();
                var latestAddress      = @event.EventAddress.Last();

                var eventName         = latestVersion.EventName;
                var eventDate         = DateHelper.GetEventDateFromString(@event.EventDate);
                var eventLocalization = latestAddress.EventLocalization;
                var eventUrl          = @event.EventUrl;
                var eventDescription  = latestVersion.EventDescription;

                var categories = new List <string>
                {
                    @event.EventCategory
                };

                var newEvent = new EventPostItem
                {
                    EventName         = eventName,
                    EventDate         = eventDate,
                    EventLocalization = eventLocalization,
                    EventUrl          = eventUrl,
                    EventDescription  = eventDescription,
                    Categories        = categories,
                    CityId            = cityId
                };

                poznanEventsToPost.Add(newEvent);
            }

            var eventItemPostList = new EventItemPostList {
                Events = poznanEventsToPost
            };
            var postEventsResult = await EventerApiService.PostEventAsList(token, eventItemPostList, "poznEventLog");

            CustomLogger.Log("infoLog",
                             postEventsResult
                    ? $"Zakończono zadanie z Poznania. Dodano {poznanEventsToPost.Count} eventów."
                    : "Zakończono zadanie z Poznania. Nie dodano eventów.");
        }