Esempio n. 1
0
        public static ObservableViewModel CombineViewModels(IViewModelServiceProvider serviceProvider, NodeContainer nodeContainer, IReadOnlyCollection<ObservableViewModel> viewModels)
        {
            if (viewModels == null) throw new ArgumentNullException(nameof(viewModels));
            var combinedViewModel = new ObservableViewModel(serviceProvider, nodeContainer, viewModels.SelectMany(x => x.Dirtiables));

            var rootNodes = new List<ObservableModelNode>();
            foreach (var viewModel in viewModels)
            {
                if (!(viewModel.RootNode is SingleObservableNode))
                    throw new ArgumentException(@"The view models to combine must contains SingleObservableNode.", nameof(viewModels));

                viewModel.parent = combinedViewModel;
                var rootNode = (ObservableModelNode)viewModel.RootNode;
                rootNodes.Add(rootNode);
            }

            if (rootNodes.Count < 2)
                throw new ArgumentException(@"Called CombineViewModels with a collection of view models that is either empty or containt just a single item.", nameof(viewModels));

            // Find best match for the root node type
            var rootNodeType = rootNodes.First().Root.Type;
            if (rootNodes.Skip(1).Any(x => x.Type != rootNodeType))
                rootNodeType = typeof(object);

            CombinedObservableNode rootCombinedNode = CombinedObservableNode.Create(combinedViewModel, "Root", null, rootNodeType, rootNodes, null);
            rootCombinedNode.Initialize();
            combinedViewModel.RootNode = rootCombinedNode;
            return combinedViewModel;
        }
Esempio n. 2
0
 public TestContext()
 {
     ObservableViewModelService = new ObservableViewModelService();
     ServiceProvider = new ViewModelServiceProvider();
     ServiceProvider.RegisterService(new DispatcherService(Dispatcher.CurrentDispatcher));
     ServiceProvider.RegisterService(ObservableViewModelService);
     NodeContainer = new NodeContainer();
 }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ObservableViewModel"/> class.
 /// </summary>
 /// <param name="serviceProvider">A service provider that can provide a <see cref="IDispatcherService"/> and an <see cref="ObservableViewModelService"/> to use for this view model.</param>
 /// <param name="nodeContainer">A <see cref="NodeContainer"/> to use to build view model nodes.</param>
 /// <param name="modelNode">The root model node of the view model to generate.</param>
 /// <param name="dirtiables">The list of <see cref="IDirtiable"/> objects linked to this view model.</param>
 public ObservableViewModel(IViewModelServiceProvider serviceProvider, NodeContainer nodeContainer, IGraphNode modelNode, IEnumerable<IDirtiable> dirtiables)
     : this(serviceProvider, nodeContainer, dirtiables.SafeArgument("dirtiables").ToList())
 {
     if (modelNode == null) throw new ArgumentNullException(nameof(modelNode));
     var node = ObservableViewModelService.ObservableNodeFactory(this, "Root", modelNode.Content.IsPrimitive, modelNode, new GraphNodePath(modelNode), modelNode.Content.Type, null);
     node.Initialize();
     RootNode = node;
     node.CheckConsistency();
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ObservableViewModel"/> class.
 /// </summary>
 /// <param name="serviceProvider">A service provider that can provide a <see cref="IDispatcherService"/> and an <see cref="ObservableViewModelService"/> to use for this view model.</param>
 /// <param name="nodeContainer">A <see cref="NodeContainer"/> to use to build view model nodes.</param>
 /// <param name="dirtiables">The list of <see cref="IDirtiable"/> objects linked to this view model.</param>
 private ObservableViewModel(IViewModelServiceProvider serviceProvider, NodeContainer nodeContainer, IEnumerable<IDirtiable> dirtiables)
     : base(serviceProvider)
 {
     if (nodeContainer == null) throw new ArgumentNullException(nameof(nodeContainer));
     if (dirtiables == null) throw new ArgumentNullException(nameof(dirtiables));
     NodeContainer = nodeContainer;
     Dirtiables = dirtiables;
     ObservableViewModelService = serviceProvider.Get<ObservableViewModelService>();
     Logger = GlobalLogger.GetLogger(DefaultLoggerName);
 }
Esempio n. 5
0
 public DefaultNodeBuilder(NodeContainer nodeContainer)
 {
     NodeContainer = nodeContainer;
 }
Esempio n. 6
0
 public DefaultNodeBuilder(NodeContainer nodeContainer)
 {
     NodeContainer = nodeContainer;
     primitiveTypes.AddRange(InternalPrimitiveTypes);
 }
Esempio n. 7
0
 public DefaultNodeBuilder(NodeContainer nodeContainer)
 {
     NodeContainer = nodeContainer;
 }
 public DefaultNodeBuilder(NodeContainer nodeContainer)
 {
     NodeContainer = nodeContainer;
     primitiveTypes.AddRange(InternalPrimitiveTypes);
 }