Пример #1
0
        private IDataSourceViewModel CreateViewModel(IDataSource dataSource)
        {
            if (dataSource == null)
                throw new ArgumentNullException(nameof(dataSource));

            IDataSourceViewModel viewModel;
            var single = dataSource as ISingleDataSource;
            if (single != null)
            {
                viewModel = new SingleDataSourceViewModel(single, _actionCenter);
            }
            else
            {
                var merged = dataSource as MergedDataSource;
                if (merged != null)
                {
                    viewModel = new MergedDataSourceViewModel(merged, _actionCenter);
                }
                else
                {
                    throw new ArgumentException(string.Format("Unknown data source: {0} ({1})", dataSource, dataSource.GetType()));
                }
            }
            viewModel.Remove += OnRemove;
            _allDataSourceViewModels.Add(viewModel);

            if (_settings.DataSources.SelectedItem == viewModel.DataSource.Id)
            {
                SelectedItem = viewModel;
            }

            return viewModel;
        }
Пример #2
0
        public void TestCanBeRemovedAsPartOfMergedDataSource()
        {
            var actionCenter = new Mock <IActionCenter>();
            var dataSource   = new Mock <ISingleDataSource>();

            dataSource.Setup(x => x.Settings).Returns(new DataSource());
            var model = new SingleDataSourceViewModel(dataSource.Object, actionCenter.Object);

            using (var monitor = model.Monitor())
            {
                model.CanBeRemoved.Should().BeTrue();

                var mergedDataSource = new Mock <IMergedDataSource>();
                mergedDataSource.Setup(x => x.Settings).Returns(new DataSource());
                var merged = new MergedDataSourceViewModel(mergedDataSource.Object, actionCenter.Object);
                model.Parent = merged;
                model.CanBeRemoved.Should().BeTrue();
                monitor.Should().NotRaisePropertyChangeFor(x => x.CanBeRemoved);

                monitor.Clear();
                model.Parent = null;
                model.CanBeRemoved.Should().BeTrue();
                monitor.Should().NotRaisePropertyChangeFor(x => x.CanBeRemoved);
            }
        }
Пример #3
0
        public void TestConstruction1()
        {
            var model = new MergedDataSourceViewModel(_dataSources.AddGroup(), _actionCenter.Object);

            model.IsSelected.Should().BeFalse();
            model.IsExpanded.Should().BeTrue();
        }
Пример #4
0
        public void TestConstruction3()
        {
            var dataSource = _dataSources.AddGroup();

            dataSource.DisplayName = "Some group";

            var model = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            model.DisplayName.Should().Be("Some group");
        }
Пример #5
0
        public void TestConstruction2([Values(DataSourceDisplayMode.Filename, DataSourceDisplayMode.CharacterCode)] DataSourceDisplayMode displayMode)
        {
            var dataSource = _dataSources.AddGroup();

            dataSource.DisplayMode = displayMode;

            var model = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            model.DisplayMode.Should().Be(displayMode);
        }
Пример #6
0
        public void TestAddChild1()
        {
            var model = new MergedDataSourceViewModel(_dataSources.AddGroup(), _actionCenter.Object);
            SingleDataSource source = _dataSources.AddDataSource("foo");
            var sourceViewModel     = new SingleDataSourceViewModel(source, _actionCenter.Object);

            model.AddChild(sourceViewModel);
            model.Observable.Should().Equal(sourceViewModel);
            sourceViewModel.Parent.Should().BeSameAs(model);
        }
Пример #7
0
        public void TestChangeDisplayMode()
        {
            var dataSource = _dataSources.AddGroup();
            var model      = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            model.DisplayMode = DataSourceDisplayMode.CharacterCode;
            dataSource.DisplayMode.Should().Be(DataSourceDisplayMode.CharacterCode);

            model.DisplayMode = DataSourceDisplayMode.Filename;
            dataSource.DisplayMode.Should().Be(DataSourceDisplayMode.Filename);
        }
Пример #8
0
        public void TestInsertChild1()
        {
            var dataSource = _dataSources.AddGroup();
            var model      = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            SingleDataSource source = _dataSources.AddDataSource("foo");
            var sourceViewModel     = new SingleDataSourceViewModel(source, _actionCenter.Object);

            model.Insert(0, sourceViewModel);
            sourceViewModel.CharacterCode.Should().Be("A", "because the merged data source is responsible for providing unique character codes");
        }
Пример #9
0
        private void DissolveGroupIfNecessary(MergedDataSourceViewModel group)
        {
            if (group.ChildCount == 1)
            {
                int groupIndex = _observable.IndexOf(group);
                _observable.RemoveAt(groupIndex);
                _dataSources.Remove(group.DataSource);

                IDataSourceViewModel child = group.Observable.First();
                group.RemoveChild(child);
                _observable.Insert(groupIndex, child);
            }
        }
Пример #10
0
        public void TestExpand()
        {
            var dataSource = _dataSources.AddGroup();
            var model      = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            model.IsExpanded = false;
            model.IsExpanded.Should().BeFalse();
            dataSource.IsExpanded.Should().BeFalse();

            model.IsExpanded = true;
            model.IsExpanded.Should().BeTrue();
            dataSource.IsExpanded.Should().BeTrue();
        }
Пример #11
0
        public void TestChangeDisplayName1()
        {
            var dataSource = _dataSources.AddGroup();
            var model      = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            model.CanBeRenamed.Should().BeTrue("because this implementation should support renaming...");
            model.DisplayName.Should().Be("Merged Data Source");

            model.MonitorEvents();
            model.DisplayName = "Foobar";
            model.DisplayName.Should().Be("Foobar");
            model.DataSourceOrigin.Should().Be("Foobar");
            model.ShouldRaisePropertyChangeFor(x => x.DisplayName, "because we've just changed the name");
            model.ShouldRaisePropertyChangeFor(x => x.DataSourceOrigin, "because we've just changed the name");
        }
