Пример #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(Request["u"]) && !string.IsNullOrEmpty(Request["json"]))
            {
                string jsonString = Request["json"];

                Affine.Data.json.MapRoute mapRoute = serializer.Deserialize <Affine.Data.json.MapRoute>(jsonString);

                long userKey = Convert.ToInt64(Request["u"]);
                Affine.Data.MapRoute route = new MapRoute()
                {
                    Name          = mapRoute.Name,
                    City          = mapRoute.City,
                    Region        = mapRoute.Region,
                    Rating        = mapRoute.Rating,
                    PortalKey     = 0,              // TODO: send this in
                    UserKey       = userKey,
                    RouteDistance = mapRoute.RouteDistance,
                    LatMax        = mapRoute.LatMax,
                    LatMin        = mapRoute.LatMin,
                    LngMax        = mapRoute.LngMax,
                    LngMin        = mapRoute.LngMin,
                    CreationDate  = DateTime.Now
                };
                Affine.Data.MapRoutePoint[] points = mapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint()
                {
                    Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order, MapRoute = route
                }).ToArray <Affine.Data.MapRoutePoint>();
                route.MapRoutePoints.Concat(points);
                aqufitEntities entities = new aqufitEntities();
                entities.AddToMapRoutes(route);
                long     id                  = entities.SaveChanges();
                MapRoute passback            = entities.MapRoutes.Where(m => m.UserKey == userKey).OrderByDescending(m => m.Id).FirstOrDefault();
                Affine.Data.json.MapRoute mr = new Affine.Data.json.MapRoute()
                {
                    Id = passback.Id, Name = passback.Name, RouteDistance = passback.RouteDistance
                };
                string json = serializer.Serialize(mr);
                Response.Write(json);
            }
            else
            {
                Affine.Data.json.MapRoute route = new Affine.Data.json.MapRoute()
                {
                    Id = -1
                };
                Response.Write(serializer.Serialize(route));
            }
        }
        catch (Exception)
        {
            Affine.Data.json.MapRoute route = new Affine.Data.json.MapRoute()
            {
                Id = -1
            };
            Response.Write(serializer.Serialize(route));
        }
    }
Пример #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(Request["u"]) && !string.IsNullOrEmpty(Request["json"]))
            {
                string jsonString = Request["json"];

                Affine.Data.json.MapRoute mapRoute = serializer.Deserialize<Affine.Data.json.MapRoute>(jsonString);

                long userKey = Convert.ToInt64(Request["u"]);
                Affine.Data.MapRoute route = new MapRoute()
                {
                    Name = mapRoute.Name,
                    City = mapRoute.City,
                    Region = mapRoute.Region,
                    Rating = mapRoute.Rating,
                    PortalKey = 0,                  // TODO: send this in
                    UserKey = userKey,
                    RouteDistance = mapRoute.RouteDistance,
                    LatMax = mapRoute.LatMax,
                    LatMin = mapRoute.LatMin,
                    LngMax = mapRoute.LngMax,
                    LngMin = mapRoute.LngMin,
                    CreationDate = DateTime.Now
                };
                Affine.Data.MapRoutePoint[] points = mapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint() { Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order, MapRoute = route }).ToArray<Affine.Data.MapRoutePoint>();
                route.MapRoutePoints.Concat(points);
                aqufitEntities entities = new aqufitEntities();
                entities.AddToMapRoutes(route);
                long id = entities.SaveChanges();
                MapRoute passback = entities.MapRoutes.Where(m => m.UserKey == userKey ).OrderByDescending( m => m.Id).FirstOrDefault();
                Affine.Data.json.MapRoute mr = new Affine.Data.json.MapRoute() { Id = passback.Id, Name = passback.Name, RouteDistance = passback.RouteDistance };
                string json = serializer.Serialize(mr);
                Response.Write(json);
            }
            else
            {
                Affine.Data.json.MapRoute route = new Affine.Data.json.MapRoute() { Id = -1 };
                Response.Write(serializer.Serialize(route));
            }
        }
        catch (Exception)
        {
            Affine.Data.json.MapRoute route = new Affine.Data.json.MapRoute() { Id = -1 };
            Response.Write(serializer.Serialize(route));
        }
    }
