public ModelMap Parse(string filePath)
        {
            _logger.LogInfo("Parsing model map config at: " + filePath);

            using (var reader = new StreamReader(filePath))
            {
                var doc    = XDocument.Load(reader);
                var report = new ModelMapCompilationReport();

                ModelMap config;
                try
                {
                    config = Parse(doc, report);
                }
                catch (Exception exc)
                {
                    report.AddError(exc.Message);
                    report.ReportTo(_logger);

                    throw;
                }

                return(config);
            }
        }
예제 #2
0
 public ParsingContext(IServiceLocator services, ModelMapCompilationReport report)
 {
     _services = services;
     _report   = report;
     _elements = new Stack <XElement>();
     _objects  = new Stack <object>();
 }
        private void parse(ModelMap map, XDocument document, ModelMapCompilationReport report)
        {
            var root    = document.Root;
            var context = new ParsingContext(_services, report);

            map.AddInstruction(new BeginModelMap(map.Name));
            context.PushObject(map);

            root
            .Elements()
            .Each(_ => _elementService.Visit(_, map, context));

            context.PopObject();
            map.AddInstruction(new EndModelMap());
        }
        public ModelMap Parse(XDocument document, ModelMapCompilationReport report)
        {
            var root = document.Root;
            var name = root.Attribute("name");

            if (name == null)
            {
                throw new InvalidOperationException("No name specified");
            }

            var entity          = "";
            var entityAttribute = root.Attribute("entity");

            if (entityAttribute != null)
            {
                entity = entityAttribute.Value;
            }

            var map = new ModelMap(name.Value, entity);

            parse(map, document, report);

            return(map);
        }