/// <summary> /// Gets the list of photos and invokes the event of number of photos changed. /// </summary> /// <returns>The list of photos</returns> public List <Photo> GetPhotos() { RefreshList(); // update the num of pictures in the main page PhotoCountEventArgs photoCountEventArgs = new PhotoCountEventArgs(this.Length()); this.GetPhotosNum?.Invoke(this, photoCountEventArgs); return(PhotosList); }
/// <summary> /// Refreshes the list. clears the current list and add all the photos in the directory (adds and removes photos) /// </summary> public void RefreshList() { // check if photo exists if (Directory.Exists(PhotoPath)) { this.PhotosList.Clear(); string[] photos = getPhotosPaths(); string[] photosThumbnails = Directory.GetFiles(PhotoPath + "\\Thumbnails", "*.*", SearchOption.AllDirectories); List <Tuple <string, string> > joinedPaths = sortPaths(photos, photosThumbnails); foreach (Tuple <string, string> photo in joinedPaths) { PhotosList.Add(new Photo(PhotoPath, photo.Item1, photo.Item2)); } // update the num of pictures in the main page PhotoCountEventArgs photoCountEventArgs = new PhotoCountEventArgs(this.Length()); this.GetPhotosNum?.Invoke(this, photoCountEventArgs); } }
/// <summary> /// Removes the photo from the list. /// </summary> /// <param name="photoToRemove">The photo to remove.</param> public void RemovePhoto(Photo photoToRemove) { foreach (Photo pic in PhotosList) { if (pic.PhotoPath.Equals(photoToRemove.PhotoPath)) { PhotosList.Remove(photoToRemove); string photoToDelete = photoToRemove.GetFullPath(); // delete the photo File.Delete(photoToDelete); string thumbToDelete = photoToRemove.GetFullThumbPath(); // delete the thumbnail File.Delete(thumbToDelete); break; } } // update the num of pictures in the main page PhotoCountEventArgs photoCountEventArgs = new PhotoCountEventArgs(this.Length()); this.GetPhotosNum?.Invoke(this, photoCountEventArgs); }
/// <summary> /// The function updates the number of photos /// </summary> /// <param name="photoCountEventArgs">The arguments received from the server</param> /// <param name="sender">The sender object</param> public void UpdatePhotosNum(object sender, PhotoCountEventArgs photoCountEventArgs) { int temp = (int)photoCountEventArgs.Count; this.GetNumofPics = temp; }