Пример #1
0
        public void AddChildSampleFile(SampleFileEntry childSampleFile)
        {
            if (null == childSampleFiles)
            {
                childSampleFiles = new List <SampleFileEntry>();
            }

            childSampleFiles.Add(childSampleFile);
        }
Пример #2
0
        internal void WalkDirectoryTree(System.IO.DirectoryInfo root, SampleFileEntry rootProperty)
        {
            try
            {
                // First try to get all the sub-directories before the files themselves.
                System.IO.DirectoryInfo[] directories = root.GetDirectories();
                if (null != directories && (directories.Length > 0))
                {
                    foreach (System.IO.DirectoryInfo directory in directories)
                    {
                        //Make sure the folder's name is not "backup"
                        if (!directory.Name.Equals(Configurations.BackupFolderName))
                        {
                            // Resursive call for each subdirectory.
                            SampleFileEntry sampleFileEntry =
                                new SampleFileEntry(directory.Name, directory.FullName);
                            WalkDirectoryTree(directory, sampleFileEntry);
                            rootProperty.AddChildSampleFile(sampleFileEntry);
                        }
                    }
                }

                // Secondly, process all the files directly under this folder
                System.IO.FileInfo[] dynamoFiles = null;
                dynamoFiles = root.GetFiles("*.dyn", System.IO.SearchOption.TopDirectoryOnly);

                if (null != dynamoFiles && (dynamoFiles.Length > 0))
                {
                    foreach (System.IO.FileInfo file in dynamoFiles)
                    {
                        if (sampleFolderPath == null)
                        {
                            sampleFolderPath = Path.GetDirectoryName(file.FullName);
                        }
                        // Add each file under the root directory property list.
                        rootProperty.AddChildSampleFile(new SampleFileEntry(file.Name, file.FullName));
                    }
                }
            }
            catch (Exception)
            {
                // Perhaps some permission problems?
            }
        }
Пример #3
0
        /// <summary>
        ///     Setup the "Samples" sub-menu with contents of samples directory.
        /// </summary>
        private void LoadSamplesMenu()
        {
            var samplesDirectory = dynamoViewModel.Model.PathManager.SamplesDirectory;
            if (Directory.Exists(samplesDirectory))
            {
                var sampleFiles = new System.Collections.Generic.List<string>();
                string[] dirPaths = Directory.GetDirectories(samplesDirectory);
                string[] filePaths = Directory.GetFiles(samplesDirectory, "*.dyn");

                // handle top-level files
                if (filePaths.Any())
                {
                    foreach (string path in filePaths)
                    {
                        var item = new MenuItem
                        {
                            Header = Path.GetFileNameWithoutExtension(path),
                            Tag = path
                        };
                        item.Click += OpenSample_Click;
                        SamplesMenu.Items.Add(item);
                        sampleFiles.Add(path);
                    }
                }

                // handle top-level dirs, TODO - factor out to a seperate function, make recusive
                if (dirPaths.Any())
                {
                    foreach (string dirPath in dirPaths)
                    {
                        var dirItem = new MenuItem
                        {
                            Header = Path.GetFileName(dirPath),
                            Tag = Path.GetFileName(dirPath)
                        };

                        filePaths = Directory.GetFiles(dirPath, "*.dyn");
                        if (filePaths.Any())
                        {
                            foreach (string path in filePaths)
                            {
                                var item = new MenuItem
                                {
                                    Header = Path.GetFileNameWithoutExtension(path),
                                    Tag = path
                                };
                                item.Click += OpenSample_Click;
                                dirItem.Items.Add(item);
                                sampleFiles.Add(path);
                            }
                        }
                        SamplesMenu.Items.Add(dirItem);
                    }
                }

                if (dirPaths.Any())
                {
                    var showInFolder = new MenuItem
                    {
                        Header = Wpf.Properties.Resources.DynamoViewHelpMenuShowInFolder,
                        Tag = dirPaths[0]
                    };
                    showInFolder.Click += OnShowInFolder;
                    SamplesMenu.Items.Add(new Separator());
                    SamplesMenu.Items.Add(showInFolder);
                }

                if (sampleFiles.Any() && startPage != null)
                {
                    var firstFilePath = Path.GetDirectoryName(sampleFiles.ToArray()[0]);
                    var rootPath = Path.GetDirectoryName(firstFilePath);
                    var root = new DirectoryInfo(rootPath);
                    var rootProperty = new SampleFileEntry("Samples", "Path");
                    startPage.WalkDirectoryTree(root, rootProperty);
                    startPage.SampleFiles.Add(rootProperty);
                }
            }
        }
Пример #4
0
        public void AddChildSampleFile(SampleFileEntry childSampleFile)
        {
            if (null == childSampleFiles)
                childSampleFiles = new List<SampleFileEntry>();

            childSampleFiles.Add(childSampleFile);
        }
Пример #5
0
        internal void WalkDirectoryTree(System.IO.DirectoryInfo root, SampleFileEntry rootProperty)
        {
            try
            {
                // First try to get all the sub-directories before the files themselves.
                System.IO.DirectoryInfo[] directories = root.GetDirectories();
                if (null != directories && (directories.Length > 0))
                {
                    foreach (System.IO.DirectoryInfo directory in directories)
                    {
                        // Resursive call for each subdirectory.
                        SampleFileEntry subProperty = 
                            new SampleFileEntry(directory.Name, directory.FullName);
                        WalkDirectoryTree(directory, subProperty);
                        rootProperty.AddChildSampleFile(subProperty);
                    }
                }

                // Secondly, process all the files directly under this folder 
                System.IO.FileInfo[] dynamoFiles = null;
                dynamoFiles = root.GetFiles("*.dyn", System.IO.SearchOption.TopDirectoryOnly);

                if (null != dynamoFiles && (dynamoFiles.Length > 0))
                {
                    foreach (System.IO.FileInfo file in dynamoFiles)
                    {
                        if (sampleFolderPath == null)
                        {                            
                            sampleFolderPath = Path.GetDirectoryName(file.FullName);
                        }
                        // Add each file under the root directory property list.
                        rootProperty.AddChildSampleFile(new SampleFileEntry(file.Name, file.FullName));
                    }
                }
            }
            catch (Exception)
            {
                // Perhaps some permission problems?
            }
        }