public void AddPhoto()
        {
            string emptyImagePath = Config.dbImgsFolder + Config.addImagePlaceHolder;


            if (ImagePath == emptyImagePath)
            {
                Message = "Putanja do slike nije dobra";
                return;
            }
            if (Title.Length == 0)
            {
                Message = "Naslov ne moze biti prazan";
                return;
            }

            string userImgsPath = Config.dbImgsFolder + Model.User.ActiveUser.Username + "\\";
            string imgFileName  = ImagePath.Split('\\').Last();

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

            File.Copy(ImagePath, userImgsPath + imgFileName);

            Model.Image tmpImage = new Model.Image(Title, Description, Model.User.ActiveUser.Username, imgFileName);
            Database.Instance().AddImage(tmpImage);
        }
示例#2
0
 public void SaveByRegion(Model.Image image, int id, int regionWidth, int regionHeight, Thickness regionPosition, string path, double scale)
 {
     if (regionWidth > 0 && regionHeight > 0)
     {
         BitmapWorker bw           = new BitmapWorker();
         BitmapSource bitmapSource = image.Bitmap;
         Bitmap       bitmap;
         int          width    = regionWidth;
         int          height   = regionHeight;
         Thickness    position = regionPosition;
         Normalize(ref width, ref height, ref position, bitmapSource);
         bitmap = bw.GetBitmap(bitmapSource);
         bitmap = bw.GetBitmapFragment(bitmap, (int)position.Left, (int)position.Top, (int)width, (int)height, (int)(image.Position.Left * bitmapSource.DpiX / 96.0), (int)(image.Position.Top * bitmapSource.DpiY / 96.0), scale);
         String fileName = $"Out_{id}.png";
         path += $"\\{fileName}";
         if (File.Exists(path))
         {
             MessageBoxResult overwriteResult = MessageBox.Show($"{fileName} already exists in this location. Do you want to overwrite it?", "Confirmation", MessageBoxButton.YesNoCancel);
             if (overwriteResult == MessageBoxResult.Yes)
             {
                 bitmap.Save(path, ImageFormat.Png);
             }
             else
             {
                 return;
             }
         }
         else
         {
             bitmap.Save(path, ImageFormat.Png);
         }
     }
 }
示例#3
0
 public void ProcessRequest(HttpContext context)
 {
     context.Response.ContentType = "text/plain";
     context.Response.Charset = "utf-8";
     HttpPostedFile hotFile = context.Request.Files[""];
     if (hotFile != null)
     {
         int id = int.Parse(context.Request.Params["uid"]);
         Stream stream = hotFile.InputStream;
         if (stream.CanRead)
         {
             byte[] reads = new byte[stream.Length];
             for (int i = 0; i < reads.Length; i++)
             {
                 reads[i] = (byte)stream.ReadByte();
             }
             Model.Image image = new Model.Image();
             image.Title = Guid.NewGuid().ToString();
             image.UpdatedDate = DateTime.Now;
             image.Data = reads;
             image.UserID = id;
             if (bll.AddImage(image))
             {
                 context.Response.Write("1");
                 return;
             }
         }
     }
     context.Response.Write("0");
 }
        public void TreeView_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var clickedItem = TryGetClickedItem(e);

            if (clickedItem == null || Path.GetExtension(clickedItem.Header.ToString()) == "")
            {
                return;
            }

            if ((e.Source as TreeViewItemImage).IsSelected)
            {
                e.Handled = true; // to cancel expanded/collapsed toggle
                Model.Image image = new Model.Image();
                try
                {
                    image.FileName  = clickedItem.Header.ToString();
                    image.FilePath  = clickedItem.Tag.ToString();
                    image.Extension = Path.GetExtension(image.FilePath);
                    if (image.Extension != "" && image.Extension != ".tmp")
                    {
                        ObservableCollection <Model.Image> temp = new ObservableCollection <Model.Image>();
                        temp.Add(image);
                        _aggregator.GetEvent <SendImage>().Publish(temp);
                    }
                }
                catch (Exception)
                {
                    CollapseAll();
                }
            }
        }
