コード例 #1
0
ファイル: BlogService.cs プロジェクト: sebnilsson/Blaven
        public async Task<BlogMeta> GetBlogMeta(BlogKey blogKey = null)
        {
            var ensuredBlogKey = this.blogSettings.GetEnsuredBlogKey(blogKey);

            var meta = await this.repository.GetBlogMeta(ensuredBlogKey);
            return meta;
        }
コード例 #2
0
ファイル: BlogService.cs プロジェクト: sebnilsson/Blaven
        public async Task<BlogPost> GetPostBySourceId(string sourceId, BlogKey blogKey = null)
        {
            if (sourceId == null)
            {
                throw new ArgumentNullException(nameof(sourceId));
            }

            var ensuredBlogKey = this.blogSettings.GetEnsuredBlogKey(blogKey);

            var post = await this.repository.GetPostBySourceId(ensuredBlogKey, sourceId);
            return post;
        }
コード例 #3
0
ファイル: BlogSetting.cs プロジェクト: sebnilsson/Blaven
        public BlogSetting(BlogKey blogKey, string id = null, string name = null)
        {
            if (blogKey == null)
            {
                throw new ArgumentNullException(nameof(blogKey));
            }
            if (!blogKey.HasValue)
            {
                throw new ArgumentOutOfRangeException(nameof(blogKey), $"{nameof(Blaven.BlogKey)} must have a value.");
            }

            this.BlogKey = blogKey.Value;
            this.Id = id;
            this.Name = name;
        }
コード例 #4
0
        public BlogKey GetEnsuredBlogKey(BlogKey blogKey)
        {
            if (blogKey != null)
            {
                return blogKey;
            }

            string blogSettingsBlogKey = this.BlogKeys.FirstOrDefault();
            if (blogSettingsBlogKey == null)
            {
                string message = $"No default item found in {nameof(this.BlogKeys)}.";
                throw new KeyNotFoundException(message);
            }

            return blogSettingsBlogKey.ToLowerInvariant();
        }
コード例 #5
0
        public BlogSetting GetBlogSetting(BlogKey blogKey)
        {
            if (blogKey == null)
            {
                throw new ArgumentNullException(nameof(blogKey));
            }
            if (!blogKey.HasValue)
            {
                throw new ArgumentOutOfRangeException(nameof(blogKey), $"{nameof(BlogKey)} must have a value.");
            }

            var blogSetting =
                this.blogSettings.FirstOrDefault(x => x.BlogKey.Equals(blogKey.Value, StringComparison.OrdinalIgnoreCase));
            if (blogSetting == null)
            {
                string message = $"Settings did not contain any item with key '{blogKey.Value}'.";
                throw new KeyNotFoundException(message);
            }

            return blogSetting;
        }