<commit_before>using System;
using System.Collections.Generic;
using System.Web.Mvc;
using System.Xml;

/*
 * *ti*ny *si*mple web management system
 * (C) <NAME>, 2003-2015
 * 
 * This is free software.
 * License: MIT
*/

namespace mkcs.libtisiweb
{
	/*
	 * Base class for controller. Provides methods for handling fragment stores.
	*/
	public abstract class TisiController : Controller {
		public TisiController () {
			if (!string.IsNullOrEmpty(FragmentRepositoryXmlFile) && System.IO.File.Exists(FragmentRepositoryXmlFile)) {
				ReadXmlRepository();
			}
		}

		public string GetURIParameter(string parameter) {
			return this.ControllerContext.RouteData.GetRequiredString(parameter);
		}

		public string GetSubsetId()
		{
			return GetURIParameter("subset");
		}

		public string FragmentRepositoryXmlFile = "";

		public void ReadXmlRepository() {
			var doc = new XmlDocument();
			doc.Load(FragmentRepositoryXmlFile);
			ProcessRepositoryNodes(doc.SelectNodes("/pages/page"));
		}

		public void ProcessRepositoryNodes(XmlNodeList nodes) {
			if (nodes == null || nodes.Count == 0)
				return;
			string pageName = "", fragmentName = "", subsetId = "";
			foreach (XmlNode node in nodes) {
				pageName = node.Attributes["name"].Value;
				foreach (XmlNode nodeFragment in node.SelectNodes("fragment")) {
					fragmentName = nodeFragment.Attributes["name"].Value;
					foreach (XmlNode nodeSubset in nodeFragment.SelectNodes("subset")) {
						subsetId = nodeSubset.Attributes["lang"].Value;
						SetFragmentValue(pageName + "." + fragmentName, subsetId, nodeSubset.InnerText);
					}
				}
				ProcessRepositoryNodes(node.SelectNodes("page"));
			}
		}

		//protected Dictionary<string, Dictionary<string, string>> fragmentRepository = new Dictionary<string, Dictionary<string, string>>();
		protected Dictionary<string, IFragment> fragmentRepository = new Dictionary<string, IFragment>();

		/// <summary>
		/// Adds the fragment specified to the repository, if it doesn't exist yet, otherwise updates the fragment in the repository.
		/// </summary>
		/// <returns><c>true</c>, if fragment was added, <c>false</c> if fragment was updated.</returns>
		/// <param name="fragment">The fragment that should be added or updated.</param>
		protected bool AddFragment(IFragment fragment) {
			if (fragmentRepository.ContainsKey(fragment.Name)) {
				fragmentRepository[fragment.Name] = fragment;
				return false;
			}
			else {
				fragmentRepository.Add(fragment.Name, fragment);
				return true;
			}
		}

		protected string subset, pageTitle, pageShortTitle, pageLongTitle;

		protected override void Initialize (System.Web.Routing.RequestContext requestContext) {
			base.Initialize (requestContext);
			subset = GetSubsetId();
			var action = GetURIParameter("action");
			pageTitle = GetFragmentValue(action + ".title", subset);
			pageShortTitle = GetFragmentValue(action + ".shorttitle", subset);
			pageLongTitle = GetFragmentValue(action + ".longtitle", subset);
		}

		protected void SetFragmentValue(string fragmentName, string subset, string fragmentValue) {
			IFragment fragment;
			if (fragmentRepository.ContainsKey(fragmentName)) {
				fragment = fragmentRepository[fragmentName];
			}
			else {
				fragment = new Fragment();
				fragmentRepository.Add(fragmentName, fragment);
			}
			if (fragment.ContainsSubset(subset)) {
				fragment.Subsets[subset] = fragmentValue;
			}
			else {
				fragment.AddSubset(subset, fragmentValue);
			}
		}
<commit_msg>Some comments added<commit_after>using System;
using System.Collections.Generic;
using System.Web.Mvc;
using System.Xml;

/*
 * *ti*ny *si*mple web management system
 * (C) <NAME>, 2003-2015
 * 
 * This is free software.
 * License: MIT
*/

namespace mkcs.libtisiweb
{
	/*
	 * Base class for controller. Provides methods for handling fragment stores.
	*/
	public abstract class TisiController : Controller {
		public TisiController () {
		}
		
