Exemplo n.º 1
0
        /// <summary>
        /// loads all of the tags that the input files have in common and places them in the applied tags list
        /// </summary>
        private void _LoadCommonTags(List <string> files)
        {
            /*first use the file paths to retrieve a list of FileTags that contain all of the tags for each file path*/
            List <DBPredicate> predicates = new List <DBPredicate>();

            foreach (string filePath in files)
            {
                predicates.Add(new DBPredicate("path", DBOperator.EQUALS, filePath));
            }
            List <FileTags> dbResults = m_database.Select <FileTags>("FileTags", predicates, new FileTagsCreator(), DBConjunction.AND);

            //now get all of the tags that are common between all the FileTags
            List <int> commonTags = new List <int>();
        }
Exemplo n.º 2
0
        private void _DirectoryMonitor_MonitoredFileRenamed(object sender, MonitoredFileRenamedArgs e)
        {
            try
            {
                //first find the file in the database
                var rawResult = m_database.Select <RawFileData>("FileCache", new DBPredicate("path", DBOperator.EQUALS, e.OldPath), new RawFileDataCreator());
                if (rawResult == null)
                {
                    //if it doesn't exist already, add it now
                    int fileType  = 0;
                    int lastSlash = e.NewPath.LastIndexOf(@"\");
                    if (lastSlash == -1)
                    {
                        return;
                    }

                    if (File.Exists(e.NewPath))
                    {
                        fileType = 1;
                    }
                    m_database.Insert <RawFileData>(DBCollisionAction.IGNORE, "FileCache", new RawFileData(-1, e.NewPath, e.NewPath.Substring(lastSlash + 1).ToLower(), fileType, null, 0, false, false));
                }
                else
                {
                    //if the file does exist in the database, update the old record

                    int lastSlash = e.NewPath.LastIndexOf(@"\");
                    if (lastSlash == -1)
                    {
                        return;
                    }

                    List <DBPredicate> updateValues = new List <DBPredicate>();
                    updateValues.Add(new DBPredicate("path", DBOperator.EQUALS, e.NewPath));
                    updateValues.Add(new DBPredicate("name", DBOperator.EQUALS, e.NewPath.Substring(lastSlash + 1).ToLower()));
                    m_database.Update("FileCache", updateValues, new DBPredicate("path", DBOperator.EQUALS, e.OldPath));
                }
            }
            catch (Exception crap)
            {
                Settings.SessionLog += crap.Message + "\n";
                Debug.WriteLine(crap.Message);
            }
        }
Exemplo n.º 3
0
        private void _SearchFiles(SearchResult resultContainer)
        {
            Debug.Assert(resultContainer != null);

            DatabaseAccess.MatchFilters activeFilter = m_activeSearchFilter != null ? m_activeSearchFilter.Type : DatabaseAccess.MatchFilters.Any;

            if (resultContainer.SearchTerm == null || resultContainer.SearchTerm.Length <= 1)
            {
                return;
            }

            List <RawFileData>     rawResults       = new List <RawFileData>();
            List <DBPredicate>     searchPredicates = new List <DBPredicate>();
            List <Common.FileInfo> convertedData    = new List <Common.FileInfo>();

            try
            {
                switch (activeFilter)
                {
                case DatabaseAccess.MatchFilters.Any:
                {
                    if (resultContainer.WildcardSearch == true)
                    {
                        searchPredicates.Add(new DBPredicate("name", DBOperator.LIKE, "%" + resultContainer.SearchTerm + "%"));
                        searchPredicates.Add(new DBPredicate("tags", DBOperator.LIKE, "%" + resultContainer.SearchTerm + "%"));
                    }
                    else
                    {
                        searchPredicates.Add(new DBPredicate("name", DBOperator.LIKE, resultContainer.SearchTerm + "%"));
                        searchPredicates.Add(new DBPredicate("tags", DBOperator.LIKE, resultContainer.SearchTerm + "%"));
                    }
                    rawResults = m_database.Select <RawFileData>("FileCache", searchPredicates, new RawFileDataCreator(), DBConjunction.OR);
                    break;
                }

                case DatabaseAccess.MatchFilters.Files:
                {
                    if (resultContainer.WildcardSearch == true)
                    {
                        searchPredicates.Add(new DBPredicate("name", DBOperator.LIKE, "%" + resultContainer.SearchTerm + "%"));
                    }
                    else
                    {
                        searchPredicates.Add(new DBPredicate("name", DBOperator.LIKE, resultContainer.SearchTerm + "%"));
                    }
                    searchPredicates.Add(new DBPredicate("type", DBOperator.EQUALS, "1"));

                    rawResults = m_database.Select <RawFileData>("FileCache", searchPredicates, new RawFileDataCreator(), DBConjunction.AND);
                    break;
                }

                case DatabaseAccess.MatchFilters.Folders:
                {
                    if (resultContainer.WildcardSearch == true)
                    {
                        searchPredicates.Add(new DBPredicate("name", DBOperator.LIKE, "%" + resultContainer.SearchTerm + "%"));
                    }
                    else
                    {
                        searchPredicates.Add(new DBPredicate("name", DBOperator.LIKE, resultContainer.SearchTerm + "%"));
                    }
                    searchPredicates.Add(new DBPredicate("type", DBOperator.EQUALS, "0"));

                    rawResults = m_database.Select <RawFileData>("FileCache", searchPredicates, new RawFileDataCreator(), DBConjunction.AND);
                    break;
                }

                case DatabaseAccess.MatchFilters.Tags:
                {
                    break;
                }

                default: break;
                }
            }
            catch (Exception crap)
            {
                m_settings.SessionLog += crap.Message + "\n";
                return;
            }

            if (rawResults.Count == 0)
            {
                return;
            }

            //take the retrieved raw data and convert it into the proper form
            for (int i = rawResults.Count - 1; i >= 0; i--)
            {
                Common.FileInfo info = new Common.FileInfo(rawResults[i], Properties.Resources.file, Properties.Resources.folder);
                info.CalculateWeight(resultContainer.SearchTerm);
                convertedData.Add(info);
                rawResults.RemoveAt(i);
            }

            /*sort the results in descending order based on relevancy weight*/
            convertedData.Sort((a, b) => - 1 * a.Weight.CompareTo(b.Weight));

            //remove all invalid files from the results list and store the results in the container
            resultContainer.InvalidResults = _ValidateFiles(convertedData);
            resultContainer.ValidResults   = convertedData;
        }