Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting CRySTAL...");
            Console.WriteLine("Linking Workflow Runtime Services...");
            CRySTAL.WorkflowInterface.WorkflowInterface.CustomerWF = new CRySTAL.WorkflowInterface.CustomerWorkflowInterface();
            WorkflowRuntime workflowRuntime = new WorkflowRuntime();
            AppDomain.CurrentDomain.SetData("WorkflowRuntime", workflowRuntime);
            ManualWorkflowSchedulerService manualScheduler =
                new ManualWorkflowSchedulerService(true);
            AppDomain.CurrentDomain.SetData("ManualScheduler", manualScheduler);
            workflowRuntime.AddService(manualScheduler);
            ExternalDataExchangeService des = new ExternalDataExchangeService();
            workflowRuntime.AddService(des);
            des.AddService(CRySTAL.WorkflowInterface.WorkflowInterface.CustomerWF);

            TimeSpan reloadIntevral = new TimeSpan(0, 0, 0, 20, 0);
            TimeSpan ownershipDuration = new TimeSpan(0, 0, 30, 0);
            string connectionString = @"Data Source=ETHIELE-LENOVO\SQLEXPRESS;Initial Catalog=WFTrackingAndPersistence;Integrated Security=True";
            SqlWorkflowPersistenceService sqlPersistenceService =
                new SqlWorkflowPersistenceService(connectionString, true, ownershipDuration, reloadIntevral);
            workflowRuntime.AddService(sqlPersistenceService);

            SqlTrackingService sts = new SqlTrackingService(connectionString);
            workflowRuntime.AddService(sts);

            Console.WriteLine("Starting Workflow Runtime...");
            workflowRuntime.StartRuntime();

            //AppDomain.CurrentDomain.SetData("firstNamestr", "thisisatest");
            List<ServiceHost> hosts = new List<ServiceHost>();
            hosts.Add(new ServiceHost(typeof(CRySTAL.CookService)));
            hosts.Add(new ServiceHost(typeof(CRySTAL.BusBoyService)));
            hosts.Add(new ServiceHost(typeof(CRySTAL.HostService)));
            hosts.Add(new ServiceHost(typeof(CRySTAL.LoginService)));
            hosts.Add(new ServiceHost(typeof(CRySTAL.MenuService)));
            hosts.Add(new ServiceHost(typeof(CRySTAL.WaiterService)));
            foreach (ServiceHost host in hosts)
            {
                host.Open();
                Console.WriteLine("CRySTAL: Service Running: " + host.BaseAddresses[0].ToString());
            }
            Console.WriteLine("CRySTAL Ready");

            Console.ReadLine();

            Console.WriteLine("Shutting down CRySTAL...");
            foreach (ServiceHost host in hosts)
            {
                host.Close();
                Console.WriteLine("CRySTAL: Shutingdown Service :" + host.BaseAddresses[0].ToString());
            }
            Console.WriteLine("Shutting down runtime...");
            workflowRuntime.StopRuntime();
            Console.WriteLine("CRySTAL shutdown complete");
            Console.ReadLine();
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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();
    }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
        public override void Initialize(string name, NameValueCollection config)
        {
            base.Initialize(name, config);

            if (!string.IsNullOrEmpty(config["applicationName"]))
            {
                this._applicationName = config["applicationName"];
                config.Remove("applicationName");
            }

            if (!string.IsNullOrEmpty(config["connectionStringName"]))
            {
                this._connectionStringName = config["connectionStringName"];
                config.Remove("connectionStringName");
            }

            if (!string.IsNullOrEmpty(config["synchronousExecution"]))
            {
                this._synchronousExecution = Convert.ToBoolean(config["synchronousExecution"]);
                config.Remove("synchronousExecution");
            }

            if (!string.IsNullOrEmpty(config["defaultStartTime"]))
            {
                this._defaultEndTime = config["defaultStartTime"];
                config.Remove("defaultStartTime");
            }

            if (!string.IsNullOrEmpty(config["defaultEndTime"]))
            {
                this._defaultEndTime = config["defaultEndTime"];
                config.Remove("defaultEndTime");
            }

            if (!string.IsNullOrEmpty(config["timeToExpire"]))
            {
                this._timeToExpire = TimeSpan.Parse(config["timeToExpire"]);
                config.Remove("timeToExpire");
            }

            if (!string.IsNullOrEmpty(config["includeWeekends"]))
            {
                this._includeWeekends = Convert.ToBoolean(config["includeWeekends"]);
                config.Remove("includeWeekends");
            }

            if (!string.IsNullOrEmpty(config["requestSchemaPath"]))
            {
                this._requestSchemaPath = config["requestSchemaPath"];
                config.Remove("requestSchemaPath");
            }

            if (!string.IsNullOrEmpty(config["responseSchemaPath"]))
            {
                this._responseSchemaPath = config["responseSchemaPath"];
                config.Remove("responseSchemaPath");
            }

            if (config.Count > 0)
                throw new ProviderException(string.Format("Unknown config attribute '{0}'", config.GetKey(0)));

            #region Workflow Runtime Initialization

            if (theWorkflowRuntime == null)
            {
                lock (this)
                {
                    if (theWorkflowRuntime == null)
                    {
                        theWorkflowRuntime = new WorkflowRuntime();

                        theWorkflowRuntime.WorkflowLoaded += new EventHandler<WorkflowEventArgs>(theWorkflowRuntime_WorkflowLoaded);
                        theWorkflowRuntime.WorkflowIdled += new EventHandler<WorkflowEventArgs>(theWorkflowRuntime_WorkflowIdled);
                        theWorkflowRuntime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(theWorkflowRuntime_WorkflowCompleted);
                        theWorkflowRuntime.WorkflowTerminated += new EventHandler<WorkflowTerminatedEventArgs>(theWorkflowRuntime_WorkflowTerminated);
                        theWorkflowRuntime.WorkflowSuspended += new EventHandler<WorkflowSuspendedEventArgs>(theWorkflowRuntime_WorkflowSuspended);

                        // Used for synchronous execution of workflow instances.
                        if (this.SynchronousExecution)
                            theSchedulerService = theWorkflowRuntime.GetService<ManualWorkflowSchedulerService>();

                        // Add the external data service
                        ExternalDataExchangeService dataService = new ExternalDataExchangeService();
                        theWorkflowRuntime.AddService(dataService);

                        // Add custom wiki management service.
                        theServiceProvider = new ServiceProviderHelper();
                        dataService.AddService(theServiceProvider);

                        // Add system SQL state service.
                        SqlWorkflowPersistenceService stateService = new SqlWorkflowPersistenceService(
                            ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString);
                        theWorkflowRuntime.AddService(stateService);

                        try
                        {
                            Trace.TraceInformation("Starting workflow engine.");
                            // Start
                            theWorkflowRuntime.StartRuntime();
                            Trace.TraceInformation("Workflow engine was sucessfully started.");
                        }
                        catch (Exception ex)
                        {
                            Trace.TraceError(string.Format(
                                "Error while starting the workflow engine. Description: {0}", ex.Message));
                            theWorkflowRuntime.Dispose();
                            throw;
                        }
                    }
                }
            }

            #endregion
        }
