コード例 #1
0
        // Upload entire file
        private void UploadWholeFile(HttpContext context, List<FilesStatus> statuses)
        {
            // hack to see if thumbnails can be added
            //Thumbnail tn = new Thumbnail();
            //tn.Description = "medium";
            //tn.MaxWidth = 600;
            //db.Thumbnails.Add(tn);
            //db.SaveChanges();

            // in a controller we would probably use data binding
            if (context.Request.Form["uploadDestination"] != "")
            {
                // this changes value of StorageRoot
                GalleryDirectory = "~/" + context.Request.Form["uploadDestination"] + "/";
            }
            else
            {
                GalleryDirectory = "~/" + ConfigurationManager.AppSettings["uploadDestination"] + "/";
            }

            for (int i = 0; i < context.Request.Files.Count; i++)
            {
                var file = context.Request.Files[i];

                // todo, see if this is really the right approach
                var fullPath =
                    Path.Combine(StorageRoot, Path.GetFileName(file.FileName));
                // hack using the file name to access the title field via the file name
                var fileTitle = context.Request.Form[file.FileName.Replace(" ", "").Replace(".","")];

                // the file title is a description

                try
                {
                       GalleryImageProcessor ip = new GalleryImageProcessor();
                        OriginalImage img = new OriginalImage();
                        img.Filename = fullPath;
                        img.Title = fileTitle;
                        // todo, see if there are better ways of generating this url
                        img.UrlPath = GalleryDirectory + "/" + Path.GetFileName(file.FileName);
                        // todo, put this saving into the image as I had a bug where no
                        // files were saved because I omitted this step.
                        file.SaveAs(img.Filename);
                        ip.ProcessPostUpload(img);

                        string fullName = Path.GetFileName(file.FileName);
                        statuses.Add(new FilesStatus(fullName, file.ContentLength, fullPath));
                }
                catch (Exception e)
                {
                    // todo, find out how to report the error to the web page
                    context.Response.Write("<p>Exception " + e.Message + "</p>" );

                }
            }
        }
コード例 #2
0
        public void TestImageProcessor()
        {
            var ip = new GalleryImageProcessor();
            OriginalImage img = new OriginalImage();
            img.Filename = @"C:\Users\Ken\Documents\GitHub\SimplePhotoGallery\SimplePhotoGallery\Galleries\Canon1IMG_0050.JPG";
            img.Title = "Renee smiling";
            ip.ProcessPostUpload(img);

            // now we should test that we have four thumbnails:
            // large, medium, small and tiny
            GalleryContext db = new GalleryContext();

            var originalImage = db.Images.ToList();
                        // .Where(b => b.Title.Contains("James")).ToList();

            /*
                        .FirstOrDefault();
             *                         .Include("ProcessedImages")

            */

            foreach (var processedImage in originalImage)
            {
                var fn = processedImage.Filename;
            }
        }