Exemple #1
0
        public SearchFile()
        {
            InitializeComponent();

            if (!(Application.Current is App))
            {
                return;
            }

            SingletonContentFactory.LoadContent();

            PublicFoundItems = FoundItems;

            // Setup running mode events
            ModeManager.RunningEvent += (s, args) =>
            {
                PauseBtn.Content    = "Pause";
                PauseBtn.Visibility = Visibility.Visible;
                SearchBtn.Content   = "Stop";
            };

            ModeManager.PausingEvent += (s, args) => { PauseBtn.Content = "Resume"; };

            ModeManager.StoppingEvent += (s, args) =>
            {
                PauseBtn.Visibility = Visibility.Hidden;
                SearchBtn.Content   = "Search";
            };

            _fileGatheringAlgorithms = UltimateFactory <FileGatheringAlgorithm> .Compute(AppDomain.CurrentDomain);

            _fileSearchingAlgorithms = UltimateFactory <ContentSearchAlgorithm> .Compute(AppDomain.CurrentDomain);

            // Get all file-searching algorithms and put them into a combobox.
            _fileGatheringAlgorithms.GetKeys().ForEach(x => FileGatheringCmbbx.Items.Add(x));

            // Get all "string in File"-searching algorithms and put them into another combobox.
            _fileSearchingAlgorithms.GetKeys().ForEach(x => AlgorithmCmbbx.Items.Add(x));

            //Loads custom plugins(if there are any)
            Loadplugin();

            // If one of those dictionary is empty, than we have a problem...
            if (AlgorithmCmbbx.Items.Count == 0 || FileGatheringCmbbx.Items.Count == 0)
            {
                MessageBox.Show(
                    $"Someone's being lazy here!\n{(AlgorithmCmbbx.Items.Count == 0 ? "There are NO algorithms, to search for content, loaded!" : "")}\n{(FileGatheringCmbbx.Items.Count == 0 ? "There are NO file gathering methods loaded!" : "")}",
                    "Ehm", new MessageBoxButton(),
                    MessageBoxImage.Error);
                Application.Current.Shutdown(); // Rage quit
                return;
            }

            FileGatheringCmbbx.SelectedIndex = 0;
            AlgorithmCmbbx.SelectedIndex     = 0;
        }
Exemple #2
0
        /// <summary>
        ///     Will load all *.dll in the Plugins directory and add the matching algorithms to their matching combobox.
        /// </summary>
        private void Loadplugin()
        {
            if (!Directory.Exists("Plugins"))
            {
                return;
            }

            // NOTE: .AsParallel().ForAll creates an endless break here! Please don't ask me why...

            foreach (var file in Directory.GetFiles("Plugins").Where(x => x.EndsWith(".dll")))
            {
                UltimateFactory <FileGatheringAlgorithm> .Compute(Assembly.LoadFrom(file)).ToList().ForEach(x =>
                {
                    _fileGatheringAlgorithms.TryAdd(x.Key, x.Value);

                    if (FileGatheringCmbbx.Dispatcher.CheckAccess())
                    // Check if the thread allows us to access the control
                    {
                        FileGatheringCmbbx.Items.Add(x.Key); // If so, than we just need to add the new item
                    }
                    else
                    {
                        // If not, than it gets a bit complicater:
                        // Now we have to invoke the dispatcher of the control from its current thread to access it.
                        FileGatheringCmbbx.Dispatcher.Invoke(DispatcherPriority.Normal,
                                                             new Action(() => FileGatheringCmbbx.Items.Add(x.Key)));
                    }
                });

                UltimateFactory <ContentSearchAlgorithm> .Compute(Assembly.LoadFrom(file)).ToList().ForEach(x =>
                {
                    _fileSearchingAlgorithms.TryAdd(x.Key, x.Value);

                    if (AlgorithmCmbbx.Dispatcher.CheckAccess()) // Check if the thread allows us to access the control
                    {
                        AlgorithmCmbbx.Items.Add(x.Key);         // If so, than we just need to add the new item
                    }
                    else
                    {
                        // If not, than it gets a bit complicater:
                        // Now we have to invoke the dispatcher of the control from its current thread to access it.
                        AlgorithmCmbbx.Dispatcher.Invoke(DispatcherPriority.Normal,
                                                         new Action(() => AlgorithmCmbbx.Items.Add(x.Key)));
                    }
                });
            }
        }