/// <summary> /// Add a List item safely, when key exists, change value. /// </summary> /// <param name="key">The dictionary item key.</param> /// <param name="val">The dictionary item value.</param> /// <param name="excpetionOnDictDuplicates">When true; throw an exception when duplicate keys found, when false, update the value of the key.</param> /// <param name="lstDct">The dictionary to add or set the key value pair to.</param> public static void AddSetDictionaryItem(String key, String val, bool excpetionOnDictDuplicates, ref Dictionary <String, String> lstDct) { try { if (lstDct == null) { lstDct = new Dictionary <String, String>(); } if (!excpetionOnDictDuplicates && lstDct.ContainsKey(key)) { lstDct[key] = val ?? String.Empty; } else { lstDct.Add(key, val ?? String.Empty); } } catch (Exception ex) { ILog.LogWarning("Key: [{0}], Value [{1}], caused an error [{2}] in method [{3}]", key ?? String.Empty, val ?? String.Empty, ex.Message, MethodBase.GetCurrentMethod().Name); ILog.LogError(ex, false); throw ex; } }
public static void PRDToXml(object sender, EventArgs e) #endif { try { using (OpenFileDialog opn = new OpenFileDialog()) { opn.Filter = "PRD files (*.prd)|*.prd|Any file (*.*)|*.*"; opn.Title = "Open source PRD\\s..."; opn.Multiselect = true; opn.DefaultExt = "prd"; if (opn.ShowDialog() == DialogResult.OK) { using (SaveFileDialog sve = new SaveFileDialog()) { sve.Filter = "XML files (*.xml)|*.xml|Any file (*.*)|*.*"; sve.Title = "Save target XML..."; sve.DefaultExt = "xml"; sve.InitialDirectory = Path.GetDirectoryName(opn.FileName); sve.FileName = Path.GetFileNameWithoutExtension(opn.FileName); if (sve.ShowDialog() == DialogResult.OK) { PRDToXml(sve.FileName, opn.FileNames); return; } } } } ILog.LogWarning("Failed converting PRD file to XML file."); } catch (Exception ex) { ILog.LogError(ex); } }
public static void XMLToPRD(object sender, EventArgs e) #endif { try { using (OpenFileDialog opn = new OpenFileDialog()) { opn.Filter = "XML files (*.xml)|*.xml|Any file (*.*)|*.*"; opn.Title = "Open source XML..."; if (opn.ShowDialog() == DialogResult.OK) { using (SaveFileDialog sve = new SaveFileDialog()) { sve.Filter = "PRD files (*.prd)|*.prd|Any file (*.*)|*.*"; sve.Title = "Save target PRD..."; sve.InitialDirectory = Path.GetDirectoryName(opn.FileName); sve.FileName = Path.GetFileNameWithoutExtension(opn.FileName); sve.DefaultExt = "prd"; if (sve.ShowDialog() == DialogResult.OK) { if (XMLToPRD(sve.FileName, opn.FileName)) { ILog.LogDebug(string.Format("Done converting XML file [{0}] to PRD file [{1}].", opn.FileName, sve.FileName)); return; } } } } } ILog.LogWarning("Failed converting XML file to PRD file."); } catch (Exception ex) { ILog.LogError(ex); } }