private void button3_Click(object sender, EventArgs e) { // Save button; send the data to parent form; Form1 parent = (Form1)this.Owner; var bs = new BindingSource(); int i; for (i = 1; i <= numberOfKeys; i++) { // set each textbox from the parent with the combobox value parent.setString(parent.textBoxArray[i], comboBoxArray[i].Text); // for each combobox add its value to the list listElement listElement1 = new listElement(comboBoxArray[i].Text); importedList.Add(listElement1); } // remove duplicates. list will be already sorted listCleanup(importedList); bs.DataSource = importedList; updateCBdataSources(bs); // call update of comboboxes datasources; parent.setBSource(bs); // pass along to Form1 the list (as a binding source); this.Close(); }
public static listElement getMeta(int id, System.Collections.Generic.Dictionary<int,mediaItem> table_medias) { Debug.Log("COUCOUOUUUOUOUOUOUOUOU"); if (table_medias.ContainsKey(id)){ Debug.Log("id " + id); Debug.Log("mediatype " + int.Parse(table_medias[id].mediaData["mediatype"])); listElement meta = new listElement(id, int.Parse(table_medias[id].mediaData["mediatype"]), table_medias[id].mediaData["link"], table_medias[id].mediaData["text"], 0, null, table_medias[id].mediaData["associated_text"], table_medias[id].mediaData["associated_audio"], table_medias[id].mediaData["associated_video"], null, null, int.Parse(table_medias[id].mediaData["previous"]), int.Parse(table_medias[id].mediaData["next"])); return meta; } else{ Debug.Log("id not found"); return null; } }
private void listCleanup(List <listElement> list) { // Duplicates will be noticed after a sort O(nLogn) list.Sort((x, y) => x.Taxon.CompareTo(y.Taxon)); // Store the current and last items. Current item declaration is not really needed, and probably optimized by the compiler, but in case it's not... listElement lastItem = new listElement(""); listElement currItem = new listElement(""); int size = list.Count; // Store the index pointing to the last item we want to keep in the list int last = size - 1; // Travel the items from last to first O(n) for (int i = last; i >= 0; --i) { currItem = list[i]; // If this item was the same as the previous one, we don't want it if (currItem.Taxon.Equals(lastItem.Taxon)) { // Overwrite last in current place. It is a swap but we don't need the last list[i] = list[last]; // Reduce the last index, we don't want that one anymore last--; } // A new item, we store it and continue else { lastItem = currItem; } } // We now have an unsorted list with the duplicates at the end. // Remove the last items just once list.RemoveRange(last + 1, size - last - 1); // Sort again O(n logn) list.Sort((x, y) => x.Taxon.CompareTo(y.Taxon)); }
private void button1_Click(object sender, EventArgs e) { // Save button Form1 parent = (Form1)this.Owner; parent.setString(tb, comboBox1.Text); //var bs = new BindingSource(); //bs = parent.bs.DataSource; // add the value to the list listElement listElement1 = new listElement(comboBox1.Text); importedList.Add(listElement1); // clean up duplicates listCleanup(importedList); this.Close(); }
private void button2_Click(object sender, EventArgs e) { // import button; try { var bs = new BindingSource(); string[] lines = System.IO.File.ReadAllLines(textBox1.Text); // read all lines; not really safe for huge files but is sufficient for most use-cases importedList.Clear(); listElement blankListElement = new listElement(""); importedList.Add(blankListElement); foreach (string line in lines) { // go through each line and add it to the list; listElement listElement1 = new listElement(line); importedList.Add(listElement1); } // importedList.Sort((x, y) => x.Taxon.CompareTo(y.Taxon)); // sort list alphabetically // remove duplicates and sort listCleanup(importedList); // assign list to binding source bs.DataSource = importedList; updateCBdataSources(bs); // call update of comboboxes datasources; Form1 parent = (Form1)this.Owner; parent.setBSource(bs); // pass along to Form1 the list (as a binding source); //MessageBox.Show("Import complete!"); this.labelStatus.Text = "Import complete!"; } catch (Exception ex) { //MessageBox.Show("Error: Could not read file from disk. " + ex.Message); this.labelStatus.Text = "Error! Could not read file from disk!"; } }
/// <summary> /// Parse ADMX Files /// </summary> /// <param name="FilePath">Admx File Path</param> /// <param name="Language">Subfolder of the Admx File with the corresponding Adml File</param> public AdmxParse(string FilePath, string Language) { categories = new List <category>(); policies = new List <policy>(); xPathMapping.LoadXml(Properties.Settings.Default.DevicePathMapping); FileInfo fiAdmx = new FileInfo(FilePath); if (fiAdmx.Exists) { FileInfo fiAdml = new FileInfo(Path.Combine(fiAdmx.DirectoryName, Language, fiAdmx.Name.Replace(".admx", ".adml"))); if (fiAdml.Exists) { xAdml.Load(fiAdml.FullName); } xAdmx.Load(FilePath); XmlNamespaceManager ns = new XmlNamespaceManager(xAdmx.NameTable); ns.AddNamespace("pd", xAdmx.DocumentElement.NamespaceURI); //Get categories foreach (XmlNode xCat in xAdmx.SelectNodes("/pd:policyDefinitions/pd:categories/pd:category", ns)) { try { var oRes = new category(); oRes.displayName = sResourceStringLookup(xCat.Attributes["displayName"].InnerText.Replace("$(string.", "").TrimEnd(')')); oRes.name = xCat.Attributes["name"].InnerText; if (xCat["parentCategory"] == null) { //oRes.parent = oRes.name; ??? oRes.parent = ""; categories.Add(oRes); continue; } oRes.parent = xCat["parentCategory"].Attributes["ref"].InnerText; if (categories.FirstOrDefault(t => t.name == oRes.parent) == null) { var xParent = xPathMapping.SelectSingleNode("//*[@name='" + oRes.parent + "']"); if (xParent != null) { XmlNode xPar = xParent; while (xPar != null) { if (xPar.Name != "#document") { if (xPar.Attributes["name"] != null) { string sPar = ""; if (xPar.ParentNode.Attributes["name"] != null) { sPar = xPar.ParentNode.Attributes["name"].Value; } categories.Add(new category() { name = xPar.Attributes["name"].Value, displayName = xPar.Attributes["displayname"].Value, parent = sPar }); } } xPar = xPar.ParentNode; } } else { string sDispName = oRes.parent; categories.Add(new category() { name = sDispName, displayName = sDispName, parent = "" }); } } categories.Add(oRes); } catch (Exception ex) { ex.Message.ToString(); } } //Get Policies foreach (XmlNode xPol in xAdmx.SelectNodes("/pd:policyDefinitions/pd:policies/pd:policy", ns)) { var oRes = new policy(); oRes.elements = new List <element>(); oRes.displayName = sResourceStringLookup(xPol.Attributes["displayName"].InnerText.Replace("$(string.", "").TrimEnd(')')); oRes.name = xPol.Attributes["name"].InnerText; oRes.state = policyState.NotConfigured; if (string.IsNullOrEmpty(oRes.displayName)) { oRes.displayName = oRes.name; } if (xPol.Attributes["explainText"] != null) { oRes.explainText = sResourceStringLookup(xPol.Attributes["explainText"].InnerText.Replace("$(string.", "").TrimEnd(')')); } oRes.parentCategory = categories.FirstOrDefault(t => t.name == xPol["parentCategory"].Attributes["ref"].InnerText); catLookup(xPol["parentCategory"].Attributes["ref"].InnerText); oRes.path = GetPath(xPol["parentCategory"].Attributes["ref"].InnerText); var pCat = categories.FirstOrDefault(t => t.name == xPol["parentCategory"].Attributes["ref"].InnerText); if (pCat != null) { oRes.displaypath = GetDisplayPath(pCat.displayName); } else { var xParent = xPathMapping.SelectSingleNode("//*[@name='" + xPol["parentCategory"].Attributes["ref"].InnerText + "']"); if (xParent != null) { string sDispName = xParent.Attributes["displayname"].Value; string sName = xParent.Attributes["name"].Value; string sParent = ""; if (xParent.ParentNode.Attributes["name"] != null) { sParent = xParent.ParentNode.Attributes["name"].Value; } categories.Add(new category() { name = sName, displayName = sDispName, parent = sParent }); oRes.displaypath = GetDisplayPath(sDispName); } } oRes.key = xPol.Attributes["key"].InnerText; if (xPol.Attributes["presentation"] != null) { oRes.presentation = sPresentationStringLookup(xPol.Attributes["presentation"].InnerText.Replace("$(presentation.", "").TrimEnd(')')); } switch (xPol.Attributes["class"].InnerText) { case "Machine": oRes.policyType = classType.Machine; break; case "User": oRes.policyType = classType.User; break; } //oRes.innerXML = xPol.InnerXml; if (xPol.Attributes["valueName"] != null) { if (xPol["enabledValue"] != null) { polEnableElement oElem = new polEnableElement(); oElem.ValueName = xPol.Attributes["valueName"].InnerText; oElem.ValueType = valueType.PolicyEnable; if (xPol["enabledValue"]["decimal"] != null) { try { oElem.enabledValue = uint.Parse(xPol["enabledValue"]["decimal"].Attributes["value"].Value); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } if (xPol["disabledValue"] != null) { if (xPol["disabledValue"]["decimal"] != null) { try { oElem.disabledValue = uint.Parse(xPol["disabledValue"]["decimal"].Attributes["value"].Value); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } oRes.elements.Add(oElem); } else { polEnableElement oElem = new polEnableElement(); oElem.ValueName = xPol.Attributes["valueName"].InnerText; oElem.ValueType = valueType.PolicyEnable; oElem.enabledValue = 1; oElem.disabledValue = 0; oRes.elements.Add(oElem); } } if (xPol["elements"] != null) { foreach (XmlNode xElem in xPol["elements"].ChildNodes) { if (xElem.Name == "#comment") { continue; } if (xElem.Name == "#text") { continue; } element oElem = new element(); switch (xElem.Name.ToLower()) { case "decimal": oElem = new decimalElement(); oElem.ValueType = valueType.Decimal; if (xElem.Attributes["minValue"] != null) { uint iRes = 0; if (uint.TryParse(xElem.Attributes["minValue"].InnerText, out iRes)) { ((decimalElement)oElem).minValue = iRes; } } if (xElem.Attributes["maxValue"] != null) { uint iRes = 0; if (uint.TryParse(xElem.Attributes["maxValue"].InnerText, out iRes)) { ((decimalElement)oElem).maxValue = iRes; } } break; case "enum": oElem = new enumElement(); oElem.ValueType = valueType.Enum; ((enumElement)oElem).valueList = new Dictionary <string, string>(); foreach (XmlNode xElemItem in xElem.SelectNodes("pd:item", ns)) { try { string sDisplayName = sResourceStringLookup(xElemItem.Attributes["displayName"].Value.Replace("$(string.", "").TrimEnd(')')); if (string.IsNullOrEmpty(sDisplayName)) { sDisplayName = xElemItem.Attributes["displayName"].Value.Replace("$(string.", "").TrimEnd(')'); } if (xElemItem["value"].FirstChild.Name == "decimal") { if (xElemItem["value"].FirstChild.Attributes.Count > 0) { ((enumElement)oElem).valueList.Add(sDisplayName, xElemItem["value"].FirstChild.Attributes["value"].Value); } else { ((enumElement)oElem).valueList.Add(sDisplayName, xElemItem["value"].FirstChild.InnerText); } } if (xElemItem["value"].FirstChild.Name == "string") { ((enumElement)oElem).valueList.Add(sDisplayName, xElemItem["value"].FirstChild.InnerText); } string sDefault = oRes.sPresentationdefaultValue(xElem.Attributes["id"].Value); if (!string.IsNullOrEmpty(sDefault)) { int iDef = 0; int.TryParse(sDefault, out iDef); ((enumElement)oElem).defaultItem = iDef; } } catch (Exception ex) { Debug.WriteLine(ex.Message); } } break; case "boolean": oElem = new decimalElement(); oElem.ValueType = valueType.Boolean; ((decimalElement)oElem).minValue = 0; ((decimalElement)oElem).maxValue = 1; oElem.value = oRes.sPresentationdefaultValue(xElem.Attributes["id"].Value); break; case "list": oElem = new listElement(); oElem.ValueType = valueType.List; ((listElement)oElem).valueList = new Dictionary <string, string>(); if (xElem.Attributes["additive"] != null) { bool bRes = false; if (bool.TryParse(xElem.Attributes["additive"].Value, out bRes)) { ((listElement)oElem).additive = bRes; } else { ((listElement)oElem).additive = null; } } if (xElem.Attributes["explicitValue"] != null) { bool bRes = false; if (bool.TryParse(xElem.Attributes["explicitValue"].Value, out bRes)) { ((listElement)oElem).explicitValue = bRes; } else { ((listElement)oElem).explicitValue = null; } } break; case "text": oElem = new textElement(); oElem.ValueType = valueType.Text; break; default: xElem.Name.ToString(); break; } oElem.value = oRes.sPresentationdefaultValue(xElem.Attributes["id"].InnerText); //oElem.innerXML = xElem.OuterXml; //List do not have a Value, they have List of Valuenames and Values if (oElem.ValueType != valueType.List) { oElem.ValueName = xElem.Attributes["valueName"].InnerText; } if (xElem.Attributes["required"] != null) { bool bReq = false; if (bool.TryParse(xElem.Attributes["required"].InnerText, out bReq)) { oElem.required = bReq; } } if (xElem.Attributes["key"] != null) { oElem.key = xElem.Attributes["key"].Value; } oRes.elements.Add(oElem); } } if (xPol["enabledList"] != null) { EnableListElement oElem = new EnableListElement(); oElem.ValueType = valueType.Enum; oElem.enabledValueList = new List <enabledList>(); foreach (XmlNode xElem in xPol["enabledList"].SelectNodes("pd:item", ns)) { try { enabledList oResList = new enabledList(); if (xElem["value"].FirstChild.Name == "decimal") { oResList.type = valueType.Decimal; oResList.key = xElem.Attributes["key"].Value; oResList.valueName = xElem.Attributes["valueName"].Value; oResList.value = xElem["value"].FirstChild.Attributes["value"].Value; } if (xElem["value"].FirstChild.Name == "string") { oResList.type = valueType.Text; oResList.key = xElem.Attributes["key"].Value; oResList.valueName = xElem.Attributes["valueName"].Value; if (xElem["value"].FirstChild.Attributes.Count > 0) { oResList.value = xElem["value"].FirstChild.Attributes["value"].Value; } else { oResList.value = xElem["value"].FirstChild.InnerText; } } oElem.enabledValueList.Add(oResList); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } oRes.elements.Add(oElem); } if (xPol["disabledList"] != null) { EnableListElement oElem = new EnableListElement(); oElem.ValueType = valueType.Enum; oElem.disabledValueList = new List <enabledList>(); foreach (XmlNode xElem in xPol["disabledList"].SelectNodes("pd:item", ns)) { try { enabledList oResList = new enabledList(); if (xElem["value"].FirstChild.Name == "decimal") { oResList.type = valueType.Decimal; oResList.key = xElem.Attributes["key"].Value; oResList.valueName = xElem.Attributes["valueName"].Value; oResList.value = xElem["value"].FirstChild.Attributes["value"].Value; } if (xElem["value"].FirstChild.Name == "string") { oResList.type = valueType.Text; oResList.key = xElem.Attributes["key"].Value; oResList.valueName = xElem.Attributes["valueName"].Value; if (xElem["value"].FirstChild.Attributes.Count > 0) { oResList.value = xElem["value"].FirstChild.Attributes["value"].Value; } else { oResList.value = xElem["value"].FirstChild.InnerText; } } oElem.disabledValueList.Add(oResList); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } oRes.elements.Add(oElem); } policies.Add(oRes); } } }