/// <summary>
        /// Create the template output
        /// </summary>
        public virtual string TransformText()
        {
            this.Write("\r\n");

            #line 9 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"

            if (this.Filter != null)
            {
                var firstGroup = true;
                foreach (var group in this.Filter.Groups)
                {
                    if (firstGroup)
                    {
                        firstGroup = false;
                    }
                    else
                    {
            #line default
            #line hidden
                        this.Write(" AND ");

            #line 21 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"
                    }


            #line default
            #line hidden
                    this.Write("\t\r\nEXISTS\r\n(\r\n\tSELECT * \r\n\tFROM \"LibraryItem_MetaDataItem\"\r\n\t\tJOIN \"MetaDataItems" +
                               "\" ON \"MetaDataItems\".\"Id\" = \"LibraryItem_MetaDataItem\".\"MetaDataItem_Id\"\r\n\tWHERE" +
                               " \"LibraryItem_MetaDataItem\".\"LibraryItem_Id\" = \"LibraryItems\".\"Id\" AND (\r\n");

            #line 30 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"

                    var firstEntry = true;
                    foreach (var entry in group.Entries)
                    {
                        if (firstEntry)
                        {
                            firstEntry = false;
                        }
                        else
                        {
            #line default
            #line hidden
                            this.Write(" OR ");

            #line 40 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"
                        }
                        var numeric   = default(int);
                        var isNumeric = NumericOperators.Contains(entry.Operator) && int.TryParse(entry.Value, out numeric);


            #line default
            #line hidden
                        this.Write("(\"MetaDataItems\".\"Name\" = ");

            #line 44 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"
                        this.Write(this.ToStringHelper.ToStringWithCulture(this.Database.QueryFactory.Dialect.String(entry.Name)));

            #line default
            #line hidden
                        this.Write(" AND ");

            #line 44 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"

                        if (isNumeric)
                        {
            #line default
            #line hidden
                            this.Write("CAST(\"MetaDataItems\".\"Value\" AS int)");

            #line 47 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"
                        }
                        else
                        {
            #line default
            #line hidden
                            this.Write("\"MetaDataItems\".\"Value\"");

            #line 51 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"
                        }
                        switch (entry.Operator)
                        {
                        default:
                        case FilterParserEntryOperator.Equal:


            #line default
            #line hidden
                            this.Write(" = ");

            #line 57 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"

                            break;

                        case FilterParserEntryOperator.Greater:


            #line default
            #line hidden
                            this.Write(" > ");

            #line 60 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"

                            break;

                        case FilterParserEntryOperator.GreaterEqual:


            #line default
            #line hidden
                            this.Write(" >= ");

            #line 63 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"

                            break;

                        case FilterParserEntryOperator.Less:


            #line default
            #line hidden
                            this.Write(" < ");

            #line 66 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"

                            break;

                        case FilterParserEntryOperator.LessEqual:


            #line default
            #line hidden
                            this.Write(" <= ");

            #line 69 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"

                            break;

                        case FilterParserEntryOperator.Match:


            #line default
            #line hidden
                            this.Write(" LIKE ");

            #line 72 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"

                            break;
                        }


            #line default
            #line hidden

            #line 76 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"

                        if (isNumeric)
                        {
            #line default
            #line hidden

            #line 79 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"
                            this.Write(this.ToStringHelper.ToStringWithCulture(numeric));

            #line default
            #line hidden

            #line 79 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"
                        }
                        else
                        {
            #line default
            #line hidden

            #line 83 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"
                            this.Write(this.ToStringHelper.ToStringWithCulture(this.Database.QueryFactory.Dialect.String(entry.Value.Replace(FilterParserResultEntry.BOUNDED_WILDCARD, "_").Replace(FilterParserResultEntry.UNBOUNDED_WILDCARD, "%"))));

            #line default
            #line hidden

            #line 83 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"
                        }


            #line default
            #line hidden
                        this.Write(")");

            #line 86 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"
                    }


            #line default
            #line hidden
                    this.Write("))");

            #line 88 "C:\personal\FoxTunes\FoxTunes.DB\Templates\LibraryFilterBuilder.tt"
                }
            }


            #line default
            #line hidden
            return(this.GenerationEnvironment.ToString());
        }
示例#2
0
        /// <summary>
        /// Create the template output
        /// </summary>
        public virtual string TransformText()
        {
            this.Write("\r\n");

            #line 9 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"

            if (this.Filter != null)
            {
                switch (this.Source)
                {
                case LibraryHierarchyFilterSource.LibraryHierarchyItem:


            #line default
            #line hidden
                    this.Write("AND EXISTS\r\n(\r\n\tSELECT * \r\n\tFROM \"LibraryHierarchyItem_LibraryItem\"\r\n\tWHERE \"Libr" +
                               "aryHierarchyItem_LibraryItem\".\"LibraryHierarchyItem_Id\" = \"LibraryHierarchyItems" +
                               "\".\"Id\"\r\n");

            #line 21 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"

                    break;
                }
                foreach (var group in this.Filter.Groups)
                {
            #line default
            #line hidden
                    this.Write(@"	
AND EXISTS
(
	SELECT * 
	FROM ""LibraryItem_MetaDataItem""
		JOIN ""MetaDataItems"" ON ""MetaDataItems"".""Id"" = ""LibraryItem_MetaDataItem"".""MetaDataItem_Id""
	WHERE ""LibraryItem_MetaDataItem"".""LibraryItem_Id"" = ""LibraryHierarchyItem_LibraryItem"".""LibraryItem_Id"" AND (
");

            #line 33 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"

                    var first = true;
                    foreach (var entry in group.Entries)
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            switch (group.Operator)
                            {
                            default:
                            case    FilterParserGroupOperator.And:


            #line default
            #line hidden
                                this.Write(" AND ");

            #line 47 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"

                                break;

                            case FilterParserGroupOperator.Or:


            #line default
            #line hidden
                                this.Write(" OR ");

            #line 50 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"

                                break;
                            }
                        }
                        var numeric   = default(int);
                        var isNumeric = NumericOperators.Contains(entry.Operator) && int.TryParse(entry.Value, out numeric);


            #line default
            #line hidden
                        this.Write("(\"MetaDataItems\".\"Name\" = ");

            #line 56 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"
                        this.Write(this.ToStringHelper.ToStringWithCulture(this.Database.QueryFactory.Dialect.String(entry.Name)));

            #line default
            #line hidden
                        this.Write(" AND ");

            #line 56 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"

                        if (isNumeric)
                        {
            #line default
            #line hidden
                            this.Write("CAST(\"MetaDataItems\".\"Value\" AS int)");

            #line 59 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"
                        }
                        else
                        {
            #line default
            #line hidden
                            this.Write("\"MetaDataItems\".\"Value\"");

            #line 63 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"
                        }
                        switch (entry.Operator)
                        {
                        default:
                        case FilterParserEntryOperator.Equal:


            #line default
            #line hidden
                            this.Write(" = ");

            #line 69 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"

                            break;

                        case FilterParserEntryOperator.Greater:


            #line default
            #line hidden
                            this.Write(" > ");

            #line 72 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"

                            break;

                        case FilterParserEntryOperator.GreaterEqual:


            #line default
            #line hidden
                            this.Write(" >= ");

            #line 75 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"

                            break;

                        case FilterParserEntryOperator.Less:


            #line default
            #line hidden
                            this.Write(" < ");

            #line 78 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"

                            break;

                        case FilterParserEntryOperator.LessEqual:


            #line default
            #line hidden
                            this.Write(" <= ");

            #line 81 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"

                            break;

                        case FilterParserEntryOperator.Match:


            #line default
            #line hidden
                            this.Write(" LIKE ");

            #line 84 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"

                            break;
                        }


            #line default
            #line hidden

            #line 88 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"

                        if (isNumeric)
                        {
            #line default
            #line hidden

            #line 91 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"
                            this.Write(this.ToStringHelper.ToStringWithCulture(numeric));

            #line default
            #line hidden

            #line 91 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"
                        }
                        else
                        {
            #line default
            #line hidden

            #line 95 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"
                            this.Write(this.ToStringHelper.ToStringWithCulture(this.Database.QueryFactory.Dialect.String(entry.Value.Replace(FilterParserResultEntry.BOUNDED_WILDCARD, "_").Replace(FilterParserResultEntry.UNBOUNDED_WILDCARD, "%"))));

            #line default
            #line hidden

            #line 95 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"
                        }


            #line default
            #line hidden
                        this.Write(")");

            #line 98 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"
                    }


            #line default
            #line hidden
                    this.Write("))");

            #line 100 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"
                }
                switch (this.Source)
                {
                case LibraryHierarchyFilterSource.LibraryHierarchyItem:


            #line default
            #line hidden
                    this.Write(")");

            #line 105 "C:\Source\FoxTunes\FoxTunes.DB\Templates\LibraryHierarchyFilterBuilder.tt"

                    break;
                }
            }


            #line default
            #line hidden
            return(this.GenerationEnvironment.ToString());
        }