/// <summary> /// Imports a graph from the given file. /// The format is determined by the file extension. /// Any errors will be reported by exception. /// </summary> /// <param name="importFilename">The filename of the file to be imported, /// the model specification part will be ignored.</param> /// <param name="backend">The backend to use to create the graph.</param> /// <param name="graphModel">The graph model to be used, /// it must be conformant to the model used in the file 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(String importFilename, IBackend backend, IGraphModel graphModel, out IActions actions) { if (importFilename.EndsWith(".gxl", StringComparison.InvariantCultureIgnoreCase)) { return(GXLImport.Import(importFilename, backend, graphModel, out actions)); } else if (importFilename.EndsWith(".grs", StringComparison.InvariantCultureIgnoreCase) || importFilename.EndsWith(".grsi", StringComparison.InvariantCultureIgnoreCase)) { return(GRSImport.Import(importFilename, backend, graphModel, out actions)); } else { throw new NotSupportedException("File format not supported"); } }
/// <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"); } } }