示例#1
0
        private static TaskBase DoGetTask(
            Assembly a,
            string commandSymbolicName,
            int depth)
        {
            if (a == null || depth > 10)
            {
                return(null);
            }
            else
            {
                LogCentral.Current.Debug(
                    string.Format(
                        @"DoGetTask(...depth={0}): Searching assembly '{1}'...",
                        depth,
                        a.GetName().Name));

                Type[] types = a.GetTypes();

                foreach (Type t in types)
                {
                    if (t.IsSubclassOf(typeof(TaskBase)) && !t.IsAbstract)
                    {
                        TaskBase b = Activator.CreateInstance(t) as TaskBase;


                        if (b.Command.SymbolicName == commandSymbolicName && b.IsActive)
                        {
                            return(b);
                        }
                        else
                        {
                            if (b.Commands != null && b.IsActive)
                            {
                                foreach (TaskCommand cn in b.Commands)
                                {
                                    if (cn.SymbolicName == commandSymbolicName)
                                    {
                                        return(b);
                                    }
                                }
                            }
                        }
                    }
                }


                return(null);
            }
        }
示例#2
0
        public static bool ExecuteTask(
            string rawCommand)
        {
            TaskBase task = GetTask(rawCommand);

            if (task != null && task.IsActive)
            {
                task.Process(task.GetCommandFromRawCommand(rawCommand));
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#3
0
        public static TaskBase GetTask(
            string commandSymbolicName)
        {
            Assembly[] asms = AppDomain.CurrentDomain.GetAssemblies();
            if (asms != null)
            {
                foreach (Assembly asm in asms)
                {
                    TaskBase tba = DoGetTask(asm, commandSymbolicName);
                    if (tba != null)
                    {
                        return(tba);
                    }
                }
            }

            Assembly a  = Assembly.GetExecutingAssembly();
            TaskBase tb = DoGetTask(a, commandSymbolicName);

            if (tb != null)
            {
                return(tb);
            }
            else
            {
                a  = Assembly.GetCallingAssembly();
                tb = DoGetTask(a, commandSymbolicName);
                if (tb != null)
                {
                    return(tb);
                }
                else
                {
                    a  = Assembly.GetEntryAssembly();
                    tb = DoGetTask(a, commandSymbolicName);
                    if (tb != null)
                    {
                        return(tb);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }
示例#4
0
        private static void DoGetAllTasks(
            ref List <TaskBase> list,
            Assembly a)
        {
            if (a != null)
            {
                LogCentral.Current.Debug(
                    string.Format(
                        @"DoGetAllTasks(): Searching assembly '{0}'...",
                        a.GetName().Name));

                Type[] types = a.GetTypes();

                foreach (Type t in types)
                {
                    if (t.IsSubclassOf(typeof(TaskBase)) && !t.IsAbstract)
                    {
                        TaskBase b = Activator.CreateInstance(t) as TaskBase;

                        if (b.IsActive)
                        {
                            bool found = false;
                            foreach (TaskBase c in list)
                            {
                                if (c.GetType() == b.GetType())
                                {
                                    found = true;
                                    break;
                                }
                            }

                            if (!found)
                            {
                                list.Add(b);
                            }
                        }
                    }
                }
            }
        }