public ThumbnailManager(ThumbnailRepository thumbnailRepository, FileManager fileManager, ImageManager imageManager)
        {
            _thumbnailRepository = thumbnailRepository;
            _fileManager         = fileManager;
            _imageManager        = imageManager;

            _fileNameRegExp = new Regex(ImageSearchPattern, RegexOptions.IgnoreCase);
        }
Esempio n. 2
0
        public RESPONSE_LOADTHUMBNAIL LoadThumbnail(REQUEST_LOADTHUMBNAIL reqparam)
        {
            var rsp = new RESPONSE_LOADTHUMBNAIL();

            using (var tdbc = new ThumbDbContext())
            {
                var repo = new ThumbnailRepository(tdbc);

                var thumb = repo.FindFromKey(reqparam.ThumbnailKey).FirstOrDefault();
                if (thumb != null)
                {
                    LOG.InfoFormat("サムネイルの送信={0}", thumb.BitmapBytes.Count());
                    rsp.ThumbnailBytes = thumb.BitmapBytes;
                }
            }
            rsp.Success = true;
            return(rsp);
        }
Esempio n. 3
0
        public bool RemoveThumbnail(string thumbnailhash)
        {
            bool bResult = false;

            using (var dbc = new ThumbDbContext())
            {
                var repo   = new ThumbnailRepository(dbc);
                var thumbs = repo.FindFromKey(thumbnailhash);

                foreach (var prop in thumbs)
                {
                    repo.Delete(prop);
                }
                bResult = true;
            }

            return(bResult);
        }
Esempio n. 4
0
            /// <summary>
            /// サムネイルを生成します
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="args"></param>
            public void Do(object sender, DoWorkEventArgs args)
            {
                try
                {
                    // バイナリに出力
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        PngBitmapEncoder encoder = new PngBitmapEncoder();
                        var frame = BitmapFrame.Create((BitmapImage)this._ImageSource);
                        encoder.Frames.Add(frame);
                        encoder.Save(memoryStream);

                        using (var dbc = new ThumbDbContext())
                        {
                            var repo = new ThumbnailRepository(dbc);

                            if (string.IsNullOrEmpty(_rebuildThumbnailKey))
                            {
                                string key = null;
                                while (key == null)
                                {
                                    var tal = RandomAlphameric.RandomAlphanumeric(20);
                                    var r   = repo.FindFromKey(tal);
                                    if (r.Count == 0)
                                    {
                                        key = tal;
                                    }
                                    foreach (var p in r)
                                    {
                                        if (p.ThumbnailType != _ThumbnailType)
                                        {
                                            key = tal;
                                        }
                                    }
                                }

                                var thumbnail = new Thumbnail();
                                thumbnail.ThumbnailKey  = key;
                                thumbnail.ThumbnailType = _ThumbnailType;
                                thumbnail.BitmapBytes   = memoryStream.ToArray();

                                repo.Add(thumbnail);

                                _ThumbnailKey = key;
                            }
                            else
                            {
                                var thumbnail = repo.FindFromKey(_rebuildThumbnailKey);

                                // サムネイルタイプのエンティティが存在する場合、trueをセットする。
                                bool isThumbnailSave = false;
                                foreach (var prop in thumbnail)
                                {
                                    if (prop.ThumbnailType == _ThumbnailType)
                                    {
                                        prop.BitmapBytes = memoryStream.ToArray();
                                        isThumbnailSave  = true;
                                    }
                                }

                                if (!isThumbnailSave)
                                {
                                    // 指定したサムネイルタイプのエンティティを、
                                    // 新規作成する。
                                    var thumbnail_NewThumbnailType = new Thumbnail();
                                    thumbnail_NewThumbnailType.ThumbnailKey  = _rebuildThumbnailKey;
                                    thumbnail_NewThumbnailType.ThumbnailType = _ThumbnailType;
                                    thumbnail_NewThumbnailType.BitmapBytes   = memoryStream.ToArray();
                                    repo.Add(thumbnail_NewThumbnailType);
                                    _ThumbnailKey = _rebuildThumbnailKey;
                                }
                                else
                                {
                                    _ThumbnailKey = _rebuildThumbnailKey;
                                }
                            }
                            dbc.SaveChanges();
                        }
                    }
                }
                catch (NotSupportedException expr)
                {
                    LOG.WarnFormat(expr.Message);
                }
            }
 public BasicDataController(ArticleApiClient articleClient, ThumbnailRepository thumbnailRepository)
 {
     _articleClient       = articleClient;
     _thumbnailRepository = thumbnailRepository;
 }