Exemplo n.º 1
0
        public int Run()
        {
            if (_settings == null)
            {
                throw new Exception("Trinity config file (app.config or web.config) not initialized.");
            }

            _sourceDir = new FileInfo(_configPath).Directory;

            if (!string.IsNullOrEmpty(_generatePath))
            {
                FileInfo fileInfo = new FileInfo(_generatePath);

                using (OntologyGenerator generator = new OntologyGenerator(_settings.Namespace))
                {
                    generator.Logger = Logger;

                    if (_settings.Ontologies != null)
                    {
                        foreach (var ontology in _settings.Ontologies)
                        {
                            UriRef t = GetPathFromSource(ontology.FileSource);

                            if (!generator.ImportOntology(ontology.Uri, t))
                            {
                                FileInfo ontologyFile = new FileInfo(t.LocalPath);

                                ElementInformation info = ontology.ElementInformation;

                                Logger.LogWarning(string.Format("Could not read ontology <{0}> from path {1}.", ontology.Uri, ontologyFile.FullName), info);
                            }

                            if (!generator.AddOntology(ontology.Uri, ontology.MetadataUri, ontology.Prefix))
                            {
                                Logger.LogMessage("Ontology with uri <{0}> or uri <{1}> could not be found in store.", ontology.Uri, ontology.MetadataUri);
                            }
                        }

                        generator.GenerateFile(fileInfo);
                    }
                    else
                    {
                        Logger.LogMessage("No ontologies configured in TrinitySettings section in app.config or web.config.");
                    }
                }

                return(0);
            }
            else
            {
                return(-1);
            }
        }
Exemplo n.º 2
0
        public int Run()
        {
            LoadLegacyConfigFile();
            if (_configuration == null)
            {
                LoadConfigFile();
            }

            if (_configuration == null)
            {
                throw new Exception("Trinity config file not fount. The project does neither have a new style (ontologies.config) or legacy (app.config or web.config) configuration file available.");
            }

            _sourceDir = new FileInfo(_configPath).Directory;

            if (!string.IsNullOrEmpty(_generatePath))
            {
                FileInfo fileInfo = new FileInfo(_generatePath);

                using (OntologyGenerator generator = new OntologyGenerator(_configuration.Namespace))
                {
                    generator.Logger = Logger;


                    foreach (var ontology in _configuration.ListOntologies())
                    {
                        UriRef t = GetPathFromLocation(ontology.Location);

                        if (!generator.ImportOntology(ontology.Uri, t))
                        {
                            FileInfo ontologyFile = new FileInfo(t.LocalPath);


                            Logger.LogWarning(string.Format("Could not read ontology <{0}> from path {1}.", ontology.Uri, ontologyFile.FullName));
                        }

                        if (!generator.AddOntology(ontology.Uri, null, ontology.Prefix))
                        {
                            Logger.LogMessage("Ontology with uri <{0}> or uri <{1}> could not be found in store.", ontology.Uri, null);
                        }
                    }

                    generator.GenerateFile(fileInfo);
                }

                return(0);
            }
            else
            {
                return(-1);
            }
        }