コード例 #1
0
        public HotKeysBuilder WithArgs(IEnumerable <string> args)
        {
            Option hkToggleOpt   = new Option("ht", "hotkey-toggle", "Hotkey to toggle between play and pause", false, -1, 2);
            Option hkNextOpt     = new Option("hn", "hotkey-next", "Hotkey to set next Media", false, -1, 2);
            Option hkPreviousOpt = new Option("hp", "hotkey-previous", "Hotkey to set previous Media", false, -1, 2);
            Option hkPlayOpt     = Option.GetLongOnly("hotkey-play", "Hotkey to set the play state to play", false, -1, 2);
            Option hkPauseOpt    = Option.GetLongOnly("hotkey-pause", "Hotkey to set the play state to pause", false, -1, 2);
            Option hkRestartOpt  = Option.GetLongOnly("hotkey-restart", "Hotkey to restart the current media", false, -1, 2);

            Options           options = new Options(hkToggleOpt, hkNextOpt, hkPreviousOpt);
            OptionParseResult result  = options.Parse(args);

            OptionParsed p;
            HotKey       hk;

            if (result.TryGetFirstValidOptionParseds(hkToggleOpt, out p) && TryGetHotKey(p, out hk))
            {
                toggle = hk;
            }
            if (result.TryGetFirstValidOptionParseds(hkNextOpt, out p) && TryGetHotKey(p, out hk))
            {
                next = hk;
            }
            if (result.TryGetFirstValidOptionParseds(hkPreviousOpt, out p) && TryGetHotKey(p, out hk))
            {
                previous = hk;
            }
            if (result.TryGetFirstValidOptionParseds(hkPlayOpt, out p) && TryGetHotKey(p, out hk))
            {
                play = hk;
            }
            if (result.TryGetFirstValidOptionParseds(hkPauseOpt, out p) && TryGetHotKey(p, out hk))
            {
                pause = hk;
            }
            if (result.TryGetFirstValidOptionParseds(hkRestartOpt, out p) && TryGetHotKey(p, out hk))
            {
                restart = hk;
            }

            return(this);
        }
コード例 #2
0
        public ServiceBuilder WithArgs(IEnumerable <string> args)
        {
            Option clientOpt = new Option("c", "client",
                                          "Starts the app as client with the following server adresse and port", false, 2, 1);
            Option serverOpt  = new Option("s", "server", "Starts the app as server with the following port", false, 1, 1);
            Option sourcesOpt = new Option("m", "media-sources", "Files and diretories to play", false, -1, 0);
            Option ifNonOpt   = new Option("i", "if-non",
                                           "If given the Media sources are only used if there are non", false, 0, 0);
            Option reloadOpt        = new Option("r", "reload", "Forces to reload", false, 0, 0);
            Option allShuffleOpt    = Option.GetLongOnly("all-shuffle", "Shuffles all songs.", false, 0, 0);
            Option searchShuffleOpt = Option.GetLongOnly("search-shuffle", "Shuffles all songs.", false, 0, 0);
            Option onlySearchOpt    = Option.GetLongOnly("only-search", "Shuffles all songs.", false, 0, 0);
            Option searchKeyOpt     = Option.GetLongOnly("search-key", "Shuffles all songs.", false, 1, 0);
            Option playOpt          = new Option("p", "play", "Starts playback on startup", false, 0, 0);
            Option serviceVolOpt    = new Option("v", "volume", "The volume of service (value between 0 and 1)", false, 1, 1);
            Option streamingOpt     = Option.GetLongOnly("stream", "If given the audio is streamed to the client", false, 0, 0);
            Option clientVolOpt     = Option.GetLongOnly("client-volume",
                                                         "The volume of client for streaming (value between 0 and 1)", false, 1, 1);

            Options           options = new Options(sourcesOpt, ifNonOpt, reloadOpt, clientOpt, serverOpt, playOpt);
            OptionParseResult result  = options.Parse(args);

            int          port;
            float        volume;
            OptionParsed parsed;

            if (result.TryGetFirstValidOptionParseds(serverOpt, out parsed) &&
                int.TryParse(parsed.Values[0], out port))
            {
                WithServer(port);
            }

            if (result.TryGetFirstValidOptionParseds(clientOpt, out parsed))
            {
                string serverAddress = parsed.Values[0];

                if (parsed.Values.Count > 1 && int.TryParse(parsed.Values[1], out port))
                {
                    WithClient(serverAddress, port);
                }
                else
                {
                    WithClient(serverAddress);
                }
            }

            if (result.HasValidOptionParseds(sourcesOpt))
            {
                WithMediaSources(result.GetValidOptionParseds(sourcesOpt).SelectMany(p => p.Values).ToArray());
            }

            if (result.TryGetFirstValidOptionParseds(allShuffleOpt, out parsed))
            {
                WithIsAllShuffle();
            }
            if (result.TryGetFirstValidOptionParseds(searchShuffleOpt, out parsed))
            {
                WithIsSearchShuffle();
            }
            if (result.TryGetFirstValidOptionParseds(onlySearchOpt, out parsed))
            {
                WithIsOnlySearch();
            }
            if (result.TryGetFirstValidOptionParseds(searchKeyOpt, out parsed))
            {
                WithSearchKey(parsed.Values.FirstOrDefault());
            }
            if (result.HasValidOptionParseds(ifNonOpt))
            {
                WithSetMediaIfNon();
            }
            if (result.HasValidOptionParseds(reloadOpt))
            {
                WithReload();
            }
            if (result.HasValidOptionParseds(playOpt))
            {
                WithPlay();
            }

            if (result.TryGetFirstValidOptionParseds(serviceVolOpt, out parsed) &&
                float.TryParse(parsed.Values[0], out volume))
            {
                WithVolume(volume);
            }

            if (result.HasValidOptionParseds(streamingOpt))
            {
                WithIsStreaming();
            }

            if (result.TryGetFirstValidOptionParseds(clientVolOpt, out parsed) &&
                float.TryParse(parsed.Values[0], out volume))
            {
                WithClientVolume(volume);
            }

            return(this);
        }