Ejemplo n.º 1
0
        private static void LoadMaps()
        {
            foreach (var fileName in Directory.GetFiles(UtilitySettings.Default.MapLocation, "*.xml"))
            {
                using (var mapFile = File.Open(fileName, FileMode.Open))
                {
                    var mapDocument = XDocument.Load(mapFile);
                    switch (MapReader.ReadHandlerType(mapDocument))
                    {
                    case HandlerType.ModuleRegistration: ModuleRegistrarFactory.LoadMap(MapReader.ReadMap(mapDocument)); break;

                    case HandlerType.TypeResolution: TypeResolverFactory.LoadMap(MapReader.ReadMap(mapDocument)); break;

                    case HandlerType.LibraryReader: LibraryReaderFactory.LoadMap(MapReader.ReadMap(mapDocument)); break;

                    case HandlerType.Verification: NodeVerifierFactory.LoadMap(MapReader.ReadMap(mapDocument)); break;

                    case HandlerType.Translation: ArtifactTranslatorFactory.LoadMap(MapReader.ReadMap(mapDocument)); break;

                    case HandlerType.NodeTranslation: NodeTranslatorFactory.LoadMap(MapReader.ReadMap(mapDocument)); break;

                    case HandlerType.ModelTranslation: ModelTranslatorFactory.LoadMap(MapReader.ReadMap(mapDocument)); break;

                    case HandlerType.Writing: ArtifactWriterFactory.LoadMap(MapReader.ReadMap(mapDocument)); break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static Library ResolveLibrary(LibraryRef libraryRef, VerificationContext context)
        {
            Library library;

            if (!_libraries.TryGetValue(libraryRef.Name, out library))
            {
                if (context == null)
                {
                    throw new InvalidOperationException("Cannot perform type verification on a library without a verification context.");
                }

                if (resolvingLibraries.Contains(libraryRef.Name))
                {
                    throw new InvalidOperationException(String.Format("Circular library reference to library {0}.", libraryRef.Name));
                }

                resolvingLibraries.Push(libraryRef.Name);
                try
                {
                    library = LibraryReaderFactory.GetHandler(libraryRef.MediaType).Read(libraryRef);
                    var verifier = new LibraryVerifier();
                    IEnumerable <VerificationException> results = verifier.Verify(library);
                    context.Messages.AddRange(results);
                    _libraries.Add(libraryRef.Name, library);

                    if (results.Any(r => !r.IsWarning))
                    {
                        throw new InvalidOperationException(String.Format("Errors encountered while verifying library {0}.", libraryRef.Name));
                    }
                }
                finally
                {
                    resolvingLibraries.Pop();
                }
            }

            return(library);
        }