<commit_before>﻿using System;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Web.Hosting;

namespace Altairis.BinaryStore.FileSystem {

    public class FileSystemStoreProvider : StoreProvider {

        private const int DEFAULT_BUFFER_SIZE = 65536;
        private const string DEFAULT_CONTENT_TYPE = "application/octet-stream";
        private const string TYPE_SUFFIX = ".$type";

        private string folderName;
        private string defaultContentType = DEFAULT_CONTENT_TYPE;
        private int bufferSize = DEFAULT_BUFFER_SIZE;

        #region Initialization and configuration

        public int BufferSize
        {
            get { return bufferSize; }
            set {
                if (value < 1) throw new ConfigurationErrorsException("Buffer size must be positive integer.");
                bufferSize = value;
            }
        }

        public string DefaultContentType {
            get { return defaultContentType; }
            set {
                if (string.IsNullOrWhiteSpace(value)) throw new ConfigurationErrorsException("Invalid default content type.");

                defaultContentType = value; 
            }
        }

        public string FolderName {
            get { return folderName; }
            set {
                if (string.IsNullOrWhiteSpace(value)) throw new ConfigurationErrorsException("Required attribute \"folderName\" not set.");
                if (value.StartsWith("~/")) {
                    // Path is web root relative
                    if (System.Web.HttpContext.Current == null) throw new ConfigurationErrorsException("Can't set folderName to relative path outside of HTTP context.");
                    this.PhysicalFolderName = System.Web.HttpContext.Current.Server.MapPath(value).TrimEnd('\\');
                }
                else {
                    // Path is absolute
                    this.PhysicalFolderName = value.TrimEnd('\\');
                }

                // Try to create the data folder
                Directory.CreateDirectory(this.PhysicalFolderName);
<commit_msg>FileSystemProvider - virtual path is resolved event when the provider is first accessed from a background thread in ASP.NET application - HostingEnvironment.IsHosted and HostingEnvironment.ApplicationPhysicalPath is used instead of HttpContext.Current != null and HttpContext.Current.Request.PhysicalApplicationPath<commit_after>﻿using System;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Web.Hosting;

namespace Altairis.BinaryStore.FileSystem {

    public class FileSystemStoreProvider : StoreProvider {

        private const int DEFAULT_BUFFER_SIZE = 65536;
        private const string DEFAULT_CONTENT_TYPE = "application/octet-stream";
        private const string TYPE_SUFFIX = ".$type";

        private string folderName;
        private string defaultContentType = DEFAULT_CONTENT_TYPE;
        private int bufferSize = DEFAULT_BUFFER_SIZE;

        #region Initialization and configuration

        public int BufferSize
        {
            get { return bufferSize; }
            set {
                if (value < 1) throw new ConfigurationErrorsException("Buffer size must be positive integer.");
                bufferSize = value;
            }
        }

        public string DefaultContentType {
            get { return defaultContentType; }
            set {
                if (string.IsNullOrWhiteSpace(value)) throw new ConfigurationErrorsException("Invalid default content type.");

                defaultContentType = value; 
            }
        }

        public string FolderName {
            get { return folderName; }
            set {
                if (string.IsNullOrWhiteSpace(value)) throw new ConfigurationErrorsException("Required attribute \"folderName\" not set.");
                if (value.StartsWith("~/")) {
                    // Path is web root relative
                    if (!HostingEnvironment.IsHosted) 
                        throw new ConfigurationErrorsException("Can't set folderName to relative path outside of HTTP context.");
                    this.PhysicalFolderName = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, value).TrimEnd('\\');
                }
                else {
                    // Path is absolute
                    this.PhysicalFolderName = value.TrimEnd('\\');
                }

                // Try to create the data folder
                Directory.CreateDirectory(this.PhysicalFolderName);

{'fraction_non_alphanumeric': 0.07275132275132275, 'fraction_numerical': 0.0026455026455026454, 'mean_word_length': 2.071767095463778, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3312469', 'n_tokens_mistral': 1059, 'n_tokens_neox': 984, 'n_words': 301}