Пример #1
0
        private void Unload(Guid workflowInstanceId) //that's weird!
        {
            WorkflowApplicationInstance instance = WorkflowApplication.GetInstance(workflowInstanceId, _store);

            // Unload the instance.
            instance.Abandon();
        }
        private void InstanceId_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (InstanceId.SelectedIndex == -1)
            {
                return;
            }

            // Clear the status window.
            WorkflowStatus.Clear();

            // If there is tracking data for this workflow, display it
            // in the status window.
            if (File.Exists(WorkflowInstanceId.ToString()))
            {
                string status = File.ReadAllText(WorkflowInstanceId.ToString());
                UpdateStatus(status);
            }

            // Get the workflow version and display it.
            // If the workflow is just starting then this info will not
            // be available in the persistence store so do not try and retrieve it.
            if (!WorkflowStarting)
            {
                WorkflowApplicationInstance instance =
                    WorkflowApplication.GetInstance(this.WorkflowInstanceId, store);

                WorkflowVersion.Text =
                    WorkflowVersionMap.GetIdentityDescription(instance.DefinitionIdentity);

                // Unload the instance.
                instance.Abandon();
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore(connectionString);

            WorkflowApplication.CreateDefaultInstanceOwner(store, null, WorkflowIdentityFilter.Any);

            IDictionary <WorkflowIdentity, DynamicUpdateInfo> updateMaps = LoadMaps();

            foreach (Guid id in GetIds())
            {
                // Get a proxy to the instance.
                WorkflowApplicationInstance instance =
                    WorkflowApplication.GetInstance(id, store);

                Console.WriteLine("Inspecting: {0}", instance.DefinitionIdentity);

                // Only update v1 workflows.
                if (instance.DefinitionIdentity != null &&
                    instance.DefinitionIdentity.Version.Equals(new Version(1, 0, 0, 0)))
                {
                    DynamicUpdateInfo info = updateMaps[instance.DefinitionIdentity];

                    // Associate the persisted WorkflowApplicationInstance with
                    // a WorkflowApplication that is configured with the updated
                    // definition and updated WorkflowIdentity.
                    Activity            wf    = WorkflowVersionMap.GetWorkflowDefinition(info.newIdentity);
                    WorkflowApplication wfApp =
                        new WorkflowApplication(wf, info.newIdentity);

                    // Apply the Dynamic Update.
                    wfApp.Load(instance, info.updateMap);

                    // Persist the updated instance.
                    wfApp.Unload();

                    Console.WriteLine("Updated to: {0}", info.newIdentity);
                }
                else
                {
                    // Not updating this instance, so unload it.
                    instance.Abandon();
                }
            }
        }
Пример #4
0
        public static void RunScenario()
        {
            //***********************************************************
            // STEP 1: create a WorkflowApplication with a definition,
            //         and an identity, start an instance, and persist it and
            //         unload it when it gets idle
            //***********************************************************

            // Create a workflow application using identity
            // notice that the delta between WF4 is the following:
            //    - create an instance of WorkflowIdentity
            //    - pass it to WorkflowApplication in its constructor
            WorkflowIdentity identityV1 =
                new WorkflowIdentity("Dev11-Sample",
                                     new Version(1, 0, 0, 0), null);
            WorkflowApplication application = new WorkflowApplication(new Activity1(), identityV1);

            // create the instance store and assign it to the workflow application
            application.InstanceStore = Utils.SetupInstanceStore();

            // start an instance, unload it, and persist it into the instance store
            Guid instanceId = Utils.StartAndUnloadInstance(application);

            // read input from the console
            string input = Console.ReadLine();


            //***********************************************************
            // STEP 2: given an instance id, look up the definition in the
            //         instance store, configure a workflow application
            //         load the instance, and continue with its execution
            //***********************************************************
            // load the instance with the correct definition
            WorkflowApplicationInstance instance       = null;
            WorkflowApplication         newApplication = null;
            AutoResetEvent syncEvent = new AutoResetEvent(false);

            try
            {
                // get a proxy to the running instance
                instance = WorkflowApplication.GetInstance(instanceId, Utils.SetupInstanceStore());

                // get the definition associated to the identity of the instance
                // for this we are using a dictionary with key=identity; value=activity
                Activity definition = WorkflowDefinitionRepository.GetActivity(instance.DefinitionIdentity);

                // create and configure the workflowApplication
                newApplication = new WorkflowApplication(definition, instance.DefinitionIdentity);

                // configure the workflow application
                newApplication.Completed = (e) => Utils.ShowMessageFromHost(string.Format("WorkflowApplication has Completed in the {0} state.", e.CompletionState), ConsoleColor.Green);
                newApplication.Unloaded  = (e) => syncEvent.Set();

                // show messages in the console
                Utils.ShowMessageFromHost("Loading the workflow using its identity in the InstanceStore...", ConsoleColor.Cyan);
                Utils.ShowMessageFromHost(string.Format("Loading with identity '{0}'", instance.DefinitionIdentity.ToString()));

                // load the application (passing the instance that we got previously)
                newApplication.Load(instance);

                //this resumes the bookmark setup by readline
                newApplication.ResumeBookmark("ReadLine", input);
                syncEvent.WaitOne();
            }
            catch
            {
                // if there is an error, discard the instance so it does not remain locked
                if (newApplication != null && instance != null)
                {
                    instance.Abandon();
                }
            }
        }