Example #1
0
        public Application(IRGBFusionMotherboard motherboardLEDs, IRGBFusionPeripherals peripheralLEDs, TextWriter stdout, TextWriter stderr)
        {
            this.motherboardLEDs = motherboardLEDs;
            this.peripheralLEDs  = peripheralLEDs;
            this.stdout          = stdout;
            this.stderr          = stderr;

            context = new ApplicationContext();

            defaultZone     = new List <string>();
            currentZone     = defaultZone;
            peripheralsArgs = new List <string>();

            genericOptions = new OptionSet
            {
                { string.Format("Usage: {0} [OPTION]... [[LEDSETTING] | [ZONE LEDSETTING]...] [peripherals GVSETTING]", AppDomain.CurrentDomain.FriendlyName) },
                { "Set RGB Fusion motherboard LEDs" },
                { "" },
                { "Options:" },
                { "v|verbose", v => context.verbosity++ },
                { "l|list", "list zones", v => context.flag_List = true },
                { "?|h|help", "show help and exit", v => context.flag_Help = true },
                { "version", "show version information and exit", v => context.flag_Version = true },
                { "" }
            };

            zoneOptions = new OptionSet
            {
                { "ZONE:" },
                { "z|zone=", "set zone", (int zone) => {
                      if (zone < 0)
                      {
                          throw new InvalidOperationException("Zones must be positive integers");
                      }
                      if (zones.ContainsKey(zone))
                      {
                          throw new InvalidOperationException(string.Format("Zone {0} already specified", zone));
                      }
                      if (zone >= motherboardLEDs.Layout.Length)
                      {
                          throw new InvalidOperationException(string.Format("Zone is {0}, max supported is {1}", zone, motherboardLEDs.Layout.Length));
                      }
                      currentZone = new List <string>();
                      zones.Add(zone, currentZone);
                  } },
                { "PERIPHERALS:" },
                { "peripherals", "set peripherals", v => {
                      currentZone     = new List <string>();
                      peripheralsArgs = currentZone;
                  } },
                { "<>", v => currentZone.Add(v) },
            };

            ledSettingArgParsers = new List <LedSettingArgParser <LedSetting> >
            {
                new StaticColorArgParser(),
                new ColorCycleArgParser(),
                new PulseArgParser(),
                new FlashArgParser(),
                new DigitalAArgParser(),
                new DigitalBArgParser(),
                new DigitalCArgParser(),
                new DigitalDArgParser(),
                new DigitalEArgParser(),
                new DigitalFArgParser(),
                new DigitalGArgParser(),
                new DigitalHArgParser(),
                new DigitalIArgParser(),
                new OffArgParser(),
            };

            gvLedSettingArgParsers = new List <LedSettingArgParser <GvLedSetting> >
            {
                new OffGvArgParser(),
                new StaticColorGvArgParser(),
                new ColorCycleGvArgParser()
            };

            helpOptionSets = new List <OptionSet>
            {
                genericOptions,
                zoneOptions,
                new OptionSet {
                    ""
                },
                new OptionSet {
                    "LEDSETTING options:"
                }
            };
            foreach (LedSettingArgParser <LedSetting> argParser in ledSettingArgParsers)
            {
                helpOptionSets.Add(new OptionSet {
                    ""
                });
                helpOptionSets.Add(argParser.RequiredOptions);
                helpOptionSets.Add(argParser.ExtraOptions);
            }
            helpOptionSets.Add(new OptionSet {
                ""
            });
            helpOptionSets.Add(new OptionSet {
                "GVSETTING options:"
            });
            foreach (LedSettingArgParser <GvLedSetting> argParser in gvLedSettingArgParsers)
            {
                helpOptionSets.Add(new OptionSet {
                    ""
                });
                helpOptionSets.Add(argParser.RequiredOptions);
                helpOptionSets.Add(argParser.ExtraOptions);
            }
        }
Example #2
0
 public void Setup()
 {
     mock        = new GvLedLibv1_0Mock();
     peripherals = new RGBFusionPeripherals(new GvLedLibDotNet.Raw.GvLedLibv1_0Wrapper(mock));
 }