public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { ObservableCollection <Song> songs = values[0] as ObservableCollection <Song>; if (songs != null) { if ((values[1] != null) && (values[1] != DependencyProperty.UnsetValue)) { IntelligentString viewAllText = (IntelligentString)values[1]; MediaItemFilter filter = values[2] as MediaItemFilter; ObservableCollection <IntelligentString> selectedGenres = values[3] as ObservableCollection <IntelligentString>; if (selectedGenres != null) { List <IntelligentString> artists = new List <IntelligentString>( (from song in songs where PassArtist(song, viewAllText, filter, selectedGenres.ToArray()) select song.Artist).Distinct()); artists.Sort(); artists.Insert(0, viewAllText); return(new ObservableCollection <IntelligentString>(artists)); } } } return(new ObservableCollection <IntelligentString>()); }
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (values.Length == 3) { if (values[0] is Boolean) { Boolean isValidPath = (Boolean)values[0]; if (isValidPath) { if (values[1] is Int64) { double usedSpace = (Int64)values[1]; if (values[2] is Int64) { double totalSpace = (Int64)values[2]; double percentage = usedSpace / totalSpace; return("Used " + IntelligentString.FormatSize(usedSpace).Value + " of " + IntelligentString.FormatSize(totalSpace).Value + " (" + percentage.ToString("0.00%") + ")"); } } } else { return("Path does not exist"); } } } return(String.Empty); }
/// <summary> /// Loads the parts for the specfied media item /// </summary> /// <param name="conn">Open connection to the database</param> /// <param name="mediaItemId">Unique identifier of the media item</param> /// <param name="mediaItemType">Type of the media item</param> /// <returns>Collection of parts belonging to the specified media item, sorted ascendingly</returns> public static Business.MediaItemPartCollection GetMediaItemPartsById(SqlConnection conn, Int64 mediaItemId, Business.MediaItemTypeEnum mediaItemType) { try { List <sp.Parameter> parameters = new List <sp.Parameter>(); parameters.Add(new sp.Parameter("MediaItemId", DbType.Int64, mediaItemId)); parameters.Add(new sp.Parameter("MediaItemType", DbType.Int16, Convert.ToInt16(mediaItemType))); sp.DataTable table = SqlDbObject.ExecuteReader("GetMediaItemPartsById", CommandType.StoredProcedure, parameters.ToArray(), conn); Business.MediaItemPartCollection parts = new Business.MediaItemPartCollection(); foreach (sp.DataRow row in table) { IntelligentString location = (String)row["Location"]; Int64 size = (Int64)row["Size"]; Int32 milliseconds = (Int32)row["Duration"]; Int16 index = (Int16)row["Index"]; parts.Add(location, size, milliseconds, index); } parts.Sort(); return(parts); } catch (System.Exception e) { throw new SpecifiedSqlDbObjectNotFoundException("Could not load play history for media item", e); } }
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { String str = value as String; IntelligentString istr = str; return(istr); }
/// <summary> /// Adds the tag entered by the user to the root folder /// </summary> private void AddTag() { try { if (String.IsNullOrEmpty(cmbTag.Text)) { GeneralMethods.MessageBoxApplicationError("Please enter a value for the tag"); return; } IntelligentString tag = cmbTag.Text; if (SelectedRootFolder.Tags.Contains(tag)) { GeneralMethods.MessageBoxApplicationError("Root folder already contains tag \"" + tag + "\""); return; } List <IntelligentString> tags = new List <IntelligentString>(SelectedRootFolder.Tags); tags.Add(tag); tags.Sort(); SelectedRootFolder.Tags = new ObservableCollection <IntelligentString>(tags); cmbTag.Text = String.Empty; cmbTag.Focus(); } catch (System.Exception e) { GeneralMethods.MessageBoxException(e, "Could not add tag: "); } }
/// <summary> /// Fires the PathChanged event /// </summary> /// <param name="rootFolder">Root folder whose path changed</param> /// <param name="previousPath">Previous path of the root folder</param> private void OnPathChanged(RootFolder rootFolder, IntelligentString previousPath) { if (PathChanged != null) { PathChanged(this, new RootFolderPathChangedEventArgs(rootFolder, previousPath)); } }
/// <summary> /// Logs and error that occurred during organisation /// </summary> /// <param name="rootFolder">The root folder the part was being organised into when the error occured</param> /// <param name="e">Error that occured during organisation</param> private void LogOrganisationError(IntelligentString rootFolder, System.Exception e) { Progress = Part.Size; Errors.Add(rootFolder, e); OnPropertyChanged("Errors"); }
/// <summary> /// Switches paths of two root folders /// </summary> /// <param name="rootFolder1">Root folder being switched</param> /// <param name="rootFolder2">Root folder being switched</param> public static void SwitchRootFolderPaths(RootFolder rootFolder1, RootFolder rootFolder2) { //get the path of the root folder moving up IntelligentString path = rootFolder1.Path; //at this point we cannot simply set the path of rootFolder2 to the path of rootFolder1 and save because //there would be a duplicate paths in the database. Therefore we need to set the path of rootFolder1 to //something unique first. our unique path will be the original path of rootFolder2 with a number on the end IntelligentString tempPath; int tempPtr = 0; do { tempPath = rootFolder2.Path + tempPtr.ToString(); tempPtr++; }while (RootFolder.RootFolderPathExists(rootFolder2.MediaItemType, tempPath)); rootFolder1.Path = tempPath; rootFolder1.Save(); //now we can set the path of rootFolder2 to the original path of rootFolder1 and save rootFolder2.Path = path; rootFolder2.Save(); //we can now remove the number from the end of rootFolder1.Path which will give us the original //path or rootFolder2. our root folders will then have had their paths switched rootFolder1.Path = rootFolder1.Path.Substring(0, rootFolder1.Path.Length - tempPtr.ToString().Length); rootFolder1.Save(); }
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); }
/// <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; } }
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { IEnumerable mediaItems = values[0] as IEnumerable; if (mediaItems != null) { if ((values[1] != null) && (values[1] != DependencyProperty.UnsetValue)) { IntelligentString viewAllText = (IntelligentString)values[1]; MediaItemFilter filter = values[2] as MediaItemFilter; List <MediaItem> lstMediaItems = new List <MediaItem>(); foreach (MediaItem mediaItem in mediaItems) { lstMediaItems.Add(mediaItem); } List <IntelligentString> genres = new List <IntelligentString>( (from mediaItem in lstMediaItems where PassGenre(mediaItem, filter) select mediaItem.Genre).Distinct()); genres.Sort(); genres.Insert(0, viewAllText); return(new ObservableCollection <IntelligentString>(genres)); } } return(new ObservableCollection <IntelligentString>()); }
/// <summary> /// Initialises a new instance of the MediaItemPart class /// </summary> internal MediaItemPart() { this.location = IntelligentString.Empty; this.size = 0; this.duration = new TimeSpan(0); this.index = -1; }
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { ObservableCollection <Video> videos = values[0] as ObservableCollection <Video>; if (videos != null) { if ((values[1] != null) && (values[1] != DependencyProperty.UnsetValue)) { IntelligentString viewAllText = (IntelligentString)values[1]; MediaItemFilter filter = values[2] as MediaItemFilter; ObservableCollection <IntelligentString> selectedGenres = values[3] as ObservableCollection <IntelligentString>; if (selectedGenres != null) { List <IntelligentString> programs = new List <IntelligentString>( (from video in videos where PassProgram(video, viewAllText, filter, selectedGenres.ToArray()) select video.Program).Distinct()); programs.Sort(); programs.Insert(0, viewAllText); return(new ObservableCollection <IntelligentString>(programs)); } } } return(new ObservableCollection <IntelligentString>()); }
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()); }
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { String toolTip = String.Empty; if (values.Length == 2) { if (values[0] is TimeSpan) { TimeSpan duration = (TimeSpan)values[0]; if (duration > new TimeSpan(0)) { if (values[1] is TimeSpan) { TimeSpan ellapsed = (TimeSpan)values[1]; TimeSpan remaining = duration - ellapsed; DateTime finishTime = DateTime.Now + remaining; toolTip += "Duration: " + IntelligentString.FormatDuration(duration, false); toolTip += Environment.NewLine + "Ellapsed: " + IntelligentString.FormatDuration(ellapsed, false); toolTip += Environment.NewLine + "Remaining: " + IntelligentString.FormatDuration(remaining, false); toolTip += Environment.NewLine + "Finish time: " + finishTime.ToString("h:mm tt"); } } } } return(toolTip); }
/// <summary> /// Intialises a new instance of the RuleHeader class /// </summary> public RuleHeader() : base() { Index = 0; Rule = null; PropertyName = null; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value is Int64) { return(IntelligentString.FormatSize((Int64)value).Value); } return(String.Empty); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { IntelligentString summary = IntelligentString.Empty; String strShowSize = "True"; Boolean showSize = true; if (parameter != null) { strShowSize = parameter.ToString(); Boolean.TryParse(strShowSize, out showSize); } if (value is IEnumerable <MediaItem> ) { MediaItem[] mediaItems = (value as IEnumerable <MediaItem>).ToArray(); int numberOfItems = mediaItems.Length; Int64 size = 0; TimeSpan duration = new TimeSpan(); String type = "Media Item"; if (numberOfItems > 0) { type = mediaItems[0].Type.ToString(); } foreach (MediaItem mediaItem in mediaItems) { size += mediaItem.Parts.Size; duration += mediaItem.Parts.Duration; if (type != mediaItem.Type.ToString()) { type = "Media Item"; } } if (numberOfItems == 1) { summary += "1 " + type + " - "; } else { summary += numberOfItems.ToString() + " " + type + "s - "; } if (showSize) { summary += IntelligentString.FormatSize(size) + " - "; } summary += IntelligentString.FormatDuration(duration, false); } return(summary); }
private static IntelligentString AppendTrailingSlash(IntelligentString value) { if (!value.EndsWith("\\")) { value += "\\"; } return(value); }
private void Window_Loaded(object sender, RoutedEventArgs e) { if (IntelligentString.IsNullOrEmpty(SelectedRootFolder.Path)) { fbtPath.Browse(); } fbtPath.Focus(); }
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (values.Length == 4) { if (values[0] is Int64) { Int64 progress = (Int64)values[0]; if (values[1] is Int64) { Int64 size = (Int64)values[1]; if (values[2] is OrganisingMediaItemPartStatus) { OrganisingMediaItemPartStatus status = (OrganisingMediaItemPartStatus)values[2]; if (values[3] is Int32) { Int32 errorCount = (Int32)values[3]; switch (status) { case OrganisingMediaItemPartStatus.Waiting: return("Waiting..."); case OrganisingMediaItemPartStatus.Organising: return(IntelligentString.FormatSize(progress).Value + " / " + IntelligentString.FormatSize(size).Value); case OrganisingMediaItemPartStatus.Error: return("Not organised"); case OrganisingMediaItemPartStatus.Organised: if (errorCount == 0) { return("Successfully organised"); } else { if (errorCount == 1) { return("Organised with 1 error"); } else { return("Organised with " + errorCount.ToString() + " errors"); } } } } } } } } return(String.Empty); }
/// <summary> /// Removes the part from the collection /// </summary> /// <param name="location">Location of the part being removed</param> public void Remove(IntelligentString location) { for (int i = 0; i < parts.Count; i++) { if (parts[i].Location == location) { RemoveAt(i); break; } } }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value is TimeSpan) { Boolean includeMilliseconds = System.Convert.ToBoolean(parameter.ToString()); TimeSpan ts = (TimeSpan)value; return(IntelligentString.FormatDuration(ts, includeMilliseconds)); } return(String.Empty); }
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> /// Initialises a new instance of the OrganisingMediaItemPart class /// </summary> /// <param name="mediaItem">Media item the part being organised belongs to</param> /// <param name="partIndex">Index in the media item's collection of the part being organised</param> /// <param name="organisedPath">Path the part will be moved to</param> /// <param name="requiresMove">Value determining whether the part needs to be moved</param> public OrganisingMediaItemPart(MediaItem mediaItem, int partIndex, IntelligentString organisedPath, Boolean requiresMove) { this.mediaItem = mediaItem; this.part = mediaItem.Parts[partIndex]; this.organisedPath = organisedPath; this.progress = 0; this.status = OrganisingMediaItemPartStatus.Waiting; this.errors = new Dictionary <IntelligentString, Exception>(); this.timeTaken = TimeSpan.FromSeconds(0); this.requiresMove = requiresMove; }
/// <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> /// Copies the data from the clone to this media item /// </summary> /// <param name="clone">Media item being cloned</param> public virtual void CopyFromClone(MediaItem clone) { Id = clone.Id; Name = clone.Name; IsHidden = clone.IsHidden; DateCreated = clone.DateCreated; DateModified = clone.DateModified; PlayHistory = clone.PlayHistory; Genre = clone.Genre; Tags = clone.Tags; UserName = clone.UserName; IsInDatabase = clone.IsInDatabase; }
private void miTags_Click(object sender, RoutedEventArgs e) { FrameworkElement element = (FrameworkElement)e.OriginalSource; if (element != null) { if (element.DataContext != null) { IntelligentString tag = (IntelligentString)element.DataContext; Filter.SearchText = tag.Value; } } }
/// <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); }