PageRenderTime 124ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/Tools/LinqPad/LINQPad/UI/SampleQueries.cs

https://github.com/vishalsh-spec/TestProject
C# | 826 lines | 778 code | 48 blank | 0 comment | 122 complexity | 90e1472b61c7c517916968385356f3c6 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.0, Apache-2.0
  1. namespace LINQPad.UI
  2. {
  3. using Ionic.Zip;
  4. using LINQPad;
  5. using LINQPad.ObjectModel;
  6. using LINQPad.Properties;
  7. using System;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Diagnostics;
  12. using System.Drawing;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Net;
  16. using System.Reflection;
  17. using System.Runtime.CompilerServices;
  18. using System.Text.RegularExpressions;
  19. using System.Threading;
  20. using System.Windows.Forms;
  21. using System.Xml.Linq;
  22. internal class SampleQueries : TreeView
  23. {
  24. private TreeNode _mouseDownNode;
  25. private static Random _random = new Random();
  26. private Dictionary<string, TreeNode> _samplesByName = new Dictionary<string, TreeNode>();
  27. private static Regex _sortPrefixWithBrackets = new Regex(@"^\[[0-9\.]+\]\s*");
  28. private bool _unshown = true;
  29. private IContainer components;
  30. private ImageList imageList;
  31. public SampleQueries()
  32. {
  33. this.Font = FontManager.GetDefaultFont();
  34. this.InitializeComponent();
  35. base.ImageList = TreeViewHelper.UpscaleImages(this.Font, this.imageList);
  36. }
  37. private void DownloadSamples(string uri, string libName)
  38. {
  39. string tempPath = Path.Combine(Path.GetTempPath(), @"LINQPad\TempSampleQueries" + _random.Next(0xf4240) + ".zip");
  40. BackgroundWorker worker = new BackgroundWorker {
  41. WorkerSupportsCancellation = true,
  42. WorkerReportsProgress = true
  43. };
  44. worker.DoWork += delegate (object sender, DoWorkEventArgs e) {
  45. string path = Path.GetDirectoryName(tempPath);
  46. if (!Directory.Exists(path))
  47. {
  48. Directory.CreateDirectory(path);
  49. }
  50. WebClient webClient = WebHelper.GetWebClient();
  51. webClient.DownloadProgressChanged += delegate (object sender, DownloadProgressChangedEventArgs e) {
  52. if (worker.IsBusy)
  53. {
  54. worker.ReportProgress(e.ProgressPercentage);
  55. }
  56. };
  57. webClient.DownloadFileAsync(new Uri(uri), tempPath);
  58. while (webClient.IsBusy)
  59. {
  60. if (worker.CancellationPending)
  61. {
  62. webClient.CancelAsync();
  63. break;
  64. }
  65. Thread.Sleep(100);
  66. }
  67. };
  68. using (WorkerForm form = new WorkerForm(worker, "Downloading...", true))
  69. {
  70. if (form.ShowDialog() != DialogResult.OK)
  71. {
  72. return;
  73. }
  74. }
  75. try
  76. {
  77. if (string.IsNullOrEmpty(libName))
  78. {
  79. try
  80. {
  81. libName = Path.GetFileNameWithoutExtension(new Uri(uri).Segments.Last<string>());
  82. }
  83. catch
  84. {
  85. }
  86. }
  87. if (this.UnzipFile(tempPath, libName))
  88. {
  89. MessageBox.Show("Samples successfully loaded.", "LINQPad", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  90. }
  91. }
  92. catch (Exception exception)
  93. {
  94. Log.Write(exception, "Unzip samples");
  95. MessageBox.Show("Error while unpacking sample queries: " + exception.Message, "LINQPad", MessageBoxButtons.OK, MessageBoxIcon.Hand);
  96. }
  97. }
  98. internal TreeNode FindByID(string id)
  99. {
  100. if (this._unshown)
  101. {
  102. this._unshown = false;
  103. this.LoadData();
  104. }
  105. return this.FindByID(base.Nodes, id);
  106. }
  107. private TreeNode FindByID(TreeNodeCollection nodes, string id)
  108. {
  109. QueryNode node = nodes.OfType<QueryNode>().FirstOrDefault<QueryNode>(n => n.ID == id);
  110. if (node != null)
  111. {
  112. return node;
  113. }
  114. foreach (DirectoryNode node3 in nodes.OfType<DirectoryNode>())
  115. {
  116. if (node3.Nodes.Count == 0)
  117. {
  118. return null;
  119. }
  120. TreeNode node4 = this.FindByID(node3.Nodes, id);
  121. if (node4 != null)
  122. {
  123. return node4;
  124. }
  125. }
  126. return null;
  127. }
  128. internal IEnumerable<RunnableQuery> GetAllQueries(TreeNodeCollection nodes)
  129. {
  130. return new <GetAllQueries>d__12(-2) { <>4__this = this, <>3__nodes = nodes };
  131. }
  132. private TreeNode GetDirectoryNode(TreeNodeCollection nodes, string path)
  133. {
  134. while (true)
  135. {
  136. string[] strArray = path.Split(new char[] { '/' }, 2);
  137. string text = _sortPrefixWithBrackets.Replace(strArray[0], "");
  138. TreeNode node = nodes[text];
  139. if (node == null)
  140. {
  141. node = new ThirdPartyDirectoryNode(text);
  142. if (nodes == base.Nodes)
  143. {
  144. base.Nodes.Insert(base.Nodes.Count - 2, node);
  145. }
  146. else
  147. {
  148. nodes.Add(node);
  149. }
  150. }
  151. if (!strArray[1].Contains("/"))
  152. {
  153. return node;
  154. }
  155. nodes = node.Nodes;
  156. path = strArray[1];
  157. }
  158. }
  159. private void InitializeComponent()
  160. {
  161. this.components = new Container();
  162. ComponentResourceManager manager = new ComponentResourceManager(typeof(MyQueries));
  163. this.imageList = new ImageList(this.components);
  164. base.SuspendLayout();
  165. this.imageList.ImageStream = (ImageListStreamer) manager.GetObject("imageList.ImageStream");
  166. this.imageList.TransparentColor = Color.Transparent;
  167. this.imageList.Images.SetKeyName(0, "Folder");
  168. this.imageList.Images.SetKeyName(1, "FolderOpen");
  169. this.imageList.Images.SetKeyName(2, "Query");
  170. this.imageList.Images.SetKeyName(3, "Add");
  171. base.HideSelection = false;
  172. base.ResumeLayout(false);
  173. }
  174. private void Load(TreeNodeCollection parent, string name, string id, string content)
  175. {
  176. name = name.Substring(3);
  177. int num = name.Count<char>(c => c == '.');
  178. if (num != 0)
  179. {
  180. if (num == 1)
  181. {
  182. QueryNode node = new QueryNode(Path.GetFileNameWithoutExtension(name), content, id);
  183. parent.Add(node);
  184. }
  185. else
  186. {
  187. string[] strArray = name.Split(new char[] { '.' }, 2);
  188. TreeNode node2 = parent[strArray[0]];
  189. if (node2 == null)
  190. {
  191. node2 = new DirectoryNode(strArray[0]);
  192. parent.Add(node2);
  193. }
  194. this.Load(node2.Nodes, strArray[1], id, content);
  195. }
  196. }
  197. }
  198. private void Load3rdPartyData()
  199. {
  200. string path = Path.Combine(Program.UserDataFolder, "Samples");
  201. if (Directory.Exists(path))
  202. {
  203. foreach (string str2 in Directory.GetDirectories(path))
  204. {
  205. string str3 = Path.Combine(str2, "queries.zip");
  206. if (File.Exists(str3))
  207. {
  208. try
  209. {
  210. this.Load3rdPartySamples(str3);
  211. }
  212. catch (Exception exception)
  213. {
  214. Log.Write(exception, "SampleQueries Load3rdPartyData");
  215. }
  216. }
  217. }
  218. }
  219. }
  220. private void Load3rdPartySamples(string target)
  221. {
  222. if (File.Exists(target))
  223. {
  224. string name = new DirectoryInfo(Path.GetDirectoryName(target)).Name;
  225. if (base.Nodes[name] != null)
  226. {
  227. base.Nodes.Remove(base.Nodes[name]);
  228. }
  229. using (ZipFile file = new ZipFile(target))
  230. {
  231. foreach (ZipEntry entry in from i in file
  232. where !i.get_IsDirectory() && (Path.GetExtension(i.get_FileName()).ToLowerInvariant() == ".linq")
  233. orderby ImportedSampleQuery.Get3rdPartySort(i.get_FileName().ToUpperInvariant())
  234. select i)
  235. {
  236. this.GetDirectoryNode(base.Nodes, name + "/" + entry.get_FileName()).Nodes.Add(new ThirdPartyQueryNode(ImportedSampleQuery.Get3rdPartyFileName(entry.get_FileName()), target, entry.get_FileName()));
  237. }
  238. }
  239. }
  240. }
  241. private void LoadData()
  242. {
  243. string samplesPrefix = "LINQPad.SampleQueries4.";
  244. Assembly assembly = base.GetType().Assembly;
  245. foreach (string str in from s in assembly.GetManifestResourceNames()
  246. where s.StartsWith(samplesPrefix, StringComparison.Ordinal)
  247. orderby s
  248. select s)
  249. {
  250. using (Stream stream = assembly.GetManifestResourceStream(str))
  251. {
  252. this.Load(base.Nodes, str.Substring(samplesPrefix.Length).Replace("_", " ").Replace("POINT", "\x00b7").Replace("CSharp", "C#").Replace("FSharp", "F#").Replace("HYPHEN", "-").Replace("BANG", "!"), str, new StreamReader(stream).ReadToEnd());
  253. }
  254. }
  255. base.Nodes.Add(new BrowseLibrariesNode());
  256. base.Nodes.Add(new SearchSamplesNode());
  257. this.Load3rdPartyData();
  258. }
  259. protected override void OnAfterCollapse(TreeViewEventArgs e)
  260. {
  261. e.Node.ImageKey = e.Node.SelectedImageKey = "Folder";
  262. base.OnAfterCollapse(e);
  263. }
  264. protected override void OnAfterExpand(TreeViewEventArgs e)
  265. {
  266. e.Node.ImageKey = e.Node.SelectedImageKey = "FolderOpen";
  267. base.OnAfterExpand(e);
  268. }
  269. protected override void OnMouseDown(MouseEventArgs e)
  270. {
  271. this._mouseDownNode = base.GetNodeAt(e.X, e.Y);
  272. base.OnMouseDown(e);
  273. }
  274. protected override void OnMouseLeave(EventArgs e)
  275. {
  276. this.Cursor = Cursors.Default;
  277. base.OnMouseLeave(e);
  278. }
  279. protected override void OnMouseMove(MouseEventArgs e)
  280. {
  281. TreeNode nodeAt = base.GetNodeAt(e.Location);
  282. Cursor hand = Cursors.Default;
  283. if ((nodeAt != null) && (nodeAt.NodeFont == SchemaTree.UnderlineFont))
  284. {
  285. hand = Cursors.Hand;
  286. }
  287. if (this.Cursor != hand)
  288. {
  289. this.Cursor = hand;
  290. }
  291. base.OnMouseMove(e);
  292. }
  293. protected override void OnMouseUp(MouseEventArgs e)
  294. {
  295. base.OnMouseUp(e);
  296. this._mouseDownNode = null;
  297. }
  298. protected override void OnNodeMouseClick(TreeNodeMouseClickEventArgs e)
  299. {
  300. EventHandler onClick = null;
  301. if ((e.Node is BrowseLibrariesNode) && (e.Button == MouseButtons.Left))
  302. {
  303. using (BrowseSamplesForm form = new BrowseSamplesForm())
  304. {
  305. if (form.ShowDialog() == DialogResult.OK)
  306. {
  307. this.DownloadSamples(form.SamplesUri, form.LibraryName);
  308. }
  309. }
  310. }
  311. if ((e.Node is SearchSamplesNode) && (e.Button == MouseButtons.Left))
  312. {
  313. using (SearchQueries queries = new SearchQueries(true))
  314. {
  315. queries.ShowDialog(MainForm.Instance);
  316. }
  317. }
  318. if (e.Button == MouseButtons.Right)
  319. {
  320. ToolStripItemClickedEventHandler handler2 = null;
  321. base.SelectedNode = e.Node;
  322. ContextMenuStrip m = new ContextMenuStrip();
  323. if ((e.Node is ThirdPartyDirectoryNode) && (e.Node.Parent == null))
  324. {
  325. if (onClick == null)
  326. {
  327. onClick = delegate (object sender, EventArgs e) {
  328. string str = Path.Combine(Program.UserDataFolder, @"Samples\" + e.Node.Text);
  329. string path = Path.Combine(str, "queries.zip");
  330. try
  331. {
  332. File.Delete(path);
  333. Directory.Delete(str, true);
  334. }
  335. catch
  336. {
  337. }
  338. this.Nodes.Remove(e.Node);
  339. };
  340. }
  341. m.Items.Add("Delete", Resources.Delete, onClick);
  342. }
  343. if (m.Items.Count > 0)
  344. {
  345. m.Show(this, e.Location);
  346. if (handler2 == null)
  347. {
  348. handler2 = (sender, e) => m.Dispose();
  349. }
  350. m.ItemClicked += handler2;
  351. }
  352. }
  353. base.OnNodeMouseClick(e);
  354. }
  355. protected override void OnNodeMouseDoubleClick(TreeNodeMouseClickEventArgs e)
  356. {
  357. if (e.Node == this._mouseDownNode)
  358. {
  359. base.OnNodeMouseDoubleClick(e);
  360. }
  361. }
  362. protected override void OnVisibleChanged(EventArgs e)
  363. {
  364. if (base.Visible && this._unshown)
  365. {
  366. this._unshown = false;
  367. if (!base.DesignMode)
  368. {
  369. this.LoadData();
  370. }
  371. }
  372. base.OnVisibleChanged(e);
  373. }
  374. internal void RefreshThirdPartySamples(string name)
  375. {
  376. this.Load3rdPartySamples(Path.Combine(Program.UserDataFolder, @"Samples\" + name + @"\queries.zip"));
  377. }
  378. private bool UnzipFile(string tempZipPath, string libName)
  379. {
  380. ZipFile file;
  381. bool flag2;
  382. string _name = libName;
  383. using (file = new ZipFile(tempZipPath))
  384. {
  385. ZipEntry entry = file.get_Item("header.xml");
  386. if (entry != null)
  387. {
  388. MemoryStream stream = new MemoryStream();
  389. entry.Extract(stream);
  390. stream.Position = 0L;
  391. string str = (string) XElement.Load(new StreamReader(stream)).Element("Name");
  392. if (!string.IsNullOrEmpty(str))
  393. {
  394. _name = str;
  395. }
  396. }
  397. }
  398. if (string.IsNullOrEmpty(_name))
  399. {
  400. MessageBox.Show("Sample library metadata file header.xml is not present or missing the Name element.", "LINQPad", MessageBoxButtons.OK, MessageBoxIcon.Hand);
  401. return false;
  402. }
  403. _name = _name.Trim();
  404. new Thread(delegate {
  405. try
  406. {
  407. WebHelper.GetWebClient().DownloadString("http://www.linqpad.net/RichClient/GetSample.aspx?lib=" + Uri.EscapeDataString(_name));
  408. }
  409. catch
  410. {
  411. }
  412. }) { IsBackground = true, Priority = ThreadPriority.Lowest, Name = "GetSample" }.Start();
  413. string targetFolder = Path.Combine(Program.UserDataFolder, @"Samples\" + _name);
  414. string path = Path.Combine(targetFolder, "queries.zip");
  415. if (File.Exists(path))
  416. {
  417. if (MessageBox.Show("This library has already been downloaded. Overwrite?", "LINQPad", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  418. {
  419. return false;
  420. }
  421. new FileInfo(path).IsReadOnly = false;
  422. }
  423. else if (!Directory.Exists(targetFolder))
  424. {
  425. Directory.CreateDirectory(targetFolder);
  426. }
  427. WorkingForm form = new WorkingForm("Extracting files...", 0x1388);
  428. form.Show();
  429. form.Update();
  430. try
  431. {
  432. File.Copy(tempZipPath, path, true);
  433. List<FileRetryForm.FileActionInfo> actions = new List<FileRetryForm.FileActionInfo>();
  434. using (file = new ZipFile(path))
  435. {
  436. foreach (ZipEntry entry2 in file)
  437. {
  438. if (!((entry2.get_IsDirectory() || entry2.get_LocalFileName().Contains("/")) || entry2.get_LocalFileName().ToLowerInvariant().EndsWith(".linq")))
  439. {
  440. ZipEntry localEntry = entry2;
  441. actions.Add(new FileRetryForm.FileActionInfo(localEntry.get_FileName(), delegate {
  442. localEntry.Extract(targetFolder, true);
  443. }));
  444. }
  445. }
  446. flag2 = FileRetryForm.TryProcessFiles(actions, new Action(form.Close));
  447. }
  448. }
  449. finally
  450. {
  451. form.Close();
  452. }
  453. try
  454. {
  455. if (File.Exists(tempZipPath))
  456. {
  457. File.Delete(tempZipPath);
  458. }
  459. }
  460. catch
  461. {
  462. }
  463. if (!string.IsNullOrEmpty(_name))
  464. {
  465. MainForm.Instance.RefreshThirdPartySamples(_name);
  466. }
  467. return flag2;
  468. }
  469. internal void UpdateSelection(QueryCore query)
  470. {
  471. if (((query == null) || !query.Predefined) || (query.UISource == null))
  472. {
  473. if (base.SelectedNode != null)
  474. {
  475. base.SelectedNode = null;
  476. }
  477. }
  478. else
  479. {
  480. QueryNode uISource = query.UISource as QueryNode;
  481. if (((uISource != base.SelectedNode) && (uISource != null)) && (base.SelectedNode != uISource))
  482. {
  483. base.SelectedNode = uISource;
  484. }
  485. }
  486. }
  487. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  488. public override System.Drawing.Font Font
  489. {
  490. get
  491. {
  492. return base.Font;
  493. }
  494. set
  495. {
  496. base.Font = value;
  497. }
  498. }
  499. [CompilerGenerated]
  500. private sealed class <GetAllQueries>d__12 : IEnumerable<RunnableQuery>, IEnumerable, IEnumerator<RunnableQuery>, IEnumerator, IDisposable
  501. {
  502. private bool $__disposing;
  503. private int <>1__state;
  504. private RunnableQuery <>2__current;
  505. public TreeNodeCollection <>3__nodes;
  506. public SampleQueries <>4__this;
  507. public IEnumerator<SampleQueries.QueryNode> <>7__wrap17;
  508. public IEnumerator<SampleQueries.DirectoryNode> <>7__wrap18;
  509. public IEnumerator<RunnableQuery> <>7__wrap19;
  510. private int <>l__initialThreadId;
  511. public SampleQueries.QueryNode <node>5__13;
  512. public SampleQueries.DirectoryNode <node>5__15;
  513. public RunnableQuery <q>5__14;
  514. public RunnableQuery <query>5__16;
  515. public SampleQueries.<>c__DisplayClass10 CS$<>8__locals11;
  516. public Func<char, bool> CS$<>9__CachedAnonymousMethodDelegatef;
  517. public TreeNodeCollection nodes;
  518. [DebuggerHidden]
  519. public <GetAllQueries>d__12(int <>1__state)
  520. {
  521. this.<>1__state = <>1__state;
  522. this.<>l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
  523. }
  524. private bool MoveNext()
  525. {
  526. try
  527. {
  528. int num;
  529. bool flag = true;
  530. switch (this.<>1__state)
  531. {
  532. case 1:
  533. break;
  534. case 2:
  535. goto Label_0191;
  536. case -1:
  537. return false;
  538. default:
  539. if (this.$__disposing)
  540. {
  541. return false;
  542. }
  543. this.CS$<>9__CachedAnonymousMethodDelegatef = null;
  544. this.CS$<>8__locals11 = new SampleQueries.<>c__DisplayClass10();
  545. this.CS$<>8__locals11.invalidChars = new HashSet<char>(Path.GetInvalidFileNameChars());
  546. this.<>7__wrap17 = this.nodes.OfType<SampleQueries.QueryNode>().GetEnumerator();
  547. break;
  548. }
  549. try
  550. {
  551. num = this.<>1__state;
  552. if (num == 1)
  553. {
  554. if (this.$__disposing)
  555. {
  556. return false;
  557. }
  558. this.<>1__state = 0;
  559. }
  560. if (this.<>7__wrap17.MoveNext())
  561. {
  562. this.<node>5__13 = this.<>7__wrap17.Current;
  563. this.<q>5__14 = new RunnableQuery();
  564. this.<q>5__14.OpenSample(this.<node>5__13.Name, this.<node>5__13.Content);
  565. if (this.CS$<>9__CachedAnonymousMethodDelegatef == null)
  566. {
  567. this.CS$<>9__CachedAnonymousMethodDelegatef = new Func<char, bool>(this.CS$<>8__locals11.<GetAllQueries>b__e);
  568. }
  569. this.<q>5__14.Name = new string(this.<node>5__13.Text.Where<char>(this.CS$<>9__CachedAnonymousMethodDelegatef).ToArray<char>());
  570. this.<>2__current = this.<q>5__14;
  571. this.<>1__state = 1;
  572. flag = false;
  573. return true;
  574. }
  575. }
  576. finally
  577. {
  578. if (flag && (this.<>7__wrap17 != null))
  579. {
  580. this.<>7__wrap17.Dispose();
  581. }
  582. }
  583. this.<>7__wrap18 = this.nodes.OfType<SampleQueries.DirectoryNode>().GetEnumerator();
  584. Label_0191:
  585. try
  586. {
  587. num = this.<>1__state;
  588. if (num != 2)
  589. {
  590. goto Label_025B;
  591. }
  592. Label_01A2:
  593. try
  594. {
  595. num = this.<>1__state;
  596. if (num == 2)
  597. {
  598. if (this.$__disposing)
  599. {
  600. return false;
  601. }
  602. this.<>1__state = 0;
  603. }
  604. if (!this.<>7__wrap19.MoveNext())
  605. {
  606. goto Label_025B;
  607. }
  608. this.<query>5__16 = this.<>7__wrap19.Current;
  609. this.<>2__current = this.<query>5__16;
  610. this.<>1__state = 2;
  611. flag = false;
  612. return true;
  613. }
  614. finally
  615. {
  616. if (flag && (this.<>7__wrap19 != null))
  617. {
  618. this.<>7__wrap19.Dispose();
  619. }
  620. }
  621. Label_0224:
  622. this.<node>5__15 = this.<>7__wrap18.Current;
  623. this.<>7__wrap19 = this.<>4__this.GetAllQueries(this.<node>5__15.Nodes).GetEnumerator();
  624. goto Label_01A2;
  625. Label_025B:
  626. if (this.<>7__wrap18.MoveNext())
  627. {
  628. goto Label_0224;
  629. }
  630. }
  631. finally
  632. {
  633. if (flag && (this.<>7__wrap18 != null))
  634. {
  635. this.<>7__wrap18.Dispose();
  636. }
  637. }
  638. }
  639. catch (Exception)
  640. {
  641. this.<>1__state = -1;
  642. throw;
  643. }
  644. this.<>1__state = -1;
  645. return false;
  646. }
  647. [DebuggerHidden]
  648. IEnumerator<RunnableQuery> IEnumerable<RunnableQuery>.GetEnumerator()
  649. {
  650. SampleQueries.<GetAllQueries>d__12 d__;
  651. if ((Thread.CurrentThread.ManagedThreadId == this.<>l__initialThreadId) && (this.<>1__state == -2))
  652. {
  653. this.<>1__state = 0;
  654. d__ = this;
  655. }
  656. else
  657. {
  658. d__ = new SampleQueries.<GetAllQueries>d__12(0) {
  659. <>4__this = this.<>4__this
  660. };
  661. }
  662. d__.nodes = this.<>3__nodes;
  663. return d__;
  664. }
  665. [DebuggerHidden]
  666. IEnumerator IEnumerable.GetEnumerator()
  667. {
  668. return this.System.Collections.Generic.IEnumerable<LINQPad.RunnableQuery>.GetEnumerator();
  669. }
  670. [DebuggerHidden]
  671. void IEnumerator.Reset()
  672. {
  673. throw new NotSupportedException();
  674. }
  675. [DebuggerHidden]
  676. void IDisposable.Dispose()
  677. {
  678. this.$__disposing = true;
  679. this.MoveNext();
  680. this.<>1__state = -1;
  681. }
  682. RunnableQuery IEnumerator<RunnableQuery>.Current
  683. {
  684. [DebuggerHidden]
  685. get
  686. {
  687. return this.<>2__current;
  688. }
  689. }
  690. object IEnumerator.Current
  691. {
  692. [DebuggerHidden]
  693. get
  694. {
  695. return this.<>2__current;
  696. }
  697. }
  698. }
  699. private class BrowseLibrariesNode : TreeNode
  700. {
  701. public BrowseLibrariesNode() : base("Download more samples...")
  702. {
  703. base.NodeFont = SchemaTree.UnderlineFont;
  704. base.ForeColor = SystemColors.HotTrack;
  705. base.ImageKey = base.SelectedImageKey = "Add";
  706. }
  707. }
  708. private class DirectoryNode : TreeNode
  709. {
  710. public DirectoryNode(string text) : base(text.Replace('\x00b7', '.').Trim())
  711. {
  712. base.ImageKey = base.SelectedImageKey = "Folder";
  713. base.Name = text;
  714. }
  715. }
  716. public class QueryNode : TreeNode
  717. {
  718. private string _content;
  719. public readonly string ID;
  720. public QueryNode(string text, string content, string id) : base(text.Replace('\x00b7', '.').Trim())
  721. {
  722. this._content = content;
  723. this.ID = id;
  724. base.ImageKey = base.SelectedImageKey = "Query";
  725. }
  726. public virtual string Content
  727. {
  728. get
  729. {
  730. return this._content;
  731. }
  732. }
  733. }
  734. private class SearchSamplesNode : TreeNode
  735. {
  736. public SearchSamplesNode() : base("Search samples...")
  737. {
  738. base.NodeFont = SchemaTree.UnderlineFont;
  739. base.ForeColor = SystemColors.HotTrack;
  740. base.ImageKey = base.SelectedImageKey = "Add";
  741. }
  742. }
  743. private class ThirdPartyDirectoryNode : SampleQueries.DirectoryNode
  744. {
  745. public ThirdPartyDirectoryNode(string text) : base(text)
  746. {
  747. }
  748. }
  749. public class ThirdPartyQueryNode : SampleQueries.QueryNode
  750. {
  751. private string _content;
  752. private string _pathWithinZip;
  753. private string _zipFilePath;
  754. public ThirdPartyQueryNode(string text, string zipFilePath, string pathWithinZip) : base(text, null, zipFilePath + "/" + pathWithinZip)
  755. {
  756. this._zipFilePath = zipFilePath;
  757. this._pathWithinZip = pathWithinZip;
  758. }
  759. public override string Content
  760. {
  761. get
  762. {
  763. if (this._content == null)
  764. {
  765. MemoryStream stream = new MemoryStream();
  766. using (ZipFile file = new ZipFile(this._zipFilePath))
  767. {
  768. file.get_Item(this._pathWithinZip).Extract(stream);
  769. }
  770. stream.Position = 0L;
  771. this._content = new StreamReader(stream).ReadToEnd();
  772. }
  773. return this._content;
  774. }
  775. }
  776. }
  777. }
  778. }