<commit_before>﻿using BrailleIO.Interface;
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using System.Threading.Tasks;

namespace BrailleIO.Renderer
{
    /// <summary>
    /// Abstract implementation for renderer that allow for a caching. 
    /// This renderer can hold a prerendered result. If the content doesn't change and a 
    /// rendering request force them for a rendering, they will return the cached result 
    /// without any new rendering.
    /// </summary>
    /// <seealso cref="BrailleIO.Interface.BrailleIOHookableRendererBase" />
    /// <seealso cref="BrailleIO.Renderer.ICacheingRenderer" />
    /// <seealso cref="BrailleIO.Interface.IBrailleIORendererInterfaces" />
    public class AbstractCachingRendererBase : BrailleIOHookableRendererBase, ICacheingRenderer, IBrailleIORendererInterfaces
    {

        #region Members

        /// <summary>
        /// Gets or sets a value indicating whether [call hooks on rendering for caching].
        /// </summary>
        /// <value>
        /// <c>true</c> if [call hooks on rendering for caching]; otherwise, <c>false</c>.
        /// </value>
        public virtual bool CallHooksOnCacherendering { get; set; }

        /// <summary>
        /// The cached rendered result matrix
        /// </summary>
        protected bool[,] _cachedMatrix;

        /// <summary>
        /// The last view used for rendering.
        /// </summary>
        protected IViewBoxModel lastView;
        /// <summary>
        /// The last content
        /// </summary>
        protected object lastContent;

        /// <summary>
        /// The rendering wait timeout in ms for checking if it is currently rendering.
        /// </summary>
        protected int renderingWaitTimeout = 5;

        /// <summary>
        /// The maximum attempts for waiting for completing the rendering.
        /// </summary>
        protected int maxRenderingWaitTrys = 10;

        #endregion

        #region ICacheingRenderer

        /// <summary>
        /// Gets or sets a value indicating whether content changed or not to check if a new rendering is necessary.
        /// You have to call the PrerenderMatrix function manually if you want to have a cached result.
        /// </summary>
        /// <value>
        ///   <c>true</c> if [content has changed]; otherwise, <c>false</c>.
        /// </value>
        public virtual bool ContentChanged { get; set; }

        /// <summary>
        /// Gets the time stamp for the last content rendering.
        /// </summary>
        /// <value>
        /// The last time stamp of content rendering rendered.
        /// </value>
        public virtual DateTime LastRendered { get; private set; }

        /// <summary>
        /// Gets a value indicating whether this instance is currently rendering.
        /// </summary>
        /// <value>
        /// <c>true</c> if this instance is currently rendering; otherwise, <c>false</c>.
        /// </value>
        public bool IsRendering { get; private set; }

        /// <summary>
        /// Informs the renderer that the content the or view has changed.
        /// You have to call the PrerenderMatrix function manually if you want to have a cached result.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="content">The content.</param>
        public virtual void ContentOrViewHasChanged(IViewBoxModel view, object content)
        {
            if (!ViewBoxModelEquals(lastView, view)) lastView = view; //Clone(view);
            lastContent = content;
            ContentChanged = true;
        }

        /// <summary>
        /// Renders the current content
        /// </summary>
        /// <param name="view"></param>
        /// <param name="content"></param>
        public virtual void PrerenderMatrix(IViewBoxModel view, object content)
        {
            int trys = 0;
            while (IsRendering && trys++ < maxRenderingWaitTrys) { Thread.Sleep(renderingWaitTimeout); }
            Task t = new Task(() =>
            {
                IsRendering = true;<commit_msg>change access modifier for abstarct chaching renderer member varaible<commit_after>﻿using BrailleIO.Interface;
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using System.Threading.Tasks;

namespace BrailleIO.Renderer
{
    /// <summary>
    /// Abstract implementation for renderer that allow for a caching. 
    /// This renderer can hold a prerendered result. If the content doesn't change and a 
    /// rendering request force them for a rendering, they will return the cached result 
    /// without any new rendering.
    /// </summary>
    /// <seealso cref="BrailleIO.Interface.BrailleIOHookableRendererBase" />
    /// <seealso cref="BrailleIO.Renderer.ICacheingRenderer" />
    /// <seealso cref="BrailleIO.Interface.IBrailleIORendererInterfaces" />
    public class AbstractCachingRendererBase : BrailleIOHookableRendererBase, ICacheingRenderer, IBrailleIORendererInterfaces
    {

        #region Members

        /// <summary>
        /// Gets or sets a value indicating whether [call hooks on rendering for caching].
        /// </summary>
        /// <value>
        /// <c>true</c> if [call hooks on rendering for caching]; otherwise, <c>false</c>.
        /// </value>
        public virtual bool CallHooksOnCacherendering { get; set; }

        /// <summary>
        /// The cached rendered result matrix
        /// </summary>
        protected bool[,] _cachedMatrix;

        /// <summary>
        /// The last view used for rendering.
        /// </summary>
        protected IViewBoxModel lastView;
        /// <summary>
        /// The last content
        /// </summary>
        protected object lastContent;

        /// <summary>
        /// The rendering wait timeout in ms for checking if it is currently rendering.
        /// </summary>
        protected int renderingWaitTimeout = 5;

        /// <summary>
        /// The maximum attempts for waiting for completing the rendering.
        /// </summary>
        protected int maxRenderingWaitTrys = 10;

        #endregion

        #region ICacheingRenderer

        /// <summary>
        /// Gets or sets a value indicating whether content changed or not to check if a new rendering is necessary.
        /// You have to call the PrerenderMatrix function manually if you want to have a cached result.
        /// </summary>
        /// <value>
        ///   <c>true</c> if [content has changed]; otherwise, <c>false</c>.
        /// </value>
        public virtual bool ContentChanged { get; set; }

        /// <summary>
        /// Gets the time stamp for the last content rendering.
        /// </summary>
        /// <value>
        /// The last time stamp of content rendering rendered.
        /// </value>
        public virtual DateTime LastRendered { get; protected set; }

        /// <summary>
        /// Gets a value indicating whether this instance is currently rendering.
        /// </summary>
        /// <value>
        /// <c>true</c> if this instance is currently rendering; otherwise, <c>false</c>.
        /// </value>
        public bool IsRendering { get; protected set; }

        /// <summary>
        /// Informs the renderer that the content the or view has changed.
        /// You have to call the PrerenderMatrix function manually if you want to have a cached result.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="content">The content.</param>
        public virtual void ContentOrViewHasChanged(IViewBoxModel view, object content)
        {
            if (!ViewBoxModelEquals(lastView, view)) lastView = view; //Clone(view);
            lastContent = content;
            ContentChanged = true;
        }

        /// <summary>
        /// Renders the current content
        /// </summary>
        /// <param name="view"></param>
        /// <param name="content"></param>
        public virtual void PrerenderMatrix(IViewBoxModel view, object content)
        {
            int trys = 0;
            while (IsRendering && trys++ < maxRenderingWaitTrys) { Thread.Sleep(renderingWaitTimeout); }
            Task t = new Task(() =>
            {
                IsRendering = true;
{'fraction_non_alphanumeric': 0.11527514231499052, 'fraction_numerical': 0.0009487666034155598, 'mean_word_length': 1.9830208701804033, 'pattern_counts': {'":': 0, '<': 115, '<?xml version=': 0, '>': 115, 'https://': 0, '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': '5034594', 'n_tokens_mistral': 2140, 'n_tokens_neox': 2074, 'n_words': 733}