private bool InheritFromSuperField(MetaMetadataRepository repository, InheritanceHandler inheritanceHandler)
        {
            bool inhertedIsInheriting = false;
            MetaMetadataCompositeField inheritedField = (MetaMetadataCompositeField)SuperField;

            if (inheritedField != null)
            {
                inheritedField.Repository = repository;
                if (inheritedField.InheritInProcess)
                {
                    inhertedIsInheriting = true;

                    // if inheriting from the root mmd, we need to clone and keep the environment right now.
                    InheritanceHandler inheritanceHandlerToUse = inheritanceHandler.clone();
                    inheritanceHandler.Pop(this);

                    //inheritedField.InheritFinished += (sender, e) => InheritFrom(repository, inheritedField);
                    this.AddInheritanceFinishHandler(inheritedField, InheritFieldFinished, inheritanceHandlerToUse);
                }
                else
                {
                    inheritedField.InheritMetaMetadata(inheritanceHandler);
                    InheritFromCompositeField(inheritedField, repository, inheritanceHandler);
                }
            }
            return(inhertedIsInheriting);
        }
예제 #2
0
        protected override MetaMetadata FindOrGenerateInheritedMetaMetadata(MetaMetadataRepository repository, InheritanceHandler inheritanceHandler)
        {
            if (MetaMetadata.IsRootMetaMetadata(this))
            {
                return(null);
            }

            MetaMetadata inheritedMmd = this.TypeMmd;

            if (inheritedMmd == null)
            {
                String inheritedMmdName = this.Type;
                if (inheritedMmdName == null)
                {
                    inheritedMmdName = this.ExtendsAttribute;
                    SetNewMetadataClass(true);
                }
                if (inheritedMmdName == null)
                {
                    throw new MetaMetadataException("no type/extends specified: " + this);
                }
                inheritedMmd = (MetaMetadata)this.Scope[inheritedMmdName];
                if (inheritedMmd == null)
                {
                    throw new MetaMetadataException("meta-metadata '" + inheritedMmdName + "' not found.");
                }
                TypeMmd = inheritedMmd;
            }
            return(inheritedMmd);
        }
        public static async Task <MetaMetadataRepository> ReadDirectoryRecursively(MetaMetadataRepository mainRepo, String path, SimplTypesScope mmdTScope, SimplTypesScope metadataTScope)
        {
            Stack <string> stack = new Stack <string>();

            stack.Push(path);
            while (stack.Count > 0)
            {
                string dir = stack.Pop();
                Debug.WriteLine("Looking in : " + dir);
                //String[] files = Directory.GetFiles(dir, "*.xml");
                string[] files = await FundamentalPlatformSpecifics.Get().GetFilesFromDirectory(dir, ".xml");

                foreach (string file in files)
                {
                    MetaMetadataRepository thatRepo = await ReadRepository(file, mmdTScope, metadataTScope, mainRepo);

                    // if (thatRepo != null)
                    //    mainRepo.IntegrateRepository(thatRepo);

                    //string[] directories = Directory.GetDirectories(dir);
                    //                                           string[] directories = await FundamentalPlatformSpecifics.Get().GetDirectoriesFromDirectory(dir);
                    //                                           foreach (
                    //                                                    string innerDir in directories.Where(
                    //                                                                                          innerDir =>
                    //                                                                                            !innerDir.Contains(".svn")))
                    //                                                                                    stack.Push(innerDir);
                    //                                                                            });
                }
            }

            return(mainRepo);
        }
예제 #4
0
        private void InitializeRepositoryAndPerformBinding()
        {
            META_METADATA_REPOSITORY = _metaMetadataRepository;

            SetDefaultMetaMetadatas();

            BindAndCallback(META_METADATA_REPOSITORY);
        }
