Beispiel #1
0
        public void TryRemove(ClipboardObject clipboardObject, ClipboardObjectRemoveType type)
        {
            if (_linkedCollection.ContainsKey(clipboardObject))
            {
                return;
            }
            else if (!_listeners.All(l => l.CanRemove(clipboardObject, type)))
            {
                return;
            }

            if (clipboardObject.Linked != null)
            {
                if (_linkedCollection.TryGetValue(clipboardObject.Linked, out var parentsChilderen))
                {
                    parentsChilderen.Remove(clipboardObject);

                    if (parentsChilderen.Count == 0)
                    {
                        _linkedCollection.TryRemove(clipboardObject.Linked, out var _);
                        TryRemove(clipboardObject.Linked, type);
                    }
                }
            }

            _allCollection.Remove(clipboardObject);

            InformListeners(l => l.OnClipboardObjectRemoved(clipboardObject));

            //TODO
            GC.Collect();
        }
Beispiel #2
0
        public async Task AddImplementationsAsync(ClipboardObject clipboardObject, Stream stream, ClipboardFormat format)
        {
            var implementations = (await Task.WhenAll(_implementationFactories.Select(f => f.Deserialize(clipboardObject, stream, format))).ConfigureAwait(false)).SelectMany(i => i).ToList();

            foreach (var implementation in implementations)
            {
                clipboardObject.Implementations.Add(implementation);
            }
        }
Beispiel #3
0
 private bool FetchAutoRemoveRecursive(Predicate <ClipboardObject> condition, ClipboardObject current, Queue <ClipboardObject> removeQueue)
 {
     if (current.IsAutoRemovalAllowed() && condition(current))
     {
         var removeAllowed = true;
         if (_linkedCollection.TryGetValue(current, out var currentChilds))
         {
             removeAllowed = currentChilds.All(c => FetchAutoRemoveRecursive(condition, c, removeQueue));
         }
         if (removeAllowed)
         {
             removeQueue.Enqueue(current);
         }
         return(removeAllowed);
     }
     return(false);
 }
Beispiel #4
0
        public static async Task <DataObject> GetDataObject(this ClipboardObject clipboardObject)
        {
            var dataObject = new DataObject();

            DataObjectExtensions.SetWClipboardId(dataObject, clipboardObject.Id);
            if (clipboardObject.Linked != null)
            {
                DataObjectExtensions.SetLinkedWClipboardId(dataObject, clipboardObject.Linked.Id);
            }

            foreach (var implementation in clipboardObject.Implementations)
            {
                await implementation.Factory.WriteToDataObject(implementation, dataObject);
            }

            return(dataObject);
        }
Beispiel #5
0
 private async Task AddImplementationsAsync(ClipboardObject clipboardObject, EqualtableFormat equatableFormat)
 {
     clipboardObject.Implementations.AddRange((await Task.WhenAll(_implementationFactories.Select(f => f.CreateFromEquatable(clipboardObject, equatableFormat))).ConfigureAwait(false)).NotNull());
 }
Beispiel #6
0
 public async Task AddImplementationsAsync(ClipboardObject clipboardObject, IEnumerable <EqualtableFormat> equaltableFormats)
 {
     await Task.WhenAll(equaltableFormats.Select(ef => AddImplementationsAsync(clipboardObject, ef))).ConfigureAwait(false);
 }
Beispiel #7
0
        private bool CheckForEqualsReference(List <ExistsEqualtableFormatContainer> registrations, ClipboardObject clipboardObject)
        {
            if (registrations.Count != clipboardObject.Implementations.Count) //Its only a match if the formats are equal hence the formats count should also be equal
            {
                return(false);
            }

            ResetRegistrations(registrations);

            foreach (var registration in registrations)
            {
                foreach (var implemention in clipboardObject.Implementations)
                {
                    if (registration.EqualtableFormat.Format == implemention.Format)
                    {
                        registration.Match = implemention;
                        break; //This one found, find next
                    }
                }

                if (registration.Match is null) //We did not found a match so there not equal
                {
                    return(false);
                }
            }

            foreach (var registration in registrations)
            {
                if (!registration.Match !.IsEqual(registration.EqualtableFormat)) //! because if it was null then it will be filtered out in the lines above
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #8
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));
        }