<commit_before>/* Yet Another Forum.NET
 * Copyright (C) 2003-2005 <NAME>
 * Copyright (C) 2006-2011 <NAME>
 * http://www.yetanotherforum.net/
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
namespace YAF.Classes
{
  #region Using

  using System;
  using System.Collections.Specialized;
  using System.Text;
  using System.Web;
  using System.Web.Hosting;

  using YAF.Types;
  using YAF.Types.Interfaces;

  #endregion

  /// <summary>
  /// The base url builder.
  /// </summary>
  public abstract class BaseUrlBuilder : IUrlBuilder
  {
    #region Constants and Fields

    /// <summary>
    /// The _base urls.
    /// </summary>
    private static readonly StringDictionary _baseUrls = new StringDictionary();

    #endregion

    #region Properties

    /// <summary>
    /// Gets BaseUrl.
    /// </summary>
    /// <exception cref="BaseUrlMaskRequiredException">Since there is no active context, a base url mask is required. Please specify in the AppSettings in your web.config.</exception>
    public static string BaseUrl
    {
      get
      {
        string baseUrl;

        try
        {
          if (HttpContext.Current != null)
          {
            // Lookup the AppRoot based on the current path. 
            baseUrl = _baseUrls[HttpContext.Current.Request.FilePath];

            if (String.IsNullOrEmpty(baseUrl))
            {
              // Each different filepath (multiboard) will specify a AppRoot key in their own web.config in their directory.
              if (!String.IsNullOrEmpty(Config.BaseUrlMask))
              {
                baseUrl = TreatBaseUrl(Config.BaseUrlMask);
              }
              else
              {
                baseUrl = GetBaseUrlFromVariables();
              }

              // save to cache
              _baseUrls[HttpContext.Current.Request.FilePath] = baseUrl;
            }
          }
          else
          {<commit_msg>BaseUrlBuilder BaseUrl fix for Multiboard on seperate domains from one YAF Instance.<commit_after>/* Yet Another Forum.NET
 * Copyright (C) 2003-2005 <NAME>
 * Copyright (C) 2006-2011 <NAME>
 * http://www.yetanotherforum.net/
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
namespace YAF.Classes
{
  #region Using

  using System;
  using System.Collections.Specialized;
  using System.Text;
  using System.Web;
  using System.Web.Hosting;

  using YAF.Types;
  using YAF.Types.Interfaces;

  #endregion

  /// <summary>
  /// The base url builder.
  /// </summary>
  public abstract class BaseUrlBuilder : IUrlBuilder
  {
    #region Constants and Fields

    /// <summary>
    /// The _base urls.
    /// </summary>
    private static readonly StringDictionary _baseUrls = new StringDictionary();

    #endregion

    #region Properties

    /// <summary>
    /// Gets BaseUrl.
    /// </summary>
    /// <exception cref="BaseUrlMaskRequiredException">Since there is no active context, a base url mask is required. Please specify in the AppSettings in your web.config.</exception>
    public static string BaseUrl
    {
      get
      {
        string baseUrl;
        // urlKey requires SERVER_NAME in case of systems that use HostNames for seperate sites or in our cases Boards as well as FilePath for multiboards in seperate folders.
        var urlKey = String.Format("{0}{1}", HttpContext.Current.Request.ServerVariables["SERVER_NAME"], HttpContext.Current.Request.FilePath);
          
        try
        {
          if (HttpContext.Current != null)
          {
              
            // Lookup the AppRoot based on the current host + path. 
              baseUrl = _baseUrls[urlKey];

            if (String.IsNullOrEmpty(baseUrl))
            {
              // Each different filepath (multiboard) will specify a AppRoot key in their own web.config in their directory.
              if (!String.IsNullOrEmpty(Config.BaseUrlMask))
              {
                baseUrl = TreatBaseUrl(Config.BaseUrlMask);
              }
              else
              {
                baseUrl = GetBaseUrlFromVariables();
              }

              // save to cache
              _baseUrls[urlKey] = baseUrl;
            }
          }
          else
          {
{'fraction_non_alphanumeric': 0.08211249773919334, 'fraction_numerical': 0.011575330077771749, 'mean_word_length': 2.218859138533178, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4889084', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1417, 'n_words': 548}