Sharing Elements in the Catalog

  • Updated

Prerequisites: A valid RuleCatalogConnection and RuleApplicationDef object
Namespaces: InRule.Repository, InRule.Repository.Client, InRule.Repository.Service.Data
Classes: RuleCatalogConnection, RuleApplicationDef, EntityDef, RuleRepositoryDefBase
See Also: Working with RuleApplicationDef in the Catalog

The following examples demonstrate how to share and consume rule elements in the Catalog.

Sharing a rule set

// set ruleset shareable
catalogConn.SetShareableFlagForDef(ruleAppDef.Entities["Entity1"].RuleElements["RuleSet1"].Guid, true);

Consuming a shared rule set in an existing rule application

// Get source rule app
RuleApplicationDef sharedRuleApp = catalogConn.GetLatestRuleAppRevision("SharedRuleApp");

// Get rule set to consume from source rule app
RuleSetDef ruleSetDef = sharedRuleApp.Entities["Entity1"].GetRuleSet("RuleSet1");

// Get consuming rule app
RuleApplicationDef consumingRuleApp = catalogConn.GetLatestRuleAppRevision("ConsumingRuleApp");

// Check out the rule app container
catalogConn.CheckoutRuleApplication(consumingRuleApp, false, "checkout comments");

// Cet entity where rule set will be added
EntityDef entityDef = consumingRuleApp.Entities["Entity1"];

// Add shared rule set, using same Guids will create the share
entityDef.RuleElements.Add(ruleSetDef.CopyWithSameGuids());

// Check in the rule application
catalogConn.Checkin(consumingRuleApp, "check in comments");

Sharing a schema

// Share the schema so it can be consumed by other rule applications
catalogConn.SetShareableFlagForDef(sharedRuleApp.SchemaGuid, true);

Binding the shared schema to a rule application

// Bind the rule
catalogConn.SetMasterRuleAppForDef(sharedRuleApp.SchemaGuid, sharedRuleApp.Guid);

// Create new rule application that will consume the shared schema
RuleApplicationDef consumerRuleApp = new RuleApplicationDef("ConsumingRuleApp");

// Add the rule application to the Catalog
catalogConn.CreateRuleApplication(consumerRuleApp, consumerRuleApp.Name);

// Check out the rule application
catalogConn.CheckoutRuleApplication(consumerRuleApp, true, "checkout consumer ruleapp");

// Get all shared elements in the Catalog
ResultMap<DefInfo, DefInfo> shareableDefs = catalogConn.GetAllShareableDefs();

// Using a Linq query to find the schema we are interested in by name
DefInfo sharedSchemaDefInfo = (
  from d in shareableDefs.Keys
  where d.MasterRuleappName == "SharedRuleApp" &&
d.Key.DefType.Equals(
typeof(RuleApplicationSchemaDef))
  select d).First();

// Add the shared schema to the derived rule app
consumerRuleApp = catalogConn.ReplaceRuleAppSchema(consumerRuleApp, sharedSchemaDefInfo.Key);

// Check-in rule app
catalogConn.Checkin(consumerRuleApp, "Comments");

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.