/// <summary> /// 各プロパティによる検索方法の定義 /// </summary> /// <returns></returns> private static Dictionary <int, PropertySearch> MakeSearchDictionary() { var dictionary = new Dictionary <int, PropertySearch>(); dictionary[(int)FileProperty.Id] = new PropertySearch(nameof(Record.Id), true, o => DatabaseReference.ToEqualsString(o)); dictionary[(int)FileProperty.DirectoryPath] = new PropertySearch(DatabaseFunction.ToLower(nameof(Record.Directory)), true, o => DatabaseReference.ToLowerEqualsString(o)); dictionary[(int)FileProperty.DirectoryPathStartsWith] = new PropertySearch(DatabaseFunction.ToLower(nameof(Record.Directory)), false, o => { var str = o.ToString(); var separator = System.IO.Path.DirectorySeparatorChar.ToString(); return((str.EndsWith(separator)) ? DatabaseReference.Match(str) : DatabaseReference.StartsWith(str + separator)); }); dictionary[(int)FileProperty.DirectoryPathContains] = new PropertySearch(DatabaseFunction.ToLower(nameof(Record.Directory)), false, o => DatabaseReference.Contains(o.ToString())); dictionary[(int)FileProperty.FullPath] = new PropertySearch( DatabaseFunction.ToLower (DatabaseFunction.Combine(nameof(Record.Directory), nameof(Record.FileName))), true, o => DatabaseReference.ToLowerEqualsString(o)); dictionary[(int)FileProperty.FileName] = new PropertySearch(true, (o, mode) => { var column = DatabaseFunction.ToLower(nameof(Record.FileName)); if (mode == CompareMode.Equal || mode == CompareMode.NotEqual) { var converted = DatabaseReference.Match(o.ToString()); if (mode == CompareMode.Equal) { return(DatabaseExpression.Is(column, converted)); } else { return(DatabaseExpression.IsNot(column, converted)); } } else { var converted = DatabaseReference.ToLowerEqualsString(o); return(DatabaseExpression.Compare(column, mode, converted)); } }); dictionary[(int)FileProperty.FileNameContains] = new PropertySearch( DatabaseFunction.ToLower(nameof(Record.FileName)), false, o => DatabaseReference.Contains(o.ToString())); dictionary[(int)FileProperty.DateTimeCreated] = new PropertySearch(nameof(Record.DateCreated), true, o => DatabaseReference.DateTimeOffsetReference((DateTimeOffset)o)); dictionary[(int)FileProperty.DateTimeModified] = new PropertySearch(nameof(Record.DateModified), true, o => DatabaseReference.DateTimeOffsetReference((DateTimeOffset)o)); dictionary[(int)FileProperty.DateTimeRegistered] = new PropertySearch(nameof(Record.DateRegistered), true, o => DatabaseReference.DateTimeOffsetReference((DateTimeOffset)o)); dictionary[(int)FileProperty.DateCreated] = new PropertySearch(DatabaseFunction.GetDate(nameof(Record.DateCreated)), true, o => DatabaseReference.DateOffsetReference((DateTimeOffset)o)); dictionary[(int)FileProperty.DateModified] = new PropertySearch(DatabaseFunction.GetDate(nameof(Record.DateModified)), true, o => DatabaseReference.DateOffsetReference((DateTimeOffset)o)); dictionary[(int)FileProperty.DateRegistered] = new PropertySearch(DatabaseFunction.GetDate(nameof(Record.DateRegistered)), true, o => DatabaseReference.DateOffsetReference((DateTimeOffset)o)); dictionary[(int)FileProperty.Width] = new PropertySearch(nameof(Record.Width), true); dictionary[(int)FileProperty.Height] = new PropertySearch(nameof(Record.Height), true); dictionary[(int)FileProperty.Size] = new PropertySearch(nameof(Record.Size), true); dictionary[(int)FileProperty.ContainsTag] = new PropertySearch(nameof(Record.TagEntry), false, o => DatabaseReference.Contains($",{(int)o},")); dictionary[(int)FileProperty.HasTag] = new PropertySearch(false, (o, c) => { var column = DatabaseFunction.Length(nameof(Record.TagEntry)); var mode = c.ContainsEqual() ? CompareMode.GreatEqual : CompareMode.Less; return(DatabaseExpression.Compare(column, mode, new DatabaseReference("2"))); }); dictionary[(int)FileProperty.Rating] = new PropertySearch(nameof(Record.Rating), true, o => new DatabaseReference(RateConvertingHelper.Reverse((int)o).ToString())); dictionary[(int)FileProperty.Group] = new PropertySearch(nameof(Record.GroupKey), true, o => DatabaseReference.ToEqualsString(o)); dictionary[(int)FileProperty.AspectRatio] = new PropertySearch( DatabaseFunction.Divide(nameof(Record.Width), nameof(Record.Height)), true); return(dictionary); }