Exemplo n.º 1
0
        private ResolvedClipboardTrigger CreateResolvedClipboardTrigger(ClipboardTrigger trigger, IDataObject dataObject)
        {
            // Check if clipboard object already exists in list
            if (dataObject.TryGetWClipboardId(out var guid) && _allCollection.TryGetValue(guid, out var refClipboardObject))
            {
                refClipboardObject.Triggers.Add(trigger);
                return(new ResolvedClipboardTrigger(trigger, refClipboardObject, ResolvedClipboardTriggerType.WClipboardId));
            }

            //Extract Formats
            //TODO retry exceptions
            var equatableFormats = formatsExtractors.SelectMany(fe => fe.Extract(trigger, dataObject)).ToList();

            trigger.AdditionalInfo.Add(new OriginalFormatsInfo(dataObject.GetFormats()));

            //Check if it contains any data
            if (equatableFormats.Count == 0)
            {
                return(new ResolvedClipboardTrigger(trigger, null, ResolvedClipboardTriggerType.Invalid));
            }

            //Filter
            if (ShouldFilter(trigger, equatableFormats))
            {
                return(new ResolvedClipboardTrigger(trigger, null, ResolvedClipboardTriggerType.Filtered));
            }

            //Check for Equals
            return(CheckForEqualsReference(trigger, dataObject, equatableFormats));
        }
Exemplo n.º 2
0
        public ResolvedClipboardTrigger ProcessClipboardTrigger(ClipboardTrigger trigger, IDataObject dataObject)
        {
            var resolvedClipboardTrigger = CreateResolvedClipboardTrigger(trigger, dataObject);

            ProcessResolvedClipboardTrigger(resolvedClipboardTrigger);
            return(resolvedClipboardTrigger);
        }
Exemplo n.º 3
0
        public Task <ResolvedClipboardTrigger> ProcessClipboardTrigger(ClipboardTrigger trigger)
        {
            var queueItem = new ClipboardTriggerQueueItem(trigger);

            _triggerQueue.Add(queueItem);
            return(queueItem.Task.Task);
        }
