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); }
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); }
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); }
SetUp() { m_oGraphAdapter = new GraphMLGraphAdapter(); m_sTempFileName = Path.GetTempFileName(); }