/// <summary> /// 异步线程池绑定缩略图 /// </summary> private static void BindThumbnialAync(ThumbnailImage image, object fileSource, double w, double h) { if (fileSource == null) { return; } IThumbnailProvider thumbnailProvider = ThumbnailProviderFactory.GetInstance(image.ThumbnailType); var cache = image.CacheEnable; var time = image.CacheTime; System.Utility.Executer.TryRunByThreadPool(() => { ImageSource img = null; if (cache) { img = CacheManager.GetCache <ImageSource>(fileSource.GetHashCode().ToString(), time, () => { return(thumbnailProvider.GenereateThumbnail(fileSource, w, h)); }); } else { img = thumbnailProvider.GenereateThumbnail(fileSource, w, h); } image.Dispatcher.BeginInvoke(new Action(() => { image.Source = img; }), DispatcherPriority.ApplicationIdle); }); }
private void OnThumbnailReady(IThumbnailProvider dw, ThumbnailReadyHandler callback, Surface thumb) { Pair <IThumbnailProvider, Surface> data = Pair.Create(dw, thumb); ThumbnailReadyArgs e = new ThumbnailReadyArgs(data); lock (this.thumbnailReadyInvokeList) { this.thumbnailReadyInvokeList.Add(new ThumbnailReadyEventDetails(callback, this, e)); } try { this.syncContext.BeginInvoke(new Procedure(DrainThumbnailReadyInvokeList), null); } catch (ObjectDisposedException) { // Ignore this error } catch (InvalidOperationException) { // If syncContext was destroyed, then ignore } }
private bool OnThumbnailReady(IThumbnailProvider dw, ValueEventHandler <Tuple <IThumbnailProvider, ISurface <ColorBgra> > > callback, ISurface <ColorBgra> thumb) { ValueEventArgs <Tuple <IThumbnailProvider, ISurface <ColorBgra> > > args = ValueEventArgs <Tuple <IThumbnailProvider, ISurface <ColorBgra> > > .Get(Tuple.Create <IThumbnailProvider, ISurface <ColorBgra> >(dw, thumb)); List <Tuple <ValueEventHandler <Tuple <IThumbnailProvider, ISurface <ColorBgra> > >, object, ValueEventArgs <Tuple <IThumbnailProvider, ISurface <ColorBgra> > > > > thumbnailReadyInvokeList = this.thumbnailReadyInvokeList; lock (thumbnailReadyInvokeList) { this.thumbnailReadyInvokeList.Add(new Tuple <ValueEventHandler <Tuple <IThumbnailProvider, ISurface <ColorBgra> > >, object, ValueEventArgs <Tuple <IThumbnailProvider, ISurface <ColorBgra> > > >(callback, this, args)); } try { this.syncContext.Post(delegate(object _) { this.DrainThumbnailReadyInvokeList(); }, null); return(true); } catch (Exception exception) { if (!(exception is ObjectDisposedException) && !(exception is InvalidOperationException)) { throw; } return(false); } }
public void QueueThumbnailUpdate(IThumbnailProvider updateMe, int thumbSideLength, ThumbnailReadyHandler callback) { if (thumbSideLength < 1) { throw new ArgumentOutOfRangeException("thumbSideLength", "must be greater than or equal to 1"); } lock (this.updateLock) { bool doIt = false; ThumbnailStackItem addMe = new ThumbnailStackItem(updateMe, callback, thumbSideLength); if (this.renderQueue.Count == 0) { doIt = true; } else { ThumbnailStackItem top = this.renderQueue.Peek(); if (addMe != top) { doIt = true; } } // Only add this item to the queue if the item is not already at the top of the queue if (doIt) { this.renderQueue.Push(addMe); } Monitor.Pulse(this.updateLock); } }
public void InitProviders() { lock (_syncObj) { if (_providerList != null) { return; } var providerList = new List <SortedThumbnailCreator>(); _thumbnailProviderPluginItemStateTracker = new FixedItemStateTracker("ThumbnailGenerator Service - Provider registration"); IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>(); foreach (PluginItemMetadata itemMetadata in pluginManager.GetAllPluginItemMetadata(ThumbnailProviderBuilder.THUMBNAIL_PROVIDER_PATH)) { try { ThumbnailProviderRegistration thumbnailProviderRegistration = pluginManager.RequestPluginItem <ThumbnailProviderRegistration>(ThumbnailProviderBuilder.THUMBNAIL_PROVIDER_PATH, itemMetadata.Id, _thumbnailProviderPluginItemStateTracker); if (thumbnailProviderRegistration == null || thumbnailProviderRegistration.ProviderClass == null) { ServiceRegistration.Get <ILogger>().Warn("Could not instantiate IThumbnailProvider with id '{0}'", itemMetadata.Id); } else { IThumbnailProvider provider = Activator.CreateInstance(thumbnailProviderRegistration.ProviderClass) as IThumbnailProvider; if (provider == null) { throw new PluginInvalidStateException("Could not create IThumbnailProvider instance of class {0}", thumbnailProviderRegistration.ProviderClass); } providerList.Add(new SortedThumbnailCreator { Priority = thumbnailProviderRegistration.Priority, Provider = provider }); } } catch (PluginInvalidStateException e) { ServiceRegistration.Get <ILogger>().Warn("Cannot add IThumbnailProvider with id '{0}'", e, itemMetadata.Id); } } providerList.Sort((p1, p2) => p1.Priority.CompareTo(p2.Priority)); _providerList = providerList; } }
private void TestSingleThumbCreation(string fileName, int size, ImageType?expectedImageType = null) { string file = Path.GetFileName(fileName); byte[] imageData = null; ImageType imageType = ImageType.Unknown; bool result = false; IThumbnailProvider lastUsedProvider = null; foreach (IThumbnailProvider provider in _providers) { // We know that not all providers can support all formats, so we allow all to be tried. lastUsedProvider = provider; result = provider.GetThumbnail(fileName, size, size, false, out imageData, out imageType); if (result) { break; } } Assert.AreEqual(true, result, $"{lastUsedProvider?.GetType().Name}: Thumbnail creation failed ({file}, {size})"); Assert.AreNotEqual(null, imageData, $"{lastUsedProvider?.GetType().Name}: Thumbnail creation success, but no image data returned (null) ({file}, {size})"); Assert.AreNotEqual(0, imageData?.Length, $"{lastUsedProvider?.GetType().Name}: Thumbnail creation success, but no image data returned (length=0) ({file}, {size})"); if (expectedImageType.HasValue) { Assert.AreEqual(expectedImageType.Value, imageType, $"{lastUsedProvider?.GetType().Name}: Thumbnail creation success, but resulting image types is wrong ({file}, {size})"); } #if DEBUG // Only write images in debug mode for checking output quality if (result) { var targetBase = Path.GetFileNameWithoutExtension(fileName); if (!Directory.Exists(RESIZED_FOLDER)) { Directory.CreateDirectory(RESIZED_FOLDER); } string targetFile = RESIZED_FOLDER + $"{targetBase}_{size}.{imageType}"; File.WriteAllBytes(targetFile, imageData); } #endif }
private void OnThumbnailReady(IThumbnailProvider dw, ThumbnailReadyHandler callback, Surface thumb) { Pair <IThumbnailProvider, Surface> data = new Pair <IThumbnailProvider, Surface>(dw, thumb); ThumbnailReadyArgs e = new ThumbnailReadyArgs(data); lock (this.thumbnailReadyInvokeList) { this.thumbnailReadyInvokeList.Add(new Triple <ThumbnailReadyHandler, object, ThumbnailReadyArgs>(callback, this, e)); } try { //this.syncContext.BeginInvoke(callback, new object[] { this, e }); this.syncContext.BeginInvoke(new Procedure(DrainThumbnailReadyInvokeList), null); } catch (InvalidOperationException) { // If syncContext was destroyed, then ignore } }
public bool RemoveFromQueue(IThumbnailProvider nukeMe) { if (nukeMe == null) { return(false); } object updateLock = this.updateLock; lock (updateLock) { bool flag2 = false; for (int i = 0; i < this.renderQueue.Count; i++) { if ((this.renderQueue[i] != null) && nukeMe.Equals(this.renderQueue[i].Item1)) { this.renderQueue[i] = null; flag2 = true; } } return(flag2); } }
public void RemoveFromQueue(IThumbnailProvider nukeMe) { lock (this.updateLock) { ThumbnailStackItem[] tsiArray = this.renderQueue.ToArray(); List <ThumbnailStackItem> tsiAccumulate = new List <ThumbnailStackItem>(); for (int i = 0; i < tsiArray.Length; ++i) { if (tsiArray[i].First != nukeMe) { tsiAccumulate.Add(tsiArray[i]); } } this.renderQueue.Clear(); for (int i = 0; i < tsiAccumulate.Count; ++i) { this.renderQueue.Push(tsiAccumulate[i]); } } }
public void QueueThumbnailUpdate(IThumbnailProvider updateMe, int thumbSideLength, ValueEventHandler <Tuple <IThumbnailProvider, ISurface <ColorBgra> > > callback) { if (thumbSideLength < 1) { throw new ArgumentOutOfRangeException("thumbSideLength", "must be greater than or equal to 1"); } object updateLock = this.updateLock; lock (updateLock) { this.RemoveFromQueue(updateMe); Tuple <IThumbnailProvider, ValueEventHandler <Tuple <IThumbnailProvider, ISurface <ColorBgra> > >, int> item = new Tuple <IThumbnailProvider, ValueEventHandler <Tuple <IThumbnailProvider, ISurface <ColorBgra> > >, int>(updateMe, callback, thumbSideLength); if (this.renderQueue.Any <Tuple <IThumbnailProvider, ValueEventHandler <Tuple <IThumbnailProvider, ISurface <ColorBgra> > >, int> >()) { Tuple <IThumbnailProvider, ValueEventHandler <Tuple <IThumbnailProvider, ISurface <ColorBgra> > >, int> tuple2 = this.renderQueue.PeekBack(); if (item.Equals(tuple2)) { this.renderQueue.DequeueBack(); } } this.renderQueue.Enqueue(item); Monitor.Pulse(this.updateLock); } }
public MaterialModificationService(IFamilyInfrastructureProvider infrastructure, IThumbnailProvider thumbnailProvider, IVideoConverter videoConverter) { _infrastructure = infrastructure; _thumbnailProvider = thumbnailProvider; _videoConverter = videoConverter; }
private void OnThumbnailReady(IThumbnailProvider dw, ThumbnailReadyHandler callback, Surface thumb) { Pair<IThumbnailProvider, Surface> data = Pair.Create(dw, thumb); ThumbnailReadyArgs e = new ThumbnailReadyArgs(data); lock (this.thumbnailReadyInvokeList) { this.thumbnailReadyInvokeList.Add(new ThumbnailReadyEventDetails(callback, this, e)); } try { this.syncContext.BeginInvoke(new Procedure(DrainThumbnailReadyInvokeList), null); } catch (ObjectDisposedException) { // Ignore this error } catch (InvalidOperationException) { // If syncContext was destroyed, then ignore } }
public void RemoveFromQueue(IThumbnailProvider nukeMe) { lock (this.updateLock) { ThumbnailStackItem[] tsiArray = this.renderQueue.ToArray(); List<ThumbnailStackItem> tsiAccumulate = new List<ThumbnailStackItem>(); for (int i = 0; i < tsiArray.Length; ++i) { if (tsiArray[i].First != nukeMe) { tsiAccumulate.Add(tsiArray[i]); } } this.renderQueue.Clear(); for (int i = 0; i < tsiAccumulate.Count; ++i) { this.renderQueue.Push(tsiAccumulate[i]); } } }
private void OnThumbnailReady(IThumbnailProvider dw, ThumbnailReadyHandler callback, Surface thumb) { Pair<IThumbnailProvider, Surface> data = new Pair<IThumbnailProvider, Surface>(dw, thumb); ThumbnailReadyArgs e = new ThumbnailReadyArgs(data); lock (this.thumbnailReadyInvokeList) { this.thumbnailReadyInvokeList.Add(new Triple<ThumbnailReadyHandler, object, ThumbnailReadyArgs>(callback, this, e)); } try { //this.syncContext.BeginInvoke(callback, new object[] { this, e }); this.syncContext.BeginInvoke(new Procedure(DrainThumbnailReadyInvokeList), null); } catch (InvalidOperationException) { // If syncContext was destroyed, then ignore } }
public PhotoView() { InitializeComponent(); _thumbnailer = new VistaThumbnailProvider();//new BitmapImageThumbnailProvider(); }