Ejemplo n.º 1
0
        DFrameWorkerCollection(Assembly[] searchAssemblies)
        {
            dframeTypes = new Dictionary <string, DFrameWorkerTypeInfo>(StringComparer.InvariantCultureIgnoreCase);

            foreach (var asm in searchAssemblies)
            {
                if (asm.FullName.StartsWith("System") || asm.FullName.StartsWith("Microsoft.Extensions"))
                {
                    continue;
                }

                Type[] types;
                try
                {
                    types = asm.GetTypes();
                }
                catch (ReflectionTypeLoadException ex)
                {
                    types = ex.Types;
                }

                foreach (var worker in types)
                {
                    if (typeof(Worker).IsAssignableFrom(worker) && !worker.IsAbstract)
                    {
                        var attr   = worker.GetCustomAttribute <WorkerAttribute>(false);
                        var master = GetMasterType(worker);
                        var name   = attr?.Name ?? worker.Name;
                        var disallowSingleExecute = attr?.DisallowSingleExecute ?? false;

                        var t = new DFrameWorkerTypeInfo(worker, master, name, disallowSingleExecute);
                        if (!dframeTypes.TryAdd(name, t))
                        {
                            throw new InvalidOperationException($"Worker name is duplicate. name:{name}, type:{t.WorkerType.FullName}");
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public bool TryGetWorker(string workerName, out DFrameWorkerTypeInfo worker)
 {
     return(dframeTypes.TryGetValue(workerName, out worker));
 }