private void Delete() { // If the named rule has siblings, move to next named rule. int index = _parentContext.Children.IndexOf(this); Debug.Assert(index != -1, "Its parent must contain it."); //NOXLATE RuleBaseContext nextRule = null; if (index + 1 < _parentContext.Children.Count) // Try to get next sibling { nextRule = _parentContext.Children.ElementAt(index + 1); } else if (index - 1 >= 0) // Try to get previous sibling { nextRule = _parentContext.Children.ElementAt(index - 1); } _parentContext.Children.Remove(this); int idx = _ruleConfigContext.SearchResult.IndexOf(this); if (idx != -1) { _ruleConfigContext.SearchResult.RemoveAt(idx); } _ruleConfigContext.IsDirty = true; if (nextRule != null) { nextRule.IsSelected = true; } }
private SortedDictionary <string, RuleBaseContext> GetWorkingSet() { SortedDictionary <string, RuleBaseContext> workingSet = new SortedDictionary <string, RuleBaseContext>(); Queue <RuleBaseContext> workingQueue = new Queue <RuleBaseContext>(); workingQueue.Enqueue(RootRulePoint); while (workingQueue.Count > 0) { RuleBaseContext theRuleContext = workingQueue.Dequeue(); string rulePath = theRuleContext.Path; if (!workingSet.ContainsKey(rulePath)) { workingSet.Add(rulePath, theRuleContext); } else { Debug.Assert(false, "There are rule points or named rules having duplicated rule path. This is not allowed. There must be something wrong."); //NOXLATE } RulePointContext rulePointContext = theRuleContext as RulePointContext; if (rulePointContext != null) { foreach (var ruleContext in rulePointContext.Children) { workingQueue.Enqueue(ruleContext); } } } return(workingSet); }
private void SelectRule(RuleBaseContext ruleContext) { if (ruleContext != null) { if (!ruleContext.IsSelected) { ruleContext.IsSelected = true; } } }
/// <summary> /// Search rules including rule points and named rules, and add searching /// result to SearchResult property. /// </summary> private void SearchRules(Stack <RuleBaseContext> workingBuffer) { const int MaxWorkload = 10; const int MaxSearchResultNumber = 1000; if (workingBuffer != _workingBuffer) { // System has started an another searching work by a new keyword. return; } int count = 0; while (workingBuffer.Count > 0 && count < MaxWorkload) { RuleBaseContext theContext = workingBuffer.Pop(); if (String.IsNullOrEmpty(SearchKeyword)) { _searchResult.Add(theContext); } else { // Call ToUpper() for search in case-insensitive way. if (theContext.DisplayName.ToUpper().Contains(SearchKeyword.ToUpper())) { _searchResult.Add(theContext); } } theContext.UpdateDisplayTexts(); // Add children into working queue if it has. RulePointContext rulePoint = theContext as RulePointContext; if (rulePoint != null) { foreach (var child in rulePoint.Children.Reverse()) // first child, first serve { workingBuffer.Push(child); } } ++count; } if (_workingBuffer.Count > 0 && _searchResult.Count < MaxSearchResultNumber) { Dispatcher.CurrentDispatcher.BeginInvoke( new Action <Stack <RuleBaseContext> >(SearchRules), DispatcherPriority.Background, workingBuffer); } }
private void RuleConfigContext_PropertyChanged(object sender, PropertyChangedEventArgs e) { RuleConfigContext context = sender as RuleConfigContext; Debug.Assert(context != null); if (e.PropertyName == "EditingRule") // NOXLATE { RuleBaseContext editingRule = context.EditingRule; if (editingRule == null) { DetachDesigner(); if (context.SelectedRule != null && context.SelectedRule is RulePointContext) { RulePointContext rpc = context.SelectedRule as RulePointContext; mDesignerViewContent.Content = rpc.CreateContentOperation; } else { mDesignerViewContent.Content = "TODO: show help doc here."; // NOXLATE } } else { RuleAppExtension.RuleDesignerManagerInst.UpdateDesignerAttributes(); _workflowDesigner = new WorkflowDesigner(); _workflowDesigner.Text = context.EditingRule.Text; _workflowDesigner.Load(); RuleEditingContext editingContext = context.EditingRule.GetEditingContext(); ServiceManager editingContextServices = _workflowDesigner.Context.Services; editingContextServices.Publish <RuleEditingContextService>(new RuleEditingContextService(editingContext)); editingContextServices.Publish <ActivityTranslator>(RuleAppExtension.ActivityTranslatorInst); editingContextServices.Publish <ActivityFactory>(RuleAppExtension.ActivityFactoryInst); _workflowDesigner.ModelChanged += new EventHandler(WorkflowDesigner_ModelChanged); if (_ruleDesigner == null) { _ruleDesigner = new InternalDesigner(); } _ruleDesigner.SetDesigner(_workflowDesigner); mDesignerViewContent.Content = _ruleDesigner; //mRulesTreeView.Focus(); } } }
/// <summary> /// Get RuleBaseContext instance by given path. /// </summary> /// <param name="path">The path of rule.</param> /// <returns>RuleBaseContext instance</returns> public RuleBaseContext GetRuleContext(string path) { if (String.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); // NOXLATE } RuleBaseContext iter = RootRulePoint; string[] pathItems = RulePathHelper.GetRulePathComponents(path); foreach (string component in pathItems) { RulePointContext rulePoint = iter as RulePointContext; if (rulePoint == null) { return(null); } iter = rulePoint.Children.FirstOrDefault((r) => (r.Name == component)) as RuleBaseContext; } return(iter); }