public override bool Process(MediaItem mediaItem, out ContentDirectoryMessaging.MediaItemChangeType changeType) { changeType = ContentDirectoryMessaging.MediaItemChangeType.None; IContentDirectory cd = ServiceRegistration.Get <IServerConnectionManager>().ContentDirectory; if (cd == null) { return(false); } var rl = mediaItem.GetResourceLocator(); Guid parentDirectoryId; if (!MediaItemAspect.TryGetAttribute(mediaItem.Aspects, ProviderResourceAspect.ATTR_PARENT_DIRECTORY_ID, out parentDirectoryId)) { return(false); } MediaItemAspect.SetAttribute(mediaItem.Aspects, MediaAspect.ATTR_PLAYCOUNT, GetNewPlayCount()); cd.AddOrUpdateMediaItem(parentDirectoryId, rl.NativeSystemId, rl.NativeResourcePath, mediaItem.Aspects.Values); changeType = ContentDirectoryMessaging.MediaItemChangeType.Updated; return(true); }
public override bool Process(MediaItem mediaItem, out ContentDirectoryMessaging.MediaItemChangeType changeType) { changeType = ContentDirectoryMessaging.MediaItemChangeType.None; if (_schedule != null) { var tvHandler = ServiceRegistration.Get <ITvHandler>(false); if (tvHandler != null && !tvHandler.ScheduleControl.RemoveSchedule(_schedule)) { ServiceRegistration.Get <ILogger>().Warn("DeleteRecordingFromStorage: Failed to remove current schedule."); return(false); } } // When the recording is stopped, it will be imported into library. This can lead to locked files by MetaDataExtractors. // So we allow some retries after a small delay here. for (int i = 1; i <= 3; i++) { if (base.Process(mediaItem, out changeType)) { return(true); } ServiceRegistration.Get <ILogger>().Info("DeleteRecordingFromStorage: Failed to delete recording (try {0})", i); Thread.Sleep(i * 1000); } ServiceRegistration.Get <ILogger>().Warn("DeleteRecordingFromStorage: Failed to delete recording."); return(false); }
protected void UpdateLoadedMediaItems(MediaItem mediaItem, ContentDirectoryMessaging.MediaItemChangeType changeType) { if (changeType == ContentDirectoryMessaging.MediaItemChangeType.None) { return; } bool changed = false; lock (_syncObj) { if (changeType == ContentDirectoryMessaging.MediaItemChangeType.Updated) { IEnumerable <PlayableContainerMediaItem> containerItems = _items.OfType <PlayableContainerMediaItem>(); PlayableContainerMediaItem existingItem = containerItems.FirstOrDefault(pcm => pcm.MediaItem.Equals(mediaItem)); if (existingItem != null) { existingItem.Update(mediaItem); changed = SetSelectedItem(containerItems); } } } if (changed) { _items.FireChange(); } }
public override bool Process(MediaItem mediaItem, out ContentDirectoryMessaging.MediaItemChangeType changeType) { changeType = ContentDirectoryMessaging.MediaItemChangeType.None; var rl = mediaItem.GetResourceLocator(); using (var ra = rl.CreateAccessor()) { var rad = ra as IResourceDeletor; if (rad == null) { return(false); } // First try to delete the file from storage. if (rad.Delete()) { changeType = ContentDirectoryMessaging.MediaItemChangeType.Deleted; // If the MediaItem was loaded from ML, remove it there as well. if (IsManagedByMediaLibrary(mediaItem)) { IContentDirectory cd = ServiceRegistration.Get <IServerConnectionManager>().ContentDirectory; if (cd == null) { return(true); } cd.DeleteMediaItemOrPath(rl.NativeSystemId, rl.NativeResourcePath, true); return(true); } } } return(false); }
public override bool Process(MediaItem mediaItem, out ContentDirectoryMessaging.MediaItemChangeType changeType) { changeType = ContentDirectoryMessaging.MediaItemChangeType.None; WorkflowAction action; if (!ServiceRegistration.Get <IWorkflowManager>().MenuStateActions.TryGetValue(ACTION_ID_ADD_ALL_TO_PLAYLIST, out action)) { return(false); } action.Execute(); return(true); }
private void OnMessageReceived(AsynchronousMessageQueue queue, SystemMessage message) { if (message.ChannelName == ContentDirectoryMessaging.CHANNEL) { ContentDirectoryMessaging.MessageType messageType = (ContentDirectoryMessaging.MessageType)message.MessageType; switch (messageType) { case ContentDirectoryMessaging.MessageType.MediaItemChanged: MediaItem mediaItem = (MediaItem)message.MessageData[ContentDirectoryMessaging.MEDIA_ITEM]; ContentDirectoryMessaging.MediaItemChangeType changeType = (ContentDirectoryMessaging.MediaItemChangeType)message.MessageData[ContentDirectoryMessaging.MEDIA_ITEM_CHANGE_TYPE]; UpdateLoadedMediaItems(mediaItem, changeType); break; } } }
public override bool Process(MediaItem mediaItem, out ContentDirectoryMessaging.MediaItemChangeType changeType) { changeType = ContentDirectoryMessaging.MediaItemChangeType.None; IContentDirectory cd = ServiceRegistration.Get <IServerConnectionManager>().ContentDirectory; if (cd == null) { return(false); } IList <MultipleMediaItemAspect> pras; if (!MediaItemAspect.TryGetAspects(mediaItem.Aspects, ProviderResourceAspect.Metadata, out pras)) { return(false); } Guid? userProfile = null; IUserManagement userProfileDataManagement = ServiceRegistration.Get <IUserManagement>(); if (userProfileDataManagement != null && userProfileDataManagement.IsValidUser) { userProfile = userProfileDataManagement.CurrentUser.ProfileId; } int playCount = GetNewPlayCount(); int playPercentage = playCount > 0 ? 100 : 0; if (playCount > 0) { cd.NotifyPlayback(mediaItem.MediaItemId, true); } if (userProfile.HasValue) { userProfileDataManagement.UserProfileDataManagement.SetUserMediaItemData(userProfile.Value, mediaItem.MediaItemId, UserDataKeysKnown.KEY_PLAY_COUNT, playCount.ToString()); userProfileDataManagement.UserProfileDataManagement.SetUserMediaItemData(userProfile.Value, mediaItem.MediaItemId, UserDataKeysKnown.KEY_PLAY_PERCENTAGE, (playCount > 0 ? 100 : 0).ToString()); } //Also update media item locally so changes are reflected in GUI without reloading MediaItemAspect.SetAttribute(mediaItem.Aspects, MediaAspect.ATTR_PLAYCOUNT, playCount); mediaItem.UserData[UserDataKeysKnown.KEY_PLAY_COUNT] = playCount.ToString(); mediaItem.UserData[UserDataKeysKnown.KEY_PLAY_PERCENTAGE] = playPercentage.ToString(); changeType = ContentDirectoryMessaging.MediaItemChangeType.Updated; return(true); }
protected void UpdateLoadedMediaItems(MediaItem mediaItem, ContentDirectoryMessaging.MediaItemChangeType changeType) { if (changeType == ContentDirectoryMessaging.MediaItemChangeType.None) { return; } bool changed = false; lock (_syncObj) { if (changeType == ContentDirectoryMessaging.MediaItemChangeType.Deleted) { PlayableMediaItem existingItem = _items.OfType <PlayableMediaItem>().FirstOrDefault(pmi => pmi.MediaItem.Equals(mediaItem)); if (existingItem != null) { int oldIndex = _items.IndexOf(existingItem); _items.Remove(existingItem); // Restore focus on same position of old item SetSelectedIndex(oldIndex); _currentTotalNumItems--; changed = true; } } if (changeType == ContentDirectoryMessaging.MediaItemChangeType.Updated) { IEnumerable <PlayableMediaItem> playableItems = _items.OfType <PlayableMediaItem>(); PlayableMediaItem existingItem = playableItems.FirstOrDefault(pmi => pmi.MediaItem.Equals(mediaItem)); if (existingItem != null) { existingItem.Update(mediaItem); changed = SetSelectedItem(playableItems); } } } if (changed) { _items.FireChange(); Display_Normal(_items.Count, _currentTotalNumItems); } }
protected void UpdateLoadedMediaItems(MediaItem mediaItem, ContentDirectoryMessaging.MediaItemChangeType changeType) { if (changeType == ContentDirectoryMessaging.MediaItemChangeType.None) { return; } lock (_syncObj) { if (changeType == ContentDirectoryMessaging.MediaItemChangeType.Updated) { PlayableContainerMediaItem existingItem = _items.OfType <PlayableContainerMediaItem>().FirstOrDefault(pcm => pcm.MediaItem.Equals(mediaItem)); if (existingItem != null) { existingItem.Update(mediaItem); } } } }
protected void UpdateLoadedMediaItems(MediaItem mediaItem, ContentDirectoryMessaging.MediaItemChangeType changeType) { if (changeType == ContentDirectoryMessaging.MediaItemChangeType.None) { return; } bool changed = false; lock (_syncObj) { if (changeType == ContentDirectoryMessaging.MediaItemChangeType.Deleted) { PlayableMediaItem existingItem = _items.OfType <PlayableMediaItem>().FirstOrDefault(pmi => pmi.MediaItem.Equals(mediaItem)); if (existingItem != null) { _items.Remove(existingItem); _currentTotalNumItems--; changed = true; } } if (changeType == ContentDirectoryMessaging.MediaItemChangeType.Updated) { PlayableMediaItem existingItem = _items.OfType <PlayableMediaItem>().FirstOrDefault(pmi => pmi.MediaItem.Equals(mediaItem)); if (existingItem != null) { existingItem.Update(mediaItem); } } } if (changed) { _items.FireChange(); Display_Normal(_items.Count, _currentTotalNumItems); } }
public abstract bool Process(MediaItem mediaItem, out ContentDirectoryMessaging.MediaItemChangeType changeType);
public override bool Process(MediaItem mediaItem, out ContentDirectoryMessaging.MediaItemChangeType changeType) { changeType = ContentDirectoryMessaging.MediaItemChangeType.None; PlayItemsModel.PlayOrEnqueueItem(mediaItem, false, PlayerContextConcurrencyMode.None); return(true); }
public override bool Process(MediaItem mediaItem, out ContentDirectoryMessaging.MediaItemChangeType changeType) { IContentDirectory cd = ServiceRegistration.Get <IServerConnectionManager>().ContentDirectory; bool removeFromML = IsManagedByMediaLibrary(mediaItem) && cd != null; changeType = ContentDirectoryMessaging.MediaItemChangeType.None; // Support multi-resource media items and secondary resources IList <MultipleMediaItemAspect> providerAspects; if (!MediaItemAspect.TryGetAspects(mediaItem.Aspects, ProviderResourceAspect.Metadata, out providerAspects)) { return(false); } foreach (MultipleMediaItemAspect providerAspect in providerAspects) { string systemId = (string)providerAspect[ProviderResourceAspect.ATTR_SYSTEM_ID]; string resourceAccessorPath = (string)providerAspect[ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH]; var rl = new ResourceLocator(systemId, ResourcePath.Deserialize(resourceAccessorPath)); using (var ra = rl.CreateAccessor()) { var rad = ra as IResourceDeletor; if (rad == null) { return(false); } // First try to delete the file from storage. if (!rad.Delete()) { return(false); } changeType = ContentDirectoryMessaging.MediaItemChangeType.Deleted; // If the MediaItem was loaded from ML, remove it there as well. if (removeFromML) { cd.DeleteMediaItemOrPath(rl.NativeSystemId, rl.NativeResourcePath, true); } } } // Check for special cases here: // 1) Recordings have an additional .xml attached // 2) Deleting files could lead to empty folders that should be also removed foreach (DeleteRule rule in _defaultRules.Where(r => r.IsEnabled)) { if (mediaItem.Aspects.ContainsKey(rule.HasAspectGuid)) { var tsPath = mediaItem.GetResourceLocator().NativeResourcePath.ToString(); foreach (string otherExtension in rule.DeleteOtherExtensions) { string otherFilePath = ProviderPathHelper.ChangeExtension(tsPath, otherExtension); IResourceAccessor ra; if (!ResourcePath.Deserialize(otherFilePath).TryCreateLocalResourceAccessor(out ra)) { continue; } // Delete other file. We do not check here for existance of file, the Delete needs to handle this. using (ra) { var rad = ra as IResourceDeletor; rad?.Delete(); } } if (rule.DeleteEmptyFolders) { var folderPath = ProviderPathHelper.GetDirectoryName(tsPath); IResourceAccessor ra; if (!ResourcePath.Deserialize(folderPath).TryCreateLocalResourceAccessor(out ra)) { continue; } // Delete folder if empty using (ra) { IFileSystemResourceAccessor fsra = ra as IFileSystemResourceAccessor; if (fsra != null) { var isEmpty = fsra.GetFiles().Count == 0 && fsra.GetChildDirectories().Count == 0; if (isEmpty) { var rad = ra as IResourceDeletor; rad?.Delete(); } } } } } } return(true); }
public override bool Process(MediaItem mediaItem, out ContentDirectoryMessaging.MediaItemChangeType changeType) { changeType = ContentDirectoryMessaging.MediaItemChangeType.None; return(ServiceRegistration.Get <IWorkflowManager>().TryExecuteAction(ACTION_ID_ADD_ALL_TO_PLAYLIST)); }