private void compareCockpitConfigurations(CockpitConfiguration cockpitConfigurationToObtain, bool isNbColumnsTrue = true, bool isNbGadgetsTrue = true, bool isGadgetsPositionTrue = true) { List<List<Gadget>> columns = cockpitConfiguration.getGadgetsColumns(); List<List<Gadget>> columnsToObtain = cockpitConfigurationToObtain.getGadgetsColumns(); //verify the number of columns if (isNbColumnsTrue) Assert.IsTrue(columns.Count == columnsToObtain.Count, "Wrong number of columns in cockpitConfiguration"); else Assert.IsFalse(columns.Count == columnsToObtain.Count, "Wrong number of columns in cockpitConfiguration"); //for each columns bool isDifference = false; for (int column = 0; column < cockpitConfiguration.getGadgetsColumns().Count; column++) { //verify the number of gadgets in columns if (isNbGadgetsTrue) Assert.IsTrue(columns[column].Count == columnsToObtain[column].Count, "Wrong number of gadget in column"); else Assert.IsFalse(columns[column].Count == columnsToObtain[column].Count, "Wrong number of gadget in column"); //for each gadgets for (int gadgetIndex = 0; gadgetIndex < columns[column].Count; gadgetIndex++) { //verifiy if gadgets' ids are similar if (columns[column][gadgetIndex].getGadgetId() != columnsToObtain[column][gadgetIndex].getGadgetId()) { isDifference = true; } } } if (isGadgetsPositionTrue) Assert.IsFalse(isDifference, "Wrong gadget's position, should be true"); else Assert.IsTrue(isDifference, "Wrong gadget's position, should be wrong"); }
/// <summary> /// Methods <c>saveConfiguration</c> is called when a cockpit configuration has to be saved /// in database. /// </summary> /// <param name="userName"></param> /// <param name="configurationToSave"></param> public void saveConfiguration(string userName, CockpitConfiguration configurationToSave) { XmlDocument configurationDoc = dbManager.retrieveDocument("cockpitConfiguration", configurationToSave.getConfigurationID()); //update username XmlNode cockpitConfigurationUserNameNode = configurationDoc.GetElementsByTagName("userName")[0]; cockpitConfigurationUserNameNode.InnerText = userName; //update display configuration id XmlNode cockpitDisplayConfigIdNode = configurationDoc.GetElementsByTagName("displayConfig")[0]; cockpitDisplayConfigIdNode.InnerText = configurationToSave.getCurrentDisplay().getDisplayId().ToString(); //udpate list of gadgets XmlNode cockpitGadgetsNode = configurationDoc.GetElementsByTagName("gadgets")[0]; StringBuilder gadgetsString = new StringBuilder(""); for (int i = 0; i < configurationToSave.getGadgetsColumns().Count; i++) { foreach (Gadget gadget in configurationToSave.getGadgetsColumns().ElementAt(i)) { gadgetsString.Append("<gadget ID='" + gadget.getGadgetId() + "' column='" + i + "'/>"); } } cockpitGadgetsNode.InnerXml = gadgetsString.ToString(); if (configurationToSave.getConfigurationID() == 0) //configuration id must be another than default one { //new docname and id is taken from current hour string uniqueDocName = System.DateTime.Now.ToString("HHmmssffff"); configurationToSave.setConfigurationID(long.Parse(uniqueDocName)); XmlNode cockpitConfigurationIdNode = configurationDoc.GetElementsByTagName("cockpitConfiguration")[0].Attributes.GetNamedItem("ID"); cockpitConfigurationIdNode.InnerText = configurationToSave.getConfigurationID().ToString(); } if (configurationToSave.getConfigurationID() != long.Parse(configurationDoc.GetElementsByTagName("cockpitConfiguration")[0].Attributes.GetNamedItem("ID").InnerText)) { throw new Exception("Configuration's id and docName are not equal, impossible to save configuration"); } dbManager.insertDocument(configurationDoc, "cockpitConfiguration", configurationToSave.getConfigurationID()); }