Exemple #1
0
        public Window1()
        {
            InitializeComponent();

            WorkflowRuntime workflowRuntime = new WorkflowRuntime();

            SqlWorkflowPersistenceService sqlService = new SqlWorkflowPersistenceService(_settings.SqlPersistenceConnectionString);

            workflowRuntime.AddService(sqlService);
            workflowRuntime.StartRuntime();

            foreach (SqlPersistenceWorkflowInstanceDescription desc in sqlService.GetAllWorkflows())
            {
                listWorkflows.Items.Add(desc.WorkflowInstanceId.ToString() + " " + desc.Status);
                Console.WriteLine(desc.WorkflowInstanceId);

                try
                {
                    WorkflowInstance workflowInstance = workflowRuntime.GetWorkflow(desc.WorkflowInstanceId);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            workflowRuntime.StopRuntime();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting Workflow");

            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                // Run SQL scripts:
                // C:\Windows\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\en\SqlPersistenceService_Schema.sql
                // C:\Windows\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\en\SqlPersistenceService_Logic.sql

                SqlWorkflowPersistenceService sqlPersistenceService = new SqlWorkflowPersistenceService("Server=localhost;Database=NetMeter;User Id=sa;Password=MetraTech1;");
                workflowRuntime.AddService(sqlPersistenceService);
                workflowRuntime.AddService(new ConsoleTrackingService());

                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted  += delegate(object sender, WorkflowCompletedEventArgs e) { waitHandle.Set(); };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                {
                    Console.WriteLine(e.Exception.ToString());
                    waitHandle.Set();
                };

                WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WorkflowConsoleApplication2.Workflow1));
                instance.Start();

                waitHandle.WaitOne();
            }

            Console.WriteLine("Workflow done");
            Console.ReadLine();
        }
Exemple #3
0
        /// <summary>
        /// 创建工作流运行时
        /// </summary>
        /// <param name="IsPer">是否使用持久化</param>
        /// <returns></returns>
        public static WorkflowRuntime CreateWorkFlowRuntime(bool IsPer)
        {
            try
            {
                WorkflowRuntime WfRuntime = new WorkflowRuntime();


                if (IsPer)
                {
                    String connStringPersistence = ConfigurationManager.ConnectionStrings["SqlPersistenceConnection"].ConnectionString;//Data Source=172.30.50.110;Initial Catalog=WorkflowPersistence;Persist Security Info=True;User ID=sa;Password=fbaz2012;MultipleActiveResultSets=True";
                    SqlWorkflowPersistenceService persistence = new SqlWorkflowPersistenceService(connStringPersistence, true, new TimeSpan(0, 0, 30), new TimeSpan(0, 1, 0));
                    WfRuntime.AddService(persistence);
                    WfRuntime.WorkflowPersisted           += new EventHandler <WorkflowEventArgs>(WfRuntime_WorkflowPersisted);
                    WfRuntime.ServicesExceptionNotHandled += new EventHandler <ServicesExceptionNotHandledEventArgs>(WfRuntime_ServicesExceptionNotHandled);
                    //    ConnectionStringSettings defaultConnectionString = ConfigurationManager.ConnectionStrings["OracleConnection"];
                    //    WfRuntime.AddService(new AdoPersistenceService(defaultConnectionString, true, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(0)));
                    //    WfRuntime.AddService(new AdoTrackingService(defaultConnectionString));
                    //    WfRuntime.AddService(new AdoWorkBatchService());
                }

                FlowEvent ExternalEvent = new FlowEvent();
                ExternalDataExchangeService objService = new ExternalDataExchangeService();
                WfRuntime.AddService(objService);
                objService.AddService(ExternalEvent);
                TypeProvider typeProvider = new TypeProvider(null);
                WfRuntime.AddService(typeProvider);
                WfRuntime.StartRuntime();
                return(WfRuntime);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("CreateWorkFlowRuntime异常信息 :" + ex.ToString());
                throw new Exception(ex.Message);
            }
        }
