Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
uses: Malcolmnixon/Setup-VSTest@v4

- name : Test
run: vstest.console GraphLayout\Test\MSAGLTests\bin\Debug\net6.0-windows\Microsoft.Msagl.UnitTests.dll
run: vstest.console GraphLayout\Test\MSAGLTests\bin\Debug\net8.0-windows\Microsoft.Msagl.UnitTests.dll
2 changes: 2 additions & 0 deletions GraphLayout/Samples/LoadingDgmlGraph/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@


using System;
using Microsoft.Msagl.Drawing;
using Microsoft.Msagl.Layout.Incremental;
using Microsoft.Msagl.Layout.Layered;
using Microsoft.Msagl.Layout.MDS;

namespace LoadingDgmlGraph {
class Program {
[STAThread]
static void Main(string[] args) {
Microsoft.Msagl.GraphViewerGdi.DisplayGeometryGraph.SetShowFunctions();
//create a form
Expand Down
2 changes: 1 addition & 1 deletion GraphLayout/Test/MSAGLTests/MSAGLTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<LangVersion>latest</LangVersion>

<AssemblyName>Microsoft.Msagl.UnitTests</AssemblyName>
Expand Down
69 changes: 46 additions & 23 deletions GraphLayout/Test/TestFormForGViewer/FormStuff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
using System;
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using DgmlParser;
using Dot2Graph;
using Microsoft.Msagl.Drawing;
using Microsoft.Msagl.GraphViewerGdi;
Expand All @@ -41,7 +42,7 @@ public class FormStuff {
protected static GViewer GViewer;

public static Form CreateOrAttachForm(GViewer gviewer, Form form) {
GViewer=gviewer;
GViewer = gviewer;
if (form == null)
form = new Form();
form.SuspendLayout();
Expand All @@ -58,13 +59,13 @@ public static Form CreateOrAttachForm(GViewer gviewer, Form form) {
return form;
}

static void form_Load(object sender,EventArgs e) {
((Form) sender).Focus();
static void form_Load(object sender, EventArgs e) {
((Form)sender).Focus();
}


static MenuStrip GetMainMenuStrip() {
var menu=new MenuStrip();
var menu = new MenuStrip();
menu.Items.Add(FileStripItem());

return menu;
Expand All @@ -73,7 +74,7 @@ static MenuStrip GetMainMenuStrip() {

static ToolStripItem FileStripItem() {
var item = new ToolStripMenuItem("File");
item.DropDownItems.Add((ToolStripItem) OpenDotFileItem());
item.DropDownItems.Add((ToolStripItem)OpenDotFileItem());
item.DropDownItems.Add(ReloadDotFileItem());
return item;
}
Expand All @@ -86,8 +87,8 @@ static ToolStripItem ReloadDotFileItem() {
}

static void ReloadFileClick(object sender, EventArgs e) {
if(lastFileName!=null)
ReadGraphFromFile(lastFileName, GViewer, false);
if (lastFileName != null)
ReadGraphFromFile(lastFileName, GViewer, false);
}

static ToolStripItem OpenDotFileItem() {
Expand All @@ -101,7 +102,7 @@ static void OpenFileClick(object sender, EventArgs e) {

var openFileDialog = new OpenFileDialog {
RestoreDirectory = true,
Filter = "DOT (*.dot,*.gv)|*.dot;*.gv| All(*.*)|*.*"
Filter = "MSAGL Files(*.msagl)|*.msagl|DOT (*.dot,*.gv)|*.dot;*.gv|DGML Files(*.dgml)|*.dgml|All(*.*)|*.*"
};

if (openFileDialog.ShowDialog() == DialogResult.OK)
Expand All @@ -110,24 +111,46 @@ static void OpenFileClick(object sender, EventArgs e) {

internal static Graph CreateDrawingGraphFromFile(string fileName, out int line, out int column, out bool msaglFile) {
string msg;
var graph = Parser.Parse(fileName, out line, out column, out msg);
if (graph != null) {
msaglFile = false;
return graph;
Graph graph = null;
msaglFile = false;
line = column = 0;

// Get extension
string ext = Path.GetExtension(fileName);
switch (ext.ToLower()) {
case ".dgml":
try {
graph = DgmlParser.DgmlParser.Parse(fileName);
line = column = 0;
return graph;
}
catch (Exception) {
System.Diagnostics.Debug.WriteLine("cannot read " + fileName);
}
Comment on lines +127 to +129
Copy link
Preview

Copilot AI Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching generic Exception without re-throwing or proper error handling can mask important errors. Consider catching specific exceptions or logging more detailed error information for debugging.

Copilot uses AI. Check for mistakes.

break;
case ".dot":
case ".gv":
graph = Parser.Parse(fileName, out line, out column, out msg);
if (graph != null) {
return graph;
}
break;
case ".msagl":
default:
Copy link
Preview

Copilot AI Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default case assumes MSAGL format for unknown extensions, which may not be intuitive. Consider adding explicit handling for .msagl extension and making the default case more explicit about fallback behavior.

Copilot uses AI. Check for mistakes.

try {
graph = Graph.Read(fileName);
msaglFile = true;
return graph;
}
catch (Exception) {
System.Diagnostics.Debug.WriteLine("cannot read " + fileName);
}
Comment on lines +145 to +147
Copy link
Preview

Copilot AI Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching generic Exception without re-throwing or proper error handling can mask important errors. Consider catching specific exceptions or logging more detailed error information for debugging.

Copilot uses AI. Check for mistakes.

break;
}

try {
graph = Graph.Read(fileName);
msaglFile = true;
return graph;
} catch (Exception) {
System.Diagnostics.Debug.WriteLine("cannot read " + fileName);
}
msaglFile = false;
return null;
return graph;
Copy link
Preview

Copilot AI Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function can return null when all parsing attempts fail, but the method signature doesn't indicate this possibility. Consider returning a default empty graph or updating the method signature to make the nullable return explicit.

Suggested change
return graph;
return graph ?? new Graph();

Copilot uses AI. Check for mistakes.

}


public static void ReadGraphFromFile(string fileName, GViewer gViewer, bool verbose) {
int eLine, eColumn;
bool msaglFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<ItemGroup>
<ProjectReference Include="..\..\Drawing\AutomaticGraphLayout.Drawing.csproj" />
<ProjectReference Include="..\..\tools\DgmlParser\DgmlParser.csproj" />
<ProjectReference Include="..\..\tools\GraphViewerGDI\GraphViewerGDI.csproj" />
<ProjectReference Include="..\..\MSAGL\AutomaticGraphLayout.csproj" />
<ProjectReference Include="..\..\tools\Dot2Graph\Dot2Graph.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion GraphLayout/Test/TestGraphmaps/TestGraphmaps.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>WinExe</OutputType>
<RootNamespace>TestGraphmaps</RootNamespace>
<AssemblyName>TestGraphmaps</AssemblyName>
<TargetFrameworks>net6.0-windows</TargetFrameworks>
<TargetFrameworks>net8.0-windows</TargetFrameworks>
<UseWPF>true</UseWPF>
<NoWarn>CS8618;CS8603</NoWarn>

Expand Down
Loading