public void ApplyChanges(WorkflowModel model, WorkflowReplacementModel replacements) { var document = XDocument.Parse(model.DiagramXml); var participants = document.Descendants(bpmn + "collaboration").Elements(bpmn + "participant").ToDictionaryEx(a => a.Attribute("id").Value); var processElements = document.Descendants(bpmn + "process").ToDictionaryEx(a => a.Attribute("id").Value); var diagramElements = document.Descendants(bpmndi + "BPMNPlane").Elements().ToDictionaryEx(a => a.Attribute("bpmnElement").Value, "bpmnElement"); if (participants.Count != processElements.Count) { throw new InvalidOperationException(WorkflowValidationMessage.ParticipantsAndProcessesAreNotSynchronized.NiceToString()); } Locator locator = new Workflow.Locator(this, diagramElements, model, replacements); var oldPools = this.pools.Values.ToDictionaryEx(a => a.pool.bpmnElementId, "pools"); Synchronizer.Synchronize(participants, oldPools, (id, pa) => { var wp = new WorkflowPoolEntity { Xml = new WorkflowXmlEmbedded(), Workflow = this.workflow }.ApplyXml(pa, locator); var pb = new PoolBuilder(wp, Enumerable.Empty <LaneBuilder>(), Enumerable.Empty <XmlEntity <WorkflowConnectionEntity> >()); this.pools.Add(wp.ToLite(), pb); pb.ApplyChanges(processElements.GetOrThrow(pa.Attribute("processRef").Value), locator); }, (id, pb) => { this.pools.Remove(pb.pool.Entity.ToLite()); pb.DeleteAll(locator); }, (id, pa, pb) => { var wp = pb.pool.Entity.ApplyXml(pa, locator); pb.ApplyChanges(processElements.GetOrThrow(pa.Attribute("processRef").Value), locator); }); var messageFlows = document.Descendants(bpmn + "collaboration").Elements(bpmn + "messageFlow").ToDictionaryEx(a => a.Attribute("id").Value); var oldMessageFlows = this.messageFlows.ToDictionaryEx(a => a.bpmnElementId, "messageFlows"); Synchronizer.Synchronize(messageFlows, oldMessageFlows, (id, mf) => { var wc = new WorkflowConnectionEntity { Xml = new WorkflowXmlEmbedded() }.ApplyXml(mf, locator); this.messageFlows.Add(new XmlEntity <WorkflowConnectionEntity>(wc)); }, (id, omf) => { this.messageFlows.Remove(omf); omf.Entity.Delete(WorkflowConnectionOperation.Delete); }, (id, mf, omf) => { omf.Entity.ApplyXml(mf, locator); }); }
public void ApplyChanges(XElement processElement, Locator locator) { var sequenceFlows = processElement.Elements(bpmn + "sequenceFlow").ToDictionary(a => a.Attribute("id").Value); var oldSequenceFlows = this.sequenceFlows.ToDictionaryEx(a => a.bpmnElementId, "sequenceFlows"); Synchronizer.Synchronize(sequenceFlows, oldSequenceFlows, null, (id, osf) => { this.sequenceFlows.Remove(osf); osf.Entity.Delete(WorkflowConnectionOperation.Delete); }, (id, sf, osf) => { var newFrom = locator.FindEntity(sf.Attribute("sourceRef").Value); var newTo = locator.FindEntity(sf.Attribute("targetRef").Value); if (!newFrom.Is(osf.Entity.From) || !newTo.Is(osf.Entity.To)) { osf.Entity.InDB().UnsafeUpdate() .Set(a => a.From, a => newFrom) .Set(a => a.To, a => newTo) .Execute(); osf.Entity.From = newFrom !; osf.Entity.To = newTo !; osf.Entity.SetCleanModified(false); } }); var oldLanes = this.lanes.Values.ToDictionaryEx(a => a.lane.bpmnElementId, "lanes"); var lanes = processElement.Element(bpmn + "laneSet").Elements(bpmn + "lane").ToDictionaryEx(a => a.Attribute("id").Value); Synchronizer.Synchronize(lanes, oldLanes, createNew: (id, l) => { var wl = new WorkflowLaneEntity { Xml = new WorkflowXmlEmbedded(), Pool = this.pool.Entity }.ApplyXml(l, locator); var lb = new LaneBuilder(wl, Enumerable.Empty <WorkflowActivityEntity>(), Enumerable.Empty <WorkflowEventEntity>(), Enumerable.Empty <WorkflowGatewayEntity>(), Enumerable.Empty <XmlEntity <WorkflowConnectionEntity> >()); lb.ApplyChanges(processElement, l, locator); this.lanes.Add(wl.ToLite(), lb); }, removeOld: null, merge: (id, l, ol) => { var wl = ol.lane.Entity.ApplyXml(l, locator); ol.ApplyChanges(processElement, l, locator); }); Synchronizer.Synchronize(lanes, oldLanes, createNew: null, removeOld: (id, ol) => { ol.ApplyChanges(processElement, ol.lane.Element, locator); this.lanes.Remove(ol.lane.Entity.ToLite()); ol.lane.Entity.Delete(WorkflowLaneOperation.Delete); }, merge: null); Synchronizer.Synchronize(sequenceFlows, oldSequenceFlows, (id, sf) => { var wc = new WorkflowConnectionEntity { Xml = new WorkflowXmlEmbedded() }.ApplyXml(sf, locator); this.sequenceFlows.Add(new XmlEntity <WorkflowConnectionEntity>(wc)); }, null, (id, sf, osf) => { osf.Entity.ApplyXml(sf, locator); }); }
public void ApplyChanges(XElement processElement, Locator locator) { var sequenceFlows = processElement.Elements(bpmn + "sequenceFlow").ToDictionary(a => a.Attribute("id").Value); var oldSequenceFlows = this.sequenceFlows.ToDictionaryEx(a => a.bpmnElementId, "sequenceFlows"); Synchronizer.Synchronize(sequenceFlows, oldSequenceFlows, null, (id, osf) => { this.sequenceFlows.Remove(osf); osf.Entity.Delete(WorkflowConnectionOperation.Delete); }, (id, sf, osf) => { osf.Entity.ApplyXml(sf, locator); }); var oldLanes = this.lanes.Values.ToDictionaryEx(a => a.lane.bpmnElementId, "lanes"); var lanes = processElement.Element(bpmn + "laneSet").Elements(bpmn + "lane").ToDictionaryEx(a => a.Attribute("id").Value); Synchronizer.Synchronize(lanes, oldLanes, (id, l) => { var wl = new WorkflowLaneEntity { Xml = new WorkflowXmlEmbedded(), Pool = this.pool.Entity }.ApplyXml(l, locator); var lb = new LaneBuilder(wl, Enumerable.Empty <WorkflowActivityEntity>(), Enumerable.Empty <WorkflowEventEntity>(), Enumerable.Empty <WorkflowGatewayEntity>(), Enumerable.Empty <XmlEntity <WorkflowConnectionEntity> >()); lb.ApplyChanges(processElement, l, locator); if (lb.IsEmpty()) { wl.Delete(WorkflowLaneOperation.Delete); } else { this.lanes.Add(wl.ToLite(), lb); } }, (id, ol) => { this.lanes.Remove(ol.lane.Entity.ToLite()); ol.DeleteAll(locator); }, (id, l, ol) => { var wl = ol.lane.Entity.ApplyXml(l, locator); ol.ApplyChanges(processElement, l, locator); if (ol.IsEmpty()) { this.lanes.Remove(wl.ToLite()); wl.Delete(WorkflowLaneOperation.Delete); } }); Synchronizer.Synchronize(sequenceFlows, oldSequenceFlows, (id, sf) => { var wc = new WorkflowConnectionEntity { Xml = new WorkflowXmlEmbedded() }.ApplyXml(sf, locator); this.sequenceFlows.Add(new XmlEntity <WorkflowConnectionEntity>(wc)); }, null, (id, sf, osf) => { osf.Entity.ApplyXml(sf, locator); }); }