Customizing Scope Builder
Copy
Scope Builder is a server method that uses a predefined method template. The template enables customers to implement a Scope builder method. All of the Configurator Services API methods that perform actions in the context of Scope should be parameterized with the Scope object. The following is an example of the method template:
<Item type="Method” action="%action name%" %specific API attributes%>
<targetScope>
<Item type="Method” action="%builder method name%" %builder method attributes%>
%builder method properties%
</Item>
</targetScope>
%specific API properties%
</Item>
Implementing the Scope Builder Method
The Scope Builder method uses the CSharp:Aras.Server.Core.Configurator template to define a class that inherits from the base abstract class. The following is the template for the Scope builder method:
namespace $(pkgname)
{public class $(clsname): ScopeBuilderBase{$(MethodCode)}}
Base abstract class:public abstract class ScopeBuilderBase{public Item ScopeItem { get; set; }public IServerConnection IomConnection { get; private set; }public void Init(Item scopeItem, IServerConnection iomConnection) {}public abstract Scope BuildScope();public abstract string[] GetGuidsItemDependsOn();public abstract List<string> GetItemTypeNamesItemDependsOn();public abstract ArrayList GetCustomKey();}
The Scope Builder method is designed to provide a way for constructing a Scope object. The Scope Builder method also provides the built-in possibility to cache the Scope object.
Input Item Format
The targetScope Property enables you to specify the Scope builder method for Configurator Services API methods using AML syntax.
The syntax is as follows:<Item type="Method” action="%action name%" %specific API attributes%><targetScope><Item type="Method” action="%builder method name%" %builder method attributes%>%builder method properties%</Item></targetScope>%specific API properties%</Item>
Where:
| %action name% | Name of the action associated with the Configurator API method. |
| %specific API attribute% | List of API attributes specifically for a particular method. For example, “fetch” is an API attribute for the cfg_GetValidCombinations and cfg_GetConflicts methods. |
| %builder method name% | Name of the server method that builds the Scope object model based on the business logic being used. |
| %builder method attributes% | Attributes that are needed for the builder method to process a business Item. |
| %builder method properties% | Properties that are needed for the builder method to process the business item. |
| %specific API properties% | List of the API properties specific to a particular method. For example, the “condition” property is specific to the cfg_GetValidCombinations method. |
%specific API attributes% and %specific API properties% define the method signature that is specified in the action attribute.
%builder method attributes% and %builder method properties% should contain all the information that is necessary for building the Scope object.
Scope Resolver
Scope Resolver is an internal module that is used as part of the Scope Builder process. It is used to parse request AML, call for the Scope builder method, and cache the Scope builder method result. The following description is for information only, to make internal processing clearer:
public class ScopeResolverModule
{
public Scope BuildScope(Item item)
{
ScopeBuilderBase builder = GetBuilder(item);
builder.Init(item, this.serverConnection);
return this.cache.CacheDriverNotNull(
CachableScopeContainer.GetKey(builder.GetCustomKey()), list => CachableScopeContainer.GetInstance(builder, this.cacheItemType)).Scope;
}
private ScopeBuilderBase GetBuilder(Item scopeItem) { }
}
Caching
The Scope builder approach provides the built-in ability to cache a built Scope object. You need to override the CustomKey function in order to store and retrieve the scope object from the cache. This function should return the same ArrayList for each request to the same Scope object. To store a different cache for different Scope objects, the GetCustomKey function should return the different contents of the ArrayList:public override ArrayList GetCustomKey(){return new ArrayList {ScopeItem.getID(),};}
The Scope object can be invalidated automatically. You need to create the following collections to make this possible:
List of ItemType Names. This list contains the name of each Item Type that was used to build the Scope.
public override List<string> GetItemTypeNamesItemDependsOn(){return new List<string> {“ItemType1",“ItemType2",“ItemType3",“ItemType4"};}Each Item Type in this list should be a polysource item for ScopeCacheDependency.
- List of Item IDs. This list contains the ID of each Item that was used to build the Scope.
public override string[] GetGuidsItemDependsOn(){return new string[] {“item_id_color”,“item_id_red”,“item_id_wheelsize”,“item_id_17inch”};}