Exemple #1
0
 /// <summary>
 /// Creates a new graph from the given ECore metamodels.
 /// If a grg file is given, the graph will use the graph model declared in it and the according
 /// actions object will be associated to the graph.
 /// If a xmi file is given, the model instance will be imported into the graph.
 /// Any errors will be reported by exception.
 /// </summary>
 /// <param name="backend">The backend to use to create the graph.</param>
 /// <param name="ecoreFilenames">A list of ECore model specification files. It must at least contain one element.</param>
 /// <param name="grgFilename">A grg file to be used to create the graph, or null.</param>
 /// <param name="xmiFilename">The filename of the model instance to be imported, or null.</param>
 /// <param name="noPackageNamePrefix">Prefix the types with the name of the package? Can only be used if names from the packages are disjoint.</param>
 /// <param name="actions">Receives the actions object in case a .grg model is given.</param>
 public static IGraph Import(IBackend backend, List<String> ecoreFilenames, String grgFilename, String xmiFilename, bool noPackageNamePrefix, out IActions actions)
 {
     ECoreImport imported = new ECoreImport();
     imported.graph = imported.ImportModels(ecoreFilenames, grgFilename, backend, out actions);
     if(xmiFilename != null)
     {
         Console.WriteLine("Importing graph...");
         imported.ImportGraph(xmiFilename);
     }
     return imported.graph;
 }
Exemple #2
0
        /// <summary>
        /// Creates a new graph from the given ECore metamodels.
        /// If a grg file is given, the graph will use the graph model declared in it and the according
        /// actions object will be associated to the graph.
        /// If a xmi file is given, the model instance will be imported into the graph.
        /// Any errors will be reported by exception.
        /// </summary>
        /// <param name="backend">The backend to use to create the graph.</param>
        /// <param name="ecoreFilenames">A list of ECore model specification files. It must at least contain one element.</param>
        /// <param name="grgFilename">A grg file to be used to create the graph, or null.</param>
        /// <param name="xmiFilename">The filename of the model instance to be imported, or null.</param>
        /// <param name="noPackageNamePrefix">Prefix the types with the name of the package? Can only be used if names from the packages are disjoint.</param>
        /// <param name="actions">Receives the actions object in case a .grg model is given.</param>
        public static IGraph Import(IBackend backend, List <String> ecoreFilenames, String grgFilename, String xmiFilename, bool noPackageNamePrefix, out IActions actions)
        {
            ECoreImport imported = new ECoreImport();

            imported.graph = imported.ImportModels(ecoreFilenames, grgFilename, backend, out actions);
            if (xmiFilename != null)
            {
                Console.WriteLine("Importing graph...");
                imported.ImportGraph(xmiFilename);
            }
            return(imported.graph);
        }
Exemple #3
0
        /// <summary>
        /// Imports a graph from the given files.
        /// If the filenames only specify a model, the graph is empty.
        /// The format is determined by the file extensions.
        /// Currently available are: .grs/.grsi or .gxl or .ecore with .xmi.
        /// Optionally suffixed by .gz; in this case they are expected to be gzipped.
        /// Any error will be reported by exception.
        /// </summary>
        /// <param name="backend">The backend to use to create the graph.</param>
        /// <param name="filenameParameters">The names of the files to be imported.</param>
        /// <param name="actions">Receives the actions object in case a .grg model is given.</param>
        /// <returns>The imported graph.
        /// The .grs/.grsi importer returns an INamedGraph. If you don't need it: create an LGSPGraph from it and throw the named graph away.
        /// (the naming requires about the same amount of memory the raw graph behind it requires).</returns>
        public static IGraph Import(IBackend backend, List <String> filenameParameters, out IActions actions)
        {
            String       first    = ListGet(filenameParameters, 0);
            FileInfo     fi       = new FileInfo(first);
            long         fileSize = fi.Length;
            StreamReader reader   = null;

            if (first.EndsWith(".gz", StringComparison.InvariantCultureIgnoreCase))
            {
                FileStream filereader = new FileStream(first, FileMode.Open, FileAccess.Read);
                reader = new StreamReader(new GZipStream(filereader, CompressionMode.Decompress));
                first  = first.Substring(0, first.Length - 3);
            }
            else
            {
                reader = new StreamReader(first);
            }

            using (reader)
            {
                if (first.EndsWith(".gxl", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(GXLImport.Import(reader, ListGet(filenameParameters, 1), backend, out actions));
                }
                else if (first.EndsWith(".grs", StringComparison.InvariantCultureIgnoreCase) ||
                         first.EndsWith(".grsi", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(GRSImport.Import(reader, fileSize, ListGet(filenameParameters, 1), backend, out actions));
                }
                else if (first.EndsWith(".ecore", StringComparison.InvariantCultureIgnoreCase))
                {
                    List <String> ecores = new List <String>();
                    String        grg    = null;
                    String        xmi    = null;
                    bool          noPackageNamePrefix = false;
                    foreach (String filename in filenameParameters)
                    {
                        if (filename.EndsWith(".ecore"))
                        {
                            ecores.Add(filename);
                        }
                        else if (filename.EndsWith(".grg"))
                        {
                            if (grg != null)
                            {
                                throw new NotSupportedException("Only one .grg file supported");
                            }
                            grg = filename;
                        }
                        else if (filename.EndsWith(".xmi"))
                        {
                            if (xmi != null)
                            {
                                throw new NotSupportedException("Only one .xmi file supported");
                            }
                            xmi = filename;
                        }
                        else if (filename == "nopackagenameprefix")
                        {
                            noPackageNamePrefix = true;
                        }
                    }
                    return(ECoreImport.Import(backend, ecores, grg, xmi, noPackageNamePrefix, out actions));
                }
                else
                {
                    throw new NotSupportedException("File format not supported");
                }
            }
        }