Пример #1
0
        /// <summary>
        /// Конструирует объект
        /// </summary>
        public QpContentManager(IQpDbConnector dbConnector, ILogger <IQpContentManager> logger)
        {
            _dbConnection = dbConnector;
            _logger       = logger;

            _query = new ContentDataQueryObject(
                null, null, null, null, null, null,
                (long)0, (long)0,
                (byte)0,
                QpContentItemStatus.Published.GetDescription(),
                (byte)0, (byte)0, false, 0.0, false, false);
            _query.GetCount = false;

            _includes = new List <string>();
        }
        public DataTable GetContentDataWithSecurity(string siteName, string contentName, string whereExpression, string orderExpression, long startRow, long pageSize, out long totalRecords, byte useSchedule, string statusName, byte showSplittedArticle, byte includeArchive, long lngUserId, long lngGroupId, int intStartLevel, int intEndLevel, bool blnFilterRecords)
        {
            var obj = new ContentDataQueryObject(this, siteName, contentName, string.Empty, whereExpression, orderExpression, startRow, pageSize, useSchedule, statusName, showSplittedArticle, includeArchive, false, 0, false, false)
            {
                UseSecurity   = true,
                UserId        = lngUserId,
                GroupId       = lngGroupId,
                StartLevel    = intStartLevel,
                EndLevel      = intEndLevel,
                FilterRecords = blnFilterRecords
            };

            var result = CacheManager.GetQueryResult(obj, out totalRecords);
            var dv     = new DataView(result);

            return(dv.ToTable());
        }
        public DbDataReader GetContentDataReader(ContentDataQueryObject obj, CommandBehavior readerParams = CommandBehavior.Default)
        {
            if (ExternalConnection == null)
            {
                throw new ApplicationException("ExternalConnection for DbConnector instance has not been defined");
            }

            obj.GetCount           = false;
            obj.UseClientSelection = false;
            var cmd = obj.GetDbCommand();

            cmd.Connection  = ExternalConnection as SqlConnection;
            cmd.Transaction = GetActualTransaction();
            if (cmd.Connection != null && cmd.Connection.State == ConnectionState.Closed)
            {
                cmd.Connection.Open();
            }

            return(cmd.ExecuteReader(readerParams));
        }
Пример #4
0
 public DataTable GetContentData(ContentDataQueryObject query, ref long totalRecords)
 {
     throw new NotImplementedException();
 }
Пример #5
0
        /// <summary>
        /// Получает связанные контенты
        /// </summary>
        /// <param name="result">Результат</param>
        protected virtual void GetIncludes(QpContentResult result)
        {
            if (_includes.Count > 0)
            {
                var attributes = new QpMetadataManager(_dbConnection)
                                 .GetContentAttributes(
                    _query.SiteName,
                    _query.ContentName);

                foreach (var path in _includes)
                {
                    var    attr        = attributes.Where(w => w.Name == path).SingleOrDefault();
                    string contentName = _dbConnection.GetContentName(attr.RelatedContentId.Value);

                    string values = string.Empty;

                    if (attr.LinkId == null)
                    {
                        foreach (DataRow row in result.PrimaryContent.Rows)
                        {
                            if (contentName == _query.ContentName & !string.IsNullOrEmpty(row[path].ToString()))
                            {
                                if (result.PrimaryContent.Select(ContentItemIdFieldName + " = " + row[path].ToString()).Any())
                                {
                                    continue;
                                }
                            }

                            if (!string.IsNullOrEmpty(values) && !values.EndsWith(", "))
                            {
                                values += ", ";
                            }

                            string val = row[path].ToString();
                            if (!string.IsNullOrEmpty(val))
                            {
                                values += val;
                            }
                        }
                    }
                    else
                    {
                        foreach (DataRow row in result.PrimaryContent.Rows)
                        {
                            if (!string.IsNullOrEmpty(values))
                            {
                                values += ", ";
                            }

                            string val = row[ContentItemIdFieldName].ToString();
                            if (!string.IsNullOrEmpty(val))
                            {
                                values += val;
                            }
                        }

                        if (!string.IsNullOrEmpty(values) && !string.IsNullOrWhiteSpace(values))
                        {
                            values = _dbConnection.GetContentItemLinkIDs(attr.Name, values);
                        }
                    }

                    values = values.Trim();
                    if (values.EndsWith(","))
                    {
                        values = values.Substring(0, values.Length - 1);
                    }

                    if (!string.IsNullOrEmpty(values))
                    {
                        var query = new ContentDataQueryObject(
                            _dbConnection.DbConnector, _query.SiteName, contentName, "*",
                            string.Format(ContentItemIdFieldName + " in ({0})", values), null,
                            (long)0, (long)0,
                            (byte)0,
                            QpContentItemStatus.Published.GetDescription(),
                            (byte)0, (byte)0, false, 0.0, false, false);

                        var contentData       = _dbConnection.GetContentData(query, out _);
                        var existsContentData = result.GetContent(contentName);

                        if (existsContentData != null)
                        {
                            //NOTE: this line doesn't coverage unit tests
                            existsContentData.Merge(
                                contentData);
                        }

                        result.AddContent(contentName, contentData);
                    }
                }
            }
        }
        public DataTable GetContentData(ContentDataQueryObject obj, out long totalRecords)
        {
            var result = CacheManager.GetQueryResult(obj, out totalRecords);

            if ((!CacheData || !obj.CacheResult) && !obj.UseClientSelection)
            {
                return(result);
            }

            var dv = new DataView(result);

            if (obj.UseClientSelection)
            {
                var hasRegionId = dv.Table.Columns.Contains("RegionId");
                if (!string.IsNullOrEmpty(obj.Where))
                {
                    dv.RowFilter = obj.Where;
                }

                totalRecords = dv.Count;
                if (!string.IsNullOrEmpty(obj.OrderBy))
                {
                    dv.Sort = obj.OrderBy;
                }

                if (obj.StartRow < 1)
                {
                    obj.StartRow = 1;
                }

                if (obj.PageSize < 0)
                {
                    obj.PageSize = 0;
                }

                if (obj.StartRow > 1 || obj.PageSize > 0)
                {
                    if (dv.Count > 0)
                    {
                        if ((int)obj.StartRow <= dv.Count)
                        {
                            int endRow;
                            if (obj.PageSize == 0)
                            {
                                endRow = dv.Count;
                            }
                            else if (obj.StartRow + obj.PageSize > dv.Count)
                            {
                                endRow = dv.Count;
                            }
                            else
                            {
                                endRow = (int)obj.StartRow + (int)obj.PageSize - 1;
                            }

                            var ids = new string[endRow - (int)obj.StartRow + 1];
                            int i;
                            var j = 0;
                            for (i = (int)obj.StartRow - 1; i <= endRow - 1; i++)
                            {
                                if (hasRegionId)
                                {
                                    ids[j] =
                                        $"(CONTENT_ITEM_ID = {dv[i]["CONTENT_ITEM_ID"]} and RegionId = {dv[i]["RegionId"]})";
                                }
                                else
                                {
                                    ids[j] = $"CONTENT_ITEM_ID = {dv[i]["CONTENT_ITEM_ID"]}";
                                }
                                j = j + 1;
                            }

                            dv.RowFilter = string.Join(" or ", ids);
                        }
                        else
                        {
                            dv.RowFilter = "CONTENT_ITEM_ID = 0";
                        }
                    }
                }
            }

            return(dv.ToTable());
        }
 public DataTable GetContentData(ContentDataQueryObject obj)
 {
     obj.GetCount = false;
     return(GetContentData(obj, out var _));
 }
        public DataTable GetContentData(string siteName, string contentName, string fields, string whereExpression, string orderExpression, long startRow, long pageSize, out long totalRecords, byte useSchedule, string statusName, byte showSplittedArticle, byte includeArchive, bool cacheResult, double cacheInterval, bool useClientSelection, bool withReset)
        {
            var obj = new ContentDataQueryObject(this, siteName, contentName, fields, whereExpression, orderExpression, startRow, pageSize, useSchedule, statusName, showSplittedArticle, includeArchive, cacheResult, cacheInterval, useClientSelection, withReset);

            return(GetContentData(obj, out totalRecords));
        }
 /// <summary>
 /// Возвращает данные контента
 /// </summary>
 /// <param name="query">Запрос</param>
 /// <param name="totalRecords">Общее количество строк</param>
 /// <returns></returns>
 public DataTable GetContentData(ContentDataQueryObject query, out long totalRecords)
 {
     return(DbConnector.GetContentData(query, out totalRecords));
 }