Пример #1
0
    public static void Main(string[] args)
    {
        if (args.Length < 3) {
            Console.Error.WriteLine("Usage:  mono rdfbind.exe bindings.txt targetschema schmefile1 schemafile2 . . .");
            return;
        }

        // Parse command-line arguments
        string bindingmapfile = args[0];
        string targetschema = args[1];
        ArrayList schemafiles = new ArrayList();
        for (int i = 2; i < args.Length; i++)
            schemafiles.Add(args[i]);

        // Load the binding map
        Hashtable bindingmap = new Hashtable();
        ArrayList schemalist = new ArrayList();
        try {
            char[] whitespacechars = { ' ', '\t' };
            using (TextReader map = new StreamReader(bindingmapfile)) {
                string line;
                while ((line = map.ReadLine()) != null) {
                    if (line == "" || line.StartsWith("#")) continue;
                    int whitespace = line.IndexOfAny(whitespacechars);
                    if (whitespace == -1)
                        throw new FormatException("Each line should be an assembly/namespace name followed by a space or tab, followed by a schema URI.");
                    string name = line.Substring(0, whitespace).Trim();
                    string uri = line.Substring(whitespace+1).Trim();
                    bindingmap[uri] = name;
                    schemalist.Add(uri);

                    // Let targetscheme be either a name or URI.
                    if (targetschema == name)
                        targetschema = uri;
                }
            }
        } catch (Exception e) {
            Console.Error.WriteLine("Error loading the binding map: " + e.Message);
            return;
        }

        if (!bindingmap.ContainsKey(targetschema)) {
            Console.Error.WriteLine("The target schema must have an entry in the binding map.");
            return;
        }

        MultiStore schemas = new MultiStore();
        foreach (string schemafile in schemafiles) {
            try {
                Store schema = new MemoryStore(new RdfXmlReader(schemafile));
                schemas.Add(schema);
            } catch (Exception e) {
                Console.Error.WriteLine("Error loading the schema in '" + schemafile + "': " + e.Message);
                return;
            }
        }

        foreach (string sch in schemalist) {
            AssemblyBuilder a = new SemWeb.Bind.Bindings(sch, schemas, bindingmap).CreateBindings();
            a.Save((string)bindingmap[sch] + ".dll");
        }
    }
Пример #2
0
    public static void Main(string[] args)
    {
        if (args.Length < 3)
        {
            Console.Error.WriteLine("Usage:  mono rdfbind.exe bindings.txt targetschema schmefile1 schemafile2 . . .");
            return;
        }

        // Parse command-line arguments
        string    bindingmapfile = args[0];
        string    targetschema   = args[1];
        ArrayList schemafiles    = new ArrayList();

        for (int i = 2; i < args.Length; i++)
        {
            schemafiles.Add(args[i]);
        }

        // Load the binding map
        Hashtable bindingmap = new Hashtable();
        ArrayList schemalist = new ArrayList();

        try {
            char[] whitespacechars = { ' ', '\t' };
            using (TextReader map = new StreamReader(bindingmapfile)) {
                string line;
                while ((line = map.ReadLine()) != null)
                {
                    if (line == "" || line.StartsWith("#"))
                    {
                        continue;
                    }
                    int whitespace = line.IndexOfAny(whitespacechars);
                    if (whitespace == -1)
                    {
                        throw new FormatException("Each line should be an assembly/namespace name followed by a space or tab, followed by a schema URI.");
                    }
                    string name = line.Substring(0, whitespace).Trim();
                    string uri  = line.Substring(whitespace + 1).Trim();
                    bindingmap[uri] = name;
                    schemalist.Add(uri);

                    // Let targetscheme be either a name or URI.
                    if (targetschema == name)
                    {
                        targetschema = uri;
                    }
                }
            }
        } catch (Exception e) {
            Console.Error.WriteLine("Error loading the binding map: " + e.Message);
            return;
        }

        if (!bindingmap.ContainsKey(targetschema))
        {
            Console.Error.WriteLine("The target schema must have an entry in the binding map.");
            return;
        }

        MultiStore schemas = new MultiStore();

        foreach (string schemafile in schemafiles)
        {
            try {
                Store schema = new MemoryStore(new RdfXmlReader(schemafile));
                schemas.Add(schema);
            } catch (Exception e) {
                Console.Error.WriteLine("Error loading the schema in '" + schemafile + "': " + e.Message);
                return;
            }
        }

        foreach (string sch in schemalist)
        {
            AssemblyBuilder a = new SemWeb.Bind.Bindings(sch, schemas, bindingmap).CreateBindings();
            a.Save((string)bindingmap[sch] + ".dll");
        }
    }