private void _samplesTreeView_AfterSelect(object sender, TreeViewEventArgs e) { this.SuspendLayout(); NuGenTreeNode treeNode = e.Node as NuGenTreeNode; if (treeNode != null) { SampleDescriptor sampleDescriptor = treeNode.Tag as SampleDescriptor; if (sampleDescriptor != null) { _runButton.Enabled = sampleDescriptor.ExeIsAvailable; _csSampleButton.Enabled = sampleDescriptor.CsProjectIsAvailable; _vbSampleButton.Enabled = sampleDescriptor.VbProjectIsAvailable; _browseButton.Enabled = sampleDescriptor.SamplePath != null; _exePath = sampleDescriptor.ExePath; _csProjectPath = sampleDescriptor.CsProjectPath; _vbProjectPath = sampleDescriptor.VbProjectPath; _samplePath = sampleDescriptor.SamplePath; if (sampleDescriptor.DescriptionIsAvailable) { using (StreamReader sr = new StreamReader(sampleDescriptor.DescriptionPath)) { try { _descriptionTextBox.Text = sr.ReadToEnd(); } catch (IOException) { _descriptionTextBox.Text = ""; } catch (OutOfMemoryException) { _descriptionTextBox.Text = ""; } } } if (sampleDescriptor.ImageIsAvailable) { if (_imagePictureBox.Image != null) { _imagePictureBox.Image.Dispose(); _imagePictureBox.Image = null; } _imagePictureBox.Image = Image.FromFile(sampleDescriptor.ImagePath); } } } this.ResumeLayout(); }
private void BuildSampleTreeNode( ISampleFolderDescriptor sampleFolderDescriptor , DirectoryInfo sampleDirInfo , NuGenTreeNode treeNode , int folderImageIndex , int expandedFolderImageIndex , int sampleImageIndex ) { Debug.Assert(sampleFolderDescriptor != null, "sampleFolder != null"); Debug.Assert(sampleDirInfo != null, "sampleDirInfo != null"); Debug.Assert(treeNode != null, "treeNode != null"); string samplePath = null; string descriptionPath = null; string screenShotPath = null; string exePath = null; string csProjectPath = null; string vbProjectPath = null; /* * Algorithm: * Get description if available. * Get screen-shot if available. * Get the list of folders. * If CS folder exists, search for *.csproj file inside. And EXE in bin/Debug or bin/Release as well. * If VB folder exists, search for *.vbproj file inside. And EXE in bin/Debug or bin/Release if CS project does not exist. * Call this method recursively for other folders. */ FileInfo descriptionFileInfo = new FileInfo(Path.Combine(sampleDirInfo.FullName, sampleFolderDescriptor.DescriptionFileName)); if (descriptionFileInfo.Exists) { descriptionPath = descriptionFileInfo.FullName; } Debug.WriteLine("descriptionPath = " + descriptionPath); FileInfo screenShotFileInfo = new FileInfo(Path.Combine(sampleDirInfo.FullName, sampleFolderDescriptor.ScreenshotFileName)); if (screenShotFileInfo.Exists) { screenShotPath = screenShotFileInfo.FullName; } Debug.WriteLine("screenShotPath = " + screenShotPath); if (!string.IsNullOrEmpty(descriptionPath) && !string.IsNullOrEmpty(screenShotPath)) { samplePath = sampleDirInfo.FullName; } Debug.WriteLine("samplePath = " + samplePath); DirectoryInfo[] subDirInfoCollection = sampleDirInfo.GetDirectories(); Debug.WriteLine("Getting the list of sub-directories..."); Debug.WriteLineIf(subDirInfoCollection != null, "subDirInfoCollection.Length = " + subDirInfoCollection.Length.ToString()); if (subDirInfoCollection != null) { Debug.WriteLine("Looping through the sub-directories..."); foreach (DirectoryInfo subDirInfo in subDirInfoCollection) { if (subDirInfo.Name == sampleFolderDescriptor.CSProjectFolderName) { Debug.WriteLine("CS project folder found."); csProjectPath = this.GetProjectPath(subDirInfo, sampleFolderDescriptor.CSProjectExtension); Debug.WriteLine("csProjectPath = " + csProjectPath); if (exePath == null) { exePath = this.FindExe(Path.GetDirectoryName(csProjectPath)); } Debug.WriteLine("exePath = " + exePath); } else if (subDirInfo.Name == sampleFolderDescriptor.VBProjectFolderName) { Debug.WriteLine("VB project folder found."); vbProjectPath = this.GetProjectPath(subDirInfo, sampleFolderDescriptor.VBProjectExtension); Debug.WriteLine("vbProjectPath = " + vbProjectPath); if (exePath == null) { exePath = this.FindExe(Path.GetDirectoryName(vbProjectPath)); } Debug.WriteLine("exePath = " + exePath); } else { NuGenTreeNode childNode = treeNode; if (this.ShouldCreateSubFolder(sampleFolderDescriptor, subDirInfo)) { childNode = new NuGenTreeNode(subDirInfo.Name, folderImageIndex, expandedFolderImageIndex); treeNode.Nodes.Add(childNode); } this.BuildSampleTreeNode(sampleFolderDescriptor, subDirInfo, childNode, folderImageIndex, expandedFolderImageIndex, sampleImageIndex); } } } if (samplePath != null) { SampleDescriptor sampleDescriptor = new SampleDescriptor( samplePath , descriptionPath , screenShotPath , exePath , csProjectPath , vbProjectPath ); Debug.WriteLine("Creating a node with a sample descriptor assigned to the Tag property..."); NuGenTreeNode sampleNode = new NuGenTreeNode(sampleDirInfo.Name, sampleImageIndex, sampleImageIndex); sampleNode.Tag = sampleDescriptor; Debug.WriteLine("Adding the node to the parent node..."); treeNode.Nodes.Add(sampleNode); } }
private void BuildSampleTreeNode( ISampleFolderDescriptor sampleFolderDescriptor , DirectoryInfo sampleDirInfo , NuGenTreeNode treeNode , int folderImageIndex , int expandedFolderImageIndex , int sampleImageIndex ) { Debug.Assert(sampleFolderDescriptor != null, "sampleFolder != null"); Debug.Assert(sampleDirInfo != null, "sampleDirInfo != null"); Debug.Assert(treeNode != null, "treeNode != null"); string samplePath = null; string descriptionPath = null; string screenShotPath = null; string exePath = null; string csProjectPath = null; string vbProjectPath = null; /* * Algorithm: * Get description if available. * Get screen-shot if available. * Get the list of folders. * If CS folder exists, search for *.csproj file inside. And EXE in bin/Debug or bin/Release as well. * If VB folder exists, search for *.vbproj file inside. And EXE in bin/Debug or bin/Release if CS project does not exist. * Call this method recursively for other folders. */ FileInfo descriptionFileInfo = new FileInfo(Path.Combine(sampleDirInfo.FullName, sampleFolderDescriptor.DescriptionFileName)); if (descriptionFileInfo.Exists) { descriptionPath = descriptionFileInfo.FullName; } Debug.WriteLine("descriptionPath = " + descriptionPath); FileInfo screenShotFileInfo = new FileInfo(Path.Combine(sampleDirInfo.FullName, sampleFolderDescriptor.ScreenshotFileName)); if (screenShotFileInfo.Exists) { screenShotPath = screenShotFileInfo.FullName; } Debug.WriteLine("screenShotPath = " + screenShotPath); if (!string.IsNullOrEmpty(descriptionPath) && !string.IsNullOrEmpty(screenShotPath)) { samplePath = sampleDirInfo.FullName; } Debug.WriteLine("samplePath = " + samplePath); DirectoryInfo[] subDirInfoCollection = sampleDirInfo.GetDirectories(); Debug.WriteLine("Getting the list of sub-directories..."); Debug.WriteLineIf(subDirInfoCollection != null, "subDirInfoCollection.Length = " + subDirInfoCollection.Length.ToString()); if (subDirInfoCollection != null) { Debug.WriteLine("Looping through the sub-directories..."); foreach (DirectoryInfo subDirInfo in subDirInfoCollection) { if (subDirInfo.Name == sampleFolderDescriptor.CSProjectFolderName) { Debug.WriteLine("CS project folder found."); csProjectPath = this.GetProjectPath(subDirInfo, sampleFolderDescriptor.CSProjectExtension); Debug.WriteLine("csProjectPath = " + csProjectPath); if (exePath == null) { exePath = this.FindExe(Path.GetDirectoryName(csProjectPath)); } Debug.WriteLine("exePath = " + exePath); } else if (subDirInfo.Name == sampleFolderDescriptor.VBProjectFolderName) { Debug.WriteLine("VB project folder found."); vbProjectPath = this.GetProjectPath(subDirInfo, sampleFolderDescriptor.VBProjectExtension); Debug.WriteLine("vbProjectPath = " + vbProjectPath); if (exePath == null) { exePath = this.FindExe(Path.GetDirectoryName(vbProjectPath)); } Debug.WriteLine("exePath = " + exePath); } else { NuGenTreeNode childNode = treeNode; if (this.ShouldCreateSubFolder(sampleFolderDescriptor, subDirInfo)) { childNode = new NuGenTreeNode(subDirInfo.Name, folderImageIndex, expandedFolderImageIndex); treeNode.Nodes.Add(childNode); } this.BuildSampleTreeNode(sampleFolderDescriptor, subDirInfo, childNode, folderImageIndex, expandedFolderImageIndex, sampleImageIndex); } } } if (samplePath != null) { SampleDescriptor sampleDescriptor = new SampleDescriptor( samplePath , descriptionPath , screenShotPath , exePath , csProjectPath , vbProjectPath ); Debug.WriteLine("Creating a node with a sample descriptor assigned to the Tag property..."); NuGenTreeNode sampleNode = new NuGenTreeNode(sampleDirInfo.Name, sampleImageIndex, sampleImageIndex); sampleNode.Tag = sampleDescriptor; Debug.WriteLine("Adding the node to the parent node..."); treeNode.Nodes.Add(sampleNode); } }