Projects and Project Resources
Projects and Resource Collections
Beyond system-wide configuration data, the most common data used by modules is project-based resource objects, also known as resource collections. A project's resource collection will come from a RuntimeResourceCollection object and is usually modified through the Designer. Individual resources in a collection are identified by their resource type and module id. When a module defines a new project resource, it will define an instance of ResourceType.
In most cases, modules will want to load custom resource types. This can be accomplished by first setting up the lifecycle management of your project's resource collection. Implementing subclasses of ResourceCollectionLifecycleFactory and ResourceCollectionLifecycle in the Gateway scope will allow you to specify all relevant resource types for a project.
ResourceCollectionLifecycle will provide the method
getResourceCollection() for returning the RuntimeResourceCollection object of your project. Once the RuntimeResourceCollection object is retrieved, the individual resources can be accessed if needed using either getResources() or getAllResources().
The subclass of ResourceCollectionLifecycle provides various listeners for notifying the module when a project is added, removed, or modified.
Project Injection for Modules
The ProjectManager interface provides the function ProjectManager.addImmutableProject() for embedding immutable projects into modules. This allows custom modules to inject projects into the Gateway. The main purpose for this function is to allow module authors to package a project *.zip inside their *.modl file for specific client usage only.
Since these types of projects will be immutable, you can expect the following restrictions for injected projects in your custom modules:
- Cannot be edited
- Cannot change its enabled state
- Cannot be duplicated
- Cannot be renamed
- Cannot be opened in the Designer
- Cannot be exported
- Will not be included in Gateway backups
- Will not be synchronized across Redundancy channels
Example
This code example provides a solution for injecting the zipped Ignition project my-embedded-project.zip using ProjectManager.addImmutableProject() in the GatewayHook class's setup() method.
@Override
public void setup(GatewayContext gatewayContext) {
try (InputStream projBytes =
getClass().getClassLoader().getResourceAsStream("my-embedded-project.zip")) {
ProjectImport importedProj = ProjectFileUtil.importFromZip(projBytes, "MyProjectName");
gatewayContext.getProjectManager().addImmutableProject(importedProj);
} catch (IOException | ResourceCollectionInvalidException e) {
// handle error here
}
}