public void SaveImage(ImageStorageInfo storageInfo, int numberOfChunks, string thumbnail) { var recordPath = Path.Combine(Properties.Settings.Default.ImagesDir, "record.xml"); var record = new Record(); if (File.Exists(recordPath)) { record = XmlFileSerializer.Deserialize <Record>(recordPath); } var images = record.Images?.ToList() ?? new List <Image>(); images.Add(new Image { CreatedAt = storageInfo.CreatedAt, DirectoryName = storageInfo.DirectoryName, NumberOfChunks = numberOfChunks, Thumbnail = thumbnail }); record.Images = images.ToArray(); XmlFileSerializer.Serialize(record, recordPath); }
public IEnumerable <ImageListItem> GetImages() { var recordPath = Path.Combine(Properties.Settings.Default.ImagesDir, "record.xml"); var record = XmlFileSerializer.Deserialize <Record>(recordPath); return(record.Images.OrderByDescending(x => x.CreatedAt).Select(x => new ImageListItem { CreatedAt = x.CreatedAt, DirectoryName = x.DirectoryName, Thumbnail = !string.IsNullOrEmpty(x.Thumbnail) ? Convert.FromBase64String(x.Thumbnail) : null })); }
public void RemoveDir(string dir) { var path = Path.Combine(Properties.Settings.Default.ImagesDir, dir); Directory.Delete(path, true); var recordPath = Path.Combine(Properties.Settings.Default.ImagesDir, "record.xml"); var record = XmlFileSerializer.Deserialize <Record>(recordPath); var images = record.Images.Where(x => x.DirectoryName != dir).ToArray(); record.Images = images; XmlFileSerializer.Serialize(record, recordPath); }
public StrollerImageObject GetImageJson(string dirName) { var path = Path.Combine(Properties.Settings.Default.ImagesDir, dirName); var recordPath = Path.Combine(Properties.Settings.Default.ImagesDir, "record.xml"); var record = XmlFileSerializer.Deserialize <Record>(recordPath); var imageInfo = record.Images.First(x => x.DirectoryName == dirName); var obj = new StrollerImageObject { CreatedAt = imageInfo.CreatedAt, Thumbnail = "data:image/jpeg;base64," + imageInfo.Thumbnail }; var files = Directory.GetFiles(path, "*.jpg"); var chunks = new List <StrollerChunkItem>(); foreach (var file in files) { var index = int.Parse(Path.GetFileNameWithoutExtension(file)); string chunkString; using (var fs = File.Open(file, FileMode.Open, FileAccess.Read)) { var buff = new byte[fs.Length]; fs.Read(buff, 0, buff.Length); chunkString = Convert.ToBase64String(buff); } chunks.Add(new StrollerChunkItem { Image = "data:image/jpeg;base64," + chunkString, Index = index }); } obj.Chunks = chunks.ToArray(); return(obj); }