示例#1
0
        public void SaveDataBase()
        {
            using (ArgeoContext context = GetNewLocalRepositoryInstance())
            {
                foreach (PointOfInterestViewModel poi in this.Entities.OfType <PointOfInterestViewModel>().Where(s => s._Id == 0))
                {
                    Graphics old = context.Graphics.Find(poi._Id);
                    if (old != null)
                    {
                        old.Height    = poi.Graphics.Height;
                        old.Width     = poi.Graphics.Width;
                        old.Type      = poi.Graphics.Type;
                        old.Image     = Helper.BitmapHelper.SaveImage(poi.Graphics.Image);
                        old.ImageId   = poi.Graphics.ImageId;
                        old.Timestamp = Helper.DateTimeHelper.DateTimeToUnixTimeStamp(poi.Graphics.Timestamp);
                        context.SaveChanges();
                    }
                    else
                    {
                        Graphics model = new Graphics
                        {
                            Height    = poi.Graphics.Height,
                            Width     = poi.Graphics.Width,
                            Type      = poi.Graphics.Type,
                            Image     = Helper.BitmapHelper.SaveImage(poi.Graphics.Image),
                            ImageId   = poi.Graphics.ImageId,
                            Timestamp = Helper.DateTimeHelper.DateTimeToUnixTimeStamp(poi.Graphics.Timestamp),
                        };
                        context.Graphics.Add(model);
                        // Need _Id obtained by autoincrement
                        context.SaveChanges();
                        poi.Graphics._Id = model._Id;
                    }
                }

                foreach (PointOfInterestViewModel poi in this.Entities.OfType <PointOfInterestViewModel>().Where(s => s._Id == 0))
                {
                    PointOfInterest old = context.PointsOfInterest.Find(poi._Id);
                    if (old != null)
                    {
                        old.Id          = poi.Id;
                        old.Description = poi.Description;
                        old.Height      = poi.Height;
                        old.Latitude    = poi.Latitude;
                        old.Longitude   = poi.Longitude;
                        old.IdGraphics  = poi.Graphics._Id;
                        old.Timestamp   = Helper.DateTimeHelper.DateTimeToUnixTimeStamp(poi.Timestamp);
                        context.SaveChanges();
                    }
                    else
                    {
                        PointOfInterest model = new PointOfInterest
                        {
                            Id          = poi.Id,
                            Description = poi.Description,
                            Height      = poi.Height,
                            Latitude    = poi.Latitude,
                            Longitude   = poi.Longitude,
                            IdGraphics  = poi.Graphics._Id,
                            Timestamp   = Helper.DateTimeHelper.DateTimeToUnixTimeStamp(poi.Timestamp)
                        };
                        context.PointsOfInterest.Add(model);
                        // Need _Id obtained by autoincrement
                        context.SaveChanges();
                        poi._Id = model._Id;
                    }
                }

                foreach (PlaneViewModel plane in this.Entities.OfType <PlaneViewModel>())
                {
                    Plane old = context.Planes.Find(plane._Id);
                    if (old != null)
                    {
                        old.Id                     = plane.Id;
                        old.Description            = plane.Description;
                        old.Dip                    = plane.Dip;
                        old.Height                 = plane.Height;
                        old.Latitude               = plane.Latitude;
                        old.Longitude              = plane.Longitude;
                        old.ShowVirtualOrientation = plane.ShowVirtualOrientation;
                        old.Size                   = plane.Size;
                        old.Strike                 = plane.Strike;
                        old.Thickness              = plane.Thickness;
                        old.VirtualOrientation     = plane.VirtualOrientation;
                        old.Timestamp              = Helper.DateTimeHelper.DateTimeToUnixTimeStamp(plane.Timestamp);
                        context.SaveChanges();
                    }
                    else
                    {
                        Plane model = new Plane
                        {
                            Id                     = plane.Id,
                            Description            = plane.Description,
                            Dip                    = plane.Dip,
                            Height                 = plane.Height,
                            Latitude               = plane.Latitude,
                            Longitude              = plane.Longitude,
                            ShowVirtualOrientation = plane.ShowVirtualOrientation,
                            Size                   = plane.Size,
                            Strike                 = plane.Strike,
                            Thickness              = plane.Thickness,
                            VirtualOrientation     = plane.VirtualOrientation,
                            Timestamp              = Helper.DateTimeHelper.DateTimeToUnixTimeStamp(plane.Timestamp)
                        };

                        context.Planes.Add(model);
                        // Need _Id obtained by autoincrement
                        context.SaveChanges();
                        plane._Id = model._Id;
                    }
                }

                foreach (TTARViewViewModel ttarview in this.Entities.OfType <TTARViewViewModel>())
                {
                    TTARView old = context.TTARViews.Find(ttarview._Id);
                    if (old != null)
                    {
                        old.Id          = ttarview.Id;
                        old.Description = ttarview.Description;
                        old.BitmapFrame = Helper.BitmapHelper.SaveImage(ttarview.BitmapFrame);
                        old.BitmapView  = Helper.BitmapHelper.SaveImage(ttarview.BitmapView);
                        old.Pitch       = ttarview.Pitch;
                        old.Roll        = ttarview.Roll;
                        old.Yaw         = ttarview.Yaw;
                        old.Height      = ttarview.Height;
                        old.Latitude    = ttarview.Latitude;
                        old.Longitude   = ttarview.Longitude;
                        old.Timestamp   = Helper.DateTimeHelper.DateTimeToUnixTimeStamp(ttarview.Timestamp);
                        context.SaveChanges();
                    }
                    else
                    {
                        TTARView model = new TTARView
                        {
                            Id          = ttarview.Id,
                            Description = ttarview.Description,
                            BitmapFrame = Helper.BitmapHelper.SaveImage(ttarview.BitmapFrame),
                            BitmapView  = Helper.BitmapHelper.SaveImage(ttarview.BitmapView),
                            Pitch       = ttarview.Pitch,
                            Roll        = ttarview.Roll,
                            Yaw         = ttarview.Yaw,
                            Height      = ttarview.Height,
                            Latitude    = ttarview.Latitude,
                            Longitude   = ttarview.Longitude,
                            Timestamp   = Helper.DateTimeHelper.DateTimeToUnixTimeStamp(ttarview.Timestamp)
                        };

                        context.TTARViews.Add(model);
                        // Need _Id obtained by autoincrement
                        context.SaveChanges();
                        ttarview._Id = model._Id;
                    }
                }


                foreach (CoreSampleViewModel coresample in this.Entities.OfType <CoreSampleViewModel>())
                {
                    CoreSample old = context.CoreSamples.Find(coresample._Id);
                    if (old != null)
                    {
                        old.Id           = coresample.Id;
                        old.Description  = coresample.Description;
                        old.Height       = coresample.Height;
                        old.Latitude     = coresample.Latitude;
                        old.Longitude    = coresample.Longitude;
                        old.BottomRadius = coresample.BottomRadius;
                        old.TopRadius    = coresample.TopRadius;
                        old.Length       = coresample.Length;
                        old.Slices       = coresample.Slices;
                        old.Timestamp    = Helper.DateTimeHelper.DateTimeToUnixTimeStamp(coresample.Timestamp);
                        context.SaveChanges();
                    }
                    else
                    {
                        CoreSample model = new CoreSample
                        {
                            Id           = coresample.Id,
                            Description  = coresample.Description,
                            Height       = coresample.Height,
                            Latitude     = coresample.Latitude,
                            Longitude    = coresample.Longitude,
                            BottomRadius = coresample.BottomRadius,
                            TopRadius    = coresample.TopRadius,
                            Length       = coresample.Length,
                            Slices       = coresample.Slices,
                            Timestamp    = Helper.DateTimeHelper.DateTimeToUnixTimeStamp(coresample.Timestamp)
                        };

                        context.CoreSamples.Add(model);
                        // Need _Id obtained by autoincrement
                        context.SaveChanges();
                        coresample._Id = model._Id;
                    }
                }

                foreach (PlaneViewModel entityToRemove in this.EntitiesToRemove.OfType <PlaneViewModel>())
                {
                    context.Planes.Remove(context.Planes.Find(entityToRemove._Id));
                }

                foreach (TTARViewViewModel entityToRemove in this.EntitiesToRemove.OfType <TTARViewViewModel>())
                {
                    context.TTARViews.Remove(context.TTARViews.Find(entityToRemove._Id));
                }

                foreach (PointOfInterestViewModel entityToRemove in this.EntitiesToRemove.OfType <PointOfInterestViewModel>())
                {
                    context.PointsOfInterest.Remove(context.PointsOfInterest.Find(entityToRemove._Id));
                }

                foreach (CoreSampleViewModel entityToRemove in this.EntitiesToRemove.OfType <CoreSampleViewModel>())
                {
                    context.CoreSamples.Remove(context.CoreSamples.Find(entityToRemove._Id));
                }

                foreach (GraphicsViewModel entityToRemove in this.EntitiesToRemove.OfType <GraphicsViewModel>())
                {
                    context.Graphics.Remove(context.Graphics.Find(entityToRemove._Id));
                }

                context.SaveChanges();
                this.EntitiesToRemove.Clear();
            }
        }
