示例#1
0
        private async Task OnFwRenamed(string oldPath, string newPath, bool isAFolder)
        {
            var files = PlayLists
                        .SelectMany(f => f.Items)
                        .Where(f => isAFolder ? f.Path.StartsWith(oldPath) : f.Path == oldPath)
                        .ToList();

            foreach (var file in files)
            {
                var playlist = PlayLists.FirstOrDefault(f => f.Id == file.PlayListId);
                if (playlist == null)
                {
                    continue;
                }

                if (isAFolder)
                {
                    //Here I'm not sure how to retain the order
                    await playlist.RemoveFilesThatStartsWith(oldPath);

                    await playlist.OnFolderAddedCommand.ExecuteAsync(new[] { newPath });
                }
                else
                {
                    await playlist.OnFilesAddedCommand.ExecuteAsync(new[] { newPath });

                    playlist.ExchangeLastFilePosition(file.Id);
                    await playlist.RemoveFile(file.Id);
                }
                _appWebServer?.OnPlayListChanged(playlist.Id);
            }
        }
示例#2
0
        private void InitializeOrUpdateFileWatcher(bool update)
        {
            Logger.LogInformation($"{nameof(InitializeOrUpdateFileWatcher)}: Getting directories to watch...");
            var dirs = PlayLists.SelectMany(pl => pl.Items)
                       .Where(f => f.IsLocalFile)
                       .Select(f => Path.GetDirectoryName(f.Path))
                       .Distinct()
                       .ToList();

            Logger.LogInformation($"{nameof(InitializeOrUpdateFileWatcher)}: Got = {dirs.Count} directories...");
            if (!update)
            {
                Logger.LogInformation($"{nameof(InitializeOrUpdateFileWatcher)}: Starting to watch for {dirs.Count} directories...");
                _fileWatcherService.StartListening(dirs);
                _fileWatcherService.OnFileCreated = OnFwCreated;
                _fileWatcherService.OnFileChanged = OnFwChanged;
                _fileWatcherService.OnFileDeleted = OnFwDeleted;
                _fileWatcherService.OnFileRenamed = OnFwRenamed;
            }
            else
            {
                Logger.LogInformation($"{nameof(InitializeOrUpdateFileWatcher)}: Updating watched directories...");
                _fileWatcherService.UpdateWatchers(dirs);
            }
        }
示例#3
0
        private async Task OnFwChanged(string path, bool isAFolder)
        {
            var files = PlayLists
                        .SelectMany(f => f.Items)
                        .Where(f => isAFolder ? f.Path.StartsWith(path) : f.Path == path)
                        .ToList();

            foreach (var file in files)
            {
                var playlist = PlayLists.FirstOrDefault(f => f.Id == file.PlayListId);
                if (playlist == null)
                {
                    continue;
                }

                await playlist.SetFileInfo(file.Id, _setDurationTokenSource.Token);

                _appWebServer?.OnFileChanged(playlist.Id);
            }
        }