Exemple #1
0
        // ----------------------------------------------------------------------------------------
        /// <!-- TestKeyListFile -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="inputPath"></param>
        /// <param name="targetPath"></param>
        /// <remarks>
        ///      Usage:
        ///      KeyListFile.TestKeyListFile("C:\\docs\\input.txt", "C:\\docs\\output.txt");
        /// </remarks>
        public static void TestKeyListFile(string inputPath, string targetPath)
        {
            // --------------------------------------------------------------------------
            //  Produce a report of what keys contain what values in their value list
            // --------------------------------------------------------------------------
            string      fileInput        = KeyListFile.GetStringFromFile(inputPath, "");
            KeyListFile valuesforEachKey = new KeyListFile(fileInput, ':', ' ');
            KeyListFile keysForEachValue = valuesforEachKey.ConvertValuesAndKeys(':', ' ');
            string      report           = keysForEachValue.ConstructOrderedReport(false, true);


            // --------------------------------------------------------------------------
            //  Test and output the report
            // --------------------------------------------------------------------------
            string target = KeyListFile.GetStringFromFile(targetPath, "");

            if (report == target)
            {
                Console.Write("success\r\n");
            }
            else
            {
                Console.Write("not quite\r\n");
            }
            Console.Write(report);
        }
Exemple #2
0
        // ----------------------------------------------------------------------------------------
        /// <!-- ConvertValuesAndKeys -->
        /// <summary>
        ///      Returns a KeyListFile identifying which values are used by which keys and
        /// </summary>
        /// <returns></returns>
        public KeyListFile ConvertValuesAndKeys(char keyDelimiter, char itemDelimiter)
        {
            // --------------------------------------------------------------------------
            //  Initialize the conversion
            // --------------------------------------------------------------------------
            KeyListFile valuesBecomeKeys = new KeyListFile(keyDelimiter, itemDelimiter);

            foreach (string formerKey in this.Keys)
            {
                List <string> formerValue = this[formerKey];
                for (int i = 0; i < formerValue.Count; ++i)
                {
                    if (!valuesBecomeKeys.ContainsKey(formerValue[i]))
                    {
                        valuesBecomeKeys.Add(formerValue[i], new List <string>());
                    }
                }
            }

            // --------------------------------------------------------------------------
            //  Fill the conversion
            // --------------------------------------------------------------------------
            foreach (string formerKey in this.Keys)
            {
                List <string> formerValue = this[formerKey];
                for (int i = 0; i < formerValue.Count; ++i)
                {
                    valuesBecomeKeys[formerValue[i]].Add(formerKey);
                }
            }

            return(valuesBecomeKeys);
        }