Exemple #4
0
        /// <summary>
        /// 从持久化库在恢复实例
        /// </summary>
        /// <param name="WfRuntime"></param>
        /// <param name="INSTANCEID"></param>
        /// <returns></returns>
        public static WorkflowInstance GetWorkflowInstance(WorkflowRuntime WfRuntime, string INSTANCEID)
        {
            try
            {
                WfRuntime = new WorkflowRuntime();

                if (WfRuntime.GetService(typeof(AdoPersistenceService)) == null)
                {
                    ConnectionStringSettings defaultConnectionString = ConfigurationManager.ConnectionStrings["OracleConnection"];
                    WfRuntime.AddService(new AdoPersistenceService(defaultConnectionString, true, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(0)));
                    WfRuntime.AddService(new AdoTrackingService(defaultConnectionString));
                    WfRuntime.AddService(new AdoWorkBatchService());
                }

                FlowEvent ExternalEvent = new FlowEvent();
                ExternalDataExchangeService objService = new ExternalDataExchangeService();
                WfRuntime.AddService(objService);
                objService.AddService(ExternalEvent);
                TypeProvider typeProvider = new TypeProvider(null);
                WfRuntime.AddService(typeProvider);
                WfRuntime.StartRuntime();

                WorkflowInstance instance = null;
                try
                {
                    instance = WfRuntime.GetWorkflow(new Guid(INSTANCEID));
                }
                catch
                {
                    instance = null;
                }
                if (instance == null) //try find instance in sql server persistence
                {
                    WfRuntime     = new WorkflowRuntime();
                    ExternalEvent = new FlowEvent();
                    objService    = new ExternalDataExchangeService();
                    WfRuntime.AddService(objService);
                    objService.AddService(ExternalEvent);
                    typeProvider = new TypeProvider(null);
                    WfRuntime.AddService(typeProvider);

                    String connStringPersistence = ConfigurationManager.ConnectionStrings["SqlPersistenceConnection"].ConnectionString;//Data Source=172.30.50.110;Initial Catalog=WorkflowPersistence;Persist Security Info=True;User ID=sa;Password=fbaz2012;MultipleActiveResultSets=True";
                    SqlWorkflowPersistenceService persistence = new SqlWorkflowPersistenceService(connStringPersistence, true, new TimeSpan(0, 2, 0), new TimeSpan(0, 0, 5));
                    WfRuntime.AddService(persistence);
                    WfRuntime.StartRuntime();
                    instance = WfRuntime.GetWorkflow(new Guid(INSTANCEID));
                }
                //WfRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
                //{
                //    instance = null;

                //};
                return(instance);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("GetWorkflowInstance异常信息 :" + ex.ToString());
                throw new Exception(ex.Message);
            }
        }
Exemple #5
0
    public static void StartWorkflowRuntime()
    {
        // Create a new Workflow Runtime for this application
        runtime = new WorkflowRuntime();

        // Create EventHandlers for the WorkflowRuntime
        //runtime.WorkflowTerminated += new EventHandler<WorkflowTerminatedEventArgs>(Runtime_WorkflowTerminated);
        //runtime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(Runtime_WorkflowCompleted);
        //runtime.WorkflowIdled += new EventHandler<WorkflowEventArgs>(Runtime_WorkflowIdled);
        // Add the External Data Exchange Service
        ExternalDataExchangeService dataExchangeService = new ExternalDataExchangeService();

        runtime.AddService(dataExchangeService);

        // Add a new instance of the OrderService to the External Data Exchange Service
        ValuationEvents = new ValuationProcessEvents();
        dataExchangeService.AddService(ValuationEvents);
        // Add Persistance service to the runtime
        SqlWorkflowPersistenceService sqlPersistenceService = new SqlWorkflowPersistenceService("Data Source=blrserver\\sql2005;Initial Catalog=IGRSS_EF;User ID=sa;Password=trans");

        runtime.AddService(sqlPersistenceService);

        // Start the Workflow services
        runtime.StartRuntime();
    }
