public void TwoDiscosConcurrently_lattersGetFirstsInquiredList_basedOnTestOne()
        {
            TestInquiryBtIf btIf;
            BluetoothClient cli;

            //
            Create_BluetoothClient(out btIf, out cli);
            Assert.IsFalse(btIf.testDoCallbacksFromWithinStartInquiry, "tdcfwsi");
            ThreadStart dlgt = delegate {
                bool signalled = btIf.startInquiryCalled.WaitOne(10000, false);
                Assert.IsTrue(signalled, "!signalled!!!!!");
                btIf.InquiryEventsOne();
            };

            WidcommBluetoothClient.ReadKnownDeviceFromTheRegistry = false;
            // We really should test with two BtCli instances but that's a bit hard to set-up.
            IAsyncResult ar1         = cli.BeginDiscoverDevices(255, true, true, true, false, null, null);
            IAsyncResult ar2         = cli.BeginDiscoverDevices(255, true, true, true, false, null, null);
            IAsyncResult arDlgt      = Delegate2.BeginInvoke(dlgt, null, null);
            bool         signalledAr = _WaitAll(new WaitHandle[] { ar1.AsyncWaitHandle, ar2.AsyncWaitHandle }, 15000);

            Assert.IsTrue(signalledAr, "signalledAr");
            BluetoothDeviceInfo[] devices1 = cli.EndDiscoverDevices(ar1);
            BluetoothDeviceInfo[] devices2 = cli.EndDiscoverDevices(ar2);
            Delegate2.EndInvoke(dlgt, arDlgt); // any exceptions?
            VerifyDevicesOne(devices1);
            VerifyDevicesOne(devices2);
            Assert.AreEqual(1, btIf.stopInquiryCalled, "stopInquiryCalled");
        }
        public void Main()
        {
            Delegate1 d1     = AddNums1;
            double    result = d1(10, 20, 30);

            Console.WriteLine(result);
            //or
            Func <int, float, double, double> obj1 = AddNums1;

            result = obj1(11, 22, 33);
            Console.WriteLine(result);

            Delegate2 d2 = AddNums2;

            d2(20, 30, 40);
            //or
            Action <int, float, double> obj2 = AddNums2;

            obj2(22, 33, 44);


            Delegate3 d3   = CheckLenght;
            bool      flag = d3("Navjyot");

            Console.WriteLine(flag);
            //or
            Predicate <string> obj3 = CheckLenght;

            obj3("Navjyot");
        }
        // With default non-infinite InquiryLength, test now no correct.[Test]
        public void One_CompletedEventLateOrNeverComes()
        {
            TestInquiryBtIf btIf;
            BluetoothClient cli;

            //
            Create_BluetoothClient(out btIf, out cli);
            Assert.IsFalse(btIf.testDoCallbacksFromWithinStartInquiry, "tdcfwsi");
            ThreadStart dlgt = delegate {
                bool signalled = btIf.startInquiryCalled.WaitOne(10000, false);
                Assert.IsTrue(signalled, "!signalled!!!!!");
                btIf.InquiryEventsOne_WithNoCompletedEvent();
            };
            IAsyncResult arDlgt = Delegate2.BeginInvoke(dlgt, null, null);

            //
            WidcommBluetoothClient.ReadKnownDeviceFromTheRegistry = false;
            Assert.IsTrue(cli.InquiryLength.CompareTo(TimeSpan.Zero) < 0, "Excepted infinite InquiryLength, but was: " + cli.InquiryLength);
            IAsyncResult arDD      = cli.BeginDiscoverDevices(255, true, true, true, false, null, null);
            bool         completed = arDD.AsyncWaitHandle.WaitOne(1 * 1000, false);

            Assert.IsFalse(completed, "Expected DD to time-out.");
            // NON USEFUL/WOULD BLOCK
            //BluetoothDeviceInfo[] devices = cli.EndDiscoverDevices(arDD);
            Delegate2.EndInvoke(dlgt, arDlgt); // any exceptions?
            //VerifyDevicesOne(devices);
            //Assert.AreEqual(1, btIf.stopInquiryCalled, "stopInquiryCalled");
        }
        public void One_CompletedEventLateOrNeverComes_ButHasTimeout()
        {
            TestInquiryBtIf btIf;
            BluetoothClient cli;

            //
            Create_BluetoothClient(out btIf, out cli);
            cli.InquiryLength = TimeSpan.FromMilliseconds(750);
            //
            Assert.IsFalse(btIf.testDoCallbacksFromWithinStartInquiry, "tdcfwsi");
            ThreadStart dlgt = delegate {
                bool signalled = btIf.startInquiryCalled.WaitOne(10000, false);
                Assert.IsTrue(signalled, "!signalled!!!!!");
                btIf.InquiryEventsOne_WithNoCompletedEvent();
            };
            IAsyncResult arDlgt = Delegate2.BeginInvoke(dlgt, null, null);

            //
            WidcommBluetoothClient.ReadKnownDeviceFromTheRegistry = false;
            Assert.IsTrue(cli.InquiryLength.CompareTo(TimeSpan.Zero) > 0, "blehhhhhhhhhhhhhhhhhhhhhh");
            IAsyncResult arDD = cli.BeginDiscoverDevices(255, true, true, true, false, null, null);
            // Timeout Killer occurs 1.5 times the InquiryLength, 1125ms
            bool completed = arDD.AsyncWaitHandle.WaitOne(1500, false);

            Assert.IsTrue(completed, "Unexpected DD time-out.");
            BluetoothDeviceInfo[] devices = cli.EndDiscoverDevices(arDD);
            Delegate2.EndInvoke(dlgt, arDlgt); // any exceptions?
            VerifyDevicesOne(devices);
            Assert.AreEqual(1, btIf.stopInquiryCalled, "stopInquiryCalled");
        }
Example #5
0
        //public static bool PrintClient(MyClient client, string name)
        //{
        //    return client.Name == name;
        //}
        static void Main(string[] args)
        {
            //Delegate d = PrintClient;
            //MyClient c = new MyClient("Петр");
            //MyClient c1 = new MyClient("Иван");
            //List<MyClient> list = new List<MyClient>();
            //list.Add(c1);

            //MyClientsGList m = new MyClientsGList();
            //m.MYClients = list;
            //d(c, d => d.);

            Delegate2 d = delegate(string s) { return(s == "Иван"); };

            d.Method
            Console.WriteLine(l1_d(10));


            //Лямбда-Оператор
            l1_d = (x) => { return(x * 2); };
            Console.WriteLine(l1_d(10));


            //Лямбда-Выражение
            l1_d = x => x * 2;
        }
Example #6
0
        static void Main(string[] args)
        {
            Console.WriteLine(PerformOperation(Calculator.Add, 4, 6));
            Console.WriteLine(PerformOperation(Calculator.Subtract, 4, 6));
            string input = Console.ReadLine();
            int    i     = System.Convert.ToInt32(input);

            Delegate1 d1 = null;

            if (i == 0)
            {
                d1 = Display;
            }
            else
            {
                d1 = Display4;
            }
            d1.Invoke();
            d1();
            //Delegate2 d2 = new Delegate2(Display2);
            Delegate2 d2 = Display2;

            d2("AOA Pakistan...");

            Delegate3 d3 = Display3;
            string    s  = d3("Some text");
        }
Example #7
0
 public void Dispose()
 {
     if (this.thread_0 != null)
     {
         try
         {
             this.bool_0 = true;
             if (this.intptr_0 != IntPtr.Zero)
             {
                 Class162.waveInReset(this.intptr_0);
             }
             this.method_1();
             this.thread_0.Join();
             this.delegate2_0 = null;
             this.method_0();
             if (this.intptr_0 != IntPtr.Zero)
             {
                 Class162.waveInClose(this.intptr_0);
             }
         }
         finally
         {
             this.thread_0 = null;
             this.intptr_0 = IntPtr.Zero;
         }
     }
     GC.SuppressFinalize(this);
 }
Example #8
0
        static void Main(string[] args)
        {
            Delegate1 delegate1 = new Delegate1(Method1);
            Delegate2 delegate2 = delegate1();

            delegate2();
        }
