public InstanceViewModel(WorkflowInstanceInfo instanceInfo)
        {
            if (instanceInfo != null)
            {
                this.Name               = instanceInfo.InstanceName;
                this.LastModified       = instanceInfo.LastModified.ToLocalTime();
                this.CreatedTime        = instanceInfo.CreationTime.ToLocalTime();
                this.UserStatus         = instanceInfo.UserStatus ?? "(None)";
                this.WorkflowStatus     = instanceInfo.WorkflowStatus.ToString();
                this.ActivationMetadata = (IDictionary)instanceInfo.ActivationParameters.Metadata;

                if (instanceInfo.MappedVariables != null)
                {
                    // CONSIDER: Create a view model specifically for mapped variables which removes the XName namespace
                    IDictionary mappedVariableHashtable = new Hashtable(instanceInfo.MappedVariables.Count);
                    foreach (KeyValuePair <XName, string> pair in instanceInfo.MappedVariables)
                    {
                        mappedVariableHashtable.Add(pair.Key.LocalName, pair.Value);
                    }

                    this.MappedVariables = mappedVariableHashtable;
                }

                this.ShowActivationMetadataCommand = new SimpleActionCommand(this.OnShowMetadata);
                this.ShowMappedVariablesCommand    = new SimpleActionCommand(this.OnShowMappedVariables);
            }
        }
Esempio n. 2
0
        public static string WaitForWorkflowCompletion(this WorkflowManagementClient client, string workflowName, string instanceId, int pollingInterval = 0)
        {
            string currentStatus = string.Empty;
            string lastStatus    = string.Empty;

            WorkflowInstanceInfo instanceInfo = client.Instances.Get(workflowName, instanceId);

            while (true)
            {
                instanceInfo = client.Instances.Get(workflowName, instanceId);

                currentStatus = instanceInfo.UserStatus;

                if (currentStatus != lastStatus && !string.IsNullOrWhiteSpace(currentStatus))
                {
                    Console.Write("   Current Status: ");
                    WorkflowUtils.Print(currentStatus, ConsoleColor.Cyan);
                    lastStatus = currentStatus;
                }

                if (instanceInfo.WorkflowStatus == WorkflowInstanceStatus.Started || instanceInfo.WorkflowStatus == WorkflowInstanceStatus.NotStarted)
                {
                    Thread.Sleep(pollingInterval);
                    continue;
                }

                if (instanceInfo.WorkflowStatus == WorkflowInstanceStatus.Completed)
                {
                    Console.WriteLine("\nWorkflow instance completed");
                }

                break;
            }

            return(instanceInfo.UserStatus);
        }