Exemplo n.º 1
0
        static void Main(string[] args)
        {
            string response = string.Empty;

            Process.GetCurrentProcess().Exited += new EventHandler(process_Exited);

            // test option
            bool bIsStateMachineTest = false;

            try
            {
                // hosting remoting
                string configFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
                RemotingConfiguration.Configure(configFile, false);

                // hosting workflow and trace handlers
                WorkflowRuntime wr = WorkflowHosting.Attach("WorkflowRuntimeConfig", "LocalServicesConfig");
                wr.WorkflowIdled     += new EventHandler <WorkflowEventArgs>(wr_WorkflowIdled);
                wr.WorkflowPersisted += new EventHandler <WorkflowEventArgs>(wr_WorkflowPersisted);
                wr.WorkflowCompleted += new EventHandler <WorkflowCompletedEventArgs>(wr_WorkflowCompleted);
                wr.WorkflowCreated   += new EventHandler <WorkflowEventArgs>(wr_WorkflowCreated);
                wr.WorkflowStarted   += new EventHandler <WorkflowEventArgs>(wr_WorkflowStarted);
                wr.WorkflowLoaded    += new EventHandler <WorkflowEventArgs>(wr_WorkflowLoaded);
                wr.WorkflowUnloaded  += new EventHandler <WorkflowEventArgs>(wr_WorkflowUnloaded);

                // workflow init data
                Dictionary <string, object> dictionary = new Dictionary <string, object>();
                HybridDictionary            initData   = new HybridDictionary();
                initData["abc"] = 12345;
                dictionary.Add("InitData", initData);
                dictionary.Add("Counter", 10);

                // create and persiste our test state machine (myWorkflow6), - SqlWorkflowPersistenceService is required
                Guid stateMachineId = Guid.NewGuid();
                bool bIsUnloaded    = WorkflowInvoker.CreateAndUnload("myWorkflow6", dictionary, stateMachineId);
                Console.WriteLine("StateMachine {0} has been created and unloaded={1}\n\n", stateMachineId, bIsUnloaded);

                for (int ii = 0; ii < 10000; ii++)
                {
                    // each call will have an unique context
                    using (LogicalWorkflowContext lwc = LCC.LogicalWorkflowContext)
                    {
                        // application specific Context for test purpose
                        CallContext.SetData("LogicalTicket", new LogicalTicket(Guid.NewGuid(), Convert.ToString(ii)));
                        CallContext.SetData("Ticket", Guid.NewGuid());
                        lwc.Properties["MyTest"] = DateTime.Now;

                        // some workflow init data
                        lwc.WorkflowInitData["InitData"] = initData;

                        // use this Guid (for persisted state machine) - SqlWorkflowPersistenceService is required
                        //lwc.WorkflowId = stateMachineId;

                        // endpoint scenarios for some kind of tests
                        string endpoint = "wf://localhost/myWorkflow5";   // tcp remoting (workflow5)
                        //endpoint = "tcp://localhost:1234/myWorkflow5";  // null remoting
                        //endpoint = "tcp://localhost:1234/myWorkflow6";  // tcp remoting - state machine
                        //endpoint = "wf://localhost/myWorkflow6";        // null remoting - state machine
                        //endpoint = "tcp://localhost:1234/myWorkflow4";  // tcp remoting with chaining (workflow4 -> workflow5)
                        //endpoint = "wf://localhost/myWorkflow4";        // null remoting
                        //endpoint = "wf://localhost/myWorkflow7";        // null remoting - workflow craeted by xoml
                        //endpoint = "wcf://myWorkflow4";                   // wcf/workflow invoker



                        if (bIsStateMachineTest)
                        {
                            // action 1: - standard way
                            ITest test = (ITest)Activator.GetObject(typeof(ITest), endpoint);
                            response = test.SayHello(string.Format("[{0}]: Hello world", ii));

                            // use the same state machine - SqlWorkflowPersistenceService is required
                            LCC.LogicalWorkflowContext.WorkflowId = stateMachineId;

                            // action 2: - another way how to invoke workflow
                            WorkflowInvoker.Contract <ITest>(endpoint).OneWay(string.Format("[{0}]: Hello world", ii));
                            //response = WorkflowInvoker.Contract<ITest>(endpoint).SayHello(string.Format("[{0}]: Hello world", ii));
                        }
                        else
                        {
                            // action 1:
                            ITest test = (ITest)Activator.GetObject(typeof(ITest), endpoint);
                            response = test.SayHello(string.Format("[{0}]: Hello world", ii));

                            // action 2:
                            //WorkflowInvoker.Contract<ITest>(endpoint).OneWay(string.Format("[{0}]: Hello world", ii));
                        }

                        // show CallContext
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("LWC={0}, Client.Response:    {1}, CallContext: {2}", LCC.LogicalWorkflowContext.ContextId, response, ConvertListToText(LCC.GetKeys()));
                        Console.ResetColor();

                        Console.ReadLine();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException == null ? ex : ex.InnerException);
                Console.ReadLine();
            }
            finally
            {
                // workflow
                WorkflowHosting.Detach();
            }
        }
Exemplo n.º 2
0
 private void Workflow5_Received(object sender, EventArgs e)
 {
     Console.WriteLine("LWC={0}, {1}.Received: {2}, CallContext: {3}", LCC.LogicalWorkflowContext.ContextId, this.Name, Workflow5_msg1, Helpers.ConvertListToText(LCC.GetKeys()));
 }
Exemplo n.º 3
0
        private void OnCleanup(object sender, EventArgs e)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("LWC={0}, {1}.Exit,\t\t\tCallContext: {2}", LCC.LogicalWorkflowContext.ContextId, this.Name, Helpers.ConvertListToText(LCC.GetKeys()));
            Console.ResetColor();

            if (StateMsg == "Fire")
            {
                Console.WriteLine();
            }
        }
Exemplo n.º 4
0
 private void OnFinish(object sender, EventArgs e)
 {
     StateMsg = "Finish";
     Console.WriteLine("LWC={0}, {1}.Finish, Counter={2},\t\tCallContext: {3}", LCC.LogicalWorkflowContext.ContextId, this.Name, Counter, Helpers.ConvertListToText(LCC.GetKeys()));
 }
Exemplo n.º 5
0
 private void OnFireProcessor(object sender, EventArgs e)
 {
     StateMsg = "Fire";
     Console.WriteLine("LWC={0}, {1}.OnFire:   {2},\tCallContext: {3}", LCC.LogicalWorkflowContext.ContextId, this.Name, Connector_msg1, Helpers.ConvertListToText(LCC.GetKeys()));
 }
Exemplo n.º 6
0
 private void OnSayHelloProcessor(object sender, EventArgs e)
 {
     StateMsg = "SayHello";
     Counter++;
     Return__ReturnValue_1 = Connector_msg1;
     Console.WriteLine("LWC={0}, {1}.SayHello: {2},\tCallContext: {3}", LCC.LogicalWorkflowContext.ContextId, this.Name, Connector_msg1, Helpers.ConvertListToText(LCC.GetKeys()));
 }
Exemplo n.º 7
0
 private void OnInit(object sender, EventArgs e)
 {
     StateMsg = "Init";
     Console.WriteLine("LWC={0}, {1}.Init,\t\t\tCallContext: {2}", LCC.LogicalWorkflowContext.ContextId, this.Name, Helpers.ConvertListToText(LCC.GetKeys()));
 }