Example #9
0
        static void Main(string[] args)
        {
            var d = new Delegate(() => { });

            Delegate1 d1 = delegate() { };
            Delegate2 d2 = delegate(string s) { };
            Delegate3 d3 = delegate() { return(string.Empty); };
            Delegate4 d4 = delegate(string s) { return(s); };
            Delegate5 d5 = delegate(string s, int x)
            {
                var xs = x.ToString();
                return($"{s}{xs}");
            };

            Delegate1 dl1 = () => { };
            //Delegate2 dl2 = (string s) => { };
            //Delegate2 dl2 = (s) => { };
            Delegate2 dl2 = s => { };
            //Delegate3 dl3 = () => { return string.Empty; };
            Delegate3 dl3 = () => string.Empty;
            Delegate4 dl4 = s => s;
            Delegate5 dl5 = (s, x) =>
            {
                var xs = x.ToString();
                return($"{s}{xs}");
            };


            var odd = Enumerable.Range(0, 100).Where(i => i % 2 == 1);

            int[] array = Enumerable.Range(0, 100).ToArray();

            var myOdd  = array.Filter(i => i % 2 == 1);
            var myEven = array.Filter(i => i % 2 == 0);
        }
Example #10
0
 public void Dispose()
 {
     if (this.thread_0 != null)
     {
         try
         {
             this.bool_0 = true;
             if (this.intptr_0 != IntPtr.Zero)
             {
                 Class162.waveInReset(this.intptr_0);
             }
             this.method_1();
             this.thread_0.Join();
             this.delegate2_0 = null;
             this.method_0();
             if (this.intptr_0 != IntPtr.Zero)
             {
                 Class162.waveInClose(this.intptr_0);
             }
         }
         finally
         {
             this.thread_0 = null;
             this.intptr_0 = IntPtr.Zero;
         }
     }
     GC.SuppressFinalize(this);
 }
Example #11
0
 public void Dispose()
 {
     if (_thread0 != null)
     {
         try
         {
             _bool0 = true;
             if (_intptr0 != IntPtr.Zero)
             {
                 Class162.waveInReset(_intptr0);
             }
             method_1();
             _thread0.Join();
             _delegate20 = null;
             method_0();
             if (_intptr0 != IntPtr.Zero)
             {
                 Class162.waveInClose(_intptr0);
             }
         }
         finally
         {
             _thread0 = null;
             _intptr0 = IntPtr.Zero;
         }
     }
     GC.SuppressFinalize(this);
 }
        public void One_TimeoutSet_ButCompletesBeforeTimeout()
        {
            TestInquiryBtIf btIf;
            BluetoothClient cli;

            //
            Create_BluetoothClient(out btIf, out cli);
            cli.InquiryLength = TimeSpan.FromSeconds(1);
            //
            Assert.IsFalse(btIf.testDoCallbacksFromWithinStartInquiry, "tdcfwsi");
            ThreadStart dlgt = delegate {
                bool signalled = btIf.startInquiryCalled.WaitOne(10000, false);
                Assert.IsTrue(signalled, "!signalled!!!!!");
                btIf.InquiryEventsOne();
            };
            IAsyncResult arDlgt = Delegate2.BeginInvoke(dlgt, null, null);

            //
            WidcommBluetoothClient.ReadKnownDeviceFromTheRegistry = false;
            BluetoothDeviceInfo[] devices = cli.DiscoverDevices();
            Delegate2.EndInvoke(dlgt, arDlgt); // any exceptions?
            VerifyDevicesOne(devices);
            Assert.AreEqual(1, btIf.stopInquiryCalled, "stopInquiryCalled");
            // Wait around, trying to see any exception on the timeout thread.
            Thread.Sleep(1650);
        }
Example #13
0
        static void method(Delegate1 d, Delegate2 e, System.Delegate f)
        {
            //컴파일 에러
            //Console.WriteLine(d==e);

            //
            System.Console.WriteLine(d == f);
        }
Example #14
0
 // Token: 0x060024FA RID: 9466
 // RVA: 0x0001CDB8 File Offset: 0x0001AFB8
 public Class523(VoidDelegate voidDelegate_1, Delegate2 delegate2_1)
     : base(false)
 {
     Class115.bool_31 = true;
     this.voidDelegate_0 = voidDelegate_1;
     this.delegate2_0 = delegate2_1;
     this.thread_0 = Class115.smethod_87(new VoidDelegate(this.method_0));
 }
