Ejemplo n.º 1
0
        public async void UpdateInfo(DbMediaFile file)
        {
            m_smtControl.DisplayUpdater.Type = MediaPlaybackType.Music;
            m_smtControl.DisplayUpdater.MusicProperties.Title       = file.Title;
            m_smtControl.DisplayUpdater.MusicProperties.AlbumArtist = file.AlbumArtist;
            m_smtControl.DisplayUpdater.MusicProperties.AlbumTitle  = file.Album;
            m_smtControl.DisplayUpdater.MusicProperties.Artist      = file.Artist;
            try
            {
                var coverStream = await ThumbnailCache.RetrieveStorageFileAsStreamAsync(
                    await StorageFile.GetFileFromPathAsync(file.Path), true);

                if (coverStream != null)
                {
                    using (coverStream)
                    {
                        m_smtControl.DisplayUpdater.Thumbnail =
                            RandomAccessStreamReference.CreateFromStream(coverStream);
                        m_smtControl.DisplayUpdater.Update();
                        return;
                    }
                }
            }
            catch { }

            if (m_defaultPicture == null)
            {
                var coverPath = Path.Combine(
                    Package.Current.InstalledLocation.Path, "Assets", "DefaultCover.png");
                m_defaultPicture = RandomAccessStreamReference.CreateFromFile(
                    await StorageFile.GetFileFromPathAsync(coverPath));
            }
            m_smtControl.DisplayUpdater.Thumbnail = m_defaultPicture;
            m_smtControl.DisplayUpdater.Update();
        }
 public MovieViewModel(Movie movie, ThumbnailCache thumbnailCache)
 {
     _thumbnailId    = movie.ThumbnailId;
     _thumbnailCache = thumbnailCache;
     Id   = movie.Id;
     Name = movie.Name;
     // copy other property values across
 }
