Beispiel #1
0
        /// <inheritdoc/>
        public async Task <ValidState> ValidateNodeAsync(TreeNode node, ValidState state)
        {
            var id     = new EntityId(node.Id.System, node.Id.Type, Constraints.SCH_GNODE, node.G_Parent.ToString());
            var parent = await this.GetNodeInfoAsync(id, node.StartUtc, CacheParams.ReadFreshWriteSec(60)).ConfigureAwait(false);

            if (parent == null)
            {
                state = new ValidState(state, new FieldValidationException(node, nameof(node.G_Parent),
                                                                           "Parent node `{0}` is not found as of the requested StartUtc of `{1}`. Create parent node first".Args(id, node.StartUtc)));
            }
            return(state);
        }
Beispiel #2
0
 public override void Add <TResult>(SerializedForm <TResult> result, string f, object entity, CacheParams cacheParams, params object[] parameters)
 {
     InMemoryCacheSet <TResult> .Add(f, entity, result, cacheParams, parameters);
 }
Beispiel #3
0
        public virtual IEnumerable <Comment> Fetch(CommentQuery query)
        {
            var start    = query.BlockIndex * CommentQuery.COMMENT_BLOCK_SIZE;
            var comments = Cache.FetchThrough <CommentQuery, IEnumerable <Comment> >(query,
                                                                                     SocialConsts.GS_COMMENT_BLOCK_TBL,
                                                                                     CacheParams.ReadFreshWriteSec(0), // todo TO DISCUSS
                                                                                     commQry =>
            {
                var rows       = new List <CommentRow>();
                var qryVolumes = Queries.FindCommentVolumes <CommentVolumeRow>(query.G_TargetNode, query.Dimension, MaxLastCommentVolumes, query.AsOfDate);
                var volumes    = ForNode(query.G_TargetNode).LoadEnumerable(qryVolumes);
                foreach (var volume in volumes)
                {
                    var qryComments = Queries.FindComments <CommentRow>(query.G_TargetNode, query.Dimension, true);
                    var loadRows    = ForComment(volume.G_CommentVolume).LoadEnumerable(qryComments);
                    rows.AddRange(loadRows);
                }

                IEnumerable <CommentRow> orderedRows = null;

                switch (query.OrderType)
                {
                case CommentOrderType.ByDate:
                    if (query.Ascending)
                    {
                        orderedRows = rows.OrderBy(row => row.Create_Date);
                    }
                    else
                    {
                        orderedRows = rows.OrderByDescending(row => row.Create_Date);
                    }
                    break;

                case CommentOrderType.ByPositive:
                    orderedRows = rows.OrderBy(row => row.Rating)
                                  .ThenByDescending(row => row.Create_Date);
                    break;

                case CommentOrderType.ByNegative:
                    orderedRows = rows.OrderByDescending(row => row.Rating)
                                  .ThenByDescending(row => row.Create_Date);
                    break;

                case CommentOrderType.ByPopular:
                    if (query.Ascending)
                    {
                        orderedRows = rows.OrderBy(row => row.Like + row.Dislike)
                                      .ThenByDescending(row => row.Create_Date);
                    }
                    else
                    {
                        orderedRows = rows.OrderByDescending(row => row.Like + row.Dislike)
                                      .ThenByDescending(row => row.Create_Date);
                    }
                    break;

                case CommentOrderType.ByUsefull:
                    if (query.Ascending)
                    {
                        orderedRows = rows.OrderBy(row => row.Like - row.Dislike)
                                      .ThenByDescending(row => row.Create_Date);
                    }
                    else
                    {
                        orderedRows = rows.OrderByDescending(row => row.Like - row.Dislike)
                                      .ThenByDescending(row => row.Create_Date);
                    }
                    break;

                default:
                    orderedRows = rows.OrderByDescending(row => row.Create_Date);
                    break;
                }
                return(orderedRows.Skip(start)
                       .Take(CommentQuery.COMMENT_BLOCK_SIZE)
                       .Select(RowToComment).ToArray());
            });

            return(comments);
        }
Beispiel #4
0
        public static void Add(string funcId, object entity, SerializedForm <TResult> result, CacheParams cacheParams, params object[] parameters)
        {
            rwLock.EnterWriteLock();
            try
            {
                if (!MemoizationTable.ContainsKey(funcId))
                {
                    MemoizationTable.Add(funcId, new List <MemoizationEntry <TResult> >());
                }

                MemoizationTable[funcId].Add(new MemoizationEntry <TResult>
                {
                    FuncId      = funcId,
                    Instance    = entity,
                    Result      = result,
                    Params      = parameters,
                    CacheParams = cacheParams,
                    TimeAdded   = DateTime.Now
                });
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }