protected override void OnInit(EventArgs e) { base.OnInit(e); string routeName = Request.Params["Route"]; Route r = DBHelper.GetRoute(routeName); if (r == null) { RouteHeader1.Visible = false; DownloadGpsTrack1.Visible = false; ImageIterator1.Visible = false; UnexistingRoute.Visible = true; } else { RouteHeader1.RouteName = routeName; DownloadGpsTrack1.RouteName = routeName; ImageIterator1.ImagesPath = PathFunctions.GetImagePathFromRouteName(routeName); } if (r == null || string.IsNullOrEmpty(r.Description)) { DescriptionParagraphs = new string[0]; return; } DescriptionParagraphs = r.Description.Split(new char[] { '\n' }); }
private string GetRandomImageUrl(out string title, out string pageUrl) { Random r = new Random(DateTime.Now.Second); int i = 10; while (i > 0) { i--; int routeIdx = r.Next(DBHelper.Routes.Count()); Route route = DBHelper.Routes.ElementAt(routeIdx); ImageCache cache = Helper.GetImageCache(PathFunctions.GetImagePathFromRouteName(route.Name)); if (cache.thumbUrls.Length == 0) { continue; } int imageIdx = r.Next(cache.fileUrls.Length); title = route.Title; pageUrl = route.GetRouteUrl(false); return(cache.thumbUrls[imageIdx]); } title = ""; pageUrl = ""; return(""); }
protected void ButtonOffsetDate_Click(object sender, EventArgs e) { string original = PathFunctions.GetImagePathFromRouteName(TextBoxRouteName.Text); if (!Directory.Exists(original)) { return; } TimeSpan offset; if (!TimeSpan.TryParse(TextBoxOffset.Text, out offset)) { return; } foreach (string file in Directory.GetFiles(original, "*.jpg")) { DateTime photoTime; double latidudeRef, latitude, longitudeRef, longitude; Helper.GetImageInfos(file, out photoTime, out latidudeRef, out latitude, out longitudeRef, out longitude); photoTime += offset; Helper.SetCreationTime(file, photoTime); } }
protected void ButtonSave_Click(object sender, EventArgs e) { string routeName = RouteName.Value; try { if (string.IsNullOrEmpty(routeName)) { return; } //non posso salvare una traccia che appartiene ad un alro utente //(se mai riesco a editarla) if (route != null && route.OwnerId != LoginState.User.Id) { return; } //calcolo l'immagine principale UploadedImages list = UploadedImages.FromSession(RouteName.Value); mainImage = ""; foreach (MyRadioButton btn in buttons) { if (btn.Checked) { mainImage = Path.GetFileName(btn.Image.File); break; } } if (route == null) { route = new Route(); } //assegno i dati al record route.Image = mainImage; route.Name = routeName; route.OwnerId = LoginState.User.Id; int c = 0; if (int.TryParse(TextBoxCiclyng.Text, out c)) { route.Cycling = c; } route.Title = TextBoxTitle.Text; route.Description = TextBoxDescription.Text; route.Difficulty = TextBoxDifficulty.Text; //salvo il file gpx GpxParser parser = GpxParser.FromSession(routeName); if (parser != null) { string gpxFile = PathFunctions.GetGpxPathFromRouteName(routeName); string path = Path.GetDirectoryName(gpxFile); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } parser.Save(gpxFile); } //salvo le immagini string imageFolder = PathFunctions.GetImagePathFromRouteName(routeName); if (!Directory.Exists(imageFolder)) { Directory.CreateDirectory(imageFolder); } foreach (UploadedImage ui in list) { ui.SaveTo(imageFolder); } //elimino una eventuale cache Helper.ClearImageCache(imageFolder); //forzo la generazione dei thumbnails Helper.GetImageCache(imageFolder); bool published = CheckBoxPublished.Checked; route.Draft = !published; //salvo il record DBHelper.SaveRoute(route); if (published) { //mando una mail agli utenti registrati string msg = string.Format("Ciao biker!<br/>L'utente {0} ha inserito o modificato il percorso<br/><a target=\"route\" href=\"{1}\">{2}</a><br/>Scarica il tracciato e vieni a provarlo!<br/><br/>MTB Scout", LoginState.User.DisplayName, "http://www.mtbscout.it" + route.GetRouteUrl(false), route.Title ); foreach (MTBUser u in DBHelper.Users) { if (u.SendMail) { Helper.SendMail(u.EMail, null, null, "Inserimento/modifica percorso", msg, true); } } } ScriptManager.RegisterStartupScript(this, GetType(), "MessageOK", "alert('Informazioni salvate correttamente.');", true); } catch (Exception ex) { Log.Add("Error saving route '{0}': '{1}'", routeName, ex.ToString()); ScriptManager.RegisterStartupScript(this, GetType(), "Error", string.Format("alert('Errore durante il salvataggio: {0}.');", ex.Message.Replace("'", "\\'")), true); } }