Пример #3
0
        protected void bAjaxPostback_Click(object sender, EventArgs e)
        {
            switch (hiddenAjaxAction.Value)
            {
                case "saveRoute":
                    aqufitEntities entities = new aqufitEntities();
                    Affine.Data.MapRoute route = new MapRoute()
                    {
                        Name = atiGMapRoute.RouteTitle,
                        PortalKey = this.PortalId,                  // TODO: send this in
                        UserSetting = entities.UserSettings.First( u => u.Id == UserSettings.Id ),
                        RouteDistance = atiGMapRoute.RouteDistance,
                        CreationDate = DateTime.Now,
                        WorkoutTypeId = atiGMapRoute.WorkoutTypeKey
                    };

                    entities.AddToMapRoutes(route);
                    double zoom = atiGMapRoute.FitZoom;
                    double w = atiGMapRoute.MapWidth/200.0;
                    double h = atiGMapRoute.MapHeight/100.0;
                    double r = w > h ? w : h;
                    zoom = r > 0 ? zoom - Math.Sqrt(r) : zoom + Math.Sqrt(r);
                    route.ThumbZoom = (short)Math.Floor(zoom);

                    Affine.Data.MapRoutePoint[] points = atiGMapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint() { Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order, MapRoute = route }).ToArray<Affine.Data.MapRoutePoint>();
                    route.MapRoutePoints.Concat(points);
                    double minLat = double.MaxValue;
                    double minLng = double.MaxValue;
                    double maxLat = double.MinValue;
                    double maxLng = double.MinValue;
                    foreach( Affine.Data.MapRoutePoint p in points )
                    {
                        if (p.Lat < minLat)
                        {
                            minLat = p.Lat;
                        }
                        if (p.Lng < minLng)
                        {
                            minLng = p.Lng;
                        }
                        if (p.Lat > maxLat)
                        {
                            maxLat = p.Lat;
                        }
                        if (p.Lng > maxLng)
                        {
                            maxLng = p.Lng;
                        }
                    }
                    route.LatMax = maxLat;
                    route.LatMin = minLat;
                    route.LngMax = maxLng;
                    route.LngMin = minLng;
                    // Cull points until there are 100 or less points to make the encoded polyline fit the 512 bytes
                    int len = 100;
                    IList<Affine.Data.MapRoutePoint> pointCopy = atiGMapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint() { Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order }).ToList<Affine.Data.MapRoutePoint>();
                    pointCopy = CullPoints(pointCopy, len);
                    route.PolyLineEncoding = Affine.Utils.PolylineEncoder.createEncodings(pointCopy, 17, 1)["encodedPoints"].ToString();
                    while (route.PolyLineEncoding.Length > 512)
                    {
                        len = len/2;
                        pointCopy = CullPoints(pointCopy, len);
                        route.PolyLineEncoding = Affine.Utils.PolylineEncoder.createEncodings(pointCopy, 17, 1)["encodedPoints"].ToString();
                    }
                    entities.SaveChanges();
                    MapRoute passback = entities.MapRoutes.Where(m => m.UserSetting.Id == this.UserSettings.Id && m.PortalKey == this.PortalId ).OrderByDescending( m => m.Id).FirstOrDefault();
                    // routes creater needs the route to show up in their route list now.
                    User2MapRouteFav fav = new User2MapRouteFav()
                    {
                        MapRoute = passback,
                        UserSettingsKey = UserSettings.Id
                    };
                    entities.AddToUser2MapRouteFav(fav);
                    entities.SaveChanges();

                    Affine.Data.json.MapRoute mr = new Affine.Data.json.MapRoute() { Id = passback.Id, Name = passback.Name, RouteDistance = passback.RouteDistance };
                    RadAjaxManager1.ResponseScripts.Add(" setSelectedMap(" + passback.Id + ", '" + passback.Name + "', " + passback.RouteDistance + ", ''); ");
                    break;
            }
            // save and close  RadAjaxManager1.ResponseScripts.Add();  /
        }
