Пример #1
0
        private bool DefaultProcessing(string libraryPath)
        {
            var files = Directory.EnumerateFiles(libraryPath, "*.os")
                        .Select(x => new { Name = Path.GetFileNameWithoutExtension(x), Path = x })
                        .Where(x => Utils.IsValidIdentifier(x.Name));

            bool hasFiles = false;

            LibraryResolver.TraceLoadLibrary(
                Locale.NStr($"ru = 'Обнаружено {files.Count()} модулей в библиотеке {libraryPath}';" +
                            $"en = 'Found {files.Count()} modules in library {libraryPath}'")
                );

            foreach (var file in files)
            {
                LibraryResolver.TraceLoadLibrary(
                    Locale.NStr($"ru = 'Загружаю модуль библиотеки из {file.Path}';" +
                                $"en = 'Load library module from {file.Path}'")
                    );
                hasFiles = true;
                AddModule(file.Path, file.Name);
            }

            return(hasFiles);
        }
Пример #2
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);
            }
        }
Пример #3
0
        public bool ProcessLibrary(string libraryPath)
        {
            bool success;

            _delayLoadedScripts.Clear();

            if (!_customized)
            {
                LibraryResolver.TraceLoadLibrary(
                    Locale.NStr($"ru = 'Использую НЕ кастомизированный загрузчик пакетов по умолчанию для библиотеки {libraryPath}';" +
                                $"en = 'Use NOT customized package loader for library {libraryPath}'")
                    );

                success = DefaultProcessing(libraryPath);
            }
            else
            {
                LibraryResolver.TraceLoadLibrary(
                    Locale.NStr($"ru = 'Использую КАСТОМИЗИРОВАННЫЙ загрузчик пакетов для библиотеки {libraryPath}';" +
                                $"en = 'Use CUSTOMIZED package loader for library {libraryPath}'")
                    );

                success = CustomizedProcessing(libraryPath);
            }

            if (success)
            {
                var library = new ExternalLibraryDef(Path.GetFileName(libraryPath));
                CompileDelayedModules(library);
            }

            return(success);
        }
Пример #4
0
        public void InitExternalLibraries(string systemLibrary, IEnumerable<string> searchDirs)
        {
            var libLoader = new LibraryResolver(_engine, _env);
            _engine.DirectiveResolver = libLoader;

            libLoader.LibraryRoot = systemLibrary;
            libLoader.SearchDirectories.Clear();
            if (searchDirs != null)
            {
                libLoader.SearchDirectories.AddRange(searchDirs);
            }
        }
Пример #5
0
        public void InitExternalLibraries(string systemLibrary, IEnumerable <string> searchDirs)
        {
            var libLoader = new LibraryResolver(_engine, _env);

            _engine.DirectiveResolver = libLoader;

            libLoader.LibraryRoot = systemLibrary;
            libLoader.SearchDirectories.Clear();
            if (searchDirs != null)
            {
                libLoader.SearchDirectories.AddRange(searchDirs);
            }
        }