Example #1
0
        internal void Initialize()
        {
            var commandGroups = new Dictionary <string, List <ModelNodeCommandWrapper> >();

            foreach (var node in combinedNodes)
            {
                foreach (var command in node.Commands)
                {
                    var list = commandGroups.GetOrCreateValue(command.Name);
                    list.Add((ModelNodeCommandWrapper)command);
                }
            }

            foreach (var commandGroup in commandGroups)
            {
                var mode = commandGroup.Value.First().CombineMode;
                if (commandGroup.Value.Any(x => x.CombineMode != mode))
                {
                    throw new InvalidOperationException(string.Format("Inconsistent combine mode among command {0}", commandGroup.Key));
                }

                var shouldCombine = mode != CombineMode.DoNotCombine && (mode == CombineMode.AlwaysCombine || commandGroup.Value.Count == combinedNodes.Count);

                if (shouldCombine)
                {
                    var command = new CombinedNodeCommandWrapper(ServiceProvider, commandGroup.Key, Path, Owner.Identifier, commandGroup.Value);
                    AddCommand(command);
                }
            }

            if (!HasList || HasDictionary)
            {
                var commonChildren = GetCommonChildren();
                GenerateChildren(commonChildren);
            }
            else
            {
                var allChildren = GetAllChildrenByValue();
                if (allChildren != null)
                {
                    // TODO: Disable list children for now - they need to be improved a lot (resulting combinaison is very random, especially for list of ints
                    //GenerateListChildren(allChildren);
                }
            }
            foreach (var key in AssociatedData.Keys.ToList())
            {
                RemoveAssociatedData(key);
            }

            // TODO: we add associatedData added to SingleObservableNode this way, but it's a bit dangerous. Maybe we should check that all combined nodes have this data entry, and all with the same value.
            foreach (var singleData in CombinedNodes.SelectMany(x => x.AssociatedData).Where(x => !AssociatedData.ContainsKey(x.Key)))
            {
                AddAssociatedData(singleData.Key, singleData.Value);
            }

            FinalizeChildrenInitialization();

            CheckDynamicMemberConsistency();
        }
        private void Initialize(bool isUpdating)
        {
            var commandGroups = new Dictionary <string, List <ModelNodeCommandWrapper> >();

            foreach (var node in combinedNodes)
            {
                foreach (var command in node.Commands)
                {
                    var list = commandGroups.GetOrCreateValue(command.Name);
                    list.Add((ModelNodeCommandWrapper)command);
                }
            }

            foreach (var commandGroup in commandGroups)
            {
                var mode = commandGroup.Value.First().CombineMode;
                if (commandGroup.Value.Any(x => x.CombineMode != mode))
                {
                    throw new InvalidOperationException(string.Format("Inconsistent combine mode among command {0}", commandGroup.Key));
                }

                var shouldCombine = mode != CombineMode.DoNotCombine && (mode == CombineMode.AlwaysCombine || commandGroup.Value.Count == combinedNodes.Count);

                if (shouldCombine)
                {
                    var command = new CombinedNodeCommandWrapper(ServiceProvider, commandGroup.Key, Path, Owner.Identifier, commandGroup.Value);
                    AddCommand(command);
                }
            }

            if (!HasList || HasDictionary)
            {
                var commonChildren = GetCommonChildren();
                GenerateChildren(commonChildren, isUpdating);
            }
            else
            {
                var allChildren = GetAllChildrenByValue();
                if (allChildren != null)
                {
                    GenerateListChildren(allChildren, isUpdating);
                }
            }

            if (Owner.ObservableViewModelService != null)
            {
                var data = Owner.ObservableViewModelService.RequestAssociatedData(this, isUpdating);
                SetValue(ref associatedData, data, "AssociatedData");
            }
            CheckDynamicMemberConsistency();
        }
Example #3
0
        internal void Initialize()
        {
            var commandGroups = new Dictionary<string, List<ModelNodeCommandWrapper>>();
            foreach (var node in combinedNodes)
            {
                if (node.IsDisposed)
                    throw new InvalidOperationException("One of the combined node is already disposed.");

                foreach (var command in node.Commands)
                {
                    var list = commandGroups.GetOrCreateValue(command.Name);
                    list.Add((ModelNodeCommandWrapper)command);
                }
            }

            foreach (var commandGroup in commandGroups)
            {
                var mode = commandGroup.Value.First().CombineMode;
                if (commandGroup.Value.Any(x => x.CombineMode != mode))
                    throw new InvalidOperationException($"Inconsistent combine mode among command {commandGroup.Key}");

                var shouldCombine = mode != CombineMode.DoNotCombine && (mode == CombineMode.AlwaysCombine || commandGroup.Value.Count == combinedNodes.Count);

                if (shouldCombine)
                {
                    var command = new CombinedNodeCommandWrapper(ServiceProvider, commandGroup.Key, commandGroup.Value);
                    AddCommand(command);
                }
            }

            if (!HasList || HasDictionary)
            {
                var commonChildren = GetCommonChildren();
                GenerateChildren(commonChildren);
            }
            else
            {
                var commonChildren = GetCommonChildrenInList();
                if (commonChildren != null)
                {
                    // TODO: Disable list children for now - they need to be improved a lot (resulting combinaison is very random, especially for list of ints
                    GenerateChildren(commonChildren);
                }
            }
            foreach (var key in AssociatedData.Keys.ToList())
            {
                RemoveAssociatedData(key);
            }

            // TODO: we add associatedData added to SingleObservableNode this way, but it's a bit dangerous. Maybe we should check that all combined nodes have this data entry, and all with the same value.
            foreach (var singleData in CombinedNodes.SelectMany(x => x.AssociatedData).Where(x => !AssociatedData.ContainsKey(x.Key)))
            {
                AddAssociatedData(singleData.Key, singleData.Value);
            }

            FinalizeChildrenInitialization();

            CheckDynamicMemberConsistency();
        }