<commit_before>﻿/*----------------------------------------------------------
This Source Code Form is subject to the terms of the 
Mozilla Public License, v.2.0. If a copy of the MPL 
was not distributed with this file, You can obtain one 
at http://mozilla.org/MPL/2.0/.
----------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;

namespace ScriptEngine.Machine.Contexts
{
    public class UserScriptContextInstance : ScriptDrivenObject
    {
        readonly LoadedModule _module;
        Dictionary<string, int> _ownPropertyIndexes;
        List<IValue> _ownProperties;

        private Func<string> _asStringOverride;
        
        public IValue[] ConstructorParams { get; private set; }
        
        static UserScriptContextInstance()
        {
            TypeManager.RegisterType("Сценарий", typeof(UserScriptContextInstance));
        }

        public UserScriptContextInstance(LoadedModule module) : base(module)
        {
            _module = module;
            ConstructorParams = new IValue[0];
        }

        public UserScriptContextInstance(LoadedModule module, string asObjectOfType, IValue[] args = null)
            : base(module, true)
        {
            DefineType(TypeManager.GetTypeByName(asObjectOfType));
            _module = module;

            ConstructorParams = args;
            if (args == null)
            {
                ConstructorParams = new IValue[0];
            }

        }

        protected override void OnInstanceCreation()
        {
            ActivateAsStringOverride();

            base.OnInstanceCreation();
            var methId = GetScriptMethod("ПриСозданииОбъекта", "OnObjectCreate");
            int constructorParamsCount = ConstructorParams.Count();

            if (methId > -1)
            {
                var procInfo = GetMethodInfo(methId);

                int procParamsCount = procInfo.Params.Count();

                int reqParamsCount = procInfo.Params.Count(x => !x.HasDefaultValue);

                if (constructorParamsCount != reqParamsCount)
                    throw new RuntimeException("Параметры конструктора: "
                        + "необходимых параметров: " + Math.Min(procParamsCount, reqParamsCount).ToString()
                        + ", передано параметров " + constructorParamsCount.ToString()
                        );

                CallAsProcedure(methId, ConstructorParams);
            }
            else
            {
                if (constructorParamsCount > 0)
                {
                    throw new RuntimeException("Конструктор не определен, но переданы параметры конструктора.");
                }<commit_msg>Проверка на заполнение фактических параметров<commit_after>﻿/*----------------------------------------------------------
This Source Code Form is subject to the terms of the 
Mozilla Public License, v.2.0. If a copy of the MPL 
was not distributed with this file, You can obtain one 
at http://mozilla.org/MPL/2.0/.
----------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;

namespace ScriptEngine.Machine.Contexts
{
    public class UserScriptContextInstance : ScriptDrivenObject
    {
        readonly LoadedModule _module;
        Dictionary<string, int> _ownPropertyIndexes;
        List<IValue> _ownProperties;

        private Func<string> _asStringOverride;
        
        public IValue[] ConstructorParams { get; private set; }
        
        static UserScriptContextInstance()
        {
            TypeManager.RegisterType("Сценарий", typeof(UserScriptContextInstance));
        }

        public UserScriptContextInstance(LoadedModule module) : base(module)
        {
            _module = module;
            ConstructorParams = new IValue[0];
        }

        public UserScriptContextInstance(LoadedModule module, string asObjectOfType, IValue[] args = null)
            : base(module, true)
        {
            DefineType(TypeManager.GetTypeByName(asObjectOfType));
            _module = module;

            ConstructorParams = args;
            if (args == null)
            {
                ConstructorParams = new IValue[0];
            }

        }

        protected override void OnInstanceCreation()
        {
            ActivateAsStringOverride();

            base.OnInstanceCreation();
            var methId = GetScriptMethod("ПриСозданииОбъекта", "OnObjectCreate");
            int constructorParamsCount = ConstructorParams.Count();

            if (methId > -1)
            {
                var procInfo = GetMethodInfo(methId);

                int procParamsCount = procInfo.Params.Count();

                int reqParamsCount = procInfo.Params.Count(x => !x.HasDefaultValue);

                if (constructorParamsCount < reqParamsCount || constructorParamsCount > procParamsCount)
                    throw new RuntimeException("Параметры конструктора: "
                        + "необходимых параметров: " + Math.Min(procParamsCount, reqParamsCount).ToString()
                        + ", передано параметров " + constructorParamsCount.ToString()
                        );

                for (int i = 0; i < procParamsCount; i++)
                    if (!procInfo.Params[i].HasDefaultValue && ConstructorParams.Count() - 1 < i)
                        throw RuntimeException.TooLittleArgumentsPassed();

                CallAsProcedure(methId, ConstructorParams);
            }
            else
            {
                if (constructorParamsCount > 0)
                {
                    throw new RuntimeException("Конструктор не определен, но переданы параметры конструктора.");
                }
{'fraction_non_alphanumeric': 0.11701201462650183, 'fraction_numerical': 0.003134250391781299, 'mean_word_length': 1.7430754536771729, 'pattern_counts': {'":': 0, '<': 12, '<?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': '4440382', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1395, 'n_words': 324}