public static bool IsCompatibleImage(FileResource resource) { string[] supported = new string[] { ".jpg", ".png", ".bmp", ".gif" }; bool compatible = false; foreach (string extension in supported) { if (resource.Path.EndsWith(extension)) { return true; } } return compatible; }
public static bool IsCompatibleVideo(FileResource resource) { string[] supported = new string[] { ".mp4" }; bool compatible = false; foreach (string extension in supported) { if (resource.Path.EndsWith(extension)) { return true; } } return compatible; }
private async void HandleFileResource(Job job, FileResource resource) { bool accessable = false; try { // Try to access file at the given path StorageFile file = await StorageFile.GetFileFromPathAsync(resource.Path); accessable = true; } catch (Exception ex) { // It is a file, but it could not be found or accessed if (ex is FileNotFoundException) { if (this.OnResourceNotAvailable != null) { this.OnResourceNotAvailable(job); } } else if (ex is UnauthorizedAccessException) { EventsManager.Log(Job_EventType.Error, this.configuration, "Could not access " + resource.Path); } else { // non html web resources are also file resources if (await CompatibilityManager.IsAvailableWebResource(resource.Path)) { accessable = true; } } } if (accessable) { if (CompatibilityManager.IsCompatibleImage(resource)) { if (this.OnImageDisplayRequested != null) { await this.displayDispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { BitmapImage img = new BitmapImage(new Uri(resource.Path)); this.OnImageDisplayRequested(img); }); } } else if (CompatibilityManager.IsCompatibleVideo(resource)) { if (this.OnVideoDisplayRequested != null) { await this.displayDispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this.OnVideoDisplayRequested(new Uri(resource.Path)); }); } } } else { RenderConfiguration config = this.GetNewRenderConfiguration(job); WorkingAgent worker = await this.agentSelectors[job].GetCompatibleAgent(config); this.HandleFoundWorkingAgent(job, worker); } }