Exemplo n.º 1
0
        public void SetAll()
        {
            peripherals.SetAll(new ColorCycleGvLedSetting(1, 10));

            foreach (GVLED_CFG ledSetting in mock.Settings)
            {
                GvLedSettingTests.AssertGVLedStructEqual(SettingStructs.ColorCycleA, ledSetting);
            }
        }
Exemplo n.º 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 < peripheralLEDs.Devices.Length; i++)
                    {
                        stdout.WriteLine("Peripheral {0}: {1}", i, peripheralLEDs.Devices[i]);
                    }
                    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 && peripheralsArgs.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())));
                }

                if (defaultZone.Count > 0)
                {
                    LedSetting setting = null;
                    foreach (LedSettingArgParser <LedSetting> 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;
                }
                else if (zones.Count > 0)
                {
                    foreach (int zone in zones.Keys)
                    {
                        LedSetting setting = null;
                        foreach (LedSettingArgParser <LedSetting> 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)
                        {
                            stdout.WriteLine("Set zone {0}: {1}", zone, motherboardLEDs.LedSettings[zone]);
                        }
                    }

                    motherboardLEDs.Set(zones.Keys);
                }

                if (peripheralsArgs.Count > 0)
                {
                    GvLedSetting setting = null;
                    foreach (LedSettingArgParser <GvLedSetting> parser in gvLedSettingArgParsers)
                    {
                        setting = parser.TryParse(peripheralsArgs);
                        if (setting != null)
                        {
                            break;
                        }
                    }

                    if (setting == null)
                    {
                        throw new InvalidOperationException("No Peripheral LED mode specified");
                    }

                    if (context.verbosity > 0)
                    {
                        stdout.WriteLine("Set All Peripherals: {0}", setting);
                    }
                    peripheralLEDs.SetAll(setting);
                    return;
                }
            }
            catch (Exception e)
            {
                ShowHelp(stderr);
                stderr.WriteLine();
                stderr.WriteLine("Error: {0}", e.ToString());
                throw;
            }
            return;
        }