internal override void LoadChildren() { if (this.PerfEventProvider != null) { this.PerfEventProvider.DesignerTreeViewLoadChildrenStart(); } base.LoadChildren(); if (this.Value.IsCollection) { ModelItemCollection mc = this.Value.Value as ModelItemCollection; TreeViewItemViewModel.AddModelItemCollection(this, mc, this.Value); } else if (this.Value.IsDictionary) { ModelItemDictionary dictionary = this.Value.Dictionary; TreeViewItemViewModel.AddModelItemDictionary(this, dictionary, this.Value); } else if (this.Value.Value != null) { TreeViewItemViewModel.AddChild(this, this.Value.Value, this.Value.Value, this.DuplicatedNodeVisible, string.Empty, this.Value); } if (this.PerfEventProvider != null) { this.PerfEventProvider.DesignerTreeViewLoadChildrenEnd(); } }
public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource) { ModelPropertyEntryToOwnerActivityConverter ownerActivityConverter = new ModelPropertyEntryToOwnerActivityConverter(); ModelItem activityItem = ownerActivityConverter.Convert(propertyValue.ParentProperty, typeof(ModelItem), false, null) as ModelItem; EditingContext context = activityItem.GetEditingContext(); ModelItem parentModelItem = ownerActivityConverter.Convert(propertyValue.ParentProperty, typeof(ModelItem), true, null) as ModelItem; ModelItemDictionary arguments = parentModelItem.Properties[propertyValue.ParentProperty.PropertyName].Dictionary; DynamicArgumentDesignerOptions options = new DynamicArgumentDesignerOptions { Title = propertyValue.ParentProperty.DisplayName }; using (ModelEditingScope change = arguments.BeginEdit("PowerShellParameterEditing")) { if (DynamicArgumentDialog.ShowDialog(activityItem, arguments, context, activityItem.View, options)) { change.Complete(); } else { change.Revert(); } } }
private void Button_Click_2(object sender, RoutedEventArgs e) { ModelItemDictionary dictionary = base.ModelItem.Properties["Arguments"].Dictionary; try { string form = ModelItem.GetValue <string>("Form"); var definition = Forge.Forms.FormBuilding.FormBuilder.Default.GetDefinition(form, freeze: false); foreach (DataFormField f in definition.GetElements().Where(x => x is DataFormField)) { bool exists = false; foreach (var key in dictionary.Keys) { if (key.ToString() == f.Key) { exists = true; } if (key.GetValue <string>("AnnotationText") == f.Key) { exists = true; } if (key.GetValue <string>("Name") == f.Key) { exists = true; } } if (!exists) { Type t = f.PropertyType; Type atype = typeof(VisualBasicValue <>); Type constructed = atype.MakeGenericType(t); object o = Activator.CreateInstance(constructed, f.Key); Argument a = null; a = Argument.Create(t, ArgumentDirection.InOut); dictionary.Add(f.Key, a); } } } catch (Exception) { } var options = new System.Activities.Presentation.DynamicArgumentDesignerOptions() { Title = "Map Arguments" }; using (ModelEditingScope modelEditingScope = dictionary.BeginEdit()) { if (System.Activities.Presentation.DynamicArgumentDialog.ShowDialog(base.ModelItem, dictionary, base.Context, base.ModelItem.View, options)) { modelEditingScope.Complete(); } else { modelEditingScope.Revert(); } } }
public override void ShowDialog(PropertyValue propertyValue, Windows.IInputElement commandSource) { ModelPropertyEntryToOwnerActivityConverter propertyEntryConverter = new ModelPropertyEntryToOwnerActivityConverter(); ModelItem parentModelItem = (ModelItem)propertyEntryConverter.Convert(propertyValue.ParentProperty, typeof(ModelItem), true, null); EditingContext context = ((IModelTreeItem)parentModelItem).ModelTreeManager.Context; ModelItemDictionary inputData = parentModelItem.Properties[propertyValue.ParentProperty.PropertyName].Dictionary; DynamicArgumentDesignerOptions options = new DynamicArgumentDesignerOptions(); options.Title = propertyValue.ParentProperty.DisplayName; DynamicArgumentDialog.ShowDialog(parentModelItem, inputData, context, parentModelItem.View, options); }
private void EditArgumentsBtn_Click(object sender, RoutedEventArgs e) { DynamicArgumentDesignerOptions options = new DynamicArgumentDesignerOptions { Title = "执行Python脚本文件参数设置" }; ModelItemDictionary dictionary = base.ModelItem.Properties["Arguments"].Dictionary; using (ModelEditingScope modelEditingScope = dictionary.BeginEdit("PythonScriptFileArgumentEditing")) { if (DynamicArgumentDialog.ShowDialog(base.ModelItem, dictionary, base.Context, base.ModelItem.View, options)) { modelEditingScope.Complete(); } else { modelEditingScope.Revert(); } } }
private void Button_Click(object sender, RoutedEventArgs e) { ModelItemDictionary dictionary = base.ModelItem.Properties["Arguments"].Dictionary; var options = new System.Activities.Presentation.DynamicArgumentDesignerOptions() { Title = "Map Arguments" }; using (ModelEditingScope modelEditingScope = dictionary.BeginEdit()) { if (System.Activities.Presentation.DynamicArgumentDialog.ShowDialog(base.ModelItem, dictionary, base.Context, base.ModelItem.View, options)) { modelEditingScope.Complete(); } else { modelEditingScope.Revert(); } } }
internal static void AddModelItemDictionary(TreeViewItemViewModel parent, ModelItemDictionary dictionary, ModelProperty trackingProperty) { parent.GetTracker(trackingProperty).AddCollection(dictionary); bool duplicatedNodeVisible = true; string childNodePrefix = string.Empty; ShowPropertyInOutlineViewAttribute viewChild = ExtensibilityAccessor.GetAttribute <ShowPropertyInOutlineViewAttribute>(trackingProperty); if (viewChild != null) { duplicatedNodeVisible = viewChild.DuplicatedChildNodesVisible; childNodePrefix = viewChild.ChildNodePrefix; } foreach (var pair in dictionary) { ModelItem item = null; //AddChild(parent, pair.Value, pair, duplicatedNodeVisible, trackingProperty); AddChild(parent, item, pair, duplicatedNodeVisible, childNodePrefix, trackingProperty); } }
private void RemoveDescription(ModelItemDictionary modelItem, string propertyFormat) { using (var change2 = modelItem.BeginEdit("ObjectEditing2")) { foreach (var p in modelItem.ToArray()) { //Убираем null object currentvalue; if (p.Value == null || (currentvalue = p.Value.GetCurrentValue()) == null || (currentvalue as Argument != null && ((Argument)currentvalue).Expression == null)) { modelItem.Remove(p.Key); continue; } //Убираем описание var key = p.Key.GetCurrentValue().To(string.Empty); var propertySubkey = string.Format(propertyFormat, GetProperty(key)); modelItem[propertySubkey] = p.Value; modelItem.Remove(p.Key); } change2.Complete(); } }
private void Button2_Click(object sender, RoutedEventArgs e) { if (ModelItem.Properties["workflow"].Value == null) { return; } string workflowid = (string)ModelItem.Properties["workflow"].Value.GetCurrentValue(); if (string.IsNullOrEmpty(workflowid)) { throw new ArgumentException("workflow property is null"); } var workflow = RobotInstance.instance.GetWorkflowByIDOrRelativeFilename(workflowid); var designer = RobotInstance.instance.Window.Designer; if (workflow == null) { throw new ArgumentException("workflow is null, not found"); } if (designer == null) { throw new ArgumentException("designer is null, cannot find current designer"); } ModelItemDictionary dictionary = base.ModelItem.Properties["Arguments"].Dictionary; try { workflow.ParseParameters(); } catch (Exception ex) { Log.Error(ex.ToString()); } foreach (var p in workflow.Parameters) { bool exists = false; foreach (var key in dictionary.Keys) { if (key.ToString() == p.name) { exists = true; } if (key.GetValue <string>("AnnotationText") == p.name) { exists = true; } if (key.GetValue <string>("Name") == p.name) { exists = true; } } if (!exists) { Type t = OpenRPA.Interfaces.Extensions.FindType(p.type); if (p.type == "System.Data.DataTable") { t = typeof(System.Data.DataTable); } if (t == null) { throw new ArgumentException("Failed resolving type '" + p.type + "'"); } //Type atype = typeof(VisualBasicValue<>); //Type constructed = atype.MakeGenericType(t); //object o = Activator.CreateInstance(constructed, p.name); //Log.Information("Checking for variable " + p.name + " of type " + p.type); //designer.GetVariable(p.name, t); Argument a = null; if (p.direction == workflowparameterdirection.@in) { a = Argument.Create(t, ArgumentDirection.In); } if (p.direction == workflowparameterdirection.inout) { a = Argument.Create(t, ArgumentDirection.InOut); } if (p.direction == workflowparameterdirection.@out) { a = Argument.Create(t, ArgumentDirection.Out); } // a.GetType().GetProperties().Where(x => x.Name == "Expression").Last().SetValue(a, o); //a.Expression = o as VisualBasicValue<>; dictionary.Add(p.name, a); } } foreach (var a in dictionary.ToList()) { bool exists = workflow.Parameters.Where(x => x.name == a.Key.ToString()).Count() > 0; if (!exists) { dictionary.Remove(a.Key); } } var options = new System.Activities.Presentation.DynamicArgumentDesignerOptions() { Title = "Map Arguments" }; using (ModelEditingScope modelEditingScope = dictionary.BeginEdit()) { if (System.Activities.Presentation.DynamicArgumentDialog.ShowDialog(base.ModelItem, dictionary, base.Context, base.ModelItem.View, options)) { modelEditingScope.Complete(); } else { modelEditingScope.Revert(); } } }
internal static void AddModelProperty(TreeViewItemViewModel parent, ModelItem item, ModelProperty trackingProperty, ModelProperty property) { //in the case of multiple attributes, they go in this order //HidePropertyInOutlineViewAttribute //[item.ShowInOutlineViewAttribute.PromotedProperty = property.Name]. Set VisualValue by property and ignore itself. Usage ActivityDelegate, FlowStep. //ShowPropertyInOutlineViewAttribute //ShowPropertyInOutlineViewAsSiblingAttribute //ShowInOutlineViewAttribute ShowPropertyInOutlineViewAttribute viewChild = ExtensibilityAccessor.GetAttribute <ShowPropertyInOutlineViewAttribute>(property); if (ExtensibilityAccessor.GetAttribute <HidePropertyInOutlineViewAttribute>(property) != null) { //ignore return; } else if (IsPromotedProperty(item, property)) { if (property.IsCollection) { ModelItemCollection mc = property.Value as ModelItemCollection; AddModelItemCollection(parent, mc, trackingProperty); } else if (property.IsDictionary) { ModelItemDictionary dictionary = property.Dictionary; AddModelItemDictionary(parent, dictionary, trackingProperty); } else { parent.GetTracker(trackingProperty).Add(item, property); //if property.Value is null, then this would not add any node // Use promoted ModelItem's property to track, so pass null to AddModelItem method. AddModelItem(parent, property.Value, null); } } else if (viewChild != null) { if (viewChild.CurrentPropertyVisible) //property node visible { if (property.Value != null) { TreeViewItemViewModel childModel = TreeViewItemViewModel.CreateViewModel(parent, property); childModel.DuplicatedNodeVisible = viewChild.DuplicatedChildNodesVisible; parent.AddChild(childModel, trackingProperty); } else { //just add the notification tracker without adding the empty child parent.GetTracker(trackingProperty, true).Add(item, trackingProperty); } } else { if (property.IsCollection) { ModelItemCollection mc = property.Value as ModelItemCollection; AddModelItemCollection(parent, mc, trackingProperty); } else if (property.IsDictionary) { ModelItemDictionary dictionary = property.Dictionary; AddModelItemDictionary(parent, dictionary, trackingProperty); } else { if (property.Value != null) { TreeViewItemViewModel childModel = TreeViewItemViewModel.CreateViewModel(parent, property.Value); childModel.DuplicatedNodeVisible = viewChild.DuplicatedChildNodesVisible; parent.AddChild(childModel, trackingProperty); } else { parent.GetTracker(trackingProperty).Add(item, property); } } } } else if (ExtensibilityAccessor.GetAttribute <ShowPropertyInOutlineViewAsSiblingAttribute>(property) != null) { //add notification to the tracker that is responsible for this node ChangeNotificationTracker tracker = parent.Parent.GetTracker(parent); tracker.Add(item, property); TreeViewItemViewModel siblingNode = null; if (property.Value != null) { siblingNode = TreeViewItemViewModel.CreateViewModel(parent.Parent, property.Value); } parent.Parent.AddChild(siblingNode, tracker.ParentProperty); } else if (ExtensibilityAccessor.GetAttribute <ShowInOutlineViewAttribute>(property) != null) { if (property.Value != null) { ShowInOutlineViewAttribute outlineView = ExtensibilityAccessor.GetAttribute <ShowInOutlineViewAttribute>(property); if (string.IsNullOrWhiteSpace(outlineView.PromotedProperty)) { parent.AddChild(TreeViewItemViewModel.CreateViewModel(parent, property), trackingProperty); } else { ModelProperty promotedProperty = property.Value.Properties.Find(outlineView.PromotedProperty); if (promotedProperty == null) { throw FxTrace.Exception.AsError(new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.PromotedPropertyNotFound, outlineView.PromotedProperty, property.Value.Name))); } // Add promoted ModelItem and property into tracker. So when property got changed, the grandparent of promoted ModelItem will be notified. ChangeNotificationTracker tracker = parent.GetTracker(trackingProperty, true); tracker.Add(property.Value, promotedProperty); if (promotedProperty.Value == null) { tracker.Add(item, property); } else { parent.AddChild(TreeViewItemViewModel.CreateViewModel(parent, property), trackingProperty); } } } else { parent.GetTracker(trackingProperty, true).Add(item, property); } } //if the values in the dictionary is viewvisible, note this only works with generic dictionary else if (property.IsDictionary && property.PropertyType.IsGenericType) { Type[] arguments = property.PropertyType.GetGenericArguments(); if (ExtensibilityAccessor.GetAttribute <ShowInOutlineViewAttribute>(arguments[1]) != null) { if (property.Value != null) { parent.AddChild(TreeViewItemViewModel.CreateViewModel(parent, property), trackingProperty); } else { parent.GetTracker(trackingProperty, true).Add(item, property); } } } }
internal static void AddModelItemDictionary(TreeViewItemViewModel parent, ModelItemDictionary dictionary, ModelProperty trackingProperty) { parent.GetTracker(trackingProperty).AddCollection(dictionary); bool duplicatedNodeVisible = true; string childNodePrefix = string.Empty; ShowPropertyInOutlineViewAttribute viewChild = ExtensibilityAccessor.GetAttribute<ShowPropertyInOutlineViewAttribute>(trackingProperty); if (viewChild != null) { duplicatedNodeVisible = viewChild.DuplicatedChildNodesVisible; childNodePrefix = viewChild.ChildNodePrefix; } foreach (var pair in dictionary) { ModelItem item = null; //AddChild(parent, pair.Value, pair, duplicatedNodeVisible, trackingProperty); AddChild(parent, item, pair, duplicatedNodeVisible, childNodePrefix, trackingProperty); } }
private void Button2_Click(object sender, RoutedEventArgs e) { string workflowid = ModelItem.GetValue <string>("workflow"); ModelItemDictionary dictionary = base.ModelItem.Properties["Arguments"].Dictionary; if (!string.IsNullOrEmpty(workflowid)) { var workflow = RobotInstance.instance.GetWorkflowByIDOrRelativeFilename(workflowid); var designer = RobotInstance.instance.Window.Designer; if (workflow != null) { try { workflow.ParseParameters(); } catch (Exception) { workflow = null; } } if (workflow != null) { foreach (var p in workflow.Parameters) { bool exists = false; foreach (var key in dictionary.Keys) { if (key.ToString() == p.name) { exists = true; } if (key.GetValue <string>("AnnotationText") == p.name) { exists = true; } if (key.GetValue <string>("Name") == p.name) { exists = true; } } if (!exists) { Type t = OpenRPA.Interfaces.Extensions.FindType(p.type); if (p.type == "System.Data.DataTable") { t = typeof(System.Data.DataTable); } if (t == null) { throw new ArgumentException("Failed resolving type '" + p.type + "'"); } Argument a = null; if (p.direction == workflowparameterdirection.@in) { a = Argument.Create(t, ArgumentDirection.In); } if (p.direction == workflowparameterdirection.inout) { a = Argument.Create(t, ArgumentDirection.InOut); } if (p.direction == workflowparameterdirection.@out) { a = Argument.Create(t, ArgumentDirection.Out); } // a.GetType().GetProperties().Where(x => x.Name == "Expression").Last().SetValue(a, o); //a.Expression = o as VisualBasicValue<>; dictionary.Add(p.name, a); } } foreach (var a in dictionary.ToList()) { bool exists = workflow.Parameters.Where(x => x.name == a.Key.ToString()).Count() > 0; if (!exists) { dictionary.Remove(a.Key); } } } } var options = new System.Activities.Presentation.DynamicArgumentDesignerOptions() { Title = ModelItem.GetValue <string>("DisplayName") }; using (ModelEditingScope modelEditingScope = dictionary.BeginEdit()) { if (System.Activities.Presentation.DynamicArgumentDialog.ShowDialog(base.ModelItem, dictionary, base.Context, base.ModelItem.View, options)) { modelEditingScope.Complete(); } else { modelEditingScope.Revert(); } } }
// Return HashSet containing ModelItems found only through given property: Cannot reach property.Parent without // hitting property from these immediate descendents of property.Value // Set may contain some internal duplication -- all nodes, not just the root, of a linked tree will be included // // Caveat 1: Due to problems removing Parents (e.g. Case content sometimes holds references to FlowSwitch after // Case removed), this method is not entirely reliable -- customers may occasionally need to reopen Designer // Caveat 2: Due to lazy loading of Properties (and therefore the back-pointing Parents collection), may // temporarily include non-unique ModelItems in returned set -- cleared as tree or designer views expand // // (Throughout, cannot use ModelItem.GetParentEnumerator because that does not check all Sources and Parents) internal static HashSet <ModelItem> FindUniqueChildren(ModelProperty property) { HashSet <ModelItem> retval = new HashSet <ModelItem>(); if (null != property && null != property.Parent && null != property.Value) { ModelItem target = property.Parent; ModelItem expected = property.Value; HashSet <ModelItem> visited = new HashSet <ModelItem>(); // Check all immediate children of property.Value ModelItemCollection collection = expected as ModelItemCollection; if (null == collection) { ModelItemDictionary dictionary = expected as ModelItemDictionary; if (null == dictionary) { // ModelItem // Can't use UniqueRoute because we're starting at expected // Can't use EnqueueParents because we need to special-case given property // Instead confirm property.Value is not referenced anywhere else ModelItemImpl expectedImpl = expected as ModelItemImpl; if (null != expectedImpl) { bool justThisSource = true; // expectedImpl.InternalParents does not include ModelItems that are just Sources if (0 == expectedImpl.InternalParents.Count) { // expectedImpl.InternalSources would be similar but adds a wrapper we don't need here foreach (ModelProperty source in expected.Sources) { if (null != source.Parent && !visited.Contains(source.Parent)) { visited.Add(source.Parent); if (!property.Equals(source) && !expected.Equals(source) && null == ExtensibilityAccessor.GetAttribute <HidePropertyInOutlineViewAttribute>(source)) { // Found a non-ignored property from somewhere else referencing expected justThisSource = false; break; } } } } else { // Found a Parent that's not a Source.Parent: property.Value is in some collection justThisSource = false; } if (justThisSource) { retval.Add(expected); } } } else { // ModelItemDictionary foreach (KeyValuePair <ModelItem, ModelItem> child in dictionary) { if (null != child.Key && !visited.Contains(child.Key)) { visited.Add(child.Key); if (UniqueModelItemHelper.UniqueRoute(child.Key, target, expected)) { retval.Add(child.Key); } } if (null != child.Value && !visited.Contains(child.Value)) { visited.Add(child.Value); if (UniqueModelItemHelper.UniqueRoute(child.Value, target, expected)) { retval.Add(child.Value); } } } } } else { // ModelItemCollection foreach (ModelItem child in collection) { if (null != child && !visited.Contains(child)) { visited.Add(child); if (UniqueModelItemHelper.UniqueRoute(child, target, expected)) { retval.Add(child); } } } } } return(retval); }