Exemple #6
0
        /// <summary>
        /// Add any services needed by the runtime engine
        /// </summary>
        /// <param name="instance"></param>
        private static void AddServices(WorkflowRuntime instance)
        {
            //use the standard SQL Server persistence service
            SqlWorkflowPersistenceService persistence =
                new SqlWorkflowPersistenceService(
                    ConfigurationManager.ConnectionStrings
                    ["WorkflowPersistence"].ConnectionString,
                    true, new TimeSpan(0, 2, 0), new TimeSpan(0, 0, 5));

            instance.AddService(persistence);
        }
Exemple #7
0
        /// <summary>
        /// Runs a flow based on a xoml file.
        /// </summary>
        /// <param name="xomlFile">Xoml file name containing the flow. Please note that the .rules file containing the rules
        /// must be located at the same folder as the xoml file.</param>
        /// <param name="parameters">The parameters to pass to the workflow</param>
        /// <param name="conditionValues">The condition values to use in the workflow</param>
        public void RunXomlFlow(string xomlFile, Hashtable parameters, Hashtable conditionValues)
        {
            if (!File.Exists(xomlFile) ||
                xomlFile == null ||
                xomlFile == String.Empty)
            {
                throw new ArgumentException("Invalid workflow parameter. Cannot be null/empty, or xoml file does not exist.");
            }

            Console.WriteLine("Running XOML Flow (" + xomlFile + ")");
            using (WorkflowRuntime runtime = new WorkflowRuntime())
            {
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                runtime.WorkflowCompleted  += delegate(object sender, WorkflowCompletedEventArgs e) { waitHandle.Set(); };
                runtime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                {
                    Console.WriteLine(e.Exception.Message);
                    waitHandle.Set();
                };


                SqlWorkflowPersistenceService persistanceService =
                    new SqlWorkflowPersistenceService(_connectionString);

                runtime.AddService(persistanceService);
                runtime.StartRuntime();

                //Fill the parameters .
                Dictionary <string, object> paramsD = new Dictionary <string, object>();
                paramsD.Add("Parameters", parameters);
                paramsD.Add("ConditionValues", conditionValues);

                WorkflowInstance instance = null;
                using (XmlTextReader reader = new XmlTextReader(xomlFile))
                {
                    string rulesFileName = xomlFile.Replace(".xoml", ".rules");
                    if (File.Exists(rulesFileName))
                    {
                        XmlTextReader rulesFileReader = new XmlTextReader(rulesFileName);
                        instance = runtime.CreateWorkflow(reader, rulesFileReader, paramsD);
                    }
                    else
                    {
                        instance = runtime.CreateWorkflow(reader, null, paramsD);
                    }
                }

                instance.Start();

                waitHandle.WaitOne();
            }
        }
Exemple #8
0
        private static void AddServices()
        {
            #region Basic Workflow Services

            // Add the SqlWorkflowPersistenceService to the runtime engine.
            SqlWorkflowPersistenceService PersistService = new SqlWorkflowPersistenceService(Settings.Default.AppConnectionString);
            Runtime.AddService(PersistService);

            //SqlTrackingService TrackingService = new SqlTrackingService(Settings.Default.AppConnectionString);
            //Runtime.AddService(TrackingService);

            // Add ExternalDataExchangeService to communicate with any running Workflow
            ExternalDataExchangeService DataExchangeService = new ExternalDataExchangeService();
            Runtime.AddService(DataExchangeService);

            #endregion


            #region Igrss Business Services

            ComplainServices = new ComplainService();
            DataExchangeService.AddService(ComplainServices);

            LicenseApplicationServices = new LicenseApplicationService();
            DataExchangeService.AddService(LicenseApplicationServices);

            AppealServices = new AppealService();
            DataExchangeService.AddService(AppealServices);

            RefundServices = new RefundService();
            DataExchangeService.AddService(RefundServices);

            AdjudicationServices = new AdjudicationService();
            DataExchangeService.AddService(AdjudicationServices);

            #endregion

            //ComplainService complainService = new ComplainService();
            //DataService.AddService(complainService);

            //OrderService orderService = OrderService.Instance;
            //dataService.AddService(orderService);

            //OrderTransactionService txnService = new OrderTransactionService();
            //Runtime.AddService(txnService);

            //ContextService = new HttpContextWrapper();
        }
