public PresentedParameter Present(IParameterDescriptor param, Action updateCallback)
        {
            var textBox = new TextBox {
                MaxLength = param.ValueType == typeof(char) ? 1 : 128
            };

            textBox.TextChanged += (sender, args) => updateCallback();
            void Setter(object val) => textBox.Text = param.ConvertValueToString(val ?? "");
            object Getter() => param.ParseValueFromString(textBox.Text ?? "");

            void Updater(ParameterStateType state, bool value)
            {
                switch (state)
                {
                case ParameterStateType.Enabled:
                    textBox.IsEnabled = value;
                    break;

                case ParameterStateType.Valid:
                    textBox.Background = value ? Brushes.Transparent : new SolidColorBrush(ViewConstants.InvalidColor);
                    break;
                }
            }

            return(new PresentedParameter(param, textBox, new PresentedParameter.ParamDelegates(Getter, Setter, param.IsValid, Updater)));
        }
Exemplo n.º 2
0
            private IParameterDescriptor[] GetParameterArray(IParameterDescriptor parameter)
            {
                if (!parameter.Metadata.Contains(IncludedTimeUnitsProperty) && !parameter.Metadata.Contains(ExcludedTimeUnitsProperty))
                {
                    return(DefaultParameters);
                }
                if (_cache.TryGetValue(parameter, out var cachedParameters))
                {
                    return(cachedParameters);
                }
                var meta = new Context(Unit.Metadata);

                SelectablePresenter.SelectableValuesFuncProperty.Set(meta, p =>
                {
                    var list = new LinkedList <TimeUnit>();
                    list.AddAll(IncludedTimeUnitsProperty.TryGet(parameter.Metadata, out var included) ? included : Enum.GetValues(typeof(TimeUnit)).Cast <TimeUnit>());
                    if (ExcludedTimeUnitsProperty.TryGet(parameter.Metadata, out var excluded))
                    {
                        list.RemoveAll(excluded);
                    }
                    return(list.ToArray());
                });
                var parameters = new IParameterDescriptor[] { Length, new MetadataOverridenParameter(Unit, meta) };

                _cache.Add(parameter, parameters);
                return(parameters);
            }
 public InlineAdapter(IParameterDescriptor parameter, IParameterizedObjectFactory factory, Panel container, PresentedParameter[] subParameters)
 {
     _parameter     = parameter;
     _factory       = factory;
     _container     = container;
     _subParameters = subParameters;
 }
Exemplo n.º 4
0
        public PresentedParameter Present(IParameterDescriptor param, Action updateCallback)
        {
            void StateChangeHandler(object sender, RoutedEventArgs args) => updateCallback();

            var checkBox = new CheckBox
            {
                HorizontalAlignment      = HorizontalAlignment.Left,
                VerticalAlignment        = VerticalAlignment.Center,
                VerticalContentAlignment = VerticalAlignment.Center
            };

            if (CheckboxTextProperty.TryGet(param.Metadata, out var checkboxText))
            {
                checkBox.Content = checkboxText;
            }
            checkBox.Checked   += StateChangeHandler;
            checkBox.Unchecked += StateChangeHandler;
            void Setter(object val) => checkBox.IsChecked = (bool?)val ?? false;
            object Getter() => checkBox.IsChecked ?? false;

            void Updater(ParameterStateType state, bool value)
            {
                switch (state)
                {
                case ParameterStateType.Enabled:
                    checkBox.IsEnabled = value;
                    break;
                }
            }

            return(new PresentedParameter(param, checkBox, new PresentedParameter.ParamDelegates(Getter, Setter, param.IsValid, Updater)));
        }
Exemplo n.º 5
0
            public Adapter([NotNull] IParameterDescriptor parameter, [NotNull] IParameterDescriptor elementParameter,
                           [NotNull] UIElement container, [NotNull] StackPanel itemsContainer, [CanBeNull] PlusButton plusButton,
                           bool distinct, bool @fixed, int maxElementNum)
            {
                _parameter        = parameter;
                _elementParameter = elementParameter;
                _elementPresenter = elementParameter.GetPresenter();
                _container        = container;
                _itemsContainer   = itemsContainer;
                _plusButton       = plusButton;
                _distinct         = distinct;
                _fixed            = @fixed;
                _maxElementNum    = maxElementNum;

                if (plusButton != null)
                {
                    plusButton.Triggered += PlusButton_OnTriggered;
                }
                if (_fixed)
                {
                    for (var i = 0; i < maxElementNum; i++)
                    {
                        var viewModel = _elementPresenter.Present(_elementParameter);
                        viewModel.ValueChanged += ElementViewModel_OnValueChanged;
                        _itemsContainer.Children.Add(viewModel.Element);
                        _elementViewModels.Add(new ElementViewModel(viewModel, viewModel.Element));
                    }
                }
            }
Exemplo n.º 6
0
 public static string SerializeParam(this IParameterDescriptor parameter, [CanBeNull] object value)
 {
     if (value == null)
     {
         return(null);
     }
     if (TryGetPersistentTypeConverter(parameter, out var converter))
     {
         return(JsonUtils.Serialize(converter.ConvertForward(value)));
     }
     if (typeof(IParameterizedObject).IsAssignableFrom(parameter.ValueType))
     {
         var factory = parameter.GetParameterizedObjectFactory();
         var context = factory.Parse(parameter, (IParameterizedObject)value);
         var output  = new Dictionary <string, string>();
         foreach (var p in factory.GetParameters(parameter))
         {
             if (context.TryGet(p, out var val))
             {
                 output[p.Key] = SerializeParam(p, val);
             }
         }
         return(JsonUtils.Serialize(output));
     }
     return(JsonUtils.Serialize(value));
 }
            public override IReadOnlyCollection <IParameterDescriptor> GetParameters(IParameterDescriptor parameter) =>
            parameter.Metadata.Contains(TwoSidedProperty) ? new IParameterDescriptor[]
            {
                Duration
            }

                                                                                                      : new IParameterDescriptor[] { TwoSided, Duration };
Exemplo n.º 8
0
            public Accessor([NotNull] IParameterDescriptor parameter, [NotNull] Slider slider)
            {
                _parameter = parameter;
                _slider    = slider;

                _slider.ValueChanged += Slider_OnValueChanged;
            }
Exemplo n.º 9
0
 public Adapter(IParameterDescriptor parameter, bool isSdColor, Rectangle rect, TextBlock textBlock)
 {
     _parameter = parameter;
     _isSdColor = isSdColor;
     _rect      = rect;
     _textBlock = textBlock;
 }
Exemplo n.º 10
0
 protected LookupItemBase CreateItem(IParameterDescriptor descriptor, CodeCompletionContext context)
 {
     if (descriptor.DecraedElement != null)
         return new ParameterLookupItem(descriptor, new DeclaredElementLookupItemCreationContext(context.ProjectFile));
     else
         return new StaticParameterLookupItem(descriptor.Name);
 }
Exemplo n.º 11
0
 public static string ConvertValueToString(this IParameterDescriptor parameter, object val)
 {
     if (TryGetPersistentTypeConverter(parameter, out var converter))
     {
         val = converter.ConvertForward(val);
     }
     return(val == null ? NullPlaceholder : ConvertValueToString(val.GetType(), val));
 }
Exemplo n.º 12
0
 public Adapter(IParameterDescriptor parameter, ISet <string> supportedSchemes, bool checkFileExistence, TextBox uriTextBox, Button browseButton)
 {
     _parameter          = parameter;
     _supportedSchemes   = supportedSchemes;
     _checkFileExistence = checkFileExistence;
     _uriTextBox         = uriTextBox;
     _browseButton       = browseButton;
 }
Exemplo n.º 13
0
 public RuntimeAspectContext(IServiceProvider serviceProvider, ITargetDescriptor target, IProxyDescriptor proxy, IParameterCollection parameters, IParameterDescriptor returnParameter)
 {
     _serviceProvider = serviceProvider;
     Target           = target;
     Proxy            = proxy;
     Parameters       = parameters;
     ReturnParameter  = returnParameter;
 }
Exemplo n.º 14
0
 public MissedParameterError(IParameterDescriptor descriptor, IElement element)
 {
     if (descriptor == null) throw new ArgumentNullException("descriptor");
     if (element == null) throw new ArgumentNullException("element");
     this.descriptor = descriptor;
     this.element = element;
     this.toolTip = string.Format("Missed requred {0} {1}", (descriptor.IsAttribute ? "attribute" : "element" ), descriptor.Name);
 }
Exemplo n.º 15
0
 public override Task Invoke(IParameterDescriptor parameter, ParameterAspectContext context, ParameterAspectDelegate next)
 {
     if (string.IsNullOrEmpty(parameter.Value?.ToString()))
     {
         throw new ArgumentNullException($"Invalid parameter. {parameter.Name} cannot be null or empty");
     }
     return(next(parameter, context));
 }
Exemplo n.º 16
0
 public Adapter(IParameterDescriptor parameter, PathType pathType, bool checkExistence, TextBox pathTextBox, Button browseButton)
 {
     _parameter      = parameter;
     _pathType       = pathType;
     _checkExistence = checkExistence;
     _pathTextBox    = pathTextBox;
     _browseButton   = browseButton;
 }
Exemplo n.º 17
0
 public ParameterLookupItem(IParameterDescriptor parameterDescriptor, IElementPointerFactory elementInstancePointer)
     : base(new DeclaredElementInstance(parameterDescriptor.DecraedElement), 
              elementInstancePointer, 
              L4NLanguageService.L4N)
 {
     if (parameterDescriptor == null) throw new ArgumentNullException("parameterDescriptor");
     this.parameterDescriptor = parameterDescriptor;
 }
Exemplo n.º 18
0
 public Accessor(IParameterDescriptor parameter, CheckBox checkBox)
 {
     _parameter              = parameter;
     _checkBox               = checkBox;
     checkBox.Checked       += CheckBox_OnValueChanged;
     checkBox.Unchecked     += CheckBox_OnValueChanged;
     checkBox.Indeterminate += CheckBox_OnValueChanged;
 }
Exemplo n.º 19
0
 public override IReadonlyContext Parse(IParameterDescriptor parameter, Margins margins) => new Context
 {
     [Relative] = margins.Relative,
     [Edges[0]] = margins.Left,
     [Edges[1]] = margins.Top,
     [Edges[2]] = margins.Right,
     [Edges[3]] = margins.Bottom
 };
        public void Add(IParameterDescriptor descriptor)
        {
            if (descriptor == null) throw new ArgumentNullException("descriptor");

            List<IParameterDescriptor> list = new List<IParameterDescriptor>();
            list.Add(descriptor);
            Add(list);
        }
Exemplo n.º 21
0
        public PresentedParameter Present(IParameterDescriptor param, Action updateCallback)
        {
            var container = new Grid();
            var checkbox  = new CheckBox();

            container.Children.Add(checkbox);
            // TODO
            return(null);
        }
Exemplo n.º 22
0
 internal TypeOverridenParameter([NotNull] IParameterDescriptor originalParameter,
                                 [NotNull] Type valueType, [NotNull] IReadonlyContext metadata,
                                 [CanBeNull] object defaultValue, [CanBeNull] IEnumerable selectableValues) : base(originalParameter)
 {
     ValueType        = valueType;
     Metadata         = metadata;
     DefaultValue     = defaultValue;
     SelectableValues = selectableValues;
 }
Exemplo n.º 23
0
            public PopupAdapter([NotNull] MultiParameterPresenter presenter, [NotNull] IParameterDescriptor parameter,
                                [NotNull] ButtonBase button, [CanBeNull] object value) : base(button)
            {
                _presenter = presenter;
                _parameter = parameter;
                _value     = value;

                button.Click += Button_OnClick;
            }
Exemplo n.º 24
0
 public Adapter(IParameterDescriptor parameter, bool isSdColor, Rectangle rect, TextBlock textBlock)
 {
     _parameter               = parameter;
     _isSdColor               = isSdColor;
     _rect                    = rect;
     _textBlock               = textBlock;
     _rect.MouseEnter        += Rect_OnMouseEnter;
     _rect.MouseLeave        += Rect_OnMouseLeave;
     _rect.MouseLeftButtonUp += Rect_OnMouseLeftButtonUp;
 }
Exemplo n.º 25
0
        public static IParameterDescriptor GetRawParameter(this IParameterDescriptor parameter)
        {
            var param = parameter;

            while (param is IRoutedParameter routedParameter)
            {
                param = routedParameter.OriginalParameter;
            }
            return(param);
        }
Exemplo n.º 26
0
 public Adapter(IParameterDescriptor parameter, Type valueType, Grid container, CheckBox checkBox, PresentedParameter presented)
 {
     _parameter        = parameter;
     _container        = container;
     _checkBox         = checkBox;
     _presented        = presented;
     _constructor      = _parameter.ValueType.GetConstructor(new [] { typeof(bool), valueType }) ?? throw new Exception("cannot found optional constructor");
     _hasValueProperty = _parameter.ValueType.GetProperty(nameof(Optional <object> .HasValue)) ?? throw new Exception("cannot found 'HasValue' property");
     _valueProperty    = _parameter.ValueType.GetProperty(nameof(Optional <object> .Value)) ?? throw new Exception("cannot found 'Value' property");
 }
Exemplo n.º 27
0
            public override IReadonlyContext Parse(IParameterDescriptor parameter, Rectangle rectangle)
            {
                var parameters = GetParameterArray(parameter);

                return(new Context
                {
                    [parameters[0]] = rectangle.Width,
                    [parameters[1]] = rectangle.Height,
                });
            }
Exemplo n.º 28
0
 public static object ParseValueFromString(this IParameterDescriptor parameter, string strVal)
 {
     if (Equals(NullPlaceholder, strVal))
     {
         return(null);
     }
     return(TryGetPersistentTypeConverter(parameter, out var converter)
         ? converter.ConvertBackward(ParseValue(converter.OutputType, strVal))
         : ParseValue(parameter.ValueType, strVal));
 }
Exemplo n.º 29
0
        public IParameterStringValueValidator GetValidator(IParameterDescriptor descriptor)
        {
            IParameterStringValueValidator byType = GetValidator(descriptor.Type);
            if (byType != null)
                return byType;

            if (descriptor.IsEnumerable)
                return GetValidator(descriptor.PossibleValues);

            return null;
        }
Exemplo n.º 30
0
            public Adapter([NotNull] IParameterDescriptor parameter, [NotNull] TextBox pathTextBox, [CanBeNull] Button browseButton,
                           PathType pathType, bool checkExistence)
            {
                _parameter      = parameter;
                _pathTextBox    = pathTextBox;
                _browseButton   = browseButton;
                _pathType       = pathType;
                _checkExistence = checkExistence;

                _pathTextBox.TextChanged += PathTextBox_OnTextChanged;
            }
Exemplo n.º 31
0
            public override Colors Create(IParameterDescriptor parameter, IReadonlyContext context)
            {
                var colorKeys = ColorKeysProperty.Get(parameter.Metadata);
                var colors    = new uint[colorKeys.Length];

                for (var i = 0; i < colorKeys.Length; i++)
                {
                    colors[i] = GetParameter(colorKeys[i]).Get(context).ToUIntArgb();
                }
                return(new Colors(colorKeys, colors));
            }
Exemplo n.º 32
0
            public override IReadonlyContext Parse(IParameterDescriptor parameter, Colors colors)
            {
                var context   = new Context();
                var colorKeys = ColorKeysProperty.Get(parameter.Metadata);

                for (var i = 0; i < colorKeys.Length; i++)
                {
                    GetParameter(colorKeys[i]).Set(context, colors[i].ToSdColor());
                }
                return(context);
            }
            public Adapter([NotNull] IParameterDescriptor parameter,
                           [NotNull] IList <ParameterViewModel> memberParamViewModels)
            {
                _parameter             = parameter;
                _memberParamViewModels = memberParamViewModels;

                foreach (var memberParamViewModel in _memberParamViewModels)
                {
                    memberParamViewModel.ValueChanged += MemberParamViewModel_OnValueChanged;
                }
            }
Exemplo n.º 34
0
        public IParameterizedObject Create(IParameterDescriptor parameter, IReadonlyContext context)
        {
            var meta  = GetMeta(parameter);
            var value = meta.Constructor();

            foreach (var autoParameter in meta.Parameters)
            {
                autoParameter.SetMemberValue(value, context.TryGet(autoParameter, out var pv) ? pv : autoParameter.DefaultValue);
            }
            return(value);
        }
Exemplo n.º 35
0
        public IReadonlyContext Parse(IParameterDescriptor parameter, IParameterizedObject parameterizedObject)
        {
            var meta    = GetMeta(parameter);
            var context = new Context(meta.Parameters.Length);

            foreach (var autoParameter in meta.Parameters)
            {
                context[autoParameter] = autoParameter.GetMemberValue(parameterizedObject);
            }
            return(context);
        }
 public LevelParameterDescriptorDecorator(IParameterDescriptor original)
 {
     this.original = original;
 }
 public EncodingParameterDescriptorDecorator(IParameterDescriptor original)
 {
     this.original = original;
 }
 public void AddParameter(IParameterDescriptor parameterDescriptor)
 {
     m_container.Add(parameterDescriptor.Id, parameterDescriptor);
 }
 public IPAddressParameterDescriptorDecorator(IParameterDescriptor original)
 {
     this.original = original;
 }