public void TestBasicSave() { XmlDocument doc = new XmlDocument(); doc.LoadXml(TestResource.FileMate_Test_Config); CopyGroupDTO cgDto = new CopyGroupDTO(doc); XmlDocument testDoc = cgDto.AsXml(); // assert some things about the produced xml XmlNodeList ops = Helper.GetCopyOperationNodes(testDoc); Assert.AreEqual <int>(1, ops.Count); Assert.AreEqual <string>("summa", Helper.GetCopyOperationName(ops[0])); Assert.IsFalse(Helper.GetCalledFromForOperation(ops[0])); Assert.IsFalse(Helper.GetCopyOperationDeleteSource(ops[0])); Assert.AreEqual <string>(@"c:\source\", Helper.GetSourceUrl(Helper.GetSourceNodeForOperation(ops[0]))); Assert.AreEqual <int>(1, Helper.GetTargetsForOperation(ops[0]).Count); XmlNode targetNode = Helper.GetTargetsForOperation(ops[0])[0]; Assert.AreEqual <string>(@"c:\target\", Helper.GetTargetUrl(targetNode)); Assert.AreEqual <string>("1m", Helper.GetScheduleForOperation(ops[0])); Assert.AreEqual <string>("*.dat", Helper.GetFilePatternForOperation(ops[0])); }
private void btnSaveAll_Click(object sender, EventArgs e) { try { // write summa settings xml file XmlDocument summaSettingsDoc = new XmlDocument(); summaSettingsDoc.AppendChild(summaSettingsDoc.CreateNode(XmlNodeType.XmlDeclaration, "", "")); XmlNode rootNode = summaSettingsDoc.CreateNode(XmlNodeType.Element, "SummaSettings", ""); XmlAttribute ListenPortAttr = summaSettingsDoc.CreateAttribute("ListenPort"); ListenPortAttr.InnerText = tbPort.Text; rootNode.Attributes.Append(ListenPortAttr); XmlAttribute OutputFilePathAttr = summaSettingsDoc.CreateAttribute("OutputFilePath"); OutputFilePathAttr.InnerText = Helper.FormatUrl(tbExportPath.Text); rootNode.Attributes.Append(OutputFilePathAttr); XmlAttribute enabledAttr = summaSettingsDoc.CreateAttribute("Enabled"); enabledAttr.InnerText = cbSummaEnabled.Checked ? "true" : "false"; rootNode.Attributes.Append(enabledAttr); summaSettingsDoc.AppendChild(rootNode); if (File.Exists(Path.Combine(_path, SUMMA_SETTINGS_FILENAME))) { File.Copy( Path.Combine(_path, SUMMA_SETTINGS_FILENAME), Path.Combine(_path, SUMMA_SETTINGS_FILENAME + ".bak"), true); } summaSettingsDoc.Save(Path.Combine(_path, SUMMA_SETTINGS_FILENAME)); // write id map XmlDocument summaIdMapDoc = new XmlDocument(); summaIdMapDoc.AppendChild(summaIdMapDoc.CreateNode(XmlNodeType.XmlDeclaration, "", "")); rootNode = summaIdMapDoc.CreateNode(XmlNodeType.Element, "SummaSiteIdMap", ""); foreach (KeyValuePair <int, int> kvp in _summaIdMap.IdMap) { XmlNode n = summaIdMapDoc.CreateNode(XmlNodeType.Element, "SummaIdMapEntry", ""); XmlAttribute siteIdAttr = summaIdMapDoc.CreateAttribute("siteId"); siteIdAttr.InnerText = kvp.Key.ToString(); XmlAttribute summaIdAttr = summaIdMapDoc.CreateAttribute("summaSiteId"); summaIdAttr.InnerText = kvp.Value.ToString(); n.Attributes.Append(siteIdAttr); n.Attributes.Append(summaIdAttr); rootNode.AppendChild(n); } summaIdMapDoc.AppendChild(rootNode); if (File.Exists(Path.Combine(_path, SUMMA_ID_MAP_FILENAME))) { File.Copy( Path.Combine(_path, SUMMA_ID_MAP_FILENAME), Path.Combine(_path, SUMMA_ID_MAP_FILENAME + ".bak"), true); } summaIdMapDoc.Save(Path.Combine(_path, SUMMA_ID_MAP_FILENAME)); CaptureSummaInfo(); // backup if (File.Exists(Path.Combine(_path, FILEMATE_CONFIG_FILENAME))) { File.Copy( Path.Combine(_path, FILEMATE_CONFIG_FILENAME), Path.Combine(_path, FILEMATE_CONFIG_FILENAME + ".bak"), true); } // write filemate copy operations (including summa copyop) _fileMateSettings.AsXml().Save(Path.Combine(_path, FILEMATE_CONFIG_FILENAME)); // since we have saved/modified settings.. need to restart the windows service // restartService("FileMate", 1000); // close form this.Close(); } catch (IOException ioe) { new ErrorHandler(ioe.ToString()).ShowDialog(); } catch (UnauthorizedAccessException uae) { new ErrorHandler(uae.ToString()).ShowDialog(); } }