Example #1
0
        public void SaveToDb()
        {
            NineWorldsDeep.Db.Sqlite.DbAdapterSwitch db =
                new NineWorldsDeep.Db.Sqlite.DbAdapterSwitch();

            //get unique list of paths (as dictionary, id = -1)
            Dictionary<string, int> pathsToIds =
                new Dictionary<string, int>();

            foreach (string path in fileTagsMap.Keys)
            {
                pathsToIds[path] = -1;
            }

            //get unique list of tags (as dictionary, id = -1)
            Dictionary<string, int> tagsToIds =
                new Dictionary<string, int>();

            foreach (string tag in tagFilesMap.Keys)
            {
                //store as lower case, was throwing errors below
                //TODO: encapsulate tag in class and make comparison case-insensitive
                tagsToIds[tag.ToLower()] = -1;
            }

            //store paths
            db.StorePaths(pathsToIds.Keys.ToList<string>());

            //store tags
            db.StoreTags(tagsToIds.Keys.ToList<string>());

            //store device in device table
            db.StoreDevice("Main Laptop", "Main Laptop", "hp 2000", "laptop");

            //get device id
            int deviceId = db.GetDeviceId("Main Laptop", "Main Laptop", "hp 2000", "laptop");

            //populate path ids in dict from above
            db.PopulatePathIds(pathsToIds);

            //populate tag ids in dict from above
            db.PopulateTagIds(tagsToIds);

            //iterate and create mappings
            List<NineWorldsDeep.Db.PathToTagMapping> mappings =
                new List<NineWorldsDeep.Db.PathToTagMapping>();

            foreach (string path in fileTagsMap.Keys)
            {
                int pathId = pathsToIds[path];

                var tags = fileTagsMap[path];

                foreach (string tag in tags)
                {
                    if (!string.IsNullOrWhiteSpace(tag))
                    {
                        int tagId = tagsToIds[tag.ToLower()];

                        mappings.Add(
                            new NineWorldsDeep.Db.PathToTagMapping()
                            {
                                PathId = pathId,
                                TagId = tagId,
                                DeviceId = deviceId
                            });
                    }
                }
            }

            //store mappings
            db.StorePathToTagMappings(mappings);
        }
Example #2
0
        /// <summary>
        /// will retrieve load all paths and tags for those paths
        /// where the path begins with filePathTopFolder
        /// 
        /// any level of hierarchy is supported (i.e. "C:\NWD-AUX\" 
        /// will work, as will "C:\NWD-AUX\voicememos", with
        /// the first one including the results from the second
        /// one, thus respecting hierarchy)
        /// 
        /// Also note, passing "" as a parameter will match
        /// all paths for which tags have been stored
        /// </summary>
        /// <param name="filePathTopFolder"></param>
        public void LoadFromDb(string filePathTopFolder)
        {
            NineWorldsDeep.Db.Sqlite.DbAdapterSwitch db =
                new NineWorldsDeep.Db.Sqlite.DbAdapterSwitch();

            //retrieve all path to tag mappings
            List<NineWorldsDeep.Db.PathTagLink> lst =
                db.GetPathTagLinks(filePathTopFolder);

            //foreach Link(path, tag)
            foreach (NineWorldsDeep.Db.PathTagLink ptl in lst)
            {
                Link(ptl.PathValue, ptl.TagValue);
            }
        }