Пример #1
0
        /// <summary>
        /// Handle special cases ("Favoriten" and "M") and remove them from Lists
        /// </summary>
        /// <param name="outputData">Object, in which anything that shoult be written in the XML-file is stored</param>
        /// <param name="presetData">Ridden Names and Values</param>
        /// <param name="xmlAttributes">Only names to generate values</param>
        /// <param name="maxLength">Maximum length of any values-lits in <paramref name="outputData"/></param>
        /// <param name="favoritString">String to write before "M"-values</param>
        private static void specialCaseHandling(List <KeyList> outputData, List <KeyList> presetData, List <string> xmlAttributes, int maxLength, string favoritString)
        {
            // Check Parameter and remove special cases
            if (xmlAttributes.FindIndex(x => x.Equals("Favorit")) != -1)
            {
                xmlAttributes.RemoveAt(xmlAttributes.FindIndex(x => x.Equals("Favorit")));
            }

            if (presetData.FindIndex(x => x.keyName.Equals("Favorit")) != -1)
            {
                presetData.RemoveAt(presetData.FindIndex(x => x.keyName.Equals("Favorit")));
            }

            if (xmlAttributes.FindIndex(x => x.Equals("M")) != -1)
            {
                xmlAttributes.RemoveAt(xmlAttributes.FindIndex(x => x.Equals("M")));
            }

            if (presetData.FindIndex(x => x.keyName.Equals("M")) == -1)
            {
                throw new ArgumentException("Die CSV-Date enthält keine 'M'-Spalte");
            }

            // Exclude special case for "Favorit" and "M"
            KeyList       outputItem  = new KeyList("Favorit");
            List <string> valuesToSet = presetData.Find(x => x.keyName.Equals("M")).keyValues;

            // Checking if there is a specific default value and if so, sets it

            // Setting favorite-values
            for (int i = 0; i <= maxLength; i++)
            {
                outputItem.keyValues.Add(favoritString + " M" + valuesToSet[i]);
            }
            outputData.Add(outputItem);

            // Remove "M"-Column to avoit being in output
            presetData.RemoveAt(presetData.FindIndex(x => x.keyName.Equals("M"))); //TODO Wieso verursacht das einen Fehler?
        }
Пример #2
0
        /// <summary>
        /// Make a List of Names and Values to print in xml vie <see cref="createAndCompareValues(List{KeyList}, List{string})"/>
        /// </summary>
        /// <param name="presetData">Ridden Names and Values</param>
        /// <param name="settings">The initializes <see cref="Settings"/>-object</param>
        /// <returns>Complete list with names and values</returns>
        private static List <KeyList> createAndCompareValues(List <KeyList> presetData, Settings settings)
        {
            #region initialize
            // Getting some settings
            List <string> xmlAttributes = settings.getXmlAttributes();
            List <KeyValuePair <string, string> > defaultValues = settings.DefaultValues;

            //set the maximum lenght of each list to the shortes row of the original Table to prevent null-pointer
            // count -1 becaus we want the biggest index
            int maxLength = presetData[0].keyValues.Count() - 1;

            foreach (KeyList preset in presetData)
            {
                if (preset.keyValues.Count() - 1 < maxLength)
                {
                    maxLength = preset.keyValues.Count() - 1;
                }
            }

            // Create empty output list
            List <KeyList> outputData = new List <KeyList>();
            #endregion
            #region compareism
            //Handling special cases ("Favorit" and "M")
            specialCaseHandling(outputData, presetData, xmlAttributes, maxLength, settings.FavoritString);

            // Filling output list
            foreach (string xmlAttribute in xmlAttributes)
            {
                // Setting Name of XML-Attribute
                KeyList outputItem = new KeyList(xmlAttribute);

                //check if there is somthing in the Presets matching
                if (presetData.FindIndex(x => x.keyName.Equals(xmlAttribute)) != -1)
                {
                    #region presets to set
                    // Make a list of things to set...
                    List <string> valuesToSet = presetData.Find(x => x.keyName.Equals(xmlAttribute)).keyValues;
                    // ...and set it for each item
                    for (int i = 0; i <= maxLength; i++)
                    {
                        outputItem.keyValues.Add(valuesToSet[i]);
                    }
                    #endregion
                }
                else
                {
                    #region defaults to set
                    // Initializing default value
                    string valueToSet = settings.FallbackDefaultValue;
                    // Checking if there is a specific default value and if so, sets it
                    if (defaultValues.FindIndex(x => x.Key.Equals(xmlAttribute)) != -1)
                    {
                        valueToSet = defaultValues.Find(x => x.Key.Equals(xmlAttribute)).Value;
                    }

                    //setting default-FValues
                    for (int i = 0; i <= maxLength; i++)
                    {
                        outputItem.keyValues.Add(valueToSet);
                    }
                    #endregion
                }
                // Finally adding it for each item to the output-object
                outputData.Add(outputItem);
            }

            //check, if there are attributes in the presetData, which arent in the xmlAttributes, but have to be set
            foreach (KeyList presetItem in presetData)
            {
                //finding none existing attribute
                if (xmlAttributes.FindIndex(x => x.Equals(presetItem.keyName)) == -1)
                {
                    // Setting Name of XML-Attribute
                    KeyList outputItem = new KeyList(presetItem.keyName);
                    // Set values for key
                    for (int i = 0; i <= maxLength; i++)
                    {
                        outputItem.keyValues.Add(presetItem.keyValues[i]);
                    }
                    outputData.Add(outputItem);
                }
            }
            #endregion

            return(outputData);
        }