Example #15
0
        //===================================
        //delegate TResult Func<T1, T2, TResult>(T1 p1, T2 p2);

        protected IAsyncResult BeginTimedRead_(Stream stream, bool expectedToThrow, int?expectedError)
        {
            Trace.Assert(expectedError.HasValue == expectedToThrow);
            Func <Stream, bool, int?, int> dlgt = TimedRead_Runner;
            Func <int> dlgt0 = delegate { return(dlgt(stream, expectedToThrow, expectedError)); };

            return(Delegate2.BeginInvoke(dlgt0, null, dlgt0));
        }
Example #16
0
        public void Invoke4()
        {
            Delegate2 del2 = new Delegate2(Helper.WorkPerformed6);
            Delegate3 del3 = new Delegate3(Helper.WorkPerformed7);

            del2(35, WorkType.Golf);
            int result = del3(45, 2);
            Console.WriteLine(result);
        }
Example #17
0
        // Comparing delegates of two different types assigned at compile-time will result in a compilation error. If the delegate
        // instances are statically of the type System.Delegate, then the comparison is allowed, but will return false at run time.
        static void method(Delegate1 d, Delegate2 e, System.Delegate f)
        {
            // Compile-time error.
            //Console.WriteLine(d == e);

            // OK at compile-time. False if the run-time type of f
            // is not the same as that of d.
            Console.WriteLine(d == f);
        }
Example #18
0
        static void Main(string[] args)
        {
            Delegate1 my   = new Delegate1(Method1);
            Delegate2 math = my();

            Console.WriteLine(math(5));
            Console.WriteLine();
            Console.ReadKey();
        }
Example #19
0
        static void Main(string[] args)
        {
            string    input  = Console.ReadLine();
            Delegate1 myDel1 = () => Method1; // Использована техника предположения делегата
            Delegate2 myDel2 = myDel1();

            myDel2(input);
            Console.ReadKey();
        }
Example #20
0
        public static void Run()
        {
            Delegate1 deleg1 = FooDelegate;
            Delegate2 deleg2 = FooDelegate;

            //deleg2 = deleg1;

            RunDelegatsArgContvar();
            RunDelegatsReturnCovar();
        }
Example #21
0
        public void Invoke2()
        {
            Delegate2 del1 = new Delegate2(Helper.WorkPerformed4);
            Delegate2 del2 = new Delegate2(Helper.WorkPerformed5);
            Delegate2 del3 = new Delegate2(Helper.WorkPerformed6);

            del1 += del2 + del3;

            int result = del1(10, WorkType.Golf);
            Console.WriteLine(result);
        }
        static void Main(string[] args)
        {
            Delegate1 obj = AddNums1;
            double result = obj.Invoke(10, 20.5f, 50.2);
            Console.WriteLine(result);
            Delegate2 obj2 = AddNums2;
            obj2.Invoke(10, 55.2f,12.5);
           //
            Console.Read();


        }
        static void Main(string[] args)
        {
            int num = 22869;

            int[] arr = new int[] { 69, 96, 14, 88, 11, 22, 33, 44, 56, 66 };

            Delegate1 del1 = new Delegate1(Class1.FormArray);
            Delegate2 del2 = new Delegate2(Class1.DisplayArray);

            del2(del1(num));
            del2(arr);
        }
Example #24
0
        /// <summary>
        /// Находит максимум через делегата
        /// </summary>
        /// <param name="f">Метод делегат</param>
        /// <param name="data">Данные</param>
        /// <returns>Минимум</returns>
        public double Max(Delegate2 f, double[] data)
        {
            double max = double.MinValue;

            for (int i = 0; i < data.Length; i++)
            {
                if (f(data[i], max) > 0)
                {
                    max = data[i];
                }
            }
            return(max);
        }
Example #25
0
        static void Main(string[] args)
        {
            var delegateInstance1 = new Delegate1(Method01);

            delegateInstance1();
            Delegate1 delegateInstance2 = Method01;

            delegateInstance2();
            Action delegateInstance3 = Method01;

            Delegate2 delegateInstance4 = (x) => { return((int)Math.Pow(x, 3)); };
            Delegate2 delegateInstance5 = x => (int)Math.Pow(x, 3);
        }