Ejemplo n.º 3
0
 public HttpServer(Int32 HTTP_Port, String HTTP_ListeningIP, String HTTP_DocumentRoot, ConsoleOutputLogger Logger)
 {
     HTTPServer_Port         = HTTP_Port;
     HTTPServer_ListeningIP  = HTTP_ListeningIP;
     HTTPServer_DocumentRoot = HTTP_DocumentRoot;
     ConsoleOutputLogger     = Logger;
     ThumbCache = new ThumbnailCache(GalleryServer.Properties.Settings.Default.CacheImages);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Each HTTP processor object handles one client.  If Keep-Alive is enabled then this
 /// object will be reused for subsequent requests until the client breaks keep-alive.
 /// This usually happens when it times out.  Because this could easily lead to a DoS
 /// attack, we keep track of the number of open processors and only allow 100 to be
 /// persistent active at any one time.  Additionally, we do not allow more than 500
 /// outstanding requests.
 /// </summary>
 /// <param name="docRoot">Root-Directory of the HTTP Server</param>
 /// <param name="s">the Socket to work with</param>
 /// <param name="webserver">the "master" HttpServer Object of this Client</param>
 public HttpProcessor(Socket s, String HTTP_DocumentRoot, ConsoleOutputLogger Logger, ThumbnailCache Thumb_Cache)
 {
     this.s = s;
     HTTPServer_DocumentRoot = HTTP_DocumentRoot;
     docRootFile             = new FileInfo(HTTPServer_DocumentRoot);
     headers             = new Hashtable();
     ConsoleOutputLogger = Logger;
     FileManager         = new FileManagement();
     ThumbCache          = Thumb_Cache;
 }
Ejemplo n.º 5
0
        public Image GetIcon(string material)
        {
            string path;

            mMaterialImages.TryGetValue(material, out path);
            if (path != null)
            {
                return(ThumbnailCache.GetThumbnail(path));
            }

            return(null);
        }
Ejemplo n.º 6
0
        public PictureDisplay(  )
            : base()
        {
            InitializeComponent();

            this.thumbnailsCacheActive = Settings.Default.LoadThumbnailsInBackground;
            this.rotatePreview         = Settings.Default.RotatePreview;

            this.thumbnails = new ThumbnailCache();

            Settings.Default.PropertyChanged += Settings_PropertyChanged;
        }
Ejemplo n.º 7
0
 private static byte[] GetThumbnailCache(Guid SiteId, Guid HashId)
 {
     if (ThumbnailCache.ContainsKey(SiteId))
     {
         var list = ThumbnailCache[SiteId];
         if (list.ContainsKey(HashId))
         {
             return(list[HashId]);
         }
     }
     return(null);
 }
Ejemplo n.º 8
0
    private async ValueTask <ThumbnailGeneratorGetThumbnailResult> GetPictureThumbnailAsync(NestedPath filePath, ThumbnailGeneratorGetThumbnailOptions options, CancellationToken cancellationToken = default)
    {
        var ext = filePath.GetExtension().ToLower();

        if (!_pictureTypeExtensionList.Contains(ext))
        {
            return(new ThumbnailGeneratorGetThumbnailResult(ThumbnailGeneratorGetThumbnailResultStatus.Failed));
        }

        try
        {
            var fileLength = await _fileSystem.GetFileSizeAsync(filePath, cancellationToken);

            var fileLastWriteTime = await _fileSystem.GetFileLastWriteTimeAsync(filePath, cancellationToken);

            using (var inStream = await _fileSystem.GetFileStreamAsync(filePath, cancellationToken))
                using (var outStream = new RecyclableMemoryStream(_bytesPool))
                {
                    this.ConvertImage(inStream, outStream, options.Width, options.Height, options.ResizeType, options.FormatType);
                    outStream.Seek(0, SeekOrigin.Begin);

                    var image = outStream.ToMemoryOwner();

                    var fileMeta      = new FileMeta(filePath, (ulong)fileLength, Timestamp.FromDateTime(fileLastWriteTime));
                    var thumbnailMeta = new ThumbnailMeta(options.ResizeType, options.FormatType, (uint)options.Width, (uint)options.Height);
                    var content       = new ThumbnailContent(image);
                    var cache         = new ThumbnailCache(fileMeta, thumbnailMeta, new[] { content });

                    await _thumbnailGeneratorRepository.ThumbnailCaches.InsertAsync(cache);

                    return(new ThumbnailGeneratorGetThumbnailResult(ThumbnailGeneratorGetThumbnailResultStatus.Succeeded, cache.Contents));
                }
        }
        catch (NotSupportedException e)
        {
            _logger.Warn(e);
        }
        catch (OperationCanceledException e)
        {
            _logger.Debug(e);
        }
        catch (Exception e)
        {
            _logger.Error(e);
            throw;
        }

        return(new ThumbnailGeneratorGetThumbnailResult(ThumbnailGeneratorGetThumbnailResultStatus.Failed));
    }
Ejemplo n.º 9
0
 public void ReloadImage()
 {
     if (FileEntry.Extension == ".blp")
     {
         LoadImage(FileEntry);
     }
     else if (FileEntry.Extension == ".m2")
     {
         PreviewImage.Source = WpfImageSource.FromGdiImage(ThumbnailCache.TryGetThumbnail(FileEntry.FullPath, Images.Page_Icon_48));
     }
     else
     {
         PreviewImage.Source = PageImageSource;
     }
 }
Ejemplo n.º 10
0
 private static void SetThumbnailCache(Guid SiteId, Guid HashId, byte[] thumbnail)
 {
     lock (_locker)
     {
         Dictionary <Guid, byte[]> sitecache;
         if (ThumbnailCache.ContainsKey(SiteId))
         {
             sitecache         = ThumbnailCache[SiteId];
             sitecache[HashId] = thumbnail;
         }
         else
         {
             sitecache = new Dictionary <Guid, byte[]>();
             ThumbnailCache[SiteId] = sitecache;
             sitecache[HashId]      = thumbnail;
         }
     }
 }
        public async ValueTask InsertAsync(ThumbnailCache entity)
        {
            await Task.Delay(1).ConfigureAwait(false);

            using (await _asyncLock.LockAsync())
            {
                var id = new ThumbnailCacheIdEntity()
                {
                    FilePath            = NestedPathEntity.Import(entity.FileMeta.Path),
                    ThumbnailWidth      = (int)entity.ThumbnailMeta.Width,
                    ThumbnailHeight     = (int)entity.ThumbnailMeta.Height,
                    ThumbnailResizeType = entity.ThumbnailMeta.ResizeType,
                    ThumbnailFormatType = entity.ThumbnailMeta.FormatType,
                };
                var storage = this.GetStorage();

                if (!_database.BeginTrans())
                {
                    _logger.Error("current thread already in a transaction");
                    throw new Exception();
                }

                try
                {
                    using (var outStream = storage.OpenWrite(id, "-"))
                    {
                        RocketMessage.ToStream(entity, outStream);
                    }

                    if (!_database.Commit())
                    {
                        _logger.Error("failed to commit");
                        throw new Exception();
                    }
                }
                catch (Exception e)
                {
                    _logger.Debug(e);
                    _database.Rollback();
                }
            }
        }
Ejemplo n.º 12
0
    private async ValueTask <ThumbnailGeneratorGetThumbnailResult> GetMovieThumbnailAsync(NestedPath filePath, ThumbnailGeneratorGetThumbnailOptions options, CancellationToken cancellationToken = default)
    {
        if (!_movieTypeExtensionList.Contains(filePath.GetExtension().ToLower()))
        {
            return(new ThumbnailGeneratorGetThumbnailResult(ThumbnailGeneratorGetThumbnailResultStatus.Failed));
        }

        try
        {
            var fileLength = await _fileSystem.GetFileSizeAsync(filePath, cancellationToken);

            var fileLastWriteTime = await _fileSystem.GetFileLastWriteTimeAsync(filePath, cancellationToken);

            var images = await this.GetMovieImagesAsync(filePath, options.MinInterval, options.MaxImageCount, options.Width, options.Height, options.ResizeType, options.FormatType, cancellationToken).ConfigureAwait(false);

            var fileMeta      = new FileMeta(filePath, (ulong)fileLength, Timestamp.FromDateTime(fileLastWriteTime));
            var thumbnailMeta = new ThumbnailMeta(options.ResizeType, options.FormatType, (uint)options.Width, (uint)options.Height);
            var contents      = images.Select(n => new ThumbnailContent(n)).ToArray();
            var cache         = new ThumbnailCache(fileMeta, thumbnailMeta, contents);

            await _thumbnailGeneratorRepository.ThumbnailCaches.InsertAsync(cache);

            return(new ThumbnailGeneratorGetThumbnailResult(ThumbnailGeneratorGetThumbnailResultStatus.Succeeded, cache.Contents));
        }
        catch (NotSupportedException e)
        {
            _logger.Warn(e);
        }
        catch (OperationCanceledException e)
        {
            _logger.Debug(e);
        }
        catch (Exception e)
        {
            _logger.Error(e);
            throw;
        }

        return(new ThumbnailGeneratorGetThumbnailResult(ThumbnailGeneratorGetThumbnailResultStatus.Failed));
    }
Ejemplo n.º 13
0
        public Image GetIcon(JsonFileData jsonFileData)
        {
            foreach (KeyValuePair <string, FileData> kv in jsonFileData.LinkedFileData)
            {
                FileData fileData = kv.Value;
                string   path     = "";
                if (fileData is JsonFileData)
                {
                    path = (fileData as JsonFileData).GetImageForFile();
                }
                else if (fileData is ImageFileData)
                {
                    path = fileData.Path;
                }

                if (path != "" && System.IO.File.Exists(path))
                {
                    return(ThumbnailCache.GetThumbnail(path));
                }
            }

            return(null);
        }
Ejemplo n.º 14
0
        private void UpdateItems(bool directoryChanged = false)
        {
            if (mCurrentDirectory == null)
            {
                mBrowser.SelectedFilesListView.ItemsSource = new object[0];
                return;
            }

            var files =
                mCurrentDirectory.Files.Select(
                    f => new AssetBrowserFilePreviewElement {
                View = new AssetBrowserFilePreview(f)
            }).ToList();
            var elements = files.Where(f =>
            {
                string[] known = new string[] { "m2", "blp", "wmo" };

                var ext = f.View.FileEntry.Extension.ToLowerInvariant();
                if (ext.Contains("blp") && mShowTextures == false)
                {
                    return(false);
                }

                if (ext.Contains("m2") && mShowModels == false)
                {
                    return(false);
                }

                if (f.View.FileEntry.Name.ToLowerInvariant().Contains("_s.blp") && mShowSpecularTextures == false)
                {
                    return(false);
                }

                if (f.View.FileEntry.Name.ToLowerInvariant().Contains("_h.blp") && mShowSpecularTextures == false)
                {
                    return(false);
                }

                if (!known.Contains(ext.TrimStart('.')) && mHideUnknown)
                {
                    return(false);
                }

                return(true);
            }).ToList();

            if (directoryChanged == false && mCurFiles.Count() == elements.Count())
            {
                return;
            }

            mFullElements = files;

            mCurFiles.Clear();
            foreach (var elem in elements)
            {
                mCurFiles.Add(elem);

                if (elem.View.FileEntry.Extension.Contains("m2"))
                {
                    if (!ThumbnailCache.IsCached(elem.View.FileEntry.FullPath))
                    {
                        mThumbCapture.AddModel(elem.View.FileEntry.FullPath);
                    }
                }
            }
        }