Esempio n. 1
0
        public async Task <string> StartWorkflowAsync(string workflowId, int?version, Dictionary <string, object> data)
        {
            var wfd = _registry.GetWorkflowDefinition(workflowId, version);

            if (wfd == null)
            {
                throw new WorkflowNotRegisteredException(workflowId, version);
            }

            var wfi = new WorkflowInstance()
            {
                Id         = Guid.NewGuid().ToString(),
                WorkflowId = wfd.Id,
                Steps      = wfd.Steps,
                Data       = wfd.Data,
                Version    = wfd.Version
            };

            if (wfi.Data == null)
            {
                wfi.Data = data;
            }
            else
            {
                foreach (var dataKey in data.Keys)
                {
                    if (wfi.Data.ContainsKey(dataKey))
                    {
                        wfi.Data[dataKey] = data[dataKey];
                    }
                    else
                    {
                        wfi.Data.Add(dataKey, data[dataKey]);
                    }
                }
            }

            if (await _tokenBucket.TryGetToken(default))