Exemplo n.º 1
0
        /// <summary>
        /// Add an ActionMethod (with lowest priority) to be called when an Action is performed
        /// </summary>
        /// <param name="ActionName">The name of the Action that will trigger the ActionMethod</param>
        /// <param name="Method">The ActionMethod to run</param>
        public static void AddMethod(string actionName, ActionMethod method)
        {
            // set the method assembly, if it is not manually set
            if (method.AssemblyName == null)
            {
                method.AssemblyName = Assembly.GetCallingAssembly().FullName;
            }

            ActionManager.AddMethod(actionName, method, 0);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add an ActionMethod to be called when an Action is performed
        /// </summary>
        /// <param name="ActionName">The name of the Action that will trigger the ActionMethod</param>
        /// <param name="Method">The ActionMethod to run</param>
        /// <param name="priority">The priority of the ActionMethod</param>
        public static void AddMethod(string actionName, ActionMethod method, int priority)
        {
            // set the action name
            method.ActionName = actionName;

            // set the action priority
            method.Priority = priority;

            // set the method assembly, if it is not manually set
            if (method.AssemblyName == null)
            {
                method.AssemblyName = Assembly.GetCallingAssembly().FullName;
            }

            // if the method already exists for this action, delete it
            if (Methods.FirstOrDefault(m => m.ActionName == method.ActionName && m.Namespace == method.Namespace && m.ClassName == method.ClassName && m.MethodName == method.MethodName) != null)
            {
                ActionMethod foundMethod = Methods.FirstOrDefault(m => m.ActionName == method.ActionName && m.Namespace == method.Namespace && m.ClassName == method.ClassName && m.MethodName == method.MethodName);
                Methods.Remove(foundMethod);
            }

            // add this method
            Methods.Add(method);
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            #region Generic tests

            // tests without the object parameter

            // same namespace, static
            ActionMethod Test1 = new ActionMethod("TestApp.StaticMethods.WithoutObject");
            ActionManager.AddMethod("TestAction", Test1);

            // same namespace, instantiated
            ActionMethod Test2 = new ActionMethod("TestApp.Methods.WithoutObject", false);
            ActionManager.AddMethod("TestAction", Test2);

            // different namespace, static
            ActionMethod Test3 = new ActionMethod("Namespace1.StaticMethods.WithoutObject");
            ActionManager.AddMethod("TestAction", Test3);

            // different namespace, instantiated
            ActionMethod Test4 = new ActionMethod("Namespace2.Methods.WithoutObject", false);
            ActionManager.AddMethod("TestAction", Test4);

            // tests with the object parameter

            // same namespace, static
            ActionMethod Test5 = new ActionMethod("TestApp.StaticMethods.WithObject", true, true);
            ActionManager.AddMethod("TestActionWithObject", Test5);

            // same namespace, instantiated
            ActionMethod Test6 = new ActionMethod();
            Test6.Namespace = "TestApp";
            Test6.ClassName = "Methods";
            Test6.MethodName = "WithObject";
            Test6.AcceptsParameters = true;
            Test6.IsStatic = false;
            ActionManager.AddMethod("TestActionWithObject", Test6);

            // different namespace, static
            ActionMethod Test7 = new ActionMethod();
            Test7.Namespace = "Namespace1";
            Test7.ClassName = "StaticMethods";
            Test7.MethodName = "WithObject";
            Test7.AcceptsParameters = true;
            ActionManager.AddMethod("TestActionWithObject", Test7);

            // different namespace, instantiated
            ActionMethod Test8 = new ActionMethod();
            Test8.Namespace = "Namespace2";
            Test8.ClassName = "Methods";
            Test8.MethodName = "WithObject";
            Test8.AcceptsParameters = true;
            Test8.IsStatic = false;
            ActionManager.AddMethod("TestActionWithObject", Test8);

            #endregion

            // run the test method
            TestMethod();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Run a simple method with actions that can be used
        /// </summary>
        private void TestMethod()
        {
            // register the new action
            ActionMethod AddPerson = new ActionMethod();
            AddPerson.Namespace = "TestApp";
            AddPerson.ClassName = "PersonMethods";
            AddPerson.MethodName = "OnAddPerson";
            AddPerson.IsStatic = false;
            AddPerson.AcceptsParameters = true;
            AddPerson.ThrowOnException = true;
            ActionManager.AddMethod("AddPerson", AddPerson);

            // create a new datatable
            DataTable dt = new DataTable();
            dt.Columns.Add("id");
            dt.Columns.Add("name");
            dt.Columns.Add("age");
            dt.Columns.Add("extra");

            // add some rows, calling the AddRow action
            object[] person1 = new object[] { 1, "Jim", 33, null };
            dt.Rows.Add(person1);
            ActionManager.PerformAction("AddPerson", dt.Rows[dt.Rows.Count - 1]);

            object[] person2 = new object[] { 2, "Dave", 29, null };
            dt.Rows.Add(person2);
            ActionManager.PerformAction("AddPerson", dt.Rows[dt.Rows.Count - 1]);

            object[] person3 = new object[] { 4, "Harriet", 45, null };
            dt.Rows.Add(person3);
            ActionManager.PerformAction("AddPerson", dt.Rows[dt.Rows.Count - 1]);

            object[] person4 = new object[] { 5, "Nicola", 19, null };
            dt.Rows.Add(person4);
            ActionManager.PerformAction("AddPerson", dt.Rows[dt.Rows.Count-1]);

            PeopleTable.DataSource = dt;
            PeopleTable.DataBind();
        }