/// <summary>
        /// Creates a new solution root item from the given parameters
        /// (replacing the current root item if there is any)
        /// and returns its interface.
        /// </summary>
        /// <param name="displayName"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public IItemChildrenModel AddSolutionRootItem(string displayName, long id = -1)
        {
            Root = new SolutionRootItemModel(displayName)
            {
                Id = id
            };

            return(Root);
        }
예제 #2
0
        /// <summary>
        /// Method implements Level-Order traversal via <see cref="TreeLib"/> nuget
        /// package to convert the <see cref="SolutionModel"/> model in <paramref name="model"/>
        /// into a <see cref="ISolution"/> viewmodel in <paramref name="solutionRoot"/>.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="solutionRoot"></param>
        /// <returns></returns>
        public ISolution ToViewModel(ISolutionModel model
                                     , ISolution solutionRoot)
        {
            solutionRoot.ResetToDefaults(); // Reset current viewmodel to construction time defaults

            ISolutionRootItemModel treeRootModel = model.Root;
            long itemId = 0;

            var items = TreeLib.BreadthFirst.Traverse.LevelOrder <IItemModel>(treeRootModel
                                                                              , (i) =>
            {
                var it = i as IItemChildrenModel;

                if (it != null)
                {
                    return(it.Children);
                }

                // Emulate an emtpy list if items have no children
                return(new List <IItemChildrenModel>());
            });

            var dstIdItems = new Dictionary <long, IItemChildren>();

            foreach (var item in items.Select(i => i.Node))
            {
                item.Id = itemId++;

                if (item.Parent == null)
                {
                    var rootItem = solutionRoot.AddSolutionRootItem(item.DisplayName);
                    rootItem.SetId(item.Id);

                    dstIdItems.Add(rootItem.GetId(), rootItem);
                }
                else
                {
                    IItemChildren modelParentItem;
                    IItem         modelNewChild;
                    dstIdItems.TryGetValue(item.Parent.Id, out modelParentItem);

                    modelNewChild = ConvertToViewModel(solutionRoot, modelParentItem, item);

                    modelNewChild.SetId(item.Id);

                    // Store only items that can have children for later lock-up
                    if (modelNewChild is IItemChildren)
                    {
                        dstIdItems.Add(modelNewChild.GetId(), modelNewChild as IItemChildren);
                    }
                }
            }

            return(solutionRoot);
        }
        /// <summary>
        /// Adds a solution root item (replacing the current root item if there is any)
        /// and returns its interface.
        /// </summary>
        /// <param name="rootItem"></param>
        /// <returns></returns>
        public IItemChildrenModel AddSolutionRootItem(ISolutionRootItemModel rootItem)
        {
            Root = rootItem;

            return(Root);
        }