Ejemplo n.º 1
0
        public static void LoadPlugins()
        {
            Assembly searchAssembly = null;

            Type[] searchprocesses;
            var    potentialAssemblies = getPotentialAssemblies(settings.SearchDirAbs);

            potentialAssemblies.Add("thisEXE");
            if (potentialAssemblies.Count == 0)
            {
                return;
            }

            foreach (string filepath in potentialAssemblies)
            {
                try
                {
                    if (filepath == "thisEXE")
                    {
                        searchAssembly = Assembly.GetExecutingAssembly();
                    }
                    else
                    {
                        searchAssembly = Assembly.LoadFrom(filepath);
                    }
                    searchprocesses = searchAssembly.GetExportedTypes();
                    foreach (Type spt in searchprocesses)
                    {
                        if (!spt.IsAbstract && SearchProcess.IsInheritedType(spt) &&
                            !SearchAlgorithms.Any(w => w.GetType().FullName.Equals(spt.FullName)))
                        {
                            LoadSearchAlgo(spt);
                        }
                    }
                }
                catch (Exception exc)
                {
                    if (searchAssembly == null)
                    {
                        SearchIO.output("Unable to open " + filepath + ": " + exc.Message);
                    }
                    else
                    {
                        SearchIO.output("Unable to open " + searchAssembly.FullName + "(" + filepath + "): " +
                                        exc.Message);
                    }
                }
            }
            //load from this exe
            searchAssembly  = Assembly.GetExecutingAssembly();
            searchprocesses = searchAssembly.GetExportedTypes();
            foreach (Type spt in searchprocesses)
            {
                if (!spt.IsAbstract && SearchProcess.IsInheritedType(spt) &&
                    !SearchAlgorithms.Any(w => w.GetType().FullName.Equals(spt.FullName)))
                {
                    LoadSearchAlgo(spt);
                }
            }
        }
Ejemplo n.º 2
0
        public void setUpSearchProcessMenu()
        {
            SearchIO.output("Setting Up Search Process Algorithms");
            var k = 0;

            SearchCommands   = new List <RoutedUICommand>();
            SearchAlgorithms = new List <SearchProcess>();
            while (DesignDropDown.Items.Count > 14)
            {
                DesignDropDown.Items.RemoveAt(14);
            }

            var potentialAssemblies = getPotentialAssemblies(GSApp.settings.SearchDirAbs);

            potentialAssemblies.Add("thisEXE");

            foreach (string filepath in potentialAssemblies)
            {
                Assembly searchAssembly = null;
                try
                {
                    if (filepath == "thisEXE")
                    {
                        searchAssembly = Assembly.GetExecutingAssembly();
                    }
                    else
                    {
                        searchAssembly = Assembly.LoadFrom(filepath);
                    }
                    var searchprocesses = searchAssembly.GetTypes();
                    foreach (Type spt in searchprocesses)
                    {
                        if (!spt.IsAbstract && SearchProcess.IsInheritedType(spt) &&
                            !SearchAlgorithms.Any(w => w.GetType().FullName.Equals(spt.FullName)))
                        {
                            try
                            {
                                var        constructor = spt.GetConstructor(new[] { typeof(GlobalSettings) });
                                var        searchAlgo  = (SearchProcess)constructor.Invoke(new object[] { GSApp.settings });
                                KeyGesture kg          = null;
                                if (k < endOfFKeys)
                                {
                                    kg = new KeyGesture((Key)(k + keyNumOffset), ModifierKeys.None);
                                }
                                else if (k < 2 * endOfFKeys)
                                {
                                    kg = new KeyGesture((Key)(k + keyNumOffset - endOfFKeys), ModifierKeys.Shift);
                                }
                                else if (k < 3 * endOfFKeys)
                                {
                                    kg = new KeyGesture((Key)(k + keyNumOffset - 2 * endOfFKeys),
                                                        ModifierKeys.Control | ModifierKeys.Shift);
                                }
                                else
                                {
                                    MessageBox.Show(
                                        "No shortcut has been assigned to " + searchAlgo.text +
                                        ". That sure is an awful lot "
                                        +
                                        " of search process algorithms! Consider reducing the number included in the plugins directory",
                                        "No ShortCut Assigned", MessageBoxButton.OK);
                                }
                                SearchAlgorithms.Add(searchAlgo);
                                var newSearchCommand = new RoutedUICommand(searchAlgo.text, spt.Name,
                                                                           GetType(), new InputGestureCollection {
                                    kg
                                });
                                SearchCommands.Add(newSearchCommand);
                                CommandBindings.Add(new CommandBinding(newSearchCommand, RunSearchProcessOnExecuted,
                                                                       RunSearchProcessCanExecute));
                                DesignDropDown.Items.Add(new MenuItem {
                                    Command = newSearchCommand
                                });
                                k++;
                                SearchIO.output("\t" + spt.Name + " loaded successfully.");
                            }
                            catch (Exception exc)
                            {
                                SearchIO.output("Unable to load " + spt.Name + ": " + exc.Message);
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    if (exc.Message.Equals("Assembly with same name is already loaded"))
                    {
                        continue;
                    }
                    if (searchAssembly == null)
                    {
                        SearchIO.output("Unable to open " + filepath + ": " + exc.Message);
                    }
                    else
                    {
                        SearchIO.output("Unable to open " + searchAssembly.FullName + "(" + filepath + "): " +
                                        exc.Message);
                    }
                }
            }
            if (Directory.Exists(GSApp.settings.SearchDirAbs))
            {
                sWatcher                       = new FileSystemWatcher(GSApp.settings.SearchDirAbs, "*.dll");
                sWatcher.Changed              += SearchDir_Changed;
                sWatcher.Created              += SearchDir_Changed;
                sWatcher.Deleted              += SearchDir_Changed;
                sWatcher.Renamed              += SearchDir_Changed;
                sWatcher.EnableRaisingEvents   = true;
                sWatcher.IncludeSubdirectories = true;
                sWatcher.NotifyFilter          = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                                 | NotifyFilters.FileName;
            }
        }