Пример #4
0
        protected void bAjaxPostback_Click(object sender, EventArgs e)
        {
            switch (hiddenAjaxAction.Value)
            {
            case "saveRoute":
                aqufitEntities       entities = new aqufitEntities();
                Affine.Data.MapRoute route    = new MapRoute()
                {
                    Name          = atiGMapRoute.RouteTitle,
                    PortalKey     = this.PortalId,                  // TODO: send this in
                    UserSetting   = entities.UserSettings.First(u => u.Id == UserSettings.Id),
                    RouteDistance = atiGMapRoute.RouteDistance,
                    CreationDate  = DateTime.Now,
                    WorkoutTypeId = atiGMapRoute.WorkoutTypeKey
                };

                entities.AddToMapRoutes(route);
                double zoom = atiGMapRoute.FitZoom;
                double w    = atiGMapRoute.MapWidth / 200.0;
                double h    = atiGMapRoute.MapHeight / 100.0;
                double r    = w > h ? w : h;
                zoom            = r > 0 ? zoom - Math.Sqrt(r) : zoom + Math.Sqrt(r);
                route.ThumbZoom = (short)Math.Floor(zoom);

                Affine.Data.MapRoutePoint[] points = atiGMapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint()
                {
                    Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order, MapRoute = route
                }).ToArray <Affine.Data.MapRoutePoint>();
                route.MapRoutePoints.Concat(points);
                double minLat = double.MaxValue;
                double minLng = double.MaxValue;
                double maxLat = double.MinValue;
                double maxLng = double.MinValue;
                foreach (Affine.Data.MapRoutePoint p in points)
                {
                    if (p.Lat < minLat)
                    {
                        minLat = p.Lat;
                    }
                    if (p.Lng < minLng)
                    {
                        minLng = p.Lng;
                    }
                    if (p.Lat > maxLat)
                    {
                        maxLat = p.Lat;
                    }
                    if (p.Lng > maxLng)
                    {
                        maxLng = p.Lng;
                    }
                }
                route.LatMax = maxLat;
                route.LatMin = minLat;
                route.LngMax = maxLng;
                route.LngMin = minLng;
                // Cull points until there are 100 or less points to make the encoded polyline fit the 512 bytes
                int len = 100;
                IList <Affine.Data.MapRoutePoint> pointCopy = atiGMapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint()
                {
                    Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order
                }).ToList <Affine.Data.MapRoutePoint>();
                pointCopy = CullPoints(pointCopy, len);
                route.PolyLineEncoding = Affine.Utils.PolylineEncoder.createEncodings(pointCopy, 17, 1)["encodedPoints"].ToString();
                while (route.PolyLineEncoding.Length > 512)
                {
                    len       = len / 2;
                    pointCopy = CullPoints(pointCopy, len);
                    route.PolyLineEncoding = Affine.Utils.PolylineEncoder.createEncodings(pointCopy, 17, 1)["encodedPoints"].ToString();
                }
                entities.SaveChanges();
                MapRoute passback = entities.MapRoutes.Where(m => m.UserSetting.Id == this.UserSettings.Id && m.PortalKey == this.PortalId).OrderByDescending(m => m.Id).FirstOrDefault();
                // routes creater needs the route to show up in their route list now.
                User2MapRouteFav fav = new User2MapRouteFav()
                {
                    MapRoute        = passback,
                    UserSettingsKey = UserSettings.Id
                };
                entities.AddToUser2MapRouteFav(fav);
                entities.SaveChanges();

                Affine.Data.json.MapRoute mr = new Affine.Data.json.MapRoute()
                {
                    Id = passback.Id, Name = passback.Name, RouteDistance = passback.RouteDistance
                };
                RadAjaxManager1.ResponseScripts.Add(" setSelectedMap(" + passback.Id + ", '" + passback.Name + "', " + passback.RouteDistance + ", ''); ");
                break;
            }
            // save and close  RadAjaxManager1.ResponseScripts.Add();  /
        }
