Пример #1
0
            private void EnsureEffectiveCaptureState()
            {
                if (_targets.Any())
                {
                    // We have some target, self enable us

                    if (_actives.TryGetValue(Pointer, out var capture))
                    {
                        if (capture != this)
                        {
                            throw new InvalidOperationException("There is already another active capture.");
                        }
                    }
                    else
                    {
                        // This is what makes this capture active
                        _actives.Add(Pointer, this);
                    }

                    if (_nativeCaptureElement == null)
                    {
                        _nativeCaptureElement = _targets.Single().Value.NativeCaptureElement;

                        try
                        {
                            _nativeCaptureElement.CapturePointerNative(Pointer);
                        }
                        catch (Exception e)
                        {
                            this.Log().Error($"Failed to capture natively pointer {Pointer}.", e);
                        }
                    }
                }
                else
                {
                    // We no longer have any target, cleanup

                    if (_nativeCaptureElement != null)
                    {
                        try
                        {
                            _nativeCaptureElement.ReleasePointerNative(Pointer);
                        }
                        catch (Exception e)
                        {
                            this.Log().Error($"Failed to release native capture of {Pointer}", e);
                        }

                        _nativeCaptureElement = null;
                    }

                    if (_actives.TryGetValue(Pointer, out var capture) && capture == this)
                    {
                        // This is what makes this capture inactive
                        _actives.Remove(Pointer);
                    }
                }
            }
Пример #2
0
 private void CapturePointerNative()
 {
     try
     {
         _nativeCaptureElement.CapturePointerNative(Pointer);
     }
     catch (Exception e)
     {
         this.Log().Error($"Failed to capture natively pointer {Pointer}.", e);
     }
 }