protected virtual void InheritNonFieldElements(MetaMetadata inheritedMmd, InheritanceHandler inheritanceHandler)
 {
     Scope = new MmdScope(Scope, inheritedMmd.Scope);
 }
        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;
        }