示例#1
0
      internal void Handle(UpdateTrafficEvents input) {
         using (var dbConn = DatabaseManager.DbConn()) {
            dbConn.CreateTempTableOf("T_TRAFFIC_EVENTS");

            foreach (var ie in input.Events) {

               var ei = new TrafficEventInfo();

               ei.EventId = ie.Id;
               ei.Codes = ie.Codes;
               ei.Direction = ie.Direction;
               ei.Extent = ie.Extent;
               ei.IsTwoWay = ie.IsTwoWay;

               if (ie.Origin != null) {
                  ei.OriginLocation = ie.Origin.Location;
                  ei.OriginLocationCode = ie.Origin.LocationCode;
                  ei.OriginCountryCode = ie.Origin.CountryCode;
                  ei.OriginLocationTableNumber = ie.Origin.LocationTableNumber;
               } else {
                  if (ie.Destination == null) {
                     Log.Warn("No ORIGIN and DESTINATION provided for traffic event {0}", ie.Id);
                     continue;
                  } else {
                     ei.OriginLocation = ie.Destination.Location;
                     ei.OriginLocationCode = ie.Destination.LocationCode;
                     ei.OriginCountryCode = ie.Destination.CountryCode;
                     ei.OriginLocationTableNumber = ie.Destination.LocationTableNumber;
                  }
               }

               if (ie.Destination != null) {
                  ei.DestinationLocation = ie.Destination.Location;
                  ei.DestinationLocationCode = ie.Destination.LocationCode;
                  ei.DestinationCountryCode = ie.Destination.CountryCode;
                  ei.DestinationLocationTableNumber = ie.Destination.LocationTableNumber;
               } else {
                  if (ie.Origin == null) {
                     Log.Warn("No ORIGIN and DESTINATION provided for traffic event {0}", ie.Id);
                     continue;
                  } else {
                     ei.DestinationLocation = ie.Origin.Location;
                     ei.DestinationLocationCode = ie.Origin.LocationCode;
                     ei.DestinationCountryCode = ie.Origin.CountryCode;
                     ei.DestinationLocationTableNumber = ie.Origin.LocationTableNumber;
                  }
               }

               ei.ApproximatedDelay = ie.ApproximatedDelay;
               ei.ApproximatedSpeed = ie.ApproximatedSpeed;
               ei.LastUpdate = ie.LastUpdate;
               ei.Length = ie.Length;
               ei.Load = ie.Load;

               ei.Operator = _getOperatorByRegion(ei.OriginLocation, ei.DestinationLocation);
               if ((ei.Operator == null) || (ei.Operator.Id.IsEmpty)) {
                  Log.Warn("Undefined OPERATOR in tmp update (OR: {0}, DE: {1}, Skipping record", ei.OriginLocation, ei.DestinationLocation);
                  continue;
               }

               dbConn.ExecuteBpl(new TrafficEventAddTemp { i = ei });
            }

            dbConn.BeginTransaction();
            dbConn.ExecuteBpl(new TrafficEventSave());
            dbConn.CommitTransaction();
         }

         Reply(true);
      }
示例#2
0
 /// <summary>Update traffic events retrived by the provider.</summary>
 /// <param name="args">Traffic events to update.</param>
 protected void UpdateTrafficEvents(params TrafficEvent[] args) {
    args.Apply(a => a.ProviderId = ServiceName);
    var t = new UpdateTrafficEvents();
    t.Events.AddRange(args);
    Services.Invoke(t);
 }