protected override bool ValidateProperties(DbConnection conn, out Exception exception)
        {
            if (IntelligentString.IsNullOrEmpty(Path))
            {
                exception = new PropertyNotSetException(GetType(), "Path");
                return(false);
            }

            Boolean checkPathExists = true;

            if (IsInDatabase)
            {
                RootFolder clone = new RootFolder(MediaItemType, Priority);

                if (clone.Path == Path)
                {
                    checkPathExists = false;
                }
            }

            if (checkPathExists)
            {
                if (RootFolderPathExists(MediaItemType, Path))
                {
                    exception = new DuplicatePropertyValueException(GetType(), "Path", Path);
                    return(false);
                }
            }

            exception = null;
            return(true);
        }
示例#2
0
        protected override IntelligentString GetDescription(IntelligentString seperator)
        {
            IntelligentString description = IntelligentString.Empty;

            if (!IntelligentString.IsNullOrEmpty(Genre))
            {
                description += Genre.Trim() + seperator;
            }

            if (!IntelligentString.IsNullOrEmpty(Program))
            {
                description += Program.Trim() + seperator;
            }

            if (Series != 0)
            {
                description += "Series " + Series.ToString() + seperator;
            }

            if (!IntelligentString.IsNullOrEmpty(EpisodeOfString))
            {
                description += "Episode " + EpisodeOfString + seperator;
            }

            if (description.EndsWith(seperator))
            {
                description = description.Substring(0, description.Length - seperator.Length);
            }

            return(description.Trim());
        }
示例#3
0
        /// <summary>
        /// Saves the selected media item to the database
        /// </summary>
        /// <returns>True if the media item is saved successfully, false if not</returns>
        private Boolean UpdateSelectedMediaItem()
        {
            try
            {
                if (IntelligentString.IsNullOrEmpty(SelectedMediaItem.Name))
                {
                    GeneralMethods.MessageBoxApplicationError("Please give the " + SelectedMediaItem.Type.ToString().ToLower() + " a name");
                    return false;
                }

                if (mipParts.MediaItem.Parts.Count == 0)
                {
                    GeneralMethods.MessageBoxApplicationError("A " + SelectedMediaItem.Type.ToString().ToLower() + " must have at least 1 part");
                    return false;
                }

                MediaItem selectedMediaItem = MediaItems[SelectedIndex];
                CopyPropertiesFromClone(selectedMediaItem);
                selectedMediaItem.Parts = new MediaItemPartCollection(mipParts.MediaItem.Parts);

                OnSavedMediaItem(selectedMediaItem);

                SelectedMediaItem = selectedMediaItem.Clone() as MediaItem;

                return true;
            }
            catch (System.Exception e)
            {
                GeneralMethods.MessageBoxException(e, "Could not save video: ");
                return false;
            }
        }
示例#4
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (IntelligentString.IsNullOrEmpty(SelectedRootFolder.Path))
            {
                fbtPath.Browse();
            }

            fbtPath.Focus();
        }
