public ActionResult Update(Views.ParkingLot.ParkingLot lot)
        {
            ParkingLot model;

            if (TryGetLot(lot.ID, out model))
            {
                lock (model)
                {
                    model.Annotations.Clear();
                    // Add annotations
                    if (lot.Annotations != null)
                    {
                        foreach (var annotation in lot.Annotations)
                        {
                            var modelAnnotation = new Annotation(model.Annotations.Count > 0 ? model.Annotations.Max(a => a.ID) + 1 : 0, (Annotation.AnnotationType)Enum.Parse(typeof(Annotation.AnnotationType), annotation.Type));
                            model.Annotations.Add(modelAnnotation);
                            foreach (var point in annotation.Points)
                            {
                                modelAnnotation.Add(new Models.Geometry.Vector2(point.X, point.Y));
                            }
                        }
                    }
                    // Set the camera
                    model.Camera = Repository <Camera> .Get(lot.CameraID);
                }
                EagleEyeConfig.ExportDatabase();
                return(new EmptyResult());
            }
            return(new HttpNotFoundResult());
        }
Beispiel #2
0
 public static void ImportDatabase()
 {
     try
     {
         locker.AcquireReaderLock(Int32.MaxValue);
         using (var stream = new StreamReader(DatabasePath))
         {
             Json database = Json.Import(stream);
             Json cameras  = database["Cameras"];
             for (int i = 0; i < cameras.Count; i++)
             {
                 Json   cameraJson = cameras[i];
                 Camera camera     = new Camera(cameraJson["ID"], cameraJson["Name"]);
                 Repository <Camera> .Add(camera);
             }
             Json parkingLots = database["ParkingLots"];
             for (int i = 0; i < parkingLots.Count; i++)
             {
                 Json       lotJson    = parkingLots[i];
                 ParkingLot lot        = new ParkingLot(lotJson["ID"], lotJson["Name"], Repository <Camera> .Get(lotJson["Camera"]));
                 string     bitmapPath = $"{HttpRuntime.AppDomainAppPath}App_Data\\{(int)lotJson["ID"]}.jpg";
                 if (File.Exists(bitmapPath))
                 {
                     lot.Baseline = new Bitmap(Bitmap.FromFile(bitmapPath) as Bitmap);
                 }
                 for (int a = 0; a < lotJson["Annotations"].Count; a++)
                 {
                     Json       ann        = lotJson["Annotations"][a];
                     Annotation annotation = new Annotation(ann["ID"], (Annotation.AnnotationType)(int) ann["Type"]);
                     for (int p = 0; p < ann["Points"].Count; p++)
                     {
                         Json point = ann["Points"][p];
                         Models.Geometry.Vector2 pnt = new Models.Geometry.Vector2(point["X"], point["Y"]);
                         annotation.Add(pnt);
                     }
                     lot.Annotations.Add(annotation);
                 }
                 Repository <ParkingLot> .Add(lot);
             }
         }
     } finally
     {
         locker.ReleaseReaderLock();
     }
 }
        Annotation ReadAnnotation(XmlElement e)
        {
            Annotation annotation = new Annotation();

             if (e.HasChildNodes)
             {
            foreach (XmlNode node in e.ChildNodes)
            {
               annotation.Add(node);
            }
             }

             return annotation;
        }