Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions Developer Samples/CommandLineTools/PromoteRuleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using InRule.Repository.Client;
using InRule.Repository;
using System;
using InRule.Repository.Service.Data;
using Mono.Options;
using InRule.Runtime;

Expand All @@ -14,8 +15,10 @@ static int Main(string[] args)
bool showHelp = false;

string ruleAppName = null;
string label = "LIVE";
string comment = "";
string label = null;
string comment = null;
string applyLabelToSource = null;
string removeLabelFromSource = null;

string sourceCatalogUrl = null;
string sourceCatalogUsername = null;
Expand All @@ -30,6 +33,8 @@ static int Main(string[] args)
{ "n|RuleAppName=", "The name of the Rule App to promote.", n => ruleAppName = n },
{ "l|Label=", "Label assigned to the desired version of the Rule App.", l => label = l },
{ "m|Comment=", "Comment to be associated with the promotion commit.", c => comment = c },
{ "g|ApplyLabelToSource=", "Label to apply to source Rule App", l => applyLabelToSource = l },
{ "j|RemoveLabelFromSource=", "Label to remove from source Rule App", j => removeLabelFromSource = j},
//Source
{ "a|SrcCatUri=", "Web URI for the source IrCatalog Service endpoint.", c => sourceCatalogUrl = c },
{ "b|SrcCatUser=", "IrCatalog Username for authentication .", u => sourceCatalogUsername = u },
Expand Down Expand Up @@ -64,19 +69,20 @@ static int Main(string[] args)
}
else
{
var sourceCatCon = new RuleCatalogConnection(new Uri(sourceCatalogUrl), TimeSpan.FromSeconds(60), sourceCatalogUsername, sourceCatalogPassword, RuleCatalogAuthenticationType.BuiltIn);

RuleApplicationDef sourceRuleAppDef = null;
try
{
CatalogRuleApplicationReference sourceRuleApp;
if (string.IsNullOrEmpty(label))
{
sourceRuleApp = new CatalogRuleApplicationReference(sourceCatalogUrl, ruleAppName, sourceCatalogUsername, sourceCatalogPassword);
sourceRuleAppDef = sourceCatCon.GetLatestRuleAppRevision(ruleAppName);
}
else
{
sourceRuleApp = new CatalogRuleApplicationReference(sourceCatalogUrl, ruleAppName, sourceCatalogUsername, sourceCatalogPassword, label);
var sourceRuleAppRef = sourceCatCon.GetRuleAppRef(ruleAppName);
sourceRuleAppDef = sourceCatCon.GetRuleAppByLabel(sourceRuleAppRef.Guid, label);
}
sourceRuleAppDef = sourceRuleApp.GetRuleApplicationDef();
}
catch (Exception ex)
{
Expand All @@ -88,8 +94,20 @@ static int Main(string[] args)
{
if (sourceRuleAppDef != null)
{
var destCatCon = new RuleCatalogConnection(new Uri(destCatalogUrl), TimeSpan.FromSeconds(60), destCatalogUsername, destCatalogPassword);
var promotedDef = destCatCon.PromoteRuleApplication(sourceRuleAppDef, comment);
var destCatCon = new RuleCatalogConnection(new Uri(destCatalogUrl), TimeSpan.FromSeconds(60), destCatalogUsername, destCatalogPassword, RuleCatalogAuthenticationType.BuiltIn);

destCatCon.PromoteRuleApplication(sourceRuleAppDef, comment);

if (!string.IsNullOrEmpty(applyLabelToSource))
{
sourceCatCon.ApplyLabel(sourceRuleAppDef, applyLabelToSource);
}

if (!string.IsNullOrEmpty(removeLabelFromSource))
{
sourceCatCon.RemoveLabel(sourceRuleAppDef.Guid, removeLabelFromSource);
}
Comment on lines +99 to +109

Console.WriteLine("Success!");
return 0;
}
Expand Down