Exemplo n.º 4
0
        public bool ShouldFilter(ClipboardTrigger clipboardTrigger, IEnumerable <EqualtableFormat> equaltableFormats)
        {
            if (programFilterSetting.Value is List <string> paths)
            {
                if (clipboardTrigger.DataSourceProgram?.Path != null && paths.Any(p => string.Equals(p, clipboardTrigger.DataSourceProgram.Path, System.StringComparison.OrdinalIgnoreCase)))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 5
0
 public ClipboardObject(Guid id, ClipboardTrigger mainTrigger, ClipboardObject?linked)
 {
     Id              = id;
     MainTrigger     = mainTrigger;
     Linked          = linked;
     Implementations = new ConcurrentObservableList <ClipboardImplementation>();
     Implementations.CollectionChanged += CheckIfImplementationShouldBeInThis;
     Properties = new ConcurrentObservableList <ClipboardObjectProperty>();
     Triggers   = new ConcurrentObservableList <ClipboardTrigger>
     {
         MainTrigger
     };
 }
Exemplo n.º 6
0
        public bool ShouldFilter(ClipboardTrigger clipboardTrigger, IEnumerable <EqualtableFormat> equaltableFormats)
        {
            if (clipboardTrigger.AdditionalInfo.TryGetValue <Windows10HistoryInfo>(out var historyInfo) && !historyInfo.Allowed && historySetting.GetValue <bool>())
            {
                return(true);
            }
            if (clipboardTrigger.AdditionalInfo.TryGetValue <Windows10CloudInfo>(out var cloudInfo) && !cloudInfo.Allowed && cloudSetting.GetValue <bool>())
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 7
0
        public ResolvedClipboardTrigger CreateResolvedCustomClipboardTrigger(ClipboardTrigger trigger, ClipboardObject?linked = null, Guid?id = null)
        {
            if (!(trigger.Type is CustomClipboardTriggerType))
            {
                throw new ArgumentException($"It is not allowed to use {nameof(CreateResolvedCustomClipboardTrigger)} with a {nameof(ClipboardTrigger)} that has a {nameof(ClipboardTrigger.Type)} that is not a {nameof(CustomClipboardTriggerType)}", nameof(trigger));
            }
            if (id.HasValue && _allCollection.ContainsKey(id.Value))
            {
                throw new ArgumentException($"There is already an {nameof(ClipboardObject)} with this id", nameof(id));
            }


            return(CreateResolvedCustomClipboardTriggerInternal(trigger, id ?? NewWClipboardId(), linked));
        }
 public IEnumerable <EqualtableFormat> Extract(ClipboardTrigger trigger, IDataObject dataObject)
 {
     if (dataObject.TryGetData(DefaultClipboardFormats.Unicode.Format, out var unicode) && unicode is string unicodeText)
     {
         yield return(new TextEquatableFormat(DefaultClipboardFormats.Unicode, unicodeText));
     }
     if (dataObject.TryGetData(DefaultClipboardFormats.FileDrop.Format, out var fileDrop) && fileDrop is string[] paths)
     {
         yield return(new PathsEquatableFormat(DefaultClipboardFormats.FileDrop, paths));
     }
     if (dataObject.TryGetData(DefaultClipboardFormats.Bitmap.Format, out var bitmap) && bitmap is BitmapSource bitmapSource)
     {
         yield return(new BitmapEquatableFormat(DefaultClipboardFormats.Bitmap, bitmapSource));
     }
 }
Exemplo n.º 9
0
        private ResolvedClipboardTrigger CreateResolvedTrigger(ClipboardTrigger trigger, IDataObject dataObject, IEnumerable <EqualtableFormat> equaltableFormats)
        {
            // Check if linked
            ClipboardObject?linked = null;

            if (dataObject.TryGetLinkedWClipboardId(out var linkedGuid))
            {
                _allCollection.TryGetValue(linkedGuid, out linked);
            }

            //Create
            var returner = CreateResolvedCustomClipboardTriggerInternal(trigger, NewWClipboardId(), linked: linked);

            _objectManager.AddImplementationsAsync(returner.Object !, equaltableFormats); //returner.Object should never be null from previous method
            return(returner);
        }
Exemplo n.º 10
0
        private ResolvedClipboardTrigger CheckForEqualsReference(ClipboardTrigger trigger, IDataObject dataObject, List <EqualtableFormat> equatableFormats)
        {
            var registrations = new List <ExistsEqualtableFormatContainer>(equatableFormats.Count);

            registrations.AddRange(equatableFormats.Select(ef => new ExistsEqualtableFormatContainer(ef)));

            foreach (var clipboardObject in _allCollection)
            {
                if (CheckForEqualsReference(registrations, clipboardObject))
                {
                    clipboardObject.Triggers.Add(trigger);
                    return(new ResolvedClipboardTrigger(trigger, clipboardObject, ResolvedClipboardTriggerType.EqualsReference));
                }
            }

            return(CreateResolvedTrigger(trigger, dataObject, equatableFormats));
        }
        public IEnumerable <EqualtableFormat> Extract(ClipboardTrigger trigger, IDataObject dataObject)
        {
            if (dataObject.TryGetData(HistoryFormat, out var historyObj) && historyObj is MemoryStream historyMemoryStream && historyMemoryStream.Length == 4)
            {
                using (var br = new BinaryReader(historyMemoryStream))
                {
                    trigger.AdditionalInfo.Add(new Windows10HistoryInfo(br.ReadInt32() != 0));
                }
            }
            if (dataObject.TryGetData(CloudFormat, out var cloudObj) && cloudObj is MemoryStream cloudMemoryStream && cloudMemoryStream.Length == 4)
            {
                using (var br = new BinaryReader(cloudMemoryStream))
                {
                    trigger.AdditionalInfo.Add(new Windows10CloudInfo(br.ReadInt32() != 0));
                }
            }

            return(Enumerable.Empty <EqualtableFormat>());
        }
Exemplo n.º 12
0
 public Task ProcessClipboardTrigger(ClipboardTrigger trigger)
 {
     return(clipboardTriggerScheduler.Schedule(trigger));
 }
Exemplo n.º 13
0
        private ResolvedClipboardTrigger CreateResolvedCustomClipboardTriggerInternal(ClipboardTrigger trigger, Guid id, ClipboardObject?linked = null)
        {
            var clipboardObject = new ClipboardObject(id, trigger, linked);

            return(new ResolvedClipboardTrigger(trigger, clipboardObject, ResolvedClipboardTriggerType.Created));
        }
 internal ResolvedClipboardTrigger(ClipboardTrigger trigger, ClipboardObject?clipboardObject, ResolvedClipboardTriggerType resolvedType)
 {
     Trigger      = trigger;
     Object       = clipboardObject;
     ResolvedType = resolvedType;
 }
Exemplo n.º 15
0
 public ClipboardTriggerQueueItem(ClipboardTrigger trigger)
 {
     Trigger = trigger;
     Task    = new TaskCompletionSource <ResolvedClipboardTrigger>();
 }
Exemplo n.º 16
0
        public async Task Schedule(ClipboardTrigger trigger)
        {
            if (trigger.Type is OSClipboardTriggerType)
            {
                lock (this)
                {
                    if (_currentMergableTrigger != null)
                    {
                        if (trigger.When >= _currentMergableTrigger.When && trigger.When <= _currentMergableTrigger.When + ((MergableClipboardTriggerType)_currentMergableTrigger.Type).MergeTimeout)
                        {
                            trigger.Merge(_currentMergableTrigger);
                            _currentMergableTrigger = null;
                        }
                    }

                    _lastOSTrigger = trigger;
                }
            }
            else if (trigger.Type is MergableClipboardTriggerType mergable)
            {
                lock (this)
                {
                    if (_currentMergableTrigger != null)
                    {
                        clipboardClonerThread.ProcessClipboardTrigger(_currentMergableTrigger).ConfigureAwait(false);
                        _currentMergableTrigger = null;
                    }

                    if (_lastOSTrigger != null)
                    {
                        if (_lastOSTrigger.When >= trigger.When - mergable.MergeBefore && _lastOSTrigger.When <= trigger.When)
                        {
                            _lastOSTrigger.Merge(trigger);
                            _lastOSTrigger = null;
                            //exit method, trigger is already merged
                            return;
                        }
                    }

                    _currentMergableTrigger = trigger;
                }

                await Task.Delay(trigger.When + mergable.MergeTimeout - System.DateTime.Now).ConfigureAwait(false);

                lock (this)
                {
                    if (trigger == _currentMergableTrigger)
                    {
                        _currentMergableTrigger = null;
                        //exit lock and resolve
                    }
                    else
                    {
                        //exit method, trigger is already merged
                        return;
                    }
                }
            }

            await clipboardClonerThread.ProcessClipboardTrigger(trigger).ConfigureAwait(false);
        }
Exemplo n.º 17
0
 private bool ShouldFilter(ClipboardTrigger trigger, IEnumerable <EqualtableFormat> equaltableFormats)
 {
     return(clipboardFilters.Any(cf => cf.ShouldFilter(trigger, equaltableFormats)));
 }