Esempio n. 1
0
        public void Load(TagQueryCriteria tagQueryCriteria = null, bool newAdditionsOnly = false)
        {
            FileNames.Clear();

            currentQuery = tagQueryCriteria ?? new TagQueryCriteria();
            var sourcePath = PersistanceUtil.RetreiveSetting(Setting.SourceDirectory);

            if (!Directory.Exists(sourcePath))
            {
                sourcePath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                PersistanceUtil.RecordSetting(Setting.SourceDirectory, sourcePath);
            }
            if (newAdditionsOnly)
            {
                FileNames.Add(NewFiles);
            }
            else
            {
                FileNames.Add(ImageFileUtil.GetImageFilenames(sourcePath, currentQuery));
            }

            if (currentQuery.orderDirection == OrderDirection.RANDOM)
            {
                FileNames.Shuffle();
            }
            watcher.Path = sourcePath;
            watcher.EnableRaisingEvents = true;
            FilesLoaded(null, new EventArgs());
        }
Esempio n. 2
0
        private static bool MatchesCriteria(string imgPath, TagQueryCriteria criteria)
        {
            var tags     = GetImageTags(imgPath).Select(t => t.TagName);
            var success  = true;
            var anyFound = false;

            foreach (var tag in tags)
            {
                anyFound |= criteria.anyOfThese.Contains(tag);

                success &= criteria.allOfThese.Count == 0 || criteria.allOfThese.Contains(tag) &&
                           !criteria.noneOfThese.Contains(tag);

                if (!success)
                {
                    break;
                }
            }
            success &= (anyFound || criteria.anyOfThese.Count == 0);

            return(success);
        }
Esempio n. 3
0
 public void SetSearch(TagQueryCriteria tagQueryCriteria = null, bool newAdditionsOnly = false)
 {
     ImageFiles.Load(tagQueryCriteria, newAdditionsOnly);
 }
Esempio n. 4
0
        }                                                                                            //, "jpeg", "gif", "png", };

        public static List <string> GetImageFilenames(string sourcePath = null, TagQueryCriteria tagQueryCriteria = null)
        {
            sourcePath = sourcePath ?? PersistanceUtil.RetreiveSetting(Setting.SourceDirectory);
            if (!Directory.Exists(sourcePath))
            {
                sourcePath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            }
            tagQueryCriteria = tagQueryCriteria ?? new TagQueryCriteria();

            var result = new List <string>();
            var query  = tagQueryCriteria.GetQueryClause(sourcePath, out bool randomize);

            var windowsSearchConnection = @"Provider=Search.CollatorDSO.1;Extended Properties=""Application=Windows""";

            using (OleDbConnection connection = new OleDbConnection(windowsSearchConnection))
            {
                connection.Open();
                var command = new OleDbCommand(query, connection);
                try
                {
                    using (var r = command.ExecuteReader())
                    {
                        var cont     = true;
                        var context  = new CancelDialogDataContext();
                        var dialogue = new CancelDialog(context);
                        context.OnCancel = (n, m) => cont = false;
                        context.OnClosed = (n, m) => context.OnCancel(n, null);

                        dialogue.Show();
                        while (cont)
                        {
                            try
                            {
                                cont = r.Read();
                                var filepath = $"{r[0]}";

                                if (IsJpg(filepath))
                                {
                                    result.Add(filepath);
                                }
                            }
                            catch (Exception e) { Debug.WriteLine(e); }
                            finally { dialogue.Close(); }
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                    var dialogue = new CancelDialog();
                    var context  = new CancelDialogDataContext();
                    int i;
                    var files = Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories);
                    context.MaxValue      = files.Length;
                    context.PerformAction = () =>
                    {
                        for (i = 0; i < files.Length; i++)
                        {
                            var fileName = files[i];
                            if (IsJpg(fileName) && MatchesCriteria(fileName, tagQueryCriteria))
                            {
                                result.Add(fileName);
                            }

                            context.CurrentValue++;
                        }
                    };
                    context.OnCancel = (n, m) => { i = files.Length; dialogue.Close(); };
                    context.OnClosed = (n, m) => context.OnCancel(n, null);

                    dialogue.SetContext(context);
                    dialogue.ShowDialog();
                }
                finally
                {
                    connection.Close();
                }
            }
            if (randomize)
            {
                result.Shuffle();
            }

            return(result);
        }