Exemple #1
0
 private void ResolveRGBColors()
 {
     foreach (TableConfig TC in TableConfigurations)
     {
         foreach (TableConfigColumn C in TC.Columns)
         {
             foreach (TableConfigSetting S in C)
             {
                 if (ColorConfigurations.Any(CC => CC.Name.Equals(S.ColorName, StringComparison.InvariantCultureIgnoreCase)))
                 {
                     S.ColorConfig = ColorConfigurations.First(CC => CC.Name.Equals(S.ColorName, StringComparison.InvariantCultureIgnoreCase));
                 }
             }
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Parses the ledcontrol.ini file.
        /// </summary>
        /// <param name="LedControlIniFile">The ledcontrol.ini FileInfo object.</param>
        /// <param name="ThrowExceptions">if set to <c>true</c> [throw exceptions].</param>
        /// <exception cref="System.Exception">
        /// File {0} does not contain data.
        /// or
        /// Could not find {0} section in file {1}.
        /// or
        /// File {1} does not contain data in the {0} section.
        /// or
        /// Section {0} of file {1} does not have the same number of columns in all lines.
        /// </exception>
        private void ParseLedControlIni(FileInfo LedControlIniFile, bool ThrowExceptions = false)
        {
            string[] ColorStartStrings         = { "[Colors DOF]", "[Colors LedWiz]" };
            string[] OutStartStrings           = { "[Config DOF]", "[Config outs]" };
            string[] VariableStartStrings      = { "[Variables DOF]" };
            string[] VersionStartStrings       = { "[version]" };
            string[] TableVariableStartStrings = { "[TableVariables]" };;
            string   FileData = "";

            #region Read file
            try
            {
                FileData = General.FileReader.ReadFileToString(LedControlIniFile);
            }
            catch (Exception E)
            {
                Log.Exception("Could not read file {0}.".Build(LedControlIniFile), E);
                if (ThrowExceptions)
                {
                    throw new Exception("Could not read file {0}.".Build(LedControlIniFile), E);
                }
            }
            if (FileData.IsNullOrWhiteSpace())
            {
                Log.Warning("File {0} does not contain data.".Build(LedControlIniFile));
                if (ThrowExceptions)
                {
                    throw new Exception("File {0} does not contain data.".Build(LedControlIniFile));
                }
            }
            #endregion

            Dictionary <string, List <string> > Sections = new Dictionary <string, List <String> >();

            #region Read sections

            List <string> SectionData   = new List <string>();
            String        SectionHeader = null;
            foreach (string RawIniLine in FileData.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
            {
                string IniLine = RawIniLine.Trim();
                if (IniLine.Length > 0 && !IniLine.StartsWith("#"))
                {
                    if (IniLine.StartsWith("[") && IniLine.EndsWith("]") && IniLine.Length > 2)
                    {
                        //This is a section header
                        if (!SectionHeader.IsNullOrWhiteSpace())
                        {
                            if (Sections.ContainsKey(SectionHeader))
                            {
                                int Cnt = 2;
                                while (Sections.ContainsKey("{0} {1}".Build(SectionHeader, Cnt)))
                                {
                                    Cnt++;
                                    if (Cnt > 999)
                                    {
                                        throw new Exception("Section header {0} exists to many times.".Build(SectionHeader));
                                    }
                                }
                                SectionHeader = "{0} {1}".Build(SectionHeader, Cnt);
                            }
                            Sections.Add(SectionHeader, SectionData);
                            SectionData = new List <string>();
                        }
                        SectionHeader = IniLine;
                    }
                    else
                    {
                        //Its a data line
                        SectionData.Add(IniLine);
                    }
                }
            }

            if (!SectionHeader.IsNullOrWhiteSpace())
            {
                if (Sections.ContainsKey(SectionHeader))
                {
                    int Cnt = 2;
                    while (Sections.ContainsKey("{0} {1}".Build(SectionHeader, Cnt)))
                    {
                        Cnt++;
                        if (Cnt > 999)
                        {
                            throw new Exception("Section header {0} exists to many times.".Build(SectionHeader));
                        }
                    }
                    SectionHeader = "{0} {1}".Build(SectionHeader, Cnt);
                }
                Sections.Add(SectionHeader, SectionData);
                SectionData = new List <string>();
            }
            SectionData = null;
            #endregion

            FileData = null;

            List <string> ColorData         = GetSection(Sections, ColorStartStrings);
            List <string> OutData           = GetSection(Sections, OutStartStrings);
            List <string> VariableData      = GetSection(Sections, VariableStartStrings);
            List <string> VersionData       = GetSection(Sections, VersionStartStrings);
            List <string> TableVariableData = GetSection(Sections, TableVariableStartStrings);

            if (VersionData != null && VersionData.Count > 0)
            {
                MinDOFVersion = null;

                string MinDofVersionLine = VersionData.FirstOrDefault(S => S.ToLowerInvariant().StartsWith("mindofversion="));

                if (MinDofVersionLine != null)
                {
                    string MinDofVersionString = MinDofVersionLine.Substring("mindofversion=".Length);

                    try
                    {
                        MinDOFVersion = new Version(MinDofVersionString);
                    }
                    catch (Exception E)
                    {
                        Log.Exception("Could not parse line {1} from file {0}".Build(LedControlIniFile, MinDofVersionLine));
                        MinDOFVersion = null;
                    }
                    if (MinDOFVersion != null)
                    {
                        Log.Write("Min DOF Version is {0} for file {1}".Build(MinDOFVersion.ToString(), LedControlIniFile.Name));
                    }
                }
                else
                {
                    Log.Warning("No DOF version information found in file {0}.".Build(LedControlIniFile));
                }
            }
            else
            {
                Log.Warning("No version section found in file {0}.".Build(LedControlIniFile));
            }

            if (ColorData == null)
            {
                Log.Warning("Could not find color definition section in file {0}.".Build(LedControlIniFile));
                if (ThrowExceptions)
                {
                    throw new Exception("Could not find  color definition section in file {0}.".Build(LedControlIniFile));
                }
                return;
            }
            else if (ColorData.Count < 1)
            {
                Log.Warning("File {0} does not contain data in the color definition section.".Build(LedControlIniFile));
                if (ThrowExceptions)
                {
                    throw new Exception("File {0} does not contain data in the color definition section.".Build(LedControlIniFile));
                }
                return;
            }

            if (OutData == null)
            {
                Log.Warning("Could not find table config section in file {0}.".Build(LedControlIniFile));
                if (ThrowExceptions)
                {
                    throw new Exception("Could not find table config section section in file {1}.".Build(LedControlIniFile));
                }
                return;
            }
            else if (OutData.Count < 1)
            {
                Log.Warning("File {0} does not contain data in the table config section.".Build(LedControlIniFile));
                if (ThrowExceptions)
                {
                    throw new Exception("File {0} does not contain data in the table config section".Build(LedControlIniFile));
                }
                return;
            }

            if (VariableData != null)
            {
                ResolveVariables(OutData, VariableData);
            }

            if (TableVariableData != null)
            {
                ResolveTableVariables(OutData, TableVariableData);
            }



            ColorConfigurations.ParseLedControlData(ColorData, ThrowExceptions);

            TableConfigurations.ParseLedcontrolData(OutData, ThrowExceptions);

            //ResolveOutputNumbers();
            ResolveRGBColors();

            this.LedControlIniFile = LedControlIniFile;
        }