/// <summary> /// Parses the comment file. /// </summary> /// <param name="file">The comment file.</param> private bool ParseComment(FileInfo file) { if (ValidateFile(file, Parser.Comment)) { var content = m_fileContent.ToString().Split('|'); var commentEntity = new PhpCommentEntity(); for (int i = 0; i < content.Length; i++) { switch (content[i]) { case "VERSION": try { commentEntity.Version = content[i + 1]; } catch { commentEntity.Version = string.Empty; } break; case "NAME": try { commentEntity.Name = ParseContent(content[i + 1]); } catch { commentEntity.Name = string.Empty; } break; case "DATE": try { commentEntity.Date = Convert.ToInt64(content[i + 1]); } catch { commentEntity.Date = 0; } break; case "CONTENT": try { commentEntity.Content = ParseContent(content[i + 1]); } catch { commentEntity.Content = string.Empty; } commentEntity.Content = commentEntity.Content.Replace(Environment.NewLine, "<br />"); break; case "EMAIL": try { commentEntity.Email = content[i + 1]; } catch { commentEntity.Email = string.Empty; } break; case "URL": try { commentEntity.Url = content[i + 1]; } catch { commentEntity.Url = string.Empty; } break; case "IP-ADDRESS": try { commentEntity.IpAddress = content[i + 1]; } catch { commentEntity.IpAddress = string.Empty; } break; case "MODERATIONFLAG": try { commentEntity.ModerationFlag = content[i + 1]; } catch { commentEntity.ModerationFlag = string.Empty; } break; } } if (m_commentEntries == null) { m_commentEntries = new List<PhpCommentEntity>(); } var phpCommentEntity = m_commentEntries.Find( item => item.Date == commentEntity.Date && item.Name == commentEntity.Name && item.Content == commentEntity.Content); if (phpCommentEntity == null) { m_commentEntries.Add(commentEntity); } return true; } return false; }
/// <summary> /// Converts the Simple PHP Comment entity to a WordPress Comment entity. /// </summary> /// <param name="commentEntity">The comment entity.</param> /// <returns></returns> private WpCommentEntity ConvertCommentEntity(PhpCommentEntity commentEntity) { var comment = new WpCommentEntity { ID = null, Agent = string.Empty, Approved = 1, Author = commentEntity.Name, Content = commentEntity.Content, Date = commentEntity.DateConverted, DateGmt = commentEntity.DateConverted.ToUniversalTime(), Karma = 0, Email = commentEntity.Email, IP = commentEntity.IpAddress, PostID = null, Type = "reply", Url = commentEntity.Url, UserID = null, ParentID = null }; return comment; }