private void TestCase(string[] sourceContent, string[] destinationContent, string[] expectedOperations, string[] expectedDisposals)
        {
            List <string> disposals = new List <string>();

            ObservableCollectionMapper <string, SimpleViewModel> mapper = new ObservableCollectionMapper <string, SimpleViewModel>(
                entity => new SimpleViewModel(disposals, entity, "D-" + entity),
                model => model.Entity,
                (entity, model) => { },
                null);

            ObservableCollection <SimpleViewModel> target = new ObservableCollection <SimpleViewModel>();

            mapper.UpdateCollection(sourceContent, target);
            Assert.That(disposals, Is.Empty);

            List <string> operations = new List <string>();

            target.CollectionChanged += (sender, args) => operations.Add(FormatChangeEvent(args));

            mapper.UpdateCollection(destinationContent, target);
            Assert.That(target.Select(m => m.Entity).ToList(), Is.EqualTo(destinationContent));
            if (expectedOperations != null)
            {
                Assert.That(operations, Is.EqualTo(expectedOperations), "operations does not match expectations");
            }
            Assert.That(disposals, Is.EquivalentTo(expectedDisposals), "disposals does not match expectations");
        }
        public DockerImageListViewModel(AppBrowserViewModel appBrowserViewModel, DockerService service)
        {
            this.appBrowserViewModel = appBrowserViewModel;
            this.service             = service;
            ModuleName = "Images";

            imagesMapper = new ObservableCollectionMapper <DockerImage, DockerImageViewModel>(
                image => new DockerImageViewModel(service, image),
                viewModel => viewModel.Image,
                (image, viewModel) => viewModel.Update(),
                (viewModel1, viewModel2) =>
            {
                int r = string.CompareOrdinal(viewModel1.RepoTagsAsText, viewModel2.RepoTagsAsText);
                if (r == 0)
                {
                    r = string.CompareOrdinal(viewModel1.RepoDigestsAsText, viewModel2.RepoDigestsAsText);
                }
                if (r == 0)
                {
                    r = string.CompareOrdinal(viewModel1.Id, viewModel2.Id);
                }
                return(r);
            }
                );

            RefreshCommand      = new BasicCommand(() => service.Connected, o => service.Refresh());
            DeleteImagesCommand = new BasicCommand(() => service.Connected && SelectedImages.Count > 0, o => DeleteImages());

            SelectedImages.CollectionChanged += (sender, args) => { DeleteImagesCommand.UpdateState(); };

            service.StageChanged += () => appBrowserViewModel.ViewContext.Invoke(Update);

            Update();
        }
示例#3
0
        public EurekaServiceViewModel(AppBrowserViewModel appBrowserViewModel, EurekaService service)
        {
            this.appBrowserViewModel = appBrowserViewModel;
            this.service             = service;

            appMapper = new ObservableCollectionMapper <Tuple <EurekaApplication, EurekaApplicationInstance>, EurekaApplicationViewModel>(
                tuple => new EurekaApplicationViewModel(tuple.Item1, tuple.Item2),
                viewModel => Tuple.Create(viewModel.Application, viewModel.Instance),
                (tuple, viewModel) => viewModel.Update(),
                (viewModel1, viewModel2) =>
            {
                int r = string.CompareOrdinal(viewModel1.AppName, viewModel2.AppName);
                if (r == 0)
                {
                    r = string.CompareOrdinal(viewModel1.HostName, viewModel2.HostName);
                }
                if (r == 0)
                {
                    r = string.CompareOrdinal(viewModel1.InstanceId, viewModel2.InstanceId);
                }
                return(r);
            }
                );

            ConnectCommand                = new BasicCommand(() => !service.Connected, o => service.Connect());
            DisconnectCommand             = new BasicCommand(() => service.Connected, o => service.Disconnect());
            RefreshCommand                = new BasicCommand(() => service.Connected, o => service.RefreshApplications());
            DeregisterApplicationsCommand = new BasicCommand(() => service.Connected && SelectedApplications.Count > 0, o => DeregisterApplications());

            SelectedApplications.CollectionChanged += (sender, args) => { DeregisterApplicationsCommand.UpdateState(); };
            service.StateChanged += () => appBrowserViewModel.ViewContext.Invoke(Update);

            Update();
        }
示例#4
0
        public NodeBase(NodeDependencyAggregate dependencies)
        {
            BaseNode = (T)Activator.CreateInstance(typeof(T));
            (Location, ErrorState, Name, _factory) = dependencies;
            Name.Value = BaseNode.NodeName;

            INodeBase.NodeBases.Add(BaseNode, this);

            FieldList            = Constructor.NodeComponentList(BaseNode.Fields);
            FieldList.ParentNode = BaseNode;
            Fields = ObservableCollectionMapper <IVisualNodeComponent, IVisualNodeComponentContainer> .Create(FieldList.VisualNodeComponentsObservable, _factory);
        }
