Exemplo n.º 1
0
        /// <summary>
        /// Internal method to add a new DictionaryConfiguration
        /// </summary>
        /// <returns><c>true</c>, if dictionary config was added, <c>false</c> otherwise.</returns>
        /// <param name="toAdd">the DicConfiguration to add</param>
        internal bool AddDicConf(DicConfiguration toAdd)
        {
            this.Log().Debug(string.Format("trying to add Dictionary configuration: {0}", toAdd.header));
            bool found = false;

            if (toAdd.header == "")
            {
                this.Log().Debug("Header is empty");
                return(false);
            }

            if (toAdd.dicto.Count == 0)
            {
                this.Log().Debug("Dictionary is empty");
                return(false);
            }

            foreach (DicConfiguration d in content)
            {
                if (d.header.ToLower() == toAdd.header.ToLower())
                {
                    this.Log().Debug("Found the Dictionary Confiuguration");
                    found = true;
                }
            }

            if (!found)
            {
                this.Log().Debug(string.Format("Adding toAdd: {0}", toAdd.header));
                content.Add(toAdd);
                isEmpty = false;
            }

            return(!found);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method to add an input in the DicConfiguration
        /// </summary>
        /// <returns><c>true</c>, if the entry was added, <c>false</c> otherwise.</returns>
        /// <param name="header">Header.</param>
        /// <param name="variable">Variable.</param>
        /// <param name="value">Value.</param>
        public bool AddDicEntry(string header, string variable, string value)
        {
            this.Log().Debug(string.Format("Trying to add a dictionary entry with params: header: {0}, variable: {1}, value: {2}", header, variable, value));

            Stack <DicConfiguration> old = new Stack <DicConfiguration> ();
            bool found = false;

            foreach (DicConfiguration d in content)
            {
                if (!found)
                {
                    if (d.header.ToLower() == header.ToLower())
                    {
                        DicConfiguration newOne = d;
                        if (!d.dicto.ContainsKey(variable))
                        {
                            this.Log().Debug("Found the dictionary entry, replacing it with the new content.");
                            found = true;
                            newOne.dicto.Add(variable, value);
                        }
                        else
                        {
                            // we already have that variable. exit
                            this.Log().Debug("Found the dictionary entry, which contains the variable already. Aborting.");
                            return(false);
                        }
                        old.Push(newOne);
                    }
                    else
                    {
                        old.Push(d);
                    }
                }
                else
                {
                    old.Push(d);
                }
            }

            if (found)
            {
                // replace the dicConfig list with the stack
                content = new List <DicConfiguration> ();
                foreach (DicConfiguration d in old)
                {
                    content.Add(d);
                }
            }

            return(found);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Internal method to convert a List of string to a set of DicConfiguration.
        /// </summary>
        /// <param name="rawData">Raw list of string input</param>
        private void ConvertToDictionary(List <string> rawData)
        {
            this.Log().Debug("Filling the Dictionary");
            DicConfiguration current = new DicConfiguration();

            foreach (string s in rawData)
            {
                if (s.Length == 0)
                {
                    this.Log().Debug("Empty string, skipping");
                    continue;
                }

                if (IsLineComment(s))
                {
                    // skip line
                    this.Log().Debug("Comment line, skipping");
                    continue;
                }

                if (IsHeader(s))
                {
                    this.Log().Debug(string.Format("Current line is a header: {0}", s));
                    // save the old one if not empty
                    if (current.dicto.Count > 0)
                    {
                        this.Log().Debug(string.Format("Adding current: {0}", current.header));
                        content.Add(current);
                    }

                    // make a new one
                    current = new DicConfiguration(s.Substring(1, s.Length - 2));

                    // next
                    continue;
                }

                // not comment nor header. config!
                string[] splitData = s.Split("=".ToCharArray(0, 1));
                if (splitData.GetLength(0) == 2)
                {
                    this.Log().Debug(string.Format("Adding to current: {0}={1}", splitData[0], splitData[1]));
                    current.dicto.Add(splitData[0], splitData[1]);
                }
                else
                {
                    //invalid format. skipping
                    this.Log().Warn("invalid format for line: " + s);
                }
            }

            // if we have leftovers to save
            if (current.dicto.Count > 0)
            {
                this.Log().Debug(string.Format("Adding current: {0}", current.header));
                content.Add(current);
            }

            // set the isEmpty flag
            isEmpty = (content.Count == 0);
        }