Esempio n. 1
0
        /// <summary>
        /// Process the tracking record and update instance status.
        /// </summary>
        /// <param name="instanceRecord">The instance record.</param>
        private void OnWorkflowInstanceRecord(WorkflowInstanceRecord instanceRecord)
        {
            IChannelInstance channelInstance;
            _instances.TryGetValue(instanceRecord.InstanceId, out channelInstance);

            switch (instanceRecord.State)
            {
                case "Started":
                    if (channelInstance == null)
                    {
                        channelInstance = new ChannelInstance(this, instanceRecord.InstanceId);
                        _instances.TryAdd(instanceRecord.InstanceId, channelInstance);
                    }

                    channelInstance.State = instanceRecord.State;
                    break;

                case "Idle":
                    if (channelInstance == null)
                        return;
                    channelInstance.State = channelInstance.Pipelines.Any(p => !p.IsCompleted)
                        ? "Processing"
                        : instanceRecord.State;
                    break;

                case "Completed":
                case "Canceled":
                    if (channelInstance == null)
                        return;
                    channelInstance.State = instanceRecord.State;
                    channelInstance.CompletedAt = DateTimeOffset.Now;
                    channelInstance.IsCompleted = true;
                    break;

                case "Deleted":
                    if (channelInstance == null)
                        return;
                    // TODO: Schedule archive/removal
                    channelInstance.IsDeleted = true;
                    break;
            }

            // Publish the updated instance
            ChannelBus.Publish(channelInstance);
        }
Esempio n. 2
0
        /// <summary>
        /// Called when workflow needs to create a pipeline manager for an instance.
        /// </summary>
        /// <returns>Pipeline Manager.</returns>
        private IPipelineManager OnCreatePipelineManager()
        {
            var manager = new PipelineManager(this);
            manager.WorkflowInstanceSet = instance =>
            {
                var channelInstance = new ChannelInstance(this, instance.Id) { PipelineManager = manager };
                _instances.TryAdd(instance.Id, channelInstance);
            };

            return manager;
        }