示例#5
0
        public NodeBase(INode baseNode)
        {
            _baseNode                = baseNode;
            _fieldSection            = Constructor.NodeComponentList(baseNode.Fields);
            _fieldSection.ParentNode = baseNode;

            Fields = ObservableCollectionMapper <IVisualNodeComponent, IVisualNodeComponentDisplay> .Create(_fieldSection.VisualNodeComponentsObservable, new VisualNodeComponentMapper(this));

            baseNode.SubscribeToEvaluate(TryEvaluate);

            TryEvaluate();
        }
示例#6
0
        public ModulesTreeView()
        {
            XamlReader.Load(this);
            DataContextChanged += OnDataContextChanged;

            nodeMapper = new ObservableCollectionMapper <IModuleViewModel, ITreeItem>(
                CreateNode,
                node => ((TreeItem)node).Tag as IModuleViewModel,
                UpdateNode,
                (node1, node2) => string.CompareOrdinal(node1.Text, node2.Text)
                );

            Tree.DataStore         = treeNodes;
            Tree.SelectionChanged += TreeOnSelectionChanged;
        }
        public AppEnvironmentViewModel(AppBrowserViewModel appBrowserViewModel, AppEnvironment environment)
        {
            this.appBrowserViewModel = appBrowserViewModel;
            this.environment         = environment;

            serviceMapper = new ObservableCollectionMapper <IService, IServiceViewModel>(
                CreateServiceViewModel,
                viewModel => viewModel.Service,
                (service, viewModel) => viewModel.Update(),
                (viewModel1, viewModel2) => string.CompareOrdinal(viewModel1.ModuleName, viewModel2.ModuleName)
                );

            environment.ServiceListChanged += Update;
            Services.CollectionChanged     += (sender, args) => SubModulesChanged?.Invoke();
            Update();
        }
        public void TestPerformance()
        {
            const int iterationCount       = 1000;
            const int availableValuesCount = 2000;
            const int sourceListSize       = 1000;
            const int destListSize         = 1000;

            Stopwatch stopwatch      = new Stopwatch();
            long      operationCount = 0;

            for (int it = 0; it < iterationCount; it++)
            {
                List <string> sourceList = GenerateSet(sourceListSize, availableValuesCount, 0.5, 3);
                List <string> destList   = GenerateSet(destListSize, availableValuesCount, 0.65, 1);

                ObservableCollection <string> collection = new ObservableCollection <string>();

                ObservableCollectionMapper <string, string> mapper = new ObservableCollectionMapper <string, string>
                                                                     (
                    entity => entity,
                    model => model,
                    (entity, model) => { },
                    null
                                                                     );

                mapper.UpdateCollection(sourceList, collection);

                collection.CollectionChanged += (sender, args) => operationCount++;

                stopwatch.Start();
                mapper.UpdateCollection(destList, collection);
                stopwatch.Stop();

                Assert.That(collection, Is.EqualTo(destList));
            }

            Console.WriteLine("Update Time:     {0} ms ({1} ms per iteration)", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedMilliseconds / iterationCount);
            Console.WriteLine("Operation Count: {0} ({1} per iteration)", operationCount, operationCount / iterationCount);
        }
示例#9
0
        public DockerContainerListViewModel(AppBrowserViewModel appBrowserViewModel, DockerService service)
        {
            this.appBrowserViewModel = appBrowserViewModel;
            this.service             = service;
            ModuleName = "Containers";

            containersMapper = new ObservableCollectionMapper <DockerContainer, DockerContainerViewModel>(
                container => new DockerContainerViewModel(service, container),
                viewModel => viewModel.Container,
                (container, viewModel) => viewModel.Update(),
                (viewModel1, viewModel2) =>
            {
                int r = string.CompareOrdinal(viewModel1.Image, viewModel2.Image);
                if (r == 0)
                {
                    r = string.CompareOrdinal(viewModel1.Id, viewModel2.Id);
                }
                return(r);
            }
                );

            RefreshCommand         = new BasicCommand(() => service.Connected, o => service.Refresh());
            StartContainersCommand = new BasicCommand(() => service.Connected && SelectedContainers.Count > 0, o => StartContainers());
            StopContainersCommand  = new BasicCommand(() => service.Connected && SelectedContainers.Count > 0, o => StopContainers());

            SelectedContainers.CollectionChanged += (sender, args) =>
            {
                StartContainersCommand.UpdateState();
                StopContainersCommand.UpdateState();
            };

            service.StageChanged += () => appBrowserViewModel.ViewContext.Invoke(Update);
            service.LogChanged   += UpdateLog;

            Update();

            timer = new Timer(TimerCallback, null, 0, 500);
        }
示例#10
0
 public NodeContainer(NodeDependencyAggregate dependencies)
 {
     (Location, ErrorState, NameLabel, FieldList, _factory) = dependencies;
     Name   = _factory.GetImplementation <IVisualNodeComponentContainer>();
     Fields = ObservableCollectionMapper <IVisualNodeComponent, IVisualNodeComponentContainer> .Create(FieldList.VisualNodeComponentsObservable, _factory);
 }