GetSelectedEdgeRowIDs ( NodeXLControl nodeXLControl ) { Debug.Assert(nodeXLControl != null); LinkedList<Int32> oSelectedEdgeRowIDs = new LinkedList<Int32>(); foreach (IEdge oSelectedEdge in nodeXLControl.SelectedEdges) { // The IDs from the worksheet are stored in the edge Tags. if ( !(oSelectedEdge.Tag is Int32) ) { // The ID column is optional, so edges may not have their Tag // set. continue; } oSelectedEdgeRowIDs.AddLast( (Int32)oSelectedEdge.Tag ); } return (oSelectedEdgeRowIDs); }
CreateNodeXLControl() { // AssertValid(); // Control hierarchy: // // 1. ehElementHost contains a NodeXLWithAxesControl. // // 2. The NodeXLWithAxesControl contains a NodeXLControl. m_oNodeXLControl = new NodeXLControl(); m_oNodeXLWithAxesControl = new NodeXLWithAxesControl(m_oNodeXLControl); // Don't show the axes now. If they are supposed to be shown, the // Ribbon, which is responsible for maintaining the visibility of the // axes, will send a NoParamCommand.ShowGraphAxes command to the // TaskPane later. m_oNodeXLWithAxesControl.ShowAxes = false; m_oNodeXLControl.LayingOutGraph += new System.EventHandler( this.oNodeXLControl_LayingOutGraph); m_oNodeXLControl.GraphLaidOut += new AsyncCompletedEventHandler( this.oNodeXLControl_GraphLaidOut); ehNodeXLControlHost.Child = m_oNodeXLWithAxesControl; }
//************************************************************************* // Constructor: ExportToEmailDialog() // /// <summary> /// Initializes a new instance of the <see cref="ExportToEmailDialog" /> /// class. /// </summary> /// /// <param name="mode"> /// Indicates the mode in which the dialog is being used. /// </param> /// /// <param name="workbook"> /// Workbook containing the graph data. /// </param> /// /// <param name="nodeXLControl"> /// NodeXLControl containing the graph. This can be null if <paramref /// name="mode" /> is <see cref="DialogMode.EditOnly" />. /// </param> //************************************************************************* public ExportToEmailDialog ( DialogMode mode, Microsoft.Office.Interop.Excel.Workbook workbook, NodeXLControl nodeXLControl ) { Debug.Assert(workbook != null); Debug.Assert(nodeXLControl != null || mode == DialogMode.EditOnly); m_eMode = mode; m_oWorkbook = workbook; m_oNodeXLControl = nodeXLControl; m_oExportToEmailUserSettings = new ExportToEmailUserSettings(); m_oPasswordUserSettings = new PasswordUserSettings(); InitializeComponent(); if (m_eMode == DialogMode.EditOnly) { InitializeForEditOnly(); } // Instantiate an object that saves and retrieves the user settings for // this dialog. Note that the object automatically saves the settings // when the form closes. m_oExportToEmailDialogUserSettings = new ExportToEmailDialogUserSettings(this); DoDataExchange(false); AssertValid(); }
//************************************************************************* // Constructor: ReadabilityMetricsDialog() // /// <summary> /// Initializes a new instance of the <see /// cref="ReadabilityMetricsDialog" /> class. /// </summary> /// /// <param name="nodeXLControl"> /// NodeXLControl containing the graph. /// </param> /// /// <param name="workbook"> /// Workbook containing the graph data. /// </param> //************************************************************************* public ReadabilityMetricsDialog ( NodeXLControl nodeXLControl, Microsoft.Office.Interop.Excel.Workbook workbook ) { InitializeComponent(); m_oNodeXLControl = nodeXLControl; m_oWorkbook = workbook; m_oReadabilityMetricUserSettings = new ReadabilityMetricUserSettings(); // Instantiate an object that saves and retrieves the user settings for // this dialog. Note that the object automatically saves the settings // when the form closes. m_oReadabilityMetricsDialogUserSettings = new ReadabilityMetricsDialogUserSettings(this); DoDataExchange(false); m_oNodeXLControl.VerticesMoved += new VerticesMovedEventHandler(this.OnVerticesMoved); m_oNodeXLControl.GraphLaidOut += new AsyncCompletedEventHandler(this.OnGraphLaidOut); AssertValid(); }
//************************************************************************* // Constructor: GraphRectangleEventArgs() // /// <summary> /// Initializes a new instance of the <see /// cref="GraphRectangleEventArgs" /> class. /// </summary> /// /// <param name="graphRectangle"> /// The rectangle the graph was drawn within. /// </param> /// /// <param name="nodeXLControl"> /// The control in which the graph was drawn. /// </param> //************************************************************************* public GraphRectangleEventArgs ( Rectangle graphRectangle, NodeXLControl nodeXLControl ) { m_oGraphRectangle = graphRectangle; m_oNodeXLControl = nodeXLControl; // AssertValid(); }
CreateNodeXLControl() { m_oNodeXLWithAxesControl = new NodeXLWithAxesControl(); m_oNodeXLWithAxesControl.XAxis.Label = "This is the x-axis"; m_oNodeXLWithAxesControl.YAxis.Label = "This is the y-axis"; m_oNodeXLControl = m_oNodeXLWithAxesControl.NodeXLControl; m_oNodeXLControl.SelectionChanged += new System.EventHandler(this.m_oNodeXLControl_SelectionChanged); m_oNodeXLControl.VertexClick += new Smrf.NodeXL.Core.VertexEventHandler( this.m_oNodeXLControl_VertexClick); m_oNodeXLControl.VertexDoubleClick += new Smrf.NodeXL.Core.VertexEventHandler( this.m_oNodeXLControl_VertexDoubleClick); m_oNodeXLControl.VertexMouseHover += new Smrf.NodeXL.Core.VertexEventHandler( this.m_oNodeXLControl_VertexMouseHover); m_oNodeXLControl.VertexMouseLeave += new EventHandler(this.m_oNodeXLControl_VertexMouseLeave); m_oNodeXLControl.VerticesMoved += new Smrf.NodeXL.Visualization.Wpf.VerticesMovedEventHandler( this.m_oNodeXLControl_VerticesMoved); m_oNodeXLControl.PreviewVertexToolTipShown += new VertexToolTipShownEventHandler( this.m_oNodeXLControl_PreviewVertexToolTipShown); m_oNodeXLControl.GraphMouseDown += new Smrf.NodeXL.Visualization.Wpf.GraphMouseButtonEventHandler( this.m_oNodeXLControl_GraphMouseDown); m_oNodeXLControl.GraphMouseUp += new Smrf.NodeXL.Visualization.Wpf.GraphMouseButtonEventHandler( this.m_oNodeXLControl_GraphMouseUp); m_oNodeXLControl.GraphZoomChanged += new System.EventHandler(this.m_oNodeXLControl_GraphZoomChanged); m_oNodeXLControl.LayingOutGraph += new System.EventHandler(this.m_oNodeXLControl_LayingOutGraph); m_oNodeXLControl.GraphLaidOut += new AsyncCompletedEventHandler(this.m_oNodeXLControl_GraphLaidOut); ehElementHost.Child = m_oNodeXLWithAxesControl; }
//************************************************************************* // Constructor: GraphImageScaler() // /// <summary> /// Initializes a new instance of the <see cref="GraphImageScaler" /> /// class. /// </summary> /// /// <param name="nodeXLControl"> /// The control for which a graph image will be created. /// </param> //************************************************************************* public GraphImageScaler ( NodeXLControl nodeXLControl ) { Debug.Assert(nodeXLControl != null); m_oNodeXLControl = nodeXLControl; m_dOriginalGraphScale = 0; m_dOriginalGroupLabelScale = 0; AssertValid(); }
//************************************************************************* // Constructor: VerticesMovedEventArgs2() // /// <summary> /// Initializes a new instance of the <see /// cref="VerticesMovedEventArgs2" /> class. /// </summary> /// /// <param name="verticesAndRowIDs"> /// Collection of <see cref="VertexAndRowID" /> objects, one for each /// vertex that was moved. /// </param> /// /// <param name="graphRectangle"> /// The rectangle the graph was drawn within. /// </param> /// /// <param name="nodeXLControl"> /// The control in which the graph was drawn. /// </param> //************************************************************************* public VerticesMovedEventArgs2 ( ICollection<VertexAndRowID> verticesAndRowIDs, Rectangle graphRectangle, NodeXLControl nodeXLControl ) : base(graphRectangle, nodeXLControl) { m_oVerticesAndRowIDs = verticesAndRowIDs; AssertValid(); }
//************************************************************************* // Constructor: GroupsCollapsedOrExpandedEventArgs() // /// <summary> /// Initializes a new instance of the <see /// cref="GroupsCollapsedOrExpandedEventArgs" /> class. /// </summary> /// /// <param name="graphRectangle"> /// The rectangle the graph was drawn within. /// </param> /// /// <param name="nodeXLControl"> /// The control in which the graph was drawn. /// </param> /// /// <param name="groupsRedrawnImmediately"> /// true if the groups were redrawn immediately after they were collapsed /// or expanded, false if they won't be redrawn until the graph is redrawn. /// </param> //************************************************************************* public GroupsCollapsedOrExpandedEventArgs ( Rectangle graphRectangle, NodeXLControl nodeXLControl, Boolean groupsRedrawnImmediately ) : base(graphRectangle, nodeXLControl) { m_bGroupsRedrawnImmediately = groupsRedrawnImmediately; AssertValid(); }
//************************************************************************* // Constructor: GraphImageCompositor() // /// <summary> /// Initializes a new instance of the <see cref="GraphImageCompositor" /> /// class. /// </summary> /// /// <param name="nodeXLControl"> /// The NodeXLControl that will be composited by <see cref="Composite" />. /// This is assumed to be hosted in a Panel. /// </param> //************************************************************************* public GraphImageCompositor ( NodeXLControl nodeXLControl ) { m_oNodeXLControl = nodeXLControl; m_oLayoutSaver = null; m_oGraphImageScaler = null; m_oGraphImageCenterer = null; m_oParentPanel = null; m_iChildIndex = Int32.MinValue; m_oGrid = null; AssertValid(); }
//************************************************************************* // Constructor: GraphLaidOutEventArgs() // /// <summary> /// Initializes a new instance of the <see cref="GraphLaidOutEventArgs" /> /// class. /// </summary> /// /// <param name="graphRectangle"> /// The rectangle the graph was drawn within. /// </param> /// /// <param name="edgeIDDictionary"> /// Dictionary that maps edge IDs stored in the edge worksheet to edge /// objects in the graph. /// </param> /// /// <param name="vertexIDDictionary"> /// Dictionary that maps vertex IDs stored in the vertex worksheet to /// vertex objects in the graph. /// </param> /// /// <param name="nodeXLControl"> /// The control in which the graph was laid out. /// </param> /// /// <param name="legendControls"> /// Zero or more legend controls associated with <paramref /// name="nodeXLControl" />. Can't be null. /// </param> //************************************************************************* public GraphLaidOutEventArgs ( Rectangle graphRectangle, Dictionary<Int32, IIdentityProvider> edgeIDDictionary, Dictionary<Int32, IIdentityProvider> vertexIDDictionary, NodeXLControl nodeXLControl, IEnumerable<LegendControlBase> legendControls ) : base(graphRectangle, nodeXLControl) { m_oEdgeIDDictionary = edgeIDDictionary; m_oVertexIDDictionary = vertexIDDictionary; m_oLegendControls = legendControls; AssertValid(); }
//************************************************************************* // Constructor: GraphImageCenterer() // /// <summary> /// Initializes a new instance of the <see cref="GraphImageCenterer" /> /// class. /// </summary> /// /// <param name="nodeXLControl"> /// The control for which a graph image will be created. /// </param> //************************************************************************* public GraphImageCenterer ( NodeXLControl nodeXLControl ) { Debug.Assert(nodeXLControl != null); m_oNodeXLControl = nodeXLControl; m_dOriginalTranslateTransformForRenderX = m_dOriginalTranslateTransformForRenderY = m_dOriginalScaleTransformForRenderCenterX = m_dOriginalScaleTransformForRenderCenterY = Double.MinValue; AssertValid(); }
//************************************************************************* // Constructor: ExportToNodeXLGraphGalleryDialog() // /// <summary> /// Initializes a new instance of the <see /// cref="ExportToNodeXLGraphGalleryDialog" /> class. /// </summary> /// /// <param name="mode"> /// Indicates the mode in which the dialog is being used. /// </param> /// /// <param name="workbook"> /// Workbook containing the graph data. /// </param> /// /// <param name="nodeXLControl"> /// NodeXLControl containing the graph. This can be null if <paramref /// name="mode" /> is <see cref="DialogMode.EditOnly" />. /// </param> //************************************************************************* public ExportToNodeXLGraphGalleryDialog ( DialogMode mode, Microsoft.Office.Interop.Excel.Workbook workbook, NodeXLControl nodeXLControl ) { Debug.Assert(workbook != null); Debug.Assert(nodeXLControl != null || mode == DialogMode.EditOnly); m_eMode = mode; m_oWorkbook = workbook; m_oNodeXLControl = nodeXLControl; m_oExportToNodeXLGraphGalleryUserSettings = new ExportToNodeXLGraphGalleryUserSettings(); m_oPasswordUserSettings = new PasswordUserSettings(); InitializeComponent(); if (m_eMode == DialogMode.EditOnly) { InitializeForEditOnly(); } lnkNodeXLGraphGallery.Tag = ProjectInformation.NodeXLGraphGalleryUrl; usrExportedFilesDescription.Workbook = workbook; lnkCreateAccount.Tag = ProjectInformation.NodeXLGraphGalleryCreateAccountUrl; // Instantiate an object that saves and retrieves the position of // this dialog. Note that the object automatically saves the settings // when the form closes. m_oExportToNodeXLGraphGalleryDialogUserSettings = new ExportToNodeXLGraphGalleryDialogUserSettings(this); DoDataExchange(false); AssertValid(); }
//************************************************************************* // Constructor: AutomateTasksDialog() // /// <summary> /// Initializes a new instance of the <see cref="AutomateTasksDialog" /> /// class. /// </summary> /// /// <param name="mode"> /// Indicates the mode in which the dialog is being used. /// </param> /// /// <param name="thisWorkbook"> /// Workbook containing the graph contents. /// </param> /// /// <param name="nodeXLControl"> /// The NodeXLControl object. This can be null if <paramref name="mode" /> /// is <see cref="DialogMode.EditOnly" />. /// </param> //************************************************************************* public AutomateTasksDialog ( DialogMode mode, ThisWorkbook thisWorkbook, NodeXLControl nodeXLControl ) { Debug.Assert(thisWorkbook != null); Debug.Assert(nodeXLControl != null || mode == DialogMode.EditOnly); m_eMode = mode; m_oAutomateTasksUserSettings = new AutomateTasksUserSettings(); m_oThisWorkbook = thisWorkbook; m_oNodeXLControl = nodeXLControl; m_bIgnoreItemCheckEvents = false; InitializeComponent(); if (m_eMode == DialogMode.EditOnly) { this.Text += " Options"; btnOK.Text = "OK"; } // Instantiate an object that saves and retrieves the user settings for // this dialog. Note that the object automatically saves the settings // when the form closes. m_oAutomateTasksDialogUserSettings = new AutomateTasksDialogUserSettings(this); PopulateTasksToRun(); DoDataExchange(false); AssertValid(); }
//************************************************************************* // Constructor: SelectSubgraphsDialog() // /// <overloads> /// Initializes a new instance of the <see cref="SelectSubgraphsDialog" /> /// class. /// </overloads> /// /// <summary> /// Initializes a new instance of the <see cref="SelectSubgraphsDialog" /> /// class with a NodeXLControl. /// </summary> /// /// <param name="nodeXLControl"> /// The NodeXLControl whose subgraphs should be selected. /// </param> /// /// <param name="clickedVertex"> /// Vertex that was clicked in the graph, or null if no vertex was clicked. /// </param> //************************************************************************* public SelectSubgraphsDialog ( NodeXLControl nodeXLControl, IVertex clickedVertex ) : this() { // Instantiate an object that retrieves and saves the user settings for // this dialog. Note that the object automatically saves the settings // when the form closes. m_oSelectSubgraphsDialogUserSettings = new SelectSubgraphsDialogUserSettings(this); m_oNodeXLControl = nodeXLControl; m_oClickedVertex = clickedVertex; m_aoInitiallySelectedVertices = nodeXLControl.SelectedVertices.ToArray(); DoDataExchange(false); AssertValid(); }
OnDynamicFilterColumnsChanged ( DynamicFilterDialog dynamicFilterDialog, DynamicFilterColumnsChangedEventArgs e, Microsoft.Office.Interop.Excel.Workbook workbook, NodeXLControl nodeXLControl, Dictionary<Int32, IIdentityProvider> edgeRowIDDictionary, Dictionary<Int32, IIdentityProvider> vertexRowIDDictionary ) { Debug.Assert(dynamicFilterDialog != null); Debug.Assert(e != null); Debug.Assert(workbook != null); Debug.Assert(nodeXLControl != null); Debug.Assert(edgeRowIDDictionary != null); Debug.Assert(vertexRowIDDictionary != null); if (e.DynamicFilterColumns == (DynamicFilterColumns.EdgeTable | DynamicFilterColumns.VertexTable) ) { ReadDynamicFilterColumns(dynamicFilterDialog, workbook, nodeXLControl, true, edgeRowIDDictionary, vertexRowIDDictionary ); } else if (e.DynamicFilterColumns == DynamicFilterColumns.EdgeTable) { ReadEdgeDynamicFilterColumn(dynamicFilterDialog, workbook, nodeXLControl, true, edgeRowIDDictionary); } else if (e.DynamicFilterColumns == DynamicFilterColumns.VertexTable) { ReadVertexDynamicFilterColumn(dynamicFilterDialog, workbook, nodeXLControl, true, vertexRowIDDictionary); } }
ReadDynamicFilterColumns ( DynamicFilterDialog dynamicFilterDialog, Microsoft.Office.Interop.Excel.Workbook workbook, NodeXLControl nodeXLControl, Boolean forceRedraw, Dictionary<Int32, IIdentityProvider> oEdgeRowIDDictionary, Dictionary<Int32, IIdentityProvider> oVertexRowIDDictionary ) { Debug.Assert(dynamicFilterDialog != null); Debug.Assert(workbook != null); Debug.Assert(nodeXLControl != null); Debug.Assert(oEdgeRowIDDictionary != null); Debug.Assert(oVertexRowIDDictionary != null); ReadEdgeDynamicFilterColumn(dynamicFilterDialog, workbook, nodeXLControl, false, oEdgeRowIDDictionary); ReadVertexDynamicFilterColumn(dynamicFilterDialog, workbook, nodeXLControl, forceRedraw, oVertexRowIDDictionary); }
CreateNodeXLControl() { // AssertValid(); // Control hierarchy: // // 1. ehElementHost contains a NodeXLWithAxesControl. // // 2. The NodeXLWithAxesControl contains a NodeXLControl. oNodeXLControl = new NodeXLControl(); m_oNodeXLWithAxesControl = new NodeXLWithAxesControl(oNodeXLControl); // Don't show the axes now. If they are supposed to be shown, the // Ribbon, which is responsible for maintaining the visibility of the // axes, will send a NoParamCommand.ShowGraphAxes command to the // TaskPane later. m_oNodeXLWithAxesControl.ShowAxes = false; oNodeXLControl.SelectionChanged += new System.EventHandler(this.oNodeXLControl_SelectionChanged); oNodeXLControl.VerticesMoved += new VerticesMovedEventHandler( this.oNodeXLControl_VerticesMoved); oNodeXLControl.GraphMouseUp += new GraphMouseButtonEventHandler( this.oNodeXLControl_GraphMouseUp); oNodeXLControl.LayingOutGraph += new System.EventHandler( this.oNodeXLControl_LayingOutGraph); oNodeXLControl.GraphLaidOut += new AsyncCompletedEventHandler( this.oNodeXLControl_GraphLaidOut); oNodeXLControl.KeyDown += new System.Windows.Input.KeyEventHandler( this.oNodeXLControl_KeyDown); ehNodeXLControlHost.Child = m_oNodeXLWithAxesControl; }
AddAttachmentsAndAlternateHtml ( MailMessage oMailMessage, Microsoft.Office.Interop.Excel.Workbook oWorkbook, NodeXLControl oNodeXLControl, Boolean bExportWorkbookAndSettings, Boolean bExportGraphML, Boolean bUseFixedAspectRatio ) { Debug.Assert(oMailMessage != null); Debug.Assert(oWorkbook != null); Debug.Assert(oNodeXLControl != null); Debug.Assert(oNodeXLControl.ActualWidth >= GraphExporterUtil.MinimumNodeXLControlWidth); Debug.Assert(oNodeXLControl.ActualHeight >= GraphExporterUtil.MinimumNodeXLControlHeight); AssertValid(); String sSuggestedFileNameNoExtension = GetSuggestedFileNameNoExtension(oWorkbook); String sGraphMLFileNameNoExtension = sSuggestedFileNameNoExtension + "-GraphML"; Byte [] abtFullSizeImage, abtThumbnail, abtWorkbookContents, abtGraphMLZipped; String sWorkbookSettings; GraphExporterUtil.GetDataToExport(oWorkbook, oNodeXLControl, bExportWorkbookAndSettings, bExportGraphML, Path.ChangeExtension(sGraphMLFileNameNoExtension, "xml"), bUseFixedAspectRatio, out abtFullSizeImage, out abtThumbnail, out abtWorkbookContents, out sWorkbookSettings, out abtGraphMLZipped); AddAttachments(oMailMessage, sSuggestedFileNameNoExtension, sGraphMLFileNameNoExtension, abtFullSizeImage, abtWorkbookContents, sWorkbookSettings, abtGraphMLZipped); AddAlternateHtml(oMailMessage, abtFullSizeImage); }
ExportToNodeXLGraphGallery ( Microsoft.Office.Interop.Excel.Workbook workbook, NodeXLControl nodeXLControl, String title, String description, String spaceDelimitedTags, String author, String password, Boolean exportWorkbookAndSettings, Boolean exportGraphML, Boolean useFixedAspectRatio ) { Debug.Assert(workbook != null); Debug.Assert(nodeXLControl != null); Debug.Assert(nodeXLControl.ActualWidth >= GraphExporterUtil.MinimumNodeXLControlWidth); Debug.Assert(nodeXLControl.ActualHeight >= GraphExporterUtil.MinimumNodeXLControlHeight); Debug.Assert( !String.IsNullOrEmpty(title) ); Debug.Assert( !String.IsNullOrEmpty(author) ); AssertValid(); Byte [] abtFullSizeImage, abtThumbnail, abtWorkbookContents, abtGraphML; String sWorkbookSettings; // Note that the name of the Zipped GraphML is not important. When a // user downloads the GraphML from the Graph Gallery website, the // website will rename the GraphML before giving it to the user. GraphExporterUtil.GetDataToExport(workbook, nodeXLControl, exportWorkbookAndSettings, exportGraphML, "GraphML.xml", useFixedAspectRatio, out abtFullSizeImage, out abtThumbnail, out abtWorkbookContents, out sWorkbookSettings, out abtGraphML); NodeXLGraphGalleryServiceClient oClient = new NodeXLGraphGalleryServiceClient(GetWcfServiceBinding(), new EndpointAddress( ProjectInformation.NodeXLGraphGalleryWcfServiceUrl) ); oClient.Endpoint.Binding.SendTimeout = new TimeSpan(0, SendTimeoutMinutes, 0); try { oClient.AddGraph4(title, author, password, description, spaceDelimitedTags, abtFullSizeImage, abtThumbnail, abtWorkbookContents, sWorkbookSettings, abtGraphML); } catch (ProtocolException oProtocolException) { // The following text search detects an exception thrown by the WCF // service when the exported byte count exceeds the maximum that // can be handled by the WCF service. // // This isn't a very robust test. Is there a better way to do // it? An earlier version attempted to calculate the number of // bytes that would be exported before attempting to export them, // but it didn't seem to be doing so accurately. // // See the MaximumBytes constant for more details. if (oProtocolException.Message.IndexOf("(400) Bad Request") >= 0) { throw new GraphTooLargeException(); } throw (oProtocolException); } }
TryExportToNodeXLGraphGallery ( Microsoft.Office.Interop.Excel.Workbook oWorkbook, NodeXLControl oNodeXLControl ) { Debug.Assert(oWorkbook != null); Debug.Assert(oNodeXLControl != null); ExportToNodeXLGraphGalleryUserSettings oExportToNodeXLGraphGalleryUserSettings = new ExportToNodeXLGraphGalleryUserSettings(); String sAuthor, sPassword; GetGraphGalleryAuthorAndPassword( oExportToNodeXLGraphGalleryUserSettings, out sAuthor, out sPassword); // Note that the workbook's name is used for the title, and a graph // summary is used for the description. Debug.Assert( !String.IsNullOrEmpty(oWorkbook.Name) ); try { ( new NodeXLGraphGalleryExporter() ).ExportToNodeXLGraphGallery( oWorkbook, oNodeXLControl, oWorkbook.Name, GraphSummarizer.SummarizeGraph(oWorkbook), oExportToNodeXLGraphGalleryUserSettings.SpaceDelimitedTags, sAuthor, sPassword, oExportToNodeXLGraphGalleryUserSettings .ExportWorkbookAndSettings, oExportToNodeXLGraphGalleryUserSettings.ExportGraphML, oExportToNodeXLGraphGalleryUserSettings.UseFixedAspectRatio ); return (true); } catch (Exception oException) { String sMessage; if ( NodeXLGraphGalleryExceptionHandler .TryGetMessageForRecognizedException( oException, out sMessage) ) { FormUtil.ShowWarning(sMessage); } else { ErrorUtil.OnException(oException); } return (false); } }
TryExportToEmail ( Microsoft.Office.Interop.Excel.Workbook oWorkbook, NodeXLControl oNodeXLControl ) { Debug.Assert(oWorkbook != null); Debug.Assert(oNodeXLControl != null); ExportToEmailUserSettings oExportToEmailUserSettings = new ExportToEmailUserSettings(); String sSmtpPassword = ( new PasswordUserSettings() ).SmtpPassword; if ( !ExportToEmailUserSettingsAreComplete( oExportToEmailUserSettings, sSmtpPassword) ) { FormUtil.ShowWarning( "The graph can't be exported to email because all required" + " email options haven't been specified yet. Go to NodeXL," + " Graph, Automate to fix this." ); return (false); } // Note that the workbook's name is used for the subject. Debug.Assert( !String.IsNullOrEmpty(oWorkbook.Name) ); try { ( new EmailExporter() ).ExportToEmail( oWorkbook, oNodeXLControl, oExportToEmailUserSettings.SpaceDelimitedToAddresses.Split(' '), oExportToEmailUserSettings.FromAddress, oWorkbook.Name, oExportToEmailUserSettings.MessageBody, oExportToEmailUserSettings.SmtpHost, oExportToEmailUserSettings.SmtpPort, oExportToEmailUserSettings.UseSslForSmtp, oExportToEmailUserSettings.SmtpUserName, sSmtpPassword, oExportToEmailUserSettings.ExportWorkbookAndSettings, oExportToEmailUserSettings.ExportGraphML, oExportToEmailUserSettings.UseFixedAspectRatio ); return (true); } catch (Exception oException) { String sMessage; if ( EmailExceptionHandler.TryGetMessageForRecognizedException( oException, out sMessage) ) { FormUtil.ShowWarning(sMessage); } else { ErrorUtil.OnException(oException); } return (false); } }
RunReadWorkbookTasks ( ThisWorkbook oThisWorkbook, NodeXLControl oNodeXLControl, AutomationTasks eTasksToRun, String sFolderToSaveWorkbookTo ) { Debug.Assert(oThisWorkbook != null); Debug.Assert(oNodeXLControl != null); Boolean bReadWorkbook = ShouldRunTask( eTasksToRun, AutomationTasks.ReadWorkbook); Boolean bSaveWorkbookIfNeverSaved = ShouldRunTask( eTasksToRun, AutomationTasks.SaveWorkbookIfNeverSaved); Boolean bSaveGraphImageFile = ShouldRunTask( eTasksToRun, AutomationTasks.SaveGraphImageFile); Boolean bExportToNodeXLGraphGallery = ShouldRunTask( eTasksToRun, AutomationTasks.ExportToNodeXLGraphGallery); Boolean bExportToEmail = ShouldRunTask( eTasksToRun, AutomationTasks.ExportToEmail); Microsoft.Office.Interop.Excel.Workbook oWorkbook = oThisWorkbook.InnerObject; if (bReadWorkbook) { // If the vertex X and Y columns were autofilled, the layout type // was set to LayoutType.Null. This will cause // TaskPane.ReadWorkbook() to display a warning. Temporarily turn // the warning off. Boolean bLayoutTypeIsNullNotificationsWereEnabled = EnableLayoutTypeIsNullNotifications(false); if ( bSaveWorkbookIfNeverSaved || bSaveGraphImageFile || bExportToNodeXLGraphGallery || bExportToEmail ) { // These tasks need to wait until the workbook is read and the // graph is laid out. EventHandler<GraphLaidOutEventArgs> oGraphLaidOutEventHandler = null; oGraphLaidOutEventHandler = delegate(Object sender, GraphLaidOutEventArgs e) { // This delegate remains forever, even when the dialog // class is destroyed. Prevent it from being called again. oThisWorkbook.GraphLaidOut -= oGraphLaidOutEventHandler; if (bSaveWorkbookIfNeverSaved) { if ( !TrySaveWorkbookIfNeverSaved(oWorkbook, sFolderToSaveWorkbookTo) ) { return; } } if (bSaveGraphImageFile) { Debug.Assert( !String.IsNullOrEmpty( oThisWorkbook.Path) ); SaveGraphImageFile(e.NodeXLControl, e.LegendControls, oThisWorkbook.FullName); } if (bExportToNodeXLGraphGallery) { if ( !TryExportToNodeXLGraphGallery( oThisWorkbook.InnerObject, oNodeXLControl) ) { return; } } if (bExportToEmail) { if ( !TryExportToEmail( oThisWorkbook.InnerObject, oNodeXLControl) ) { return; } } }; oThisWorkbook.GraphLaidOut += oGraphLaidOutEventHandler; } // Read the workbook and lay out the graph. CommandDispatcher.SendNoParamCommand(oThisWorkbook, NoParamCommand.ShowGraphAndReadWorkbook); EnableLayoutTypeIsNullNotifications( bLayoutTypeIsNullNotificationsWereEnabled); } else { if (bSaveWorkbookIfNeverSaved) { if ( !TrySaveWorkbookIfNeverSaved(oWorkbook, sFolderToSaveWorkbookTo) ) { return; } } } }
//************************************************************************* // Constructor: NodeXLWithAxesControl() // /// <summary> /// Initializes a new instance of the <see cref="NodeXLWithAxesControl" /> /// class with a specified <see cref="NodeXLControl" />. /// </summary> /// /// <param name="nodeXLControl"> /// The <see cref="NodeXLControl" /> to embed within the control. /// </param> //************************************************************************* public NodeXLWithAxesControl ( NodeXLControl nodeXLControl ) { Debug.Assert(nodeXLControl != null); m_oNodeXLControl = nodeXLControl; // Create a 1x1 grid. The y-axis is in (0,0), the x-axis is in (1,1), // the embedded NodeXLControl is in (0,1), and a Rectangle control is // in (1,0). // // The x-axis sizes itself vertically and the y-axis sizes itself // horizontally, so their row or column definition uses // GridLength.Auto. RowDefinitionCollection oRowDefinitions = this.RowDefinitions; oRowDefinitions.Add( new RowDefinition() ); RowDefinition oSecondRowDefinition = new RowDefinition(); oSecondRowDefinition.Height = GridLength.Auto; oRowDefinitions.Add(oSecondRowDefinition); ColumnDefinitionCollection oColumnDefinitions = this.ColumnDefinitions; ColumnDefinition oFirstColumnDefinition = new ColumnDefinition(); oFirstColumnDefinition.Width = GridLength.Auto; oColumnDefinitions.Add(oFirstColumnDefinition); oColumnDefinitions.Add( new ColumnDefinition() ); UIElementCollection oChildren = this.Children; Grid.SetColumn(m_oNodeXLControl, 1); oChildren.Add(m_oNodeXLControl); // The Rectangle in cell (1,0) exists only to cover up the // NodeXLControl's contents when it is zoomed, because the Grid does // not clip the NodeXLControl. What is the correct way to force the // Grid to clip the NodeXLControl's contents? Setting // NodeXLControl.ClipToBounds to true does not do anything. Rectangle oRectangle = new Rectangle(); oRectangle.Fill = SystemColors.WindowBrush; Grid.SetRow(oRectangle, 1); oChildren.Add(oRectangle); m_oXAxis = new Axis(); Grid.SetRow(m_oXAxis, 1); Grid.SetColumn(m_oXAxis, 1); oChildren.Add(m_oXAxis); m_oYAxis = new Axis(); m_oYAxis.IsXAxis = false; oChildren.Add(m_oYAxis); // Allow the Axis controls to adjust themselves when the graph is // zoomed or translated. m_oXAxis.DockedControlRenderTransform = m_oYAxis.DockedControlRenderTransform = m_oNodeXLControl.RenderTransform; m_oNodeXLControl.GraphZoomChanged += new EventHandler(this.m_oNodeXLControl_GraphZoomChanged); m_oNodeXLControl.GraphTranslationChanged += new EventHandler(this.m_oNodeXLControl_GraphTranslationChanged); AssertValid(); }
AutomateOneWorkbook ( ThisWorkbook thisWorkbook, NodeXLControl nodeXLControl, AutomationTasks tasksToRun, String folderToSaveWorkbookTo ) { Debug.Assert(thisWorkbook != null); Debug.Assert(nodeXLControl != null); CheckTasksToRunArgument(ref tasksToRun); Microsoft.Office.Interop.Excel.Workbook oWorkbook = thisWorkbook.InnerObject; if ( ( ShouldRunTask(tasksToRun, AutomationTasks.MergeDuplicateEdges) && !TryMergeDuplicateEdges(thisWorkbook) ) || ( ShouldRunTask(tasksToRun, AutomationTasks.CalculateClusters) && !TryCalculateClusters(thisWorkbook) ) || ( ShouldRunTask(tasksToRun, AutomationTasks.CalculateGraphMetrics) && !TryCalculateGraphMetrics(oWorkbook) ) || ( ShouldRunTask(tasksToRun, AutomationTasks.AutoFillWorkbook) && !TryAutoFillWorkbook(thisWorkbook) ) || ( ShouldRunTask(tasksToRun, AutomationTasks.CreateSubgraphImages) && !TryCreateSubgraphImages(thisWorkbook) ) ) { return; } RunReadWorkbookTasks(thisWorkbook, nodeXLControl, tasksToRun, folderToSaveWorkbookTo); }
SaveGraphImageFile ( NodeXLControl oNodeXLControl, IEnumerable<LegendControlBase> oLegendControls, String sWorkbookFilePath ) { Debug.Assert(oNodeXLControl != null); Debug.Assert(oLegendControls != null); Debug.Assert( !String.IsNullOrEmpty(sWorkbookFilePath) ); AutomatedGraphImageUserSettings oAutomatedGraphImageUserSettings = new AutomatedGraphImageUserSettings(); System.Drawing.Size oImageSizePx = oAutomatedGraphImageUserSettings.ImageSizePx; Int32 iWidth = oImageSizePx.Width; Int32 iHeight = oImageSizePx.Height; Boolean bIncludeHeader = oAutomatedGraphImageUserSettings.IncludeHeader; Boolean bIncludeFooter = oAutomatedGraphImageUserSettings.IncludeFooter; Debug.Assert(!bIncludeHeader || oAutomatedGraphImageUserSettings.HeaderText != null); Debug.Assert(!bIncludeFooter || oAutomatedGraphImageUserSettings.FooterText != null); GraphImageCompositor oGraphImageCompositor = new GraphImageCompositor(oNodeXLControl); UIElement oCompositeElement = oGraphImageCompositor.Composite( iWidth, iHeight, bIncludeHeader ? oAutomatedGraphImageUserSettings.HeaderText : null, bIncludeFooter ? oAutomatedGraphImageUserSettings.FooterText : null, oAutomatedGraphImageUserSettings.HeaderFooterFont, oLegendControls ); System.Drawing.Bitmap oBitmap = WpfGraphicsUtil.VisualToBitmap( oCompositeElement, iWidth, iHeight); ImageFormat eImageFormat = oAutomatedGraphImageUserSettings.ImageFormat; String sImageFilePath = Path.ChangeExtension( sWorkbookFilePath, SaveableImageFormats.GetFileExtension(eImageFormat) ); try { oBitmap.Save(sImageFilePath, eImageFormat); } catch (System.Runtime.InteropServices.ExternalException) { // When an image file already exists and is read-only, an // ExternalException is thrown. // // Note that this method is called from the // ThisWorkbook.GraphLaidOut event handler, so this exception can't // be handled by a TaskAutomator.AutomateOneWorkbook() exception // handler. FormUtil.ShowWarning( String.Format( "The image file \"{0}\" couldn't be saved. Does a read-only" + " file with the same name already exist?" , sImageFilePath ) ); } finally { oBitmap.Dispose(); oGraphImageCompositor.RestoreNodeXLControl(); } }
ShowDialogAndSaveGraphImage ( NodeXLControl nodeXLControl, Int32 width, Int32 height, String headerText, String footerText, System.Drawing.Font headerFooterFont, IEnumerable<LegendControlBase> legendControls ) { Debug.Assert(nodeXLControl != null); Debug.Assert(width > 0); Debug.Assert(height > 0); Debug.Assert(headerFooterFont != null); Debug.Assert(legendControls != null); AssertValid(); // Let the base class do most of the work. The actual saving will be // done by SaveObject() in this class. Wrap the information required // by SaveObject(). GraphImageInfo oGraphImageInfo = new GraphImageInfo(); oGraphImageInfo.NodeXLControl = nodeXLControl; oGraphImageInfo.Width = width; oGraphImageInfo.Height = height; oGraphImageInfo.HeaderText = headerText; oGraphImageInfo.FooterText = footerText; oGraphImageInfo.HeaderFooterFont = headerFooterFont; oGraphImageInfo.LegendControls = legendControls; return ( ShowDialogAndSaveObject(oGraphImageInfo) ); }
ReadDynamicFilterColumn ( DynamicFilterDialog oDynamicFilterDialog, Microsoft.Office.Interop.Excel.Workbook oWorkbook, NodeXLControl oNodeXLControl, String sWorksheetName, String sTableName, Dictionary<Int32, IIdentityProvider> oRowIDDictionary, HashSet<Int32> oFilteredIDs, EdgeOrVertexCanBeMadeVisibleHandler oOnEdgeOrVertexCanBeMadeVisible, EdgeOrVertexFilteredHandler oOnEdgeOrVertexFiltered, Boolean bForceRedraw ) { Debug.Assert(oDynamicFilterDialog != null); Debug.Assert(oWorkbook != null); Debug.Assert(oNodeXLControl != null); Debug.Assert( !String.IsNullOrEmpty(sWorksheetName) ); Debug.Assert( !String.IsNullOrEmpty(sTableName) ); Debug.Assert(oRowIDDictionary != null); Debug.Assert(oFilteredIDs != null); Debug.Assert(oOnEdgeOrVertexCanBeMadeVisible != null); Debug.Assert(oOnEdgeOrVertexFiltered != null); if (oNodeXLControl.IsLayingOutGraph) { return; } oFilteredIDs.Clear(); // The dynamic filter column on the edge or vertex table contains // Booleans indicating whether the edge or vertex should be made // visible. // Get the data in the ID and dynamic filter columns. Object [,] oIDColumnValues, oDynamicFilterColumnValues; if ( !TryGetIDAndDynamicFilterValues(oWorkbook, sWorksheetName, sTableName, out oIDColumnValues, out oDynamicFilterColumnValues) ) { return; } HashSet<Int32> oFilteredVertexIDs = GetFilteredVertexIDs(oDynamicFilterDialog); Int32 iRows = oIDColumnValues.GetUpperBound(0); Debug.Assert( iRows == oDynamicFilterColumnValues.GetUpperBound(0) ); for (Int32 iOneBasedRow = 1; iOneBasedRow <= iRows; iOneBasedRow++) { Object oID = oIDColumnValues[iOneBasedRow, 1]; Object oDynamicFilter = oDynamicFilterColumnValues[iOneBasedRow, 1]; IIdentityProvider oEdgeOrVertex; if ( oID is Double && oRowIDDictionary.TryGetValue( (Int32)(Double)oID, out oEdgeOrVertex ) && oDynamicFilter is Boolean ) { Debug.Assert(oEdgeOrVertex is IMetadataProvider); IMetadataProvider oEdgeOrVertex2 = (IMetadataProvider)oEdgeOrVertex; Boolean bMakeVisible = (Boolean)oDynamicFilter; if (!bMakeVisible) { oFilteredIDs.Add(oEdgeOrVertex.ID); } else if ( !oOnEdgeOrVertexCanBeMadeVisible( oEdgeOrVertex, GetFilteredEdgeIDs(oDynamicFilterDialog), oFilteredVertexIDs ) ) { bMakeVisible = false; } // Filter or make visible the edge or vertex, then call the // handler specified by the caller. DynamicallyFilterEdgeOrVertex(oEdgeOrVertex2, bMakeVisible); oOnEdgeOrVertexFiltered(oEdgeOrVertex2, bMakeVisible, oDynamicFilterDialog); } } if (bForceRedraw) { oNodeXLControl.DrawGraph(); } }
ReadVertexDynamicFilterColumn ( DynamicFilterDialog oDynamicFilterDialog, Microsoft.Office.Interop.Excel.Workbook oWorkbook, NodeXLControl oNodeXLControl, Boolean bForceRedraw, Dictionary<Int32, IIdentityProvider> oVertexRowIDDictionary ) { Debug.Assert(oDynamicFilterDialog != null); Debug.Assert(oWorkbook != null); Debug.Assert(oNodeXLControl != null); Debug.Assert(oVertexRowIDDictionary != null); ReadDynamicFilterColumn(oDynamicFilterDialog, oWorkbook, oNodeXLControl, WorksheetNames.Vertices, TableNames.Vertices, oVertexRowIDDictionary, GetFilteredVertexIDs(oDynamicFilterDialog), VertexCanBeMadeVisible, OnVertexFiltered, bForceRedraw); }
ReadFilteredAlpha ( DynamicFilterDialog dynamicFilterDialog, NodeXLControl nodeXLControl, Boolean forceRedraw ) { Debug.Assert(dynamicFilterDialog != null); Debug.Assert(nodeXLControl != null); nodeXLControl.FilteredAlpha = ( new AlphaConverter() ).WorkbookToGraphAsByte( dynamicFilterDialog.FilteredAlpha); if (forceRedraw) { nodeXLControl.DrawGraph(); } }