-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathAppPackageForm.cs
167 lines (142 loc) · 5.81 KB
/
AppPackageForm.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace AutoCADIODemo
{
public partial class AppPackageForm : Form
{
Dictionary<String, String> _packageDetails = new Dictionary<string, string>();
Dictionary<String, String> listedCommands = new Dictionary<string, string>();
String _packageId = String.Empty;
String _resource = String.Empty;
public AppPackageForm()
{
InitializeComponent();
}
private void AppPackageForm_Load(object sender, EventArgs e)
{
LoadPackagesList();
}
private void LoadPackagesList()
{
_packageDetails = Autodesk.AcadIOUtils.GetAppPackageDetails();
AppPackagesList.Items.Clear();
foreach (KeyValuePair<String, String> kp in _packageDetails)
{
AppPackagesList.Items.Add(kp.Key);
}
if (AppPackagesList.Items.Count > 0)
AppPackagesList.SelectedIndex = 0;
else
{
PackageIdText.Text = "";
ResourceText.Text = "";
ListedCommandsText.Text = "";
}
}
private void AppPackagesList_SelectedIndexChanged(object sender, EventArgs e)
{
int index = AppPackagesList.SelectedIndex;
if (index > -1 && index < _packageDetails.Count)
{
String key = AppPackagesList.SelectedItem.ToString();
_packageId = key;
String value = _packageDetails[key];
_resource = value;
PackageIdText.Text = _packageId;
ResourceText.Text = _resource;
if (listedCommands.ContainsKey(key))
{
ListedCommandsText.Text = listedCommands[key];
}
else
{
String appPackageResource = _resource;
if (String.IsNullOrEmpty(appPackageResource) == false)
{
String localFilePath = String.Empty;
if (Autodesk.GeneralUtils.Download(appPackageResource, ref localFilePath))
{
StringCollection localCommands = new StringCollection();
StringCollection globalCommands = new StringCollection();
// Identify the commands listed in the downloaded bundle
Autodesk.GeneralUtils.FindListedCommands(localFilePath, ref localCommands, ref globalCommands);
StringBuilder commandsList = new StringBuilder();
foreach (String localCmd in localCommands)
{
commandsList.Append(localCmd);
commandsList.Append(Environment.NewLine);
}
listedCommands.Add(key, commandsList.ToString());
ListedCommandsText.Text = listedCommands[key];
}
}
}
}
}
private void DownloadPackageBtn_Click(object sender, EventArgs e)
{
String appPackageResource = ResourceText.Text;
if (String.IsNullOrEmpty(appPackageResource) == false)
{
String localFilePath = String.Empty;
if (Autodesk.GeneralUtils.Download(appPackageResource, ref localFilePath))
{
System.Windows.Forms.MessageBox.Show(String.Format("AppPackage downloaded to {0}", localFilePath));
}
else
{
System.Windows.Forms.MessageBox.Show(String.Format("Sorry, could not downloaded AppPackage from {0}", appPackageResource));
}
}
}
private void NewPackageBtn_Click(object sender, EventArgs e)
{
String packageId = PackageIdText.Text;
if (String.IsNullOrEmpty(packageId))
{
System.Windows.Forms.MessageBox.Show(String.Format("Please provide an id for the package"));
return;
}
if (bundleFolderBrowseDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Cursor.Current = Cursors.WaitCursor;
String packageZipFilePath = String.Empty;
String bundleFolderPath = bundleFolderBrowseDialog.SelectedPath;
if (Autodesk.AcadIOUtils.CreateAppPackageFromBundle(packageId, bundleFolderPath))
{// App Package created ok
LoadPackagesList();
}
else
{
Cursor.Current = Cursors.Default;
System.Windows.Forms.MessageBox.Show("Sorry, could not create new app package.");
}
Cursor.Current = Cursors.Default;
}
}
private void DeletePackageBtn_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(_packageId))
{
Cursor.Current = Cursors.WaitCursor;
if (Autodesk.AcadIOUtils.DeletePackage(_packageId))
LoadPackagesList();
else
{
Cursor.Current = Cursors.Default;
System.Windows.Forms.MessageBox.Show("Sorry, could not delete app package.");
}
Cursor.Current = Cursors.Default;
}
}
}
}