Пример #1
0
        public void SaveImagebyUrl(Guid userId, Guid wantId, string url)
        {
            if (Guid.Empty != userId && Guid.Empty != wantId && !String.IsNullOrWhiteSpace(url))
            {
                var itemImage = new ItemRequestImageInput()
                {
                    UserIdentifier        = userId,
                    ItemRequestIdentifier = wantId,
                    FileName = url,
                };

                using (var file = imageCore.Download(url))
                {
                    itemImage.ContentType = file.ContentType;
                    using (var response = file.GetResponseStream())
                    {
                        using (var ms = new MemoryStream())
                        {
                            response.CopyTo(ms);
                            itemImage.Contents = ms.ToArray();
                        }
                    }
                }

                var result = this.imageCore.Save(itemImage);
            }
        }
Пример #2
0
        public ItemImage UploadImage()
        {
            var userId  = User.Identifier();
            var request = HttpContext.Current.Request;

            var image = new ItemRequestImageInput()
            {
                UserIdentifier        = userId,
                ItemRequestIdentifier = Guid.Parse(request.Form["Identifier"]),
            };

            if (request.Files.Count > 0)
            {
                //we are uploading the old way
                var file = request.Files[0];
                image.Contents = new byte[file.ContentLength];
                file.InputStream.Read(image.Contents, 0, file.ContentLength);
                image.ContentType = file.ContentType;
                image.FileName    = file.FileName;
            }
            else if (request.ContentLength > 0)
            {
                // Using FileAPI the content is in Request.InputStream!!!!
                image.Contents = new byte[request.ContentLength];
                request.InputStream.Read(image.Contents, 0, request.ContentLength);
                image.FileName    = request.Headers["X-File-Name"];
                image.ContentType = request.Headers["X-File-Type"];
            }

            image.FileSize = image.Contents != null ? image.Contents.Length : 0;

            return(this.imageCore.Save(image));
        }
Пример #3
0
        public void NewItemRequestImage(ItemRequestImageInput item)
        {
            var activity = new Activity()
            {
                Type                = Reference.ItemRequestImage,
                Text                = string.Format("added a photo to a request"),
                UserIdentifier      = item.UserIdentifier,
                ReferenceIdentifier = item.Identifier,
            };

            this.Save(activity);
        }
Пример #4
0
        public ItemImage Save(ItemRequestImageInput image)
        {
            var id          = Guid.NewGuid();
            var virtualPath = string.Format("request/{0}_{1}.jpg", id, "{0}");
            var sproc       = new GoodsSaveItemRequestImage()
            {
                Identifier            = id,
                ContentType           = image.ContentType,
                FileName              = image.FileName,
                FileSize              = image.FileSize,
                ItemRequestIdentifier = image.ItemRequestIdentifier,
                UserIdentifier        = image.UserIdentifier,
                Path = string.Format("/user/{0}", virtualPath),
            };

            var storedImage = sproc.CallObject <ItemRequestImageInput>();

            var container = new BinaryContainer("user");

            container.Save(string.Format(virtualPath, OriginalName), image.Contents, image.ContentType);

            var thumbnail = this.Thumbnail(image.Contents, ImageFormat.Jpeg);

            var thumbnailPath = string.Format(virtualPath, ImageCore.ThumbnailName);

            container.Save(thumbnailPath, thumbnail, contentType);

            var large = this.Large(image.Contents, ImageFormat.Jpeg);

            var largePath = string.Format(virtualPath, ImageCore.LargeName);

            container.Save(largePath, large, contentType);

            var activity = new ActivityCore();

            activity.NewItemRequestImage(storedImage);

            return(new ItemImage()
            {
                VirtualPathFormat = string.Format("/user/{0}", thumbnailPath),
            });
        }
Пример #5
0
        public ItemImage SaveImagebyUrl(PublicItemRequestImage image)
        {
            if (null == image)
            {
                throw new ArgumentNullException("image");
            }

            if (Guid.Empty == image.ItemRequestIdentifier)
            {
                throw new ArgumentException("Identifer");
            }

            var userId = User.Identifier();

            var itemImage = new ItemRequestImageInput()
            {
                UserIdentifier        = userId,
                ItemRequestIdentifier = image.ItemRequestIdentifier,
                FileName = image.Url,
            };

            using (var file = imageCore.Download(image.Url))
            {
                itemImage.ContentType = file.ContentType;
                using (var response = file.GetResponseStream())
                {
                    using (var ms = new MemoryStream())
                    {
                        response.CopyTo(ms);
                        itemImage.Contents = ms.ToArray();
                    }
                }
            }

            return(this.imageCore.Save(itemImage));
        }