Пример #5
0
 public string getWorkout(long wid)
 {
     aqufitEntities entities = new aqufitEntities();
     Workout workout = entities.UserStreamSet.Include("WorkoutExtendeds").Include("WorkoutExtendeds.MapRoute").Include("UserSetting").OfType<Workout>().FirstOrDefault(w => w.Id == wid);
     if (workout != null)
     {
         Affine.Data.json.Workout json = new Affine.Data.json.Workout()
         {
             Calories = workout.Calories,
             Date = workout.Date.ToLocalTime().ToShortDateString(),
             Description = workout.Description,
             Distance = workout.Distance,
             Duration = workout.Duration,
             Emotion = workout.Emotion,
             Id = workout.Id,
             Title = workout.Title,
             PortalKey = workout.PortalKey,
             UserKey = workout.UserSetting.UserKey,
             Weather = workout.Weather,
             DataSrc = workout.DataSrc,
             WorkoutTypeKey = Convert.ToInt64( workout.WorkoutTypeKey )
         };
         if (workout.WorkoutExtendeds.FirstOrDefault() != null)
         {
             WorkoutExtended ext = workout.WorkoutExtendeds.First();
             Affine.Data.json.WorkoutExtended jsonWorkoutExtended = new Affine.Data.json.WorkoutExtended()
             {
                 Id = ext.Id,
                 LatMax = ext.LatMax,
                 LatMin = ext.LatMin,
                 LngMax = ext.LngMax,
                 LngMin = ext.LngMin
             };
             Affine.Data.json.WorkoutSample[] samples = entities.WorkoutSamples.Where(s => s.WorkoutExtended.Id == ext.Id).OrderBy(s => s.SampleNumber)
                                                         .Select(s => new Affine.Data.json.WorkoutSample()
                                                         {
                                                             Date = s.Date,
                                                             Time = 0,
                                                             Distance = s.Distance,
                                                             Elevation = s.Elevation,
                                                             HeartRate = s.HeartRate,
                                                             Id = s.Id,
                                                             Lat = s.Lat,
                                                             Lng = s.Lng,
                                                             SampleNumber = s.SampleNumber
                                                         }).ToArray();
             foreach (Affine.Data.json.WorkoutSample s in samples)
             {
                 s.Time = s.Date.Ticks;
             }
             jsonWorkoutExtended.WorkoutSamples = samples;
             json.WorkoutExtended = jsonWorkoutExtended;
             if (ext.MapRoute != null)
             {
                 MapRoute mr = ext.MapRoute;
                 Affine.Data.json.MapRoute jsonMapRoute = new Affine.Data.json.MapRoute()
                 {
                     Id = mr.Id,
                     LatMax = mr.LatMax,
                     LatMin = mr.LatMin,
                     LngMax = mr.LngMax,
                     LngMin = mr.LngMin,
                     City = mr.City,
                     Name = mr.Name,
                     PortalKey = mr.PortalKey,
                     Rating = mr.Rating,
                     RouteDistance = mr.RouteDistance,
                     UserKey = workout.UserSetting.Id,
                     Region = mr.Region
                 };
                 Affine.Data.json.MapRoutePoint[] points = entities.MapRoutePoints.Where( mp => mp.MapRoute.Id == mr.Id ).OrderBy( mp => mp.Order ).Select(p => new Affine.Data.json.MapRoutePoint()
                                                                                                 {
                                                                                                     Id = p.Id,
                                                                                                     Lat = p.Lat,
                                                                                                     Lng = p.Lng,
                                                                                                     Order = p.Order
                                                                                                 }).ToArray();
                 jsonMapRoute.MapRoutePoints = points;
                 json.WorkoutExtended.MapRoute = jsonMapRoute;
             }
         }
         JavaScriptSerializer jserializer = new JavaScriptSerializer();
         return jserializer.Serialize(json);
     }
     return "";
 }