예제 #1
0
        /// <summary>
        /// ライブラリデータをロードします。
        /// </summary>
        /// <param name="libCondition"></param>
        /// <param name="nowPlayingInfo"></param>
        public void Load(LibraryCondition libCondition, INowPlayingInfo nowPlayingInfo)
        {
            var libraries = _databaseAccessor.SelectLibraryList(libCondition);

            LibraryItems.Clear();
            foreach (var libraryItem in libraries)
            {
                if (nowPlayingInfo.Library != null && nowPlayingInfo.Id == libraryItem.Id) libraryItem.IsPlaying = true; 
                LibraryItems.Add(libraryItem);
            }
        }
예제 #2
0
        /// <summary>
        /// ライブラリを取得するSQLを生成します。
        /// </summary>
        /// <returns></returns>
        public string CreateSelectLibrary(LibraryMode libraryMode, LibraryCondition libCondition)
        {
            bool isFullSql = false;
            var sb = new StringBuilder();
            sb.Append(SQLResource.SelectLibraryList);
            sb.Append(" WHERE ");
            sb.Append(CreateRatingWhereString(libraryMode));

            if (!string.IsNullOrEmpty(libCondition.FilteringText))
            {
                // フィルタリング
                var filterString = libCondition.FilteringText.ToLower();
                sb.Append(" AND ");
                var normalFilter = "lower(IFNULL(FILEPATH,'') || IFNULL(TITLE,'') || IFNULL(GPL.GROUPNAME,'') || IFNULL(SEASON,'')) LIKE '%" +
                        EscapeSQL(filterString) + "%' ";
                if (filterString.Length < 3)
                {
                    sb.Append(normalFilter);
                }
                else
                {
                    var migemoFilter = "ISMATCHMIGEMO('" + EscapeSQL(filterString) +
                                       "',lower(IFNULL(FILEPATH,'') || IFNULL(TITLE,'') || IFNULL(GPL.GROUPNAME,''))) ";
                    sb.Append(string.Format("(({0}) OR ({1}))", normalFilter, migemoFilter));
                }
            }

            var condSql = libCondition.Condition.Sql;

            switch (libCondition.FilteringMode)
            {
                case FilteringMode.SQL:
                    condSql = condSql.ToUpper();
                    if (string.IsNullOrEmpty(condSql)) break;
                    if (!(condSql.Substring(0, 3).Equals("AND")
                          || condSql.Substring(0, 2).Equals("OR"))) isFullSql = true;
                    sb.Append(condSql);
                    break;

                case FilteringMode.Group:
                    // TODO: Gidでもよいのでは?
                    sb.Append(" AND ");
                    if (!string.IsNullOrEmpty(condSql))
                    {
                        sb.Append(" GPL.GROUPNAME = '" + EscapeSQL(condSql) + "'");
                    }
                    else
                    {
                        sb.Append(" GPL.GROUPNAME IS NULL ");
                    }
                    sb.Append(" ORDER BY round(PL.NO)");
                    break;
            }
            

            var sql = sb.ToString();
            if (isFullSql) sql = SQLResource.SelectLibraryList + " " + condSql;
            if (!sql.ToUpper().Contains("ORDER BY")) sql += " ORDER BY PL.DATE desc ";
            if (libCondition.Condition.IsLimited && libCondition.MaxLimitNum > 0) sql += string.Format(" LIMIT {0}", libCondition.MaxLimitNum);
            return sql;
        }
예제 #3
0
 public void DiffLoad(LibraryCondition libCondition)
 {
     var libraries = _databaseAccessor.SelectLibraryList(libCondition).ToArray();
     LibraryItems.DiffInsert(libraries,
         new LibraryItemComparer());
 
 }
        /// <summary>
        /// ライブラリを取得します。
        /// </summary>
        /// <param name="libCondition"></param>
        /// <returns></returns>
        public IEnumerable<LibraryItem> SelectLibraryList(LibraryCondition libCondition)
        {
            _lastLibrarySelectSQL = _sqlBuilder.CreateSelectLibrary(_appConfig.LibraryMode, libCondition);
            return SqlExecuter.Query<LibraryItem>(_lastLibrarySelectSQL);

        }