Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            HorseMq mq = HorseMqBuilder.Create()
                         .AddClientHandler <ClientHandler>()
                         .AddQueueEventHandler <QueueEventHandler>()
                         .UseJustAllowDeliveryHandler()
                         .Build();

            var sampleMessageRouter        = mq.AddRouter("SAMPLE-MESSAGE-ROUTER", RouteMethod.Distribute);
            var sampleMessageQueueBinding  = new QueueBinding("sample-message-queue-binding", "SAMPLE-MESSAGE-QUEUE", 1, BindingInteraction.Response);
            var sampleMessageDirectBinding = new DirectBinding("sample-message-direct-binding", "@type:SAMPLE-MESSAGE-CONSUMER", 2, BindingInteraction.Response, RouteMethod.RoundRobin);

            sampleMessageRouter.AddBinding(sampleMessageQueueBinding);
            sampleMessageRouter.AddBinding(sampleMessageDirectBinding);

            var giveMeGuidRequestRouter  = mq.AddRouter("GIVE-ME-REQUEST-ROUTER", RouteMethod.Distribute);
            var giveMeGuidRequestHandler = new DirectBinding("sample-message-direct-binding", "@name:GIVE-ME-GUID-REQUEST-HANDLER-CONSUMER", 2, BindingInteraction.Response);

            giveMeGuidRequestRouter.AddBinding(giveMeGuidRequestHandler);

            HorseServer server = new HorseServer();

            server.UseHorseMq(mq);
            server.Run(15500);
        }
Exemplo n.º 2
0
 private static DirectBinding <T> Convert <T>(this DirectBinding <PluginSetting> binding, PropertyInfo property)
 {
     return(binding.Convert(
                s => s.GetValueOrDefault <T>(property),
                v => new PluginSetting(property, v)
                ));
 }
                protected override Control CreateControl(DirectBinding <byte> keyBinding, DirectBinding <string> valueBinding)
                {
                    var keyBox = new IntegerNumberBox();

                    keyBox.ValueBinding.Bind(keyBinding.Convert(
                                                 b => (int)b,
                                                 i => (byte)i
                                                 ));
                    keyBox.TextChanging += (sender, e) => e.Cancel = byte.TryParse(e.NewText, out byte newByte) && ItemSource.Keys.Contains(newByte);

                    var valueBox = new TextBox();

                    valueBox.TextBinding.Bind(valueBinding);

                    return(new StackLayout
                    {
                        Orientation = Orientation.Horizontal,
                        Padding = new Padding(0, 0, 5, 0),
                        Spacing = 5,
                        Items =
                        {
                            keyBox,
                            new StackLayoutItem(valueBox, true)
                        }
                    });
                }
Exemplo n.º 4
0
        protected override Control CreateControlBase(int index, DirectBinding <T> itemBinding)
        {
            var remove = new Button
            {
                Text = "-"
            };

            remove.Click += (sender, e) => Remove(index);

            return(new StackLayout
            {
                Orientation = Orientation.Horizontal,
                VerticalContentAlignment = VerticalAlignment.Top,
                Items =
                {
                    new StackLayoutItem
                    {
                        Expand = true,
                        Control = base.CreateControlBase(index, itemBinding)
                    },
                    new StackLayoutItem
                    {
                        VerticalAlignment = VerticalAlignment.Bottom,
                        Control = remove
                    }
                }
            });
        }
Exemplo n.º 5
0
		/// <summary>
		/// Adds a new dual binding between the control and the specified source binding
		/// </summary>
		/// <param name="widgetPropertyName">Property on the control to update</param>
		/// <param name="sourceBinding">Binding to get/set the value to from the control</param>
		/// <param name="mode">Mode of the binding</param>
		/// <returns>A new instance of the DualBinding class that is used to control the binding</returns>
		public DualBinding Bind(string widgetPropertyName, DirectBinding sourceBinding, DualBindingMode mode = DualBindingMode.TwoWay)
		{
			var binding = new DualBinding(
				sourceBinding,
				new ObjectBinding(this, widgetPropertyName),
				mode
			);
			Bindings.Add(binding);
			return binding;
		}
                protected override Control CreateControl(int index, DirectBinding <byte[]> itemBinding)
                {
                    MaskedTextBox <byte[]> arrayEditor = new HexByteArrayBox();

                    arrayEditor.ValueBinding.Bind(itemBinding);

                    return(new Panel
                    {
                        Padding = new Padding(0, 0, 5, 0),
                        Content = arrayEditor
                    });
                }
        protected override Control CreateControl(int index, DirectBinding <PluginSettingStore> itemBinding)
        {
            BindingDisplay display = new BindingDisplay();

            display.StoreBinding.Bind(itemBinding);

            return(new Group
            {
                Text = GetTextForIndex(index),
                Orientation = Orientation.Horizontal,
                ExpandContent = false,
                Content = display
            });
        }
        protected override Control CreateControl(int index, DirectBinding <DeviceIdentifier> itemBinding)
        {
            var entry = new DeviceIdentifierEntry <DeviceIdentifier>();

            entry.EntryBinding.Bind(itemBinding);

            return(new Panel
            {
                Padding = 5,
                Content = new Expander
                {
                    Header = $"Identifier {index + 1}",
                    Content = entry
                }
            });
        }
                protected override Control CreateControl(int index, DirectBinding <byte> itemBinding)
                {
                    MaskedTextBox <int> intBox = new IntegerNumberBox();

                    intBox.ValueBinding.Bind(
                        itemBinding.Convert <int>(
                            c => (int)c,
                            v => (byte)v
                            )
                        );

                    return(new Panel
                    {
                        Padding = new Padding(0, 0, 5, 0),
                        Content = intBox
                    });
                }