Exemplo n.º 6
0
        /// <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);
            }
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                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.Message);
                    waitHandle.Set();
                };

                // Add Persistence and Tracking
                SqlWorkflowPersistenceService persistenceService;
                persistenceService = new SqlWorkflowPersistenceService(
                            ConfigurationManager.
                            ConnectionStrings["PersistentDataStore"].
                            ConnectionString, true, TimeSpan.MaxValue, TimeSpan.MinValue);
                workflowRuntime.AddService(persistenceService);

                SqlTrackingService trackingService;
                trackingService = new SqlTrackingService(
                            ConfigurationManager.
                            ConnectionStrings["PersistentDataStore"].
                            ConnectionString);
                trackingService.UseDefaultProfile = true;
                workflowRuntime.AddService(trackingService);

                // Set up the data exchange
                ExternalDataExchangeService dataExchange;
                dataExchange = new ExternalDataExchangeService();
                workflowRuntime.AddService(dataExchange);

                // Instatiate the local communication service
                CustomerCallService customerCallService = new CustomerCallService();
                dataExchange.AddService(customerCallService);

                // Create a new workflow instance
                WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(CustomerService));
                instance.Start();

                // Create a new Call
                Call newCall = new Call();
                newCall.CallersFirstName = "Alex";
                newCall.Product = "Widget Number Nine";

                // Change the state using the service and events
                customerCallService.ReceiveCall(instance.InstanceId, newCall);
                customerCallService.SendCallToPhoneResolution(instance.InstanceId, newCall);
                customerCallService.AssignCallToSupportPerson(instance.InstanceId, newCall);

                //Get a look at where we have wound up
                PrintStateMachineState(workflowRuntime, instance.InstanceId);

                // Change the state one last time
                customerCallService.ResolveCall(instance.InstanceId, newCall);

                // Print the history of our instance
                PrintHistory(workflowRuntime, instance.InstanceId);

                waitHandle.WaitOne();

                // Keep the console open until key strokes are entered so that you can see what we did...
                Console.ReadLine();
            }
        }
Exemplo n.º 8
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();
            }
        }