Exemplo n.º 1
0
        public async Task <IActionResult> Edit(long id, [Bind("ImageId,Title,ImageName")] ImageModel imageModel)
        {
            if (id != imageModel.ImageId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(imageModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ImageModelExists(imageModel.ImageId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(imageModel));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutImage(long id, Image image)
        {
            if (id != image.Id)
            {
                return(BadRequest());
            }

            _context.Entry(image).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ImageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 3
0
        public async Task <IHttpActionResult> PutImage(int id, Image image)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != image.ImageId)
            {
                return(BadRequest());
            }

            db.Entry(image).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ImageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IActionResult> Create([Bind("ImageId,Title,ImageFile")] ImageModel imageModel)
        {
            if (ModelState.IsValid)
            {
                //Bu kodlar resimleri wwwroot a kaydeder

                string wwwRoothPath = _hostEnvironment.WebRootPath;
                string fileName     = Path.GetFileNameWithoutExtension(imageModel.ImageFile.FileName);
                string extension    = Path.GetExtension(imageModel.ImageFile.FileName);
                imageModel.ImageName = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                string path = Path.Combine(wwwRoothPath + "/Image/", fileName);

                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    await imageModel.ImageFile.CopyToAsync(fileStream);
                }


                _context.Add(imageModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(imageModel));
        }
Exemplo n.º 5
0
        public async Task <int> Create(ImageModel imageModel)
        {
            Image image = ConvertImageModelToImage(imageModel);

            _context.Add(image);
            int success = await _context.SaveChangesAsync();

            return(success);
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("WordId,Title,WordName")] WordModel wordModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(wordModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(wordModel));
        }
Exemplo n.º 7
0
        /// <summary>
        /// 将组添加到数据库
        /// </summary>
        /// <param name="context">数据库上下文</param>
        /// <param name="item">组</param>
        /// <returns></returns>
        public async Task <int> AddGroupToDatabase(ImageDbContext context, OneDriveImageGroup item)
        {
            await context.Groups.AddAsync(item);

            int num = await context.SaveChangesAsync();

            AppTools.WriteLocalSetting(AppSettings.IsDatabaseChanged, "True");
            return(num);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 将图片数据添加到数据库
        /// </summary>
        /// <param name="context">数据库上下文</param>
        /// <param name="item">图片条目</param>
        /// <returns></returns>
        public async Task <int> AddImageToDatabase(ImageDbContext context, ICollection <OneDriveImage> item)
        {
            await context.Images.AddRangeAsync(item);

            int num = await context.SaveChangesAsync();

            AppTools.WriteLocalSetting(AppSettings.IsDatabaseChanged, "True");
            return(num);
        }
Exemplo n.º 9
0
        public async Task <ActionResult <ImageModel> > UploadImage([FromForm] ImageModel imageModel)
        {
            string wwwRootPath = _hostEnviroment.WebRootPath;
            string fileName    = Path.GetFileNameWithoutExtension(imageModel.ImageFile.FileName);
            string extension   = Path.GetExtension(imageModel.ImageFile.FileName);

            imageModel.ImageName = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
            string path = Path.Combine(wwwRootPath + "/images/", fileName);

            using (var fileStream = new FileStream(path, FileMode.Create))
            {
                await imageModel.ImageFile.CopyToAsync(fileStream);
            }
            await _context.Images.AddAsync(imageModel);

            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetImageById), new { id = imageModel.ImageId }, _mapper.Map <ImageReadDto>(imageModel)));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Create([Bind("HaberId,Baslik,İcerik,SonDakika,ResimDosyası")] Haber haber)
        {
            if (ModelState.IsValid)
            {
                string wwwRoothPath = _hostEnvironment.WebRootPath;
                string fileName     = Path.GetFileNameWithoutExtension(haber.ResimDosyası.FileName);
                string extension    = Path.GetExtension(haber.ResimDosyası.FileName);
                haber.ResimYolu = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                string path = Path.Combine(wwwRoothPath + "/HaberResimleri/", fileName);

                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    await haber.ResimDosyası.CopyToAsync(fileStream);
                }
                _context.Add(haber);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(haber));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Create([Bind("Id,Name,FileType,Description,FilePath,VideoYolu")] VideoModel videoModel)
        {
            if (ModelState.IsValid)
            {
                string wwwRoothPath = _hostEnvironment.WebRootPath;
                string fileName     = Path.GetFileNameWithoutExtension(videoModel.VideoDosyası.FileName);
                string extension    = Path.GetExtension(videoModel.VideoDosyası.FileName);
                videoModel.FilePath = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                string path = Path.Combine(wwwRoothPath + "/Videolar/", fileName);

                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    await videoModel.VideoDosyası.CopyToAsync(fileStream);
                }
                _context.Add(videoModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(videoModel));
        }
Exemplo n.º 12
0
        public override async Task <SendResult> SendFile(Chunk request, ServerCallContext context)
        {
            var content = request.Content.ToArray();
            var img     = new Image
            {
                Id          = new Guid(request.PostId),
                Full        = content,
                TimeCreated = DateTime.Now
            };

            _db.Images.Add(img);
            await _db.SaveChangesAsync();

            //https://www.c-sharpcorner.com/article/publisher-and-consumer-with-rabbitmq-docker-container/
            var factory = new ConnectionFactory()
            {
                HostName = "localhost",
                UserName = ConnectionFactory.DefaultUser,
                Password = ConnectionFactory.DefaultPass,
                Port     = 5672
            };

            using var connection = factory.CreateConnection();
            using var channel    = connection.CreateModel();


            channel.QueueDeclare(queue: "image_crop",
                                 durable: false,
                                 exclusive: false,
                                 autoDelete: false,
                                 arguments: null);

            string msg  = img.Id.ToString();
            var    body = Encoding.UTF8.GetBytes(msg);

            channel.BasicPublish(exchange: "",
                                 routingKey: "image_crop",
                                 basicProperties: null,
                                 body: body);

            return(new SendResult {
                Success = true
            });
        }
Exemplo n.º 13
0
        public override async Task <SendResult> SendFile(Chunk request, ServerCallContext context)
        {
            var content = request.Content.ToArray();
            var img     = new Image
            {
                Id          = new Guid(request.PostId),
                Full        = content,
                TimeCreated = DateTime.Now
            };

            _db.Images.Add(img);
            await _db.SaveChangesAsync();

            var factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            using var connection = factory.CreateConnection();
            using var channel    = connection.CreateModel();


            channel.QueueDeclare(queue: "image_crop",
                                 durable: false,
                                 exclusive: false,
                                 autoDelete: false,
                                 arguments: null);

            string msg  = img.Id.ToString();
            var    body = Encoding.UTF8.GetBytes(msg);

            channel.BasicPublish(exchange: "",
                                 routingKey: "image_crop",
                                 basicProperties: null,
                                 body: body);

            return(new SendResult {
                Success = true
            });
        }
Exemplo n.º 14
0
        private async void Consumer_Received(object sender, BasicDeliverEventArgs e)
        {
            var body   = e.Body;
            var postId = Encoding.UTF8.GetString(body.ToArray());

            _logger.LogInformation(postId);

            var image = await _db.Images.FindAsync(Guid.Parse(postId));

            var stream = new MemoryStream();

            using (var pic = SixLabors.ImageSharp.Image.Load(image.Full))
            {
                pic.Mutate(x => x
                           .Resize(200, 200));

                //pic.SaveAsJpeg(stream);
                stream.Position = 0;

                pic.SaveAsJpeg(stream);
            }

            stream.Position = 0;
            image.Thumb     = stream.ToArray();

            await Task.Delay(3000);

            await _db.SaveChangesAsync();

            _logger.LogInformation("Save to database -> PostId :", postId);


            var redis = ConnectionMultiplexer.Connect("localhost:6379");
            var db    = redis.GetDatabase();

            var pubsub = redis.GetSubscriber();

            pubsub.Publish("post_notify", new RedisValue("Post is ready!"));
        }