public static async Task <MetaMetadataRepository> ReadRepository(string filename, SimplTypesScope mmdTScope, SimplTypesScope metadataTScope, MetaMetadataRepository mainRepo)
        {
            MetaMetadataRepository repo = null;

            Debug.WriteLine("MetaMetadataRepository Reading:\t\t" + filename);

            try
            {
                repo = await mmdTScope.DeserializeFile(filename, Format.Xml) as MetaMetadataRepository;

                if (repo != null)
                {
                    repo.MetadataTScope = metadataTScope;
                    repo.File           = filename;
                    repo.InitializeSuffixAndMimeDicts();

                    if (repo.RepositoryByName == null)
                    {
                        return(repo);
                    }

                    foreach (var repoEntry in repo.RepositoryByName)
                    {
                        MetaMetadata mmd     = repoEntry.Value;
                        string       mmdName = repoEntry.Key;

                        //mmd.File = new FileInfo(filename);
                        mmd.File = await FundamentalPlatformSpecifics.Get().CreateFile(filename);

                        mmd.Parent     = mainRepo;
                        mmd.Repository = mainRepo;

                        string packageName = mmd.PackageName ?? repo.PackageName;
                        if (packageName == null)
                        {
                            throw new MetaMetadataException("No Package Name Specified For " + mmd);
                        }
                        mmd.PackageName = packageName;

                        MmdScope packageMmdScopes;
                        mainRepo.PackageMmdScopes.TryGetValue(mmd.PackageName, out packageMmdScopes);
                        if (packageMmdScopes == null)
                        {
                            packageMmdScopes = new MmdScope(repo.PackageName);
                            packageMmdScopes.PutAll(mainRepo.RepositoryByName);
                            mainRepo.PackageMmdScopes.Put(packageName, packageMmdScopes);
                        }

                        MetaMetadata existingMmd;
                        switch (mmd.Visibility)
                        {
                        case Visibility.GLOBAL:

                            mainRepo.RepositoryByName.TryGetValue(mmdName, out existingMmd);

                            if (existingMmd != null && existingMmd != mmd)
                            {
                                throw new MetaMetadataException("MMD already exists: " + mmdName + " in " + filename);
                            }

                            mainRepo.RepositoryByName.Put(mmdName, mmd);
                            break;

                        case Visibility.PACKAGE:
                            Object mmdObj = null;
                            packageMmdScopes.TryGetValue(mmdName, out mmdObj);
                            existingMmd = (MetaMetadata)mmdObj;

                            if (existingMmd != null && existingMmd != mmd)
                            {
                                throw new MetaMetadataException("MMD already exists: " + mmdName + " in " + filename);
                            }

                            packageMmdScopes.Put(mmdName, mmd);
                            break;
                        }
                    }

                    foreach (MetaMetadata metaMetadata in repo.RepositoryByName.Values)
                    {
                        if (metaMetadata.PackageName == null)
                        {
                            Debug.WriteLine("No Package name defined for: " + metaMetadata.Name);
                            continue;
                        }
                        MmdScope packageMmdScope;
                        mainRepo.PackageMmdScopes.TryGetValue(metaMetadata.PackageName, out packageMmdScope);
                        metaMetadata.Scope = packageMmdScope;
                    }

                    mainRepo.IntegrateRepository(repo);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Couldn't translate repository file: " + filename);
                Debug.WriteLine(e);
            }

            return(repo);
        }
Пример #2
0
        public void SemanticOperationTest()// throws SIMPLTranslationException
        {
            String collectedExampleUrlMetadata         = @"..\..\..\..\..\MetaMetadataRepository\MmdRepository\testData\collectedExampleUrlMetadata.xml";
            String collectedExampleUrlMetadataNoAuthor = @"..\..\Data\InformationCompositionDeclarationExample.xml";
            String useAuthor = @"..\..\Data\InformationCompositionDeclarationUseAuthor.xml";

            SimplTypesScope _repositoryMetadataTranslationScope = RepositoryMetadataTranslationScope.Get();

            SemanticsGlobalScope _semanticsSessionScope = new SemanticsSessionScope(
                _repositoryMetadataTranslationScope,
                MetaMetadataRepositoryInit.DEFAULT_REPOSITORY_LOCATION);

            InformationCompositionDeclaration doc = (InformationCompositionDeclaration)_repositoryMetadataTranslationScope.DeserializeFile(collectedExampleUrlMetadata, Format.Xml);

            foreach (Metadata metadata in doc.Metadata)
            {
                MetaMetadata metaMetadata = (MetaMetadata)metadata.MetaMetadata;

                SemanticOperationHandler handler = new SemanticOperationHandler(_semanticsSessionScope, null);
                handler.TakeSemanticOperations(metaMetadata, metadata, metaMetadata.SemanticActions);
            }

            Console.WriteLine(SimplTypesScope.Serialize(doc, StringFormat.Xml));
        }