Esempio n. 1
0
        private bool ContainsDependency(ModuleRecipe dependency)
        {
            if (publicRecipeDependencies.Contains(dependency) || privateRecipeDependencies.Contains(dependency))
            {
                return(true);
            }

            else if (publicRecipeDependencies != null)
            {
                foreach (ModuleRecipe dep in publicRecipeDependencies)
                {
                    if (dep.ContainsDependency(dependency))
                    {
                        return(true);
                    }
                }
            }
            else if (privateRecipeDependencies != null)
            {
                foreach (ModuleRecipe dep in privateRecipeDependencies)
                {
                    if (dep.ContainsDependency(dependency))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Create all the recipe targets for this module
        /// </summary>
        public bool CreateRecipes(RecipeTarget[] targets)
        {
            recipeLookup = new Dictionary <RecipeTarget, ModuleRecipe>();

            foreach (RecipeTarget target in targets)
            {
                ModuleRecipe recipe = Activator.CreateInstance(recipeType, target) as ModuleRecipe;
                recipe.Initialise(this);
                recipeLookup[target] = recipe;
            }

            return(true);
        }
Esempio n. 3
0
        public void AddPrivateModuleDependency(ModuleRecipe dependency)
        {
            if (publicRecipeDependencies.Contains(dependency))
            {
                throw new Exception("Cannot have both public and private dependency for " + dependency.module.internalName + " in " + module.internalName);
            }

            // Detect circular dependencies
            if (dependency.ContainsDependency(this))
            {
                throw new Exception("Circular dependency detected between " + module.internalName + " and " + dependency.module.internalName);
            }

            privateRecipeDependencies.Add(dependency);
        }
Esempio n. 4
0
        public void AddCollection(ModuleCollection collection)
        {
            foreach (ModuleContainer container in collection.modules.Values)
            {
                ModuleRecipe recipe = container.GetRecipe(target);
                if (recipe == null)
                {
                    throw new Exception("ModuleRecipe is null");
                }

                if (moduleRecipes.ContainsKey(container.internalUrl))
                {
                    throw new Exception("Multiple module entries for " + container.internalUrl);
                }

                moduleRecipes[container.internalUrl] = recipe;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Attempt to load
        /// </summary>
        /// <param name="url">The url to the module.aethermod file</param>
        /// <param name="container">The container which will be created</param>
        /// <returns>True if the container is successfully loaded</returns>
        public static bool TryLoadFromFile(string url, out ModuleContainer container)
        {
            container         = new ModuleContainer();
            container.fileUrl = Path.GetFullPath(url);


            // Check file exists
            if (!File.Exists(container.fileUrl))
            {
                Logger.LogError("Unable to load ModuleContainer from path (Unable to locate): '" + container.fileUrl + "'");
                return(false);
            }

            // Load file info from aetherproj njox
            NjoxNode rootNode;

            if (!NjoxStatics.TryParseObject(File.ReadAllText(container.fileUrl), out rootNode))
            {
                Logger.LogError("Unable to load ModuleContainer from path (Unable to parse njox): '" + container.fileUrl + "'");
                return(false);
            }
            string mainDirectory = new FileInfo(container.fileUrl).Directory.FullName;


            if (rootNode.Properties.Length != 2)
            {
                Logger.LogError("Unable to load ModuleContainer from path (Expected root node Module <version_number>): '" + container.fileUrl + "'");
                return(false);
            }
            if (rootNode.PrimaryProperty.Key != "Module")
            {
                Logger.LogError("Unable to load ModuleContainer from path (Expected root node Module <version_number>): '" + container.fileUrl + "'");
                return(false);
            }

            float version;

            if (!rootNode.Properties[1].GetKeyAs <float>(out version) || version != 1.0f)
            {
                Logger.LogError("Unable to load ModuleContainer from path (Expected Module version to be 1.0): '" + container.fileUrl + "'");
                return(false);
            }


            // Read collection data
            if (!rootNode.HasChild("name"))
            {
                Logger.LogError("Unable to load ModuleContainer from path (Expected name node): '" + container.fileUrl + "'");
                return(false);
            }

            // Read internal and display name
            {
                var nameNode = rootNode.GetFirstChild("name");
                if (!nameNode.HasProperty("internal"))
                {
                    Logger.LogError("ModuleContainer node 'name' is missing required property 'internal': '" + container.fileUrl + "'");
                    return(false);
                }

                container.internalName = nameNode.GetFirstProperty("internal").Value;
                container.displayName  = container.internalName;

                if (nameNode.HasProperty("display"))
                {
                    container.displayName = nameNode.GetFirstProperty("display").Value;
                }
            }


            // Load recipe assembly for this module
            {
                // Load recipe assembly
                Assembly recipeAssembly;
                if (!ModuleRecipe.TryLoadAssembly(Path.Combine(mainDirectory, container.internalName + "ModuleRecipe.cs"), out recipeAssembly))
                {
                    Logger.LogError("Failed to compile ModuleRecipe for '" + container.fileUrl + "'");
                    return(false);
                }

                // Check required class exists
                container.recipeType = recipeAssembly.GetType(container.internalName + "ModuleRecipe");
                if (container.recipeType == null)
                {
                    Logger.LogError("ModuleRecipe is missing " + container.internalName + "ModuleRecipe class for '" + container.fileUrl + "'");
                    return(false);
                }
                if (!container.recipeType.IsSubclassOf(typeof(ModuleRecipe)))
                {
                    Logger.LogError("ModuleRecipe " + container.internalName + "ModuleRecipe class needs to extend from ModuleRecipe for '" + container.fileUrl + "'");
                    return(false);
                }
            }


            Logger.Log("ModuleContainer successfully loaded '" + container.fileUrl, 5);
            return(true);
        }