private string RelativizePath(string path, string relativePathBase, PathRelativizationId relativizationId) { if (!path.StartsWith(relativePathBase)) return path; return "{" + relativizationId + "}" + Path.DirectorySeparatorChar + path.Substring(relativePathBase.Length).Trim(Path.DirectorySeparatorChar); }
private XmlImporter CreateXmlImporter(string name, string path, string relativePathBase, PathRelativizationId relativizationId, string sourceURI, Type[] rowInserterTypes, string[] databaseColumns, CreateXmlRowInserterDelegate createXmlRowInserter) { DynamicForm rowInserterForm = new DynamicForm("Define row inserter...", DynamicForm.CloseButtons.OkCancel); rowInserterForm.AddDropDown("Row inserter:", rowInserterTypes, null, "row_inserter", true); string[] inputColumns = XmlImporter.GetColumnNames(path, "row", "row"); Array.Sort(inputColumns); foreach (string databaseColumn in databaseColumns) rowInserterForm.AddDropDown(databaseColumn + ":", inputColumns, null, databaseColumn, true); XmlImporter importer = null; if (rowInserterForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Type rowInserterType = rowInserterForm.GetValue<Type>("row_inserter"); Dictionary<string, string> databaseColumnInputColumn = new Dictionary<string, string>(); foreach (string databaseColumn in databaseColumns) databaseColumnInputColumn.Add(databaseColumn, rowInserterForm.GetValue<string>(databaseColumn)); importer = new XmlImporter(name, path, RelativizePath(path, relativePathBase, relativizationId), sourceURI, createXmlRowInserter(databaseColumnInputColumn), "row", "row"); } return importer; }