コード例 #1
0
        private void addKeyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddConfigValue input = new AddConfigValue();
            input.ShowDialog();
            string pKey = input.getPKey();
            string pValue = input.getPValue();

            PKeyValuePair newKeyValuePair = new PKeyValuePair { PKey = pKey, PValue = pValue };
            upsertPKeyValuePair(newKeyValuePair, true);
        }
コード例 #2
0
 private int upsertPKeyValuePair(string pKey, string pValue, bool appendAtEnd)
 {
     PKeyValuePair newPair = new PKeyValuePair { PKey = pKey, PValue = pValue };
     return upsertPKeyValuePair(newPair, appendAtEnd);
 }
コード例 #3
0
        private int loadConfigurationFile(string filePath)
        {
            bool currentConfigCleared = false;
            int keyCount = 0;

            System.IO.StreamReader file;
            string fileCurrentLine;

            if (!File.Exists(filePath))
                return -1;

            file = new System.IO.StreamReader(filePath);

            while ((fileCurrentLine = file.ReadLine()) != null)
            {
                string fileCurrentLineTrimmed = fileCurrentLine.Trim();
                if (String.IsNullOrEmpty(fileCurrentLineTrimmed) || fileCurrentLineTrimmed[0] == '#') // ignore config/template blank lines and comment lines
                    continue;
                else if (fileCurrentLineTrimmed[0] == 'P')
                {
                    string pKey;
                    string pValue;
                    char[] delimeter = { '=' };
                    string[] fileCurrentLineSplit = fileCurrentLineTrimmed.Split(delimeter, 2);

                    pKey = fileCurrentLineSplit[0].Trim();

                    if (fileCurrentLineSplit.Length < 2 || String.IsNullOrEmpty(fileCurrentLineSplit[1]))
                        pValue = String.Empty;
                    else
                        pValue = fileCurrentLineSplit[1].Trim();

                    PKeyValuePair newPair = new PKeyValuePair { PValue = pValue, PKey = pKey };

                    if (!currentConfigCleared)
                    {
                        currentConfig.Clear();
                        currentConfigCleared = true;
                    }

                    currentConfig.Add(newPair);
                    keyCount++;
                }
            }
            file.Close();

            return keyCount;
        }
コード例 #4
0
        private int upsertPKeyValuePair(PKeyValuePair newPair, bool appendAtEnd)
        {
            string pKey = newPair.PKey;
            string pValue = newPair.PValue;

            if (pKey.CompareTo(String.Empty) == 0)
                return -2; // no point adding an invalid/blank key

            // Before adding, we need to see if the new pair is a duplicate of one already existing in our currentConfig list.

            foreach (PKeyValuePair pair in currentConfig)
            {
                if (pair.PKey.CompareTo(pKey) == 0) // if a duplicate is detected, only update the value.
                {
                    pair.PValue = pValue;
                    configDataView.UpdateCellValue(1, currentConfig.IndexOf(pair)); // update field if it was a duplicate
                    return currentConfig.IndexOf(pair); // exit here and return where we updated
                }
            }

            // Next we add our pair object and insert it before the current index.
            if (!appendAtEnd)
                currentConfig.Insert(contextRow.RowIndex, newPair);
            else
                currentConfig.Add(newPair);

            return -1;
        }
コード例 #5
0
        private void insertNewToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddConfigValue input = new AddConfigValue();
            input.ShowDialog();
            string pKey = input.getPKey();
            string pValue = input.getPValue();

            // Next we create our pair object and insert it before the current index.*/
            PKeyValuePair newKeyValuePair = new PKeyValuePair { PKey = pKey, PValue = pValue };
            upsertPKeyValuePair(newKeyValuePair, false);
        }