PageRenderTime 151ms CodeModel.GetById 61ms app.highlight 49ms RepoModel.GetById 31ms app.codeStats 1ms

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