예제 #5
0
        /// <summary>
        /// Integrate the contents of otherRepository with this one.
        /// </summary>
        /// <param name="repository"></param>
        public void IntegrateRepository(MetaMetadataRepository repository)
        {
            // combine userAgents
            if (!MergeDictionaries(repository.userAgents, this.userAgents))
            {
                this.userAgents = repository.userAgents;
            }

            // combine searchEngines
            if (!MergeDictionaries(repository.searchEngines, this.searchEngines))
            {
                this.searchEngines = repository.searchEngines;
            }

            // combine namedStyles
            if (!MergeDictionaries(repository.namedStyles, this.namedStyles))
            {
                this.namedStyles = repository.namedStyles;
            }

            // combine sites
            if (!MergeDictionaries(repository.sites, this.sites))
            {
                this.sites = repository.sites;
            }

            if (!MergeDictionaries(repository._repositoryByMime, this._repositoryByMime))
            {
                this._repositoryByMime = repository._repositoryByMime;
            }

            if (!MergeDictionaries(repository._repositoryBySuffix, this._repositoryBySuffix))
            {
                this._repositoryBySuffix = repository._repositoryBySuffix;
            }

            Dictionary <String, MetaMetadata> otherRepositoryByTagName = repository._repositoryByName;

            //set metaMetadata to have the correct parent repository in ElementState
            if (otherRepositoryByTagName != null)
            {
                foreach (MetaMetadata mmd in otherRepositoryByTagName.Values)
                {
                    mmd.Parent = this;
                    if (mmd.PackageName == null)
                    {
                        mmd.PackageName = repository.packageName;
                    }
                }

                if (!MergeDictionaries(otherRepositoryByTagName, this._repositoryByName))
                {
                    this._repositoryByName = otherRepositoryByTagName;
                }
            }
            //MetadataTScope = repository.MetadataTScope;
        }
예제 #6
0
        public async Task <MetaMetadataRepository> LoadRepositoryFromCache(object file)
        {
            _metaMetadataRepository =
                await MetaMetadataTranslationScope.Get().Deserialize(file, Format.Xml) as MetaMetadataRepository;

            InitializeRepositoryAndPerformBinding();

            return(_metaMetadataRepository);
        }
예제 #7
0
        private void BindAndCallback(MetaMetadataRepository repository)
        {
            if (repository != null)
            {
                repository.BindMetadataClassDescriptorsToMetaMetadata(_metadataTranslationScope);
            }

            if (RepositoryLoaded != null)
            {
                RepositoryLoaded(repository, new EventArgs());
            }
        }
예제 #8
0
        public async Task <MetaMetadataRepository> LoadRepositoryFromServiceAsync(ParsedUri serviceUri, object cacheFile = null)
        {
            _metaMetadataRepository = (serviceUri != null) ? await RequestMetaMetadataRepository(new ParsedUri(serviceUri, "mmdrepository.xml")) : new MetaMetadataRepository();

            if (cacheFile != null)
            {
                SimplTypesScope.Serialize(_metaMetadataRepository, cacheFile, Format.Xml);
            }

            InitializeRepositoryAndPerformBinding();

            return(_metaMetadataRepository);
        }
