コード例 #1
0
            //This is the new process to retrieve comments.
            public static List <T> Retrieve <T>(int submissionID, int?depth, int?parentID, Func <usp_CommentTree_Result, T> selector, Action <T> processor)
            {
                if (depth.HasValue && depth < 0)
                {
                    depth = null;
                }


                //Get cached results
                List <usp_CommentTree_Result> commentTree = CacheHandler.Register <List <usp_CommentTree_Result> >(CacheHandler.Keys.CommentTree(submissionID),

                                                                                                                   new Func <List <usp_CommentTree_Result> >(() =>
                {
                    using (voatEntities db = new voatEntities())
                    {
                        //currently only working on the full tree, so params are nulled out
                        var flatTree = db.usp_CommentTree(submissionID, null, null).ToList();
                        return(flatTree);
                    }
                }), TimeSpan.FromSeconds(cacheTimeInSeconds), 10);

                //execute query
                var results = commentTree.Select(selector).ToList();

                if (results != null && processor != null)
                {
                    results.ForEach(processor);
                }
                return(results);
            }