Beispiel #1
0
        public void StorageFactoryCreationTest(TargetStorage targetStorage, Type factoryType)
        {
            StorageFactoryFactory factoryFactory = new StorageFactoryFactory();
            IStorageFactory       storageFactory = factoryFactory.CreateStorageFactory(targetStorage);

            Assert.True(storageFactory.GetType().Equals(factoryType));
        }
Beispiel #2
0
        public override void Add(TargetStorage storage)
        {
            base.Add(storage);

            foreach (MemberTarget element in elements)
            {
                element.Add(storage);
            }
        }
        public IStorageFactory CreateStorageFactory(TargetStorage targetStorage)
        {
            switch (targetStorage)
            {
            case TargetStorage.Source:
                return(new SourceStorageFactory());

            case TargetStorage.Destination:
                return(new DestinationStorageFactory());

            default:
                throw new NotSupportedException($"The target storage {targetStorage} isn't supported.");
            }
        }
        /// <summary>
        /// Called when the behavior is removed from the attached control.
        /// Used to remove tap recognizer and perform cleanup.
        /// </summary>
        /// <param name="bindable">The object to which the behavior is binded.</param>
        protected override void OnDetachingFrom(BindableObject bindable)
        {
            base.OnDetachingFrom(bindable);
            if (!_storage.ContainsKey(bindable))
            {
                return;
            }

            TargetStorage targetStorage = _storage[bindable];
            Image         target        = (Image)bindable;

            target.GestureRecognizers.Remove(targetStorage.TapRecognizer);

            _storage.Remove(bindable);
        }
        /// <summary>
        /// Called when the behavior is attached to the view.
        /// Adds tap recognizer (to the image) which change the source for a specified time
        /// (active state).
        /// </summary>
        /// <param name="bindable">The object to which the behavior is being binded.</param>
        protected override void OnAttachedTo(BindableObject bindable)
        {
            base.OnAttachedTo(bindable);
            Image target = (Image)bindable;

            target.Source = SourceToImageSource(OriginalSource);

            TargetStorage targetStorage = new TargetStorage
            {
                TapRecognizer = new TapGestureRecognizer(),
            };

            targetStorage.TapRecognizer.Tapped += (sender, args) =>
            {
                if (targetStorage.Active)
                {
                    return;
                }

                target.Source        = SourceToImageSource(ActiveSource);
                targetStorage.Active = true;

                Device.StartTimer(TimeSpan.FromMilliseconds(Timeout), () =>
                {
                    if (_storage.ContainsKey(bindable))
                    {
                        target.Source = SourceToImageSource(OriginalSource);
                    }

                    targetStorage.Active = false;
                    return(false);
                });
            };

            target.GestureRecognizers.Add(targetStorage.TapRecognizer);
            _storage[bindable] = targetStorage;
        }
Beispiel #6
0
 public virtual void Add(TargetStorage targets)
 {
     targets.Add(this);
 }