Exemplo n.º 1
0
        private void ResizeAllImages()
        {
            try
            {
                Photo[] _AllPhotos = new Photo().GetAllPhotos();

                List <ImageResizeDimension> _Dimensions    = new List <ImageResizeDimension>();
                ImageResizeDimension        _EachDimension = new ImageResizeDimension();

                foreach (var EachPhoto in _AllPhotos)
                {
                    _Dimensions = new List <ImageResizeDimension>();

                    _EachDimension = new ImageResizeDimension();
                    _EachDimension.CropAndProceed = true;
                    _EachDimension.CropX          = EachPhoto.PhotoCropDetails.XPosition;
                    _EachDimension.CropY          = EachPhoto.PhotoCropDetails.YPosition;
                    _EachDimension.CropWidth      = EachPhoto.PhotoCropDetails.XWidth;
                    _EachDimension.CropHeight     = EachPhoto.PhotoCropDetails.YWidth;

                    _EachDimension.Width  = Convert.ToInt32(ConfigurationManager.AppSettings["PCT"]);
                    _EachDimension.Height = Convert.ToInt32(ConfigurationManager.AppSettings["PCT"]);
                    _EachDimension.Title  = "PCT";
                    _Dimensions.Add(_EachDimension);


                    _EachDimension = new ImageResizeDimension();
                    _EachDimension.CropAndProceed = false;
                    _EachDimension.Title          = "PCGT";
                    _EachDimension.Width          = Convert.ToInt32(ConfigurationManager.AppSettings["PCGT"]);
                    _EachDimension.Height         = 0;
                    _Dimensions.Add(_EachDimension);

                    string _Path = ConfigurationManager.AppSettings["PhotosRootPath"].ToString() + EachPhoto.PhotoPath;
                    new ImageResizeQueue().EnqueImage(_Path, _Dimensions.ToArray());
                }
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            UploadResponse m_UploadResponse = new UploadResponse {
                ResponseCode = 0, UploadPath = "", ErrorMessage = ""
            };
            string _ResponseJson = JsonConvert.SerializeObject(m_UploadResponse);

            try
            {
                int UserID = Convert.ToInt32(HttpContext.Current.User.Identity.Name);

                Response.Clear();
                Response.ContentType = "text/json";

                // Get the user id
                if (HttpContext.Current.User.Identity.Name == "")
                {
                    Response.Write(_ResponseJson);
                    return;
                }

                int _UserID = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
                if (Request.Files.Count > 0)
                {
                    HttpPostedFile m_PostedFile   = Request.Files[0];
                    string         _FilePath      = _UserID.ToString() + "\\" + DateTime.Now.ToString("ddMMyyhhmmss") + GetFileName(m_PostedFile.FileName.Split('.')[0]);
                    string         _RootDirectory = ConfigurationManager.AppSettings["PhotosRootPath"].ToString();
                    string         _UserDirectory = _RootDirectory + "\\" + _UserID.ToString();

                    if (!Directory.Exists(_UserDirectory))
                    {
                        Directory.CreateDirectory(_UserDirectory);
                    }

                    // Save the original photo
                    m_PostedFile.SaveAs(_RootDirectory + _FilePath + GetExtension(m_PostedFile.FileName));

                    FileInfo f         = new FileInfo(_RootDirectory + _FilePath + GetExtension(m_PostedFile.FileName));
                    long     PhotoSize = f.Length;

                    int PhotoWidth  = 0;
                    int PhotoHeight = 0;
                    using (Bitmap _Temp = new Bitmap(_RootDirectory + _FilePath + GetExtension(m_PostedFile.FileName)))
                    {
                        PhotoWidth  = _Temp.Width;
                        PhotoHeight = _Temp.Height;
                    }


                    PhotoCrop _PhotoCrop = new PhotoCrop();
                    // Get the crop dimensions
                    if (Request.QueryString["crop"] != null)
                    {
                        _PhotoCrop = new PhotoCrop
                        {
                            XPosition = Convert.ToInt32(Request.QueryString["X1"].ToString()),
                            YPosition = Convert.ToInt32(Request.QueryString["Y1"].ToString()),
                            XWidth    = Convert.ToInt32(Request.QueryString["X2"].ToString()),
                            YWidth    = Convert.ToInt32(Request.QueryString["Y2"].ToString())
                        };
                    }

                    // Submit details
                    Photo m_PhotoDetails = new Photo().SavePhoto(UserID, _FilePath + GetExtension(m_PostedFile.FileName), PhotoSize, PhotoWidth, PhotoHeight, "", (_PhotoCrop.XWidth != 0), _PhotoCrop);

                    List <ImageResizeDimension> _Dimensions = new List <ImageResizeDimension>();

                    ImageResizeDimension _EachDimension = new ImageResizeDimension();
                    _EachDimension.CropAndProceed = true;
                    _EachDimension.CropX          = _PhotoCrop.XPosition;
                    _EachDimension.CropY          = _PhotoCrop.YPosition;
                    _EachDimension.CropWidth      = _PhotoCrop.XWidth;
                    _EachDimension.CropHeight     = _PhotoCrop.YWidth;
                    _EachDimension.Title          = "PCT";
                    _EachDimension.Width          = Convert.ToInt32(ConfigurationManager.AppSettings["PCT"]);
                    _EachDimension.Height         = Convert.ToInt32(ConfigurationManager.AppSettings["PCT"]);
                    _Dimensions.Add(_EachDimension);

                    _EachDimension = new ImageResizeDimension();
                    _EachDimension.CropAndProceed = false;
                    _EachDimension.Width          = Convert.ToInt32(ConfigurationManager.AppSettings["PCGT"]);
                    _EachDimension.Height         = 0;
                    _EachDimension.Title          = "PCGT";
                    _Dimensions.Add(_EachDimension);

                    new ImageResizeQueue().EnqueImage(_RootDirectory + _FilePath + GetExtension(m_PostedFile.FileName), _Dimensions.ToArray());

                    if (m_PhotoDetails == null)
                    {
                        m_UploadResponse = new UploadResponse {
                            ResponseCode = 0, UploadPath = "", ErrorMessage = "we can't upload more then 15 photos"
                        };
                    }
                    else
                    {
                        m_UploadResponse = new UploadResponse {
                            ResponseCode = 1, UploadPath = _FilePath + GetExtension(m_PostedFile.FileName), ErrorMessage = ""
                        };
                    }
                    _ResponseJson = JsonConvert.SerializeObject(m_UploadResponse);
                    Response.Write(_ResponseJson);
                }
            }
            catch (Exception ex)
            {
                m_UploadResponse = new UploadResponse {
                    ResponseCode = 0, UploadPath = "", ErrorMessage = ex.Message
                };
                _ResponseJson = JsonConvert.SerializeObject(m_UploadResponse);
                Response.Write(_ResponseJson);
            }
        }
Exemplo n.º 3
0
        void _Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            try
            {
                int    UserID         = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
                string _FileName      = Request.Form["PhotoFileName"].ToString();
                string _RootDirectory = ConfigurationManager.AppSettings["PhotosRootPath"].ToString();
                string _UserDirectory = _RootDirectory + "\\" + UserID.ToString();


                FileInfo f         = new FileInfo(_RootDirectory + _FilePath);
                long     PhotoSize = f.Length;

                int PhotoWidth  = 0;
                int PhotoHeight = 0;
                using (Bitmap _Temp = new Bitmap(_RootDirectory + _FilePath))
                {
                    PhotoWidth  = _Temp.Width;
                    PhotoHeight = _Temp.Height;
                }

                PhotoCrop _PhotoCrop = new PhotoCrop();
                if (Request.QueryString["crop"] != null)
                {
                    _PhotoCrop = new PhotoCrop
                    {
                        XPosition = Convert.ToInt32(Request.QueryString["X1"].ToString()),
                        YPosition = Convert.ToInt32(Request.QueryString["Y1"].ToString()),
                        XWidth    = Convert.ToInt32(Request.QueryString["X2"].ToString()),
                        YWidth    = Convert.ToInt32(Request.QueryString["Y2"].ToString())
                    };
                }

                if (Request.Form["IsDefaultPhoto"] != null)
                {
                    bool _IsDefaultPhoto = Convert.ToBoolean(Request.Form["IsDefaultPhoto"]);
                    new Photo().SavePhoto(UserID, _FilePath, PhotoSize, PhotoWidth, PhotoHeight, "", _IsDefaultPhoto, _PhotoCrop);
                }
                else
                {
                    // Submit details
                    new Photo().SavePhoto(UserID, _FilePath, PhotoSize, PhotoWidth, PhotoHeight, "", true, _PhotoCrop);
                }

                List <ImageResizeDimension> _Dimensions = new List <ImageResizeDimension>();

                ImageResizeDimension _EachDimension = new ImageResizeDimension();
                _EachDimension.CropAndProceed = true;
                _EachDimension.CropX          = _PhotoCrop.XPosition;
                _EachDimension.CropY          = _PhotoCrop.YPosition;
                _EachDimension.CropWidth      = _PhotoCrop.XWidth;
                _EachDimension.CropHeight     = _PhotoCrop.YWidth;
                _EachDimension.Title          = "PCT";
                _EachDimension.Width          = Convert.ToInt32(ConfigurationManager.AppSettings["PCT"]);
                _EachDimension.Height         = Convert.ToInt32(ConfigurationManager.AppSettings["PCT"]);
                _Dimensions.Add(_EachDimension);

                _EachDimension = new ImageResizeDimension();
                _EachDimension.CropAndProceed = false;
                _EachDimension.Width          = Convert.ToInt32(ConfigurationManager.AppSettings["PCGT"]);
                _EachDimension.Height         = 0;
                _EachDimension.Title          = "PCGT";
                _Dimensions.Add(_EachDimension);


                new ImageResizeQueue().EnqueImage(_RootDirectory + _FilePath, _Dimensions.ToArray());

                UploadResponse m_UploadResponse = new UploadResponse {
                    ResponseCode = 1, UploadPath = _FilePath, ErrorMessage = ""
                };
                string _ResponseJson = JsonConvert.SerializeObject(m_UploadResponse);
                Response.Write(_ResponseJson);
            }
            catch (Exception)
            {
            }
            //throw new NotImplementedException();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            UploadResponse m_UploadResponse = new UploadResponse {
                ResponseCode = 0, UploadPath = "", ErrorMessage = ""
            };

            if (!Page.IsPostBack)
            {
                if (Request.QueryString["pid"] != null)
                {
                    PhotoCrop _PhotoCrop;
                    int       _PhotoID = Convert.ToInt32(Request.QueryString["pid"]);
                    int       _UserID  = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
                    if (Request.QueryString["crop"] != null)
                    {
                        _PhotoCrop = new PhotoCrop
                        {
                            XPosition = Convert.ToInt32(Request.QueryString["X1"].ToString()),
                            YPosition = Convert.ToInt32(Request.QueryString["Y1"].ToString()),
                            XWidth    = Convert.ToInt32(Request.QueryString["X2"].ToString()),
                            YWidth    = Convert.ToInt32(Request.QueryString["Y2"].ToString())
                        };
                        bool _Result = new Photo().MakeExistingAsProfilePhoto(_UserID, _PhotoID, _PhotoCrop);

                        if (_Result)
                        {
                            m_UploadResponse.ResponseCode = 1;
                            m_UploadResponse.ErrorMessage = "done";

                            Photo _PhotoDetails = new Photo().GetPhoto(_PhotoID);

                            string _FilePath      = _PhotoDetails.PhotoPath.Split('.')[0];
                            string _RootDirectory = ConfigurationManager.AppSettings["PhotosRootPath"].ToString();
                            string _UserDirectory = _RootDirectory + "\\" + _UserID.ToString();

                            if (!Directory.Exists(_UserDirectory))
                            {
                                Directory.CreateDirectory(_UserDirectory);
                            }

                            List <ImageResizeDimension> _Dimensions    = new List <ImageResizeDimension>();
                            ImageResizeDimension        _EachDimension = new ImageResizeDimension();
                            _EachDimension.CropAndProceed = true;
                            _EachDimension.CropX          = _PhotoCrop.XPosition;
                            _EachDimension.CropY          = _PhotoCrop.YPosition;
                            _EachDimension.CropWidth      = _PhotoCrop.XWidth;
                            _EachDimension.CropHeight     = _PhotoCrop.YWidth;
                            _EachDimension.Title          = "PCT";
                            _EachDimension.Width          = Convert.ToInt32(ConfigurationManager.AppSettings["PCT"]);
                            _EachDimension.Height         = Convert.ToInt32(ConfigurationManager.AppSettings["PCT"]);
                            _Dimensions.Add(_EachDimension);

                            _EachDimension = new ImageResizeDimension();
                            _EachDimension.CropAndProceed = false;
                            _EachDimension.Width          = Convert.ToInt32(ConfigurationManager.AppSettings["PCGT"]);
                            _EachDimension.Height         = 0;
                            _EachDimension.Title          = "PCGT";
                            _Dimensions.Add(_EachDimension);
                            new ImageResizeQueue().EnqueImage(_RootDirectory + _FilePath + GetExtension(_PhotoDetails.PhotoPath), _Dimensions.ToArray());
                        }
                    }
                    string _ResponseJson = JsonConvert.SerializeObject(m_UploadResponse);
                    Response.Write(_ResponseJson);
                }
            }
        }