<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using SwaggerWcf.Models;
using SwaggerWcf.Support;
using System.Runtime.CompilerServices;

namespace SwaggerWcf
{
    public delegate Stream GetFileCustomDelegate(string filename, out string contentType, out long contentLength);

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class SwaggerWcfEndpoint : ISwaggerWcfEndpoint
    {
        public SwaggerWcfEndpoint()
        {
            Init(ServiceBuilder.Build);
        }

        internal SwaggerWcfEndpoint(Func<string, Service> buildService)
        {
            Init(buildService);
        }

        internal static Info Info { get; private set; }

        internal static SecurityDefinitions SecurityDefinitions { get; private set; }

        private static Dictionary<string, string> SwaggerFiles { get; } = new Dictionary<string, string>();

        public static bool DisableSwaggerUI { get; set; }

        public static Func<string, List<string>, List<string>> FilterVisibleTags { get; set; } =
            (string path, List<string> visibleTags) => visibleTags;

        public static Func<string, List<string>, List<string>> FilterHiddenTags { get; set; } =
            (string path, List<string> hiddenTags) => hiddenTags;

        public static void Configure(Info info, SecurityDefinitions securityDefinitions = null)
        {
            Info = info;
            SecurityDefinitions = securityDefinitions;
        }

        [MethodImpl(MethodImplOptions.Synchronized)]
        internal static void Init(Func<string, Service> buildService)
        {
            string[] paths = GetAllPaths().Where(p => !SwaggerFiles.Keys.Contains(p)).ToArray();
            
            foreach (string path in paths)
            {
                Service service = buildService(path);
                service.Info = Info;
                service.SecurityDefinitions = SecurityDefinitions;

                string swagger = Serializer.Process(service);
                if (SwaggerFiles.ContainsKey(path) == false)
                    SwaggerFiles.Add(path, swagger);
            }
        }

        private static string[] GetAllPaths()
        {<commit_msg>fix #125<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using SwaggerWcf.Models;
using SwaggerWcf.Support;
using System.Runtime.CompilerServices;

namespace SwaggerWcf
{
    public delegate Stream GetFileCustomDelegate(string filename, out string contentType, out long contentLength);

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class SwaggerWcfEndpoint : ISwaggerWcfEndpoint
    {
        public SwaggerWcfEndpoint()
        {
            Init(ServiceBuilder.Build);
        }

        internal SwaggerWcfEndpoint(Func<string, Service> buildService)
        {
            Init(buildService);
        }

        internal static Info Info { get; private set; }

        internal static SecurityDefinitions SecurityDefinitions { get; private set; }

        private static Dictionary<string, string> SwaggerFiles { get; } = new Dictionary<string, string>();

        public static bool DisableSwaggerUI { get; set; }

        public static Func<string, List<string>, List<string>> FilterVisibleTags { get; set; } =
            (string path, List<string> visibleTags) => visibleTags;

        public static Func<string, List<string>, List<string>> FilterHiddenTags { get; set; } =
            (string path, List<string> hiddenTags) => hiddenTags;

        public static void Configure(Info info, SecurityDefinitions securityDefinitions = null)
        {
            Info = info;
            SecurityDefinitions = securityDefinitions;
        }

        [MethodImpl(MethodImplOptions.Synchronized)]
        internal static void Init(Func<string, Service> buildService)
        {
            string[] paths = GetAllPaths().Where(p => !SwaggerFiles.Keys.Contains(p)).ToArray();
            
            foreach (string path in paths)
            {
                Service service = buildService(path);
                if (Info != null)
                    service.Info = Info;
                if (SecurityDefinitions != null)
                    service.SecurityDefinitions = SecurityDefinitions;

                string swagger = Serializer.Process(service);
                if (SwaggerFiles.ContainsKey(path) == false)
                    SwaggerFiles.Add(path, swagger);
            }
        }

        private static string[] GetAllPaths()
        {
{'fraction_non_alphanumeric': 0.08601057340382269, 'fraction_numerical': 0.0006100040666937779, 'mean_word_length': 2.6383136094674557, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 33, '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': '1349723', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1195, 'n_words': 313}