コード例 #1
0
        TryGetGraphFromGraphDataProvider
        (
            Object graphDataProvider,
            out IGraph graph
        )
        {
            Debug.Assert(graphDataProvider != null);

            Debug.Assert(graphDataProvider is IGraphDataProvider2 ||
                         graphDataProvider is IGraphDataProvider);

            graph = null;
            GraphMLGraphAdapter oGraphMLGraphAdapter = new GraphMLGraphAdapter();

            if (graphDataProvider is IGraphDataProvider2)
            {
                String sPathToTemporaryFile = null;

                if (!((IGraphDataProvider2)graphDataProvider)
                    .TryGetGraphDataAsTemporaryFile(out sPathToTemporaryFile))
                {
                    return(false);
                }

                try
                {
                    graph = oGraphMLGraphAdapter.LoadGraphFromFile(
                        sPathToTemporaryFile);
                }
                finally
                {
                    File.Delete(sPathToTemporaryFile);
                }
            }
            else
            {
                String sGraphDataAsGraphML;

                if (!((IGraphDataProvider)graphDataProvider).TryGetGraphData(
                        out sGraphDataAsGraphML))
                {
                    return(false);
                }

                graph = oGraphMLGraphAdapter.LoadGraphFromString(
                    sGraphDataAsGraphML);
            }

            return(true);
        }
コード例 #2
0
        OpenObject
        (
            String sFileName,
            out Object oObject
        )
        {
            Debug.Assert(!String.IsNullOrEmpty(sFileName));
            Debug.Assert(File.Exists(sFileName));
            AssertValid();

            oObject = null;

            // Use a graph adapter to create a graph from the file.

            IGraphAdapter oGraphMLGraphAdapter = new GraphMLGraphAdapter();

            oObject = oGraphMLGraphAdapter.LoadGraphFromFile(sFileName);
        }
コード例 #3
0
        GetGraphML
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook
        )
        {
            Debug.Assert(oWorkbook != null);

            String sGraphML = null;

            // The graph owned by the NodeXLControl can't be used, because it
            // doesn't include all the edge and vertex column data needed for
            // GraphML.  Instead, read the graph from the workbook and include all
            // the necessary data.

            ReadWorkbookContext oReadWorkbookContext = new ReadWorkbookContext();

            oReadWorkbookContext.ReadAllEdgeAndVertexColumns = true;

            WorkbookReader oWorkbookReader = new WorkbookReader();

            IGraph oGraphForGraphML = oWorkbookReader.ReadWorkbook(
                oWorkbook, oReadWorkbookContext);

            GraphMLGraphAdapter oGraphMLGraphAdapter = new GraphMLGraphAdapter();

            using (MemoryStream oMemoryStream = new MemoryStream())
            {
                oGraphMLGraphAdapter.SaveGraph(oGraphForGraphML, oMemoryStream);
                oMemoryStream.Position = 0;

                using (StreamReader oStreamReader =
                           new StreamReader(oMemoryStream))
                {
                    sGraphML = oStreamReader.ReadToEnd();
                }
            }

            return(sGraphML);
        }
コード例 #4
0
 SetUp()
 {
     m_oGraphAdapter = new GraphMLGraphAdapter();
     m_sTempFileName = Path.GetTempFileName();
 }