Exemplo n.º 10
0
            protected override Control CreateControl(int index, DirectBinding <PluginSettingStore> itemBinding)
            {
                BindingDisplay display;

                var group = new Group
                {
                    Text          = $"{Prefix} {index + 1}",
                    Orientation   = Orientation.Horizontal,
                    ExpandContent = false,
                    Content       = display = new BindingDisplay
                    {
                        MinimumSize = new Size(300, 0)
                    }
                };

                display.StoreBinding.Bind(itemBinding);
                return(group);
            }
Exemplo n.º 11
0
        protected override Control CreateControl(DirectBinding <string> keyBinding, DirectBinding <string> valueBinding)
        {
            TextBox keyBox = new TextBox();

            keyBox.TextBinding.Bind(keyBinding);
            keyBox.TextChanging += (sender, e) => e.Cancel = ItemSource.Keys.Contains(e.NewText);

            TextBox valueBox = new TextBox();

            valueBox.TextBinding.Bind(valueBinding);

            return(new StackLayout
            {
                Orientation = Orientation.Horizontal,
                Padding = new Padding(0, 0, 5, 0),
                Spacing = 5,
                Items =
                {
                    new StackLayoutItem(keyBox,   true),
                    new StackLayoutItem(valueBox, true)
                }
            });
        }
Exemplo n.º 12
0
        private static Control GetControlForSetting(PropertyInfo property, DirectBinding <PluginSetting> binding)
        {
            if (property.PropertyType == typeof(string))
            {
                if (property.GetCustomAttribute <PropertyValidatedAttribute>() is PropertyValidatedAttribute validateAttr)
                {
                    var comboBox = new DropDown <string>
                    {
                        DataStore = validateAttr.GetValue <IEnumerable <string> >(property),
                    };
                    comboBox.SelectedItemBinding.Bind(binding.Convert <string>(property));
                    return(comboBox);
                }
                else
                {
                    var textBox = new TextBox();
                    textBox.TextBinding.Bind(binding.Convert <string>(property));
                    return(textBox);
                }
            }
            else if (property.PropertyType == typeof(bool))
            {
                string description = property.Name;
                if (property.GetCustomAttribute <BooleanPropertyAttribute>() is BooleanPropertyAttribute attribute)
                {
                    description = attribute.Description;
                }

                var checkbox = new CheckBox
                {
                    Text = description
                };
                checkbox.CheckedBinding.Cast <bool>().Bind(
                    binding.Convert(
                        s => s.GetValueOrDefault <bool>(property),
                        v => new PluginSetting(property, v)
                        )
                    );
                return(checkbox);
            }
            else if (property.PropertyType == typeof(float))
            {
                var tb = GetMaskedTextBox <FloatNumberBox, float>(property, binding);

                if (property.GetCustomAttribute <SliderPropertyAttribute>() is SliderPropertyAttribute sliderAttr)
                {
                    // TODO: replace with slider when possible (https://github.com/picoe/Eto/issues/1772)
                    tb.ToolTip         = $"Minimum: {sliderAttr.Min}, Maximum: {sliderAttr.Max}";
                    tb.PlaceholderText = $"{sliderAttr.DefaultValue}";

                    if (!binding.DataValue.HasValue)
                    {
                        binding.DataValue.SetValue(sliderAttr.DefaultValue);
                    }
                }
                return(tb);
            }
            else if (genericControls.TryGetValue(property.PropertyType, out var getGenericTextBox))
            {
                return(getGenericTextBox(property, binding));
            }
            throw new NotSupportedException($"'{property.PropertyType}' is not supported for generated controls.");
        }
Exemplo n.º 13
0
        private static TControl GetMaskedTextBox <TControl, T>(PropertyInfo property, DirectBinding <PluginSetting> binding) where TControl : MaskedTextBox <T>, new()
        {
            var textBox = new TControl();

            textBox.ValueBinding.Bind(binding.Convert <T>(property));
            return(textBox);
        }
Exemplo n.º 14
0
 private static MaskedTextBox <T> GetMaskedTextBox <T>(PropertyInfo property, DirectBinding <PluginSetting> binding)
 {
     return(GetMaskedTextBox <MaskedTextBox <T>, T>(property, binding));
 }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(DirectBinding obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Exemplo n.º 16
0
		public DualBinding Bind(IndirectBinding controlBinding, DirectBinding valueBinding, DualBindingMode mode = DualBindingMode.TwoWay)
		{
			var binding = new ObjectBinding(this, controlBinding);
			return binding.Bind(valueBinding: valueBinding, mode: mode);
		}