Ejemplo n.º 1
0
        public static Boolean TryParse(List <string> crozzleFileFragment, out FileFragment <CrozzleFileItem> aCrozzleFileFragment)
        {
            Errors = new List <String>();
            crozzleFileFragment.RemoveAll(s => String.IsNullOrEmpty(s));
            aCrozzleFileFragment = new FileFragment <CrozzleFileItem>();

            String   formattedLine = String.Empty;
            DataKeys flag          = DataKeys.UNDEFINED;

            foreach (String line in crozzleFileFragment)
            {
                /// Discard comment and trim possible whitespace.
                if (line.Contains("//"))
                {
                    int index = line.IndexOf("//");
                    formattedLine = line.Remove(index);
                }
                else
                {
                    formattedLine = line;
                }
                formattedLine = formattedLine.Trim();

                CrozzleFileItem aCrozzleFileItem = new CrozzleFileItem(formattedLine);

                if (Regex.IsMatch(formattedLine, @"^\s*$"))
                {
                    continue;
                }
                else if (Regex.IsMatch(formattedLine, ForeignCharacters))
                {
                    Errors.Add(String.Format(ConfigurationFileItemErrors.SymbolError, aCrozzleFileItem));
                }
                else
                {
                    /// TODO: switch case with flag
                    switch (flag)
                    {
                    case DataKeys.UNDEFINED:
                        /// fragment specification
                        if (Regex.IsMatch(formattedLine, @"^" + FileDependenciesKeys.OpenBracket + @".*"))
                        {
                            flag = DataKeys.DEPENDENCIES;
                            aCrozzleFileFragment.Name = FileDependenciesKeys.OpenBracket;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + CrozzleSizeKeys.OpenBracket + @".*"))
                        {
                            flag = DataKeys.SIZE;
                            aCrozzleFileFragment.Name = CrozzleSizeKeys.OpenBracket;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + HorizontalSequenceKeys.OpenBracket + @".*"))
                        {
                            flag = DataKeys.HORZSEQUENCE;
                            aCrozzleFileFragment.Name = HorizontalSequenceKeys.OpenBracket;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + VerticalSequenceKeys.OpenBracket + @".*"))
                        {
                            flag = DataKeys.VERTSEQUENCE;
                            aCrozzleFileFragment.Name = VerticalSequenceKeys.OpenBracket;
                        }
                        break;

                    case DataKeys.DEPENDENCIES:
                        if (Regex.IsMatch(formattedLine, @"^" + FileDependenciesKeys.ConfigFileName + @".*"))
                        {
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, FileDependenciesKeys.ConfigFileName, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aCrozzleFileItem.Name     = FileDependenciesKeys.ConfigFileName;
                            aCrozzleFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + FileDependenciesKeys.SequenceFileName + @".*"))
                        {
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, FileDependenciesKeys.SequenceFileName, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aCrozzleFileItem.Name     = FileDependenciesKeys.SequenceFileName;
                            aCrozzleFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + FileDependenciesKeys.EndBracket + @".*"))
                        {
                            flag = DataKeys.UNDEFINED;
                        }
                        break;

                    case DataKeys.SIZE:
                        if (Regex.IsMatch(formattedLine, @"^" + CrozzleSizeKeys.Size + @".*"))
                        {
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, CrozzleSizeKeys.Size, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aCrozzleFileItem.Name     = CrozzleSizeKeys.Size;
                            aCrozzleFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + CrozzleSizeKeys.EndBracket + @".*"))
                        {
                            flag = DataKeys.UNDEFINED;
                        }
                        break;

                    case DataKeys.HORZSEQUENCE:
                        if (Regex.IsMatch(formattedLine, @"^" + HorizontalSequenceKeys.Sequence + @".*"))
                        {
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, HorizontalSequenceKeys.Sequence, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aCrozzleFileItem.Name     = HorizontalSequenceKeys.Sequence;
                            aCrozzleFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + HorizontalSequenceKeys.EndBracket + @".*"))
                        {
                            flag = DataKeys.UNDEFINED;
                        }
                        break;

                    case DataKeys.VERTSEQUENCE:
                        if (Regex.IsMatch(formattedLine, @"^" + VerticalSequenceKeys.Sequence + @".*"))
                        {
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, VerticalSequenceKeys.Sequence, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aCrozzleFileItem.Name     = VerticalSequenceKeys.Sequence;
                            aCrozzleFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + VerticalSequenceKeys.EndBracket + @".*"))
                        {
                            flag = DataKeys.UNDEFINED;
                        }
                        break;
                    }

                    aCrozzleFileItem.Valid = Errors.Count == 0;
                    /// If the current line is the opening bracket to a fragment, do not add as a new item. Else, do so.
                    if (aCrozzleFileItem.Name != null)
                    {
                        aCrozzleFileFragment.AddNewItem(aCrozzleFileItem);
                    }
                }
            }
            /// FALSE TRUE FALSE
            /// FALSE FALSE TRUE
            return(!aCrozzleFileFragment.Items.Exists(item => item.Valid == false));
        }
        public static Boolean TryParse(List <String> configurationFileFragment, out FileFragment <ConfigurationFileItem> aConfigurationFileFragment)
        {
            Errors = new List <String>();
            configurationFileFragment.RemoveAll(s => String.IsNullOrEmpty(s));
            aConfigurationFileFragment = new FileFragment <ConfigurationFileItem>();

            String   formattedLine = String.Empty;
            DataKeys flag          = DataKeys.UNDEFINED;

            foreach (String line in configurationFileFragment)
            {
                /// Discard comment and trim possible whitespace.
                if (line.Contains("//"))
                {
                    int index = line.IndexOf("//");
                    formattedLine = line.Remove(index);
                }
                else
                {
                    formattedLine = line;
                }
                formattedLine = formattedLine.Trim();

                ConfigurationFileItem aConfigurationFileItem = new ConfigurationFileItem(formattedLine);

                if (Regex.IsMatch(formattedLine, @"^\s*$"))
                {
                    continue;
                }
                else if (Regex.IsMatch(formattedLine, ForeignCharacters))
                {
                    Errors.Add(String.Format(ConfigurationFileItemErrors.SymbolError, aConfigurationFileItem)); /// Checks if the line contains foreign characters
                }
                else
                {
                    switch (flag)
                    {
                    case DataKeys.UNDEFINED:
                        /// fragment specification.
                        if (Regex.IsMatch(formattedLine, @"^" + LogFileKeys.OpenBracket + @".*"))
                        {
                            flag = DataKeys.LOGFILE;
                            aConfigurationFileFragment.Name = LogFileKeys.OpenBracket;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + UniqueSequenceKeys.OpenBracket + @".*"))
                        {
                            flag = DataKeys.SEQUENCES;
                            aConfigurationFileFragment.Name = UniqueSequenceKeys.OpenBracket;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + CrozzleOutputKeys.OpenBracket + @".*"))
                        {
                            flag = DataKeys.OUTPUT;
                            aConfigurationFileFragment.Name = CrozzleOutputKeys.OpenBracket;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + CrozzleSizeKeys.OpenBracket + @".*"))
                        {
                            flag = DataKeys.SIZE;
                            aConfigurationFileFragment.Name = CrozzleSizeKeys.OpenBracket;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + DirectionalSequenceKeys.OpenBracket + @".*"))
                        {
                            flag = DataKeys.LIMITSEQUENCE;
                            aConfigurationFileFragment.Name = DirectionalSequenceKeys.OpenBracket;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + DirectionalIntersectionKeys.OpenBracket + @".*"))
                        {
                            flag = DataKeys.LIMITINTERSECT;
                            aConfigurationFileFragment.Name = DirectionalIntersectionKeys.OpenBracket;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + DuplicateSequenceKeys.OpenBracket + @".*"))
                        {
                            flag = DataKeys.DUPLICATE;
                            aConfigurationFileFragment.Name = DuplicateSequenceKeys.OpenBracket;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + ValidGroupKeys.OpenBracket + @".*"))
                        {
                            flag = DataKeys.VALIDGROUP;
                            aConfigurationFileFragment.Name = ValidGroupKeys.OpenBracket;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + IntersectionKeys.OpenBracket + @".*"))
                        {
                            flag = DataKeys.INTERSECT;
                            aConfigurationFileFragment.Name = IntersectionKeys.OpenBracket;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + NonIntersectionKeys.OpenBracket + @".*"))
                        {
                            flag = DataKeys.NONINTERSECT;
                            aConfigurationFileFragment.Name = NonIntersectionKeys.OpenBracket;
                        }
                        break;

                    case DataKeys.LOGFILE:
                        if (Regex.IsMatch(formattedLine, @"^" + LogFileKeys.FileName + @".*"))
                        {
                            /// get the LogFile key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, LogFileKeys.FileName, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = LogFileKeys.FileName;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + LogFileKeys.EndBracket + @".*"))
                        {
                            flag = DataKeys.UNDEFINED;
                        }
                        break;

                    case DataKeys.SEQUENCES:
                        if (Regex.IsMatch(formattedLine, @"^" + UniqueSequenceKeys.MinUnique + @".*"))
                        {
                            /// get the MinimumUniqueLetterSequences key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, UniqueSequenceKeys.MinUnique, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = UniqueSequenceKeys.MinUnique;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + UniqueSequenceKeys.MaxUnique + @".*"))
                        {
                            /// get the MaximumUniqueLetterSequences key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, UniqueSequenceKeys.MaxUnique, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = UniqueSequenceKeys.MaxUnique;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + UniqueSequenceKeys.EndBracket + @".*"))
                        {
                            flag = DataKeys.UNDEFINED;
                        }
                        break;

                    case DataKeys.OUTPUT:
                        if (Regex.IsMatch(formattedLine, @"^" + CrozzleOutputKeys.InvalidScore + @".*"))
                        {
                            /// get the InvalidCrozzleScore key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, CrozzleOutputKeys.InvalidScore, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = CrozzleOutputKeys.InvalidScore;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + CrozzleOutputKeys.Uppercase + @".*"))
                        {
                            /// get the Uppercase key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, CrozzleOutputKeys.Uppercase, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = CrozzleOutputKeys.Uppercase;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + CrozzleOutputKeys.Style + @".*"))
                        {
                            /// get the Style key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, CrozzleOutputKeys.Style, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = CrozzleOutputKeys.Style;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + CrozzleOutputKeys.BGColourEmptyTD + @".*"))
                        {
                            /// get the BGColourEmptyTD key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, CrozzleOutputKeys.BGColourEmptyTD, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = CrozzleOutputKeys.BGColourEmptyTD;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + CrozzleOutputKeys.BGColourNonEmptyTD + @".*"))
                        {
                            /// get the BGColourNonEmptyTD key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, CrozzleOutputKeys.BGColourNonEmptyTD, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = CrozzleOutputKeys.BGColourNonEmptyTD;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + CrozzleOutputKeys.EndBracket + @".*"))
                        {
                            flag = DataKeys.UNDEFINED;
                        }
                        break;

                    case DataKeys.SIZE:
                        if (Regex.IsMatch(formattedLine, @"^" + CrozzleSizeKeys.MinRows + @".*"))
                        {
                            /// get the MinimumCrozzleSizeRows key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, CrozzleSizeKeys.MinRows, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = CrozzleSizeKeys.MinRows;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + CrozzleSizeKeys.MaxRows + @".*"))
                        {
                            /// get the MaximumCrozzleSizeRows key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, CrozzleSizeKeys.MaxRows, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = CrozzleSizeKeys.MaxRows;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + CrozzleSizeKeys.MinCols + @".*"))
                        {
                            /// get the MinimumCrozzleSizeColumns key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, CrozzleSizeKeys.MinCols, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = CrozzleSizeKeys.MinCols;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + CrozzleSizeKeys.MaxCols + @".*"))
                        {
                            /// get the MaximumCrozzleSizeColumns key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, CrozzleSizeKeys.MaxCols, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = CrozzleSizeKeys.MaxCols;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + CrozzleSizeKeys.EndBracket + @".*"))
                        {
                            flag = DataKeys.UNDEFINED;
                        }
                        break;

                    case DataKeys.LIMITSEQUENCE:
                        if (Regex.IsMatch(formattedLine, @"^" + DirectionalSequenceKeys.MinHorz + @".*"))
                        {
                            /// get the MinimumHorizontalSequences key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, DirectionalSequenceKeys.MinHorz, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = DirectionalSequenceKeys.MinHorz;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + DirectionalSequenceKeys.MaxHorz + @".*"))
                        {
                            /// get the MaximumHorizontalSequences key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, DirectionalSequenceKeys.MaxHorz, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = DirectionalSequenceKeys.MaxHorz;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + DirectionalSequenceKeys.MinVert + @".*"))
                        {
                            /// get the MinimumVerticalSequences key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, DirectionalSequenceKeys.MinVert, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = DirectionalSequenceKeys.MinVert;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + DirectionalSequenceKeys.MaxVert + @".*"))
                        {
                            /// get the MaximumVerticalSequences key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, DirectionalSequenceKeys.MaxVert, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = DirectionalSequenceKeys.MaxVert;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + DirectionalSequenceKeys.EndBracket + @".*"))
                        {
                            flag = DataKeys.UNDEFINED;
                        }
                        break;

                    case DataKeys.LIMITINTERSECT:
                        if (Regex.IsMatch(formattedLine, @"^" + DirectionalIntersectionKeys.MinHorz + @".*"))
                        {
                            /// get the MinimumHorizontalIntersections key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, DirectionalIntersectionKeys.MinHorz, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = DirectionalIntersectionKeys.MinHorz;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + DirectionalIntersectionKeys.MaxHorz + @".*"))
                        {
                            /// get the MaximumHorizontalIntersections key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, DirectionalIntersectionKeys.MaxHorz, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = DirectionalIntersectionKeys.MaxHorz;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + DirectionalIntersectionKeys.MinVert + @".*"))
                        {
                            /// get the MinimumVerticalIntersections key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, DirectionalIntersectionKeys.MinVert, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = DirectionalIntersectionKeys.MinVert;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + DirectionalIntersectionKeys.MaxVert + @".*"))
                        {
                            /// get the MaximumVerticalIntersections key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, DirectionalIntersectionKeys.MaxVert, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = DirectionalIntersectionKeys.MaxVert;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + DirectionalIntersectionKeys.EndBracket + @".*"))
                        {
                            flag = DataKeys.UNDEFINED;
                        }
                        break;

                    case DataKeys.DUPLICATE:
                        if (Regex.IsMatch(formattedLine, @"^" + DuplicateSequenceKeys.MinDupe + @".*"))
                        {
                            /// get the MinimumDuplicateSequences key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, DuplicateSequenceKeys.MinDupe, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = DuplicateSequenceKeys.MinDupe;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + DuplicateSequenceKeys.MaxDupe + @".*"))
                        {
                            /// get the MaximumDuplicateSequences key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, DuplicateSequenceKeys.MaxDupe, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = DuplicateSequenceKeys.MaxDupe;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + DuplicateSequenceKeys.EndBracket + @".*"))
                        {
                            flag = DataKeys.UNDEFINED;
                        }
                        break;

                    case DataKeys.VALIDGROUP:
                        if (Regex.IsMatch(formattedLine, @"^" + ValidGroupKeys.MinValidGroup + @".*"))
                        {
                            /// get the MinimumValidGroups key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, ValidGroupKeys.MinValidGroup, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = ValidGroupKeys.MinValidGroup;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + ValidGroupKeys.MaxValidGroup + @".*"))
                        {
                            /// get the MaximumValidGroups key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, ValidGroupKeys.MaxValidGroup, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = ValidGroupKeys.MaxValidGroup;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + ValidGroupKeys.EndBracket + @".*"))
                        {
                            flag = DataKeys.UNDEFINED;
                        }
                        break;

                    case DataKeys.INTERSECT:
                        if (Regex.IsMatch(formattedLine, AtoZ))
                        {
                            /// get the AtoZ key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, AtoZ, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = aKeyValue.Key;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + IntersectionKeys.EndBracket + @".*"))
                        {
                            flag = DataKeys.UNDEFINED;
                        }
                        break;

                    case DataKeys.NONINTERSECT:
                        if (Regex.IsMatch(formattedLine, AtoZ))
                        {
                            /// get the AtoZ key-value pair.
                            KeyValue aKeyValue;
                            if (!KeyValue.TryParse(formattedLine, AtoZ, out aKeyValue))
                            {
                                Errors.AddRange(KeyValue.Errors);
                            }
                            aConfigurationFileItem.Name     = aKeyValue.Key;
                            aConfigurationFileItem.KeyValue = aKeyValue;
                        }
                        else if (Regex.IsMatch(formattedLine, @"^" + NonIntersectionKeys.EndBracket + @".*"))
                        {
                            flag = DataKeys.UNDEFINED;
                        }
                        break;
                    }
                }

                aConfigurationFileItem.Valid = Errors.Count == 0;
                /// If the current line is the opening bracket to a fragment, do not add as a new item. Else, do so.
                if (aConfigurationFileItem.Name != null)
                {
                    aConfigurationFileFragment.AddNewItem(aConfigurationFileItem);
                }
            }
            /// FALSE TRUE FALSE
            /// FALSE FALSE TRUE
            return(!aConfigurationFileFragment.Items.Exists(item => item.Valid == false));
        }