Exemple #1
0
        public void SetAll()
        {
            motherboard.SetAll(new StaticLedSetting(Color.Red, 50));

            TestHelper.AssertAllLeds(mock,
                                     LedSettingTests.SettingByteArrays.StaticRed50,
                                     GLedApiv1_0_0Mock.DEFAULT_MAXDIVISIONS);

            // Verify again
            motherboard.Set();

            TestHelper.AssertAllLeds(mock,
                                     LedSettingTests.SettingByteArrays.StaticRed50,
                                     GLedApiv1_0_0Mock.DEFAULT_MAXDIVISIONS);
        }
Exemple #2
0
        public void Main(string[] args)
        {
            context.SetDefaults();

            try
            {
                List <string> afterGeneric = genericOptions.Parse(args);

                if (context.flag_Help)
                {
                    ShowHelp(stdout);
                    return;
                }

                if (context.flag_Version)
                {
                    ShowVersion(stdout);
                    return;
                }

                zoneOptions.Parse(afterGeneric);

                if (context.flag_List || context.verbosity > 0)
                {
                    for (int i = 0; i < motherboardLEDs.Layout.Length; i++)
                    {
                        stdout.WriteLine("Zone {0}: {1}", i, motherboardLEDs.Layout[i]);
                    }
                }

                if (defaultZone.Count == 0 && zones.Count == 0)
                {
                    return;
                }
                else if (defaultZone.Count > 0 && zones.Count > 0)
                {
                    throw new InvalidOperationException(string.Format("Unexpected options {0} before zone-specific options", string.Join(" ", defaultZone.ToArray())));
                }

                foreach (int zone in zones.Keys)
                {
                    LedSetting setting = null;
                    foreach (LedSettingArgParser parser in ledSettingArgParsers)
                    {
                        setting = parser.TryParse(zones[zone]);
                        if (setting != null)
                        {
                            break;
                        }
                    }
                    motherboardLEDs.LedSettings[zone] = setting ?? throw new InvalidOperationException(string.Format("No LED mode specified for zone {0}", zone));
                }
                if (context.verbosity > 0)
                {
                    foreach (int zone in zones.Keys)
                    {
                        stdout.WriteLine("Set zone {0}: {1}", zone, motherboardLEDs.LedSettings[zone]);
                    }
                }
                if (zones.Count > 0)
                {
                    motherboardLEDs.Set(zones.Keys);
                }

                if (defaultZone.Count > 0)
                {
                    LedSetting setting = null;
                    foreach (LedSettingArgParser parser in ledSettingArgParsers)
                    {
                        setting = parser.TryParse(defaultZone);
                        if (setting != null)
                        {
                            break;
                        }
                    }

                    if (setting == null)
                    {
                        throw new InvalidOperationException("No LED mode specified");
                    }
                    if (context.verbosity > 0)
                    {
                        stdout.WriteLine("Set All: {0}", setting);
                    }
                    motherboardLEDs.SetAll(setting);
                    return;
                }
            }
            catch (Exception e)
            {
                ShowHelp(stderr);
                stderr.WriteLine();
                stderr.WriteLine("Error: {0}", e.ToString());
                throw;
            }
            return;
        }