示例#5
0
        protected override bool ValidateProperties(DbConnection conn, out Exception exception)
        {
            if (IntelligentString.IsNullOrEmpty(Name))
            {
                exception = new PropertyNotSetException(typeof(MediaItem), "Name");
                return(false);
            }

            exception = null;
            return(true);
        }
        /// <summary>
        /// Gets the type of the property that the rule will be applied to
        /// </summary>
        /// <param name="mediaItem">Media item the rule will be applied to</param>
        /// <returns>Type of the property that the rule will be applied to</returns>
        public Type GetPropertyType(MediaItem mediaItem)
        {
            if (IntelligentString.IsNullOrEmpty(PropertyName))
            {
                return(null);
            }

            PropertyInfo pi = mediaItem.GetType().GetProperty(PropertyName.Value);

            return(pi.PropertyType);
        }
        /// <summary>
        /// Determines whether or not the values in the control are valid
        /// </summary>
        /// <param name="errorMessage">Description of the reason the values in the control are not valid</param>
        /// <returns>True if the values in the control are valid, false if not</returns>
        public Boolean Validate(out String errorMessage)
        {
            if (IntelligentString.IsNullOrEmpty(Options.ViewAllText))
            {
                errorMessage = "Please set 'View All' text";
                return(false);
            }

            errorMessage = null;
            return(true);
        }
        /// <summary>
        /// Determines whether or not the genre of the specified media item passes throught the filter and should be displayed
        /// </summary>
        /// <param name="mediaItem">Media item being checked</param>
        /// <param name="filter">Filter used to filter media items</param>
        /// <returns>True if the genre of the specified media item passes throught the filter and should be displayed, false if not</returns>
        private static Boolean PassGenre(MediaItem mediaItem, MediaItemFilter filter)
        {
            if (IntelligentString.IsNullOrEmpty(mediaItem.Genre))
            {
                return(false);
            }

            if (!filter.PassMediaItem(mediaItem))
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Determines whether or not the album of the specified song passes throught the filter and should be displayed
        /// </summary>
        /// <param name="song">Song being checked</param>
        /// <param name="showHidden">Value determining whether or not hidden songs should be displayed</param>
        /// <returns>True if the album of the specified song passes throught the filter and should be displayed, false if not</returns>
        private static Boolean PassAlbum(Song song, Boolean?showHidden)
        {
            if (IntelligentString.IsNullOrEmpty(song.Album))
            {
                return(false);
            }

            if (showHidden.HasValue)
            {
                if (song.IsHidden != showHidden.Value)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#10
0
        /// <summary>
        /// Determines whether or not the program of the specified video passes throught the filter and should be displayed
        /// </summary>
        /// <param name="video">Video being checked</param>
        /// <param name="showHidden">Value determining whether or not hidden videos should be displayed</param>
        /// <returns>True if the program of the specified video passes throught the filter and should be displayed, false if not</returns>
        private static Boolean PassProgram(Video video, Boolean?showHidden)
        {
            if (IntelligentString.IsNullOrEmpty(video.Program))
            {
                return(false);
            }

            if (showHidden.HasValue)
            {
                if (video.IsHidden != showHidden.Value)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#11
0
        /// <summary>
        /// Determines whether or not the genre of the specified media item passes throught the filter and should be displayed
        /// </summary>
        /// <param name="mediaItem">Media item being checked</param>
        /// <param name="showHidden">Value determining whether or not hidden videos should be displayed</param>
        /// <returns>True if the genre of the specified media item passes throught the filter and should be displayed, false if not</returns>
        private static Boolean PassGenre(MediaItem mediaItem, Boolean?showHidden)
        {
            if (IntelligentString.IsNullOrEmpty(mediaItem.Genre))
            {
                return(false);
            }

            if (showHidden.HasValue)
            {
                if (mediaItem.IsHidden != showHidden.Value)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#12
0
        public Boolean Validate(Type propertyType, out String errorMessage)
        {
            if (propertyType != typeof(IntelligentString))
            {
                errorMessage = "Cannot apply a prefix to a value of type " + propertyType.Name;
                return(false);
            }

            if (IntelligentString.IsNullOrEmpty(Prefix))
            {
                errorMessage = "Prefix cannot be empty";
                return(false);
            }

            errorMessage = null;
            return(true);
        }
示例#13
0
        public override IntelligentString GetSearchString()
        {
            IntelligentString searchString = IntelligentString.Empty;

            if ((!IntelligentString.IsNullOrEmpty(Program)) &&
                (Series != 0) &&
                (Episode != 0))
            {
                searchString += Program + " S" + Series.ToString("00") + "E" + Episode.ToString("00");
            }
            else
            {
                searchString = Name;
            }

            return(searchString);
        }
        /// <summary>
        /// Determines whether or not the artist of the specified song passes throught the filter and should be displayed
        /// </summary>
        /// <param name="song">Song being checked</param>
        /// <param name="viewAllText">Text used to view all songs</param>
        /// <param name="filter">Filter used to filter songs</param>
        /// <param name="selectedGenres">Genres selected in the filter</param>
        /// <returns>True if the artist of the specified song passes throught the filter and should be displayed, false if not</returns>
        private static Boolean PassArtist(Song song, IntelligentString viewAllText, MediaItemFilter filter, IntelligentString[] selectedGenres)
        {
            if (IntelligentString.IsNullOrEmpty(song.Artist))
            {
                return(false);
            }

            if ((!selectedGenres.Contains(viewAllText)) && (!selectedGenres.Contains(song.Genre)))
            {
                return(false);
            }

            if (!filter.PassMediaItem(song))
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Determines whether or not the program of the specified video passes throught the filter and should be displayed
        /// </summary>
        /// <param name="video">Video being checked</param>
        /// <param name="viewAllText">Text used to view all videos</param>
        /// <param name="filter">Filter used to filter videos</param>
        /// <param name="selectedGenres">Genres selected in the filter</param>
        /// <returns>True if the program of the specified video passes throught the filter and should be displayed, false if not</returns>
        private static Boolean PassProgram(Video video, IntelligentString viewAllText, MediaItemFilter filter, IntelligentString[] selectedGenres)
        {
            if (IntelligentString.IsNullOrEmpty(video.Program))
            {
                return(false);
            }

            if ((!selectedGenres.Contains(viewAllText)) && (!selectedGenres.Contains(video.Genre)))
            {
                return(false);
            }

            if (!filter.PassMediaItem(video))
            {
                return(false);
            }

            return(true);
        }
示例#16
0
        public Boolean Validate(Type propertyType, out String errorMessage)
        {
            if (propertyType != typeof(IntelligentString))
            {
                errorMessage = "Cannot do a find and replace to a value of type " + propertyType.Name;
                return(false);
            }

            if (IntelligentString.IsNullOrEmpty(OldValue))
            {
                errorMessage = "Text to replace cannot be empty";
                return(false);
            }

            if (IntelligentString.IsNullOrEmpty(NewValue))
            {
                errorMessage = "Text to replace old text with cannot be empty";
                return(false);
            }

            errorMessage = null;
            return(true);
        }
        /// <summary>
        /// Gets the organised path of a media item part
        /// </summary>
        /// <param name="mediaItemOrganisedPath">Organised path of the media item the part belongs to</param>
        /// <param name="index">Index in the collection of the part being organised</param>
        /// <returns>Organised path of a media item part</returns>
        public IntelligentString GetPartOrganisedPath(IntelligentString mediaItemOrganisedPath, int index)
        {
            MediaItemPart part = parts[index];

            if (!IntelligentString.IsNullOrEmpty(part.Location))
            {
                if (parts.Count > 1)
                {
                    String format = "0";

                    for (int i = 1; i < parts.Count.ToString().Length; i++)
                    {
                        format += "0";
                    }

                    mediaItemOrganisedPath += " (Part " + (part.Index + 1).ToString(format) + ")";
                }

                FileInfo fi = new FileInfo(part.Location.Value);
                mediaItemOrganisedPath += fi.Extension;
            }

            return(mediaItemOrganisedPath);
        }
示例#18
0
        protected override IntelligentString GetDescription(IntelligentString seperator)
        {
            IntelligentString description = IntelligentString.Empty;

            if (!IntelligentString.IsNullOrEmpty(Genre))
            {
                description += Genre.Trim() + seperator;
            }

            if (!IntelligentString.IsNullOrEmpty(Artist))
            {
                description += Artist.Trim() + seperator;
            }

            if (!IntelligentString.IsNullOrEmpty(Album))
            {
                description += Album.Trim() + seperator;
            }

            if (!IntelligentString.IsNullOrEmpty(DiskNumberOfString))
            {
                description += "Disk " + DiskNumberOfString + seperator;
            }

            if (!IntelligentString.IsNullOrEmpty(TrackNumberOfString))
            {
                description += "Track " + TrackNumberOfString + seperator;
            }

            if (description.EndsWith(seperator))
            {
                description = description.Substring(0, description.Length - seperator.Length);
            }

            return(description.Trim());
        }
        /// <summary>
        /// Submits the rules
        /// </summary>
        private void SubmitRules()
        {
            if (Rules.Any(p => p.Rule == null))
            {
                MessageBox.Show("Rule has not been selected.", "", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            String errorMessage = String.Empty;

            if (Rules.Any(p => !p.Rule.Validate(p.GetPropertyType(MediaItems[0]), out errorMessage)))
            {
                MessageBox.Show(errorMessage, "", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (Rules.Any(p => IntelligentString.IsNullOrEmpty(p.PropertyName)))
            {
                MessageBox.Show("Property to modify has not been selected", "", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            foreach (MediaItem mediaItem in MediaItems)
            {
                foreach (RuleHeader rule in Rules)
                {
                    PropertyInfo pi    = mediaItem.GetType().GetProperty(rule.PropertyName.Value);
                    object       value = pi.GetValue(mediaItem);

                    value = rule.Rule.Apply(rule.GetPropertyType(mediaItem), value);
                    pi.SetValue(mediaItem, value);
                }
            }

            DialogResult = true;
        }
示例#20
0
        /// <summary>
        /// Loads the videos into the window
        /// </summary>
        private void LoadVideos()
        {
            try
            {
                Video firstVideo = Videos[0];

                Boolean sameProgram          = true;
                Boolean sameGenre            = true;
                Boolean sameEpisode          = true;
                Boolean sameNumberOfEpisodes = true;
                Boolean sameSeries           = true;
                Boolean?hidden = firstVideo.IsHidden;

                for (int i = 1; i < Videos.Length; i++)
                {
                    if (Videos[i].Program != firstVideo.Program)
                    {
                        sameProgram = false;
                    }

                    if (Videos[i].Genre != firstVideo.Genre)
                    {
                        sameGenre = false;
                    }

                    if (Videos[i].Episode != firstVideo.Episode)
                    {
                        sameEpisode = false;
                    }

                    if (Videos[i].NumberOfEpisodes != firstVideo.NumberOfEpisodes)
                    {
                        sameNumberOfEpisodes = false;
                    }

                    if (Videos[i].Series != firstVideo.Series)
                    {
                        sameSeries = false;
                    }

                    if (Videos[i].IsHidden != firstVideo.IsHidden)
                    {
                        hidden = null;
                    }
                }

                if (sameProgram)
                {
                    if (!IntelligentString.IsNullOrEmpty(firstVideo.Program.Value))
                    {
                        cmbProgram.Text      = firstVideo.Program.Value;
                        chkProgram.IsChecked = false;
                    }
                }

                if (sameGenre)
                {
                    if (!IntelligentString.IsNullOrEmpty(firstVideo.Genre.Value))
                    {
                        cmbGenre.Text      = firstVideo.Genre.Value;
                        chkGenre.IsChecked = false;
                    }
                }

                if (sameEpisode)
                {
                    if (firstVideo.Episode != 0)
                    {
                        iudEpisode.Text      = firstVideo.Episode.ToString();
                        chkEpisode.IsChecked = false;
                    }
                }

                if (sameNumberOfEpisodes)
                {
                    if (firstVideo.NumberOfEpisodes != 0)
                    {
                        iudNumberOfEpisodes.Text      = firstVideo.NumberOfEpisodes.ToString();
                        chkNumberOfEpisodes.IsChecked = false;
                    }
                }

                if (sameSeries)
                {
                    if (firstVideo.Series != 0)
                    {
                        iudSeries.Text      = firstVideo.Series.ToString();
                        chkSeries.IsChecked = false;
                    }
                }

                if (hidden.HasValue)
                {
                    if (hidden.Value)
                    {
                        cmbIsHidden.Text = "Yes";
                    }
                    else
                    {
                        cmbIsHidden.Text = "No";
                    }

                    chkIsHidden.IsChecked = false;
                }
            }
            catch (System.Exception e)
            {
                GeneralMethods.MessageBoxException(e, "Could not load videos: ");
            }
        }
示例#21
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (IntelligentString.IsNullOrEmpty(SelectedRootFolder.Path))
                {
                    GeneralMethods.MessageBoxApplicationError("Please select the path to the root folder.");
                    return;
                }

                Boolean           updateMediaItems = false;
                IntelligentString previousPath     = IntelligentString.Empty;

                if (SelectedRootFolder.IsInDatabase)
                {
                    RootFolder clone = new RootFolder(SelectedRootFolder.MediaItemType, SelectedRootFolder.Priority);

                    if (clone.Path != SelectedRootFolder.Path)
                    {
                        if (RootFolder.RootFolderPathExists(SelectedRootFolder.MediaItemType, SelectedRootFolder.Path.Value))
                        {
                            GeneralMethods.MessageBoxApplicationError("There is already another root folder with the path \"" + SelectedRootFolder.Path + "\"");
                            return;
                        }

                        MessageBoxResult result = GeneralMethods.MessageBox("Would you like to update the locations of all media items that are in this root folder to match the new path?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);

                        switch (result)
                        {
                        case MessageBoxResult.Cancel:
                            return;

                        case MessageBoxResult.Yes:
                            updateMediaItems = true;
                            previousPath     = clone.Path;
                            break;
                        }
                    }
                }
                else
                {
                    if (RootFolder.RootFolderPathExists(SelectedRootFolder.MediaItemType, SelectedRootFolder.Path.Value))
                    {
                        GeneralMethods.MessageBoxApplicationError("There is already a root folder with the path \"" + SelectedRootFolder.Path + "\"");
                        return;
                    }
                }

                SelectedRootFolder.Save();

                if (updateMediaItems)
                {
                    OnPathChanged(SelectedRootFolder, previousPath);
                }

                DialogResult = true;
            }
            catch (System.Exception ex)
            {
                GeneralMethods.MessageBoxException(ex, "Could not save root folder: ");
            }
        }
        private void btnAddRootFolderDirectoryException_Click(object sender, RoutedEventArgs e)
        {
            Button         btnAddRootFolderDirectoryExceptio = sender as Button;
            NonLibraryFile nlf = btnAddRootFolderDirectoryExceptio.DataContext as NonLibraryFile;

            Options.RootFolderDirectoryExceptions.Add(nlf.SubFolderName.Value);
            Options.Save();

            NonLibraryFile[] matches = ItemsSource.Where(p => p.SubFolderName == nlf.SubFolderName).ToArray();

            foreach (NonLibraryFile nonLibraryFile in matches)
            {
                FileInfo fi = new FileInfo(nonLibraryFile.FullName.Value);

                RootFolder.CleanUp(fi.Directory.Parent.FullName, new List <String>(), Options.RootFolderFileExceptions.ToArray(), Options.RootFolderDirectoryExceptions.ToArray(), IntelligentString.IsNullOrEmpty(nonLibraryFile.SubFolderPath));
                ItemsSource.Remove(nonLibraryFile);
            }

            if (ItemsSource.Count == 0)
            {
                DialogResult = true;
            }
        }
        /// <summary>
        /// Loads the songs into the window
        /// </summary>
        private void LoadSongs()
        {
            try
            {
                Song firstSong = Songs[0];

                Boolean sameArtist         = true;
                Boolean sameAlbum          = true;
                Boolean sameGenre          = true;
                Boolean sameTrack          = true;
                Boolean sameNumberOfTracks = true;
                Boolean sameDisk           = true;
                Boolean sameNumberOfDisks  = true;
                Boolean sameYear           = true;
                Boolean?hidden             = firstSong.IsHidden;

                for (int i = 1; i < Songs.Length; i++)
                {
                    if (Songs[i].Artist != firstSong.Artist)
                    {
                        sameArtist = false;
                    }

                    if (Songs[i].Album != firstSong.Album)
                    {
                        sameAlbum = false;
                    }

                    if (Songs[i].Genre != firstSong.Genre)
                    {
                        sameGenre = false;
                    }

                    if (Songs[i].TrackNumber != firstSong.TrackNumber)
                    {
                        sameTrack = false;
                    }

                    if (Songs[i].NumberOfTracks != firstSong.NumberOfTracks)
                    {
                        sameNumberOfTracks = false;
                    }

                    if (Songs[i].DiskNumber != firstSong.DiskNumber)
                    {
                        sameDisk = false;
                    }

                    if (Songs[i].NumberOfDisks != firstSong.NumberOfDisks)
                    {
                        sameNumberOfDisks = false;
                    }

                    if (Songs[i].Year != firstSong.Year)
                    {
                        sameYear = false;
                    }

                    if (Songs[i].IsHidden != firstSong.IsHidden)
                    {
                        hidden = null;
                    }
                }

                if (sameArtist)
                {
                    if (!IntelligentString.IsNullOrEmpty(firstSong.Artist.Value))
                    {
                        cmbArtist.Text      = firstSong.Artist.Value;
                        chkArtist.IsChecked = false;
                    }
                }

                if (sameAlbum)
                {
                    if (!IntelligentString.IsNullOrEmpty(firstSong.Album.Value))
                    {
                        cmbAlbum.Text      = firstSong.Album.Value;
                        chkAlbum.IsChecked = false;
                    }
                }

                if (sameGenre)
                {
                    if (!IntelligentString.IsNullOrEmpty(firstSong.Genre.Value))
                    {
                        cmbGenre.Text      = firstSong.Genre.Value;
                        chkGenre.IsChecked = false;
                    }
                }

                if (sameTrack)
                {
                    if (firstSong.TrackNumber != 0)
                    {
                        iudTrack.Text      = firstSong.TrackNumber.ToString();
                        chkTrack.IsChecked = false;
                    }
                }

                if (sameNumberOfTracks)
                {
                    if (firstSong.NumberOfTracks != 0)
                    {
                        iudNumberOfTracks.Text      = firstSong.NumberOfTracks.ToString();
                        chkNumberOfTracks.IsChecked = false;
                    }
                }

                if (sameDisk)
                {
                    if (firstSong.DiskNumber != 0)
                    {
                        iudDisk.Text      = firstSong.DiskNumber.ToString();
                        chkDisk.IsChecked = false;
                    }
                }

                if (sameNumberOfDisks)
                {
                    if (firstSong.NumberOfDisks != 0)
                    {
                        iudNumberOfDisks.Text      = firstSong.NumberOfDisks.ToString();
                        chkNumberOfDisks.IsChecked = false;
                    }
                }

                if (sameYear)
                {
                    if (firstSong.Year != 0)
                    {
                        iudYear.Text      = firstSong.Year.ToString();
                        chkYear.IsChecked = true;
                    }
                }

                if (hidden.HasValue)
                {
                    if (hidden.Value)
                    {
                        cmbIsHidden.Text = "Yes";
                    }
                    else
                    {
                        cmbIsHidden.Text = "No";
                    }

                    chkIsHidden.IsChecked = false;
                }
            }
            catch (System.Exception e)
            {
                GeneralMethods.MessageBoxException(e, "Could not load songs: ");
            }
        }