Search code examples
c#.netrdfowlrowlex

Programatically generating assemblies from OWL files with ROWLEX


I have been using the ROWLEX library to handle RDF-s. It is shipped with a designtime GUI tool called OwlGrinder.exe that can generate C# helper classes (.NET assemblies to be exact) from my OWL ontologies. I wonder if anyone knows if I could do the same programatically in runtime.


Solution

  • ROWLEX just became open source, so now you have the chance to actually look inside the code of OwlGrinder.exe and copy the code from there. However, here is a short example:

        private NC3A.SI.Rowlex.AssemblyGenerator generator;
    
        private void RunAssemblyGeneration(XmlDocument ontologyFileInRdfXml)
        {
            this.generator = new NC3A.SI.Rowlex.AssemblyGenerator();
            this.generator.GenerateAsync(ontologyFileInRdfXml, "myAssemblyName", 
                                            null, this.OnGenerationFinished);
        }
    
        private void OnGenerationFinished(string errorMessage)
        {
            if (errorMessage == null)
            {
                // Success
                // Displaying warnings and saving result
                string[] warnings = this.generator.Warnings;
                this.generator.SaveResult(@"C:\myAssemblyName.dll");
                    // Important! One generator instance can be executed only once. 
                    this.generator = null; 
                    this.RejoiceOverSuccess();
                }
            else
            {
                    // Failure
                    this.MournOverFailure();
                }
    
        }
    

    If you want to generate assemblies in runtime, I assume that you might want to repeat that over and over again as your user demands. You have to watch out here, because .NET does not allow you to unload an assembly. Therefore you cannot get rid of the assemblies from your previous runs. The solution is that you execute the generation code every time in a new AppDomain which can be unloaded. OwlGrinder.exe does exactly this, you might want to peak inside the MainForm.cs