Exemple #1
0
        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
                {
                    EyeShadow.dbml.Images i = new EyeShadow.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.GetEyeShadowContext2.Images.InsertOnSubmit(i);
                    this.GetEyeShadowContext2.SubmitChanges();
                    EyeShadow.dbml.BoardsImagesMapping bim = new EyeShadow.dbml.BoardsImagesMapping();
                    bim.BoardID     = board;
                    bim.ImageID     = i.ID;
                    bim.Image_Title = desc;
                    bim.UserID      = Common.UserID.Value;
                    this.GetEyeShadowContext2.BoardsImagesMapping.InsertOnSubmit(bim);
                    this.GetEyeShadowContext2.SubmitChanges();
                    scope.Complete();
                    context.Response.Write(JsonConvert.SerializeObject(new { PinID = ((ulong)bim.ID + _crc64).ToString() }));
                }
                catch (Exception e)
                {
                    throw;
                }
                finally
                {
                    scope.Dispose();
                }
            }
        }
Exemple #2
0
        private void SaveRepin(HttpContext context)
        {
            int    id     = int.Parse(context.Request.Params["id"]);
            int    board  = int.Parse(context.Request.Params["board"]);
            string desc   = context.Request.Params["desc"];
            string source = context.Request.Params["source"];

            EyeShadow.dbml.BoardsImagesMapping bim = new EyeShadow.dbml.BoardsImagesMapping();
            bim.ImageID     = id;
            bim.Source      = source;
            bim.Image_Title = desc;
            bim.UserID      = Common.UserID;
            bim.BoardID     = board;
            this.GetEyeShadowContext2.BoardsImagesMapping.InsertOnSubmit(bim);
            this.GetEyeShadowContext2.SubmitChanges();
        }
Exemple #3
0
 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
         {
             EyeShadow.dbml.Images i = new EyeShadow.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.GetEyeShadowContext2.Images.InsertOnSubmit(i);
             this.GetEyeShadowContext2.SubmitChanges();
             EyeShadow.dbml.BoardsImagesMapping bim = new EyeShadow.dbml.BoardsImagesMapping();
             bim.BoardID = board;
             bim.ImageID = i.ID;
             bim.Image_Title = desc;
             bim.UserID = Common.UserID.Value;
             this.GetEyeShadowContext2.BoardsImagesMapping.InsertOnSubmit(bim);
             this.GetEyeShadowContext2.SubmitChanges();
             scope.Complete();
             context.Response.Write(JsonConvert.SerializeObject(new { PinID = ((ulong)bim.ID + _crc64).ToString() }));
         }
         catch (Exception e)
         {
             throw;
         }
         finally
         {
             scope.Dispose();
         }
     }
 }
Exemple #4
0
 private void SaveRepin(HttpContext context)
 {
     int id = int.Parse(context.Request.Params["id"]);
     int board = int.Parse(context.Request.Params["board"]);
     string desc = context.Request.Params["desc"];
     string source = context.Request.Params["source"];
     EyeShadow.dbml.BoardsImagesMapping bim = new EyeShadow.dbml.BoardsImagesMapping();
     bim.ImageID = id;
     bim.Source = source;
     bim.Image_Title = desc;
     bim.UserID = Common.UserID;
     bim.BoardID = board;
     this.GetEyeShadowContext2.BoardsImagesMapping.InsertOnSubmit(bim);
     this.GetEyeShadowContext2.SubmitChanges();
 }
Exemple #5
0
 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
         {
             EyeShadow.dbml.Images i = new EyeShadow.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;
             EyeShadow.dbml.EyeShadowDataContext _context = this.GetEyeShadowContext2;
             _context.Images.InsertOnSubmit(i);
             _context.SubmitChanges();
             EyeShadow.dbml.BoardsImagesMapping bim = new EyeShadow.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();
         }
     }
 }
Exemple #6
0
        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
                {
                    EyeShadow.dbml.Images i = new EyeShadow.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;
                    EyeShadow.dbml.EyeShadowDataContext _context = this.GetEyeShadowContext2;
                    _context.Images.InsertOnSubmit(i);
                    _context.SubmitChanges();
                    EyeShadow.dbml.BoardsImagesMapping bim = new EyeShadow.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();
                }
            }
        }