示例#2
0
        private void OnImportCSV(object commandParameter)
        {
            List <string> columns = new List <string>();
            Dictionary <string, List <string> > values = new Dictionary <string, List <string> >();
            ArgeoContext localRepository = GetNewLocalRepositoryInstance();

            // Import Core Sample
            Helper.Importer.ImportCSVToDataBase(
                out columns,
                out values,
                @"C:\Users\juanmanuel\desktop\coresamples.csv");

            int count = values.First().Value.Count;

            for (int i = 0; i < count; i++)
            {
                CoreSample model = new CoreSample
                {
                    _Id          = Int64.Parse(values["_Id"][i]),
                    Id           = values["Id"][i],
                    Description  = values["Description"][i],
                    Longitude    = Double.Parse(values["Longitude"][i]),
                    Latitude     = Double.Parse(values["Latitude"][i]),
                    Height       = Double.Parse(values["Height"][i]),
                    BottomRadius = Double.Parse(values["BottomRadius"][i]),
                    TopRadius    = Double.Parse(values["TopRadius"][i]),
                    Length       = Double.Parse(values["Length"][i]),
                    Slices       = Double.Parse(values["Slices"][i]),
                    Timestamp    = Int64.Parse(values["Timestamp"][i]),
                };

                CoreSample coresample = localRepository.CoreSamples.Find(model._Id);
                if (coresample == null || model.Timestamp > coresample.Timestamp)
                {
                    localRepository.CoreSamples.Add(model);
                }
            }


            // Import TTAR Views
            Helper.Importer.ImportCSVToDataBase(
                out columns,
                out values,
                @"C:\Users\juanmanuel\desktop\ttarviews.csv");

            count = values.First().Value.Count;
            for (int i = 0; i < count; i++)
            {
                TTARView model = new TTARView
                {
                    _Id         = Int64.Parse(values["_Id"][i]),
                    Id          = values["Id"][i],
                    Description = values["Description"][i],
                    Longitude   = Double.Parse(values["Longitude"][i]),
                    Latitude    = Double.Parse(values["Latitude"][i]),
                    Height      = Double.Parse(values["Height"][i]),
                    Pitch       = Double.Parse(values["Pitch"][i]),
                    Roll        = Double.Parse(values["Roll"][i]),
                    Yaw         = Double.Parse(values["Yaw"][i]),
                    BitmapFrame = Convert.FromBase64String(values["BitmapFrame"][i]),
                    BitmapView  = Convert.FromBase64String(values["BitmapView"][i]),
                    Timestamp   = Int64.Parse(values["Timestamp"][i]),
                };

                TTARView ttarview = localRepository.TTARViews.Find(model._Id);
                if (ttarview == null || model.Timestamp > ttarview.Timestamp)
                {
                    localRepository.TTARViews.Add(model);
                }
            }

            // Import Planes
            Helper.Importer.ImportCSVToDataBase(
                out columns,
                out values,
                @"C:\Users\juanmanuel\desktop\planes.csv");

            count = values.First().Value.Count;
            for (int i = 0; i < count; i++)
            {
                Plane model = new Plane
                {
                    _Id                    = Int64.Parse(values["_Id"][i]),
                    Id                     = values["Id"][i],
                    Description            = values["Description"][i],
                    Longitude              = Double.Parse(values["Longitude"][i]),
                    Latitude               = Double.Parse(values["Latitude"][i]),
                    Height                 = Double.Parse(values["Height"][i]),
                    Dip                    = Double.Parse(values["Dip"][i]),
                    ShowVirtualOrientation = Boolean.Parse(values["ShowVirtualOrientation"][i]),
                    Size                   = Double.Parse(values["Size"][i]),
                    Strike                 = Double.Parse(values["Strike"][i]),
                    Thickness              = Double.Parse(values["Thickness"][i]),
                    VirtualOrientation     = Double.Parse(values["VirtualOrientation"][i]),
                    Timestamp              = Int64.Parse(values["Timestamp"][i]),
                };

                Plane plane = localRepository.Planes.Find(model._Id);
                if (plane == null || model.Timestamp > plane.Timestamp)
                {
                    localRepository.Planes.Add(model);
                }
            }

            // Import Pois
            Helper.Importer.ImportCSVToDataBase(
                out columns,
                out values,
                @"C:\Users\juanmanuel\desktop\pois.csv");

            count = values.First().Value.Count;
            for (int i = 0; i < count; i++)
            {
                PointOfInterest model = new PointOfInterest
                {
                    _Id         = Int64.Parse(values["_Id"][i]),
                    Id          = values["Id"][i],
                    Description = values["Description"][i],
                    Longitude   = Double.Parse(values["Longitude"][i]),
                    Latitude    = Double.Parse(values["Latitude"][i]),
                    Height      = Double.Parse(values["Height"][i]),
                    IdGraphics  = Int64.Parse(values["IdGraphics"][i]),
                    Timestamp   = Int64.Parse(values["Timestamp"][i]),
                };

                PointOfInterest poi = localRepository.PointsOfInterest.Find(model._Id);
                if (poi == null || model.Timestamp > poi.Timestamp)
                {
                    localRepository.PointsOfInterest.Add(model);
                }
            }

            // Import Graphics
            Helper.Importer.ImportCSVToDataBase(
                out columns,
                out values,
                @"C:\Users\juanmanuel\desktop\graphics.csv");

            count = values.First().Value.Count;
            for (int i = 0; i < count; i++)
            {
                Graphics model = new Graphics
                {
                    _Id       = Int64.Parse(values["_Id"][i]),
                    ImageId   = values["ImageId"][i],
                    Image     = Convert.FromBase64String(values["Image"][i]),
                    Height    = Int64.Parse(values["Height"][i]),
                    Width     = Int64.Parse(values["Width"][i]),
                    Type      = values["Type"][i],
                    Timestamp = Int64.Parse(values["Timestamp"][i]),
                };
                Graphics graphics = localRepository.Graphics.Find(model._Id);
                if (graphics == null || model.Timestamp > graphics.Timestamp)
                {
                    localRepository.Graphics.Add(model);
                }
            }

            localRepository.SaveChanges();

            this.LoadDataBase();
        }