Esempio n. 1
0
    public void ApplyChanges(WorkflowModel model, WorkflowReplacementModel?replacements)
    {
        var document = WorkflowBuilder.ParseDocument(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 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,
                                 null,
                                 (id, omf) =>
        {
            this.messageFlows.Remove(omf);
            omf.Entity.Delete(WorkflowConnectionOperation.Delete);
        },
                                 (id, mf, omf) =>
        {
            omf.Entity.ApplyXml(mf, locator);
        });

        var oldPools = this.pools.Values.ToDictionaryEx(a => a.pool.bpmnElementId, "pools");

        Synchronizer.Synchronize(participants, oldPools,
                                 createNew: (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);
        },