Skip to content

Commit

Permalink
feat: added support for xtis that contain PLCs
Browse files Browse the repository at this point in the history
  • Loading branch information
iadonkey committed Feb 11, 2024
1 parent 3315526 commit 9a36d71
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion TwinpackShared/Models/Plc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public Plc(string name, string filepath)
throw new FileNotFoundException($"PLC {filepath} could not be found in workspace");

Name = name;
FilePath = filepath;
FilePath = Path.GetFullPath(filepath);
}

public string Name { get; private set; } = null;
Expand Down
17 changes: 17 additions & 0 deletions TwinpackShared/Models/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ public Project(string name, string filepath)
Plcs = content?.Root?.Elements("Project")?.Elements("Plc")?.Elements("Project")
.Where(x => x.Attribute("Name")?.Value != null && x.Attribute("PrjFilePath")?.Value != null)
.Select(x => new Plc(x.Attribute("Name")?.Value, $@"{directory}\{x.Attribute("PrjFilePath")?.Value}")).ToList();

var xtis = content?.Root?.Elements("Project")?.Elements("Plc")?.Elements("Project")
.Where(x => x.Attribute("File")?.Value != null)
.Select(x => $"{directory}\\_Config\\PLC\\" + x.Attribute("File")?.Value).ToList();

foreach(var xti in xtis)
{
if (!File.Exists(xti))
throw new FileNotFoundException($"XTI {xti} could not be found in workspace");

content = XDocument.Load(xti);
directory = new FileInfo(xti).Directory.FullName;

Plcs = Plcs.Concat(content?.Root?.Elements("Project")?
.Where(x => x.Attribute("Name")?.Value != null && x.Attribute("PrjFilePath")?.Value != null)
.Select(x => new Plc(x.Attribute("Name")?.Value, $@"{directory}\{x.Attribute("PrjFilePath")?.Value}"))).ToList();
}
}

public string Name { get; private set; } = null;
Expand Down

0 comments on commit 9a36d71

Please sign in to comment.