Ejemplo n.º 1
0
        public AppResult <IEnumerable <string> > Execute(IEnumerable <MethodInfo> commands, IEnumerable <string> options, Action beforeExecution)
        {
            AppResult <IEnumerable <string> > rtn = default;

            if (!commands?.Any() ?? true)
            {
                throw new ArgumentNullException(nameof(commands));
            }
            if (!options?.Any() ?? true)
            {
                throw new ArgumentNullException(nameof(options));
            }
            AppResult <IEnumerable <string> > result = default;
            object specialValue = default;

            if (beforeExecution != default)
            {
                beforeExecution.Invoke();
            }

            foreach (var command in commands)
            {
                if ((command.Name == nameof(RemoteConfig)) && isConfigured)
                {
                    continue;
                }

                var parCount = command.GetParameters().Length;
                rtn = command.Invoke(repoCommandProcessor, options.Take(parCount).ToArray()) as AppResult <IEnumerable <string> >;

                if ((command.Name == nameof(RemoteConfig)) && rtn.IsSuccess)
                {
                    specialValue = RemoteConfig(rtn);
                    continue;
                }

                if (result == default)
                {
                    result = rtn;
                }
                else
                {
                    result.Add(rtn);
                }
            }
            if (result == default)
            {
                result = rtn;
            }
            result.SpecialValue = specialValue;
            return(result);
        }