اکتیویتی InvokeMethod

چاپ

استفاده ازاکتیویتی InvokeMethod در Workflow

در این قسمت از آموزش ساخت Workflow، قصد داریم نحوه ی فراخوانی متدهای مختلف را با استفاده از اکتیویتی InvokeMethod آموزش دهیم.

مراحل انجام کار

 پروژه گردش کار UsingInvokeMethodActivityInCode شامل 5 مرحله زیر است:

  1. ایجاد یک پروژه از نوع Workflow Console Application
  2. ایجاد فایل TestClass.cs
  3. طراحی Workflow و نحوه استفاده از اکتیویتی InvokeMethod
  4. اجرای Workflow
  5. سیستم گردش کار UsingInvokeMethodActivityInCode چگونه کار می کند؟

ایجاد یک پروژه از نوع Workflow Console Application

یک پروژه جدید از نوع Workflow Console Application ایجاد کنید و آنرا UsingInvokeMethodActivityInCode نامگذاری نمایید.


ایجاد فایل TestClass.cs

یک فایل جدید بنام TestClass.cs به پروژه اضافه کنید و کدهای زیر را در آن پیست نمایید:

TestClass.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UsingInvokeMethodActivityInCode
{
    public class TestClass
    {
        public void Method()
        {
            Console.WriteLine("------------1-----------");
            Console.WriteLine("Hello, message from Method()");
            
        }
        public void Method(string message1, string message2)
        {
            Console.WriteLine("-----------2------------");
            Console.WriteLine("Hello, your message1 is:" + message1);
            Console.WriteLine("Hello, this is your message2:" + message2);
            
        }
        public string MethodWithReturn(string message1, string message2)
        {
            Console.WriteLine("-----------3------------");
            return "message1:" + message1 + " " + "message2:" + message2 ;
        }
        public void MethodWithRef(string message1, string message2, ref string resultMessage)
        {
            Console.WriteLine("-----------4------------");
            resultMessage = "message1:" + message1 + " " + "message2:" + message2;
        }
        public void Method<T1, T2>(T1 param1, T2 param2)
        {
            Console.WriteLine("-----------5------------");
            Console.WriteLine("The type of T1 is:" + typeof(T1));
            Console.WriteLine("The value of param1 is:" + param1.ToString());
            Console.WriteLine("The type of T2 is:" + typeof(T2));
            Console.WriteLine("The value of param2 is:" + param2.ToString());
        }
        public static string StaticMethod(string message1, string message2)
        {
            Console.WriteLine("-----------6------------");
            return "message1:" + message1 + " " + "message2:" + message2;
        }
    }
}

طراحی Workflow و نحوه استفاده از اکتیویتی InvokeMethod

از پنل Solution Explorerr فایل Workflow1.xaml را باز کنید و Workflow را مطابق زیر طراحی نمایید:

  1. از پنل ToolBox، اکتیویتی Sequence را انتخاب کرده و به داخل صفحه طراحی گردش کار بکشید.
  2. از پنل ToolBox، اکتیویتی InvokeMethod را انتخاب کرد به داخل اکتیویتی Sequence بکشید و مطابق شکل زیر Workflow را طراحی نمایید:


اجرای Workflow

پروژه UsingInvokeMethodActivityInCode را بعنوان پروژه StartUp تنظیم نمایید و در ادامه برای اجرای Workflow دکمه های میانبر Ctrl+F5 را فشار دهید:


سیستم گردش کار UsingInvokeMethodActivityInCode چگونه کار می کند؟

Property های مهم اکتیویتی InvokeMethod عبارت اند از:

{module خرید و دانلود فصل دوم آموزش Workflow}