Ragazzi vi prego aiutatemi a capire dove sbaglio.
Io avevo scritto questa applicazione in stile "procedurale" e ora mi sono deciso a riscriverla OOP però ora non funziona più!
In pratica io interrogo un file xml e restituisco una lista che però è sempre vuota, cosa che non ovrebbe accadere. Allora ho provato a commentare il codice che interroga il db e a inserire manualmente un elemento ma mi dice che il Server non è disponibile.
Io vi posto il codice e vi prego fate un ecezione, potete correggerlo?
Ecco vi prego aiutatemi!codice:private class Project { public int id { get { return id; } set { id = value; } } public string name { get { return name; } set { name = value; } } public int year { get { return year; } set { year = value; } } public string state { get { return state; } set { state = value; } } public bool hasPage { get { return hasPage; } set { hasPage = value; } } public ProjectCategory category; public ProjectDescription description; public ProjectImage image; public class ProjectImage { public int width { get { return width; } set { width = value; } } public int height { get { return height; } set { height = value; } } public string src { get { return src; } set { src = value; } } } public class ProjectCategory { public int id { get { return id; } set { id = value; } } public string name { get { return name; } set { name = value; } } private string[] categories = { "Commerciale/Direzionale", "Industriale/Artigianale", "Residenziale", "Strutture Ricettive", "Urbanistica/Viabilità" }; public ProjectCategory(int id) { //if (id < 0 | id > this.categories.size() - 1) return; this.id = id; this.name = this.categories[id]; } } public class ProjectDescription { public string small { get { return small; } set { small = value; } } public string large { get { return large; } set { large = value; } } } public Project() { this.description = new ProjectDescription(); this.image = new ProjectImage(); } } private ProjectList GetProjects() { ProjectList projects = new ProjectList(); XPathDocument file = new XPathDocument(this.PortfolioFile); XPathNavigator nav = ((IXPathNavigable)file).CreateNavigator(); XPathNodeIterator iter = nav.Select("/portfolio/project"); while (iter.MoveNext()) { Project project = new Project(); iter.Current.MoveToFirstAttribute(); project.id = Convert.ToInt32(iter.Current.Value); iter.Current.MoveToParent(); XPathNodeIterator nodeiter = iter.Current.SelectDescendants(XPathNodeType.Element, false); while (nodeiter.MoveNext()) { switch (nodeiter.Current.Name) { case "name": project.name = ConvertToTxt(nodeiter.Current.Value); break; case "year": project.year = Convert.ToInt32(nodeiter.Current.Value); break; case "state": project.state = nodeiter.Current.Value; break; case "description": project.description.small = nodeiter.Current.Value; break; case "descriptionlong": project.description.large = nodeiter.Current.Value; break; case "category": project.category = new Project.ProjectCategory(Convert.ToInt32(nodeiter.Current.Value)); break; case "imagewidth": project.image.width = Convert.ToInt32(nodeiter.Current.Value); break; case "imageheight": project.image.height = Convert.ToInt32(nodeiter.Current.Value); break; } string imageSrc = ""; for (int i = 0; i <= this.imgFormats.Length; i++) { imageSrc = "~\\Projects\\" + project.id.ToString() + "\\default" + this.imgFormats[i]; if (File.Exists(System.Web.HttpContext.Current.Server.MapPath(imageSrc))) project.image.src = imageSrc; else project.image.src = ""; } if (project.image.src != "") { if (project.image.width == 0) project.image.width = 100; if (project.image.height == 0) project.image.height = 100; } project.hasPage = (Directory.Exists(System.Web.HttpContext.Current.Server.MapPath("~\\Projects\\" + project.id))) ? true : false; projects.Add(project); } } return projects; }![]()
![]()

Rispondi quotando
