Ejemplo n.º 1
0
        public string Format(IClaptrapDesignStore claptrapDesignStore)
        {
            var designs = claptrapDesignStore
                          .OrderBy(x => x.MasterOfSelfTypeCode())
                          .ThenBy(x => x.IsMinion())
                          .ToArray();
            var sb = new StringBuilder();

            sb.AppendLine("# claptrap");
            foreach (var design in designs)
            {
                sb.AppendLine(OneDesign(design));
            }

            sb.AppendLine("# events");

            var eventDefs = designs.SelectMany(design => design.EventHandlerDesigns
                                               .Select(eventHandlerDesign => new
            {
                design,
                eventHandlerDesign,
                masterClaptrapTypeCode = design.ClaptrapMasterDesign != null
                            ? design.ClaptrapMasterDesign.ClaptrapTypeCode
                            : design.ClaptrapTypeCode,
                eventTypeCode = eventHandlerDesign.Key
            }))
                            .GroupBy(x => x.masterClaptrapTypeCode + x.eventTypeCode)
                            .Select(x =>
            {
                var first = x.First();
                return(new EventDef
                {
                    EventTypeCode = first.eventHandlerDesign.Key,
                    MasterClaptrapTypeCode = first.masterClaptrapTypeCode,
                    EventHandlerDefs = x.Select(a => new EventHandlerDef
                    {
                        Handler = a.eventHandlerDesign.Value.EventHandlerType.Name,
                        ClaptrapTypeCode = a.design.ClaptrapTypeCode,
                    })
                                       .ToArray(),
                });
            });

            foreach (var eventDef in eventDefs)
            {
                sb.AppendLine(OneEvent(eventDef));
            }

            var re = sb.ToString();

            return(re);
        }