public static Collection MakeCollection() { string folder = @"C:\Users\Public\Pictures\Sample Pictures"; string[] files = Directory.GetFiles(folder); Collection coll = new Collection(); coll.Name = "Sample Pictures"; bool anyItems = false; foreach (string path in files) { string extension = Path.GetExtension(path); bool isJpeg = (0 == string.Compare(".jpg", extension, true)); bool isPng = (0 == string.Compare(".png", extension, true)); if (isJpeg || isPng) { anyItems = true; FileInfo info = new FileInfo(path); coll.AddItem(Path.GetFileNameWithoutExtension(path), path, null, new ItemImage(path) , new Facet("File name", Path.GetFileName(path) , isJpeg ? "*.jpg" : null , isPng ? "*.png" : null ) , new Facet("File size", info.Length / 1000) , new Facet("Creation time", info.CreationTime) , new Facet("Link:", new FacetHyperlink("click to view image", path)) ); } } if (anyItems) { coll.SetFacetDisplay("Creation time", false, true, false); coll.SetFacetFormat("File size", "#,#0 kb"); } else { coll.AddItem("No pictures", null, string.Format("The folder \"{0}\" does not contain any JPEG or PNG files.", folder), null); } return coll; }
// Public Methods //====================================================================== public override Collection MakeCollection(CollectionRequestContext context) { try { var crashes = db.Crashes .Include(c => c.Light) .Include(c => c.Weather) .Include(c => c.CrashLocation) .Include(c => c.SurfCondition) .Include(c => c.CrashClass) .Include(c => c.VehCollision) .Include(c => c.ObjectStruck) .Include(c => c.RoadCharacter) .Include(c => c.ContFactor1) .Include(c => c.ContFactor2) .Include(c => c.CrashCategory); Collection collection = new Collection(); collection.Name = "NPS Crashes"; foreach (var crash in crashes.Take(maxItems)) { string imgFolder = HttpRuntime.BinDirectory.Substring(0, HttpRuntime.BinDirectory.Length - 5); string imgName = GetImageName(crash.Category); ItemImage image = null; if (imgName != null) { image = new ItemImage(string.Format(@"{0}\Images\{1}", imgFolder, imgName)); } collection.AddItem(crash.IncidentNo, null, null, image, GetFacets(crash)); } // Set facet display properties collection.SetFacetDisplay("Park Alpha", true, true, true); collection.SetFacetDisplay("State", true, true, false); collection.SetFacetDisplay("Crash Year", true, true, false); collection.SetFacetDisplay("Crash Date", false, true, false); collection.SetFacetDisplay("Crash Time", false, true, false); collection.SetFacetDisplay("Route ID", true, true, true); collection.SetFacetDisplay("Road Name", false, true, true); collection.SetFacetDisplay("Node Distance (Ft)", false, true, false); collection.SetFacetDisplay("Node Distance (Mi)", false, true, false); collection.SetFacetDisplay("Node Direction", false, true, false); collection.SetFacetDisplay("Node Number", false, true, false); collection.SetFacetDisplay("Node MP", false, true, false); collection.SetFacetDisplay("Crash MP", true, true, false); collection.SetFacetDisplay("Light Condition", true, true, false); collection.SetFacetDisplay("Weather Condition", true, true, false); collection.SetFacetDisplay("Crash Location", true, true, false); collection.SetFacetDisplay("Surface Condition", true, true, false); collection.SetFacetDisplay("Crash Class", true, true, false); collection.SetFacetDisplay("Vehicle Collision", true, true, false); collection.SetFacetDisplay("Fixed Object Struck", true, true, false); collection.SetFacetDisplay("Road Character", true, true, false); collection.SetFacetDisplay("Contributing Factor 1", true, true, false); collection.SetFacetDisplay("Contributing Factor 2", true, true, false); collection.SetFacetDisplay("Contributing Factor 3", false, true, false); collection.SetFacetDisplay("Contributing Factor 4", false, true, false); collection.SetFacetDisplay("Contributing Factor 5", false, true, false); collection.SetFacetDisplay("Contributing Factor 6", false, true, false); collection.SetFacetDisplay("Category", true, true, false); collection.SetFacetDisplay("Hit & Run", false, true, false); collection.SetFacetDisplay("Fatal", false, true, false); collection.SetFacetDisplay("Injured", false, true, false); collection.SetFacetDisplay("Pedestrian Fatal", false, true, false); collection.SetFacetDisplay("Pedestrian Injured", false, true, false); collection.SetFacetDisplay("Bikers Fatal", false, true, false); collection.SetFacetDisplay("Bikers Injured", false, true, false); collection.SetFacetDisplay("Pedestrian", true, true, false); collection.SetFacetDisplay("Comments", false, true, true); collection.SetFacetDisplay("Spatial Location", true, true, false); //collection.SetFacetDisplay("Case Number", false, true, false); //collection.SetFacetDisplay("Location", false, true, false); //collection.SetFacetDisplay("USPP/NPS Veh. Inv.", false, true, false); //collection.SetFacetDisplay("Park Property Dest.", false, true, false); //collection.SetFacetDisplay("Data Source", false, true, false); //collection.SetFacetDisplay("Latitude", false, true, false); //collection.SetFacetDisplay("Longitude", false, true, false); //collection.SetFacetDisplay("Save Date", false, true, false); //collection.SetFacetDisplay("RIP Cycle", false, true, false); // Set facet formats //collection.SetFacetFormat("List price", "$#,0.00"); return collection; } catch (Exception ex) { return ErrorCollection.FromException(ex); } }