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(); } } }
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(); } } }
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(); } } }