Beispiel #1
0
        public void ApplyChanges(XElement processElement, XElement laneElement, Locator locator)
        {
            var laneIds      = laneElement.Elements(bpmn + "flowNodeRef").Select(a => a.Value).ToHashSet();
            var laneElements = processElement.Elements().Where(a => laneIds.Contains(a.Attribute("id")?.Value !));

            var events    = laneElements.Where(a => WorkflowEventTypes.Where(kvp => !kvp.Key.IsBoundaryTimer()).ToDictionary().Values.Contains(a.Name.LocalName)).ToDictionary(a => a.Attribute("id") !.Value);
            var oldEvents = this.events.Values.Where(a => a.Entity.BoundaryOf == null).ToDictionaryEx(a => a.bpmnElementId, "events");

            Synchronizer.Synchronize(events, oldEvents,
                                     (id, e) =>
            {
                var already = (WorkflowEventEntity?)locator.FindEntity(id);
                if (already != null)
                {
                    locator.FindLane(already.Lane).events.Remove(id);
                    already.Lane = this.lane.Entity;
                }

                var we = (already ?? new WorkflowEventEntity {
                    Xml = new WorkflowXmlEmbedded(), Lane = this.lane.Entity
                }).ApplyXml(e, locator);
                this.events.Add(id, new XmlEntity <WorkflowEventEntity>(we));
            },
                                     (id, oe) =>
            {
                if (!locator.ExistDiagram(id))
                {
                    this.events.Remove(id);
                    if (oe.Entity.Type == WorkflowEventType.IntermediateTimer)
                    {
                        MoveCasesAndDelete(oe.Entity, locator);
                    }
                    else
                    {
                        oe.Entity.Delete(WorkflowEventOperation.Delete);
                    }
                }
                ;
            },
                                     (id, e, oe) =>
            {
                var we = oe.Entity.ApplyXml(e, locator);
            });

            var activities    = laneElements.Where(a => WorkflowActivityTypes.Values.Contains(a.Name.LocalName)).ToDictionary(a => a.Attribute("id") !.Value);
            var oldActivities = this.activities.Values.ToDictionaryEx(a => a.bpmnElementId, "activities");

            Synchronizer.Synchronize(activities, oldActivities,
                                     (id, a) =>
            {
                var already = (WorkflowActivityEntity?)locator.FindEntity(id);
                if (already != null)
                {
                    locator.FindLane(already.Lane).activities.Remove(id);
                    already.Lane = this.lane.Entity;
                }

                var wa = (already ?? new WorkflowActivityEntity {
                    Xml = new WorkflowXmlEmbedded(), Lane = this.lane.Entity
                }).ApplyXml(a, locator, this.events);
                this.activities.Add(id, new XmlEntity <WorkflowActivityEntity>(wa));
            },
                                     (id, oa) =>
            {
                if (!locator.ExistDiagram(id))
                {
                    this.activities.Remove(id);
                    MoveCasesAndDelete(oa.Entity, locator);
                }
                ;
            },
                                     (id, a, oa) =>
            {
                var we = oa.Entity.ApplyXml(a, locator, this.events);
            });

            var gateways = laneElements
                           .Where(a => WorkflowGatewayTypes.Values.Contains(a.Name.LocalName))
                           .ToDictionary(a => a.Attribute("id") !.Value);
            var oldGateways = this.gateways.Values.ToDictionaryEx(a => a.bpmnElementId, "gateways");

            Synchronizer.Synchronize(gateways, oldGateways,
                                     (id, g) =>
            {
                var already = (WorkflowGatewayEntity?)locator.FindEntity(id);
                if (already != null)
                {
                    locator.FindLane(already.Lane).gateways.Remove(id);
                    already.Lane = this.lane.Entity;
                }

                var wg = (already ?? new WorkflowGatewayEntity {
                    Xml = new WorkflowXmlEmbedded(), Lane = this.lane.Entity
                }).ApplyXml(g, locator);
                this.gateways.Add(id, new XmlEntity <WorkflowGatewayEntity>(wg));
            },
                                     (id, og) =>
            {
                if (!locator.ExistDiagram(id))
                {
                    this.gateways.Remove(id);
                    og.Entity.Delete(WorkflowGatewayOperation.Delete);
                }
                ;
            },
                                     (id, g, og) =>
            {
                var we = og.Entity.ApplyXml(g, locator);
            });
        }