protected qf4net.IQEventEditor GetEditor(qf4net.TransitionEventAttribute te) { EditorAttribute editor = GetEditorType(te); Type editorType = Type.GetType(editor.EditorTypeName); object editorObj = Activator.CreateInstance(editorType); qf4net.IQEventEditor eventEditor = editorObj as qf4net.IQEventEditor; if (eventEditor == null) { throw new ArgumentException(editor.EditorTypeName + " is not a valid IQEventEditor Type"); } return(eventEditor); }
private void injectButton_Click(object sender, System.EventArgs e) { qf4net.ILQHsm hsm = SelectedHSM; if (hsm == null) { throw new ArgumentException("No hsm selected"); } if (eventInput.Text.Trim() != "") { string inject = eventInput.Text; inject = inject.Trim(); // if inject matches a TransitionEventAttribute then find its editor an edit! foreach (qf4net.TransitionEventAttribute te in hsm.TransitionEvents) { if (te.HasDataType) { if (te.ToString() == inject) { qf4net.IQEventEditor eventEditor = GetEditor(te); Form frm = new OkCancelForm(); frm.Text = "Event " + te.EventName; QEventDefaultEditContext ctx = new QEventDefaultEditContext(frm); if (eventEditor.Edit(ctx) == false) { return; } hsm.AsyncDispatch(new qf4net.QEvent(te.EventName, ctx.Instance)); if (eventEditor.SupportsParse) { inject = te + "|" + ctx.Instance; if (!eventInput.Items.Contains(inject)) { eventInput.Items.Add(inject); } } return; } } } // if inject matches a TransitionEventAttribute + extra data then parse the extra data! foreach (qf4net.TransitionEventAttribute te in hsm.TransitionEvents) { if (te.HasDataType) { if (inject.StartsWith(te.ToString() + "|")) { qf4net.IQEventEditor eventEditor = GetEditor(te); if (!eventEditor.SupportsParse) { throw new NotSupportedException(te.ToString() + " editor does not support string parsing"); } string[] strlist = inject.Split(new char[] { '|' }, 2); string eventName = strlist[0].Trim(); System.Diagnostics.Debug.Assert(eventName != "" && eventName == te.ToString()); string data = null; if (strlist.Length > 1) { data = strlist [1].Trim(); } if (data == null) { throw new ArgumentException("[" + inject + "] does not contain a Parsable event data string"); } object instance = eventEditor.Parse(data); hsm.AsyncDispatch(new qf4net.QEvent(te.EventName, instance)); return; } } } hsm.AsyncDispatch(new qf4net.QEvent(inject)); } }