public MediaItemsViewerPage() { InitializeComponent(); MediaItemModel = new MediaItemsListModelItem(); PrepareApplicationBar(); }
public MediaItemsListModelItem GetMediaItemForId(string id) { var mediaItemQuery = from items in MediaItems where items.Id == id select items; MediaItemsListModelItem resultItem = mediaItemQuery.First <MediaItemsListModelItem>(); return(resultItem != null ? resultItem : new MediaItemsListModelItem()); }
private MediaItemStatisticItem(StatisticType type, string username, MediaItemsListModelItem mediaItem) : base(type, username) { Details = new Dictionary <string, string>() { { DetailKeys.MediaId, mediaItem.Id }, { DetailKeys.MediaTitle, mediaItem.Title }, { DetailKeys.MediaType, mediaItem.ItemType.ToString() }, }; }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs args) { IDictionary<string, string> parameters = NavigationContext.QueryString; Debug.Assert(parameters.ContainsKey("id")); ContentId = parameters["id"]; App.Engine.LibraryModel.LoadLibraryStateIfNotLoaded(); MediaItemModel = App.Engine.LibraryModel.GetMediaItemForId(ContentId); ContentPanel.DataContext = MediaItemModel.ExternalLinks; base.OnNavigatedTo(args); }
public QueuedDownload(MediaItemsListModelItem mediaItem) { Id = mediaItem.Id; Type = mediaItem.ItemType; Title = mediaItem.Title; LibraryId = mediaItem.LibraryId; Filename = mediaItem.FileName; State = DownloadState.Queued; DownloadedBytes = 0; DownloadSize = long.MaxValue; ForceActiveDownload = false; }
public void DeleteItem(LibraryModelItem item) { XElement node = (from nedNodeElements in LibraryDocument.Descendants(NedNodeTag) where (string)nedNodeElements.Attribute(NedNodeIdAttribute) == item.Id select nedNodeElements).FirstOrDefault(); if (node != null) { node.Remove(); } if (item is CatalogueModelItem) { CatalogueItems.Remove(item as CatalogueModelItem); var query = from categoriesToRemove in CategoryItems where categoriesToRemove.ParentId == item.Id select categoriesToRemove; List <CategoryModelItem> catTempList = query.ToList <CategoryModelItem>(); foreach (LibraryModelItem itemToRemove in catTempList) { DeleteItem(itemToRemove); } } else if (item is CategoryModelItem) { CategoryItems.Remove(item as CategoryModelItem); foreach (LibraryModelItem miToRemove in (item as CategoryModelItem).Children()) { DeleteItem(miToRemove); } } else if (item is MediaItemsListModelItem) { MediaItemsListModelItem mediaItem = item as MediaItemsListModelItem; MediaItems.Remove(mediaItem); App.Engine.DeleteMediaItem(mediaItem); } else { Debug.Assert(false, FileLanguage.LibraryModel_RemovingUnknowTypeError); } App.Engine.StatisticsManager.LogItemDeleted(item.Id); OnLibraryItemRemoved(new LibraryRemovedEventArgs() { RemovedItem = item }); }
public AddingToQueueResult EnqueueMediaItem(MediaItemsListModelItem mediaItem, bool immediate, bool forceNow = false) { if (LoggedUser.Downloads.Count(queuedDownload => queuedDownload.Id == mediaItem.Id) == 0) { QueuedDownload.DownloadState initialState = App.Engine.LoggedUser.Settings.AutomaticDownloads ? QueuedDownload.DownloadState.Queued : (immediate ? QueuedDownload.DownloadState.Queued : QueuedDownload.DownloadState.Paused); QueuedDownload queuedDownload = new QueuedDownload(mediaItem) { State = initialState }; using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { if (isf.FileExists(Utils.MediaFilePath(LoggedUser, queuedDownload))) { return(AddingToQueueResult.ItemAlreadyDownloaded); } } StatisticsManager.LogDownloadAdd(queuedDownload); LoggedUser.Downloads.Add(queuedDownload); _downloadEnqueuedEvent.OnNext(queuedDownload); if (initialState != QueuedDownload.DownloadState.Stopped) { DownloadManager.StartDownload(queuedDownload, false, forceNow); } return(AddingToQueueResult.ItemAddedToQueue); } else if (immediate) { QueuedDownload queuedDownload = (from download in LoggedUser.Downloads where download.Id == mediaItem.Id select download).First(); queuedDownload.State = QueuedDownload.DownloadState.Queued; DownloadManager.StartDownload(queuedDownload); return(AddingToQueueResult.DownloadItemStarted); } else { return(AddingToQueueResult.ItemAlreadyDownloaded); } }
public void DeleteMediaItem(MediaItemsListModelItem item) { var downloads = LoggedUser.Downloads.Where(dl => dl.Id == item.Id).ToList(); if (downloads.Count > 0) { DownloadManager.CancelDownloads(downloads) .ObserveOnDispatcher() .Finally(() => { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { foreach (var download in downloads) { string path = Utils.MediaFilePath(LoggedUser, download); if (isf.FileExists(path)) { isf.DeleteFile(path); } } } }) .Subscribe(); LoggedUser.Downloads.Remove(downloads); } else { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { string path = Utils.MediaFilePath(LoggedUser, item); if (isf.FileExists(path)) { isf.DeleteFile(path); } } } }
public void LogShowMediaDetails(MediaItemsListModelItem mediaItem) { Statistics.Add(MediaItemStatisticItem.CreateMediaShowDetailsEvent(LoggedUser.LoggedUser, mediaItem)); }
public static string MediaFilePath(User user, MediaItemsListModelItem item) { return(MediaFilePath(user, item.LibraryId, FilenameToLocalFilename(item.FileName))); }
public void LogShowMediaDetails( MediaItemsListModelItem mediaItem ) { Statistics.Add( MediaItemStatisticItem.CreateMediaShowDetailsEvent( LoggedUser.LoggedUser, mediaItem ) ); }
private void RemoveChildFromCollection( MediaItemsListModelItem child ) { ChildrenItems.Remove( child ); child.PropertyChanged -= OnChildPropertyChanged; }
public void RemoveChild( MediaItemsListModelItem child ) { RemoveChildFromCollection( child ); UpdateSubtitleString(); }
private void AddChildToCollection(MediaItemsListModelItem child) { child.PropertyChanged += OnChildPropertyChanged; ChildrenItems.Add(child); }
public void AddChild(MediaItemsListModelItem child) { AddChildToCollection(child); UpdateSubtitleString(); }
public void LogMediaStop(MediaItemsListModelItem mediaItem) { Statistics.Add(MediaItemStatisticItem.CreateMediaStopItemStartEvent(LoggedUser.LoggedUser, mediaItem)); }
public void RemoveChild(MediaItemsListModelItem child) { RemoveChildFromCollection(child); UpdateSubtitleString(); }
public void DeleteMediaItem( MediaItemsListModelItem item ) { var downloads = LoggedUser.Downloads.Where( dl => dl.Id == item.Id ).ToList(); if( downloads.Count > 0 ) { DownloadManager.CancelDownloads( downloads ) .ObserveOnDispatcher() .Finally( () => { using( IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication() ) { foreach( var download in downloads ) { string path = Utils.MediaFilePath( LoggedUser, download ); if( isf.FileExists( path ) ) { isf.DeleteFile( path ); } } } } ) .Subscribe(); LoggedUser.Downloads.Remove( downloads ); } else { using( IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication() ) { string path = Utils.MediaFilePath( LoggedUser, item ); if( isf.FileExists( path ) ) { isf.DeleteFile( path ); } } } }
private void RemoveChildFromCollection(MediaItemsListModelItem child) { ChildrenItems.Remove(child); child.PropertyChanged -= OnChildPropertyChanged; }
public AddingToQueueResult EnqueueMediaItem( MediaItemsListModelItem mediaItem, bool immediate, bool forceNow = false ) { if( LoggedUser.Downloads.Count( queuedDownload => queuedDownload.Id == mediaItem.Id ) == 0 ) { QueuedDownload.DownloadState initialState = App.Engine.LoggedUser.Settings.AutomaticDownloads ? QueuedDownload.DownloadState.Queued : ( immediate ? QueuedDownload.DownloadState.Queued : QueuedDownload.DownloadState.Paused ); QueuedDownload queuedDownload = new QueuedDownload( mediaItem ) { State = initialState }; using( IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication() ) { if( isf.FileExists( Utils.MediaFilePath( LoggedUser, queuedDownload ) ) ) { return AddingToQueueResult.ItemAlreadyDownloaded; } } StatisticsManager.LogDownloadAdd( queuedDownload ); LoggedUser.Downloads.Add( queuedDownload ); _downloadEnqueuedEvent.OnNext( queuedDownload ); if( initialState != QueuedDownload.DownloadState.Stopped ) { DownloadManager.StartDownload( queuedDownload, false, forceNow ); } return AddingToQueueResult.ItemAddedToQueue; } else if( immediate ) { QueuedDownload queuedDownload = ( from download in LoggedUser.Downloads where download.Id == mediaItem.Id select download ).First(); queuedDownload.State = QueuedDownload.DownloadState.Queued; DownloadManager.StartDownload( queuedDownload ); return AddingToQueueResult.DownloadItemStarted; } else { return AddingToQueueResult.ItemAlreadyDownloaded; } }
public void AddChild( MediaItemsListModelItem child ) { AddChildToCollection( child ); UpdateSubtitleString(); }
public static MediaItemStatisticItem CreateMediaPlayItemStartEvent(User user, MediaItemsListModelItem startedMediaItem) { return(new MediaItemStatisticItem(StatisticType.PLAY_ITEM_START, user.Username, startedMediaItem)); }
private void AddChildToCollection( MediaItemsListModelItem child ) { child.PropertyChanged += OnChildPropertyChanged; ChildrenItems.Add( child ); }
public static MediaItemStatisticItem CreateMediaStopItemStartEvent(User user, MediaItemsListModelItem stoppedMediaItem) { return(new MediaItemStatisticItem(StatisticType.PLAY_ITEM_END, user.Username, stoppedMediaItem)); }
public void LogMediaStop( MediaItemsListModelItem mediaItem ) { Statistics.Add( MediaItemStatisticItem.CreateMediaStopItemStartEvent( LoggedUser.LoggedUser, mediaItem ) ); }
public static MediaItemStatisticItem CreateMediaShowDetailsEvent(User user, MediaItemsListModelItem mediaItem) { return(new MediaItemStatisticItem(StatisticType.DETAILS_SHOW, user.Username, mediaItem)); }
public void UpdatedView( MediaItemsListModelItem mediaItem ) { switch( mediaItem.ItemType ) { case MediaItemType.Picture: PictureItemModel pictureModel = new PictureItemModel(); pictureModel.LoadImage( mediaItem.GetMediaFileIsolatedStoragePath() ); Content = pictureModel; ContentTemplate = PictureTemplate; break; case MediaItemType.Text: ContentTemplate = TextTemplate; break; case MediaItemType.Audio: Content = new AudioVideoItemModel() { MediaSource = mediaItem.GetMediaFileIsolatedStoragePath() }; ContentTemplate = AudioTemplate; break; case MediaItemType.Video: Content = new AudioVideoItemModel() { MediaSource = mediaItem.GetMediaFileIsolatedStoragePath() }; ContentTemplate = VideoTemplate; break; case MediaItemType.Undefined: ContentTemplate = UnknownTemplate; break; default: break; } }
public static MediaItemStatisticItem CreateMediaShowLinksEvent(User user, MediaItemsListModelItem mediaItem) { return(new MediaItemStatisticItem(StatisticType.SHOW_LINKS, user.Username, mediaItem)); }
protected override void OnNavigatedTo( System.Windows.Navigation.NavigationEventArgs args ) { IDictionary<string, string> parameters = NavigationContext.QueryString; string id = parameters["id"]; App.Engine.LibraryModel.LoadLibraryStateIfNotLoaded(); MediaItemModel = App.Engine.LibraryModel.GetMediaItemForId( id ); if( id == null || MediaItemModel == null ) { MessageBox.Show( FileLanguage.MediaItemViewerPage_CanNotOpenItem ); System.Diagnostics.Debug.Assert( false, "Navigated to MediaItemsViewerPage without or with non-existant item ID" ); } else { TitlePanel.TitleText = MediaItemModel.Title; } base.OnNavigatedTo( args ); }
// Load library and return it's id public string LoadLibrary(Library library) { ActiveLibrary = library; LibraryDocument = Library.GetLibraryContents(ActiveLibrary, App.Engine.LoggedUser); LibraryDocument.Changed += OnLibraryDocumentChanged; ChangedContent = Library.GetChangedContent(ActiveLibrary, App.Engine.LoggedUser); LibraryId = LibraryDocument.Root.Attribute(NedNodeIdAttribute).Value; var mediaItemsQuery = from nedNodeElements in LibraryDocument.Descendants(NedNodeTag) from nedNodeChildren in nedNodeElements.Element(NedNodeChildrenTag).Elements() where (string)nedNodeElements.Attribute(NedNodeTypeAttribute) == CategoryTagType select new MediaItemsListModelItem() { Id = nedNodeChildren.Attribute(NedNodeIdAttribute).Value, LibraryId = this.LibraryId, ParentId = nedNodeElements.Attribute(NedNodeIdAttribute).Value, Title = nedNodeChildren.Element(TitleTag).Value, FileName = nedNodeChildren.Attribute(NedNodeDataAttribute) != null?nedNodeChildren.Attribute(NedNodeDataAttribute).Value : String.Empty, ItemType = MediaItemsListModelItem.GetTypeFromString(nedNodeChildren.Attribute(NedNodeTypeAttribute).Value), Description = nedNodeChildren.Element(NedNodeDescriptionTag) != null?nedNodeChildren.Element(NedNodeDescriptionTag).Value : String.Empty, ExternalLinks = (from linkElement in nedNodeChildren.Elements(NedNodeLinkTag) select linkElement.Value).ToList(), Keywords = (from keywordElement in nedNodeChildren.Elements(NedNodeKeywordTag) select keywordElement.Value).ToList(), IsChanged = ChangedContent != null ? (from changedElements in ChangedContent.Root.Descendants(NedNodeTag) where changedElements.Attribute(NedNodeIdAttribute).Value == nedNodeChildren.Attribute(NedNodeIdAttribute).Value select changedElements).Count() > 0 : false }; ObservableCollection <MediaItemsListModelItem> AllMediaItemsTemp = new ObservableCollection <MediaItemsListModelItem>(); foreach (MediaItemsListModelItem item in mediaItemsQuery) { // To avoid multiple observers notifications on initialization AllMediaItemsTemp.Add(item); } MediaItems = AllMediaItemsTemp; var categoryItemsQuery = from nedNodeElements in LibraryDocument.Descendants(NedNodeTag) from nedNodeChildren in nedNodeElements.Element(NedNodeChildrenTag).Elements() where (string)nedNodeElements.Attribute(NedNodeTypeAttribute) == CatalogueTagType select new CategoryModelItem() { Id = nedNodeChildren.Attribute(NedNodeIdAttribute).Value, ParentId = nedNodeElements.Attribute(NedNodeIdAttribute).Value, Title = nedNodeChildren.Element(TitleTag).Value, IsChanged = ChangedContent != null ? (from changedElements in ChangedContent.Root.Descendants(NedNodeTag) where changedElements.Attribute(NedNodeIdAttribute).Value == nedNodeChildren.Attribute(NedNodeIdAttribute).Value select changedElements).Count() > 0 : false }; ObservableCollection <CategoryModelItem> AllCategoryItemsTemp = new ObservableCollection <CategoryModelItem>(); foreach (CategoryModelItem item in categoryItemsQuery) { // To avoid multiple observers notifications on initialization AllCategoryItemsTemp.Add(item); } CategoryItems = AllCategoryItemsTemp; foreach (CategoryModelItem catItem in CategoryItems) { catItem.AddChildren((from catChild in MediaItems where catChild.ParentId == catItem.Id select catChild).ToList()); } var catalogueItemsQuery = from nedNodeElements in LibraryDocument.Descendants(NedNodeTag) from nedNodeChildren in nedNodeElements.Element(NedNodeChildrenTag).Elements() where (string)nedNodeElements.Attribute(NedNodeTypeAttribute) == LibraryTagType select new CatalogueModelItem() { Id = nedNodeChildren.Attribute(NedNodeIdAttribute).Value, ParentId = nedNodeElements.Attribute(NedNodeIdAttribute).Value, Title = nedNodeChildren.Element(TitleTag).Value, Subtitle = CatalogueModelItem.GetSubtitleString(nedNodeChildren.Element(NedNodeChildrenTag).Elements().Count <XElement>()), IsChanged = ChangedContent != null ? (from changedElements in ChangedContent.Root.Descendants(NedNodeTag) where changedElements.Attribute(NedNodeIdAttribute).Value == nedNodeChildren.Attribute(NedNodeIdAttribute).Value select changedElements).Count() > 0 : false }; ObservableCollection <CatalogueModelItem> CatalogueItemsTemp = new ObservableCollection <CatalogueModelItem>(); foreach (CatalogueModelItem item in catalogueItemsQuery) { // To avoid multiple observers notifications on initialization CatalogueItemsTemp.Add(item); } CatalogueItems = CatalogueItemsTemp; CatalogueItems.CollectionChanged += OnCatalogueItemsPropertyChanged; LibraryName = LibraryDocument.Root.Element(TitleTag).Value; UpdateMediaItemsDownloadedStatus(); return(LibraryId); }