Prerequisites: A valid RuleCatalogConnection
Namespaces: InRule.Repository, InRule.Repository.Client, InRule.Repository.Service.Data
Classes: RuleCatalogConnection, RuleApplicationDef, RuleAppRef, RuleRepositoryDefBase
See Also: Creating a RuleCatalogConnection
The following examples demonstrate how to perform rollback functionality in the Catalog. The functionality does not perform a true rollback, instead it will save the previously desired rule application or rulse set back to the Catalog as the latest revision.
Rollback to a previous rule application
// Get a RuleAppRef object which will contain details about the rule app we are loading
RuleAppRef ruleAppRefLatest = connection.GetRuleAppRef("Historical");
// Get a RuleAppRef object which will contain details about the rule app we want to become the latest
RuleAppRef ruleAppRefPrior = connection.GetRuleAppRef("RuleAppRollback", 2);
// Load the RuleApplicationDef from the repository, specifying the GUID and Revision
RuleApplicationDef ruleAppDefPrior = connection.GetSpecificRuleAppRevision(ruleAppRefPrior.Guid, ruleAppRefPrior.PublicRevision);
// overwrite the existing rule app with the prior version
connection.OverwriteRuleApplication(ruleAppRefLatest.Guid, ruleAppDefPrior, true, "replacing latest with
prior version");
#endregion
Rollback to a previous rule set
// Get a RuleAppRef object which will contain details about the rule app we are loading
RuleAppRef ruleAppRefLatest = connection.GetRuleAppRef("InvoiceRollbackExample");
// Load the RuleApplicationDef from the repository, specifying the GUID and Revision
RuleApplicationDef ruleAppDefLatest = connection.GetSpecificRuleAppRevision(ruleAppRefLatest.Guid,
ruleAppRefLatest.PublicRevision);
// Get the RuleSet
EntityDef entityDefLatest = ruleAppDefLatest.Entities["LineItem"];
RuleRepositoryDefBase ruleSetDefLatest = entityDefLatest.GetRuleSet("LineItemRules");
// Check out the RuleApp
connection.CheckoutRuleApplication(ruleAppDefLatest, false, "checking out rule application");
// Get a RuleAppRef object which will contain details about the rule app we are loading
RuleAppRef ruleAppRefPrior = connection.GetRuleAppRef("InvoiceRollbackExample", 1);
// Load the RuleApplicationDef from the repository, specifying the GUID and Revision
RuleApplicationDef ruleAppDefPrior = connection.GetSpecificRuleAppRevision(ruleAppRefPrior.Guid, ruleAppRefPrior.PublicRevision);
// Get the RuleSet
EntityDef entityDefPrior = ruleAppDefPrior.Entities["LineItem"];
RuleRepositoryDefBase ruleSetDefPrior = entityDefPrior.GetRuleSet("LineItemRules");
// Remove the ruleset from the latest revision
entityDefLatest.RuleElements.Remove(ruleSetDefLatest);
// Add prior revision of the ruleset to the latest entity
entityDefLatest.RuleElements.Add(ruleSetDefPrior.Copy());
// Checkin the rule app
connection.Checkin(ruleAppDefLatest, "rolled back to prior revision of LineItemRules");
Comments
0 comments
Please sign in to leave a comment.