//string artistName) public ActionResult Index() { PhotoList photos = new PhotoList(); List<string> fileList = new List<string>(); var dirList = System.IO.Directory.GetDirectories(Server.MapPath(Url.Content("~/Content/Artists/"))); Random rand = new Random(); //Selects a random sample of 10 pictures and returns them to the view to use in the slider. foreach (string directory in dirList) { var artist = GetArtistName(directory); var files = from f in System.IO.Directory.GetFiles(directory) where System.IO.Path.GetFileName(f).ToUpper().StartsWith("TAT") select f; fileList.AddRange(files); foreach (string fileName in files) { decimal sortKey = rand.Next(); photos.Add( new Models.Photo { FileName = artist + "/" + System.IO.Path.GetFileName(fileName), Title = GetTitle(fileName), SortKey = sortKey}); } } photos.Sort((p1, p2) => (p1.SortKey.CompareTo(p2.SortKey))); return View(new PhotoList(photos.GetRange(0, 10))); }
private void FindPhotosInDirectory(string directoryPath) { var subDirectories = Directory.GetDirectories(directoryPath); // Recursively process each directory foreach (var subDirectory in subDirectories) { // TODO: Add support for configurable ignore files/dirs if (Path.GetFileName(subDirectory).Equals("@eaDir", StringComparison.InvariantCultureIgnoreCase)) { continue; } FindPhotosInDirectory(subDirectory); } // Get each file path in directory var pathsOfDirectoryFiles = new List <string>(); foreach (var filePath in Directory.GetFiles(directoryPath)) { pathsOfDirectoryFiles.Add(filePath); } // Filter to only include photos (and videos) // TODO: Replace magical strings with crawler recognized extensions settings var photoRegex = new Regex(@".*\.(gif|jpe?g|bmp|png|vmv)$", RegexOptions.IgnoreCase); var videoRegex = new Regex(@".*\.(mov|mpe?g|mp4|avi)$", RegexOptions.IgnoreCase); var pathsOfDirectoryPhotos = pathsOfDirectoryFiles .Where(p => photoRegex.IsMatch(p) || videoRegex.IsMatch(p)) .ToList(); // Process each photo in directory for (var index = 0; index < pathsOfDirectoryPhotos.Count; index++) { var filePath = pathsOfDirectoryPhotos[index]; var(photo, error) = PhotoReader.ReadPhoto(filePath, false, true); if (photo != null) { _list.Add(photo); } if (error != null) { _errorList.Add(error); } var progressReport = new ProgressReport( $"Find photos {directoryPath}", index, pathsOfDirectoryPhotos.Count); _outputPort?.HandleProgress(progressReport); } }
async Task SaveToJson() { try { // read list of photos from JSON file FileStream stream1 = new FileStream(JsonFilePath, FileMode.Open); StreamReader reader = new StreamReader(stream1); string fileContents = reader.ReadToEnd(); reader.Close(); PhotoList = JsonConvert.DeserializeObject <List <PhotoItem> >(fileContents); // query to see if photo object already in file List <PhotoItem> otherObjects = (from photoItemObject in PhotoList where photoItemObject.PhotoFilePath != PhotoItemObject.PhotoFilePath select photoItemObject).ToList <PhotoItem>(); // photo object already exists; update it if (otherObjects.Count != PhotoList.Count) { otherObjects.Add(PhotoItemObject); PhotoList = otherObjects; AllPhotos = PhotoList; } // add new photo item to list else { PhotoList.Add(PhotoItemObject); AllPhotos.Add(PhotoItemObject); } AllPhotos = (from photo in AllPhotos orderby photo.PhotoTime select photo).ToList(); PhotoSource = new ObservableCollection <PhotoItem>(AllPhotos); // write updated photo list to JSON file StreamWriter writer = new StreamWriter(JsonFilePath, false); writer.WriteLine(JsonConvert.SerializeObject(PhotoList)); writer.Close(); // update locations Location currentLocation = await GetCurrentDistance(); for (int i = 0; i < AllPhotos.Count; i++) { AllPhotos[i].DistanceToCurrent = Math.Round(Location.CalculateDistance(currentLocation, AllPhotos[i].PhotoLocation, DistanceUnits.Miles), 4); } } catch (Exception e) { Console.WriteLine(e.Message); } }
/// <summary> /// プレイヤー操作終了時関数 /// </summary> public void GameEnd() { for (int i = 0; i < PhotoShotList.Count; i++) { var list = PhotoShotList[i]; for (int j = 0; j < list.Count; j++) { if (list[j].isShootted) { PhotoList.Add(list[j].photo); } } } }
private void btnAddnew_Click(object sender, RoutedEventArgs e) { //Create a photo object to pass in to the addnew form - the arguments will be supplied within that form Photograph newphoto = new Photograph(null, DateTime.MinValue, DateTime.MinValue, null, null, null, null); //Create an editing form, passing in a new photo and a bool that tells the form whether we're editing or adding a record. addnew frm = new addnew(newphoto, false); if (frm.ShowDialog() == true) { //Add newphoto to plist plist.Add(newphoto); DatabaseUtil.AddRecord(newphoto); CollectionViewSource.GetDefaultView(dgPhotoInfo.ItemsSource).Refresh(); } }
protected void ScanPhotoDirectory(ImportController controller, SafeUri uri, PhotoList photo_list) { var enumerator = new RecursiveFileEnumerator(uri) { Recurse = controller.RecurseSubdirectories, CatchErrors = true, IgnoreSymlinks = true }; var infos = new List <FileImportInfo> (); foreach (var file in enumerator) { if (ImageFile.HasLoader(new SafeUri(file.Uri.ToString(), true))) { infos.Add(new FileImportInfo(new SafeUri(file.Uri.ToString(), true))); } if (infos.Count % 10 == 0 || infos.Count < 10) { var to_add = infos; // prevents race condition ThreadAssist.ProxyToMain(() => photo_list.Add(to_add.ToArray())); infos = new List <FileImportInfo> (); } if (!run_photoscanner) { return; } } if (infos.Count > 0) { var to_add = infos; // prevents race condition ThreadAssist.ProxyToMain(() => photo_list.Add(to_add.ToArray())); } }
public void FindMissing() { int i; missing.Clear(); for (i = 0; i < source.Count; i++) { IPhoto item = source [i]; string path = item.DefaultVersion.Uri.LocalPath; if (!File.Exists(path) || (new FileInfo(path).Length == 0)) { missing.Add(item); } } }
public void SubmitExecute(object obj) { PhotoList.Clear(); //Check if search string is null or empty if (String.IsNullOrWhiteSpace(ImageSearchKeyword)) { IsPhotoListEmpty = true; EmptyPhotoListMessage = ConstantsUtility.EmptySearchStringErrorMessage; return; } //Fetch data from api call var result = (FlickerFeed)_feedApi.ImageSearch(ImageSearchKeyword); if (result != null && result.IsSuccessful) { foreach (var i in result.Entry) { foreach (var link in i.Link) { if (link.Type.Contains(ConstantsUtility.LinkTypeImageString)) { var pic = new Photo() { Title = i.Title, Url = link.Href.ToString() }; PhotoList.Add(pic); } } } CheckAndUpdateIsPhotoListEmpty(); } else { IsPhotoListEmpty = true; //We can handle error message based on the business logic scenarios if (result != null) { EmptyPhotoListMessage = result.ErrorMessage; } else { EmptyPhotoListMessage = ConstantsUtility.ErrorMessageString; } } }
/// <summary> /// Add image from call UriDialog to PhotoList,ListBox and puts current picture in Panel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddImageURL_Click(object sender, EventArgs e) { string path = ""; using (var uD = new UrlDialog()) if (uD.ShowDialog(this) == DialogResult.OK) { path = uD.Path; } if (!string.IsNullOrWhiteSpace(path)) { PhotoList.Add(path); IListBox.Items.Add(path.GetLastPart()); Slider.BackgroundImage = Image.FromFile(path); } }
private void AddPhotoToList(FlickrNet.Flickr f, FlickrNet.Photo flickrPhoto, Photoset photoset) { // Filter by date, if filter option enabled and date taken is known. if (!Settings.FilterByDate || flickrPhoto.DateTakenUnknown || (flickrPhoto.DateTaken.Date >= Settings.StartDate && flickrPhoto.DateTaken.Date <= Settings.StopDate)) { Photo photo = new Photo(flickrPhoto, photoset); PhotoList.Add(photo); // Get the photo info to get the raw tags, and put them into the photo object. // The raw tags are as uploaded or entered -- with spaces, punctuation, and // upper/lower case. FlickrNet.PhotoInfo info = f.PhotosGetInfo(flickrPhoto.PhotoId); photo.Tags.Clear(); for (int i = 0; i < info.Tags.Count; i++) { photo.Tags.Add(info.Tags[i].Raw); } } }
/// <summary> /// Add image from call OpenFileDialog to PhotoList,ListBox and puts current picture in Panel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddImage_Click(object sender, EventArgs e) { if (OpenFilePicker.ShowDialog() == DialogResult.OK) { string localPath = ""; foreach (var item in OpenFilePicker.FileNames) { if (SettingList.SaveImage) { localPath = DataWorker.Copy(item); } else { localPath = item; } PhotoList.Add(localPath); IListBox.Items.Add(localPath.GetLastPart()); Slider.BackgroundImage = Image.FromFile(localPath); } } }
protected void ScanPhotoDirectory(ImportController controller, SafeUri uri, PhotoList photo_list) { var enumerator = new RecursiveFileEnumerator(uri) { Recurse = controller.RecurseSubdirectories, CatchErrors = true, IgnoreSymlinks = true }; foreach (var file in enumerator) { if (ImageFile.HasLoader(new SafeUri(file.Uri.ToString(), true))) { var info = new FileImportInfo(new SafeUri(file.Uri.ToString(), true)); ThreadAssist.ProxyToMain(() => photo_list.Add(info)); } if (!run_photoscanner) { return; } } }
/// <summary> /// This method Reads all records from the database into the list /// </summary> /// <param name="list">This is the list that should be populated with records from the database</param> public static void ReadDatabase(PhotoList list) { //Read all database records into photolist using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("SELECT * FROM tblPhotoAlbum", connection); try { connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Photograph photo = new Photograph((string)reader["Title"], Convert.ToDateTime(reader["DateTaken"]), Convert.ToDateTime(reader["DateMod"]), (string)reader["Description"], (string)reader["Photographer"], (string)reader["Keywords"], (string)reader["FileLocation"]); photo.Id = (int)reader["ID"]; list.Add(photo); } } catch (SqlException e) { MessageBox.Show("An exception occurred:" + e.Message); } } }