public FakeArticle(ArticleTitle title) { _source = new FakePath(title.PlainText); Parts = new List <ArticlePart>() { ArticlePart.CreateHeader(title.TextWithLineBreak) }; }
public void Setup() { _article = new FakeArticle(new List <ArticlePart>() { ArticlePart.CreateHeader("Some new article\n"), ArticlePart.CreateText("Blah blah text with "), ArticlePart.CreateLink("link to another", "Another Article"), ArticlePart.CreateText(" article.\n"), ArticlePart.CreateText("Next P.") }); }
private void Fetch() { if (_fetched == false) { _fetched = true; for (int i = 0; i < 25; i++) { Parts.Add(ArticlePart.CreateText(ContentHelper.GenerateParagraph())); } } }
public string Import() { ApiResult result = new ApiResult(); try { User user = GetUserInfo(); if (user == null) { result.message = EnumBase.GetDescription(typeof(Enum_ErrorCode), Enum_ErrorCode.UnLogin); result.code = Enum_ErrorCode.UnLogin; return(JsonConvert.SerializeObject(result)); } var urls = ZNRequest.GetString("Url"); var number = ZNRequest.GetString("ArticleNumber"); if (string.IsNullOrWhiteSpace(urls)) { result.message = "信息异常"; return(JsonConvert.SerializeObject(result)); } var list = new List <ArticlePartJson>(); var url = urls.Split(',').ToList(); url.ForEach(x => { var model = new ArticlePart(); model.Introduction = x; model.IntroExpand = string.Empty; model.ArticleNumber = number; model.Types = Enum_ArticlePart.Pic; model.CreateUserNumber = user.Number; model.CreateIP = Tools.GetClientIP; model.CreateDate = DateTime.Now; model.Status = Enum_Status.Audit; model.SortID = 0; var id = Tools.SafeInt(db.Add <ArticlePart>(model)); list.Add(new ArticlePartJson(id, x)); }); result.result = true; result.message = list; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_ArticlePart_Import" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public async Task <ActionResult> CreateArticle([FromBody] CreateArticleDto dto) { var newArticle = new Article() { Title = dto.Title, Description = dto.Description, HeroImage = _mapper.Map <Image>(dto.HeroImage) }; for (int partCount = 0; partCount < dto.Parts.Count; partCount++) { var newPart = new ArticlePart() { PartNumber = partCount + 1, Title = dto.Parts[partCount].Title, Description = dto.Parts[partCount].Description }; for (int stepCount = 0; stepCount < dto.Parts[partCount].Steps.Count; stepCount++) { var newStep = new ArticleStep() { StepNumber = stepCount + 1, Title = dto.Parts[partCount].Steps[stepCount].Title, Description = dto.Parts[partCount].Steps[stepCount].Description }; newPart.Steps.Add(newStep); } newArticle.Parts.Add(newPart); } var currentUser = await GetCurrentUser(); newArticle.Users.Add(currentUser); await _appDbContext.Articles.AddAsync(newArticle); await _appDbContext.SaveChangesAsync(); return(Ok()); }
public void InsertPart(int offset, string textToInsert) { var partToInsert = GetRange(offset, 0); if (partToInsert.Parts.Any()) { var part = partToInsert.Parts.First(); if (part.MarkerStyle == MarkerStyle.Header && textToInsert.Contains('\n')) { var newText = part.Text.Insert(partToInsert.StartingOffset, textToInsert); var parts = newText.Split('\n'); if (parts.Length == 1) { part.Text = parts[0] + '\n'; } else { part.Text = parts[0] + '\n'; Parts.Insert(1, ArticlePart.CreateText(parts[1] + '\n')); _view?.Render(); } } else { part.Text = part.Text.Insert(partToInsert.StartingOffset, textToInsert); } } else if (Parts.Any()) { Parts.Last().Text += textToInsert; } else { Parts.Add(ArticlePart.CreateHeader(textToInsert)); } }
/// <summary> /// Internal function for retrieving article parts. /// </summary> /// <param name="towrite">String to write to server.</param> /// <returns></returns> private string GetArticlePart(string towrite, ArticlePart artpart) { string response; NetworkStream s = GetStream(); StreamWriter w = new StreamWriter( s); StreamReader r = new StreamReader( s, System.Text.Encoding.GetEncoding("iso-8859-1")); w.AutoFlush = true; Global.ConnectionLog.LogLine( "{0}|W|{1}", System.Threading.Thread.CurrentThread.Name, towrite); WriteLine( w, towrite); response = ReadLine( r); Global.ConnectionLog.LogLine( "{0}|R|{1}", System.Threading.Thread.CurrentThread.Name, response); //check positive responses if( ( response.StartsWith( "220") && artpart == ArticlePart.WHOLE) || ( response.StartsWith( "221") && artpart == ArticlePart.HEAD) || ( response.StartsWith( "222") && artpart == ArticlePart.BODY)) { bool Done = false; int LineCount = 0; StringBuilder Body = new StringBuilder( 256*1024 ); do { response = ReadLine( r); if( OnReceivedArticleLine != null) Done = !OnReceivedArticleLine( LineCount+1, response.Length); if( response == ".") { Done = true; } else { if( response.StartsWith( "..")) response = response.Remove(0,1); Body.Append( response); Body.Append( "\r\n"); LineCount++; } } while( !Done); return Body.ToString(); } bool validResponse = true; try { int.Parse( response.Split(' ')[0]); } catch { validResponse = false; } if( !validResponse) { frmMain.LogWriteError("The server gave back an invalid response, closing connection."); Close(); } if(artpart == ArticlePart.WHOLE) frmMain.LogWriteError("Failed to retrieve article with code: " + response.Split(' ')[0]); else if(artpart == ArticlePart.HEAD) frmMain.LogWriteError("Failed to retrieve article header with code: " + response.Split(' ')[0]); else if(artpart == ArticlePart.BODY) frmMain.LogWriteError("Failed to retrieve article body with code: " + response.Split(' ')[0]); throw new Exception("Unexpected response from server: " + response); }
/// <summary> /// Internal function for retrieving article parts. /// </summary> /// <param name="towrite">String to write to server.</param> /// <returns></returns> private string GetArticlePart(string towrite, ArticlePart artpart) { string response; Stream s = GetStream(); StreamWriter w = new StreamWriter(s); StreamReader r = new StreamReader(s, System.Text.Encoding.GetEncoding("iso-8859-1")); w.AutoFlush = true; Global.ConnectionLog.LogLine("{0}|W|{1}", System.Threading.Thread.CurrentThread.Name, towrite); WriteLine(w, towrite); response = ReadLine(r); Global.ConnectionLog.LogLine("{0}|R|{1}", System.Threading.Thread.CurrentThread.Name, response); //check positive responses if ((response.StartsWith("220") && artpart == ArticlePart.WHOLE) || (response.StartsWith("221") && artpart == ArticlePart.HEAD) || (response.StartsWith("222") && artpart == ArticlePart.BODY)) { bool Done = false; int LineCount = 0; StringBuilder Body = new StringBuilder(256 * 1024); do { response = ReadLine(r); if (OnReceivedArticleLine != null) { Done = !OnReceivedArticleLine(LineCount + 1, response.Length); } if (response == ".") { Done = true; } else { if (response.StartsWith("..")) { response = response.Remove(0, 1); } Body.Append(response); Body.Append("\r\n"); LineCount++; } } while(!Done); return(Body.ToString()); } bool validResponse = true; try { int.Parse(response.Split(' ')[0]); } catch { validResponse = false; } if (!validResponse) { frmMain.LogWriteError("The server gave back an invalid response, closing connection."); Close(); } if (artpart == ArticlePart.WHOLE) { frmMain.LogWriteError("Failed to retrieve article with code: " + response.Split(' ')[0]); } else if (artpart == ArticlePart.HEAD) { frmMain.LogWriteError("Failed to retrieve article header with code: " + response.Split(' ')[0]); } else if (artpart == ArticlePart.BODY) { frmMain.LogWriteError("Failed to retrieve article body with code: " + response.Split(' ')[0]); } throw new Exception("Unexpected response from server: " + response); }
public ActionResult Edit() { var parts = ""; try { User user = GetUserInfo(); if (user == null) { return(Json(new { result = false, message = "用户信息验证失败", code = Enum_ErrorCode.UnLogin }, JsonRequestBehavior.AllowGet)); } Article model = new Article(); model.ID = ZNRequest.GetInt("ArticleID"); if (model.ID > 0) { model = db.Single <Article>(x => x.ID == model.ID); if (model == null) { model = new Article(); } else { //判断权限 if (user.UserRole == Enum_UserRole.Common) { if (user.Number != model.CreateUserNumber) { return(Json(new { result = false, message = "没有权限", code = Enum_ErrorCode.NoPower }, JsonRequestBehavior.AllowGet)); } } } } model.Title = SqlFilter(ZNRequest.GetString("Title")); model.Title = CutString(model.Title, 100); var dirtyword = AppHelper.HasDirtyWord(model.Title); if (!string.IsNullOrWhiteSpace(dirtyword)) { return(Json(new { result = false, message = "您输入的标题含有敏感内容[" + dirtyword + "],请检查后重试哦" }, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrWhiteSpace(model.Title)) { model.Title = "我的小微篇"; } model.Province = ZNRequest.GetString("Province"); model.City = ZNRequest.GetString("City"); model.District = ZNRequest.GetString("District"); model.Street = ZNRequest.GetString("Street"); model.DetailName = ZNRequest.GetString("DetailName"); model.CityCode = ZNRequest.GetString("CityCode"); model.Latitude = Tools.SafeDouble(ZNRequest.GetString("Latitude")); model.Longitude = Tools.SafeDouble(ZNRequest.GetString("Longitude")); model.Template = ZNRequest.GetInt("Template"); model.ColorTemplate = ZNRequest.GetInt("ColorTemplate"); model.UpdateUserNumber = user.Number; model.UpdateDate = DateTime.Now; model.UpdateIP = Tools.GetClientIP; model.Status = Enum_Status.Approved; model.Submission = Enum_Submission.TemporaryApproved;//默认临时投稿审核 var ArticlePower = ZNRequest.GetInt("ArticlePower", -1); if (ArticlePower > -1) { model.ArticlePower = ArticlePower; } var ArticlePowerPwd = ZNRequest.GetString("ArticlePowerPwd"); if (!string.IsNullOrWhiteSpace(ArticlePowerPwd)) { model.ArticlePowerPwd = ArticlePowerPwd; } var TypeID = ZNRequest.GetInt("ArticleType", 0); if (TypeID > 0) { var articleType = AppHelper.GetArticleType().FirstOrDefault <ArticleType>(x => x.ID == TypeID); if (articleType != null) { model.TypeID = TypeID; model.TypeIDList = articleType.ParentIDList; } } var result = false; if (model.ID == 0) { var cover = ZNRequest.GetString("Cover"); if (string.IsNullOrWhiteSpace(cover)) { return(Json(new { result = false, message = "文章信息异常" }, JsonRequestBehavior.AllowGet)); } var covers = cover.Split(','); model.Cover = covers[0]; model.Recommend = Enum_ArticleRecommend.None; model.CreateUserNumber = user.Number; model.CreateDate = DateTime.Now; model.CreateIP = Tools.GetClientIP; model.Number = BuildNumber(); model.ID = Tools.SafeInt(db.Add <Article>(model)); result = model.ID > 0; //初始化文章段落 if (result) { for (var i = 0; i < covers.Length; i++) { ArticlePart part = new ArticlePart(); part.ArticleNumber = model.Number; part.Types = Enum_ArticlePart.Pic; part.Introduction = covers[i]; part.IntroExpand = string.Empty; part.SortID = Tools.SafeInt(i); part.Status = Enum_Status.Audit; part.CreateDate = DateTime.Now; part.CreateUserNumber = user.Number; part.CreateIP = Tools.GetClientIP; part.ID = Tools.SafeInt(db.Add <ArticlePart>(part)); result = part.ID > 0; } } if (result) { ArticleType articleType = AppHelper.GetArticleType().FirstOrDefault <ArticleType>(x => x.ID == model.TypeID); model.TypeName = articleType == null ? string.Empty : articleType.Name; return(Json(new { result = true, message = new { ID = model.ID, Number = model.Number, ArticlePower = model.ArticlePower, ArticlePowerPwd = model.ArticlePowerPwd, ArticleType = model.TypeID, ArticleTypeName = model.TypeName } }, JsonRequestBehavior.AllowGet)); } } else { if (model.ArticlePower == Enum_ArticlePower.Public) { model.ArticlePower = Enum_ArticlePower.Myself; } if (string.IsNullOrWhiteSpace(model.Title)) { model.Title = "我的小微篇"; } result = db.Update <Article>(model) > 0; //取消自定义模板启用 if (model.Template != 1) { var list = db.Find <Background>(x => x.ArticleNumber == model.Number && x.IsUsed == Enum_Used.Approved).ToList(); if (list.Count > 0) { list.ForEach(x => { x.IsUsed = Enum_Used.Audit; }); db.UpdateMany <Background>(list); } } ArticleType articleType = AppHelper.GetArticleType().FirstOrDefault <ArticleType>(x => x.ID == model.TypeID); model.TypeName = articleType == null ? string.Empty : articleType.Name; parts = SqlFilter(ZNRequest.GetString("Part").Trim(), false, false); if (!string.IsNullOrWhiteSpace(parts)) { List <PartJson> list = Newtonsoft.Json.JsonConvert.DeserializeObject <List <PartJson> >(parts); list.ForEach(x => { if (x.Status == 0) { //排序 var partid = Tools.SafeInt(x.ID); var part = db.Single <ArticlePart>(y => y.ID == partid); if (part != null) { part.SortID = Tools.SafeInt(x.SortID); db.Update <ArticlePart>(part); } } else if (x.Status == 1) { //新增 ArticlePart part = new ArticlePart(); part.ArticleNumber = model.Number; part.Types = x.PartType; part.Introduction = x.Introduction; part.IntroExpand = x.IntroExpand; part.SortID = Tools.SafeInt(x.SortID); part.Status = Enum_Status.Audit; part.CreateDate = DateTime.Now; part.CreateUserNumber = user.Number; part.CreateIP = Tools.GetClientIP; part.ID = Tools.SafeInt(db.Add <ArticlePart>(part)); } else if (x.Status == 2) { //编辑 var partid = Tools.SafeInt(x.ID); var part = db.Single <ArticlePart>(y => y.ID == partid); if (part != null) { part.Introduction = x.Introduction; part.IntroExpand = x.IntroExpand; part.SortID = Tools.SafeInt(x.SortID); db.Update <ArticlePart>(part); } } else if (x.Status == 3) { //是否临时删除删除 if (x.Temporary == 0) { db.Delete <ArticlePart>(x.ID); } } }); } } if (result) { //更新自定义漂浮 var ShowyUrl = ZNRequest.GetString("ShowyUrl"); var MusicID = ZNRequest.GetInt("MusicID"); var MusicName = ZNRequest.GetString("MusicName"); var MusicUrl = ZNRequest.GetString("MusicUrl"); ArticleCustom custom = db.Single <ArticleCustom>(x => x.ArticleNumber == model.Number); if (custom == null) { custom = new ArticleCustom(); custom.ArticleNumber = model.Number; } custom.ShowyUrl = ShowyUrl; custom.MusicID = MusicID; custom.MusicName = MusicName; custom.MusicUrl = MusicUrl; if (custom.ID == 0) { db.Add <ArticleCustom>(custom); } else { db.Update <ArticleCustom>(custom); } return(Json(new { result = true, message = new { ID = model.ID, Number = model.Number, ArticlePower = model.ArticlePower, ArticlePowerPwd = model.ArticlePowerPwd, TypeID = model.TypeID, TypeName = model.TypeName } }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { LogHelper.ErrorLoger.Error("ArticleController_Edit:" + ex.Message + "," + parts); } return(Json(new { result = false, message = "失败" }, JsonRequestBehavior.AllowGet)); }