private static void RegisterSimpleEnum(Type enumType, RuntimeEnvironment environment)
        {
            var enumTypeAttribute = (EnumerationTypeAttribute)enumType.GetCustomAttributes(typeof(EnumerationTypeAttribute), false)[0];

            var type = TypeManager.RegisterType("Перечисление" + enumTypeAttribute.Name, typeof(EnumerationContext));

            if (enumTypeAttribute.Alias != null)
            {
                TypeManager.RegisterAliasFor(type, "Enum" + enumTypeAttribute.Alias);
            }

            var enumValueType = TypeManager.RegisterType(enumTypeAttribute.Name, enumType);

            var instance = new EnumerationContext(type, enumValueType);

            var wrapperTypeUndefined = typeof(CLREnumValueWrapper <>);
            var wrapperType          = wrapperTypeUndefined.MakeGenericType(new Type [] { enumType });
            var constructor          = wrapperType.GetConstructor(new Type [] { typeof(EnumerationContext), enumType, typeof(DataType) });

            foreach (var field in enumType.GetFields())
            {
                foreach (var contextFieldAttribute in field.GetCustomAttributes(typeof(EnumItemAttribute), false))
                {
                    var contextField = (EnumItemAttribute)contextFieldAttribute;
                    var osValue      = (EnumerationValue)constructor.Invoke(new object [] { instance, field.GetValue(null), DataType.Enumeration });

                    if (contextField.Alias == null)
                    {
                        if (StringComparer
                            .InvariantCultureIgnoreCase
                            .Compare(field.Name, contextField.Name) != 0)
                        {
                            instance.AddValue(contextField.Name, field.Name, osValue);
                        }
                        else
                        {
                            instance.AddValue(contextField.Name, osValue);
                        }
                    }
                    else
                    {
                        instance.AddValue(contextField.Name, contextField.Alias, osValue);
                    }
                }
            }

            if (enumTypeAttribute.CreateGlobalProperty)
            {
                GlobalsManager.RegisterInstance(enumType, instance);
                environment.InjectGlobalProperty(instance, enumTypeAttribute.Name, true);
                if (enumTypeAttribute.Alias != null)
                {
                    environment.InjectGlobalProperty(instance, enumTypeAttribute.Alias, true);
                }
            }
        }
Example #2
0
        private static void RegisterSystemEnum(Type enumType, RuntimeEnvironment environment)
        {
            var method = enumType.GetMethod(INSTANCE_RETRIEVER_NAME, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
            
            System.Diagnostics.Trace.Assert(method != null, "System enum must have a static method " + INSTANCE_RETRIEVER_NAME);

            var instance = (IValue)method.Invoke(null, null);
            GlobalsManager.RegisterInstance(instance);
            var enumMetadata = (SystemEnumAttribute)enumType.GetCustomAttributes(typeof(SystemEnumAttribute), false)[0];
            environment.InjectGlobalProperty(instance, enumMetadata.GetName(), true);
            if(enumMetadata.GetAlias() != String.Empty)
                environment.InjectGlobalProperty(instance, enumMetadata.GetAlias(), true);
        }
Example #3
0
        public static void PrepareBgJobsEnvironment(IServiceProvider services, RuntimeEnvironment environment)
        {
            var hfOptions = services.GetService <IOptions <OscriptBackgroundJobsOptions> >().Value;

            if (hfOptions != null)
            {
                var jobsManager = new ScheduledJobsManagerContext(environment, services.GetService <DbContextProvider>());

                environment.InjectGlobalProperty(jobsManager, "РегламентныеЗадания", true);
                environment.InjectGlobalProperty(jobsManager, "ScheduledJobs", true);

                var bgJobsManager = new BackgroundJobsManagerContext(environment);
                environment.InjectGlobalProperty(bgJobsManager, "ФоновыеЗадания", true);
                environment.InjectGlobalProperty(bgJobsManager, "BackgroundJobs", true);
            }
        }
Example #4
0
        public void AddModule(string file, string moduleName)
        {
            if (!Utils.IsValidIdentifier(moduleName))
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            _delayLoadedScripts.Add(new DelayLoadedScriptData()
            {
                path       = file,
                identifier = moduleName,
                asClass    = false
            });

            try
            {
                LibraryResolver.TraceLoadLibrary(
                    Locale.NStr($"ru = 'Загружаю модуль ={moduleName}= в область видимости из файла {file}';" +
                                $"en = 'Load module ={moduleName}= in to context from file {file}'")
                    );
                _env.InjectGlobalProperty(null, moduleName, true);
            }
            catch (InvalidOperationException e)
            {
                // символ уже определен
                throw new RuntimeException(String.Format("Невозможно загрузить модуль {0}. Такой символ уже определен.", moduleName), e);
            }
        }
        private static void RegisterSystemEnum(Type enumType, RuntimeEnvironment environment)
        {
            var method = enumType.GetMethod(INSTANCE_RETRIEVER_NAME, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);

            System.Diagnostics.Trace.Assert(method != null, "System enum must have a static method " + INSTANCE_RETRIEVER_NAME);

            var instance = (IValue)method.Invoke(null, null);

            GlobalsManager.RegisterInstance(instance);
            var enumMetadata = (SystemEnumAttribute)enumType.GetCustomAttributes(typeof(SystemEnumAttribute), false)[0];

            environment.InjectGlobalProperty(instance, enumMetadata.GetName(), true);
            if (enumMetadata.GetAlias() != String.Empty)
            {
                environment.InjectGlobalProperty(instance, enumMetadata.GetAlias(), true);
            }
        }
Example #6
0
        public static void PrepareDbEnvironment(IServiceProvider services, RuntimeEnvironment environment)
        {
            var dbOptions = services.GetService <IOptions <OscriptDbOptions> >().Value;

            if (dbOptions != null && dbOptions.DbType != SupportedDatabase.Unknown)
            {
                var dbctx = services.GetService <ApplicationDbContext>();
                dbctx.Database.EnsureCreated();

                var userManager = new InfobaseUsersManagerContext(services);
                environment.InjectGlobalProperty(userManager, "ПользователиИнформационнойБазы", true);
                environment.InjectGlobalProperty(userManager, "InfoBaseUsers", true);

                var ib = new InfobaseContext();
                Infobase     = ib; // Костыль
                ib.DbContext = services.GetRequiredService <ApplicationDbContext>();
                environment.InjectGlobalProperty(ib, "ИнформационнаяБаза", true);
                environment.InjectGlobalProperty(ib, "InfoBase", true);
            }
        }
Example #7
0
        public void AddModule(string file, string moduleName)
        {
            if (!Utils.IsValidIdentifier(moduleName))
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            var compiler = _engine.GetCompilerService();
            var instance = (IValue)_engine.AttachedScriptsFactory.LoadFromPath(compiler, file);

            _env.InjectGlobalProperty(instance, moduleName, true);
        }
Example #8
0
        public void AddModule(string file, string moduleName)
        {
            if (!Utils.IsValidIdentifier(moduleName))
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            _delayLoadedScripts.Add(new DelayLoadedScriptData()
            {
                path       = file,
                identifier = moduleName,
                asClass    = false
            });

            try
            {
                _env.InjectGlobalProperty(null, moduleName, true);
            }
            catch (InvalidOperationException e)
            {
                // символ уже определен
                throw new RuntimeException(String.Format("Невозможно загрузить модуль {0}. Такой символ уже определен.", moduleName), e);
            }
        }
 public void InjectGlobalProperty(string name, IValue value, bool readOnly)
 {
     _env.InjectGlobalProperty(value, name, readOnly);
 }