<commit_before>﻿/*
 * Copyright (c) 2017 <NAME>
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 * 
 * https://github.com/piranhacms/piranha.core
 * 
 */

using System;

namespace Piranha
{
    /// <summary>
    /// Class for easy access to built-in config parameters.
    /// </summary>
    public sealed class Config : IDisposable
    {
        #region Members
        /// <summary>
        /// The private api.
        /// </summary>
        private readonly IApi api;

        /// <summary>
        /// The system config keys.
        /// </summary>
        public static readonly string CACHE_EXPIRES_PAGES = "CacheExpiresPages";
        public static readonly string PAGES_HIERARCHICAL_SLUGS = "HierarchicalPageSlugs";
        public static readonly string MANAGER_EXPANDED_SITEMAP_LEVELS = "ManagerExpandedSitemapLevels";
        #endregion

        #region Properties
        /// <summary>
        /// Gets/sets the currently configured cache expiration
        /// in minutes for pages.
        /// </summary>
        public int CacheExpiresPages {
            get {
                var param = api.Params.GetByKey(CACHE_EXPIRES_PAGES);
                if (param != null)
                    return Convert.ToInt32(param.Value);
                return 0;
            }
            set {
                var param = api.Params.GetByKey(CACHE_EXPIRES_PAGES);
                if (param == null) {
                    param = new Data.Param() {
                        Key = CACHE_EXPIRES_PAGES
                    };
                }
                param.Value = value.ToString();
                api.Params.Save(param);
            }
        }

        /// <summary>
        /// Gets/sets if hierarchical slugs should be generated when
        /// creating new pages.
        /// </summary>
        public bool HierarchicalPageSlugs {
            get {
                var param = api.Params.GetByKey(PAGES_HIERARCHICAL_SLUGS);
                if (param != null)
                    return Convert.ToBoolean(param.Value);
                return true;
            }
            set {
                var param = api.Params.GetByKey(PAGES_HIERARCHICAL_SLUGS);
                if (param == null) {
                    param = new Data.Param() {
                        Key = PAGES_HIERARCHICAL_SLUGS
                    };
                }
                param.Value = value.ToString();
                api.Params.Save(param);
            }
        }

        /// <summary>
        /// Gets/sets the default number of expanded sitemap levels
        /// in the manager interface.
        /// </summary>
        public int ManagerExpandedSitemapLevels {
            get {
                var param = api.Params.GetByKey(MANAGER_EXPANDED_SITEMAP_LEVELS);
                if (param != null)
                    return Convert.ToInt32(param.Value);
                return 0;
            }
            set {
                var param = api.Params.GetByKey(MANAGER_EXPANDED_SITEMAP_LEVELS);
                if (param == null) {
                    param = new Data.Param() {
                        Key = MANAGER_EXPANDED_SITEMAP_LEVELS
                    };
                }
                param.Value = value.ToString();
                api.Params.Save(param);                
            }
        }
        #endregion

        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="api">The current api</param>
        public Config(IApi api) {
            this.api = api;
        }

        /// <summary>
        /// Disposes the config.
        /// </summary>
        public void Dispose() {
            GC.SuppressFinalize(this);
        }
    }
}<commit_msg>Fix for #133<commit_after>﻿/*
 * Copyright (c) 2017 <NAME>
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 * 
 * https://github.com/piranhacms/piranha.core
 * 
 */

using System;
using System.Data;

namespace Piranha
{
    /// <summary>
    /// Class for easy access to built-in config parameters.
    /// </summary>
    public sealed class Config : IDisposable
    {
        #region Members
        /// <summary>
        /// The private api.
        /// </summary>
        private readonly IApi api;

        /// <summary>
        /// The private transaction.
        /// </summary>
        private readonly IDbTransaction transaction;

        /// <summary>
        /// The system config keys.
        /// </summary>
        public static readonly string CACHE_EXPIRES_PAGES = "CacheExpiresPages";
        public static readonly string PAGES_HIERARCHICAL_SLUGS = "HierarchicalPageSlugs";
        public static readonly string MANAGER_EXPANDED_SITEMAP_LEVELS = "ManagerExpandedSitemapLevels";
        #endregion

        #region Properties
        /// <summary>
        /// Gets/sets the currently configured cache expiration
        /// in minutes for pages.
        /// </summary>
        public int CacheExpiresPages {
            get
            {
                var param = api.Params.GetByKey(CACHE_EXPIRES_PAGES, transaction);
                if (param != null)
                    return Convert.ToInt32(param.Value);
                return 0;
            }
            set {
                var param = api.Params.GetByKey(CACHE_EXPIRES_PAGES, transaction);
                if (param == null) {
                    param = new Data.Param() {
                        Key = CACHE_EXPIRES_PAGES
                    };
                }
                param.Value = value.ToString();
                api.Params.Save(param, transaction);
            }
        }

        /// <summary>
        /// Gets/sets if hierarchical slugs should be generated when
        /// creating new pages.
        /// </summary>
        public bool HierarchicalPageSlugs {
            get {
                var param = api.Params.GetByKey(PAGES_HIERARCHICAL_SLUGS, transaction);
                if (param != null)
                    return Convert.ToBoolean(param.Value);
                return true;
            }
            set {
                var param = api.Params.GetByKey(PAGES_HIERARCHICAL_SLUGS, transaction);
                if (param == null) {
                    param = new Data.Param() {
                        Key = PAGES_HIERARCHICAL_SLUGS
                    };
                }
                param.Value = value.ToString();
                api.Params.Save(param, transaction);
            }
        }

        /// <summary>
        /// Gets/sets the default number of expanded sitemap levels
        /// in the manager interface.
        /// </summary>
        public int ManagerExpandedSitemapLevels {
            get {
                var param = api.Params.GetByKey(MANAGER_EXPANDED_SITEMAP_LEVELS, transaction);
                if (param != null)
                    return Convert.ToInt32(param.Value);
                return 0;
            }
            set {
                var param = api.Params.GetByKey(MANAGER_EXPANDED_SITEMAP_LEVELS, transaction);
                if (param == null) {
                    param = new Data.Param() {
                        Key = MANAGER_EXPANDED_SITEMAP_LEVELS
                    };
                }
                param.Value = value.ToString();
                api.Params.Save(param, transaction);                
            }
        }
        #endregion

        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="api">The current api</param>
        /// <param name="tx"></param>
        public Config(IApi api, IDbTransaction tx = null) {
            this.api = api;
            this.transaction = tx;
        }

        /// <summary>
        /// Disposes the config.
        /// </summary>
        public void Dispose() {
            GC.SuppressFinalize(this);
        }
    }
}
{'fraction_non_alphanumeric': 0.09824120603015075, 'fraction_numerical': 0.0028894472361809045, 'mean_word_length': 1.2784773898111048, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4854920', 'n_tokens_mistral': 2153, 'n_tokens_neox': 2014, 'n_words': 493}