workflow-core icon indicating copy to clipboard operation
workflow-core copied to clipboard

GetDefinition fails when no version is provided and workflowid is not registered yet

Open datametrics opened this issue 8 years ago • 1 comments

Hi all,

found a little bug when a concrete implementation is not registered yet and startworkflow is called without specific version:

I solved it for me with the following two lines in the registry:

if (!_registry.Any(x => x.Item1 == workflowId)) return null;

    public WorkflowDefinition GetDefinition(string workflowId, int? version = null)
    {
        if (version.HasValue)
        {
            var entry = _registry.FirstOrDefault(x => x.Item1 == workflowId && x.Item2 == version.Value);
            if (entry == null)
            {
                return null;
            }
            return entry.Item3;
        }
        else
        {
            if (!_registry.Any(x => x.Item1 == workflowId))
                return null;

            int maxVersion = _registry.Where(x => x.Item1 == workflowId).Max(x => x.Item2);
            var entry = _registry.FirstOrDefault(x => x.Item1 == workflowId && x.Item2 == maxVersion);
            if (entry == null)
            {
                return null;
            }
            return entry.Item3;
        }
    }

Regards,

d-metrics

datametrics avatar May 13 '18 21:05 datametrics

😃 thanks Would you be willing to make a PR? I'd really like to get more code contributors on this project, I'm a huge bottle neck at the moment

danielgerlag avatar May 17 '18 23:05 danielgerlag