Example #1
0
        /// <summary>
        /// Exports the given named graph to a file with the given filename.
        /// The format is determined by the file extension.
        /// Currently available are: .grs/.grsi or .gxl or .xmi.
        /// Optionally suffixed by .gz; in this case they are saved gzipped.
        /// Any errors will be reported by exception.
        /// </summary>
        /// <param name="graph">The named graph to export.
        /// The .grs/.grsi exporter is exporting the names/including the names; import will return a named graph again.
        /// The .gxl exporter is exporting without the names, which is equivalent of calling the non-named graph export.</param>
        /// The .xmi exporter is using the names as xmi ids.</param>
        /// <param name="filenameParameters">The names of the files to be exported.
        /// The first must be a filename, the following may be used for giving export parameters
        /// (in fact currently no exporter supports multiple files).</param>
        public static void Export(INamedGraph graph, List <String> filenameParameters)
        {
            String       first  = ListGet(filenameParameters, 0);
            StreamWriter writer = null;

            if (first.EndsWith(".gz", StringComparison.InvariantCultureIgnoreCase))
            {
                FileStream filewriter = new FileStream(first, FileMode.OpenOrCreate, FileAccess.Write);
                writer = new StreamWriter(new GZipStream(filewriter, CompressionMode.Compress));
                first  = first.Substring(0, first.Length - 3);
            }
            else
            {
                writer = new StreamWriter(first);
            }

            using (writer)
            {
                if (first.EndsWith(".gxl", StringComparison.InvariantCultureIgnoreCase))
                {
                    GXLExport.Export(graph, writer);
                }
                else if (first.EndsWith(".grs", StringComparison.InvariantCultureIgnoreCase) ||
                         first.EndsWith(".grsi", StringComparison.InvariantCultureIgnoreCase))
                {
                    GRSExport.Export(graph, writer);
                }
                else if (first.EndsWith(".xmi", StringComparison.InvariantCultureIgnoreCase))
                {
                    XMIExport.Export(graph, writer);
                }
                else if (first.EndsWith(".grg", StringComparison.InvariantCultureIgnoreCase))
                {
                    GRGExport.Export(graph, writer);
                }
                else
                {
                    throw new NotSupportedException("File format not supported");
                }
            }
        }
Example #2
0
 /// <summary>
 /// Exports the given graph in GXL format to the given text writer output stream.
 /// Any errors will be reported by exception.
 /// </summary>
 /// <param name="graph">The graph to export.</param>
 /// <param name="streamWriter">The stream writer to export to.</param>
 public static void Export(IGraph graph, TextWriter streamWriter)
 {
     using (GXLExport export = new GXLExport(streamWriter))
         export.Export(graph);
 }
Example #3
0
 /// <summary>
 /// Exports the given graph to a GXL file with the given filename.
 /// Any errors will be reported by exception.
 /// </summary>
 /// <param name="graph">The graph to export.</param>
 /// <param name="exportFilename">The filename for the exported file.</param>
 public static void Export(IGraph graph, String exportFilename)
 {
     using (GXLExport export = new GXLExport(exportFilename))
         export.Export(graph);
 }
Example #4
0
 /// <summary>
 /// Exports the given graph in GXL format to the given text writer output stream.
 /// Any errors will be reported by exception.
 /// </summary>
 /// <param name="graph">The graph to export.</param>
 /// <param name="streamWriter">The stream writer to export to.</param>
 public static void Export(IGraph graph, TextWriter streamWriter)
 {
     using(GXLExport export = new GXLExport(streamWriter))
         export.Export(graph);
 }
Example #5
0
 /// <summary>
 /// Exports the given graph to a GXL file with the given filename.
 /// Any errors will be reported by exception.
 /// </summary>
 /// <param name="graph">The graph to export.</param>
 /// <param name="exportFilename">The filename for the exported file.</param>
 public static void Export(IGraph graph, String exportFilename)
 {
     using(GXLExport export = new GXLExport(exportFilename))
         export.Export(graph);
 }
Example #6
0
        /// <summary>
        /// Exports the given named graph to a file with the given filename.
        /// The format is determined by the file extension.
        /// Currently available are: .grs/.grsi or .gxl or .xmi.
        /// Optionally suffixed by .gz; in this case they are saved gzipped.
        /// Any errors will be reported by exception.
        /// </summary>
        /// <param name="graph">The named graph to export.
        /// The .grs/.grsi exporter is exporting the names/including the names; import will return a named graph again.
        /// The .gxl exporter is exporting without the names, which is equivalent of calling the non-named graph export.</param>
        /// The .xmi exporter is using the names as xmi ids.</param>
        /// <param name="filenameParameters">The names of the files to be exported.
        /// The first must be a filename, the following may be used for giving export parameters
        /// (in fact currently no exporter supports multiple files).</param>
        public static void Export(INamedGraph graph, List <String> filenameParameters)
        {
            String       first  = ListGet(filenameParameters, 0);
            StreamWriter writer = null;

            if (first.EndsWith(".gz", StringComparison.InvariantCultureIgnoreCase))
            {
                FileStream filewriter = new FileStream(first, FileMode.OpenOrCreate, FileAccess.Write);
                writer = new StreamWriter(new GZipStream(filewriter, CompressionMode.Compress), System.Text.Encoding.UTF8);
                first  = first.Substring(0, first.Length - 3);
            }
            else
            {
                writer = new StreamWriter(first, false, System.Text.Encoding.UTF8);
            }

            using (writer)
            {
                if (first.EndsWith(".gxl", StringComparison.InvariantCultureIgnoreCase))
                {
                    GXLExport.Export(graph, writer);
                }
                else if (first.EndsWith(".grs", StringComparison.InvariantCultureIgnoreCase) ||
                         first.EndsWith(".grsi", StringComparison.InvariantCultureIgnoreCase))
                {
                    bool noNewGraph = false;
                    Dictionary <String, Dictionary <String, String> > typesToAttributesToSkip = new Dictionary <string, Dictionary <string, string> >();
                    for (int i = 1; i < filenameParameters.Count; ++i)
                    {
                        if (filenameParameters[i].StartsWith("skip/") || filenameParameters[i].StartsWith("skip\\"))
                        {
                            String toSkip    = filenameParameters[i].Substring(5);
                            String type      = toSkip.Substring(0, toSkip.IndexOf('.'));
                            String attribute = toSkip.Substring(toSkip.IndexOf('.') + 1);
                            Dictionary <String, String> attributesToSkip;
                            if (!typesToAttributesToSkip.TryGetValue(type, out attributesToSkip))
                            {
                                typesToAttributesToSkip[type] = new Dictionary <string, string>();
                            }
                            typesToAttributesToSkip[type].Add(attribute, null);
                        }
                        else if (filenameParameters[i] == "nonewgraph")
                        {
                            noNewGraph = true;
                        }
                        else
                        {
                            throw new NotSupportedException("Export Parameter " + i + " not supported: " + filenameParameters[i]);
                        }
                    }
                    GRSExport.Export(graph, writer, noNewGraph, typesToAttributesToSkip.Count > 0 ? typesToAttributesToSkip : null);
                }
                else if (first.EndsWith(".xmi", StringComparison.InvariantCultureIgnoreCase))
                {
                    XMIExport.Export(graph, writer);
                }
                else if (first.EndsWith(".grg", StringComparison.InvariantCultureIgnoreCase))
                {
                    GRGExport.Export(graph, writer);
                }
                else
                {
                    throw new NotSupportedException("File format not supported");
                }
            }
        }