<commit_before>﻿using Microsoft.Owin.Hosting;
using Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;

namespace DrawShip.Viewer
{
    public class WebApiStartup
    {
        private static HttpConfiguration _configuation;
        private static List<string> _rootUrls;

        // This code configures Web API. The Startup class is specified as a type
        // parameter in the WebApp.Start method.
        public void Configuration(IAppBuilder appBuilder)
        {
            // Configure Web API for self-host.
            _configuation = new HttpConfiguration();
            _configuation.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "{directoryKey}/{fileName}/{format}/{version}",
                defaults: new
                {
                    controller = "Drawing",
                    format = DiagramFormat.Html,
                    version = RouteParameter.Optional
                }
            );

            _configuation.Routes.MapHttpRoute(
                name: "Index",
                routeTemplate: "",
                defaults: new
                {
                    controller = "Index"
                }
            );

            appBuilder.UseWebApi(_configuation);
        }

        public static IDisposable Start(IEnumerable<string> urls)
        {
            _rootUrls = urls.ToList();
            return WebApp.Start<WebApiStartup>(new StartOptions(urls.First()));
        }

        public static Uri FormatUrl(int workingDirectoryKey, string fileName, DiagramFormat format, string version, string routeName = "DefaultApi")
        {
            var route = _configuation.Routes[routeName];
            var allRouteValues = new Dictionary<string, object>
            {
                { "directoryKey", workingDirectoryKey },
                { "fileName", fileName },
                { "format", format },
                { "version", version }
            };
            var routeValues = _RemoveDefaults(allRouteValues, route.Defaults);
            var relativeUrl = route.RouteTemplate.Supplant(routeValues).RemoveAll("//");

            return new Uri(_rootUrls.First() + "/" + relativeUrl, UriKind.Absolute);
        }

        private static IReadOnlyDictionary<string, object> _RemoveDefaults(
            IReadOnlyDictionary<string, object> allRouteArgs,<commit_msg>Support multiple hostnames in the same instance<commit_after>﻿using Microsoft.Owin.Hosting;
using Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;

namespace DrawShip.Viewer
{
    public class WebApiStartup
    {
        private static HttpConfiguration _configuation;
        private static List<string> _rootUrls;

        // This code configures Web API. The Startup class is specified as a type
        // parameter in the WebApp.Start method.
        public void Configuration(IAppBuilder appBuilder)
        {
            // Configure Web API for self-host.
            _configuation = new HttpConfiguration();
            _configuation.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "{directoryKey}/{fileName}/{format}/{version}",
                defaults: new
                {
                    controller = "Drawing",
                    format = DiagramFormat.Html,
                    version = RouteParameter.Optional
                }
            );

            _configuation.Routes.MapHttpRoute(
                name: "Index",
                routeTemplate: "",
                defaults: new
                {
                    controller = "Index"
                }
            );

            appBuilder.UseWebApi(_configuation);
        }

        public static IDisposable Start(IEnumerable<string> urls)
        {
            _rootUrls = urls.ToList();

            var options = new StartOptions();
            _rootUrls.ForEach(url => options.Urls.Add(url));

            return WebApp.Start<WebApiStartup>(options);
        }

        public static Uri FormatUrl(int workingDirectoryKey, string fileName, DiagramFormat format, string version, string routeName = "DefaultApi")
        {
            var route = _configuation.Routes[routeName];
            var allRouteValues = new Dictionary<string, object>
            {
                { "directoryKey", workingDirectoryKey },
                { "fileName", fileName },
                { "format", format },
                { "version", version }
            };
            var routeValues = _RemoveDefaults(allRouteValues, route.Defaults);
            var relativeUrl = route.RouteTemplate.Supplant(routeValues).RemoveAll("//");

            return new Uri(_rootUrls.First() + "/" + relativeUrl, UriKind.Absolute);
        }

        private static IReadOnlyDictionary<string, object> _RemoveDefaults(
            IReadOnlyDictionary<string, object> allRouteArgs,
{'fraction_non_alphanumeric': 0.0868421052631579, 'fraction_numerical': 0.0, 'mean_word_length': 1.8169897377423032, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, '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': '2864007', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1170, 'n_words': 284}