コード例 #1
0
        /// <summary>
        /// 编辑投稿
        /// </summary>
        /// <param name="ArticleID"></param>
        /// <returns></returns>
        public ActionResult MarkDownEditor(string ArticleID)
        {
            Article article = Article.GetArticleBySn(ArticleID);

            if (Session[ConstHelper.Session_USERID] == null)
            {
                return(Redirect("/Home/Index"));
            }
            if (Session[ConstHelper.Session_USERID].ToString() != article.OwnerId)
            {
                return(Redirect("/Home/Index"));
            }
            ViewBag.IsPrivate  = article.IsPrivate;
            ViewBag.FreeVolumn = UploadFile.GetFreeVolumnByAccountId(article.OwnerId);
            ViewData.Model     = ArticleContent.GetMarkDown(ArticleID, RevisionType.Draft);
            ViewBag.Title      = "编辑-" + article.Title;
            return(View());
        }
コード例 #2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            string json = string.Empty;

            if (context.Session[ConstHelper.Session_USERID] == null)
            {
                var SessionTimeout = new
                {
                    success = ConstHelper.Fail,
                    message = "[保存失败]系统超时,请重新登陆",
                };
                json = JsonConvert.SerializeObject(SessionTimeout);
                context.Response.Write(json);
                return;
            }
            string  strArticleID = context.Request.Unvalidated.Form["ArticleID"];
            string  strMarkDown  = context.Request.Unvalidated.Form["Content"];
            Article article      = Article.GetArticleBySn(strArticleID);

            if (!article.OwnerId.Equals(context.Session[ConstHelper.Session_USERID].ToString()))
            {
                var NotTheOwner = new
                {
                    success = ConstHelper.Fail,
                    message = "[保存失败]你所编辑的文章的所有者和您的登陆用户不匹配",
                };
                json = JsonConvert.SerializeObject(NotTheOwner);
                context.Response.Write(json);
                return;
            }
            ArticleContent.SaveMarkDownVersion(strArticleID, strMarkDown, article.Sn, RevisionType.Draft);
            context.Response.ContentType = "text/json";
            string strfree = UploadFile.GetFreeVolumnByAccountId(context.Session[ConstHelper.Session_USERID].ToString());
            var    result  = new
            {
                success = ConstHelper.Success,
                message = "[保存成功]上次保存成功时间:" + System.DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss") + ",剩余图片空间:" + strfree,
            };

            json = JsonConvert.SerializeObject(result);
            context.Response.Write(json);
        }
コード例 #3
0
ファイル: Upload.ashx.cs プロジェクト: SauravMiah/CodeSnippet
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            string ownerId   = context.Request["OwnerId"];
            string ArticleId = context.Request["ArticleId"];
            var    httpfile  = context.Request.Files[0];

            if (UploadFile.IsAboveLimit(httpfile.ContentLength, ownerId))
            {
                var AboveLimit = new
                {
                    success = ConstHelper.Fail,
                    message = "上传失败,上传资源超过最大值限制!!"
                };
                context.Response.Write(JsonConvert.SerializeObject(AboveLimit));
                return;
            }

            UploadFile upload = new UploadFile();

            upload.Size = httpfile.ContentLength;

            Image orgImage = Image.FromStream(httpfile.InputStream);

            //保存原图到七牛
            httpfile.InputStream.Position = 0;
            string strImage     = ConfigurationManager.AppSettings["Image"];
            var    Savefilename = string.Empty;

            switch (strImage)
            {
            case "QiNue":
                Savefilename = QiniuStorage.upload(httpfile, ownerId);
                break;

            case "Mongo":
                Savefilename = MongoStorage.InsertFile(httpfile, ownerId, "Image");
                break;

            case "FileSystem":
                Savefilename = FileSystemStorage.PutFile(httpfile, ownerId, "Image");
                break;
            }

            string ThumbnailUrl = "/FileSystem/Thumbnail?filename=" + Savefilename;
            string Thumbnail    = ConfigurationManager.AppSettings["Thumbnail"];

            if (httpfile.FileName.ToLower().EndsWith(".gif"))
            {
                //直接保存
                switch (Thumbnail)
                {
                case "Mongo":
                    MongoStorage.InsertFile(httpfile, ownerId, "Thumbnail");
                    break;

                case "FileSystem":
                    Savefilename = FileSystemStorage.PutFile(httpfile, ownerId, "Thumbnail");
                    break;
                }
                upload.SmallFileSize = upload.Size;
            }
            else
            {
                //这里是拉伸图片,将图片改为BMP(PDF和画面折衷后的决定)
                var BitmapImage = ImageHelper.ResizeImage(System.Math.Min(800, orgImage.Width), orgImage.Height, ImageHelper.ResizeMode.W, orgImage);
                //string Smallfilename = MongoStorage.InsertFile(httpfile, ownerId, "Bussiness");
                //返回的名字以DefaultOwnerId开始
                var SmallStream = StreamConvert.BytesToStream(StreamConvert.BitmapToBytes(BitmapImage, ImageFormat.Gif));
                //保存有时间差,所以使用上一步保存时候的文件名称
                //同时Stream关闭后无法获得长度,长度必须先写
                upload.SmallFileSize = (int)SmallStream.Length;
                switch (Thumbnail)
                {
                case "Mongo":
                    MongoStorage.InsertStreamWithFixFileName(SmallStream, Savefilename, "Thumbnail");
                    break;

                case "FileSystem":
                    FileSystemStorage.InsertStreamWithFixFileName(SmallStream, Savefilename, "Thumbnail");
                    break;
                }
            }


            upload.Name      = Savefilename;
            upload.ArticleID = ArticleId;
            UploadFile.InsertUploadFile(upload, ownerId);
            string strfree = UploadFile.GetFreeVolumnByAccountId(ownerId);
            var    result  = new
            {
                success = ConstHelper.Success,
                message = "上传成功,剩余图片空间:" + strfree,
                url     = ThumbnailUrl
            };
            string json = JsonConvert.SerializeObject(result);

            context.Response.Write(json);
        }