Example #26
0
        /// <summary>
        /// Находит минимум через делегата
        /// </summary>
        /// <param name="f">Метод делегат</param>
        /// <param name="data">Данные</param>
        /// <returns>Минимум</returns>
        public double Min(Delegate2 f, double[] data)
        {
            double min = double.MaxValue;

            for (int i = 0; i < data.Length; i++)
            {
                if (f(data[i], min) < 0)
                {
                    min = data[i];
                }
            }
            return(min);
        }
Example #27
0
        static void Main(string[] args)
        {
            Delegate1 d1 = new Delegate1(Method1);
            Delegate2 d2 = d1();

            d2();

            Functional func = new Functional(MethodF);

            D3 d3 = func.Invoke(new D1(M1), new D2(M2));

            Console.WriteLine(d3.Invoke());
        }
        public void Ebap_TwoWithSecondNameEvent()
        {
            TestInquiryBtIf btIf;
            BluetoothClient cli;

            //
            Create_BluetoothClient(out btIf, out cli);
            Assert.IsFalse(btIf.testDoCallbacksFromWithinStartInquiry, "tdcfwsi");
            ThreadStart dlgt = delegate {
                bool signalled = btIf.startInquiryCalled.WaitOne(10000, false);
                Assert.IsTrue(signalled, "!signalled!!!!!");
                btIf.InquiryEventsTwoWithSecondNameEvent();
            };
            IAsyncResult arDlgt = Delegate2.BeginInvoke(dlgt, null, null);

            //
            WidcommBluetoothClient.ReadKnownDeviceFromTheRegistry = false;
            var bc           = new BluetoothComponent(cli);
            var devicesSteps = new List <BluetoothDeviceInfo[]>();

            BluetoothDeviceInfo[] devicesResult = null;
            var complete = new ManualResetEvent(false);

            bc.DiscoverDevicesProgress += delegate(object sender, DiscoverDevicesEventArgs e) {
                devicesSteps.Add(e.Devices);
            };
            bc.DiscoverDevicesComplete += delegate(object sender, DiscoverDevicesEventArgs e) {
                try {
                    devicesResult = e.Devices;
                } finally {
                    complete.Set();
                }
            };
            bc.DiscoverDevicesAsync(255, true, true, true, false, 999);
            bool signalled2 = complete.WaitOne(15000);

            Assert.IsTrue(signalled2, "signalled2");
            Delegate2.EndInvoke(dlgt, arDlgt); // any exceptions?
            VerifyDevicesOne(devicesResult);
            Assert.AreEqual(3, devicesSteps.Count);
            Assert.AreEqual(1, devicesSteps[0].Length, "[0].Len");
            Assert.AreEqual(AddressA, devicesSteps[0][0].DeviceAddress, "[0][0].Addr");
            Assert.AreEqual(AddressA.ToString("C"), devicesSteps[0][0].DeviceName, "[0][0].Name"); // no name
            Assert.AreEqual(1, devicesSteps[1].Length, "[1].Len");
            Assert.AreEqual(AddressB, devicesSteps[1][0].DeviceAddress, "[1][0].Addr");
            Assert.AreEqual(NameB, devicesSteps[1][0].DeviceName, "[1][0].Name");
            Assert.AreEqual(1, devicesSteps[2].Length, "[2].Len");
            Assert.AreEqual(AddressA, devicesSteps[2][0].DeviceAddress, "[2][0].Addr");
            Assert.AreEqual(NameA, devicesSteps[2][0].DeviceName, "[2][0].Name");
            Assert.AreEqual(1, btIf.stopInquiryCalled, "stopInquiryCalled");
        }
Example #29
0
        static void Main()
        {
            // Создаем экземпляр делегата delegate1 типа Delegate1 и сообщаем с ним Method1
            Delegate1 delegate1 = new Delegate1(Method1);

            // Создаем экземпляр делегата delegate1 типа Delegate1 и сообщаем с ним Method1
            Delegate2 delegate2 = delegate1.Invoke();

            // Вызываем метод сообщенный с делегатом.
            delegate2.Invoke();

            // Задержка.
            Console.ReadKey();
        }
 public static void SetText2 <TObject>(TObject objCtrl, string text, Form winf) where TObject : ToolStripStatusLabel
 {
     if (objCtrl.Owner.InvokeRequired)
     {
         Delegate2 method = new Delegate2(CallCtrlWithThreadSafety.SetText2 <ToolStripStatusLabel>);
         if (!winf.IsDisposed)
         {
             winf.Invoke(method, new object[] { objCtrl, text, winf });
         }
     }
     else
     {
         objCtrl.Text = text;
     }
 }
