Esempio n. 1
0
        private void InitPlaceMarkAfterUpload(PlacesMarkViewModel placeMarkViewModelLis, HttpPostedFileBase file, int?accurancy, string trackName)
        {
            List <PlaceMarkViewModel> firstPlaceMarkViewModelLis = new List <PlaceMarkViewModel>();

            if (file != null && file?.ContentLength > 0 && file?.ContentType == "application/octet-stream")
            {
                try
                {
                    string path = Path.Combine(Server.MapPath("/"), Path.GetFileName(file.FileName));
                    file.SaveAs(path);
                    ViewBag.Message = "File uploaded successfully";
                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(path);
                    XmlElement  xRoot      = xDoc.DocumentElement;
                    XmlNodeList childnodes = xRoot.GetElementsByTagName("trkpt");

                    var          track  = new Track(trackName);
                    List <Point> points = new List <Point>();

                    foreach (XmlNode xnode in childnodes)
                    {
                        var longitude = double.Parse(xnode.Attributes["lon"].InnerText, System.Globalization.CultureInfo.InvariantCulture);
                        var latitude  = double.Parse(xnode.Attributes["lat"].InnerText, System.Globalization.CultureInfo.InvariantCulture);
                        var altitude  = double.Parse(xnode.FirstChild.InnerText, System.Globalization.CultureInfo.InvariantCulture);
                        var symbolRow = GetSymbolRow(longitude, latitude, accurancy);

                        var point = new Point(xnode.InnerText, longitude, latitude, altitude, symbolRow);

                        points.Add(point);

                        var placeMarkViewModel = new PlaceMarkViewModel()
                        {
                            Name      = xnode.InnerText,
                            Longitude = longitude,
                            Latitude  = latitude,
                            Altitude  = altitude,
                            SymbolRow = symbolRow
                        };
                        firstPlaceMarkViewModelLis.Add(placeMarkViewModel);
                    }

                    track.Points = points;
                    db.Tracks.Add(track);

                    placeMarkViewModelLis.FirstPlaceMark = firstPlaceMarkViewModelLis;
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "ERROR:" + ex.Message.ToString();
                }
            }
            else
            {
                ViewBag.Message = "You have not specified a file or file format is wrong";
            }
            db.SaveChanges();
        }
Esempio n. 2
0
        private List <PlaceMarkViewModel> InitPlaceMark(Track track)
        {
            var firstPlaceMark = new List <PlaceMarkViewModel>();

            foreach (var point in track.Points)
            {
                var placeMarc = new PlaceMarkViewModel(point);
                firstPlaceMark.Add(placeMarc);
            }

            return(firstPlaceMark);
        }
Esempio n. 3
0
        public bool AreEqual(PlaceMarkViewModel secondMark)
        {
            if (!Altitude.Equals(secondMark.Altitude))
            {
                return(false);
            }

            if (!Longitude.Equals(secondMark.Longitude))
            {
                return(false);
            }

            if (!Latitude.Equals(secondMark.Latitude))
            {
                return(false);
            }

            return(true);
        }