Ejemplo n.º 1
0
        public IDisposable Sync <T>(Dictionary <string, T> entityDic, IEnumerable <XElement> elements, IFromXmlContext ctx, Action <T, XElement> setXml)
            where T : Entity, new()
        {
            var xmlDic = elements.ToDictionaryEx(a => a.Attribute("BpmnElementId").Value);

            Synchronizer.Synchronize(
                xmlDic,
                entityDic,
                createNew: (bpmnId, xml) =>
            {
                var entity = new T();
                setXml(entity, xml);
                entityDic.Add(bpmnId, ctx.SaveMaybe(entity));
            },
                removeOld: null,
                merge: null);


            return(new Disposable(() =>
            {
                Synchronizer.Synchronize(
                    xmlDic,
                    entityDic,
                    createNew: null,
                    removeOld: (bpmnId, entity) => ctx.DeleteMaybe(entity),
                    merge: (bpmnId, xml, entity) =>
                {
                    setXml(entity, xml);
                    ctx.SaveMaybe(entity);
                });
            }));
        }
Ejemplo n.º 2
0
        public void FromXml(XElement element, IFromXmlContext ctx)
        {
            this.workflow.Name           = element.Attribute("Name").Value;
            this.workflow.MainEntityType = ctx.GetType(element.Attribute("MainEntityType").Value).RetrieveAndForget();
            this.workflow.MainEntityStrategies.AssignMList(element.Attribute("MainEntityStrategies").Value.Split(",").Select(a => a.Trim().ToEnum <WorkflowMainEntityStrategy>()).ToMList());
            this.workflow.ExpirationDate = element.Attribute("ExpirationDate")?.Let(ed => DateTime.ParseExact(ed.Value, "o", CultureInfo.InvariantCulture));

            ctx.SaveMaybe(this.workflow);

            using (Sync(this.pools, element.Elements("Pool"), ctx, (pool, xml) =>
            {
                pool.BpmnElementId = xml.Attribute("bpmnElementId").Value;
                pool.Name = xml.Attribute("Name").Value;
                pool.Workflow = this.workflow;
                SetXmlDiagram(pool, xml);
            }))
            {
                using (Sync(this.lanes, element.Elements("Lane"), ctx, (lane, xml) =>
                {
                    lane.BpmnElementId = xml.Attribute("bpmnElementId").Value;
                    lane.Name = xml.Attribute("Name").Value;
                    lane.Pool = this.pools.GetOrThrow(xml.Attribute("Pool").Value);
                    lane.Actors = (xml.Element("Actors")?.Elements("Actor")).EmptyIfNull().Select(a => Lite.Parse(a.Value)).ToMList();
                    lane.ActorsEval = xml.Element("ActorsEval")?.Let(ae => (lane.ActorsEval ?? new WorkflowLaneActorsEval()).Do(wal => wal.Script = ae.Value));
                    SetXmlDiagram(lane, xml);
                }))
                {
                    //TODO: Complete code
                }
            }
        }