private static PhotoData ResizeToBigSize(byte[] imageData, int contactID, bool uploadOnly, string tmpDirName)
        {
            var resizeWorkerItem = new ResizeWorkerItem
            {
                ContactID       = contactID,
                UploadOnly      = uploadOnly,
                RequireFotoSize = new[] { _bigSize },
                ImageData       = imageData,
                DataStore       = Global.GetStore(),
                TmpDirName      = tmpDirName
            };

            ExecResizeImage(resizeWorkerItem);

            if (!uploadOnly)
            {
                return(new PhotoData {
                    Url = FromCache(contactID, _bigSize)
                });
            }
            else if (String.IsNullOrEmpty(tmpDirName))
            {
                return(new PhotoData {
                    Url = FromDataStore(contactID, _bigSize, true, null), Path = PhotosDefaultTmpDirName
                });
            }
            else
            {
                return(FromDataStore(_bigSize, tmpDirName));
            }
        }
        private static String ResizeToBigSize(byte[] imageData, int contactID)
        {
            var resizeWorkerItem = new ResizeWorkerItem
            {
                ContactID       = contactID,
                RequireFotoSize = new[] { _bigSize },
                ImageData       = imageData,
                DataStore       = Global.GetStore()
            };

            ExecResizeImage(resizeWorkerItem);

            return(FromCache(contactID, _bigSize));
        }
Exemple #3
0
        private void ExecGenerateThumbnail(byte[] imageData, int contactID, bool uploadOnly, string tmpDirName)
        {
            var resizeWorkerItem = new ResizeWorkerItem
            {
                ContactID       = contactID,
                UploadOnly      = uploadOnly,
                RequireFotoSize = new[] { _mediumSize, _smallSize },
                ImageData       = imageData,
                DataStore       = _global.GetStore(),
                TmpDirName      = tmpDirName
            };

            if (!_resizeQueue.GetTasks <ResizeWorkerItem>().Contains(resizeWorkerItem))
            {
                //Add
                _resizeQueue.QueueTask((a, b) => ExecResizeImage(resizeWorkerItem), resizeWorkerItem);
            }
        }
        private static void ExecGenerateThumbnail(byte[] imageData, int contactID)
        {
            var resizeWorkerItem = new ResizeWorkerItem
            {
                ContactID       = contactID,
                RequireFotoSize = new[] { _mediumSize, _smallSize },
                ImageData       = imageData,
                DataStore       = Global.GetStore()
            };

            if (!ResizeQueue.GetItems().Contains(resizeWorkerItem))
            {
                ResizeQueue.Add(resizeWorkerItem);
            }

            if (!ResizeQueue.IsStarted)
            {
                ResizeQueue.Start(ExecResizeImage);
            }
        }
        private static void ExecResizeImage(ResizeWorkerItem resizeWorkerItem)
        {
            foreach (var fotoSize in resizeWorkerItem.RequireFotoSize)
            {
                var data = resizeWorkerItem.ImageData;
                using (var stream = new MemoryStream(data))
                    using (var img = new Bitmap(stream))
                    {
                        var imgFormat = img.RawFormat;
                        if (fotoSize != img.Size)
                        {
                            using (var img2 = CommonPhotoManager.DoThumbnail(img, fotoSize, false, false, false))
                            {
                                data = CommonPhotoManager.SaveToBytes(img2, Global.GetImgFormatName(imgFormat));
                            }
                        }
                        else
                        {
                            data = Global.SaveToBytes(img);
                        }

                        var fileExtension = String.Concat("." + Global.GetImgFormatName(imgFormat));

                        var photoPath = !resizeWorkerItem.UploadOnly
                                        ? BuildFilePath(resizeWorkerItem.ContactID, fotoSize, fileExtension)
                                        : BuildFileTmpPath(resizeWorkerItem.ContactID, fotoSize, fileExtension, resizeWorkerItem.TmpDirName);

                        using (var fileStream = new MemoryStream(data))
                        {
                            var photoUri = resizeWorkerItem.DataStore.Save(photoPath, fileStream).ToString();
                            photoUri = String.Format("{0}?cd={1}", photoUri, DateTime.UtcNow.Ticks);

                            if (!resizeWorkerItem.UploadOnly)
                            {
                                ToCache(resizeWorkerItem.ContactID, photoUri, fotoSize);
                            }
                        }
                    }
            }
        }
        private static void ExecGenerateThumbnail(byte[] imageData, int contactID, bool uploadOnly, string tmpDirName)
        {
            var resizeWorkerItem = new ResizeWorkerItem
                {
                    ContactID = contactID,
                    UploadOnly = uploadOnly,
                    RequireFotoSize = new[] { _mediumSize, _smallSize },
                    ImageData = imageData,
                    DataStore = Global.GetStore(),
                    TmpDirName = tmpDirName
                };

            if (!ResizeQueue.GetItems().Contains(resizeWorkerItem))
                ResizeQueue.Add(resizeWorkerItem);

            if (!ResizeQueue.IsStarted) ResizeQueue.Start(ExecResizeImage);
        }
        private static String ResizeToBigSize(byte[] imageData, int contactID, bool uploadOnly, string tmpDirName)
        {
            var resizeWorkerItem = new ResizeWorkerItem
                {
                    ContactID = contactID,
                    UploadOnly = uploadOnly,
                    RequireFotoSize = new[] { _bigSize },
                    ImageData = imageData,
                    DataStore = Global.GetStore(),
                    TmpDirName = tmpDirName
                };

            ExecResizeImage(resizeWorkerItem);

            if (!uploadOnly)
            {
                return FromCache(contactID, _bigSize);
            }
            else if (String.IsNullOrEmpty(tmpDirName))
            {
                return FromDataStore(contactID, _bigSize, true, null);
            }
            else
            {
                return FromDataStore(_bigSize, tmpDirName);
            }
        }
        private static void ExecResizeImage(ResizeWorkerItem resizeWorkerItem)
        {
            foreach (var fotoSize in resizeWorkerItem.RequireFotoSize)
            {
                var data = resizeWorkerItem.ImageData;
                using (var stream = new MemoryStream(data))
                using (var img = new Bitmap(stream))
                {
                    var imgFormat = img.RawFormat;
                    if (fotoSize != img.Size)
                    {
                        using (var img2 = DoThumbnail(img, fotoSize))
                        {
                            data = SaveToBytes(img2, imgFormat);
                        }
                    }
                    else
                    {
                        data = SaveToBytes(img);
                    }

                    var fileExtension = String.Concat("." + GetImgFormatName(ImageFormat.Jpeg));

                    var photoPath = !resizeWorkerItem.UploadOnly
                                        ? BuildFilePath(resizeWorkerItem.ContactID, fotoSize, fileExtension)
                                        : BuildFileTmpPath(resizeWorkerItem.ContactID, fotoSize, fileExtension, resizeWorkerItem.TmpDirName);

                    using (var fileStream = new MemoryStream(data))
                    {
                        var photoUri = resizeWorkerItem.DataStore.Save(photoPath, fileStream).ToString();
                        photoUri = String.Format("{0}?cd={1}", photoUri, DateTime.UtcNow.Ticks);

                        if (!resizeWorkerItem.UploadOnly)
                        {
                            ToCache(resizeWorkerItem.ContactID, photoUri, fotoSize);
                        }
                    }
                }
            }
        }