示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            CustomerType ct;
            ct = CustomerType.Retail;
            if (ct == CustomerType.Retail)
            {
                Console.WriteLine("test");
            }

            SimpleEventHandler seh = new SimpleEventHandler(RunCode);
            seh.Invoke("A Message!");
        }
        protected override void OnPropertyChanged(string name)
        {
            base.OnPropertyChanged(name);
            if (name == "State")
            {
                if (StateChanged != null)
                {
                    StateChanged.Invoke(this);
                }

                this.RefreshTemplate();
            }
        }
示例#3
0
    public Handle Subscribe(SimpleEventHandler handler, bool includeLast = false)
    {
        if (this.handlers == null)
        {
            this.handlers = new List <SimpleEventHandler>();
        }

        this.handlers.Add(handler);

        if (this.lastEvent != null && includeLast)
        {
            handler.Invoke(this.lastEvent);
        }

        return(new Handle(() => this.Unsubscribe(handler)));
    }
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        protected override void OnPropertyChanged(string name)
        {
            base.OnPropertyChanged(name);
            if (name == "State")
            {
                this.RefreshTemplate();

                if (StateChanged != null)
                {
                    StateChanged.Invoke(this);
                }
            }
            else if (name == "SourceNode")
            {
                // Subscribing StateChanged for the input connection
                if (cacheSourceNode != null)
                {
                    cacheSourceNode.StateChanged -= OnInputStateChanged;
                    cacheSourceNode = null;
                }
                if (this.SourceNode is BaseGateViewModel inputNode)
                {
                    cacheSourceNode = inputNode;
                    this.State      = cacheSourceNode.State;
                    cacheSourceNode.StateChanged += OnInputStateChanged;
                }
            }
            else if (name == "TargetNode")
            {
                // Subscribing StateChanged for the output connection
                if (cacheTargetNode != null)
                {
                    cacheTargetNode.DisposeEvents(this);
                    cacheTargetNode = null;
                }
                if (this.TargetNode is GateViewModel outputNode)
                {
                    cacheTargetNode = outputNode;
                    cacheTargetNode.InitEvents(this);
                }
            }
        }
 /// <summary>Adds a button to the form.</summary>
 /// <param name="caption">The caption to display on the button.</param>
 /// <param name="clickHandler">The click event handler.</param>
 /// <param name="buttonWidth">Width of the button.</param>
 public SimpleButton AddButton(string caption, SimpleEventHandler clickHandler, int buttonWidth = -1)
 {
     return this.AddButton(caption, (sbtn) => clickHandler.Invoke(), buttonWidth);
 }
示例#6
0
        private void button1_Click(object sender, EventArgs e)
        {
            CustomerType objCT; //Enumeration
            SimpleEventHandler objSEH; //Delegate
            IPerson objIP; //Interface
            PersonClass objPC; //Abstract Class
            Customer objC; //"Concrete + Child + Sealed" Class
            PersonStructure objPS; //Structure

            /** Using an Enumeration **/
            objCT = new CustomerType();
            objCT = CustomerType.Retail;
            if (objCT == CustomerType.Retail) { Console.WriteLine("Retail Customer"); }

            /** Using an Delegate **/
            objSEH = new SimpleEventHandler(MyEventHanderMethod);
            objSEH.Invoke("Invoking the Method through the Delegate!");

            /** Using an Interface **/
            //objIP = new PersonClass;
            objIP = new PersonStructure();
            objIP.DOBChanged += new SimpleEventHandler(MyEventHanderMethod);
            objIP.NameChanged += new SimpleEventHandler(MyEventHanderMethod);
            objIP.Name = "Bob";
            objIP.DOB = "01/01/80";
            Console.WriteLine(objIP.GetPersonalData());
            //Console.WriteLine(objIP.GetPersonalData("|"));

            /** Using an Abstract Class **/
            //objPC = new PersonClass;
            //objPC = new PersonStructure();
            objPC = new Customer();
            objPC.DOBChanged += new SimpleEventHandler(MyEventHanderMethod);
            objPC.NameChanged += new SimpleEventHandler(MyEventHanderMethod);
            objPC.Name = "Bob";
            objPC.DOB = "01/01/80";
            Console.WriteLine(objPC.GetPersonalData());
            //Console.WriteLine(objPC.GetPersonalData("|"));

            /** Using an "Concrete + Child + Sealed" Class **/
            //objC = new PersonCustomer;
            //objC = new PersonStructure();
            objC = new Customer();
            objC.DOBChanged += new SimpleEventHandler(MyEventHanderMethod);
            objC.NameChanged += new SimpleEventHandler(MyEventHanderMethod);
            objC.Name = "Bob";
            objC.DOB = "01/01/80";
            Console.WriteLine(objC.GetPersonalData());
            Console.WriteLine(objC.GetPersonalData("|"));

            /** Using an Structure **/
            //objPS = new PersonClass;
            objPS = new PersonStructure();
            //objPS = new Customer();
            objPS.DOBChanged += new SimpleEventHandler(MyEventHanderMethod);
            objPS.NameChanged += new SimpleEventHandler(MyEventHanderMethod);
            objPS.Name = "Bob";
            objPS.DOB = "01/01/80";
            Console.WriteLine(objPS.GetPersonalData());
            //Console.WriteLine(objPS.GetPersonalData("|"));
        }
示例#7
0
 /// <summary>Adds a button to the form.</summary>
 /// <param name="caption">The caption to display on the button.</param>
 /// <param name="clickHandler">The click event handler.</param>
 /// <param name="buttonWidth">Width of the button.</param>
 public SimpleButton AddButton(string caption, SimpleEventHandler clickHandler, int buttonWidth = -1)
 {
     return(this.AddButton(caption, (sbtn) => clickHandler.Invoke(), buttonWidth));
 }
示例#8
0
        //
        // Define the eventHandler method
        public virtual void OnSimpleEventHandler()
        {
            SimpleEventHandler?.Invoke(this, EventArgs.Empty);

            Console.Write("Running Event  : OnSimpleEventHandler ", Environment.NewLine);
        }
示例#9
0
 /// <summary>Creates timer associated with the form.</summary>
 /// <param name="interval">
 /// The interval in milliseconds between consecutive ticks of the timer.
 /// </param>
 /// <param name="tickHandler">The event handler for the timer's tick.</param>
 public SimpleTimer CreateTimer(int interval, SimpleEventHandler tickHandler)
 {
     return this.CreateTimer(interval, (tmr) => tickHandler.Invoke());
 }
示例#10
0
 /// <summary>Creates timer associated with the form.</summary>
 /// <param name="interval">
 /// The interval in milliseconds between consecutive ticks of the timer.
 /// </param>
 /// <param name="tickHandler">The event handler for the timer's tick.</param>
 public SimpleTimer CreateTimer(int interval, SimpleEventHandler tickHandler)
 {
     return(this.CreateTimer(interval, (tmr) => tickHandler.Invoke()));
 }