Example #31
0
        int EndTimedRead(object ar)
        {
#if false
            IAsyncResult             ar2  = (IAsyncResult)ar;
            Func <Stream, bool, int> dlgt = (Func <Stream, bool, int>)ar2.AsyncState;
            int period = dlgt.EndInvoke(ar2);
            return(period);
#else
            IAsyncResult ar2 = (IAsyncResult)ar;
            //Func<Stream, bool, int> dlgt = (Func<Stream, bool, int>)ar2.AsyncState;
            //Func<int> dlgt0 = null;
            Func <int> dlgt0  = (Func <int>)ar2.AsyncState;
            int        period = Delegate2.EndInvoke(dlgt0, ar2);
            return(period);
#endif
        }
Example #32
0
        public static Delegate3 MethodF(Delegate1 delegate1, Delegate2 delegate2)
        {
            #region Cтарий варіант, який необхідно замінити
#if false
            return(delegate { return delegate1.Invoke() + delegate2.Invoke(); });
#endif
            #endregion

            #region Аналог старого варіанту який не підходить, так як в старих версіях це не реалізувало б замикання
#if false
            return(() => delegate1.Invoke() + delegate2.Invoke());
#endif
            #endregion

            #region Варіант з використанням Nested функції (локальної функції)
#if false
            // але в такому випадку втрачається смисл передавати в даний метод вхідні дані,
            // так як реалізація конкатанації рядків відбуваєтсья в методі AnonymousMethod()
            //return AnonymousMethod;

            // локальна функція
            string NestedMethod()
            {
                return(delegate1.Invoke() + delegate2.Invoke());
            }

            // ще простіше простіше скориставшись локальною функцією
            return(NestedMethod);
#endif
            #endregion

            #region Варіант з використанням статичних методів (можна і через звичайні, що практично дублюватиме логіку)
#if false
            // приймаємо два делегата, виконуємо і результат заносимо в поле
            ResBothDel(delegate1, delegate2);
            // зчитуємо дані з поля і передаємо їх іншим методом
            return(ForDel3);
#endif
            #endregion

            #region Варіант з використанням Extention - методів розширення
#if true
            // можна  було б назвати: методика "кидок через плече"
            return(ResDel12(delegate1, delegate2).ExMethodDel12);
#endif
            #endregion
        }
Example #33
0
        static void Main(string[] args)
        {
            Delegate1 obj1   = AddNums1; //or new DelegatesProj.Delegate1(AddNums1);
            double    result = obj1.Invoke(100, 34.2f, 129.221);

            Console.WriteLine(result);

            Delegate2 obj2 = AddNums2;

            obj2.Invoke(100, 32.2f, 129.221);

            Delegate3 obj3   = CheckLength;
            bool      status = obj3.Invoke("Hello World");

            Console.WriteLine(status);
            Console.ReadLine();
        }
Example #34
0
    internal byte[] method_11(byte[] A_0, Delegate2 A_1, int A_2)
    {
        int length = A_0.Length;

        byte[] dst     = new byte[length];
        byte[] buffer2 = new byte[A_2];
        byte[] buffer3 = new byte[A_2];
        for (int i = 0; i < length; i += A_2)
        {
            int num3  = length - i;
            int count = Math.Min(num3, A_2);
            Buffer.BlockCopy(A_0, i, buffer2, 0, count);
            A_1(buffer2, buffer3);
            Buffer.BlockCopy(buffer3, 0, dst, i, count);
        }
        return(dst);
    }
	public static int test() {
		var obj = new Delegate2();
		return obj.method();
	}
Example #36
0
 public static Delegate3 MethodF(Delegate1 delegate1, Delegate2 delegate2)
 {
     return delegate { return delegate1.Invoke() + delegate2.Invoke(); };
 }
 public void Method1(Delegate1 x, Delegate2 y)
 {
 }