コード例 #1
0
ファイル: RantEngine.cs プロジェクト: polytronicgr/Rant
        /// <summary>
        /// Loads the specified package into the engine.
        /// </summary>
        /// <param name="package">The package to load.</param>
        public void LoadPackage(RantPackage package)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }
            if (_loadedPackages.Contains(RantPackageDependency.Create(package)))
            {
                return;
            }

            foreach (var dependency in package.GetDependencies())
            {
                if (!_resolver.TryResolvePackage(dependency, out RantPackage pkg))
                {
                    throw new FileNotFoundException(GetString("err-unresolvable-package", package, dependency));
                }
                LoadPackage(pkg);
            }

            foreach (var res in package.GetResources())
            {
                res.Load(this);
            }

            _loadedPackages.Add(RantPackageDependency.Create(package));
        }
コード例 #2
0
ファイル: RantEngine.cs プロジェクト: lzxkulou/Rant
        /// <summary>
        /// Loads the specified package into the engine.
        /// </summary>
        /// <param name="package">The package to load.</param>
        /// <param name="mergeBehavior">The table merging strategy to employ.</param>
        public void LoadPackage(RantPackage package, TableMergeBehavior mergeBehavior = TableMergeBehavior.Naive)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }
            if (_loadedPackages.Contains(RantPackageDependency.Create(package)))
            {
                return;
            }

            var patterns = package.GetPatterns();
            var tables   = package.GetTables();

            if (patterns.Any())
            {
                foreach (var pattern in patterns)
                {
                    _patternCache[pattern.Name] = pattern;
                    if (pattern.Module != null)
                    {
                        PackageModules[pattern.Name] = pattern.Module;
                    }
                }
            }

            if (tables.Any())
            {
                if (_dictionary == null)
                {
                    _dictionary = new RantDictionary(tables, mergeBehavior);
                }
                else
                {
                    foreach (var table in tables)
                    {
                        _dictionary.AddTable(table, mergeBehavior);
                    }
                }
            }

            _loadedPackages.Add(RantPackageDependency.Create(package));

            foreach (var dependency in package.GetDependencies())
            {
                RantPackage pkg;
                if (!_resolver.TryResolvePackage(dependency, out pkg))
                {
                    throw new FileNotFoundException($"Package '{package}' was unable to resolve dependency '{dependency}'");
                }
                LoadPackage(pkg, mergeBehavior);
            }
        }