コード例 #1
0
        public Command Create()
        {
            var command = new Command("emoticon", "can show an emoticon");

            command.AddArgument(new Argument <string>("name"));
            command.AddOption(new Option(new string[] { "--verbose", "-v" }, "if provided, it will also print the name of the emoticon")
            {
                Argument = new Argument <bool>(() => false)
            });

            command.Handler = CommandHandler.Create <string, bool>(((name, verbose) =>
            {
                if (verbose)
                {
                    var emoji = _emoticons.Get(name);
                    Console.WriteLine($"{emoji.Name,20} {emoji.Emoji}");
                }
                else
                {
                    Console.WriteLine(_emoticons.Get(name));
                }
            }));

            return(command);
        }
コード例 #2
0
        private V GetAndCacheValue(K key)
        {
            V value = retriever.Get(key);

            if (value == null)
            {
                value = (V)NULL;
            }
            lock (cache) {
                cache[key] = value;
            }
            return(value);
        }
コード例 #3
0
        public BaseHandlerModule(IRetriever readonlyRepository, IMessageHandlerFactory messageHandlerFactory, IPersistStuff persister)
        {
            _messageHandlerFactory = messageHandlerFactory;
            _persister             = persister;
            this.RequiresHttps(true, null);
            Get["/{environment?dev}/{provider}"] = parameters =>
            {
                try
                {
                    var model = readonlyRepository.Get((string)parameters.environment, (string)parameters.provider);

                    var viewModel = new ViewModel
                    {
                        ConfigureModel = model,
                    };

                    return(View[viewModel]);
                }
                catch (Exception ex)
                {
                    return(ErrorResponse.FromException(ex).WithStatusCode(500));
                }
            };
            Post["/{environment?dev}/{provider}"] = parameters =>
            {
                var configureModel = readonlyRepository.Get(parameters.environment, parameters.provider) as ConfigureModel;

                string contents  = Respond(Request.Body, configureModel, parameters.provider);
                var    byteArray = Encoding.UTF8.GetBytes(contents);
                var    stream    = new MemoryStream(byteArray);
                return(Response.FromStream(stream, "text/xml; charset=utf-8"));
            };
            Post["/{environment?dev}/{provider}/Update"] = parameters =>
            {
                UpdateConfiguration(parameters.provider, parameters.environment);
                return(Response.AsRedirect($"/{(string) parameters.environment}/{(string) parameters.provider}"));
            };
        }