protected override void OnQueryFiltering(MediaQueryContext context, string protocol) { // TODO: We *could* do more complex parsing to automatically determine mysite.com/filename pattern without http but I don't reckon it's worth it. context.Locations.Add(new MediaLocationContext(){ Location = context.Query, QueryName = "Http", Stream = new HttpStreamAccessor(context.Query) }); }
/// <summary> /// TODO: Code repeated from QueryFiltering - could optimise slightly /// </summary> /// <param name="context"></param> public void QueryFiltered(MediaQueryContext context) { var protocol = GetProtocol(context.Query); if (String.IsNullOrWhiteSpace(protocol)) return; if (Protocols().Any(p => p == protocol)) { OnQueryFiltered(context, protocol); } }
public void QueryFiltering(MediaQueryContext context) { // Opposite of URL location filter if (context.Query.StartsWith("http://") || context.Query.StartsWith("https://")) return; var paths = new List<String>(); if (context.Query== "*") { paths.Add(null); } else { paths.AddRange(context.Query.Split(';')); } List<IStorageFile> files = new List<IStorageFile>(); foreach (var folder in paths) { // Currently we can only use try/catch because *there's no "file exists" method*!! try { var storageFiles = _storageProvider.ListFiles(folder); files.AddRange(storageFiles); } catch { try { // That wasn't a folder. Let's try getting a single file. var file = _storageProvider.GetFile(folder); files.Add(file); } catch { // No files } } } foreach (var file in files) { string filePath = file.GetPath(); context.Locations.Add(new FileSystemLocationContext() { QueryName = "FileSystem", Location = filePath, File = file, Stream = new FileSystemStreamAccessor(file.OpenRead()) }); } }
public void LocationFiltering(MediaQueryContext query, MediaLocationContext location) { // TODO: Could be an interface instead for further extensibility if (!(location is FileSystemLocationContext)) return; var fileLocation = location as FileSystemLocationContext; // Add header detail query.Headers.Add( new MediaHeaderContext(location) { ContentLength = fileLocation.File.GetSize(), // TODO: MIME will be auto-accepted since we leave ContentType blank; so format match will just be on extension. Not a viable long-term solution. ContentType = "", //fileLocation.File.GetFileType(),// .Trim('.').ToLower()), HashCode = fileLocation.File.GetHashCode(), TimeStamp = fileLocation.File.GetLastUpdated(), Title = fileLocation.File.GetName().ExtractFileName() }); }
public void HeaderFiltering(MediaQueryContext query, MediaHeaderContext header) { // Build a temporary source to test formats var testSource = new MediaSource() { Url = header.LocationContext.Location, TimeStamp = header.TimeStamp }; testSource.Metadata["ContentLength"] = header.ContentLength.ToString(); testSource.Metadata["MimeType"] = header.ContentType; testSource.Metadata["Title"] = header.Title; testSource.Metadata["SourceName"] = HeaderName; var testContext = new MediaSourceContext(testSource) { Stream = header.LocationContext.Stream }; var formats = _gardenService.Value.MatchFormats(testContext,query.MediaStereotype).ToList(); // Match a format, add it to sources if (formats.Any()) { testContext.Formats = formats; var format = formats.First(); testSource.MediaStereotype = format.MediaStereotype; testSource.FormatName = format.FormatName; query.Sources.Add(testContext); } else { // Helpful message for debugging sources that don't work :) Services.Notifier.Warning(T("No matching media formats found at {0} (with MIME type '{1}' and file extension '{2}')", testSource.Url, testSource.Metadata["MimeType"], testSource.FileExtension() )); } }
public void LocationFiltered(MediaQueryContext query, MediaLocationContext location) { if (!(location is FileSystemLocationContext)) return; }
public void QueryFiltered(MediaQueryContext context) { }
protected abstract void OnQueryFiltered(MediaQueryContext context, string protocol);
protected override void OnQueryFiltered(MediaQueryContext context, string protocol) { // TODO: Cleanup, ensure HTTP handles are closed (later) }
public void HeaderFiltered(MediaQueryContext query, MediaHeaderContext header) { }
public void LocationFiltered(MediaQueryContext query, MediaLocationContext location) { return; }
public void LocationFiltering(MediaQueryContext query, MediaLocationContext location) { if (location.QueryName != "Http") return; query.Headers.Add(ProbeHttpHeaders(location)); }