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' }); }
protected void Page_Load(object sender, EventArgs e) { string routeName = Request.QueryString["Route"]; UploadedImages list = UploadedImages.FromSession(routeName); string temporaryFolder = PathFunctions.GetTempPath(); for (int i = 0; i < Request.Files.Count; i++) { try { HttpPostedFile file = Request.Files[i]; //creo un nuovo file in session string filePath = Path.Combine(temporaryFolder, string.Format("{0}-{1}.jpg", (list.Count + 1).ToString("000"), routeName)); UploadedImage ui = new UploadedImage(filePath, file.InputStream); if (string.IsNullOrEmpty(ui.Description)) { ui.Description = Path.GetFileNameWithoutExtension(file.FileName); } list.Add(ui); } catch { //file non valido, mancato upload! } } }
/// <summary> /// Gets a list of the available object ID's managed by the repository /// </summary> /// <returns>object ids</returns> public IList <StorableItemMetadata <T> > GetIds() { var result = new List <StorableItemMetadata <T> >(); var files = GetFiles(); foreach (var name in files.FileNames) { var file = new FileInfo(name); if (mode == FileMode.DirPerFile) { result.Add( new StorableItemMetadata <T> { Id = (new DirectoryInfo(PathFunctions.GetDirectoryName(name))).Name, Loaded = false, Object = null, Uri = name }); } else { result.Add( new StorableItemMetadata <T> { Id = PathFunctions.GetFileNameWithoutExtension(name), Loaded = false, Object = null, Uri = name }); } } return(result); }
protected void ButtonNewRoute_Click(object sender, EventArgs e) { Guid guid = Guid.NewGuid(); string url = PathFunctions.GetUrlFromPath(PathFunctions.EditRoutePage, false).Replace("'", "\\'") + "?Route=" + guid.ToString(); Response.Redirect(url); }
protected void Page_Load(object sender, EventArgs e) { try { string routeName = Request.QueryString["Route"]; if (!IsPostBack) { Route r = DBHelper.GetRoute(routeName); if (r != null) { string gpxFile = PathFunctions.GetGpxPathFromRouteName(routeName); parser = Helper.GetGpxParser(gpxFile); if (parser != null) { parser.LoadPhothos(); } Title = r.Title; } } bool editMode = Request.QueryString["EditMode"] == "true"; GenerateCustomOptions(editMode); ChooseRoute.Visible = editMode; if (editMode && FileUploadGpx.HasFile) { try { GpxParser p = new GpxParser(); p.Parse(FileUploadGpx.FileContent); if (p.Tracks.Count == 0) { return; } parser = p; } catch { } } if (parser == null) { parser = GpxParser.FromSession(routeName); } else { parser.ToSession(routeName); } } finally { MapContainer.Visible = parser != null; } }
public void GenerateMarkers() { Response.Write("<script type=\"text/javascript\">\r\n"); Response.Write("function addMarkers(){\r\n"); foreach (Route r in Routes) { string url = r.GetRouteUrl(editMode); string gpxFile = PathFunctions.GetGpxPathFromRouteName(r.Name); GpxParser parser = Helper.GetGpxParser(gpxFile); if (parser == null) { continue; } //TrackPoint p = parser.Tracks[0].Segments[0].Points[0]; GenericPoint p = parser.MediumPoint; string color = r.Draft ? "red" : "blue"; string title = r.Title.Replace("'", "\\'") + (r.Draft ? " (bozza)" : ""); string name = r.Name; string description = string.Format("<iframe scrolling=\"no\" frameborder=\"no\" src=\"/RouteData.aspx?name={0}\"/>", r.Name); string icon = r.Draft ? "/Images/draft_marker.png" : ""; string imageFolder = PathFunctions.GetImagePathFromGpx(gpxFile); string imageFile = Path.Combine(imageFolder, string.IsNullOrEmpty(r.Image) ? "" : r.Image); if (!File.Exists(imageFile)) { string[] files = Directory.GetFiles(imageFolder, "*.jpg"); if (files.Length > 0) { imageFile = files[0]; } else { imageFile = ""; } } string thumbFile = imageFile.Length == 0 ? "" : PathFunctions.GetThumbFile(imageFile); string photo = thumbFile.Length == 0 ? "" : PathFunctions.GetUrlFromPath(thumbFile, false).Replace("'", "\\'"); Response.Write(string.Format( "GV_Draw_Marker({{ lat: {0}, lon: {1}, name: '{2}', desc: '{3}', color: '{4}', icon: '{5}', photo: '{6}', url: '{7}', route_name:'{8}', draw_track: true }});\r\n", p.lat.ToString(System.Globalization.CultureInfo.InvariantCulture), p.lon.ToString(System.Globalization.CultureInfo.InvariantCulture), title, description, color, icon, photo, url, name)); } Response.Write("}\r\n"); Response.Write("</script>\r\n"); }
protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack) { return; } if (string.IsNullOrEmpty(RouteName)) { RouteName = Path.GetFileName(Page.MapPath(".")); } string gpxFullPath = PathFunctions.GetGpxPathFromRouteName(RouteName); GpxParser parser = Helper.GetGpxParser(gpxFullPath); if (parser == null) { return; } MapLink.NavigateUrl = string.Format("~/Routes/Map.aspx?Route={0}", RouteName); ProfileImage.Src = Helper.GenerateProfileFile(gpxFullPath); int countryCode = 0; countryCode = parser.CountryCode; string zipPath = parser.ZippedFile; HyperLinkToGps.NavigateUrl = PathFunctions.GetUrlFromPath(zipPath, true); if (countryCode != 0) { MeteoFrame.Attributes["src"] = string.Format("http://www.ilmeteo.it/script/meteo.php?id=free&citta={0}", countryCode); } else { MeteoFrame.Visible = false; } FBLike.Attributes["src"] = string.Format( "http://www.facebook.com/widgets/like.php?href={0}", HttpUtility.UrlEncode(Page.Request.Url.ToString())); MTBUser user = LoginState.User; if (user == null) { Rank.SelectedIndex = -1; } else { Rank r = DBHelper.GetRank(user.Id, GetRoute().Id); Rank.SelectedIndex = r == null ? -1 : r.RankNumber - 1; } }
public string GetRouteUrl(bool editMode) { string routeFolderPath = PathFunctions.GetRoutePathFromName(Name); string url = editMode ? PathFunctions.GetUrlFromPath(PathFunctions.EditRoutePage, false).Replace("'", "\\'") + "?Route=" + Name : (string.IsNullOrEmpty(Page) ? PathFunctions.GetUrlFromPath(PathFunctions.RoutesPage, false).Replace("'", "\\'") + "?Route=" + Name : PathFunctions.GetUrlFromPath(Path.Combine(routeFolderPath, Page), false).Replace("'", "\\'")); return(url); }
public static void CreateReduced(string file) { string reduced = PathFunctions.GetReducedFile(file); if (File.Exists(reduced)) { return; } File.Copy(file, reduced, false); Helper.Resize(reduced, 800); }
public static string GenerateProfileFile(string gpxPath) { //calcolo la cartella che contiene le tracce string folder = Path.GetFileName(Path.GetDirectoryName(gpxPath)); string profileFileRelPath = PathFunctions.GetProfileUrl(folder); string profileFileFullPath = HttpContext.Current.Server.MapPath(profileFileRelPath); if (!File.Exists(profileFileFullPath)) { ProfileGenerator gen = new ProfileGenerator(); gen.GenerateProfile(Helper.GetGpxParser(gpxPath), profileFileFullPath); } return(profileFileRelPath); }
public static string CreateThumbnail(string file, int size) { string thumbFile = PathFunctions.GetThumbFile(file); if (File.Exists(thumbFile)) { return(thumbFile); } using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(file)) { using (Bitmap img = CreateThumbnail(bmp, size)) { img.Save(thumbFile); } } return(thumbFile); }
public void GenerateMarkers() { Response.Write("<script type=\"text/javascript\">\r\n"); Response.Write("function addMarkers(){\r\n"); if (parser != null && !string.IsNullOrEmpty(parser.SourceFile)) { string thumbsFolder = PathFunctions.GetThumbsFolder(parser.SourceFile); foreach (WayPoint wp in parser.WayPoints) { bool hasPhoto = !string.IsNullOrEmpty(wp.link) && wp.link.EndsWith(".jpg", StringComparison.InvariantCultureIgnoreCase); string color = hasPhoto ? "blue" : "red"; string name = wp.name.Replace("'", "\\'"); string description = wp.description.Replace("'", "\\'"); string icon = hasPhoto ? "/Images/camera_icon.png" : ""; string photo = hasPhoto ? PathFunctions.GetUrlFromPath(Path.Combine(thumbsFolder, Path.GetFileName(wp.link)), false).Replace("'", "\\'") : ""; string url = hasPhoto ? PathFunctions.GetUrlFromPath(wp.link, false).Replace("'", "\\'") : ""; Response.Write(string.Format( "GV_Draw_Marker({{ lat: {0}, lon: {1}, name: '{2}', desc: '{3}', color: '{4}', icon: '{5}', photo: '{6}', url: '{7}' }});\r\n", wp.lat.ToString(System.Globalization.CultureInfo.InvariantCulture), wp.lon.ToString(System.Globalization.CultureInfo.InvariantCulture), name, description, color, icon, photo, url)); } } Response.Write("}\r\n"); Response.Write("</script>\r\n"); }
static NHSessionManager() { try { Configuration cfg = new Configuration(); string configFile = @"hibernate.cfg.xml"; string mappingPath = PathFunctions.GetMappingPath(); cfg.Configure(Path.Combine(mappingPath, configFile)); foreach (string file in Directory.GetFiles(mappingPath, "*.hbm.xml")) { cfg.AddXmlFile(file); } factory = cfg.BuildSessionFactory(); } catch (Exception ex) { Log.Add(ex.ToString()); } }
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 ButtonDelete_Click(object sender, EventArgs e) { string routeName = RouteName.Value; try { if (string.IsNullOrEmpty(routeName)) { return; } //non posso eliminare una traccia che appartiene ad un alro utente //(se mai riesco a editarla) if (route != null && route.OwnerId != LoginState.User.Id) { return; } string path = PathFunctions.GetRoutePathFromName(routeName); TryDeleting(path); path = PathFunctions.GetWorkingPath(path); TryDeleting(path); if (route != null) { DBHelper.DeleteRoute(route); } GpxParser.RemoveFromSession(routeName); UploadedImages.RemoveFromSession(routeName); //forza il ricaricamento della pagina Response.Redirect(Request.Url.ToString(), true); } catch (Exception ex) { Log.Add("Error deleting route '{0}': '{1}'", routeName, ex.ToString()); ScriptManager.RegisterStartupScript(this, GetType(), "ErrorDeleting", string.Format("alert('Errore durante l'eliminazione: {0}.');", ex.Message), true); } }
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); } }
private FileInfo GetFileInfo(string name) { var files = GetFiles(); foreach (var fileName in files.FileNames) { if (mode == FileMode.DirPerFile) { if ((new DirectoryInfo(PathFunctions.GetDirectoryName(fileName)).Name.Equals(name))) { return(new FileInfo(fileName)); } } else { if (PathFunctions.GetFileNameWithoutExtension(fileName).Equals(name)) { return(new FileInfo(fileName)); } } } return(null); }
public Address Redirect(Address a) { return(new Address(ContentType ?? a.Type, PathFunctions.Redirect(a.GetAsContentPath(), SourceDescriptor))); }
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); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); PDFXC.HRef = PathFunctions.GetUrlFromPath(Page.MapPath("XCGiu2007.pdf"), true); PDFXC.Target = "_blank"; }