Exemplo n.º 1
0
        public static bool FromIsolatedStorageFormatToGRoutes(String text, out List <GRoute> routes)
        {
            routes = new List <GRoute>();
            bool succes = false;

            String[] split   = { Environment.NewLine };
            String   pattern = @">(.*?)<";
            GRoute   route   = new GRoute();
            GPoint   point   = new GPoint();

            String lineValue = "";

            try
            {
                String[] lines = text.Split(split, StringSplitOptions.RemoveEmptyEntries);
                foreach (String line in lines)
                {
                    if (line.Contains("<route>"))
                    {
                        route = new GRoute();
                    }
                    else if (line.Contains("<StartTime>"))
                    {
                        lineValue       = Regex.Matches(line, pattern)[0].Groups[1].ToString();
                        route.StartTime = GPointConverter.FromStringToDateTime(lineValue);
                    }
                    else if (line.Contains("<EndTime>"))
                    {
                        lineValue     = Regex.Matches(line, pattern)[0].Groups[1].ToString();
                        route.EndTime = GPointConverter.FromStringToDateTime(lineValue);
                    }
                    else if (line.Contains("FullTime"))
                    {
                        lineValue      = Regex.Matches(line, pattern)[0].Groups[1].ToString();
                        route.FullTime = TimeSpan.FromSeconds(Int32.Parse(lineValue));
                    }
                    else if (line.Contains("UploadCheck"))
                    {
                        lineValue         = Regex.Matches(line, pattern)[0].Groups[1].ToString();
                        route.UploadCheck = Boolean.Parse(lineValue);
                    }
                    else if (line.Contains("TotalDistance"))
                    {
                        lineValue           = Regex.Matches(line, pattern)[0].Groups[1].ToString();
                        route.TotalDistance = GPointConverter.ConvertToDouble(lineValue);
                    }
                    else if (line.Contains("<point>"))
                    {
                        point = new GPoint();
                    }
                    else if (line.Contains("Lon"))
                    {
                        lineValue       = Regex.Matches(line, pattern)[0].Groups[1].ToString();
                        point.Longitude = GPointConverter.ConvertToDouble(lineValue);
                    }
                    else if (line.Contains("Lat"))
                    {
                        lineValue      = Regex.Matches(line, pattern)[0].Groups[1].ToString();
                        point.Latitude = GPointConverter.ConvertToDouble(lineValue);
                    }
                    else if (line.Contains("Speed"))
                    {
                        lineValue   = Regex.Matches(line, pattern)[0].Groups[1].ToString();
                        point.Speed = GPointConverter.ConvertToDouble(lineValue);
                    }
                    else if (line.Contains("Alt"))
                    {
                        lineValue      = Regex.Matches(line, pattern)[0].Groups[1].ToString();
                        point.Altitude = GPointConverter.ConvertToDouble(lineValue);
                    }
                    else if (line.Contains("Com"))
                    {
                        lineValue     = Regex.Matches(line, pattern)[0].Groups[1].ToString();
                        point.Comment = lineValue;
                    }
                    else if (line.Contains("TT"))
                    {
                        lineValue       = Regex.Matches(line, pattern)[0].Groups[1].ToString();
                        point.TimeTaken = new DateTimeOffset(GPointConverter.FromStringToDateTime(lineValue));
                    }
                    else if (line.Contains("Num"))
                    {
                        lineValue      = Regex.Matches(line, pattern)[0].Groups[1].ToString();
                        point.Altitude = Int32.Parse(lineValue);
                    }
                    else if (line.Contains("/point"))
                    {
                        route.AddNewGPoint(point, false);
                    }
                    else if (line.Contains("/route"))
                    {
                        routes.Add(route);
                    }
                }
            }
            catch (Exception e)
            {
                succes = false;
                MessageBox.Show(e.Message);
            }

            return(succes);
        }