예제 #1
0
            public IList <Guid> Execute(IList <string> mediaFiles, ShareLocation shareLocation)
            {
                NumFiles = mediaFiles.Count;
                IServerConnectionManager scm = ServiceRegistration.Get <IServerConnectionManager>();
                IContentDirectory        cd  = scm.ContentDirectory;
                string systemId = shareLocation == ShareLocation.Local ? ServiceRegistration.Get <ISystemResolver>().LocalSystemId : scm.HomeServerSystemId;

                Guid[] necessaryAudioAspectIds = null;
                Guid[] optionalAudioAspectIds  = null;

                ILogger        logger        = ServiceRegistration.Get <ILogger>();
                IScreenManager screenManager = ServiceRegistration.Get <IScreenManager>();
                Guid?          dialogId      = screenManager.ShowDialog(Consts.DIALOG_IMPORT_PLAYLIST_PROGRESS, (dialogName, dialogInstanceId) => Cancel());

                if (!dialogId.HasValue)
                {
                    logger.Warn("ImportPlaylistOperation: Error showing progress dialog");
                    return(null);
                }

                Guid?           userProfile = null;
                IUserManagement userProfileDataManagement = ServiceRegistration.Get <IUserManagement>();

                if (userProfileDataManagement != null && userProfileDataManagement.IsValidUser)
                {
                    userProfile = userProfileDataManagement.CurrentUser.ProfileId;
                }

                IList <Guid> result = new List <Guid>();

                NumMatched   = 0;
                NumProcessed = 0;
                NumMatched   = 0;
                UpdateScreenData();
                try
                {
                    foreach (string localMediaFile in mediaFiles)
                    {
                        if (IsCancelled)
                        {
                            return(null);
                        }
                        CheckUpdateScreenData();
                        MediaItem item = cd.LoadItemAsync(systemId, LocalFsResourceProviderBase.ToResourcePath(localMediaFile),
                                                          necessaryAudioAspectIds, optionalAudioAspectIds, userProfile).Result;
                        NumProcessed++;
                        if (item == null)
                        {
                            logger.Warn("ImportPlaylistOperation: Media item '{0}' was not found in the media library", localMediaFile);
                            continue;
                        }
                        logger.Debug("ImportPlaylistOperation: Matched media item '{0}' in media library", localMediaFile);
                        NumMatched++;
                        result.Add(item.MediaItemId);
                    }
                }
                catch (Exception e)
                {
                    logger.Warn("ImportPlaylistOperation: Error importing playlist", e);
                }
                screenManager.CloseDialog(dialogId.Value);
                return(result);
            }