示例#5
0
        public async Task Add(Model.Image image)
        {
            image.CreatedAt = DateTime.Now;
            await _carDealerContext.Images
            .Include(x => x.Advert)
            .FirstAsync();

            await _carDealerContext.Images.AddAsync(image);

            await _carDealerContext.SaveChangesAsync();
        }
示例#6
0
        public System.Collections.ObjectModel.ObservableCollection<Model.Playlist> ExtractPlaylists()
        {
            IEnumerable<System.Xml.Linq.XElement> playlists = XElement.Elements();
            System.Collections.ObjectModel.ObservableCollection<Model.Playlist> playlistsList = new System.Collections.ObjectModel.ObservableCollection<Model.Playlist>();
            if (XElement == null)
                return null;
            try
            {
                /* CREATING AN OBSERVABLECOLLECTION FROM ALL PLAYLIST */

                foreach (var playlist in playlists)
                {
                    IEnumerable<System.Xml.Linq.XElement> medias = XElement.Elements("Media");
                    System.Collections.ObjectModel.ObservableCollection<Model.Media> mediasList = new System.Collections.ObjectModel.ObservableCollection<Model.Media>();

                    /* CREATING AN MEDIA COLLECTION CORRESPONDING TO ALL MEDIAS OF PLAYLIST */

                    foreach (var media in medias)
                    {
                        /* TEST IF XML ELEMENT IS VALID FOR MEDIA */

                        if (media != null && media.Element("Path") != null && media.Element("Type") != null)
                        {
                            Model.Media newMedia = null;

                            switch ((Model.Media.MediaType)Enum.Parse(typeof(Model.Media.MediaType), media.Element("Type").Value))
                            {
                                case Model.Media.MediaType.IMAGE:
                                    newMedia = new Model.Image(media.Element("Path").Value);
                                    break;
                                case Model.Media.MediaType.VIDEO:
                                    newMedia = new Model.Video(media.Element("Path").Value);
                                    break;
                                case Model.Media.MediaType.MUSIC:
                                    newMedia = new Model.Music(media.Element("Path").Value);
                                    break;
                            }

                            if (newMedia != null)
                                mediasList.Add(newMedia);
                        }
                    }

                    /* ADDING NEW PLAYLIST ELEMENT TO SELECTION */

                    playlistsList.Add(new Model.Playlist() { Name = playlist.Element("Name").Value, MediasList = mediasList });
                }
            }
            catch
            { }

            return playlistsList;
        }
示例#7
0
 protected void Page_Load(object sender, EventArgs e)
 {
     UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;
     if (!IsPostBack)
     {
         ddlPhoto.DataSource    = ImageManager.getAllPhoto();
         ddlPhoto.DataTextField = "PhotoID";
         ddlPhoto.DataBind();
         images.PhotoID    = ddlPhoto.SelectedValue;
         images            = ImageManager.findImageByPhotoID(images);
         imgPhoto.ImageUrl = images.Photo;
     }
 }
示例#8
0
 private void search_Click(object sender, EventArgs e)
 {
     Model.Image img = new Model.Image();
     img.ImageNumber = textbox_ImageNumber.Text;
     img.PartsName   = textbox_PartsName.Text;
     //img.UpdateTime = dateTimePicker_UpdateTime.ToDateTime(dateTimePicker_UpdateTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
     Model.Company com = new Model.Company();
     com.CompanyName   = textbox_CompanyName.Text;
     com.CompanyNumber = textbox_CompanyNumber.Text;
     Model.Product pro = new Model.Product();
     pro.ProductName = textbox_ProductName.Text;
     pro.ProductType = textbox_ProductType.Text;
 }
