internal static ProjectInjectionMapping FromInjectionMapping(InjectionMapping mapping) { ProjectInjectionMapping projMapping = new ProjectInjectionMapping(); projMapping.ClassName = mapping.Method.DeclaringType.Name; projMapping.TargetAssemblyPath = mapping.Assembly.Path; projMapping.MethodName = mapping.Method.Name; projMapping.MethodParameters = mapping.Method.Parameters.Count; projMapping.InjectorAssemblyPath = mapping.Injector.Assembly.GetPath(); projMapping.InjectorType = mapping.Injector.AssemblyQualifiedName; return(projMapping); }
internal static ProjectInjectionMapping FromInjectionMapping(InjectionMapping mapping) { ProjectInjectionMapping projMapping = new ProjectInjectionMapping(); projMapping.ClassName = mapping.Method.DeclaringType.Name; projMapping.TargetAssemblyPath = mapping.Assembly.Path; projMapping.MethodName = mapping.Method.Name; projMapping.MethodParameters = mapping.Method.Parameters.Count; projMapping.InjectorAssemblyPath = mapping.Injector.Assembly.GetPath(); projMapping.InjectorType = mapping.Injector.AssemblyQualifiedName; return projMapping; }
private void SendMessageToPlugins(EventType eventType, InjectionMapping mapping, Exception exceptionInjection, string message) { if (Plugins == null || PluginList == null || PluginList.Count == 0) return; try { PluginList.ForEach(x => { try { x.OnMessageReceived(eventType, new PluginInterface.Message { Target = mapping == null ? string.Empty : mapping.Method.Name, Injector = mapping == null ? string.Empty : mapping.Injector.Name, Error = exceptionInjection, Result = message, TimeStamp = DateTime.Now }); } catch (Exception ex) { try { x.HandleError(ex); } catch { // Ignore error caused due to plugin, later should be given back to IPlugin through } } }); } catch { } }
private bool BindMappings() { List<Type> selectedInjectors = _rootInjection.GetCheckedNodes<Type>(); Func<BindItem, bool> predicate = x => x.Method != null && x.Method.Body != null; List<BindItem> selectedMethods = _rootTarget.GetCheckedNodes<BindItem>(predicate); if (_mapping == null) _mapping = new List<InjectionMapping>(); if (selectedInjectors.Count == 0 && _mapping.Count == 0) { MessageBox.Show(@"No code injectors selected!"); return false; } bool injectAllMethods = false; if (selectedMethods.Count == 0 && _mapping.Count == 0) { DialogResult result = MessageBox.Show( @"You have not selected any methods in the Target Assembly that need to be injected!", Application.ProductName, MessageBoxButtons.OK); return false; } if (_mapping.Count > 0) { DialogResult result = MessageBox.Show( @"You have already defined a mapping, do you want to add this to the mapping or override? Click Yes if you want to add, No if you want to override & Cancel otherwise", Application.ProductName, MessageBoxButtons.YesNoCancel); if (result == System.Windows.Forms.DialogResult.No) { _mapping = new List<InjectionMapping>(); lstOutput.Items.Clear(); } else if (result == System.Windows.Forms.DialogResult.Cancel) return false; } btnRemove.Enabled = true; if (injectAllMethods) selectedMethods = _rootTarget.GetNodes<BindItem>(predicate); for (int methods = 0; methods < selectedMethods.Count; methods++) { for (int injector = 0; injector < selectedInjectors.Count; injector++) { var newMapping = new InjectionMapping(selectedMethods[methods].Assembly, selectedMethods[methods].Method, selectedInjectors[injector]); //selectedInjectors[injector] if (_mapping.Count(x => x.GetHashCode() == newMapping.GetHashCode()) == 0) _mapping.Add(newMapping); } } grdCombination.DataSource = null; grdCombination.DataSource = _mapping; grdCombination.Refresh(); return true; }