Пример #12
0
        private void Drag(IDataSourceViewModel source, IDataSourceViewModel dest)
        {
            var merged = dest as MergedDataSourceViewModel;

            if (merged != null)
            {
                // Drag from ungrouped onto an existing group
                // => add to existing group
                AddFileToGroup(source, merged);
                SelectedItem = merged;
            }
            else
            {
                // Drag from ungrouped onto a dest within a group
                // => find group of dest and addd to it
                merged = dest.Parent as MergedDataSourceViewModel;
                if (merged != null)
                {
                    AddFileToGroup(source, merged);
                    SelectedItem = merged;
                }
                else
                {
                    // Drag from ungrouped onto another ungrouped source
                    // => remove dest as well and create new group
                    int destIndex = _observable.IndexOf(dest);
                    if (destIndex != -1)
                    {
                        _observable.Remove(dest);

                        MergedDataSource mergedDataSource = _dataSources.AddGroup();
                        merged         = new MergedDataSourceViewModel(mergedDataSource, _actionCenter, _settings);
                        merged.Remove += OnRemove;
                        merged.AddChild(source);
                        merged.AddChild(dest);
                        _observable.Insert(destIndex, merged);
                        _allDataSourceViewModels.Add(merged);
                        SelectedItem = merged;
                    }
                }
            }
        }
Пример #13
0
        private IDataSourceViewModel CreateViewModel(IDataSource dataSource)
        {
            if (dataSource == null)
            {
                throw new ArgumentNullException(nameof(dataSource));
            }

            IDataSourceViewModel viewModel;

            if (dataSource is IFileDataSource single)
            {
                viewModel = new FileDataSourceViewModel(single, _actionCenter, _settings);
            }
            else if (dataSource is IMergedDataSource merged)
            {
                viewModel = new MergedDataSourceViewModel(merged, _actionCenter, _settings);
            }
            else if (dataSource is IFolderDataSource folder)
            {
                viewModel = new FolderDataSourceViewModel(folder, _actionCenter, _settings);
            }
            else if (dataSource is ICustomDataSource custom)
            {
                viewModel = new CustomDataSourceViewModel(custom, _actionCenter, _settings);
            }
            else
            {
                throw new ArgumentException(string.Format("Unknown data source: {0} ({1})", dataSource, dataSource.GetType()));
            }

            viewModel.Remove += OnRemove;
            _allDataSourceViewModels.Add(viewModel);

            if (_settings.DataSources.SelectedItem == viewModel.DataSource.Id)
            {
                SelectedItem = viewModel;
            }

            return(viewModel);
        }
Пример #14
0
        public void TestAddChild3()
        {
            var dataSource = _dataSources.AddGroup();
            var model      = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            var sources = new List <SingleDataSourceViewModel>();

            for (int i = 0; i < LogLineSourceId.MaxSources; ++i)
            {
                var source          = _dataSources.AddDataSource(i.ToString());
                var sourceViewModel = new SingleDataSourceViewModel(source, _actionCenter.Object);
                sources.Add(sourceViewModel);

                model.AddChild(sourceViewModel).Should().BeTrue("because the child should've been added");
                model.Observable.Should().Equal(sources, "because all previously added children should be there");
            }

            var tooMuch = new SingleDataSourceViewModel(_dataSources.AddDataSource("dadw"), _actionCenter.Object);

            model.AddChild(tooMuch).Should().BeFalse("because no more children can be added");
            model.Observable.Should().Equal(sources, "because only those sources which could be added should be present");
        }
Пример #15
0
        public void TestInsertChild2()
        {
            var dataSource = _dataSources.AddGroup();
            var model      = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            var child1 = new SingleDataSourceViewModel(_dataSources.AddDataSource("foo"), _actionCenter.Object);

            model.AddChild(child1);
            child1.CharacterCode.Should().Be("A");

            var child2 = new SingleDataSourceViewModel(_dataSources.AddDataSource("bar"), _actionCenter.Object);

            model.Insert(0, child2);
            model.Observable.Should().Equal(new object[]
            {
                child2, child1
            });

            const string reason = "because the merged data source is responsible for providing unique character codes";

            child2.CharacterCode.Should().Be("A", reason);
            child1.CharacterCode.Should().Be("B", reason);
        }
Пример #16
0
        public void TestRemoveChild1()
        {
            var dataSource = _dataSources.AddGroup();
            var model      = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            var child1 = new SingleDataSourceViewModel(_dataSources.AddDataSource("foo"), _actionCenter.Object);

            model.AddChild(child1);

            var child2 = new SingleDataSourceViewModel(_dataSources.AddDataSource("bar"), _actionCenter.Object);

            model.AddChild(child2);
            model.Observable.Should().Equal(new object[]
            {
                child1, child2
            });

            child1.CharacterCode.Should().Be("A");
            child2.CharacterCode.Should().Be("B");

            model.RemoveChild(child1);
            model.Observable.Should().Equal(new object[] { child2 });
            child2.CharacterCode.Should().Be("A");
        }
Пример #17
0
 private static void AddFileToGroup(IDataSourceViewModel source, MergedDataSourceViewModel viewModel)
 {
     viewModel.AddChild(source);
 }
Пример #18
0
        private void DragFromGroup(IDataSourceViewModel source, IDataSourceViewModel dest, MergedDataSourceViewModel parent)
        {
            parent.RemoveChild(source);
            DissolveGroupIfNecessary(parent);

            Drag(source, dest);
        }