| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 | using InABox.Core;using System;using System.Collections.Generic;using System.Linq;using System.Reflection;using System.Text;namespace Comal.TaskScheduler.Shared{    public static class SchedulePluginFactory    {        private static Dictionary<String, ISchedulePlugin> cache = new Dictionary<string, ISchedulePlugin>();        public static ISchedulePlugin? GetPlugin(String scheduleclass)        {            if (String.IsNullOrWhiteSpace(scheduleclass))                return null;            if (cache.ContainsKey(scheduleclass))                return cache[scheduleclass];            Type type;            try            {                type = CoreUtils.GetEntity(scheduleclass);            }            catch            {                return null;            }            Type defType = typeof(SchedulePlugin<>).MakeGenericType(type);            Type? subType = CoreUtils.TypeList(                new Assembly[] { typeof(SchedulePluginFactory).Assembly },                myType =>                myType.IsClass                && !myType.IsAbstract                && !myType.IsGenericType                && myType.IsSubclassOf(defType)            ).FirstOrDefault();            if(subType == null)            {                return null;            }            ISchedulePlugin result = (ISchedulePlugin)Activator.CreateInstance(subType)!;            cache[scheduleclass] = result;            return result;        }    }}
 |