public void DeployWorkflow(Guid guid) { List <ProcessDefinition> defs = new List <ProcessDefinition>(); _registries.ForEach(r => { ProcessDefinition pd; if (r.TryGet(guid, out pd)) { defs.Add(pd); } }); if (defs.Count == 0) { throw new ArgumentException($"No Process Definition with ID={guid} was found."); } if (defs.Count > 1) { throw new ArgumentException($"{defs.Count} Process Definitions with ID={guid} was found."); } Md5CalcVisitor visitor = new Md5CalcVisitor(); defs[0].Accept(visitor); string md5 = visitor.CalculateMd5(); IReadOnlyList <ProcessDefinitionDigest> processes = _persistence.LisAlltWorkflows(); var processDefinitionDigests = processes.Where(p => p.Id == guid).ToArray(); int nextVersion = processDefinitionDigests.Length > 0?processDefinitionDigests.Max(p => p.Version) + 1:1; foreach (ProcessDefinitionDigest p in processDefinitionDigests) { if (p.Md5 == md5) { throw new ArgumentException($"Process ID={defs[0].Id} MD5={md5} already deployed. Cannot deploy the same process with the same MD5."); } } foreach (ProcessDefinitionDigest p in processes) { _persistence.SetStatus(p.Id, p.Version, ProcessDefStatusEnum.NotActive); } _persistence.Create(defs[0], ProcessDefStatusEnum.Active, nextVersion); }
protected virtual void OnChangeProcessDefinitionStatus(IProcessDefinitionPersisnenceService service) { var processDefinition = BuildProcessdefinition(); Assert.IsNotNull(processDefinition); service.Create(processDefinition, ProcessDefStatusEnum.Active, 1); IReadOnlyList <ProcessDefinitionDigest> flows = service.LisAlltWorkflows(); Assert.IsNotNull(flows); Assert.AreEqual(1, flows.Count); flows = service.ActivetWorkflows(); Assert.IsNotNull(flows); Assert.AreEqual(1, flows.Count); Guid id = flows[0].Id; Assert.IsTrue(service.SetStatus(id, 1, ProcessDefStatusEnum.NotActive)); flows = service.ActivetWorkflows(); Assert.IsNotNull(flows); Assert.AreEqual(0, flows.Count); flows = service.LisAlltWorkflows(); Assert.IsNotNull(flows); Assert.AreEqual(1, flows.Count); }