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;
            }
        }
示例#2
0
 /// <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);
示例#3
0
 public abstract string[] GetFileAttachments(Article article, EnabledStatus enabledStatus);
示例#4
0
 public abstract FileAttachment GetFileAttachmentByName(Article article, string name, bool throwIfNotFound);
示例#5
0
 /// <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);
            }
        }
示例#8
0
 public static void DeleteArticle(Article article)
 {
     Provider.DeleteArticle(article);
 }
示例#9
0
 /// <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;
 }
示例#10
0
 /// <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);
 }
示例#11
0
 public static FileAttachment CreateFileAttachment(Article article, string name, string contentType, byte[] contentData)
 {
     return Provider.CreateFileAttachment(article, name, contentType, contentData);
 }
示例#12
0
 public static string[] GetFileAttachments(Article article, EnabledStatus enabledStatus)
 {
     return Provider.GetFileAttachments(article, enabledStatus);
 }
示例#13
0
 public static FileAttachment GetFileAttachmentByName(Article article, string name, bool throwIfNotFound)
 {
     return Provider.GetFileAttachmentByName(article, name, throwIfNotFound);
 }
示例#14
0
 /// <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();
            }
        }
示例#16
0
 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;
            }
        }
示例#18
0
 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;
            }
        }
示例#20
0
 /// <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();
            }
        }
示例#22
0
 /// <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;
            }
        }
示例#24
0
 public FileAttachment(Article pArticle, string name, string contentType, byte[] contentData)
     : base(name, contentType, contentData)
 {
     Article = pArticle;
 }