Exemplo n.º 1
0
        public string GetFilterForSourceFileType(GraphSourceType fileType)
        {
            var filter = String.Empty;

            switch (fileType)
            {
            case GraphSourceType.Gxml:
                filter = "GXML files (*.gxml) | *.gxml";
                break;

            case GraphSourceType.AdjList:
            case GraphSourceType.AdjMatrix:
            case GraphSourceType.EdgesList:
            case GraphSourceType.IncidenceMatrix:
            case GraphSourceType.GraphVizPlainExt:
                filter = "TXT files (*.txt) | *.txt";
                break;

            case GraphSourceType.HierarchicalRtf:
                filter = "Rtf file (*.rtf) | *.rtf";
                break;

            case GraphSourceType.Dot:
                filter = "Dot file (*.gv, *.dot) | *.gv; *.dot";
                break;

            default:
                throw new ArgumentException("Unknown file type");
            }
            return(filter);
        }
Exemplo n.º 2
0
        public string PresentAsText(IGraph graph, GraphSourceType sourceType)
        {
            var sb = new StringBuilder();

            using (var stringWriter = new StringWriter(sb))
            {
                switch (sourceType)
                {
                case GraphSourceType.None:
                    throw new ArgumentException("Type of source file can't be none");

                case GraphSourceType.Gxml:
                    (new GxmlFormatStorage()).Save(stringWriter, graph);
                    break;

                case GraphSourceType.AdjList:
                    (new AdjListFormatStorage()).Save(stringWriter, graph);
                    break;

                case GraphSourceType.AdjMatrix:
                    (new AdjMatrixFormatStorage()).Save(stringWriter, graph);
                    break;

                case GraphSourceType.EdgesList:
                    (new EdgesListFormatStorage()).Save(stringWriter, graph);
                    break;

                case GraphSourceType.IncidenceMatrix:
                    (new IncidenceMatrixFormatStorage()).Save(stringWriter, graph);
                    break;

                case GraphSourceType.GraphVizPlainExt:
                    (new GraphVizPlainExtFormatStorage()).Save(stringWriter, graph);
                    break;

                case GraphSourceType.HierarchicalRtf:
                    (new HierarchicalRtfFormatStorage()).Save(stringWriter, graph);
                    break;

                default:
                    throw new NotSupportedException($"{sourceType.ToString()} not support");
                }
            }
            return(sb.ToString());
        }
Exemplo n.º 3
0
        public void LoadFromText(IGraph graph, string text, GraphSourceType sourceType)
        {
            using (var stringReader = new StringReader(text))
            {
                switch (sourceType)
                {
                case GraphSourceType.None:
                    throw new ArgumentException("Type of source file can't be None");

                case GraphSourceType.Gxml:
                    (new GxmlFormatStorage()).Open(stringReader, graph);
                    break;

                case GraphSourceType.AdjList:
                    (new AdjListFormatStorage()).Open(stringReader, graph);
                    break;

                case GraphSourceType.AdjMatrix:
                    (new AdjMatrixFormatStorage()).Open(stringReader, graph);
                    break;

                case GraphSourceType.EdgesList:
                    (new EdgesListFormatStorage()).Open(stringReader, graph);
                    break;

                case GraphSourceType.IncidenceMatrix:
                    (new IncidenceMatrixFormatStorage()).Open(stringReader, graph);
                    break;

                case GraphSourceType.GraphVizPlainExt:
                    (new GraphVizPlainExtFormatStorage()).Open(stringReader, graph);
                    break;

                case GraphSourceType.Dot:
                    (new DotFormatStorage()).Open(stringReader, graph);
                    break;

                default:
                    throw new NotSupportedException($"{sourceType.ToString()} not support");
                }
            }
        }
Exemplo n.º 4
0
        public void LoadFromFile(IGraph graph, string path, GraphSourceType sourceType)
        {
            switch (sourceType)
            {
            case GraphSourceType.None:
                throw new ArgumentException("Type of source file can't be None");

            case GraphSourceType.Gxml:
                (new GxmlFormatStorage()).Open(path, graph);
                break;

            case GraphSourceType.AdjList:
                (new AdjListFormatStorage()).Open(path, graph);
                break;

            case GraphSourceType.AdjMatrix:
                (new AdjMatrixFormatStorage()).Open(path, graph);
                break;

            case GraphSourceType.EdgesList:
                (new EdgesListFormatStorage()).Open(path, graph);
                break;

            case GraphSourceType.IncidenceMatrix:
                (new IncidenceMatrixFormatStorage()).Open(path, graph);
                break;

            case GraphSourceType.GraphVizPlainExt:
                (new GraphVizPlainExtFormatStorage()).Open(path, graph);
                break;

            case GraphSourceType.Dot:
                (new DotFormatStorage()).Open(path, graph);
                break;

            default:
                throw new NotSupportedException($"{sourceType.ToString()} not support");
            }

            SourceFile = path;
            SourceType = sourceType;
        }
Exemplo n.º 5
0
 public GraphRepository()
 {
     SourceFile = "";
     SourceType = GraphSourceType.None;
 }