示例#1
0
        public override GenericResult ValidateArguments(CommandArguments args)
        {
            if (!args.ContainsKey("Key") || string.IsNullOrWhiteSpace(args["Key"]) ||
                !args.ContainsKey("Member") || string.IsNullOrWhiteSpace(args["Member"]))
            {
                return(new GenericResult().WithError("ERR wrong number of arguments for 'zrank' command"));
            }

            return(new GenericResult().Valid());
        }
示例#2
0
        public override GenericResult ValidateArguments(CommandArguments args)
        {
            if (!args.ContainsKey("Key") || string.IsNullOrWhiteSpace(args["Key"]) ||
                !args.ContainsKey("Score") || string.IsNullOrWhiteSpace(args["Score"]) ||
                !args.ContainsKey("Member") || string.IsNullOrWhiteSpace(args["Member"]))
            {
                return(new GenericResult().WithError("ERR wrong number of arguments for 'zadd' command"));
            }

            if (!float.TryParse(args["Score"], out float score))
            {
                return(new GenericResult().Invalid().WithError("ERR value is not a valid float"));
            }

            return(base.ValidateArguments(args));
        }
示例#3
0
        public override EvaluationResult Evaluate(IDatabase database, CommandArguments args)
        {
            var key   = args["Key"];
            var value = args["Value"];

            DateTimeOffset?ttl = null;

            if (args.ContainsKey("TTL"))
            {
                if (!string.IsNullOrWhiteSpace(args["TTL"]))
                {
                    if (long.TryParse(args["TTL"], out long ticks))
                    {
                        ttl = new DateTimeOffset(new DateTime(ticks));
                    }
                }
            }

            GenericResult result;

            lock (lockObject)
                result = database.Save(key, new DatabaseValue(value, ttl));

            return(new EvaluationResult(result.IsValid ? "OK" : "NOK"));
        }
示例#4
0
        public override GenericResult ValidateArguments(CommandArguments args)
        {
            if (!args.ContainsKey("Key") || string.IsNullOrWhiteSpace(args["Key"]) ||
                !args.ContainsKey("Start") || string.IsNullOrWhiteSpace(args["Start"]) ||
                !args.ContainsKey("Stop") || string.IsNullOrWhiteSpace(args["Stop"]))
            {
                return(new GenericResult().WithError("ERR wrong number of arguments for 'zrange' command"));
            }

            if (!int.TryParse(args["Start"], out int start))
            {
                return(new GenericResult().Invalid().WithError("ERR value is not an integer or out of range"));
            }

            if (!int.TryParse(args["Stop"], out int stop))
            {
                return(new GenericResult().Invalid().WithError("ERR value is not an integer or out of range"));
            }

            return(new GenericResult().Valid());
        }
示例#5
0
        /// <summary>
        /// Indicator that all required arguments are specified
        /// </summary>
        /// <returns></returns>
        protected bool RequiredArgumentsPresent()
        {
            var isValid = true;

            // check if the task was not created via command.
            //if not, arguments validity check presumed irrelavent/
            if (CommandArguments == null)
            {
                return(true);
            }

            foreach (var property in GetType().GetProperties())
            {
                var paramIsRequired = false;

                var attributes = property.GetCustomAttributes(true);

                foreach (var attrib in attributes)
                {
                    if (attrib is ArgumentHelp)
                    {
                        var attr = (ArgumentHelp)attrib;
                        paramIsRequired = attr.IsRequired;
                        if (paramIsRequired && !CommandArguments.ContainsKey(property.Name))
                        {
                            Console.WriteLine(
                                string.IsNullOrEmpty(attr.ErrorText) ? "{0} is required." : attr.ErrorText
                                , property.Name);
                            isValid = false;
                            break;
                        }
                    }
                    else if (attrib is RequiredArgument)
                    {
                        paramIsRequired = true;
                        if (!CommandArguments.ContainsKey(property.Name))
                        {
                            Console.WriteLine($" ** {property.Name} is a required parameter\n.");
                            isValid = false;
                            break;
                        }
                    }
                }
            }
            return(isValid);
        }