Exemple #9
0
        static void Main()
        {
            try
            {
                // Create the WorkflowRuntime
                using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
                {
                    // Add the SqlWorkflowPersistenceService service
                    WorkflowPersistenceService persistenceService =
                        new SqlWorkflowPersistenceService(
                            "Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;",
                            false,
                            new TimeSpan(1, 0, 0),
                            new TimeSpan(0, 0, 5));
                    workflowRuntime.AddService(persistenceService);

                    // Set up the WorkflowRuntime event handlers
                    workflowRuntime.WorkflowCompleted  += OnWorkflowCompleted;
                    workflowRuntime.WorkflowIdled      += OnWorkflowIdled;
                    workflowRuntime.WorkflowPersisted  += OnWorkflowPersisted;
                    workflowRuntime.WorkflowUnloaded   += OnWorkflowUnloaded;
                    workflowRuntime.WorkflowLoaded     += OnWorkflowLoaded;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                    workflowRuntime.WorkflowAborted    += OnWorkflowAborted;


                    // Load the workflow type
                    Type type = typeof(PersistenceServicesWorkflow);

                    // Create an instance of the workflow
                    Console.WriteLine("Workflow Started.");
                    workflowRuntime.CreateWorkflow(type).Start();

                    // Wait for the event to be signaled
                    waitHandle.WaitOne();

                    // Stop the runtime
                    workflowRuntime.StopRuntime();
                    Console.WriteLine("Program Complete.");
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Application exception occurred: " + exception.Message);
            }
        }
        /// <summary>
        /// Installs the workflow services.
        /// </summary>
        private static void InstallWorkflowServices(string connectionString)
        {
            // WorkFlow Work In ASP.NET Thread
            WorkflowRuntime.AddService(new ManualWorkflowSchedulerService());

            // SQL Persistence Service
            if (!string.IsNullOrEmpty(connectionString))
            {
                SqlWorkflowPersistenceService sqlSvc = new SqlWorkflowPersistenceService(
                    connectionString,
                    true,
                    TimeSpan.MaxValue,                     // TimeSpan.FromSeconds(90)
                    TimeSpan.FromSeconds(120));

                WorkflowRuntime.AddService(sqlSvc);
            }
        }
Exemple #11
0
        private void InitializeWorkflowRuntime()
        {
            // Get tracking database connection string from application settings
            String connectionString = Properties.Settings.Default.ClassRegistrationTrackingConnectionString;

            // Add External Data Service to process approval/rejection
            ExternalDataExchangeService dataService = new ExternalDataExchangeService();

            workflowRuntime.AddService(dataService);
            dataService.AddService(registrationApprover);

            // Add Sql Persistence service
            sqlService = new SqlWorkflowPersistenceService(connectionString);
            workflowRuntime.AddService(sqlService);

            // Start runtime
            workflowRuntime.StartRuntime();
        }
Exemple #12
0
        /// <summary>
        /// Add any services needed by the runtime engine
        /// </summary>
        /// <param name="instance"></param>
        private static void AddServices(WorkflowRuntime instance)
        {
            //use the standard SQL Server persistence service
            SqlWorkflowPersistenceService persistence =
                new SqlWorkflowPersistenceService(
                    ConfigurationManager.ConnectionStrings
                    ["WorkflowPersistence"].ConnectionString,
                    true, new TimeSpan(0, 2, 0), new TimeSpan(0, 0, 5));

            instance.AddService(persistence);

            //add the external data exchange service to the runtime
            ExternalDataExchangeService exchangeService
                = new ExternalDataExchangeService();

            instance.AddService(exchangeService);

            //add our local service
            exchangeService.AddService(new BatchedService());
        }
Exemple #13
0
        /// <summary>
        /// Runs a new workflow. Used mainly to save the workflow as a template.
        /// </summary>
        /// <param name="wfType">The type of the workflow</param>
        /// <param name="parameters">The parameters to use in the workflow</param>
        /// <param name="conditionValues">The condition values to use in the workflow</param>
        public void RunNewFlow(Type wfType, Hashtable parameters, Hashtable conditionValues)
        {
            Console.WriteLine("Running New Flow. Type: " + wfType.ToString());
            using (WorkflowRuntime runtime = new WorkflowRuntime())
            {
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                runtime.WorkflowCompleted  += delegate(object sender, WorkflowCompletedEventArgs e) { waitHandle.Set(); };
                runtime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                {
                    Console.WriteLine(e.Exception.Message);
                    waitHandle.Set();
                };

                SqlWorkflowPersistenceService persistanceService =
                    new SqlWorkflowPersistenceService(_connectionString);

                runtime.AddService(persistanceService);
                runtime.StartRuntime();

                //Fill the parameters .
                Dictionary <string, object> paramsD = new Dictionary <string, object>();
                paramsD.Add("Parameters", parameters);
                paramsD.Add("ConditionValues", conditionValues);

                WorkflowInstance instance = runtime.CreateWorkflow(wfType, paramsD);

                //This is a new workflow. Save it into the database.
                BaseSequentialWorkflow esw = (BaseSequentialWorkflow)Activator.CreateInstance(wfType);
                esw.WorkflowGUID     = instance.InstanceId;
                esw.ConditionValues  = conditionValues;
                esw.Parameters       = parameters;
                esw.ConnectionString = _connectionString;
                esw.Template         = true;
                esw.WorkflowType     = wfType;
                esw.Serialize();

                instance.Start();

                waitHandle.WaitOne();
            }
        }
Exemple #14
0
        static void Main(string[] args)
        {
            const string persistenceConnectionString = "Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;";
            const string transactionServiceDataBase  = "Initial Catalog=TransactionServiceSampleDB;Data Source=localhost;Integrated Security=SSPI;Enlist=false;";
            bool         validInteger   = false;
            Int32        transferAmount = 0;

            //Display account balances before requesting transfer amount
            QueryAccountService queryAccounts = new QueryAccountService(transactionServiceDataBase);

            Int32[] accountBalances = queryAccounts.QueryAccount(1);
            Console.WriteLine("The account balances for account number {0} are:  Checking : {1:c} , Savings : {2:c}",
                              1, accountBalances[0], accountBalances[1]);

            Console.WriteLine("Please enter an amount to transfer from Savings to Checking");

            while (!validInteger)
            {
                try
                {
                    transferAmount = Convert.ToInt32(Console.ReadLine());
                    if (transferAmount < 0)
                    {
                        Console.WriteLine("Please enter an amount greater than zero.");
                    }
                    else
                    {
                        validInteger = true;
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine("Please enter a valid amount and try again.");
                }
            }

            //Initiate the workflow run time
            using (WorkflowRuntime runtime = new WorkflowRuntime())
            {
                // Add the SQL persistence service
                SqlWorkflowPersistenceService persistenceService = new SqlWorkflowPersistenceService(persistenceConnectionString);
                runtime.AddService(persistenceService);

                // Add the query account service. This will be used to query the account balances
                runtime.AddService(queryAccounts);

                // Add the transactional service. This is the service which
                // does the work of crediting and debiting the amounts
                // This service participates in the work batch of the workflow instance
                TransactionalService transactionService = new TransactionalService(transactionServiceDataBase);
                runtime.AddService(transactionService);
                runtime.WorkflowCompleted  += new EventHandler <WorkflowCompletedEventArgs>(wr_OnWorkflowCompleted);
                runtime.WorkflowAborted    += new EventHandler <WorkflowEventArgs>(wr_OnWorkflowAborted);
                runtime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                {
                    Console.WriteLine(e.Exception.Message);
                    waitHandle.Set();
                };
                runtime.StartRuntime();
                Dictionary <string, object> parameters = new Dictionary <string, object>();
                parameters.Add("TransferAmount", transferAmount);

                // Initiate the workflow
                runtime.CreateWorkflow(typeof(BalanceTransferWorkflow), parameters).Start();
                Console.WriteLine("Running the workflow");

                // Wait for the workflow to finish
                waitHandle.WaitOne();

                Console.WriteLine("Done running the workflow.");

                runtime.StopRuntime();
            }
        }