private void SaveUploadedPin(HttpContext context) { int board = int.Parse(context.Request.Params["board"]); string desc = context.Request.Params["desc"]; string img = context.Request.Params["img"]; IHash fnv1a = HashFactory.Hash64.CreateFNV1a(); IHash crc64 = HashFactory.Checksum.CreateCRC64b(); IHash murmur2 = HashFactory.Hash64.CreateMurmur2(); Uri url = new Uri(img); string image = url.Segments.Last(); string fp = Path.Combine(Common.Temp, Common.UserID.ToString(), image); FileInfo fInfo = new FileInfo(fp); string destRel = Common.UploadedImageRelPath + Common.UserID; string dest = Common.UploadedImagePath + Common.UserID; string destFileName = Common.MoveAndRenameFileIfExists(fInfo, dest); string relPath = Common.UserID + "/" + destFileName; byte[] _d = File.ReadAllBytes(Path.Combine(dest, destFileName)); ulong _crc64; ulong _murmur2; ulong _fnv1a; short height, width; CalcHash(_d, out _crc64, out _murmur2, out _fnv1a, out height, out width); using (TransactionScope scope = new TransactionScope()) { try { Lipstick.dbml.Images i = new Lipstick.dbml.Images(); i.CRC64 = _crc64; i.MURMUR2 = _murmur2; i.FNV1a = _fnv1a; i.Image_Height = height; i.Image_Width = width; i.Uploaded = true; i.Tagged = true; i.RelativeImage_Path = relPath; this.GetLipstickContext2.Images.InsertOnSubmit(i); this.GetLipstickContext2.SubmitChanges(); Lipstick.dbml.BoardsImagesMapping bim = new Lipstick.dbml.BoardsImagesMapping(); bim.BoardID = board; bim.ImageID = i.ID; bim.Image_Title = desc; bim.UserID = Common.UserID.Value; this.GetLipstickContext2.BoardsImagesMapping.InsertOnSubmit(bim); this.GetLipstickContext2.SubmitChanges(); scope.Complete(); context.Response.Write(JsonConvert.SerializeObject(new { PinID = ((ulong)bim.ID + _crc64).ToString() })); } catch (Exception e) { throw; } finally { scope.Dispose(); } } }
private void SaveAddedPin(HttpContext context) { int board = int.Parse(context.Request.Params["board"]); string desc = context.Request.Params["desc"]; string img = context.Request.Params["img"]; string destRel = Common.UploadedImageRelPath + Common.UserID; string dest = Common.UploadedImagePath + Common.UserID; string destFileName = Guid.NewGuid().ToString() + ".jpg"; string destFileFullPath = Path.Combine(dest, destFileName); WebClient client = new WebClient(); MemoryStream ms = new MemoryStream(client.DownloadData(img)); using (Image image = Image.FromStream(ms)) { if (!Directory.Exists(dest)) Directory.CreateDirectory(dest); image.Save(destFileFullPath, ImageFormat.Jpeg); } string relPath = Common.UserID + "/" + destFileName; byte[] _d = File.ReadAllBytes(destFileFullPath); ulong _crc64; ulong _murmur2; ulong _fnv1a; short height, width; CalcHash(_d, out _crc64, out _murmur2, out _fnv1a, out height, out width); using (TransactionScope scope = new TransactionScope()) { try { Lipstick.dbml.Images i = new Lipstick.dbml.Images(); i.CRC64 = _crc64; i.MURMUR2 = _murmur2; i.Tagged = true; i.FNV1a = _fnv1a; i.Image_Height = height; i.Image_Width = width; i.Uploaded = true; i.RelativeImage_Path = relPath; Lipstick.dbml.LipstickDataContext _context = this.GetLipstickContext2; _context.Images.InsertOnSubmit(i); _context.SubmitChanges(); Lipstick.dbml.BoardsImagesMapping bim = new Lipstick.dbml.BoardsImagesMapping(); bim.BoardID = board; bim.ImageID = i.ID; bim.Image_Title = desc; bim.Source = img; bim.UserID = Common.UserID.Value; _context.BoardsImagesMapping.InsertOnSubmit(bim); _context.SubmitChanges(); scope.Complete(); context.Response.Write(JsonConvert.SerializeObject(new { PinID = (_crc64 + (ulong)bim.ID).ToString() })); } catch (Exception e) { throw; } finally { scope.Dispose(); } } }
private void SaveAddedPin(HttpContext context) { int board = int.Parse(context.Request.Params["board"]); string desc = context.Request.Params["desc"]; string img = context.Request.Params["img"]; string destRel = Common.UploadedImageRelPath + Common.UserID; string dest = Common.UploadedImagePath + Common.UserID; string destFileName = Guid.NewGuid().ToString() + ".jpg"; string destFileFullPath = Path.Combine(dest, destFileName); WebClient client = new WebClient(); MemoryStream ms = new MemoryStream(client.DownloadData(img)); using (Image image = Image.FromStream(ms)) { if (!Directory.Exists(dest)) { Directory.CreateDirectory(dest); } image.Save(destFileFullPath, ImageFormat.Jpeg); } string relPath = Common.UserID + "/" + destFileName; byte[] _d = File.ReadAllBytes(destFileFullPath); ulong _crc64; ulong _murmur2; ulong _fnv1a; short height, width; CalcHash(_d, out _crc64, out _murmur2, out _fnv1a, out height, out width); using (TransactionScope scope = new TransactionScope()) { try { Lipstick.dbml.Images i = new Lipstick.dbml.Images(); i.CRC64 = _crc64; i.MURMUR2 = _murmur2; i.Tagged = true; i.FNV1a = _fnv1a; i.Image_Height = height; i.Image_Width = width; i.Uploaded = true; i.RelativeImage_Path = relPath; Lipstick.dbml.LipstickDataContext _context = this.GetLipstickContext2; _context.Images.InsertOnSubmit(i); _context.SubmitChanges(); Lipstick.dbml.BoardsImagesMapping bim = new Lipstick.dbml.BoardsImagesMapping(); bim.BoardID = board; bim.ImageID = i.ID; bim.Image_Title = desc; bim.Source = img; bim.UserID = Common.UserID.Value; _context.BoardsImagesMapping.InsertOnSubmit(bim); _context.SubmitChanges(); scope.Complete(); context.Response.Write(JsonConvert.SerializeObject(new { PinID = (_crc64 + (ulong)bim.ID).ToString() })); } catch (Exception e) { throw; } finally { scope.Dispose(); } } }