Beispiel #1
0
        public void Execute(BackgroundTaskCommand command)
        {
            BackgroundWorker worker = new BackgroundWorker()
            {
                WorkerSupportsCancellation = true,
                WorkerReportsProgress      = true
            };

            InvertApplication.Log("Creating background task");
            worker.DoWork += (sender, args) =>
            {
                InvertApplication.Log("Executing background task");
                var bgCommand = args.Argument as BackgroundTaskCommand;

                if (bgCommand != null)
                {
                    bgCommand.Command.Worker = sender as BackgroundWorker;
                    bgCommand.Action(bgCommand.Command);
                }
            };
            worker.ProgressChanged += (sender, args) =>
            {
                InvertApplication.Log("PROGRESS");
                InvertApplication.SignalEvent <ICommandProgressEvent>(_ => _.Progress(null, args.UserState.ToString(), args.ProgressPercentage));
            };
            command.Task = new BackgroundTask(worker);
            worker.RunWorkerAsync(command);
        }
Beispiel #2
0
        public static IEnumerable <Type> GetDerivedTypes <T>(bool includeAbstract = false, bool includeBase = true)
        {
            var type = typeof(T);

            if (includeBase)
            {
                yield return(type);
            }
            if (includeAbstract)
            {
                foreach (var assembly in CachedAssemblies)
                {
                    //if (!assembly.FullName.StartsWith("Invert")) continue;
                    foreach (var t in assembly
                             .GetTypes()
                             .Where(x => type.IsAssignableFrom(x)))
                    {
                        yield return(t);
                    }
                }
            }
            else
            {
                var items = new List <Type>();
                foreach (var assembly in CachedAssemblies)
                {
                    //if (!assembly.FullName.StartsWith("Invert")) continue;
                    try
                    {
                        foreach (var t in assembly
                                 .GetTypes()
                                 .Where(x => type.IsAssignableFrom(x) && !x.IsAbstract))
                        {
                            items.Add(t);
                        }
                    }
                    catch (Exception ex)
                    {
                        InvertApplication.Log(ex.Message);
                    }
                }
                foreach (var item in items)
                {
                    yield return(item);
                }
            }
        }