/// <summary> /// Performs the importing /// </summary> public void Import(MemberImportingOptions options, SharpTreeNode node) { //Checks that options isn't null if (options == null) { throw new ArgumentNullException("options"); } //Checks if must perform a scan before if (!Scanned) { Scan(options); } //Imports the members required by this importer foreach (var x in _importList) { x.Import(options, node); } //Imports and invokes the event var ret = ImportCore(options, node); var evt = ImportFinished; if (evt != null) { evt(ret); } }
public MemberImportingSession(AssemblyDefinition asm, ModuleDefinition module, TypeDefinition type, MemberImportingOptions options) { //Checks that the parameters aren't null if (asm == null) throw new ArgumentNullException("asm"); if (module == null) throw new ArgumentNullException("module"); if (options == null) throw new ArgumentNullException("options"); //Stores the parameters _DestinationAssembly = asm; _DestinationModule = module; _DestinationType = type; _Options = options; }
/// <summary> /// Performs a scanning of the member /// </summary> public MemberImporter Scan(MemberImportingOptions options) { //Checks that options isn't null if (options == null) { throw new ArgumentNullException("options"); } //Checks if this is the first time that this method has been called if (Scanned) { throw new InvalidOperationException("Cannot call Scan() two times"); } //Performs the scanning _importList = new List <MemberImporter>(); ScanCore(options, _importList); //Fluid interface: returns this return(this); }
public MemberImportingSession(AssemblyDefinition asm, ModuleDefinition module, TypeDefinition type, MemberImportingOptions options) { //Checks that the parameters aren't null if (asm == null) { throw new ArgumentNullException("asm"); } if (module == null) { throw new ArgumentNullException("module"); } if (options == null) { throw new ArgumentNullException("options"); } //Stores the parameters _DestinationAssembly = asm; _DestinationModule = module; _DestinationType = type; _Options = options; }
private void InjectCommandImpl() { //Flag to determine whther to color the parent nodes var cancel = false; //Switches on the injection type (new or existing) switch (TabSelectedIndex) { //Inject new case 0: //Checks that the name has been provided if (string.IsNullOrEmpty(this.Name)) { MessageBox.Show("A name is required", "Name required", MessageBoxButton.OK, MessageBoxImage.Error); return; } //Checks that the member has been provided (if needed) if (SelectedInjector.NeedsMember && SelectedMember == null) { MessageBox.Show("A type is required", "Type required", MessageBoxButton.OK, MessageBoxImage.Error); return; } //Checks that the selected type is valid if (SelectedInjector.NeedsMember && !SelectedInjector.MemberFilter(this.SelectedMember)) { MessageBox.Show("The selected type is not valid for '" + this.SelectedInjector.Name + "'", "Type required", MessageBoxButton.OK, MessageBoxImage.Error); return; } //Injects this.SelectedInjector.Inject(_node, this.Name, this.SelectedInjector.NeedsMember ? this.SelectedMember : null); //Break break; //Inject existing case 1: //Checks that there's a selection if (ExistingSelectedMember == null) { MessageBox.Show("Select a valid member to import in '" + _node.Text.ToString() + "'", "", MessageBoxButton.OK, MessageBoxImage.Error); return; } //Cancellation token var cts = new CancellationTokenSource(); var ct = cts.Token; //Starts a new task to perform importing var t = new Task(() => { //Options var options = new Existing.MemberImportingOptions() { ImportAsNestedType = ExistingImportAsNestedTypes, CancellationToken = ct }; //Importing session var destType = !(_node is ModuleTreeNode) ? ((IMemberTreeNode)_node).Member as TypeDefinition : null; var destModule = destType != null ? destType.Module : ((ModuleTreeNode)_node).Module; var destAsm = Helpers.Tree.GetAssemblyNode(Helpers.Tree.GetModuleNode(destModule)).LoadedAssembly.AssemblyDefinition; var session = new ILEdit.Injection.Existing.MemberImportingSession(destAsm, destModule, destType, options); //Imports using (var importer = session.CreateImporter(ExistingSelectedMember)) { //Performs scanning importer.Scan(options); //Checks whether to show the preview if (ExistingPreview) { //Builds the preview var root = new SharpTreeNode(); importer.BuildPreviewNodes(root); //Shows the preview window Application.Current.Dispatcher.Invoke((Action)(() => { cancel = !new Existing.PreviewWindow(root, _node).ShowDialog().GetValueOrDefault(false); }), null); } //Performs importing on the dispatcher thread if (!cancel) { Application.Current.Dispatcher.Invoke((Action)(() => { importer.Import(options, _node); }), null); } } }, ct); t.Start(); t.ContinueWith(task => { //Hides the window Application.Current.Dispatcher.Invoke((Action)WaitWindow.Hide, null); //Checks for any exception if (task.Exception != null) { var text = string.Join(Environment.NewLine + Environment.NewLine, task.Exception.InnerExceptions.Select(x => x.Message).ToArray()); Application.Current.Dispatcher.BeginInvoke((Action)(() => { MessageBox.Show("An exception occurred:" + Environment.NewLine + Environment.NewLine + text, "Error", MessageBoxButton.OK, MessageBoxImage.Error); }), null); } }); //Shows the wait window WaitWindow.ShowDialog("Importing in progress ...", "Please, wait while the importing is in progress ...", cts); break; //Other: exception default: throw new ArgumentException("Invalid value: it can be only 0 or 1", "TabSelectedIndex"); } //Colors the parents of the node if (!cancel) { //Colors the ancestors of this node var parent = (ICSharpCode.TreeView.SharpTreeNode)_node; while (parent != null) { if (parent.Foreground != GlobalContainer.NewNodesBrush) { parent.Foreground = GlobalContainer.ModifiedNodesBrush; } parent = parent.Parent; } //Refreshes the view ICSharpCode.ILSpy.MainWindow.Instance.RefreshDecompiledView(); //Saves the settings var settings = GlobalContainer.InjectionSettings.Element("InjectExistingSettings"); settings.SetAttributeValue("Preview", ExistingPreview); if (ExistingImportAsNestedTypesEnabled) { settings.SetAttributeValue("ImportAsNestedTypes", ExistingImportAsNestedTypes); } GlobalContainer.SettingsManager.Instance.Save(); //Closes the window _window.Close(); } }
protected override IMetadataTokenProvider ImportCore(MemberImportingOptions options, SharpTreeNode node) { return(_importFunc(options, node)); }
protected override void ScanCore(MemberImportingOptions options, List <MemberImporter> importList) { }
protected abstract IMetadataTokenProvider ImportCore(MemberImportingOptions options, SharpTreeNode node);
protected abstract void ScanCore(MemberImportingOptions options, List <MemberImporter> importList);
private void InjectCommandImpl() { //Flag to determine whther to color the parent nodes var cancel = false; //Switches on the injection type (new or existing) switch (TabSelectedIndex) { //Inject new case 0: //Checks that the name has been provided if (string.IsNullOrEmpty(this.Name)) { MessageBox.Show("A name is required", "Name required", MessageBoxButton.OK, MessageBoxImage.Error); return; } //Checks that the member has been provided (if needed) if (SelectedInjector.NeedsMember && SelectedMember == null) { MessageBox.Show("A type is required", "Type required", MessageBoxButton.OK, MessageBoxImage.Error); return; } //Checks that the selected type is valid if (SelectedInjector.NeedsMember && !SelectedInjector.MemberFilter(this.SelectedMember)) { MessageBox.Show("The selected type is not valid for '" + this.SelectedInjector.Name + "'", "Type required", MessageBoxButton.OK, MessageBoxImage.Error); return; } //Injects this.SelectedInjector.Inject(_node, this.Name, this.SelectedInjector.NeedsMember ? this.SelectedMember : null); //Break break; //Inject existing case 1: //Checks that there's a selection if (ExistingSelectedMember == null) { MessageBox.Show("Select a valid member to import in '" + _node.Text.ToString() + "'", "", MessageBoxButton.OK, MessageBoxImage.Error); return; } //Cancellation token var cts = new CancellationTokenSource(); var ct = cts.Token; //Starts a new task to perform importing var t = new Task(() => { //Options var options = new Existing.MemberImportingOptions() { ImportAsNestedType = ExistingImportAsNestedTypes, CancellationToken = ct }; //Importing session var destType = !(_node is ModuleTreeNode) ? ((IMemberTreeNode)_node).Member as TypeDefinition : null; var destModule = destType != null ? destType.Module : ((ModuleTreeNode)_node).Module; var destAsm = Helpers.Tree.GetAssemblyNode(Helpers.Tree.GetModuleNode(destModule)).LoadedAssembly.AssemblyDefinition; var session = new ILEdit.Injection.Existing.MemberImportingSession(destAsm, destModule, destType, options); //Imports using (var importer = session.CreateImporter(ExistingSelectedMember)) { //Performs scanning importer.Scan(options); //Checks whether to show the preview if (ExistingPreview) { //Builds the preview var root = new SharpTreeNode(); importer.BuildPreviewNodes(root); //Shows the preview window Application.Current.Dispatcher.Invoke((Action)(() => { cancel = !new Existing.PreviewWindow(root, _node).ShowDialog().GetValueOrDefault(false); }), null); } //Performs importing on the dispatcher thread if (!cancel) Application.Current.Dispatcher.Invoke((Action)(() => { importer.Import(options, _node); }), null); } }, ct); t.Start(); t.ContinueWith(task => { //Hides the window Application.Current.Dispatcher.Invoke((Action)WaitWindow.Hide, null); //Checks for any exception if (task.Exception != null) { var text = string.Join(Environment.NewLine + Environment.NewLine, task.Exception.InnerExceptions.Select(x => x.Message).ToArray()); Application.Current.Dispatcher.BeginInvoke((Action)(() => { MessageBox.Show("An exception occurred:" + Environment.NewLine + Environment.NewLine + text, "Error", MessageBoxButton.OK, MessageBoxImage.Error); }), null); } }); //Shows the wait window WaitWindow.ShowDialog("Importing in progress ...", "Please, wait while the importing is in progress ...", cts); break; //Other: exception default: throw new ArgumentException("Invalid value: it can be only 0 or 1", "TabSelectedIndex"); } //Colors the parents of the node if (!cancel) { //Colors the ancestors of this node var parent = (ICSharpCode.TreeView.SharpTreeNode)_node; while (parent != null) { if (parent.Foreground != GlobalContainer.NewNodesBrush) parent.Foreground = GlobalContainer.ModifiedNodesBrush; parent = parent.Parent; } //Refreshes the view ICSharpCode.ILSpy.MainWindow.Instance.RefreshDecompiledView(); //Saves the settings var settings = GlobalContainer.InjectionSettings.Element("InjectExistingSettings"); settings.SetAttributeValue("Preview", ExistingPreview); if (ExistingImportAsNestedTypesEnabled) settings.SetAttributeValue("ImportAsNestedTypes", ExistingImportAsNestedTypes); GlobalContainer.SettingsManager.Instance.Save(); //Closes the window _window.Close(); } }
protected override IMetadataTokenProvider ImportCore(MemberImportingOptions options, SharpTreeNode node) { return _importFunc(options, node); }
protected override void ScanCore(MemberImportingOptions options, List<MemberImporter> importList) { }
/// <summary> /// Performs the importing /// </summary> public void Import(MemberImportingOptions options, SharpTreeNode node) { //Checks that options isn't null if (options == null) throw new ArgumentNullException("options"); //Checks if must perform a scan before if (!Scanned) Scan(options); //Imports the members required by this importer foreach (var x in _importList) x.Import(options, node); //Imports and invokes the event var ret = ImportCore(options, node); var evt = ImportFinished; if (evt != null) evt(ret); }
protected abstract void ScanCore(MemberImportingOptions options, List<MemberImporter> importList);
/// <summary> /// Performs a scanning of the member /// </summary> public MemberImporter Scan(MemberImportingOptions options) { //Checks that options isn't null if (options == null) throw new ArgumentNullException("options"); //Checks if this is the first time that this method has been called if (Scanned) throw new InvalidOperationException("Cannot call Scan() two times"); //Performs the scanning _importList = new List<MemberImporter>(); ScanCore(options, _importList); //Fluid interface: returns this return this; }