Ejemplo n.º 1
0
        public CustomRuntimeDefinedParameter(DynamicOption option) : base(option.Name, ActualParameterType(option.Type), new Collection <Attribute> {
            new ParameterAttribute()
        })
        {
            Options.Add(option);
            var values = option.PossibleValues.ToArray();

            if (!values.IsNullOrEmpty())
            {
                Attributes.Add(new ValidateSetAttribute(values));
            }
        }
Ejemplo n.º 2
0
        public ICancellableEnumerable <DynamicOption> GetDynamicOptions(OptionCategory operation, Object requestImpl)
        {
            requestImpl = requestImpl ?? new {
                IsCancelled = new IsCancelled(() => false)
            };

            var isCancelled = requestImpl.As <IsCancelled>();

            DynamicOption lastItem = null;
            var           list     = new List <string>();

            return(CallAndCollect <DynamicOption>(
                       result => Provider.GetDynamicOptions(operation.ToString(), ExtendRequest(requestImpl, new {
                YieldDynamicOption = new YieldDynamicOption((name, type, isRequired) => {
                    if (lastItem != null)
                    {
                        lastItem.PossibleValues = list.ToArray();
                        list = new List <string>();
                        result.Add(lastItem);
                    }

                    OptionType typ;

                    if (Enum.TryParse(type, true, out typ))
                    {
                        lastItem = new DynamicOption {
                            Category = operation,
                            Name = name,
                            Type = typ,
                            IsRequired = isRequired,
                            ProviderName = ProviderName,
                        };
                    }

                    return !(isCancelled() || result.IsCancelled);
                }),
                YieldKeyValuePair = new YieldKeyValuePair((key, value) => {
                    if (lastItem != null && lastItem.Name == key)
                    {
                        list.Add(value);
                    }
                    return !(isCancelled() || result.IsCancelled);
                })
            })), collection => {
                if (lastItem != null)
                {
                    lastItem.PossibleValues = list.ToArray();
                    collection.Add(lastItem);
                }
            }));
        }
Ejemplo n.º 3
0
 public void IncludeInParameterSet(DynamicOption option, bool isInvocation, IEnumerable <string> parameterSets)
 {
     foreach (var ps in parameterSets)
     {
         var parameterSetName = !string.IsNullOrWhiteSpace(ps) ? option.ProviderName + ":" + ps : option.ProviderName;
         if (Attributes.Select(each => each as ParameterAttribute).WhereNotNull().Any(each => each.ParameterSetName == parameterSetName))
         {
             continue;
         }
         Attributes.Add(
             new ParameterAttribute()
         {
             ParameterSetName = parameterSetName,
             Mandatory        = option.IsRequired
         });
     }
 }
Ejemplo n.º 4
0
        public CustomRuntimeDefinedParameter(DynamicOption option, bool isInvocation, IEnumerable <string> parameterSets)
            : base(option.Name, ActualParameterType(option.Type), new Collection <Attribute>())
        {
            if (isInvocation)
            {
                Attributes.Add(new ParameterAttribute());
            }
            else
            {
                IncludeInParameterSet(option, isInvocation, parameterSets);
            }

            Options.Add(option);
            var values = option.PossibleValues.ToArray();

            if (!values.IsNullOrEmpty())
            {
                Attributes.Add(new ValidateSetAttribute(values));
            }
        }
Ejemplo n.º 5
0
        private void _CreateAiDynamic(Info.AiInfo info)
        {
            var actions = new List <IAction>();

            foreach (var actioninfo in info.Actions)
            {
                var newAction = Actions.Create(actioninfo.RefAction);

                if (newAction == null)
                {
                    throw new NullReferenceException();
                }
                newAction.Initialize(actioninfo);
                actions.Add(newAction);
            }

            var considerations = new List <IConsideration>();

            foreach (var considerationinfo in info.Considerations)
            {
                var newConsideration = Considerations.Create(considerationinfo.RefConsideration);

                if (newConsideration == null)
                {
                    throw new NullReferenceException();
                }
                newConsideration.Initialize(considerationinfo);
                considerations.Add(newConsideration);
            }
            var options = new List <IOption>();

            foreach (var optionInfo in info.Options)
            {
                var action            = actions[optionInfo.ActionInfoIndex];
                var subConsiderations = new List <IConsideration>();
                foreach (var indexConsideration in optionInfo.ConsiderationInfoIndexes)
                {
                    subConsiderations.Add(considerations[indexConsideration]);
                }
                var newOption = new DynamicOption(action, subConsiderations, optionInfo);
                options.Add(newOption);
            }

            var behaviours = new List <IBehaviour>();

            foreach (var behaviourInfo in info.Behaviours)
            {
                var subOptions = new List <IOption>();
                foreach (var indexOption in behaviourInfo.OptionInfoIndexes)
                {
                    subOptions.Add(options[indexOption]);
                }
                var subConsiderations = new List <IConsideration>();
                foreach (var indexConsideration in behaviourInfo.ConsiderationInfoIndexes)
                {
                    subConsiderations.Add(considerations[indexConsideration]);
                }
                var newBehaviour = new DynamicBehaviours(subOptions, subConsiderations, behaviourInfo);
                behaviours.Add(newBehaviour);
            }

            var newAi = new DynamicAi(behaviours);

            AIs.Add(newAi);
        }