/// <summary>
        /// Adds a child item with the given type
        /// (<see cref="SolutionItemType.SolutionRootItem"/> cannot be added here).
        /// </summary>
        /// <param name="displayName"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static IItemModel AddStaticChild(string displayName
                                                , SolutionModelItemType type
                                                , IItemChildrenModel parent)
        {
            if (parent.FindChild(displayName) != null)
            {
                throw new ArgumentException("Item '" + displayName + "' already exists.");
            }

            IItemModel newItem = null;

            switch (type)
            {
            case SolutionModelItemType.File:
                newItem = new FileItemModel(parent, displayName);
                break;

            case SolutionModelItemType.Folder:
                newItem = new FolderItemModel(parent, displayName);
                break;

            case SolutionModelItemType.Project:
                newItem = new ProjectItemModel(parent, displayName);
                break;

            // This should be created via AddSolutionRootItem() method
            case SolutionModelItemType.SolutionRootItem:
            default:
                throw new ArgumentException(type.ToString());
            }

            parent.AddChild(newItem);

            return(newItem);
        }
Esempio n. 2
0
        /// <summary>
        /// Converts a viewmodel item into a model item and
        /// inserts it into the solution model structure.
        /// </summary>
        /// <param name="solutionModel"></param>
        /// <param name="parent"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        private IItemModel ConvertToModel(
            ISolutionModel solutionModel
            , IItemChildrenModel parent
            , IItem item)
        {
            IItemModel modelNewChild = null;

            switch (item.ItemType)
            {
            case SolutionItemType.File:
                modelNewChild = solutionModel.AddChild(item.DisplayName, SolutionModelItemType.File, parent);
                break;

            case SolutionItemType.Folder:
                modelNewChild = solutionModel.AddChild(item.DisplayName, SolutionModelItemType.Folder, parent);
                break;

            case SolutionItemType.Project:
                modelNewChild = solutionModel.AddChild(item.DisplayName, SolutionModelItemType.Project, parent);
                break;

            case SolutionItemType.SolutionRootItem:
            default:
                throw new NotSupportedException();
            }

            return(modelNewChild);
        }
Esempio n. 3
0
        /// <summary>
        /// Read the Tree Model data structure from a SQLite database file back into memory.
        /// </summary>
        /// <param name="solutionRoot"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public int ReadSolutionData(ISolutionModel solutionRoot
                                    , SQLiteDatabase db = null)
        {
            if (db == null)
            {
                db = this;
            }

            int recordCount = 0;

            var query = "SELECT * FROM solution ORDER BY level, id";

            using (SQLiteCommand cmd = new SQLiteCommand(query, db.Connection))
            {
                using (SQLiteDataReader selectResult = cmd.ExecuteReader())
                {
                    Dictionary <long, IItemChildrenModel> mapKeyToItem = new Dictionary <long, IItemChildrenModel>();

                    if (selectResult.HasRows == true)
                    {
                        if (selectResult.Read() == true)
                        {
                            var root = solutionRoot.AddSolutionRootItem(selectResult["name"].ToString());

                            // .GetInt32(0) gets the Id of Root entry
                            mapKeyToItem.Add(selectResult.GetInt32(0), root);
                            recordCount++;
                        }

                        while (selectResult.Read() == true)
                        {
                            int iParentKey            = selectResult.GetInt32(1); // Get parent key from next item
                            IItemChildrenModel parent = null;

                            if (mapKeyToItem.TryGetValue(iParentKey, out parent) == true)
                            {
                                var itemTypeId = (long)selectResult["itemtypeid"];

                                var item = solutionRoot.AddChild(selectResult["name"].ToString()
                                                                 , itemTypeId, parent);

                                IItemChildrenModel parentItem = null;
                                if ((parentItem = item as IItemChildrenModel) != null)
                                {
                                    mapKeyToItem.Add(selectResult.GetInt32(0), parentItem);
                                }
                                recordCount++;
                            }
                            else
                            {
                                throw new Exception("Data written is corrupted.");
                            }
                        }
                    }
                }
            }

            return(recordCount);
        }
        /// <summary>
        /// Adds a child item with the given type
        /// (<see cref="SolutionItemType.SolutionRootItem"/> cannot be added here).
        ///
        /// This wrapper uses a long input for conversion when reading from file.
        /// </summary>
        /// <param name="displayName"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public IItemModel AddChild(string displayName
                                   , long longType
                                   , IItemChildrenModel parent)
        {
            if (parent.FindChild(displayName) != null)
            {
                throw new ArgumentException("Item '" + displayName + "' already exists.");
            }

            SolutionModelItemType type = (SolutionModelItemType)longType;

            return(AddChild(displayName, type, parent));
        }
 public ProjectItemModel(IItemChildrenModel parent, string displayName)
     : base(parent, displayName, Enums.SolutionModelItemType.Project)
 {
 }
 /// <summary>
 /// Adds a child item with the given type
 /// (<see cref="SolutionItemType.SolutionRootItem"/> cannot be added here).
 /// </summary>
 /// <param name="displayName"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public IItemModel AddChild(string displayName
                            , SolutionModelItemType type
                            , IItemChildrenModel parent)
 {
     return(AddItem(displayName, type, parent));
 }