public override Article CreateArticle(Category category, string owner, string name, string title, string description, string body) { using (TransactionScope transaction = new TransactionScope(mConfiguration)) { ArticleDataStore articleStore = new ArticleDataStore(transaction); if (articleStore.FindByName(name) != null) throw new ArticleNameAlreadyExistsException(name); CategoryDataStore dataStore = new CategoryDataStore(transaction); dataStore.Attach(category); Article article = new Article(category, name, owner, title, description, body); article.Author = owner; if (category.AutoApprove) article.Approved = true; articleStore.Insert(article); transaction.Commit(); return article; } }
/// <summary> /// Update the specified article. The current version is incremented if required. /// </summary> /// <param name="article"></param> /// <param name="backupVersion">If true the previous article version is saved as a backup in the VersionedArticle and the current version is incremented.</param> public abstract void UpdateArticle(Article article, bool backupVersion);
public abstract string[] GetFileAttachments(Article article, EnabledStatus enabledStatus);
public abstract FileAttachment GetFileAttachmentByName(Article article, string name, bool throwIfNotFound);
/// <summary> /// Returns the specified version of the article. If the version is equal the article.Version then the article is returned. /// </summary> /// <param name="article"></param> /// <param name="version"></param> /// <returns></returns> public static ArticleBase GetArticleByVersion(Article article, int version) { return Provider.GetArticleByVersion(article, version); }
/// <summary> /// Get a list of article versions (also with the latest version) /// </summary> /// <param name="article"></param> /// <returns></returns> public override IList<ArticleBase> GetArticleVersions(Article article) { using (TransactionScope transaction = new TransactionScope(mConfiguration)) { VersionedArticleDataStore dataStore = new VersionedArticleDataStore(transaction); IList<VersionedArticle> versionedArticles = dataStore.GetArticleVersions(article); List<ArticleBase> list = new List<ArticleBase>(); //Add the latest version list.Add(article); //add all the other versions foreach (VersionedArticle verArticle in versionedArticles) list.Add(verArticle); return list; } }
public override string[] GetFileAttachments(Article article, EnabledStatus enabledStatus) { using (TransactionScope transaction = new TransactionScope(mConfiguration)) { FileAttachmentDataStore dataStore = new FileAttachmentDataStore(transaction); return dataStore.GetArticleAttachments(article, enabledStatus); } }
public static void DeleteArticle(Article article) { Provider.DeleteArticle(article); }
/// <summary> /// Create a new versioned article from the specified article source /// </summary> /// <param name="source"></param> public VersionedArticle(Article source) : base(source) { this.Article = source; }
/// <summary> /// Update the specified article. The current version is incremented if required. /// </summary> /// <param name="article"></param> /// <param name="backupVersion">If true the previous article version is saved as a backup in the VersionedArticle and the current version is incremented.</param> public static void UpdateArticle(Article article, bool backupVersion) { Provider.UpdateArticle(article, backupVersion); }
public static FileAttachment CreateFileAttachment(Article article, string name, string contentType, byte[] contentData) { return Provider.CreateFileAttachment(article, name, contentType, contentData); }
public static string[] GetFileAttachments(Article article, EnabledStatus enabledStatus) { return Provider.GetFileAttachments(article, enabledStatus); }
public static FileAttachment GetFileAttachmentByName(Article article, string name, bool throwIfNotFound) { return Provider.GetFileAttachmentByName(article, name, throwIfNotFound); }
/// <summary> /// Get a list of article versions (also with the latest version) /// </summary> /// <param name="article"></param> /// <returns></returns> public static IList<ArticleBase> GetArticleVersions(Article article) { return Provider.GetArticleVersions(article); }
public override void DeleteArticle(Article article) { using (TransactionScope transaction = new TransactionScope(mConfiguration)) { ArticleDataStore dataStore = new ArticleDataStore(transaction); dataStore.Delete(article.Id); transaction.Commit(); } }
public abstract FileAttachment CreateFileAttachment(Article article, string name, string contentType, byte[] contentData);
/// <summary> /// Returns the specified version of the article. If the version is equal the article.Version then the article is returned. /// </summary> /// <param name="article"></param> /// <param name="version"></param> /// <returns></returns> public override ArticleBase GetArticleByVersion(Article article, int version) { if (article.Version == version) return article; using (TransactionScope transaction = new TransactionScope(mConfiguration)) { VersionedArticleDataStore dataStore = new VersionedArticleDataStore(transaction); VersionedArticle versionedArticle = dataStore.FindByArticleVersion(article, version); if (versionedArticle == null) throw new ArticleNotFoundException(article.Name + " " + version.ToString()); return versionedArticle; } }
public abstract void DeleteArticle(Article article);
public override FileAttachment GetFileAttachmentByName(Article article, string name, bool throwIfNotFound) { using (TransactionScope transaction = new TransactionScope(mConfiguration)) { FileAttachmentDataStore dataStore = new FileAttachmentDataStore(transaction); FileAttachment attachment = dataStore.FindByArticleVersion(article, name); if (attachment == null && throwIfNotFound) throw new FileAttachNotFoundException(article.Name + "." + name); else if (attachment == null) return null; return attachment; } }
/// <summary> /// Returns the specified version of the article. If the version is equal the article.Version then the article is returned. /// </summary> /// <param name="article"></param> /// <param name="version"></param> /// <returns></returns> public abstract ArticleBase GetArticleByVersion(Article article, int version);
/// <summary> /// Update the specified article. Increment the version if required. /// </summary> /// <param name="article"></param> /// <param name="backupVersion">If true the previous article version is saved as a backup in the VersionedArticle and the current version is incremented.</param> public override void UpdateArticle(Article article, bool backupVersion) { using (TransactionScope transaction = new TransactionScope(mConfiguration)) { ArticleDataStore dataStore = new ArticleDataStore(transaction); VersionedArticle versionedArticle = null; if (backupVersion) { //Retrive the previous version (before saving the new instance) and save a versioned row Article prevVersion = dataStore.FindByKey(article.Id); if (prevVersion == null) throw new ArticleNotFoundException(article.Id); versionedArticle = new VersionedArticle(prevVersion); VersionedArticleDataStore versionedStore = new VersionedArticleDataStore(transaction); versionedStore.Insert(versionedArticle); //Increment the current article version article.IncrementVersion(); } //flag the entity to be updated and attach the entity to the db // I must use InsertOrUpdateCopy because if backupVersion = true there is already a // persistent entity in the session and I must copy the values to this instance. The Update method in this case throw an exception article = dataStore.InsertOrUpdateCopy(article); transaction.Commit(); } }
/// <summary> /// Get a list of article versions (also with the latest version) /// </summary> /// <param name="article"></param> /// <returns></returns> public abstract IList<ArticleBase> GetArticleVersions(Article article);
public override FileAttachment CreateFileAttachment(Article article, string name, string contentType, byte[] contentData) { FileAttachment attachment = new FileAttachment(article, name, contentType, contentData); //Check attachment if (attachment != null) Attachment.FileHelper.CheckFile(attachment, article.Category.AttachExtensions, article.Category.AttachMaxSize); using (TransactionScope transaction = new TransactionScope(mConfiguration)) { ArticleDataStore dataStore = new ArticleDataStore(transaction); dataStore.Attach(article); FileAttachmentDataStore attachmentStore = new FileAttachmentDataStore(transaction); attachmentStore.Insert(attachment); transaction.Commit(); return attachment; } }
public FileAttachment(Article pArticle, string name, string contentType, byte[] contentData) : base(name, contentType, contentData) { Article = pArticle; }