Exemple #1
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);
        }
Exemple #2
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);
        }