Exemplo n.º 1
0
        public void SetReplacements(ImportSettings settings, Dictionary<string, string> replacementsDictionary)
        {
            var projectFilePath = replacementsDictionary["$destinationdirectory$"];

            var projectHome = CommonUtils.GetRelativeDirectoryPath(projectFilePath, settings.SourceFilesPath);
            var searchPaths = string.Join(";", settings.SearchPaths.Select(p => CommonUtils.GetRelativeDirectoryPath(settings.SourceFilesPath, p)));

            var directories = new HashSet<string>();
            var content = new StringBuilder();

            content.AppendLine("  <ItemGroup>");

            var files = Directory.EnumerateFiles(settings.SourceFilesPath, "*.py", SearchOption.AllDirectories);
            foreach (var pattern in settings.Filter.Split(';')) {
                try {
                    var theseFiles = Directory.EnumerateFiles(settings.SourceFilesPath, pattern.Trim(), SearchOption.AllDirectories);
                    files = files.Concat(theseFiles);
                } catch (ArgumentException) {
                    // Probably an invalid pattern.
                }
            }

            foreach (var file in files.Distinct(StringComparer.OrdinalIgnoreCase)) {
                var relFile = CommonUtils.GetRelativeFilePath(settings.SourceFilesPath, file);
                var dir = Path.GetDirectoryName(relFile);
                if (!String.IsNullOrWhiteSpace(dir)) {
                    directories.Add(dir);
                }

                if (Path.GetExtension(file).Equals(".py", StringComparison.OrdinalIgnoreCase) ||
                    Path.GetExtension(file).Equals(".pyw", StringComparison.OrdinalIgnoreCase)) {
                    content.AppendLine(string.Format("    <Compile Include=\"{0}\" />", relFile));
                } else {
                    content.AppendLine(string.Format("    <Content Include=\"{0}\" />", relFile));
                }
            }
            content.AppendLine("  </ItemGroup>");

            if (directories.Any()) {
                content.AppendLine("  <ItemGroup>");
                foreach (var dir in directories.OrderBy(key => key)) {
                    content.AppendLine(string.Format("    <Folder Include=\"{0}\" />", dir));
                }
                content.AppendLine("  </ItemGroup>");
            }

            replacementsDictionary["$projecthome$"] = projectHome;
            replacementsDictionary["$searchpaths$"] = searchPaths;
            replacementsDictionary["$content$"] = content.ToString();

            if (!string.IsNullOrEmpty(settings.InterpreterId)) {
                replacementsDictionary["$interpreter$"] = string.Format("    <InterpreterId>{0}</InterpreterId>{2}    <InterpreterVersion>{1}</InterpreterVersion>{2}",
                    settings.InterpreterId, settings.InterpreterVersion, Environment.NewLine);
            } else {
                replacementsDictionary["$interpreter$"] = Environment.NewLine;
            }

            if (!string.IsNullOrEmpty(settings.StartupFile)) {
                replacementsDictionary["$startupfile$"] = CommonUtils.GetRelativeFilePath(settings.SourceFilesPath, settings.StartupFile);
            } else {
                replacementsDictionary["$startupfile$"] = "";
            }
        }
Exemplo n.º 2
0
        public static ImportSettings ShowImportDialog(IServiceProvider provider)
        {
            using (var dialog = new ImportWizardDialog(provider)) {
                var result = dialog.ShowDialog();

                if (result != DialogResult.OK) {
                    return null;
                }

                var settings = new ImportSettings {
                    SourceFilesPath = dialog.sourcePathTextBox.Text,
                    Filter = dialog.filterTextBox.Text,
                    SearchPaths = dialog.searchPathTextBox.Lines
                };

                var interp = dialog.interpreterCombo.SelectedItem as InterpreterItem;
                if (interp != null) {
                    settings.InterpreterId = interp.Id.ToString();
                    settings.InterpreterVersion = interp.Version;
                }

                var startupFile = dialog.startupFileList.SelectedItems.Cast<ListViewItem>().FirstOrDefault();
                if (startupFile != null) {
                    settings.StartupFile = startupFile.Name;
                }

                return settings;
            }
        }