예제 #9
0
        public static async Task <MetaMetadataRepository> RequestMetaMetadataRepository(ParsedUri requestUri)
        {
            MetaMetadataRepository repository = null;

            try
            {
                repository = await MetaMetadataTranslationScope.Get().DeserializeUri(requestUri, Format.Xml, new TranslationContext(requestUri)) as MetaMetadataRepository;
            }
            catch (Exception)
            {
                Debug.WriteLine("Error loading Meta-metadata Repo. Service is down?!");
            }


            return(repository);
        }
        public static String GetMdClassNameFromMmdOrNoChange(String mmdName,
                                                             MetaMetadataRepository repository, MmdCompilerService compilerService)
        {
            MetaMetadata mmd = repository.GetMMByName(mmdName);

            if (mmd == null)
            {
                return(mmdName);
            }
            else
            {
                MetadataClassDescriptor metadataClassDescriptor = mmd.MetadataClassDescriptor;
                if (compilerService != null)
                {
                    compilerService.AddCurrentClassDependency(metadataClassDescriptor);
                }
                return(metadataClassDescriptor.DescribedClassSimpleName);
            }
        }
        protected override bool InheritMetaMetadataHelper(InheritanceHandler inheritanceHandler)
        {
            inheritanceHandler.Push(this);

            bool inhertedIsInheriting = false;
            // init
            MetaMetadataRepository repository = Repository;

            // determine the structure we should inherit from
            MetaMetadata inheritedMmd = FindOrGenerateInheritedMetaMetadata(repository, inheritanceHandler);

            if (inheritedMmd != null)
            {
                if (inheritedMmd.InheritInProcess)
                {
                    inhertedIsInheriting = true;

                    // if inheriting from the root mmd, we need to clone and keep the environment right now.
                    InheritanceHandler inheritanceHandlerToUse = inheritanceHandler.clone();
                    inheritanceHandler.Pop(this);

                    //inheritedMmd.InheritFinished += (sender, e) => InheritFromTopLevelMetaMetadata(inheritedMmd, repository);
                    this.AddInheritanceFinishHandler(inheritedMmd, InheritMetaMetadataFinished, inheritanceHandlerToUse);
                }
                else
                {
                    inheritedMmd.InheritMetaMetadata(null); //edit
                    InheritFromTopLevelMetaMetadata(inheritedMmd, repository, inheritanceHandler);
                }
            }
            if (!inhertedIsInheriting)
            {
                inhertedIsInheriting = InheritFromSuperField(repository, inheritanceHandler);
            }

            // for the root meta-metadata, this may happend
            if (inheritedMmd == null && SuperField == null)
            {
                InheritFrom(repository, null, inheritanceHandler);
            }

            return(!inhertedIsInheriting);
        }
예제 #12
0
        protected override void InheritFrom(MetaMetadataRepository repository, MetaMetadataCompositeField inheritedStructure, InheritanceHandler inheritanceHandler)
        {
            base.InheritFrom(repository, inheritedStructure, inheritanceHandler);

            // for fields referring to this meta-metadata type
            // need to do inheritMetaMetadata() again after copying fields from this.getInheritedMmd()

/*		    foreach (MetaMetadataField f in this.Kids.Values)
 *                  {
 *                          if (f.GetType() ==  typeof(MetaMetadataNestedField))
 *                          {
 *                                  MetaMetadataNestedField nested = (MetaMetadataNestedField) f;
 *                                  if (nested.InheritedMmd == this)
 *                                  {
 *                                          nested.ClearInheritFinishedOrInProgressFlag();
 *                      nested.InheritMetaMetadata();
 *                                  }
 *                          }
 *                  }
 */
        }
