public void VectorChanged_NonActionAdded_ExceptionThrown() { ActionCollection actionCollection = new ActionCollection(); actionCollection.Add(new StubAction()); Assert.ThrowsException <COMException>(() => actionCollection.Add(new Button())); }
public void VectorChanged_NonActionAdded_ExceptionThrown() { ActionCollection actionCollection = new ActionCollection(); actionCollection.Add(new StubAction()); TestUtilities.AssertThrowsException(() => actionCollection.Add(new Button())); }
public void AddActionTest() { var collection = new ActionCollection(); var action = new MockAction(); action.NameId = "someaction"; Assert.That(collection.Add(action)); Assert.That(collection.Add(action) == false); }
public ActionCollection GetInboundActions() { ActionCollection inboundActions = new ActionCollection(); inboundActions.Add(new Action("TourDetail", new string[0])); return(inboundActions); }
private void toolStripButton1_Click(object sender, EventArgs e) { if ((treeView1.SelectedNode.Tag as string) == "Root") { return; } if (!actions.Actions.ContainsKey(treeView1.SelectedNode.Text)) { return; } ActionCollection bin = actions.Actions[treeView1.SelectedNode.Text]; NewActionDialog dialog = new NewActionDialog(); if (dialog.ShowDialog(treeView1.SelectedNode.Text, actions.Variables) == DialogResult.OK) { bin.Add(dialog.SelectedAction); treeView1.SelectedNode.Nodes.Add(new TreeNode() { Text = dialog.SelectedAction.ClassName, Name = dialog.SelectedAction.ClassName, Tag = dialog.SelectedAction, }); treeView1.SelectedNode.Expand(); } }
public ActionCollection GetOutboundActions() { ActionCollection ac = new ActionCollection(); ac.Add(new Action("Search", new string[0])); return(ac); }
public ActionCollection GetOutboundActions() { ActionCollection _outboundActions = new ActionCollection(); _outboundActions.Add(new Action(BACK, new string[0])); return(_outboundActions); }
public ActionCollection GetInboundActions() { ActionCollection _inboundActions = new ActionCollection(); _inboundActions.Add(new Action("StaticContent", new string[0])); return(_inboundActions); }
public ActionCollection GetInboundActions() { ActionCollection inboundActions = new ActionCollection(); inboundActions.Add(new CMS.Core.Communication.Action("Sails", new string[0])); return(inboundActions); }
/// <summary> /// Default constructor. /// </summary> public SearchModule() { // Init inbound actions _inboundActions = new ActionCollection(); _inboundActions.Add(new Action("Search", new string[0])); _currentAction = _inboundActions[0]; }
public ActionCollection GetOutboundActions() { ActionCollection outBoundCollection = new ActionCollection(); outBoundCollection.Add(new Action("TourDetail", new string[0])); return(outBoundCollection); }
public void TieToWorld() { if (_document.Selection.IsEmpty() || _document.Selection.InFaceSelection) { return; } var entities = _document.Selection.GetSelectedObjects().OfType <Entity>().ToList(); var children = entities.SelectMany(x => x.GetChildren()).ToList(); var ac = new ActionCollection(); ac.Add(new Reparent(_document.Map.WorldSpawn.ID, children)); ac.Add(new Delete(entities.Select(x => x.ID))); _document.PerformAction("Tie to World", ac); }
public void ContainsActionTest2() { var collection = new ActionCollection(); var action = new MockAction(); action.NameId = "name"; collection.Add(action); Assert.That(collection.Contains("name")); }
public static void Main() { ActionCollection <string> ac = new ActionCollection <string>(Console.WriteLine); ac.Add("console"); //Action<string> messageTarget; ac = new ActionCollection <string>(ShowWindowsMessage); ac.Add("Show Windows Message"); }
public void ExecuteActions_MultipleActions_AllActionsExecuted() { ActionCollection actions = new ActionCollection(); actions.Add(new StubAction()); actions.Add(new StubAction()); actions.Add(new StubAction()); Button sender = new Button(); string parameterString = "TestString"; Interaction.ExecuteActions(sender, actions, parameterString); foreach (StubAction action in actions) { Assert.AreEqual(1, action.ExecuteCount, "Each IAction should be executed once."); Assert.AreEqual(sender, action.Sender, "Sender is passed to the actions."); Assert.AreEqual(parameterString, action.Parameter, "Parameter is passed to the actions."); } }
/// <summary> /// GalleryModule constructor. /// </summary> /// <param name="fileService">FileService dependency.</param> /// <param name="sessionManager">NHibernate session manager dependency.</param> public GalleryModule(IFileService fileService, ISessionManager sessionManager) { _fileService = fileService; _sessionManager = sessionManager; _gallerythemepath = UrlHelper.GetApplicationPath() + "Modules/Gallery/Css/"; _galleryPathBuilder = new GalleryPathBuilder(fileService); // Init inbound actions _inboundActions = new ActionCollection(); _inboundActions.Add(new Action("Album", new string[0])); _currentAction = _inboundActions[0]; }
private void RegisterActions() { actions.Add(new LoadAssemblyAction()); actions.Add(new UnloadAssemblyAction()); actions.Add(new DisassembleAction()); actions.Add(new GoBackAction()); actions.Add(new GoForwardAction()); actions.Add(new AnalyzeAction()); actions.Add(new VoidAction()); }
public ActionCollection GetOutboundActions() { ActionCollection outboundActions = new ActionCollection(); outboundActions.Add(new Action(ACTION_LIST, new string[0])); outboundActions.Add(new Action(ACTION_HOTEL_CONFIG, new string[0])); outboundActions.Add(new Action(ACTION_RESTAURANT_CONFIG, new string[0])); outboundActions.Add(new Action(ACTION_GUIDE_CONFIG, new string[0])); outboundActions.Add(new Action(ACTION_TRANSPORT_CONFIG, new string[0])); outboundActions.Add(new Action(ACTION_BOAT_CONFIG, new string[0])); outboundActions.Add(new Action(ACTION_ENTRANCEFEE_CONFIG, new string[0])); outboundActions.Add(new Action("Album", new string[0])); return(outboundActions); }
static RuleSet CreateRuleset(string rulesetName) { // create a simple rule // IF MySampleBusinessObject.MyValue != XMLdocument.ID // THEN MySampleBusinessObject.MySampleMethod1(5) //Creating the XML bindings on the SampleSchema XSD //Document Binding that binds to the schema name and specifies the selector XPathPair xp_root = new XPathPair("/*[local-name()='Root']", "Root"); XMLDocumentBinding xdb = new XMLDocumentBinding("SampleSchema", xp_root); //DocumentField Bindings that bind to the fields in the schema that need to be used in rule defintion XPathPair xp_ID = new XPathPair("/*[local-name()='Root']/*[local-name()='ID']", "ID"); XMLDocumentFieldBinding xfb1 = new XMLDocumentFieldBinding(Type.GetType("System.Int32"), xp_ID, xdb); //Creating .NET class (property and member) bindings // Class Bindings to bind to the class defintions whose properties and memebers will be used in rule defintion ClassBinding cb = new ClassBinding(typeof(Microsoft.Samples.BizTalk.BusinessRulesHelloWorld2.HelloWorld2Library.HelloWorld2LibraryObject)); // Member Bindings to bind to the properties and members in the MySampleBusinessObject class that need to be used in rule definition ClassMemberBinding myValue = new ClassMemberBinding("MyValue", cb); ArgumentCollection argList = new ArgumentCollection(); argList.Add(new Constant(5)); ClassMemberBinding method1 = new ClassMemberBinding("MySampleMethod", cb, argList); // create IF part LogicalExpression condition = new NotEqual(new UserFunction(myValue), new UserFunction(xfb1)); // create then part ActionCollection actions = new ActionCollection(); actions.Add(new UserFunction(method1)); // create the rule Rule rule1 = new Rule("rule1", 0, condition, actions); //create the verion information and ruleset description DateTime time = new DateTime(System.DateTime.Now.Year, System.DateTime.Now.Month, System.DateTime.Now.Day); VersionInfo vinf1 = new VersionInfo("Sample RuleSet to demonstrate the use of the Policy object", time, "BizRules", 1, 0); // create the ruleset RuleSet rs1 = new RuleSet(rulesetName, vinf1); rs1.Rules.Add(rule1); return(rs1); }
public override ActionCollection GetActions() { ActionCollection actions = base.GetActions(); var action = new ClientAction("viewitem", UIMessages.ViewItem, "window.open('{0}');return false;", this, this.PropertiesUrl) { IsDefault = true }; actions.Add(action); return(actions); }
private void Apply() { string actionText = null; var ac = new ActionCollection(); // Check if it's actually editing keyvalues if (_values != null) { var editAction = GetEditEntityDataAction(); if (editAction != null) { // The entity change is more important to show actionText = "Edit entity data"; ac.Add(editAction); } } var visgroupAction = GetUpdateVisgroupsAction(); if (visgroupAction != null) { // Visgroup change shows if entity data not changed if (actionText == null) { actionText = "Edit object visgroups"; } ac.Add(visgroupAction); } if (!ac.IsEmpty()) { // Run if either action shows changes Document.PerformAction(actionText, ac); } Class.BackColor = Color.White; }
public void CreateActionTest() { var collection = new ActionCollection(); var action = new MockAction(); action.NameId = "someaction"; collection.Add(action); var newAction = collection.Create("someaction"); Assert.AreEqual(action.NameId, newAction.NameId); Assert.AreEqual(action.ActionStatus, newAction.ActionStatus); Assert.AreEqual(action.InCooldown, newAction.InCooldown); Assert.AreNotEqual(action, newAction); }
private void toolStripButton1_Click(object sender, EventArgs e) { NewActionDialog dialog = new NewActionDialog(); if (dialog.ShowDialog(ActionContext, Variables) == DialogResult.OK) { BaseAction action = dialog.SelectedAction; actions.Add(action); ResetActionList(); } }
private void BuildMenus() { ActionCollection allItems = (this.DataSource as ActionCollection); if (allItems == null) { if ((this.ParentAction == null) || (this.ParentAction.ActionType != ActionType.Page)) { return; } allItems = m_ParentAction.GetAvailableChildActions(m_ActionIdList, m_IsFrameworkAdmin, m_IsAuthenticated); bool flag = false; if (MasterPage != null) { flag = (MasterPage.IsHomepage && ((!MasterPage.VisibleMainMenu) || allItems.Count == 0)); } if (flag || (this.VisibleSiblingItems.HasValue && this.VisibleSiblingItems.Value)) { ActionCollection siblingActions = new ActionCollection(); foreach (Micajah.Common.Bll.Action item in ActionProvider.PagesAndControls.GetAvailableSiblingActions(m_ParentAction)) { if (ActionProvider.ShowAction(item, m_ActionIdList, m_IsFrameworkAdmin, m_IsAuthenticated)) { siblingActions.Add(item); } } allItems.AddRange(siblingActions); } } if (allItems != null) { foreach (Micajah.Common.Bll.Action item in allItems) { if (item.ShowInDetailMenu) { m_PrimaryMenuItems.Add(item); } else { m_OtherMenuItems.Add(item); } } } }
/// <summary> /// Runs the transform on all the currently selected objects /// </summary> /// <param name="transformationName">The name of the transformation</param> /// <param name="transform">The transformation to apply</param> /// <param name="clone">True to create a clone before transforming the original.</param> private void ExecuteTransform(string transformationName, IUnitTransformation transform, bool clone) { if (clone) { transformationName += "-clone"; } var objects = Document.Selection.GetSelectedParents().ToList(); var name = String.Format("{0} {1} object{2}", transformationName, objects.Count, (objects.Count == 1 ? "" : "s")); var cad = new CreateEditDelete(); var action = new ActionCollection(cad); if (clone) { // Copy the selection, transform it, and reselect var copies = ClipboardManager.CloneFlatHeirarchy(Document, Document.Selection.GetSelectedObjects()).ToList(); foreach (var mo in copies) { mo.Transform(transform, Document.Map.GetTransformFlags()); if (Chisel.Settings.Select.KeepVisgroupsWhenCloning) { continue; } foreach (var o in mo.FindAll()) { o.Visgroups.Clear(); } } cad.Create(Document.Map.WorldSpawn.ID, copies); var sel = new ChangeSelection(copies.SelectMany(x => x.FindAll()), Document.Selection.GetSelectedObjects()); action.Add(sel); } else //NOTE(SVK): This is Move???? { // Transform the selection TransformFlags Flags = Document.Map.GetTransformFlags(); cad.Edit(objects, new TransformEditOperation(transform, Flags)); } // Execute the action Document.PerformAction(name, action); }
private static void ReadFromConfigurationDataSet(Action parent, DataRow[] actionRows, List <ActionType> allowedTypes, ActionCollection actions) { foreach (ConfigurationDataSet.ActionRow row in actionRows) { ActionType type = (ActionType)row.ActionTypeId; if (allowedTypes.Contains(type)) { Action item = CreateAction(row, parent); DataRow[] childActionRows = row.GetActionRows(); if (childActionRows.Length > 0) { ReadFromConfigurationDataSet(item, childActionRows, allowedTypes, actions); } if ((type == ActionType.Page) || (type == ActionType.GlobalNavigationLink)) { if (parent != null) { parent.ChildActions.Add(item); } actions.Add(item); } else if (type == ActionType.Control && parent != null) { parent.ChildControls.Add(item); } } } if (parent != null) { if (parent.ChildActions.Count > 1) { parent.ChildActions.Sort(); } } else if (actions.Count > 1) { actions.Sort(); } }
public void ExecuteActions_ActionsWithResults_ResultsInActionOrder() { string[] expectedReturnValues = { "A", "B", "C" }; ActionCollection actions = new ActionCollection(); foreach (string returnValue in expectedReturnValues) { actions.Add(new StubAction(returnValue)); } List <object> results = Interaction.ExecuteActions(null, actions, null).ToList(); Assert.AreEqual(expectedReturnValues.Length, results.Count, "Should have the same number of results as IActions."); for (int resultIndex = 0; resultIndex < results.Count; resultIndex++) { Assert.AreEqual(expectedReturnValues[resultIndex], results[resultIndex], "Results should be returned in the order of the actions in the ActionCollection."); } }
public void ScheduleRenewTask() { string taskName = $"Lets encrypt renew {CleanFileName(_options.HostName)}"; Log.Information($"Creating Task {taskName} with Windows Task scheduler at 9am every day."); DateTime now = DateTime.UtcNow; DateTime runtime = new DateTime(now.Year, now.Month, now.Day, 9, 0, 0, DateTimeKind.Utc); string currentExec = Assembly.GetExecutingAssembly().Location; // Create an action that will launch the app with the renew parameters whenever the trigger fires string actionString = $"\"{string.Join("\" \"", Environment.GetCommandLineArgs().Skip(1))}\" --renew"; using (TaskService taskService = new TaskService()) using (DailyTrigger trigger = new DailyTrigger { DaysInterval = 1, StartBoundary = runtime }) using (ExecAction action = new ExecAction(currentExec, actionString, Path.GetDirectoryName(currentExec))) using (TaskFolder rootFolder = taskService.RootFolder) using (TaskDefinition task = taskService.NewTask()) using (TaskRegistrationInfo reginfo = task.RegistrationInfo) using (TriggerCollection triggers = task.Triggers) using (ActionCollection actions = task.Actions) using (TaskPrincipal principal = task.Principal) { rootFolder.DeleteTask(taskName, false); reginfo.Description = $"Check for renewal of ACME certificates for {_options.HostName}."; triggers.Add(trigger); actions.Add(action); principal.RunLevel = TaskRunLevel.Highest; // need admin principal.LogonType = TaskLogonType.ServiceAccount; principal.UserId = "SYSTEM"; rootFolder.RegisterTaskDefinition(taskName, task); } }
public override void MouseDown(ViewportBase viewport, ViewportEvent e) { var vp = viewport as Viewport3D; if (vp == null || (e.Button != MouseButtons.Left && e.Button != MouseButtons.Right)) { return; } var behaviour = e.Button == MouseButtons.Left ? _form.GetLeftClickBehaviour(KeyboardState.Ctrl, KeyboardState.Shift, KeyboardState.Alt) : _form.GetRightClickBehaviour(KeyboardState.Ctrl, KeyboardState.Shift, KeyboardState.Alt); var ray = vp.CastRayFromScreen(e.X, e.Y); var hits = Document.Map.WorldSpawn.GetAllNodesIntersectingWith(ray).OfType <Solid>(); var clickedFace = hits.SelectMany(f => f.Faces) .Select(x => new { Item = x, Intersection = x.GetIntersectionPoint(ray) }) .Where(x => x.Intersection != null) .OrderBy(x => (x.Intersection - ray.Start).VectorMagnitude()) .Select(x => x.Item) .FirstOrDefault(); if (clickedFace == null) { return; } var faces = new List <Face>(); if (KeyboardState.Shift) { faces.AddRange(clickedFace.Parent.Faces); } else { faces.Add(clickedFace); } var firstSelected = Document.Selection.GetSelectedFaces().FirstOrDefault(); var firstClicked = faces.FirstOrDefault(face => !String.IsNullOrWhiteSpace(face.Texture.Name)); var ac = new ActionCollection(); var select = new ChangeFaceSelection( KeyboardState.Ctrl ? faces.Where(x => !x.IsSelected) : faces, KeyboardState.Ctrl ? faces.Where(x => x.IsSelected) : Document.Selection.GetSelectedFaces().Where(x => !faces.Contains(x))); Action lift = () => { if (firstClicked == null) { return; } var itemToSelect = Document.TextureCollection.GetItem(firstClicked.Texture.Name) ?? new TextureItem(null, firstClicked.Texture.Name, TextureFlags.Missing, 64, 64); Mediator.Publish(EditorMediator.TextureSelected, itemToSelect); }; switch (behaviour) { case SelectBehaviour.Select: ac.Add(select); break; case SelectBehaviour.LiftSelect: lift(); ac.Add(select); break; case SelectBehaviour.Lift: lift(); break; case SelectBehaviour.Apply: case SelectBehaviour.ApplyWithValues: var item = _form.GetFirstSelectedTexture(); if (item != null) { var texture = item.GetTexture(); ac.Add(new EditFace(faces, (document, face) => { face.Texture.Name = item.Name; face.Texture.Texture = texture; if (behaviour == SelectBehaviour.ApplyWithValues && firstSelected != null) { // Calculates the texture coordinates face.AlignTextureWithFace(firstSelected); } else if (behaviour == SelectBehaviour.ApplyWithValues) { face.Texture.XScale = _form.CurrentProperties.XScale; face.Texture.YScale = _form.CurrentProperties.YScale; face.Texture.XShift = _form.CurrentProperties.XShift; face.Texture.YShift = _form.CurrentProperties.YShift; face.SetTextureRotation(_form.CurrentProperties.Rotation); } else { face.CalculateTextureCoordinates(true); } }, true)); } break; case SelectBehaviour.AlignToView: var right = vp.Camera.GetRight(); var up = vp.Camera.GetUp(); var loc = vp.Camera.Location; var point = new Coordinate((decimal)loc.X, (decimal)loc.Y, (decimal)loc.Z); var uaxis = new Coordinate((decimal)right.X, (decimal)right.Y, (decimal)right.Z); var vaxis = new Coordinate((decimal)up.X, (decimal)up.Y, (decimal)up.Z); ac.Add(new EditFace(faces, (document, face) => { face.Texture.XScale = 1; face.Texture.YScale = 1; face.Texture.UAxis = uaxis; face.Texture.VAxis = vaxis; face.Texture.XShift = face.Texture.UAxis.Dot(point); face.Texture.YShift = face.Texture.VAxis.Dot(point); face.Texture.Rotation = 0; face.CalculateTextureCoordinates(true); }, false)); break; default: throw new ArgumentOutOfRangeException(); } if (!ac.IsEmpty()) { Document.PerformAction("Texture selection", ac); } }
/// <summary> /// Moves the run and check actions from the source ActionCollection to the destination ActionCollection /// </summary> private static void MoveActions(ActionCollection source, ActionCollection destination) { if ((source == null) || (destination == null)) return; for (int i = 0; i < source.Count; ++i) { if ((source[i] is ActionRun) || (source[i] is ActionCheck)) { destination.Add(source[i]); source.RemoveAt(i); --i; } } }
public void CreatePolicy() { //Creating XML document bindings on the Case XSD schema //Document Binding that binds to the schema name and specifies the selector XPathPair xp_root = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']", "Root"); XMLDocumentBinding xmlCase = new XMLDocumentBinding("Microsoft.Samples.BizTalk.LoansProcessor.Case", xp_root); //DocumentField Bindings that bind to the fields int the schema that are used in the defintion of "Income Rule" and the associated negation rule (the ELSE part) XPathPair xp_basicSalary = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='Income']/*[local-name()='BasicSalary']", "Income/BasicSalary"); XMLDocumentFieldBinding xmlCase_basicSalary = new XMLDocumentFieldBinding((Type.GetType("System.Int32")), xp_basicSalary, xmlCase); XPathPair xp_otherIncome = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='Income']/*[local-name()='OtherIncome']", "Income/OtherIncome"); XMLDocumentFieldBinding xmlCase_otherIncome = new XMLDocumentFieldBinding(Type.GetType("System.Int32"), xp_otherIncome, xmlCase); Constant c1 = new Constant("Income status is valid"); XPathPair xp_incomeStatus = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='IncomeStatus']", "IncomeStatus"); XMLDocumentFieldBinding xmlCase_incomeStatus = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_incomeStatus, xmlCase, c1); Constant c1_1 = new Constant("Income status is not valid"); XMLDocumentFieldBinding xmlCase_incomeStatusNegation = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_incomeStatus, xmlCase, c1_1); // Wrapping the XML bindings as User Functions UserFunction uf_basicSalary = new UserFunction(xmlCase_basicSalary); UserFunction uf_otherIncome = new UserFunction(xmlCase_otherIncome); UserFunction uf_incomeStatus = new UserFunction(xmlCase_incomeStatus); UserFunction uf_incomeStatusNegation = new UserFunction(xmlCase_incomeStatusNegation); // Condition 1: IF Basic Salary and Other Income > 0 Constant zero = new Constant(0); GreaterThan ge1 = new GreaterThan(uf_basicSalary, zero); GreaterThan ge2 = new GreaterThan(uf_otherIncome, zero); LogicalExpressionCollection andList4 = new LogicalExpressionCollection(); andList4.Add(ge1); andList4.Add(ge2); LogicalAnd la4 = new LogicalAnd(andList4); //Action 1 - THEN set Income Status in the incoming Case document to be Valid ActionCollection actionList1 = new ActionCollection(); actionList1.Add(uf_incomeStatus); /* Name: Income Rule * * Description: * IF Basic Salary and Other Income > 0 * THEN set Income Status in the incoming Case document to be Valid * */ Microsoft.RuleEngine.Rule r1 = new Microsoft.RuleEngine.Rule("Income Status Rule", la4, actionList1); //Negation of Income Rule LogicalNot ln1 = new LogicalNot(la4); ActionCollection actionList1_1 = new ActionCollection(); actionList1_1.Add(uf_incomeStatusNegation); Microsoft.RuleEngine.Rule r1_1 = new Microsoft.RuleEngine.Rule("Negation of Income Status Rule", ln1, actionList1_1); //Creating DB bindings on the NorthWind DB -> CustInfo table // DataRow Binding to bind to the Data Table, and provide the Data Set name (defaulting here to the DB name) DataConnectionBinding drb_CustInfo = new DataConnectionBinding("CustInfo", "Northwind"); // Column bindings to bind to the columns in the Data Table that need to be used in the Commitments Status Rule DatabaseColumnBinding col_ID = new DatabaseColumnBinding(Type.GetType("System.String"), "ID", drb_CustInfo); DatabaseColumnBinding col_creditCardBalance = new DatabaseColumnBinding(Type.GetType("System.Int32"), "CreditCardBalance", drb_CustInfo); // Creating the XML Document Field Bindings required in rule defintion XPathPair xp_ID = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='ID']", "ID"); XMLDocumentFieldBinding xmlCase_ID = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_ID, xmlCase); Constant c3 = new Constant("Compute Commitments"); XPathPair xp_commitmentsStatus = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='CommitmentsStatus']", "CommitmentsStatus"); XMLDocumentFieldBinding xmlCase_commitmentsStatus = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_commitmentsStatus, xmlCase, c3); // Wrapping the DB and XML bindings as User Functions UserFunction uf_xmlID = new UserFunction(xmlCase_ID); UserFunction uf_commitmentsStatus = new UserFunction(xmlCase_commitmentsStatus); UserFunction uf_dbID = new UserFunction(col_ID); UserFunction uf_balance = new UserFunction(col_creditCardBalance); //Condition 2 : IF the ID in the XML document is equal to the ID in the DB record, and the Credit Card Balance for that record is > 500 Equal eq2 = new Equal(uf_dbID, uf_xmlID); Constant c2 = new Constant(500); GreaterThan greaterThan = new GreaterThan(uf_balance, c2); LogicalExpressionCollection andList2 = new LogicalExpressionCollection(); andList2.Add(eq2); andList2.Add(greaterThan); LogicalAnd la2 = new LogicalAnd(andList2); //Action 2 Set the Commitments Status field to "Compute Commitments" ActionCollection actionList2 = new ActionCollection(); actionList2.Add(uf_commitmentsStatus); /* Rule 2 - * Name: Commitments Rule * * IF the ID in the Document is = to the ID column in the DB * * AND * * IF Credit Card Balance > 500 * * Set Commitments Status in the XML document to be equal to "Compute Commitments" */ Microsoft.RuleEngine.Rule r2 = new Microsoft.RuleEngine.Rule("Commitments Status Rule", la2, actionList2); //Negation of Commitments Status Rule (the ELSE part) LogicalNot ln2 = new LogicalNot(greaterThan); LogicalExpressionCollection andList2negation = new LogicalExpressionCollection(); andList2negation.Add(eq2); andList2negation.Add(ln2); LogicalAnd la2negation = new LogicalAnd(andList2negation); // Creating the XML Document Field Bindings required in rule defintion Constant ignore_string = new Constant("Ignore Commitments"); XMLDocumentFieldBinding xmlCase_commitmentsStatusNegation = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_commitmentsStatus, xmlCase, ignore_string); UserFunction uf_commitmentsStatusNegation = new UserFunction(xmlCase_commitmentsStatusNegation); ActionCollection actionList2_1 = new ActionCollection(); actionList2_1.Add(uf_commitmentsStatusNegation); Microsoft.RuleEngine.Rule r2_1 = new Microsoft.RuleEngine.Rule("Negation of Commitments Rule", la2negation, actionList2_1); // Creating the XML Document Field Bindings required in the Employment Status rule XPathPair xp_employmentTime = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='EmploymentType']/*[local-name()='TimeInMonths']", "EmploymentType/TimeInMonths"); XMLDocumentFieldBinding xmlCase_employmentTime = new XMLDocumentFieldBinding(Type.GetType("System.Int32"), xp_employmentTime, xmlCase); UserFunction uf_employmentTime = new UserFunction(xmlCase_employmentTime); Constant action3 = new Constant("Employment Status is valid"); XPathPair xp_employmentStatus = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='EmploymentStatus']", "EmploymentStatus"); XMLDocumentFieldBinding xmlCase_employmentStatus = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_employmentStatus, xmlCase, action3); UserFunction uf_employmentStatus = new UserFunction(xmlCase_employmentStatus); // Condition 3: IF Employment Time > 18 months Constant lengthOfEmployment = new Constant(18); GreaterThanEqual greaterThanEqual1 = new GreaterThanEqual(uf_employmentTime, lengthOfEmployment); //Action 3 - THEN set Employment Status in the incoming Case document to be Valid ActionCollection actionList3 = new ActionCollection(); actionList3.Add(uf_employmentStatus); /* Name: Employment Status Rule * * Description: * IF Time of Employment > 18 months * THEN set Employment Status in the incoming Case document to be Valid * */ Microsoft.RuleEngine.Rule r3 = new Microsoft.RuleEngine.Rule("Employment Status Rule", greaterThanEqual1, actionList3); // Negation of EmploymentStatus Rule (the ELSE part) LogicalNot ln3 = new LogicalNot(greaterThanEqual1); Constant empStatus_invalid = new Constant("Employment Status is Invalid"); XMLDocumentFieldBinding xmlCase_employmentStatusInvalid = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_employmentStatus, xmlCase, empStatus_invalid); UserFunction uf_employmentStatusInvalid = new UserFunction(xmlCase_employmentStatusInvalid); ActionCollection actionList3_1 = new ActionCollection(); actionList3_1.Add(uf_employmentStatusInvalid); Microsoft.RuleEngine.Rule r3_1 = new Microsoft.RuleEngine.Rule("Negation of Employment Status Rule", ln3, actionList3_1); // Creating the XML Document Field Bindings required in the Residence Status rule XPathPair xp_timeinResidence = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='PlaceOfResidence']/*[local-name()='TimeInMonths']", "PlaceOfResidence/TimeInMonths"); XMLDocumentFieldBinding xmlCase_timeinResidence = new XMLDocumentFieldBinding(Type.GetType("System.Int32"), xp_timeinResidence, xmlCase); UserFunction uf_timeinResidence = new UserFunction(xmlCase_timeinResidence); Constant lengthOfResidence = new Constant(3); Constant residencyStatus_valid = new Constant("Residency Status is valid"); XPathPair xp_residencyStatus = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='ResidencyStatus']", "ResidencyStatus"); XMLDocumentFieldBinding xmlCase_residencyStatus = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_residencyStatus, xmlCase, residencyStatus_valid); UserFunction uf_residencyStatus = new UserFunction(xmlCase_residencyStatus); // Condition 4: IF Time of residence >= 3 years GreaterThanEqual greaterThanEqual2 = new GreaterThanEqual(uf_timeinResidence, lengthOfResidence); //Action 3 - THEN set Resdiency Status in the incoming Case document to be Valid ActionCollection actionList4 = new ActionCollection(); actionList4.Add(uf_residencyStatus); /* Name: Residency Status Rule * * Description: * IF Time of Residency > 3 years * THEN set Residency Status in the incoming Case document to be Valid * */ Microsoft.RuleEngine.Rule r4 = new Microsoft.RuleEngine.Rule("Residency Status Rule", greaterThanEqual2, actionList4); // Negation of Residency Status Rule LogicalNot ln4 = new LogicalNot(greaterThanEqual2); Constant residencyStatus_Invalid = new Constant("Residency Status is Invalid"); XMLDocumentFieldBinding xmlCase_residencyStatusInvalid = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_residencyStatus, xmlCase, residencyStatus_Invalid); UserFunction uf_residencyStatusInvalid = new UserFunction(xmlCase_residencyStatusInvalid); ActionCollection actionList4_1 = new ActionCollection(); actionList4_1.Add(uf_residencyStatusInvalid); Microsoft.RuleEngine.Rule r4_1 = new Microsoft.RuleEngine.Rule("Negation of Residency Status Rule", ln4, actionList4_1); // Creation of the rule-set (policy) and saving it into the file rulestore // Creating configuration information (date, version, description, creator, policy name, and fact retriever used to retrieve the required datasets at runtime) DateTime time = new DateTime(System.DateTime.Today.Year, System.DateTime.Today.Month, System.DateTime.Today.Day); VersionInfo vinf1 = new VersionInfo("Rules to process Loan applications", time, "BizRules", 1, 0); RuleSet rs1 = new RuleSet("LoanProcessing", vinf1); RuleSetExecutionConfiguration rec1 = new RuleSetExecutionConfiguration(); Type factRetriever = typeof(myFactRetriever.DbFactRetriever); RuleEngineComponentConfiguration recc1 = new RuleEngineComponentConfiguration(factRetriever.Assembly.FullName, factRetriever.FullName); rec1.FactRetriever = recc1; rs1.ExecutionConfiguration = rec1; // Adding rules to the rule-set rs1.Rules.Add(r1); rs1.Rules.Add(r1_1); rs1.Rules.Add(r2); rs1.Rules.Add(r2_1); rs1.Rules.Add(r3); rs1.Rules.Add(r3_1); rs1.Rules.Add(r4); rs1.Rules.Add(r4_1); // Saving the rule-set (policy) to an XML file in the current directory FileRuleStore frs1 = new FileRuleStore("LoanProcessing.xml"); frs1.Add(rs1); // Publish and deploy the ruleset to rulestore DeployRuleSet(rs1); }