Ejemplo n.º 1
0
      internal void Handle(UpdateSpeedCameras input) {
         using (var dbConn = DatabaseManager.DbConn()) {
            var toAdd = new List<SpeedCamera>();
            toAdd.AddRange(input.Cameras);

            var toUpdate = new List<SpeedCameraInfo>();

            var dbCameras = dbConn.ExecuteBpl(new SpeedCameraGetAll());

            var toDelete = new List<SpeedCameraInfo>();
            toDelete.AddRange(dbCameras);

            foreach (var dbCamera in dbCameras) {
               foreach (var inputCamera in input.Cameras) {
                  if (dbCamera.CameraId == inputCamera.Id) {
                     toAdd.Remove(inputCamera);
                     toDelete.Remove(dbCamera);

                     var ic = _fromInput(inputCamera);
                     if (!_isEqual(dbCamera, ic)) {
                        toUpdate.Add(ic);
                     }

                     break;
                  }
               }
            }

            Log.Trace("Speed cameras: To update {0}, To insert {1}, To delete {2}", toUpdate.Count, toAdd.Count, toDelete.Count);

            dbConn.BeginTransaction();

            foreach (var sc in toAdd) {
               var ic = _fromInput(sc);
               if (ic.Operator == null) continue;
               dbConn.ExecuteBpl(new SpeedCameraSave { i = ic });
            }

            foreach (var ic in toUpdate) {
               if (ic.Operator == null) continue;
               dbConn.ExecuteBpl(new SpeedCameraSave { i = ic });
            }

            foreach (var sc in toDelete) {
               dbConn.ExecuteBpl(new SpeedCameraDelete { CameraId = sc.CameraId });
            }

            dbConn.CommitTransaction();
         }

         Reply(true);
      }
Ejemplo n.º 2
0
 /// <summary>Update traffic cameras retrived by the provider.</summary>
 /// <param name="args">Traffic cameras to update.</param>
 protected void UpdatePoliceTraps(params SpeedCamera[] args) {
    args.Apply(a => a.ProviderId = ServiceName);
    var t = new UpdateSpeedCameras();
    t.Cameras.AddRange(args);
    Services.Invoke(t);
 }