		protected Dictionary<string, IFragment> fragmentRepository = new Dictionary<string, IFragment>();
		protected string subset, pageTitle, pageShortTitle, pageLongTitle;

		/// <summary>
		/// Gets or sets the fragment repository XML file. If this property is set, the repository will be read immediately.
		/// </summary>
		/// <value>The fragment repository XML file.</value>
		public string FragmentRepositoryXmlFile {
			get;
			set {
				if (!string.IsNullOrEmpty(value) && System.IO.File.Exists(value)) {
					ReadXmlRepository();
				}
			}
		}

		/// <summary>
		/// Gets or sets the default subset that is used in case the desired subset is not available for a given fragment.
		/// </summary>
		/// <value>The default subset.</value>
		public string DefaultSubset { get; set; }
		
		public string GetURIParameter(string parameter) {
			return this.ControllerContext.RouteData.GetRequiredString(parameter);
		}

		public string GetSubsetId() {
			return GetURIParameter("subset");
		}

		public void ReadXmlRepository() {
			var doc = new XmlDocument();
			doc.Load(FragmentRepositoryXmlFile);
			ProcessRepositoryNodes(doc.SelectNodes("/pages/page"));
		}

		public void ProcessRepositoryNodes(XmlNodeList nodes) {
			if (nodes == null || nodes.Count == 0)
				return;
			string pageName = "", fragmentName = "", subsetId = "";
			foreach (XmlNode node in nodes) {
				pageName = node.Attributes["name"].Value;
				foreach (XmlNode nodeFragment in node.SelectNodes("fragment")) {
					fragmentName = nodeFragment.Attributes["name"].Value;
					foreach (XmlNode nodeSubset in nodeFragment.SelectNodes("subset")) {
						subsetId = nodeSubset.Attributes["lang"].Value;
						SetFragmentValue(pageName + "." + fragmentName, subsetId, nodeSubset.InnerText);
					}
				}
				ProcessRepositoryNodes(node.SelectNodes("page"));
			}
		}

		/// <summary>
		/// Adds the fragment specified to the repository, if it doesn't exist yet, otherwise updates the fragment in the repository.
		/// </summary>
		/// <returns><c>true</c>, if fragment was added, <c>false</c> if fragment was updated.</returns>
		/// <param name="fragment">The fragment that should be added or updated.</param>
		protected bool AddFragment(IFragment fragment) {
			if (fragmentRepository.ContainsKey(fragment.Name)) {
				fragmentRepository[fragment.Name] = fragment;
				return false;
			}
			else {
				fragmentRepository.Add(fragment.Name, fragment);
				return true;
			}
		}

		protected override void Initialize (System.Web.Routing.RequestContext requestContext) {
			base.Initialize (requestContext);
			subset = GetSubsetId();
			var action = GetURIParameter("action");
			pageTitle = GetFragmentValue(action + ".title", subset);
			pageShortTitle = GetFragmentValue(action + ".shorttitle", subset);
			pageLongTitle = GetFragmentValue(action + ".longtitle", subset);
		}

		protected void SetFragmentValue(string fragmentName, string subset, string fragmentValue) {
			IFragment fragment;
			if (fragmentRepository.ContainsKey(fragmentName)) {
				fragment = fragmentRepository[fragmentName];
			}
			else {
				fragment = new Fragment();
				fragmentRepository.Add(fragmentName, fragment);
			}
			if (fragment.ContainsSubset(subset)) {
				fragment.Subsets[subset] = fragmentValue;
			}
			else {
				fragment.AddSubset(subset, fragmentValue);
			}
		}

{'fraction_non_alphanumeric': 0.11747693155212781, 'fraction_numerical': 0.00247899738328054, 'mean_word_length': 4.046560111188326, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, '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': '2112675', 'n_tokens_mistral': 2341, 'n_tokens_neox': 1987, 'n_words': 526}