public int Copy(CopyParameters parameters, out String newName) { if (parameters.ReadingController == null && parameters.WritingController == null) { MessageBox.Show("No reading or writing controller provided!"); newName = "-1"; return -1; } if (parameters.ReadingController != null && parameters.WritingController == null) { parameters.WritingController = parameters.ReadingController; // use read to write if no write is supplied if (parameters.ClearWriteDB) { MessageBox.Show("Clearing with no write controller is not recommended!"); newName = "-1"; return -1; } } if (parameters.StartingRootID == -1) { MessageBox.Show("No starting root ID provided!"); newName = "-1"; return -1; } this.readingController = parameters.ReadingController; this.writingController = parameters.WritingController; limitToLinkTypes = new Dictionary<String, String>(); if (parameters.LimitToLinkTypes != null) { Dictionary<String, String> buildLLFromParameters = new Dictionary<String, String>(); foreach (String llt in parameters.LimitToLinkTypes) { buildLLFromParameters.Add(llt, llt); } limitToLinkTypes = buildLLFromParameters; } if (parameters.OnlyLinkTypes != null) { onlyLinkTheseTypesMap.Clear(); foreach (String type in parameters.OnlyLinkTypes) { onlyLinkTheseTypesMap.Add(type, type); } } if (parameters.SkipParameters != null) { skipParametersMap.Clear(); foreach (String parameter in parameters.SkipParameters) { skipParametersMap.Add(parameter, parameter); } } copyOutput = parameters.CopyOutput; schemaRootToLinkType.Clear(); seenComponentIDs.Clear(); isDynamicRoot.Clear(); dynamicBridge.Clear(); appCodeObjects.Clear(); refLinkTypes.Clear(); alreadyRead.Clear(); // Read all of the XSD schemas associated with the configuration.xml in the specified directory XmlReader configFileReader = this.readingController.GetConfigurationReader(); XmlDocument configFile = new XmlDocument(); configFile.Load(configFileReader); configFileReader.Close(); // .xsds are referenced in the Links XmlNodeList links = configFile.SelectNodes("GME/Global/Links/Link"); String schemaFileName; XmlAttribute schemaFileAttribute; XmlReader schemaReader; XmlSchema schema; XmlSchemaSet schemaSet; Boolean foundRootAndLT; foreach (XmlNode link in links) { //(use the filename if provided otherwise, use the linktype + .xsd schemaFileAttribute = link.Attributes[ConfigFileConstants.schemaFilename]; if (schemaFileAttribute != null) { schemaFileName = schemaFileAttribute.Value; } else { schemaFileName = link.Attributes[ConfigFileConstants.Type].Value + ".xsd"; } XmlNode dynamic = link.SelectSingleNode("Dynamic"); if (dynamic != null) { String linkTypeValue = link.Attributes[ConfigFileConstants.Type].Value; Boolean isRoot = Boolean.Parse(dynamic.Attributes[ConfigFileConstants.isRoot].Value); isDynamicRoot.Add(linkTypeValue, isRoot); if (!isRoot) // non root dynamic, use app code class and ref link type to find it later { String appCode = dynamic.Attributes[ConfigFileConstants.appCode].Value; appCodeObjects.Add(linkTypeValue, appCode); String refLinkType = dynamic.Attributes[ConfigFileConstants.refLinkType].Value; refLinkTypes.Add(linkTypeValue, refLinkType); } } XmlNode bridgeDynamic = link.SelectSingleNode("BridgeDynamic"); if (bridgeDynamic != null) { String linkTypeValue = link.Attributes[ConfigFileConstants.Type].Value; String value = bridgeDynamic.Attributes[ConfigFileConstants.component].Value; dynamicBridge.Add(linkTypeValue, value); } schemaReader = this.readingController.GetXSD(schemaFileName); schema = XmlSchema.Read(schemaReader, null); schemaReader.Close(); schemaSet = new XmlSchemaSet(); schemaSet.Add(schema); schemaSet.Compile(); foreach (XmlSchema compiledSchema in schemaSet.Schemas()) { foundRootAndLT = false; foreach (XmlSchemaElement element in compiledSchema.Elements.Values) { foundRootAndLT |= FindRootAndLinkType(element); } if (!foundRootAndLT) { MessageBox.Show("Root and link type not found for schema: " + schemaFileName); } } } // Schemas processed, start copying! if (!parameters.UpdateAfterCopy) { writingController.TurnViewUpdateOff(); } readingController.EnableLoadingCache(); helper = new BulkHelper(); helper.BeginBulkOperations(writingController.Configuration); XPathNavigator self = readingController.GetComponent(parameters.StartingRootID).CreateNavigator().SelectSingleNode("Components/Component"); copiedRootName = parameters.NewName; // ensure no invalid filename characters for (int i = 0; i < copiedRootName.Length; i++) { char c = copiedRootName[i]; for (int j = 0; j < Path.GetInvalidFileNameChars().Length; j++) { if (c == Path.GetInvalidFileNameChars()[j]) { MessageBox.Show("Invalid character in new name: " + c); newName = "-1"; return -1; } } } newName = copiedRootName; String componentType = self.GetAttribute(XmlSchemaConstants.Display.Component.Type, String.Empty); String description = self.GetAttribute(XmlSchemaConstants.Display.Component.Description, String.Empty); if (!schemaRootToLinkType.ContainsKey(componentType)) { schemaRootToLinkType.Add(componentType, new List<String>()); } if (parameters.StartingLinkType != null && !schemaRootToLinkType[componentType].Contains(parameters.StartingLinkType)) { schemaRootToLinkType[componentType].Add(parameters.StartingLinkType); } String copyID = helper.CreateRootComponent(componentType, copiedRootName, description); CopyIDType(parameters.StartingRootID, copyID, componentType, null, null); readingController.DisableLoadingCache(); int rootID = helper.EndBulkOperations(parameters.ClearWriteDB, parameters.ShowDialog, "Copying " + componentType, "Copying..."); if (!parameters.UpdateAfterCopy) { writingController.TurnViewUpdateOn(false, false); } helper = null; return rootID; }