Example #1
0
        private void ScannerOnToolAttach(HcToolInfo info)
        {
            var lockTakenScan     = false;
            var lockTakenRegister = false;

            try
            {
                // lock
                Monitor.TryEnter(ScannedTools, Timeout, ref lockTakenScan);
                Monitor.TryEnter(RegisteredTools, Timeout, ref lockTakenRegister);
                // check lock taken
                if (!lockTakenScan || !lockTakenRegister)
                {
                    return;
                }

                // get tools
                var register = FindToolInfo(RegisteredTools, info.Mac);
                var scan     = FindToolInfo(ScannedTools, info.Mac);
                // check scan tool
                switch (scan)
                {
                case null when register == null:
                    // add scan tool
                    ScannedTools.Add(info);
                    break;

                case null:
                    // set values
                    register.SetValues(info.GetValues());
                    // tool connect event
                    ToolConnect?.Invoke(register);
                    break;
                }
            }
            finally
            {
                // unlock
                if (lockTakenScan)
                {
                    Monitor.Exit(ScannedTools);
                }
                if (lockTakenRegister)
                {
                    Monitor.Exit(RegisteredTools);
                }
            }
        }
Example #2
0
        private void ScannerOnToolAlive(HcToolInfo info)
        {
            var lockTakenScan     = false;
            var lockTakenRegister = false;

            try
            {
                // lock
                Monitor.TryEnter(ScannedTools, Timeout, ref lockTakenScan);
                Monitor.TryEnter(RegisteredTools, Timeout, ref lockTakenRegister);
                // check lock taken
                if (!lockTakenScan || !lockTakenRegister)
                {
                    return;
                }

                // get tools
                var register = FindToolInfo(RegisteredTools, info.Mac);
                var scan     = FindToolInfo(ScannedTools, info.Mac);
                // check scan/register tool
                if (scan == null && register == null)
                {
                    // add scan tool
                    ScannedTools.Add(info);
                }
                else if (register != null)
                {
                    // event
                    ToolAlive?.Invoke(info);
                }
            }
            finally
            {
                // unlock
                if (lockTakenScan)
                {
                    Monitor.Exit(ScannedTools);
                }
                if (lockTakenRegister)
                {
                    Monitor.Exit(RegisteredTools);
                }
            }
        }