<commit_before>﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Web.DynamicData;
using System.Web.Routing;
using DynamicData.EFCodeFirstProvider;

namespace NuGetGallery.Areas.Admin.DynamicData
{
    public class DynamicDataManager
    {
        [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "We do treat this as immutable.")]
        public static readonly MetaModel DefaultModel = new MetaModel() { DynamicDataFolderVirtualPath = "~/Areas/Admin/DynamicData" };

        private static DynamicDataRoute _route;
        
        public static void Register(RouteCollection routes, string root, IConfiguration configuration)
        {
            try
            {
                DefaultModel.RegisterContext(
                    new EFCodeFirstDataModelProvider(
                        () => new EntitiesContext(configuration.SqlConnectionString, readOnly: false)), // DB Admins do not need to respect read-only mode.
                        configuration: new ContextConfiguration { ScaffoldAllTables = true });
            }
            catch (SqlException e)
            {
                QuietlyLogException(e);
                return;
            }
            catch (DataException e)
            {
                QuietlyLogException(e);
                return;
            }

            // This route must come first to prevent some other route from the site to take over
            _route = new DynamicDataRoute(root + "/{table}/{action}")
            {
                Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
                Model = DefaultModel
            };
            routes.Insert(0, _route);
<commit_msg>Fixed unobtrusive validation in Dynamic Data admin section<commit_after>﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Web.DynamicData;
using System.Web.Routing;
using System.Web.UI;
using DynamicData.EFCodeFirstProvider;

namespace NuGetGallery.Areas.Admin.DynamicData
{
    public class DynamicDataManager
    {
        [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "We do treat this as immutable.")]
        public static readonly MetaModel DefaultModel = new MetaModel() { DynamicDataFolderVirtualPath = "~/Areas/Admin/DynamicData" };

        private static DynamicDataRoute _route;
        
        public static void Register(RouteCollection routes, string root, IConfiguration configuration)
        {
            // Set up unobtrusive validation
            InitializeValidation();

            // Set up dynamic data
            InitializeDynamicData(routes, root, configuration);
        }

        private static void InitializeValidation()
        {
            ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition()
            {
                Path = "~/Scripts/jquery-1.6.2.min.js",
                DebugPath = "~/Scripts/jquery-1.6.2.js"
            });
        }

        private static void InitializeDynamicData(RouteCollection routes, string root, IConfiguration configuration)
        {
            try
            {
                DefaultModel.RegisterContext(
                    new EFCodeFirstDataModelProvider(
                        () => new EntitiesContext(configuration.SqlConnectionString, readOnly: false)), // DB Admins do not need to respect read-only mode.
                        configuration: new ContextConfiguration { ScaffoldAllTables = true });
            }
            catch (SqlException e)
            {
                QuietlyLogException(e);
                return;
            }
            catch (DataException e)
            {
                QuietlyLogException(e);
                return;
            }

            // This route must come first to prevent some other route from the site to take over
            _route = new DynamicDataRoute(root + "/{table}/{action}")
            {
                Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
                Model = DefaultModel
            };
            routes.Insert(0, _route);

{'fraction_non_alphanumeric': 0.07807461999078766, 'fraction_numerical': 0.0036849378166743437, 'mean_word_length': 2.0977175463623396, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6955826', 'n_tokens_mistral': 1045, 'n_tokens_neox': 1009, 'n_words': 267}