예제 #13
0
        public async void LoadRepositoryAsync()
        {
            META_METADATA_REPOSITORY = new MetaMetadataRepository
            {
                RepositoryByName = new Dictionary <string, MetaMetadata>(),
                PackageMmdScopes = new Dictionary <string, MmdScope>()
            };

            _metaMetadataRepository = META_METADATA_REPOSITORY;

            SetDefaultMetaMetadatas();

            MetaMetadataRepository mainRepo = await MetaMetadataRepositoryLoader.ReadDirectoryRecursively(
                META_METADATA_REPOSITORY,
                MetametadataRepositoryDirFile as string,
                MetaMetadataTranslationScope.Get(),
                _metadataTranslationScope
                );



            BindAndCallback(mainRepo);
        }
        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);
        }
 private void InheritFromCompositeField(MetaMetadataCompositeField inheritedField, MetaMetadataRepository repository, InheritanceHandler inheritanceHandler)
 {
     InheritFrom(repository, inheritedField, inheritanceHandler);
 }
 private void InheritFromTopLevelMetaMetadata(MetaMetadata inheritedMmd, MetaMetadataRepository repository, InheritanceHandler inheritanceHandler)
 {
     InheritNonFieldElements(inheritedMmd, inheritanceHandler);
     InheritFrom(repository, inheritedMmd, inheritanceHandler);
 }
        protected virtual void InheritFrom(MetaMetadataRepository repository,
                                           MetaMetadataCompositeField inheritedStructure,
                                           InheritanceHandler inheritanceHandler)
        {
            // init nested fields inside this
            var subfields = Kids.Values;

            foreach (MetaMetadataField f in subfields)
            {
                if (f is MetaMetadataNestedField)
                {
                    f.Repository = (repository);
                    MetaMetadataNestedField nested = (MetaMetadataNestedField)f;
                    if (nested.PackageName == null)
                    {
                        nested.PackageName = PackageName;
                    }
                    nested.Scope = Scope;
                }
            }

            // inherit fields with attributes from inheritedStructure
            // if inheritedStructure == null, this must be the root meta-metadata
            if (inheritedStructure != null)
            {
                var inheritedStructSubfields = inheritedStructure.Kids.Values;
                foreach (MetaMetadataField field in inheritedStructSubfields)
                {
                    if (field is MetaMetadataNestedField)
                    {
                        ((MetaMetadataNestedField)field).InheritMetaMetadata(inheritanceHandler);
                    }
                    string            fieldName = field.Name;
                    MetaMetadataField fieldLocal;
                    kids.TryGetValue(fieldName, out fieldLocal);

                    if (fieldLocal == null && inheritanceHandler.IsUsingGenerics(field))
                    {
                        // if the super field is using generics, we will need to re-evaluate generic type vars
                        fieldLocal = (MetaMetadataField)Activator.CreateInstance(field.GetType());

                        //Prepare Child Field For Inheritance
                        fieldLocal.Repository = (repository);
                        if (fieldLocal is MetaMetadataNestedField)
                        {
                            MetaMetadataNestedField nested = (MetaMetadataNestedField)fieldLocal;
                            if (nested.PackageName == null)
                            {
                                nested.PackageName = PackageName;
                            }
                            nested.Scope = Scope;
                        }
                    }
                    if (fieldLocal != null)
                    {
                        Debug.WriteLine("inheriting field: " + fieldLocal + " <= " + field);
                        if (field.GetType() != fieldLocal.GetType())
                        {
                            Debug.WriteLine("local field " + fieldLocal + " hides field " + fieldLocal +
                                            " with the same name in super mmd type!");
                        }
                        // debug("inheriting field " + fieldLocal + " from " + field);
                        if (field != fieldLocal)
                        {
                            fieldLocal.SuperField = field;
                        }
                        fieldLocal.DeclaringMmd = field.DeclaringMmd;
                        fieldLocal.InheritAttributes(field);
                        if (fieldLocal is MetaMetadataNestedField)
                        {
                            ((MetaMetadataNestedField)fieldLocal).PackageName =
                                ((MetaMetadataNestedField)field).PackageName;
                        }
                    }
                }
            }

            // recursively call inheritMetaMetadata() on nested fields
            foreach (MetaMetadataField f in subfields)
            {
                // a new field is defined inside this mmd
                if (f.DeclaringMmd == this && f.SuperField == null)
                {
                    SetNewMetadataClass(true);
                }

                // recursively call this method on nested fields
                f.Repository = repository;
                if (f is MetaMetadataNestedField)
                {
                    MetaMetadataNestedField f1 = (MetaMetadataNestedField)f;
                    f1.InheritMetaMetadata(inheritanceHandler);
                    if (f1.IsNewMetadataClass())
                    {
                        SetNewMetadataClass(true);
                    }

                    MetaMetadataNestedField f0 = (MetaMetadataNestedField)f.SuperField;
                    if (f0 != null && f0.GetTypeName() != f1.GetTypeName())
                    {
                        // inherited field w changing base type (polymorphic case)
                        f1.InheritMetaMetadata(inheritanceHandler);
                        MetaMetadata mmd0 = f0.TypeMmd;
                        MetaMetadata mmd1 = f1.TypeMmd;
                        if (mmd1.IsDerivedFrom(mmd0))
                        {
                            SetNewMetadataClass(true);
                        }
                        else
                        {
                            throw new MetaMetadataException("incompatible types: " + mmd0 + " => " + mmd1);
                        }
                    }
                }
            }

            // clone fields only declared in inheritedStructure.
            // must clone them after recursively calling inheritMetaMetadata(), so that their nested
            // structures (which may be inherited too) can be cloned.
            if (inheritedStructure != null)
            {
                var inheritedStructSubfields = inheritedStructure.Kids.Values;
                foreach (MetaMetadataField field in inheritedStructSubfields)
                {
                    string            fieldName = field.Name;
                    MetaMetadataField fieldLocal;
                    kids.TryGetValue(fieldName, out fieldLocal);

                    if (fieldLocal == null)
                    {
                        //					MetaMetadataField clonedField = (MetaMetadataField) field.clone();
                        //					clonedField.setParent(this);
                        //					this.getChildMetaMetadata().put(fieldName, clonedField);
                        kids.Put(fieldName, field);
                    }
                }
            }
        }
        protected virtual MetaMetadata FindOrGenerateInheritedMetaMetadata(MetaMetadataRepository repository, InheritanceHandler inheritanceHandler)
        {
            MetaMetadata inheritedMmd = this.TypeMmd;

            if (inheritedMmd == null)
            {
                MmdScope mmdScope         = this.Scope;
                String   inheritedMmdName = Type ?? Name;

                if (ExtendsAttribute != null)
                {
                    // determine new type name
                    if (inheritedMmdName == null)
                    {
                        throw new MetaMetadataException("attribute 'name' must be specified: " + this);
                    }
                    if (inheritanceHandler.ResolveMmdName(inheritedMmdName) != null)
                    {
                        // currently we don't encourage re-using existing name. however, in the future, when package names are available, we can change this.
                        throw new MetaMetadataException("meta-metadata '" + inheritedMmdName + "' already exists! please use another name to prevent name collision. hint: use 'tag' to change the tag if needed.");
                    }

                    // determine from which meta-metadata to inherit
                    inheritedMmd = inheritanceHandler.ResolveMmdName(ExtendsAttribute);
                    if (ExtendsAttribute == null || inheritedMmd == null)
                    {
                        throw new MetaMetadataException("super type not specified or recognized: " + this + ", super type name: " + ExtendsAttribute);
                    }

                    // generate inline mmds and put it into current scope
                    MetaMetadata generatedMmd = this.GenerateMetaMetadata(inheritedMmdName, inheritedMmd);
                    mmdScope.Put(inheritedMmdName, generatedMmd);
                    mmdScope.Put(generatedMmd.Name, generatedMmd);

                    // recursively do inheritance on generated mmd
                    generatedMmd.InheritMetaMetadata(null); // this will set generateClassDescriptor to true if necessary

                    MakeThisFieldUseMmd(inheritedMmdName, generatedMmd);
                    return(generatedMmd);
                }
                else
                {
                    // use type / extends
                    if (inheritedMmdName == null)
                    {
                        throw new MetaMetadataException("no type / extends defined for " + this
                                                        + " (note that due to a limitation explicit child_scalar_type is needed for scalar collection fields, even if it has been declared in super field).");
                    }

                    NameType[] nameType = new NameType[1];
                    inheritedMmd = inheritanceHandler.ResolveMmdName(inheritedMmdName, nameType);

                    if (inheritedMmd == null)
                    {
                        throw new MetaMetadataException("meta-metadata not found: " + inheritedMmdName + " (if you want to define new types inline, you need to specify extends/child_extends).");
                    }

                    if (!inheritedMmdName.Equals(inheritedMmd.Name) && nameType[0] == NameType.MMD)
                    {
                        // could be inline mmd
                        this.MakeThisFieldUseMmd(inheritedMmdName, inheritedMmd);
                    }

                    // process normal mmd / field
                    Debug.WriteLine("setting " + this + ".inheritedMmd to " + inheritedMmd);
                    TypeMmd = inheritedMmd;
                }
            }
            return(inheritedMmd);
        }
예제 #19
0
 static MetaMetadataRepositoryInit()
 {
     SimplTypesScope.graphSwitch = SimplTypesScope.GRAPH_SWITCH.ON;
     MetaMetadataRepository.InitializeTypes();
 }
 public InheritanceHandler(MetaMetadata rootMmd)
 {
     this.rootMmd    = rootMmd;
     this.repository = rootMmd.Repository;
 }