//************************************************************************* // Constructor: ConvertGraphMLToNodeXLWorkbookException() // /// <summary> /// Initializes a new instance of the <see /// cref="ConvertGraphMLToNodeXLWorkbookException" /> class. /// </summary> /// /// <param name="errorCode"> /// The error code. /// </param> /// /// <param name="message"> /// Error message, suitable for displaying to the user. /// </param> //************************************************************************* public ConvertGraphMLToNodeXLWorkbookException ( GraphMLToNodeXLWorkbookConverter.ErrorCode errorCode, String message ) : base(message) { m_eErrorCode = errorCode; AssertValid(); }
OpenSampleNodeXLWorkbook() { // To create the sample workbook, an empty NodeXL workbook is created // from the NodeXL template, and then a GraphML file containing the // sample data is imported into it. It would be simpler to just // distribute a complete sample workbook with NodeXL, but that workbook // would have to be updated every time the NodeXL template changes. // This way, the latest template is always used. String sSampleNodeXLWorkbookSubfolderPath = Path.Combine( GetApplicationFolder(), SampleNodeXLWorkbookSubfolder); XmlDocument oGraphMLDocument = new XmlDocument(); try { oGraphMLDocument.Load(Path.Combine( sSampleNodeXLWorkbookSubfolderPath, SampleNodeXLWorkbookAsGraphMLFileName)); } catch (Exception oException) { ErrorUtil.OnException(oException); return; } // The sample workbook data contains placeholders for the path to the // image files used in the workbook. Replace those placeholders with a // real image path. String sImagePath = Path.Combine(sSampleNodeXLWorkbookSubfolderPath, SampleNodeXLWorkbookImageSubfolder); oGraphMLDocument.LoadXml(oGraphMLDocument.OuterXml.Replace( SampleNodeXLWorkbookImagePlaceholder, sImagePath)); try { GraphMLToNodeXLWorkbookConverter.SaveGraphToNodeXLWorkbook( oGraphMLDocument, null, null, null, false); } catch (ConvertGraphMLToNodeXLWorkbookException oConvertGraphMLToNodeXLWorkbookException) { FormUtil.ShowWarning( oConvertGraphMLToNodeXLWorkbookException.Message); } }
ImportGraphMLFilesInternal ( ImportGraphMLFilesAsyncArgs oImportGraphMLFilesAsyncArgs, BackgroundWorker oBackgroundWorker, DoWorkEventArgs oDoWorkEventArgs ) { Debug.Assert(oImportGraphMLFilesAsyncArgs != null); Debug.Assert(oBackgroundWorker != null); Debug.Assert(oDoWorkEventArgs != null); AssertValid(); Int32 iGraphMLFiles = 0; foreach (String sGraphMLFilePath in Directory.GetFiles( oImportGraphMLFilesAsyncArgs.SourceFolderPath, "*.graphml")) { if (oBackgroundWorker.CancellationPending) { oDoWorkEventArgs.Cancel = true; return; } String sGraphMLFileName = Path.GetFileName(sGraphMLFilePath); oBackgroundWorker.ReportProgress(0, String.Format( "Importing \"{0}\"." , sGraphMLFileName )); XmlDocument oGraphMLDocument = new XmlDocument(); try { oGraphMLDocument.Load(sGraphMLFilePath); } catch (XmlException oXmlException) { OnXmlException(sGraphMLFileName, oXmlException); continue; } String sNodeXLWorkbookPath = Path.Combine( oImportGraphMLFilesAsyncArgs.DestinationFolderPath, sGraphMLFileName ); sNodeXLWorkbookPath = Path.ChangeExtension(sNodeXLWorkbookPath, ".xlsx"); try { GraphMLToNodeXLWorkbookConverter.SaveGraphToNodeXLWorkbook( oGraphMLDocument, sGraphMLFilePath, sNodeXLWorkbookPath, null, false); } catch (XmlException oXmlException) { OnXmlException(sGraphMLFileName, oXmlException); continue; } iGraphMLFiles++; } oBackgroundWorker.ReportProgress(0, String.Format( "Done. GraphML files imported: {0}." , iGraphMLFiles )); }