private static RegisterDelegate ResolveRegisterDelegate()
        {
            // The fallback is just a normal register that capatures the execution context.
            RegisterDelegate fallback = (ref CancellationToken token, Action <object> callback, object state) =>
            {
                return(token.Register(callback, state));
            };

#if NETFX_CORE || PORTABLE
            return(fallback);
#else
            //
            // Just do not continue if we are running mono, and return the default fallback.
            // This makes it work with Mono 3.99 (the latest dev branch)
            //
            if (MonoUtility.IsRunningMono)
            {
                return(fallback);
            }

            MethodInfo methodInfo = null;

            try
            {
                // By default we don't want to capture the execution context,
                // since this is internal we need to create a delegate to this up front
                methodInfo = typeof(CancellationToken).GetMethod("InternalRegisterWithoutEC",
                                                                 BindingFlags.NonPublic | BindingFlags.Instance,
                                                                 binder: null,
                                                                 types: new[] { typeof(Action <object>), typeof(object) },
                                                                 modifiers: null);
            }
            catch
            {
                // Swallow this exception. Being extra paranoid, we don't want anything to break in case this dirty
                // reflection hack fails for any reason
            }

            // If the method was removed then fallback to the regular method
            if (methodInfo == null)
            {
                return(fallback);
            }

            try
            {
                return((RegisterDelegate)Delegate.CreateDelegate(typeof(RegisterDelegate), null, methodInfo));
            }
            catch
            {
                // If this fails for whatever reason just fallback to normal register
                return(fallback);
            }
#endif
        }
Exemple #2
0
        public Form1()
        {
            InitializeComponent();

            udpClient = new UdpClient(REGISTER_PORT);

            outputScanDelegate  = OutputScannedNetworks;
            stoppedBindDelegate = OutputBindCompleted;

            telnetDelegate   = TelnetDrone;
            registerDelegate = RegisterDrone;

            statusDelegate = StatusEx;
        }
        private static RegisterDelegate ResolveRegisterDelegate()
        {
            // The fallback is just a normal register that capatures the execution context.
            RegisterDelegate fallback = (ref CancellationToken token, Action <object> callback, object state) =>
            {
                return(token.Register(callback, state));
            };

            // PORT: The code is defensive enough that we could just remove the #ifs here.
#if NETSTANDARD1_3 || NETSTANDARD2_0
            return(fallback);
#elif NET40 || NET45
            MethodInfo methodInfo = null;

            try
            {
                // By default we don't want to capture the execution context,
                // since this is internal we need to create a delegate to this up front
                methodInfo = typeof(CancellationToken).GetMethod("InternalRegisterWithoutEC",
                                                                 BindingFlags.NonPublic | BindingFlags.Instance,
                                                                 binder: null,
                                                                 types: new[] { typeof(Action <object>), typeof(object) },
                                                                 modifiers: null);
            }
            catch
            {
                // Swallow this exception. Being extra paranoid, we don't want anything to break in case this dirty
                // reflection hack fails for any reason
            }

            // If the method was removed then fallback to the regular method
            if (methodInfo == null)
            {
                return(fallback);
            }

            try
            {
                return((RegisterDelegate)Delegate.CreateDelegate(typeof(RegisterDelegate), null, methodInfo));
            }
            catch
            {
                // If this fails for whatever reason just fallback to normal register
                return(fallback);
            }
#else
#error Unsupported framework.
#endif
        }
        private static RegisterDelegate ResolveRegisterDelegate()
        {
            // The fallback is just a normal register that capatures the execution context.
            RegisterDelegate fallback = (ref CancellationToken token, Action <object> callback, object state) =>
            {
                return(token.Register(callback, state));
            };

#if NETFX_CORE || PORTABLE || DNXCORE50
            return(fallback);
#else
            MethodInfo methodInfo = null;

            try
            {
                // By default we don't want to capture the execution context,
                // since this is internal we need to create a delegate to this up front
                methodInfo = typeof(CancellationToken).GetMethod("InternalRegisterWithoutEC",
                                                                 BindingFlags.NonPublic | BindingFlags.Instance,
                                                                 binder: null,
                                                                 types: new[] { typeof(Action <object>), typeof(object) },
                                                                 modifiers: null);
            }
            catch
            {
                // Swallow this exception. Being extra paranoid, we don't want anything to break in case reflection fails for any reason.
            }

            // If the method was removed then fallback to the regular method
            if (methodInfo == null)
            {
                return(fallback);
            }

            try
            {
                return((RegisterDelegate)Delegate.CreateDelegate(typeof(RegisterDelegate), null, methodInfo));
            }
            catch
            {
                // If this fails for whatever reason just fallback to normal register
                return(fallback);
            }
#endif
        }
Exemple #5
0
 public void SetMethods(
     ConstructDelegate construct,
     OnAssignDelegate onAssign,
     CheckDelegate check,
     ActionDelegate action,
     RegisterDelegate register,
     DisplayDelegate display,
     AddVerbDelegate addVerb,
     ParseInputDelegate parseInput
     )
 {
     ConstructMethod  = construct != null ? construct : ConstructDefault;
     OnAssignMethod   = onAssign != null ? onAssign : OnAssignDefault;
     CheckMethod      = check != null ? check : CheckDefault;
     ActionMethod     = action != null ? action : ActionDefault;
     RegisterMethod   = register != null ? register : RegisterDefault;
     DisplayMethod    = display != null ? display : DisplayDefault;
     AddVerbMethod    = addVerb != null ? addVerb : AddVerbDefault;
     ParseInputMethod = parseInput != null ? parseInput : ParseInputDefault;
 }
 public Register()
 {
     InitializeComponent();
     registerDel = RegisterCheck;
 }
 private void Register_button_Click(object sender, RoutedEventArgs e)
 {
     RegisterDelegate rd = new RegisterDelegate(register);
     rd.BeginInvoke(this.Text_regIp.Text, 
         this.Text_regPort.Text, 
         this.Text_regUser.Text, 
         this.Box_regPwd1.Password, 
         this.Box_regPwd2.Password, null, null);
 }