public Phocalstream_Shared.Data.Model.Photo.Photo ProcessPhoto(string fileName, CameraSite site) { string relativeName = fileName; fileName = Path.Combine(PathManager.GetRawPath(), fileName); FileInfo info = new FileInfo(fileName); try { // create the directory for the image and its components string basePath = Path.Combine(Path.Combine(PathManager.GetPhotoPath(), site.DirectoryName), string.Format("{0}.phocalstream", info.Name)); if (Directory.Exists(basePath) == false) { Directory.CreateDirectory(basePath); } // open a Bitmap for the image to parse the meta data from using (System.Drawing.Image img = System.Drawing.Image.FromFile(fileName)) { Photo photo = CreatePhotoWithProperties(img, info.Name); photo.Site = site; photo.FileName = relativeName; PhotoRepository.Insert(photo); // only generate the phocalstream image if it has not already been generated if (File.Exists(Path.Combine(basePath, @"High.jpg")) == false) { // this is a dirty hack, figure out why the image isn't opening with the correct width and height if (photo.Portrait) { photo.Width = img.Height; photo.Height = img.Width; } ResizeImageTo(fileName, 1200, 800, Path.Combine(basePath, @"High.jpg"), photo.Portrait); ResizeImageTo(fileName, 800, 533, Path.Combine(basePath, @"Medium.jpg"), photo.Portrait); ResizeImageTo(fileName, 400, 266, Path.Combine(basePath, @"Low.jpg"), photo.Portrait); } float[] percentages = ConvertCountsToPercentage(CountRGBPixels(new Bitmap(img))); photo.Black = percentages[(int)PixelColor.BLACK]; photo.White = percentages[(int)PixelColor.WHITE]; photo.Red = percentages[(int)PixelColor.RED]; photo.Green = percentages[(int)PixelColor.GREEN]; photo.Blue = percentages[(int)PixelColor.BLUE]; return photo; } } catch (Exception e) { // this should be logged throw new Exception(string.Format("Exception processing photo {0}. Message: {1}", fileName, e.Message)); } }
public Collection GetCollectionForProcessing(XmlNode siteData) { string siteName = siteData["Folder"].InnerText; CameraSite site = SiteRepository.Find(s => s.Name == siteName).FirstOrDefault(); Collection collection = null; if (site == null) { site = new CameraSite(); site.Name = siteData["Folder"].InnerText; site.DirectoryName = siteData["Folder"].InnerText; site.ContainerID = Guid.NewGuid().ToString(); if (siteData["Location"].Attributes["latitude"].Value != String.Empty) { site.Latitude = Convert.ToDouble(siteData["Location"].Attributes["latitude"].Value); site.Longitude = Convert.ToDouble(siteData["Location"].Attributes["longitude"].Value); } var county = siteData["County"].InnerText; var state = siteData["State"].InnerText; site.CountyFips = DMRepository.GetFipsForCountyAndState(county, state); collection = new Collection() { ContainerID = site.ContainerID, Name = site.Name, Site = site, Status = CollectionStatus.PROCESSING, Type = CollectionType.SITE }; CollectionRepository.Insert(collection); SiteRepository.Insert(site); } else { collection = CollectionRepository.Find(c => c.Site.ID == site.ID).FirstOrDefault(); collection.Status = CollectionStatus.PROCESSING; CollectionRepository.Update(collection); } return collection; }
public ActionResult CreateUserSite(AddUserCameraSite site) { User user = UserRepository.First(u => u.ProviderID == this.User.Identity.Name); string guid = Guid.NewGuid().ToString(); CameraSite newCameraSite = new CameraSite() { Name = site.CameraSiteName, Latitude = site.Latitude, Longitude = site.Longitude, CountyFips = DroughtMonitorRepository.GetFipsForCountyAndState(site.County, site.State), ContainerID = guid, DirectoryName = guid }; Collection newCollection = new Collection() { Name = site.CameraSiteName, Site = newCameraSite, Owner = user, ContainerID = guid, Type = CollectionType.USER }; CollectionRepository.Insert(newCollection); Unit.Commit(); return RedirectToAction("UploadPhotos", new { @collectionID = newCollection.ID }); }
public long CreateUserCameraSite(NewUserSiteModel model) { User user = UserRepository.First(u => u.ProviderID == this.User.Identity.Name); string guid = Guid.NewGuid().ToString(); CameraSite newCameraSite = new CameraSite() { Name = model.SiteName, Latitude = model.Latitude, Longitude = model.Longitude, CountyFips = DroughtMonitorRepository.GetFipsForCountyAndState(model.County, model.State), ContainerID = guid, DirectoryName = guid }; Collection newCollection = new Collection() { Name = model.SiteName, Site = newCameraSite, Owner = user, ContainerID = guid, Type = CollectionType.USER }; CollectionRepository.Insert(newCollection); Unit.Commit(); return newCollection.ID; }
public SiteDetails GetSiteDetails(CameraSite site) { SiteDetails details = new SiteDetails(); details.SiteName = site.Name; details.SiteID = site.ID; using (SqlConnection conn = new SqlConnection(_connectionString)) { conn.Open(); using (SqlCommand command = new SqlCommand("select min(Captured), max(Captured), count(*), max(ID) from Photos where Site_ID = @siteID", conn)) { command.Parameters.AddWithValue("@siteID", site.ID); using (SqlDataReader reader = command.ExecuteReader()) { if (reader.Read()) { details.First = reader.GetDateTime(0); details.Last = reader.GetDateTime(1); details.PhotoCount = reader.GetInt32(2); details.LastPhotoID = reader.GetInt64(3); } } } } return details; }