示例#9
0
        protected void dlImage_DeleteCommand(object source, DataListCommandEventArgs e)
        {
            images.PhotoID = dlImage.DataKeys[e.Item.ItemIndex].ToString();
            images         = ImageManager.findImageByPhotoID(images);
            string strUrl = images.Photo;
            //删除指定文件的图片
            string strFilePath = Server.MapPath(@"..\Images\Photo\") + strUrl.Substring(strUrl.LastIndexOf("\\") + 1, strUrl.Length - strUrl.LastIndexOf("\\") - 1);

            File.Delete(strFilePath);
            ImageManager.deletePhoto(images);
            dlBind();
            Response.Write("<script language=javascript>alert('头像删除成功!')</script>");
        }
示例#10
0
 public async Task <Model.Image> Get(string filename)
 {
     Model.Image result = null;
     try
     {
         result = await _context.Images
                  .FirstOrDefaultAsync(x => x.FileName == filename);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     return(result);
 }
示例#11
0
        protected void CallImg5()
        {
            Model.Image img5 = (from x in img
                                join z in prod
                                on x.ProductID equals z.ProductID
                                where z.ProductID == 44257
                                select x).FirstOrDefault();
            Product name5 = (from x in dbEntity.Products
                             where x.ProductID == 44257
                             select x).FirstOrDefault();

            Image5.ImageUrl = "./Assets/" + img5.ImageName;
            Label5.Text     = name5.ProductName;
        }
示例#12
0
 public async Task <Model.Image> GetByUrl(string url)
 {
     Model.Image result = null;
     try
     {
         result = await _context.Images
                  .FirstOrDefaultAsync(x => x.PathUrl == url);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     return(result);
 }
示例#13
0
        private void ok_Click(object sender, EventArgs e)
        {
            Model.Image img = new Model.Image();
            img.ImageNumber = intextbox_ImageNumber.Text;
            img.PartsName   = intextbox_PartsName.Text;
            img.Path        = intextBox_path.Text;
            Model.Company com = new Model.Company();
            com.CompanyName   = intextbox_CompanyName.Text;
            com.CompanyNumber = intextbox_CompanyNumber.Text;
            Model.Product pro = new Model.Product();
            pro.ProductName = intextbox_ProductName.Text;
            pro.ProductType = intextbox_ProductType.Text;

            //DepartmentName
        }
示例#14
0
        public async Task <Uri> UploadBlob(IFormFile file, long userId)
        {
            try
            {
                if (file == null)
                {
                    return(null);
                }
                string filename  = string.Concat(Properties.Resources.AzureStorageContainer + "-", Guid.NewGuid());
                string extension = Path.GetExtension(file.FileName);
                filename += extension;
                string contentType = "application/octet-stream";
                SetContentType(extension, contentType);
                var                accountName    = Properties.Resources.AzureStorageAccount;
                var                accountKey     = Properties.Resources.AzureStorageAccountKey;
                var                storageAccount = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
                CloudBlobClient    blobClient     = storageAccount.CreateCloudBlobClient();
                CloudBlobContainer container      = blobClient.GetContainerReference(Properties.Resources.AzureStorageContainer);
                CloudBlockBlob     blob           = container.GetBlockBlobReference(filename);
                blob.Properties.ContentType = contentType;
                using (Stream stream = file.OpenReadStream())
                {
                    await blob.UploadFromStreamAsync(stream);

                    stream.Close();
                }
                await container.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });

                if (blob.Uri != null)
                {
                    Model.Image image = new Model.Image()
                    {
                        CreatedOn = DateTime.Now,
                        UpdatedOn = DateTime.Now,
                        Extension = extension,
                        FileName  = filename,
                        IsActive  = true,
                        PathUrl   = blob.Uri.ToString()
                    };
                    await _image.Create(image, userId);
                }
                return(blob.Uri);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
示例#15
0
        private void ExecuteOpenImageFile()
        {
            System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
            openFileDialog.Filter = "PNG Files (.png)|*.png|JPG Files (.jpg)|*.jpg|JPEG Files (.jpeg)|*.jpeg|All Files (*.*)|*.*";
            openFileDialog.FilterIndex = 1;

            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Model.Image NewImage = new Model.Image(openFileDialog.FileName);
                ImageList.Add(NewImage);
                XMLMedia XMLImage = new XMLMedia();
                XMLImage.LoadXML("Image.xml");
                XMLImage.AddMedia(NewImage);
                XMLImage.WriteXML("Image.xml");
            }
        }
示例#16
0
        public static Entities.Image ToCore(this Model.Image image)
        {
            Entities.Image result = null;

            if (image != null)
            {
                result = new Entities.Image()
                {
                    Id                  = image.Id,
                    Name                = image.Name,
                    UserDescription     = image.UserDescription,
                    AnalyserDescription = image.AnalyserDescription,
                    Priority            = (Entities.PriorityEnum)image.Priority
                };
            }

            return(result);
        }
示例#17
0
        public static Model.Image FromCore(this Entities.Image image)
        {
            Model.Image result = null;

            if (image != null)
            {
                result = new Model.Image()
                {
                    Id                  = image.Id,
                    Name                = image.Name,
                    UserDescription     = image.UserDescription,
                    AnalyserDescription = image.AnalyserDescription,
                    Priority            = (int)image.Priority
                };
            }

            return(result);
        }
示例#18
0
        public void ProcessRequest(HttpContext context)
        {
            Stream stream = null;
            HttpPostedFile file = null;
            string qgid = context.Request.Params["gid"];
            string quid = context.Request.Params["uid"];
            int gid = -1;
            int uid = -1;
            int.TryParse(qgid, out gid);
            int.TryParse(quid, out uid);
            if (gid == -1 || uid==-1)
            {
                return;
            }
            for (int f = 0, l = context.Request.Files.Count; f < l; f++)
            {
                file = context.Request.Files[f];
                if (file != null)
                {

                    stream = file.InputStream;
                    if (stream.CanRead && stream.Length != 0)
                    {
                        byte[] reads = new byte[stream.Length];
                        for (int i = 0; i < reads.Length; i++)
                        {
                            reads[i] = (byte)stream.ReadByte();
                        }
                        Model.Image image = new Model.Image();
                        image.Title = Guid.NewGuid().ToString();
                        image.UpdatedDate = DateTime.Now;
                        image.Data = reads;
                        image.UserID = uid;
                        image.Gallery = gid;
                        bll.AddImage(image);
                    }
                }
            }
            context.Response.ContentType = "text/plain";
            context.Response.Charset = "utf-8";
            context.Response.Redirect("Uploader.aspx?action=0", true);
        }
示例#19
0
        public async Task Update(Model.Image entity)
        {
            var imageToUpdate = await _carDealerContext.Images
                                .Include(x => x.Advert)
                                .SingleOrDefaultAsync(x => x.Id == entity.Id);

            if (imageToUpdate != null)
            {
                imageToUpdate.Data   = entity.Data;
                imageToUpdate.Advert = entity.Advert;


                if (imageToUpdate.Advert != null && entity.Advert != null)
                {
                    entity.Advert.Id = imageToUpdate.Advert.Id;
                    _carDealerContext.Entry(imageToUpdate.Advert).CurrentValues.SetValues(entity.Advert);
                }
                await _carDealerContext.SaveChangesAsync();
            }
        }
示例#20
0
        public async Task <Boolean> Create(Model.Image image, long userId)
        {
            Boolean result = false;

            try
            {
                if (image != null)
                {
                    image.CreatedOn   = image.UpdatedOn = DateTime.Now;
                    image.CreatedById = userId;
                    _context.Images.Update(image);
                    result = await _context.SaveChangesAsync() > 0;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(result);
        }
        /// <summary>
        /// Создать запись об изображении
        /// </summary>
        /// <param name="imagePath">Путь к изопражению</param>
        /// <param name="targetDir">Путь назначение</param>
        /// <returns>Ключ рисунка</returns>
        private Model.Image CreateImage(string imagePath, string targetDir, IConfiguration cnf, ILogger lg, IFIleManager fm)
        {
            var    imgInfo    = new FileInfo(imagePath);
            var    imgDirPath = imgInfo.Directory.FullName;
            string newImgPath = "";

            byte[] imageData = null;
            try
            {
                newImgPath = fm.CopyImg(imagePath, targetDir);
            }
            catch (IOException copyError)
            {
                lg.Add(copyError.Message);
            }

            Bitmap bmp       = fm.GetThumb(imagePath);
            string thumbPath = fm.SaveThumb(targetDir, cnf.GetThumbDirName(), bmp, imgInfo.Name);

            imageData = fm.GetImageData(bmp);


            var im = new Model.Image()
            {
                HashCode = imgInfo.GetHashCode()
                ,
                ImagePath = newImgPath
                ,
                ImageTitle = imgInfo.Name
                ,
                ThumbnailPath = thumbPath
                ,
                Thumbnail = imageData
            };

            return(im);
        }
示例#22
0
        public ActionResult Upload(string c, string t, string k, string d, string isShow, string isTop, string urls)
        {
            if (Session["UserId"] == null)
            {
                return Redirect("/admin/");
            }
            UploadModel model = new UploadModel();
            model.CategoryList = categoryService.GetCategories("album");
            model.isSuccessful = "添加失败";
            model.SelectedCategory = c;

            if (!string.IsNullOrEmpty(c) && !string.IsNullOrEmpty(t) && !string.IsNullOrEmpty(urls))
            {
                Album album = new Album();
                album.CategoryId = c;
                album.Title = t;
                album.Keywords = k ?? string.Empty;
                album.Description = d ?? string.Empty;
                album.IsDelete = false;
                album.IsShow = false;
                album.IsTop = false;
                album.InsertTime = DateTime.Now;
                album.ViewTime = 0;
                if (!string.IsNullOrEmpty(isShow) && isShow == "true")
                {
                    album.IsShow = true;
                }
                if (!string.IsNullOrEmpty(isTop) && isTop == "true")
                {
                    album.IsTop = true;
                }

                urls = urls.Substring(0, urls.Length);
                string[] us = urls.Split('|');

                List<Image> images = new List<Image>();
                foreach (var original in us)
                {
                    if (original.Contains(".jpg") || original.Contains(".png") || original.Contains(".gif"))
                    {
                        string imageName = original.Substring(0, original.Length - 4);
                        string filetrype = original.Substring(original.Length - 4, 4);

                        Model.Image image = new Model.Image();
                        image.UrlOriginal = original;
                        image.UrlThumbnailWidth102x102 = imageName + "-102x102" + filetrype;
                        image.UrlThumbnailWidth235x350 = imageName + "-235x350" + filetrype;
                        image.UrlThumbnailWidth490x350 = imageName + "-490x350" + filetrype;
                        image.UrlThumbnailHeight200 = imageName + "-big" + filetrype;

                        images.Add(image);
                    }
                }

                if (albumService.AddAlbum(album, images))
                {
                    model.isSuccessful = "添加成功";
                    //更新首页缓存
                    Cache.UpdateHomeData();
                }
            }
            return View(model);
        }
示例#23
0
        private void LoadImageFile(String FileName)
        {
            //TODO CHECK IF MEDIA ALREADY LOADED + LOAD MEDIA

            /* ERASE */

            var Extension = System.IO.Path.GetExtension(FileName).ToUpper();

            if (Extension == ".PNG" || Extension == ".JPG" || Extension == ".JPEG")
            {
                Model.Image NewImage = new Model.Image(FileName);
                ImageList.Add(NewImage);
            }
        }