Jury-rig


Software Engineering, a personal journey

Litedb, my gallery and document databases

Every good site has some form of gallery and I have a love of Graphic Design and lots of example to share

So a gallery was an inevitability that when I got round to engineering a site it would include one. We all love trying new technology and the first time I came across litedb http://www.litedb.org I knew it was worth using but what could it be used for. As soon as I started planning jury-rig litedb was pressed into service.
Here's the view controller:
    public class GalleryController : Controller
    {
        [HttpGet]
        /// <summary>
        /// Displays a default view and sends an image list object within the biew model.
        /// </summary>
        public ActionResult Index()
        {
            var model = new GalleryModel() {Images = FileStoreManipulation.ImageList(ImageDirectory.Gallery)};
            return View(model);
        }
}

And the method used to create the image list:
    public class FileStoreManipulation
    {
        public static List<string> ImageList(string DirectoryName)
        {
            var listed = new List<string>();
            using (var db = new LiteDatabase(DbConnectionString.FileStoreLocation))
            {
                var files = db.FileStorage.Find(DirectoryName);
                listed.AddRange(files.Select(str => str.Id));
                return listed;
            }
        }
}

Inserting the images into the file store required a method like the one below:
        public static void DocumentdbImageFileUpLoad()
        {
            using (var db = new LiteDatabase(stringtodb))
            {
                var path = @"C:\Users\";
                var filePaths = Directory.GetFiles(path, "*.jpg", SearchOption.AllDirectories);
                var list = new List<string>();
                list.AddRange(filePaths);
                foreach (var file in list)
                {
                    var ext = Path.GetExtension(file);
                    var name = "$/ImageFileLocation/";
                    db.FileStorage.Upload(name + Guid.NewGuid() + ext, file);
                }
            }
        }


Comments



Have your say

Author:

Comment here (140 chars only)*:

Email address: