public static EventCallback <ChangeEventArgs> CreateBinder <[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(
     this EventCallbackFactory factory,
     object receiver,
     Action <T> setter,
     T existingValue,
     CultureInfo?culture = null)
 {
     return(CreateBinderCore <T>(factory, receiver, setter, culture, ParserDelegateCache.Get <T>()));
 }
 public static EventCallback <ChangeEventArgs> CreateBinder(
     this EventCallbackFactory factory,
     object receiver,
     Action <double> setter,
     double existingValue,
     CultureInfo?culture = null)
 {
     return(CreateBinderCore <double>(factory, receiver, setter, culture, ConvertToDoubleDelegate));
 }
 public static EventCallback <ChangeEventArgs> CreateBinder(
     this EventCallbackFactory factory,
     object receiver,
     Action <bool?> setter,
     bool?existingValue,
     CultureInfo?culture = null)
 {
     return(CreateBinderCore <bool?>(factory, receiver, setter, culture, ConvertToNullableBool));
 }
        public static EventCallback <MouseEventArgs> Create(this EventCallbackFactory factory, object receiver, Func <MouseEventArgs, Task> callback)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(factory.Create <MouseEventArgs>(receiver, callback));
        }
        public static EventCallback <PointerEventArgs> Create(this EventCallbackFactory factory, object receiver, Action <PointerEventArgs> callback)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(factory.Create <PointerEventArgs>(receiver, callback));
        }
 public static EventCallback <ChangeEventArgs> CreateBinder(
     this EventCallbackFactory factory,
     object receiver,
     Action <int> setter,
     int existingValue,
     CultureInfo?culture = null)
 {
     return(CreateBinderCore <int>(factory, receiver, setter, culture, ConvertToInt));
 }
 public static EventCallback <ChangeEventArgs> CreateBinder(
     this EventCallbackFactory factory,
     object receiver,
     Action <TimeOnly?> setter,
     TimeOnly?existingValue,
     string format,
     CultureInfo?culture = null)
 {
     return(CreateBinderCore <TimeOnly?>(factory, receiver, setter, culture, format, ConvertToNullableTimeOnlyWithFormat));
 }
示例#8
0
        protected override void OnInitialized()
        {
            base.OnInitialized();

            if (EnterButton.IsT0 && !EnterButton.AsT0)
            {
                Suffix = builder =>
                {
                    var i = 0;
                    builder.OpenComponent <Icon>(i++);
                    builder.AddAttribute(i++, "Class", $"{PrefixCls}-search-icon");
                    builder.AddAttribute(i++, "Type", "search");
                    builder.AddAttribute(i++, "OnClick", CallbackFactory.Create <MouseEventArgs>(this, HandleSearch));
                    builder.CloseComponent();
                };
            }
            else
            {
                AddOnAfter = builder =>
                {
                    builder.OpenComponent <Button>(_sequence++);
                    builder.AddAttribute(_sequence++, "Class", $"{PrefixCls}-search-button");
                    builder.AddAttribute(_sequence++, "Type", "primary");
                    builder.AddAttribute(_sequence++, "Size", Size);

                    if (_isSearching)
                    {
                        builder.AddAttribute(_sequence++, "Loading", true);
                    }
                    else
                    {
                        var e = new EventCallbackFactory().Create(this, HandleSearch);
                        builder.AddAttribute(_sequence++, "OnClick", e);
                    }

                    EnterButton.Switch(boolean =>
                    {
                        if (boolean)
                        {
                            builder.AddAttribute(_sequence++, "Icon", "search");
                        }
                    }, str =>
                    {
                        builder.AddAttribute(_sequence++, "ChildContent", new RenderFragment((b) =>
                        {
                            b.AddContent(_sequence++, str);
                        }));
                    });

                    builder.CloseComponent();
                };
            }
        }
        protected override void OnInitialized()
        {
            base.OnInitialized();

            if (EnterButton.Value == null)
            {
                Suffix = new RenderFragment((builder) =>
                {
                    builder.OpenComponent <Icon>(35);
                    builder.AddAttribute(36, "class", $"{PrefixCls}-search-icon");
                    builder.AddAttribute(37, "type", "search");
                    builder.AddAttribute(38, "onclick", CallbackFactory.Create <MouseEventArgs>(this, HandleSearch));
                    builder.CloseComponent();
                });
            }
            else
            {
                AddOnAfter = new RenderFragment((builder) =>
                {
                    builder.OpenComponent <Button>(_sequence++);
                    builder.AddAttribute(_sequence++, "class", $"{PrefixCls}-search-button");
                    builder.AddAttribute(_sequence++, "type", "primary");
                    builder.AddAttribute(_sequence++, "size", Size);

                    if (_isSearching)
                    {
                        builder.AddAttribute(_sequence++, "loading", true);
                    }
                    else
                    {
                        var e = new EventCallbackFactory().Create(this, HandleSearch);
                        builder.AddAttribute(_sequence++, "onclick", e);
                    }

                    EnterButton.Switch(boolean =>
                    {
                        if (boolean)
                        {
                            builder.AddAttribute(_sequence++, "icon", "search");
                        }
                    }, str =>
                    {
                        builder.AddAttribute(_sequence++, "ChildContent", new RenderFragment((b) =>
                        {
                            b.AddContent(_sequence++, str);
                        }));
                    });

                    builder.CloseComponent();
                });
            }
        }
        private void OnShowEditModal()
        {
            this.editSessionArgs = new EditSessionArgs()
            {
                Name      = this.session?.Name,
                SessionId = this.SessionId,
                AutoStop  = this.session?.AutoStop == true,
                Bulletin  = new Bulletin(this.bulletin)
            };

            var onConfirm = new EventCallbackFactory().Create <EditSessionArgs>(this, this.HandleEditSessionConfirmAsync);

            EditSessionDialog.Show(this.DialogService, UIResources.EditSessionDialogTitle, this.editSessionArgs, onConfirm);
        }
示例#11
0
        protected override void OnInitialized()
        {
            base.OnInitialized();

            if (Attributes == null || !Attributes.ContainsKey("enterButton"))
            {
                suffix = new RenderFragment((builder) =>
                {
                    builder.OpenComponent <AntIcon>(35);
                    builder.AddAttribute(36, "class", $"{PrefixCls}-search-icon");
                    builder.AddAttribute(37, "type", "search");
                    builder.AddAttribute(38, "onclick", _callbackFactory.Create <MouseEventArgs>(this, Search));
                    builder.CloseComponent();
                });
            }
            else
            {
                addOnAfter = new RenderFragment((builder) =>
                {
                    builder.OpenComponent <AntButton>(_sequence++);
                    builder.AddAttribute(_sequence++, "class", $"{PrefixCls}-search-button");
                    builder.AddAttribute(_sequence++, "type", "primary");
                    builder.AddAttribute(_sequence++, "size", size);
                    if (_isSearching)
                    {
                        builder.AddAttribute(_sequence++, "loading", true);
                    }
                    else
                    {
                        EventCallback <MouseEventArgs> e = new EventCallbackFactory().Create(this, Search);
                        builder.AddAttribute(_sequence++, "onclick", e);
                    }

                    if (Attributes["enterButton"].ToString() == true.ToString()) // show search icon button
                    {
                        builder.AddAttribute(_sequence++, "icon", "search");
                    }
                    else // show search content button
                    {
                        builder.AddAttribute(_sequence++, "ChildContent", new RenderFragment((b) =>
                        {
                            b.AddContent(_sequence++, Attributes["enterButton"].ToString());
                        }));
                    }

                    builder.CloseComponent();
                });
            }
        }
示例#12
0
        public async Task when_suppressing_item_if_the_pop_up_retrieve_no_the_item_should_not_be_suppressed()
        {
            ConfirmDisplayer.Setup(x => x.Confirm(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.Factory.StartNew(() => false));
            bool hasCallRemoveCallback   = false;
            var  removeItemEventCallBack = EventCallbackFactory.Create <StarpointsItem>(new object(), _ => hasCallRemoveCallback = true);
            var  starpointsItem          = CreateStarpointsItem();

            Authorize(starpointsItem, false);
            var component = CreateComponent(ComponentParameter.CreateParameter("Item", starpointsItem)
                                            , ComponentParameter.CreateParameter("PleaseRemoveItem", removeItemEventCallBack));

            component.WaitForState(() => component.Nodes?.Length > 0);
            await component.Instance.CancelItem();

            await Task.Delay(30);

            hasCallRemoveCallback.Should().BeFalse();
        }
示例#13
0
        public async Task when_updating_status_the_update_status_api_method_should_be_called()
        {
            ConfirmDisplayer.Setup(x => x.Confirm(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.Factory.StartNew(() => true));
            var removeItemEventCallBack = EventCallbackFactory.Create <StarpointsItem>(new object(), _ => { });
            var starpointsItem          = CreateStarpointsItem();

            MockHttp.Expect($"http://localhost/StarpointsManager/CancelStarpoints/-1/{starpointsItem.Id}").Respond(HttpStatusCode.OK);
            Authorize(starpointsItem, false);
            var component = CreateComponent(ComponentParameter.CreateParameter("Item", starpointsItem)
                                            , ComponentParameter.CreateParameter("PleaseRemoveItem", removeItemEventCallBack));

            component.WaitForState(() => component.Nodes?.Length > 0);
            await component.Instance.CancelItem();

            await Task.Delay(30);

            MockHttp.VerifyNoOutstandingExpectation();
        }
示例#14
0
        public void Setup()
        {
            IActivityDefinitionService service = Substitute.For <IActivityDefinitionService>();

            service.GetActivitySetNames().Returns(_activitySetNames);
            _host.AddService(service);

            EventCallbackFactory   eventCallbackFactory = new EventCallbackFactory();
            EventCallback <string> eventCallback        = eventCallbackFactory.Create <string>(this, x =>
            {
                _callBackValue = x;
            });
            IDictionary <string, object> parameters = new Dictionary <string, object>
            {
                { "CurrentActivitySetChanged", eventCallback }
            };

            _component = _host.AddComponent <ActivitySetSelector>(parameters);
        }
示例#15
0
        public async Task when_suppressing_item_if_the_pop_up_retrieve_yes_the_item_should_be_suppressed()
        {
            ConfirmDisplayer.Setup(x => x.Confirm(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.Factory.StartNew(() => true));
            bool hasCallRemoveCallback   = false;
            var  removeItemEventCallBack = EventCallbackFactory.Create <StarpointsItem>(new object(), _ => hasCallRemoveCallback = true);
            var  starpointsItem          = CreateStarpointsItem();

            MockHttp.Expect($"http://localhost/StarpointsManager/CancelStarpoints/-1/{starpointsItem.Id}").Respond(HttpStatusCode.OK);
            Authorize(starpointsItem, false);
            var component = CreateComponent(ComponentParameter.CreateParameter("Item", starpointsItem)
                                            , ComponentParameter.CreateParameter("PleaseRemoveItem", removeItemEventCallBack));

            component.WaitForState(() => component.Nodes?.Length > 0);
            await component.Instance.CancelItem();

            await Task.Delay(30);

            hasCallRemoveCallback.Should().BeTrue();
        }
    private static EventCallback <ChangeEventArgs> CreateBinderCore <T>(
        this EventCallbackFactory factory,
        object receiver,
        Action <T> setter,
        CultureInfo?culture,
        BindConverter.BindParser <T> converter)
    {
        Action <ChangeEventArgs> callback = e =>
        {
            T?  value     = default;
            var converted = false;
            try
            {
                converted = converter(e.Value, culture, out value);
            }
            catch
            {
            }

            // We only invoke the setter if the conversion didn't throw, or if the newly-entered value is empty.
            // If the user entered some non-empty value we couldn't parse, we leave the state of the .NET field
            // unchanged, which for a two-way binding results in the UI reverting to its previous valid state
            // because the diff will see the current .NET output no longer matches the render tree since we
            // patched it to reflect the state of the UI.
            //
            // This reversion behavior is valuable because alternatives are problematic:
            // - If we assigned default(T) on failure, the user would lose whatever data they were editing,
            //   for example if they accidentally pressed an alphabetical key while editing a number with
            //   @bind:event="oninput"
            // - If the diff mechanism didn't revert to the previous good value, the user wouldn't necessarily
            //   know that the data they are submitting is different from what they think they've typed
            if (converted)
            {
                setter(value !);
            }
            else if (string.Empty.Equals(e.Value))
            {
                setter(default !);
示例#17
0
 public TextInputBuilder()
 {
     this.eventCallbackFactory = new EventCallbackFactory();
 }
示例#18
0
 public FileEditPlus()
 {
     EventFactory = new EventCallbackFactory();
     Changed      = EventFactory.Create <FileChangedEventArgs>(this, OnChanged);
     Progressed   = EventFactory.Create <FileProgressedEventArgs>(this, OnProgressed);
 }
示例#19
0
 public CreateItemFormRenderer(IFormInputRendererTreeProvider formInputRendererTreeProvider)
 {
     this.formInputRendererTreeProvider = formInputRendererTreeProvider ?? throw new ArgumentNullException(nameof(formInputRendererTreeProvider));
     this.eventCallbackFactory          = new EventCallbackFactory();
 }
示例#20
0
 public NumberInputBuilder()
 {
     this.eventCallbackFactory = new EventCallbackFactory();
 }
 public DateInputBuilder()
 {
     _eventCallbackFactory = new EventCallbackFactory();
 }
 public CheckBoxInputBuilder()
 {
     _eventCallbackFactory = new EventCallbackFactory();
 }