-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojectDownload.cs
65 lines (59 loc) · 2.09 KB
/
projectDownload.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Xml;
using CONTROLBUILDERLib;
namespace Fin
{
public class projectDownload
{
public void projectTree()
{
CBOpenIF cb = null;
string folderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Project");
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
Console.WriteLine($"Creating directory at {folderPath}");
}
try
{
Console.WriteLine("Initializing CONTROLBUILDERLib...");
cb = new CBOpenIF();
// Retrieve project tree and gather individual controller data
string projectTree = cb.GetProjectTree("", -1, false);
Console.WriteLine("Project tree retrieved successfully.");
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(projectTree);
string projectTreePath = Path.Combine(folderPath, "ProjectTree.xml");
xmlDoc.Save(projectTreePath);
Console.WriteLine($"Saved project tree to: {projectTreePath}");
}
catch (COMException ex)
{
Console.WriteLine($"COM Error: {ex.Message}");
Console.WriteLine($"Error Code: 0x{ex.ErrorCode:X}");
}
catch (Exception ex)
{
Console.WriteLine($"General Error: {ex.Message}");
Console.WriteLine($"Stack Trace: {ex.StackTrace}");
}
finally
{
if (cb != null)
{
Marshal.ReleaseComObject(cb);
cb = null;
Console.WriteLine("Released COM object.");
}
Console.WriteLine("\nProcess complete. Check log file for details.");
}
}
}
}