public ActionsFilterBase(IWorkspace workspace,
            Predicate<object> filter,
            IEnumerable<string> propertiesThatCauseRefresh)
        {
            _propertiesThatCauseRefresh = propertiesThatCauseRefresh;
            Actions = new ObservableCollection<IAction>();
            _view = new ListCollectionView(workspace.Actions) {Filter = filter};

            _sync = new ListSync<IAction, IAction>(_view, Actions, WatchAction, UnwatchAction);
        }
Example #2
0
        public ActionsFilterBase(IWorkspace workspace,
                                 Predicate <object> filter,
                                 IEnumerable <string> propertiesThatCauseRefresh)
        {
            _propertiesThatCauseRefresh = propertiesThatCauseRefresh;
            Actions = new ObservableCollection <IAction>();
            _view   = new ListCollectionView(workspace.Actions)
            {
                Filter = filter
            };

            _sync = new ListSync <IAction, IAction>(_view, Actions, WatchAction, UnwatchAction);
        }
        public void Dispose_Succeeds()
        {
            var ints = new ObservableCollection <int>(new List <int> {
                1, 2, 3, 4
            });
            var strings = new ObservableCollection <string>();

            var sync
                = new ListSync <int, string>(ints,
                                             strings,
                                             x => string.Concat(StringPrefix, x.ToString()),
                                             null);

            sync.Dispose();
        }
        public void Reset_ResetsDestination()
        {
            var ints = new ObservableCollection <int>(new List <int> {
                1, 2, 3, 4
            });
            var strings = new ObservableCollection <string>();

            var sync
                = new ListSync <int, string>(ints,
                                             strings,
                                             x => string.Concat(StringPrefix, x.ToString()),
                                             null);

            ints.Clear();
            GC.KeepAlive(sync);

            Assert.Empty(strings);
        }
        public void RemoveItem_WithItemRemover_CallsItemRemover()
        {
            var ints = new ObservableCollection <int>(new List <int> {
                65, 43, 21
            });
            var  strings     = new ObservableCollection <string>();
            bool itemRemoved = false;

            var sync
                = new ListSync <int, string>(ints,
                                             strings,
                                             insertedItem => string.Concat(StringPrefix, insertedItem.ToString()),
                                             removedItem => itemRemoved = true);

            ints.Remove(43);
            GC.KeepAlive(sync);

            Assert.True(itemRemoved);
        }
        public void ItemsAreRemoved()
        {
            var ints = new ObservableCollection <int>(new List <int> {
                65, 43, 21
            });
            var strings = new ObservableCollection <string>();

            var sync
                = new ListSync <int, string>(ints,
                                             strings,
                                             x => string.Concat(StringPrefix, x.ToString()),
                                             null);

            ints.Remove(43);
            GC.KeepAlive(sync);

            Assert.Equal(StringPrefix + "65", strings[0]);
            Assert.Equal(StringPrefix + "21", strings[1]);
        }
        public void Replace_OnSource_UpdatesDestination()
        {
            var ints = new ObservableCollection <int>(new List <int> {
                1, 2, 3, 4
            });
            var strings = new ObservableCollection <string>();

            var sync
                = new ListSync <int, string>(ints,
                                             strings,
                                             x => string.Concat(StringPrefix, x.ToString()),
                                             null);

            ints[2] = 5;
            GC.KeepAlive(sync);

            Assert.Equal(StringPrefix + "1", strings[0]);
            Assert.Equal(StringPrefix + "2", strings[1]);
            Assert.Equal(StringPrefix + "5", strings[2]);
            Assert.Equal(StringPrefix + "4", strings[3]);
        }
Example #8
0
 public static void Sync <SourceT, TargetT>(IEnumerable <SourceT> sourceList, IEnumerable <TargetT> targetList, Func <SourceT, TargetT, bool> equatable, Action <SourceT, TargetT> updateFunc, Func <SourceT, TargetT> createFunc, Action <IEnumerable <TargetT>, TargetT> addFunc = null, Action <IEnumerable <TargetT>, TargetT, int> removeFunc = null, bool callUpdateFuncWhenCreated = true)
 {
     ListSync.Sync <SourceT, TargetT>(sourceList, targetList, equatable, updateFunc, createFunc, addFunc, removeFunc, callUpdateFuncWhenCreated);
 }
Example #9
0
 public override void OnInit()
 {
     this.m_Aliases          = new ListSync <Alias>(this.DataSource.Aliases);
     this.dgvGrid.DataSource = this.m_Aliases;
 }
Example #10
0
 public override void OnInit()
 {
     this.m_Macros                = new ListSync <Macro>(this.DataSource.Macros);
     this.lbxMacros.DataSource    = this.m_Macros;
     this.lbxMacros.DisplayMember = nameof(Macro.Name);
 }
        public void ItemsAreInserted()
        {
            var ints = new ObservableCollection<int>(new List<int> {65, 43, 21});
            var strings = new ObservableCollection<string>();

            var sync
                = new ListSync<int, string>(ints,
                                            strings,
                                            x => string.Concat(StringPrefix, x.ToString()),
                                            null);

            ints.Insert(2, 666);
            GC.KeepAlive(sync);

            Assert.Equal(StringPrefix + "65", strings[0]);
            Assert.Equal(StringPrefix + "43", strings[1]);
            Assert.Equal(StringPrefix + "666", strings[2]);
            Assert.Equal(StringPrefix + "21", strings[3]);
        }
        public void Dispose_Succeeds()
        {
            var ints = new ObservableCollection<int>(new List<int> {1, 2, 3, 4});
            var strings = new ObservableCollection<string>();

            var sync
                = new ListSync<int, string>(ints,
                                            strings,
                                            x => string.Concat(StringPrefix, x.ToString()),
                                            null);

            sync.Dispose();
        }
        public void Reset_ResetsDestination()
        {
            var ints = new ObservableCollection<int>(new List<int> {1, 2, 3, 4});
            var strings = new ObservableCollection<string>();

            var sync
                = new ListSync<int, string>(ints,
                                            strings,
                                            x => string.Concat(StringPrefix, x.ToString()),
                                            null);

            ints.Clear();
            GC.KeepAlive(sync);

            Assert.Empty(strings);
        }
        public void Replace_OnSource_UpdatesDestination()
        {
            var ints = new ObservableCollection<int>(new List<int> {1, 2, 3, 4});
            var strings = new ObservableCollection<string>();

            var sync
                = new ListSync<int, string>(ints,
                                            strings,
                                            x => string.Concat(StringPrefix, x.ToString()),
                                            null);

            ints[2] = 5;
            GC.KeepAlive(sync);

            Assert.Equal(StringPrefix + "1", strings[0]);
            Assert.Equal(StringPrefix + "2", strings[1]);
            Assert.Equal(StringPrefix + "5", strings[2]);
            Assert.Equal(StringPrefix + "4", strings[3]);
        }
        public void RemoveItem_WithItemRemover_CallsItemRemover()
        {
            var ints = new ObservableCollection<int>(new List<int> {65, 43, 21});
            var strings = new ObservableCollection<string>();
            bool itemRemoved = false;

            var sync
                = new ListSync<int, string>(ints,
                                            strings,
                                            insertedItem => string.Concat(StringPrefix, insertedItem.ToString()),
                                            removedItem => itemRemoved = true);

            ints.Remove(43);
            GC.KeepAlive(sync);

            Assert.True(itemRemoved);
        }