Exemplo n.º 1
0
        private Post AddArticle(Post entity, bool isNew = true)
        {
            entity.Title = entity.Title.Trim();
            entity.Url   = entity.Url.Trim().ToLower().Replace(" ", "-");

            entity.Group = Proxy.Repository <Group>().Get(entity.Group.GroupId);

            for (int i = 0; i < entity.Categorys.Count; i++)
            {
                entity.Categorys[i] = Proxy.Repository <Category>().Get(entity.Categorys[i].CategoryId);
            }

            if (isNew)
            {
                entity.PubAdmin = Proxy.Repository <User>().Get(p => p.UserName == Current.User.UserName);
                entity.PubDate  = DateTime.Now;
            }
            else
            {
                entity.EditAdmin = Proxy.Repository <User>().Get(p => p.UserName == Current.User.UserName);
                entity.EditDate  = DateTime.Now;
            }

            if (entity.Thumbnail != null)
            {
                var filename = entity.PubDate.ToString("yyyy.MM.dd.") + entity.Url +
                               Path.GetExtension(entity.Thumbnail.Url);
                var source = string.Format("{0}/{1}", HttpContext.Current.Server.MapPath("~/upload/temp"),
                                           entity.Thumbnail.Url);
                var target = string.Format("{0}/{1}", HttpContext.Current.Server.MapPath("~/upload/thumbnail"), filename);
                if (File.Exists(source))
                {
                    if (File.Exists(target))
                    {
                        File.Delete(target);
                    }
                    File.Move(source, target);
                    ImageProcessing.CutForCustom(target, 160, 100, 100);
                    entity.Thumbnail.Url = filename;
                }
            }

            //添加Post.Qrcode
            entity.QrCode = new QrCode
            {
                QrCodeId = Guid.NewGuid(),
                Content  = entity.Title,
                Url      = entity.Url + ".png"
            };
            var       gRender = new GraphicsRenderer(new FixedModuleSize(30, QuietZoneModules.Four));
            var       fullUrl = Config.URL.Domain + "/#!/post/" + entity.Url;
            BitMatrix matrix  = new QrEncoder().Encode(entity.QrCode.Content + " | " + fullUrl).Matrix;

            using (var stream = new FileStream(HttpContext.Current.Server.MapPath("/upload/qrcode/" + entity.QrCode.Url), FileMode.Create))
            {
                gRender.WriteToStream(matrix, ImageFormat.Png, stream, new Point(1000, 1000));
            }

            entity.Content     = SaveRemoteFile.SaveContentPic(entity.Content, entity.Url);
            entity.Description = SaveRemoteFile.SaveContentPic(entity.Description, entity.Url);

            entity = Proxy.Repository <Post>().Add(entity);
            Rss.BuildPostRss();
            return(entity);
        }
Exemplo n.º 2
0
 private void SaveRemoteImg(Post entity)
 {
     entity.Content     = SaveRemoteFile.SaveContentPic(entity.Content, entity.Url);
     entity.Description = SaveRemoteFile.SaveContentPic(entity.Description, entity.Url);
 }