-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProjectsList.xaml.cs
More file actions
314 lines (283 loc) · 10.9 KB
/
ProjectsList.xaml.cs
File metadata and controls
314 lines (283 loc) · 10.9 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Windows.Forms;
using System.Diagnostics;
using System.Collections.ObjectModel;
using Microsoft.WindowsAPICodePack.Shell;
using System.Xml;
using System.Xml.Linq;
namespace PM
{
public partial class ProjectsList : System.Windows.Controls.UserControl
{
/*
* Global variable for the Project (folder) selected
*/
public ProjectFiles SelectedProject { get; set; }
/*
* Constructor for the project list
*/
public ProjectsList()
{
DataContext = this;
InitializeComponent();
}
/*
* Establishing what each project (file) consists of
*/
public class ProjectFiles
{
public string Title { get; set; }
public string FullPath { get; set; }
public System.IO.FileAttributes Attr { get; set; }
public DateTime AccsTime { get; set; }
public BitmapSource Icon { get; set; }
public BitmapSource RenderedImg { get; set; }
public int BeaconCount { get; set; }
public int Progress { get; set; }
}
/* Updates the listview to show the files in the current directory */
private void updateFiles(string proj = null)
{
Random rnd = new Random();
if (String.IsNullOrEmpty(proj) || proj == "Please Select")
{
proj = projectSelect.SelectedItem as string;
if (String.IsNullOrEmpty(proj) || proj == "Please Select")
{
listView33.ItemsSource = null;
return;
}
}
ObservableCollection<ProjectFiles> lopf = new ObservableCollection<ProjectFiles>();
var fileNames = Directory.GetFiles(proj, "*.rvt");
foreach (string fn in fileNames)
{
FileInfo fi = new FileInfo(fn);
var sysicon = System.Drawing.Icon.ExtractAssociatedIcon(fi.FullName);
var bmpSrc = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
sysicon.Handle,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
sysicon.Dispose();
ShellFile sf = ShellFile.FromFilePath(fi.FullName);
//sf.Thumbnail.FormatOption = ShellThumbnailFormatOption.ThumbnailOnly;
var renderedImg = sf.Thumbnail.ExtraLargeBitmapSource;
var bc = 0;
try
{
Console.WriteLine("Trying to load XML for {0}......", fi.Name);
XDocument objDoc = XDocument.Load(fi.FullName.Replace(".rvt", ".xml"));
if (objDoc.Descendants("BeaconFamily").Any())
{
foreach (var fam in objDoc.Descendants("BeaconFamily"))
{
string famName = fam.Value;
foreach (var BType in fam.Descendants("BeaconType"))
{
string typeName = BType.Value;
if (BType.Descendants("Instance").Any())
{
foreach (var BInstance in BType.Descendants("Instance"))
{
++bc;
XElement height = BInstance.Element("BeaconHeight");
XElement level = BInstance.Element("BeaconLevel");
}
}
else { Console.WriteLine("No instances of {0} in {1}", typeName, fi.Name); }
}
}
}
else { Console.WriteLine("No BeaconFamily in {0}", fi.Name); }
}
catch (FileNotFoundException)
{
Console.WriteLine("Error Finding XML");
}
lopf.Add(new ProjectFiles() { Title = fi.Name, FullPath = fi.FullName, Attr = fi.Attributes, AccsTime = fi.LastWriteTime, Icon = bmpSrc, RenderedImg = renderedImg, BeaconCount = bc, Progress = rnd.Next(0, 100) });
}
listView33.ItemsSource = lopf;
}
/*
* Event Handler to show all files in the folder when the "See All Files" button is clicked
*/
private void SeeAllFiles_Click(object sender, RoutedEventArgs e)
{
lbFiles.Items.Clear();
string proj;
proj = projectSelect.SelectedItem as string;
if (String.IsNullOrEmpty(proj) || proj == "Please Select")
{
return;
}
var fileNames = Directory.GetFiles(proj, "*");
foreach (string fn in fileNames)
{
FileInfo fi = new FileInfo(fn);
lbFiles.Items.Add(fi.Name);
}
}
/*
* Opens up the Revit file when the users double click the item.
*/
private void ListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (sender != null)
{
System.Windows.Controls.ListBox lb = (System.Windows.Controls.ListBox)sender;
ProjectFiles p = (ProjectFiles)lb.SelectedItem;
if (p != null)
{
Process.Start(p.FullPath);
updateLastOpenedFile(p);
}
}
updateFiles();
}
/*
* Update the panel on the right hand side to show most recently selected file
*/
private void updateMostRecentFile(ProjectFiles p)
{
RFImage.Source = p.RenderedImg;
RFLabel1.Content = p.Title;
RFLabel2.Content = p.AccsTime;
//RFLabel3.Content = p.Progress;
RFLabel4.Content = String.Format("Number of Beacons: {0}", p.BeaconCount);
pbStatus.Value = p.Progress;
}
/*
* Update the panel on the right hand side to show most recently opened file
*/
private void updateLastOpenedFile(ProjectFiles p)
{
Pooplabel1.Content = p.Title;
}
/*
* opens the file when users click on the open button
*/
private void OpenButton_Click(object sender, RoutedEventArgs e)
{
if (sender != null)
{
System.Windows.Controls.Button btn = (System.Windows.Controls.Button)sender;
ProjectFiles p = btn.DataContext as ProjectFiles;
Process.Start(p.FullPath);
updateLastOpenedFile(p);
}
updateFiles();
}
/*
* Deletes the file when users click on the delete button
*/
private void DeleteButton_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);
if (messageBoxResult == MessageBoxResult.Yes)
{
try
{
System.Windows.Controls.Button btn = (System.Windows.Controls.Button)sender;
ProjectFiles p = btn.DataContext as ProjectFiles;
File.Delete(p.FullPath);
}
catch (IOException iox)
{
Console.WriteLine(iox.Message);
}
}
updateFiles();
}
/*
* Event handler for project select
*/
private void projectSelect_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// ... Get the ComboBox.
var comboBox = sender as System.Windows.Controls.ComboBox;
// ... Set SelectedItem as Window Title.
string value = comboBox.SelectedItem as string;
updateFiles(value);
}
/*
* loads the project select
*/
private void projectSelect_Loaded(object sender, RoutedEventArgs e)
{
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string[] subdirectories = Directory.GetDirectories(desktop);
List<string> data = new List<string>();
data.Add("Please Select");
data.AddRange(subdirectories);
// ... Get the ComboBox reference.
var comboBox = sender as System.Windows.Controls.ComboBox;
// ... Assign the ItemsSource to the List.
comboBox.ItemsSource = data;
// ... Make the first item selected.
comboBox.SelectedIndex = 0;
}
/*
* Event handler for project selection changed
*/
private void listView33_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender != null)
{
System.Windows.Controls.ListBox lb = (System.Windows.Controls.ListBox)sender;
ProjectFiles p = (ProjectFiles)lb.SelectedItem;
if (p != null)
{
updateMostRecentFile(p);
SelectedProject = p;
}
}
}
/*
* Event handler for adding new Revit file to project folder, needs improvement
* TODO: Make the file usable
*/
private void AddToProject_Click(object sender, RoutedEventArgs e)
{
string proj;
proj = projectSelect.SelectedItem as string;
if (String.IsNullOrEmpty(proj) || proj == "Please Select")
{
System.Windows.MessageBox.Show("Please Select a Project!");
}
else
{
var fn = NewFileName.Text;
if (fn == null)
{
fn = System.IO.Path.GetRandomFileName();
}
try
{
File.Create(proj + @"\" + fn + ".rvt");
updateFiles();
}
catch
{
System.Windows.MessageBox.Show("Error", "Cannot Create File!");
}
}
}
private void lbFiles_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
}
}