Пример #1
0
        private static bool ResumeWorkflow(Guid instanceId, RegistrationCommand command)
        {
            // Try to load the workflow and resume the bookmark
            var host        = LoadRegistrationWorkflow(instanceId);
            var commandDone = new AutoResetEvent(false);

            // Run the workflow until idle, or complete
            host.Completed += completedEventArgs => commandDone.Set();
            host.Idle      += args => commandDone.Set();

            Exception abortedException = null;

            host.Aborted += abortedEventArgs =>
            {
                abortedException = abortedEventArgs.Reason;
                commandDone.Set();
            };

            // Resume the bookmark and Wait for the workflow to complete
            // ReSharper disable AssignNullToNotNullAttribute
            if (host.ResumeBookmark(command.ToString(), null) != BookmarkResumptionResult.Success) // ReSharper restore AssignNullToNotNullAttribute
            {
                throw new InvalidOperationException("Unable to resume registration process with command " + command);
            }

            if (!commandDone.WaitOne(Timeout))
            {
                throw new TimeoutException("Timeout waiting to confirm registration");
            }

            if (abortedException != null)
            {
                throw abortedException;
            }

            return(abortedException == null);
        }