Beispiel #1
0
 public CommentTimelineViewModel()
 {
     Timeline          = new CommentTimeline();
     CodeBeforeComment = new Dictionary <string, TimelineCodeDocument>();
     CodeAfterComment  = new Dictionary <string, TimelineCodeDocument>();
     Log    = new EventLog();
     Author = new OsbideUser();
 }
Beispiel #2
0
        /// <summary>
        /// Finds 50 build events centered around the supplied id parameter
        /// </summary>
        /// <param name="eventLogId">The id of the <see cref="EventLog"/> to use as an anchor</param>
        /// <returns></returns>
        public ActionResult Index(int eventLogId)
        {
            CommentTimeline    timeline   = Db.CommentTimelines.Where(t => t.EventLogId == eventLogId).FirstOrDefault();
            EventLog           commentLog = OsbideDb.EventLogs.Include(u => u.Sender).Where(el => el.Id == timeline.EventLogId).FirstOrDefault();
            BuildDiffViewModel viewModel  = new BuildDiffViewModel();

            viewModel.User          = commentLog.Sender;
            viewModel.Comment       = timeline;
            viewModel.OriginalEvent = commentLog;

            //grab 10 prior builds
            viewModel.BuildsBefore = (
                from el in OsbideDb.EventLogs
                join be in OsbideDb.BuildEvents
                .Include(b => b.Documents.Select(d => d.Document))
                .Include(b => b.EventLog)
                on el.Id equals be.EventLogId
                where el.Id < commentLog.Id &&
                el.SenderId == commentLog.SenderId
                orderby el.Id descending
                select be).Take(25).ToList();

            //and 10 builds after
            viewModel.BuildsAfter = (
                from el in OsbideDb.EventLogs
                join be in OsbideDb.BuildEvents
                .Include(b => b.Documents.Select(d => d.Document))
                .Include(b => b.EventLog)
                on el.Id equals be.EventLogId
                where el.Id > commentLog.Id &&
                el.SenderId == commentLog.SenderId
                orderby el.Id ascending
                select be).Take(25).ToList();


            //for each build event, grab NPSM state
            foreach (BuildEvent build in viewModel.BuildsBefore.Union(viewModel.BuildsAfter))
            {
                TimelineState priorBuildState = (from npsm in Db.TimelineStates
                                                 where npsm.StartTime >= build.EventLog.DateReceived &&
                                                 npsm.IsSocialEvent == false &&
                                                 npsm.UserId == commentLog.SenderId &&
                                                 npsm.State != "--"
                                                 orderby npsm.Id ascending
                                                 select npsm).Take(1).FirstOrDefault();
                if (priorBuildState == null)
                {
                    priorBuildState = new TimelineState();
                }
                viewModel.BuildStates.Add(build.Id, priorBuildState);
            }

            return(View(viewModel));
        }
        /// <summary>
        /// Generates a list of document saves centered around a particular point of interest
        /// </summary>
        /// <param name="id">The id of the <see cref="CommentTimeline"/> to use as an anchor</param>
        /// <returns></returns>
        public ActionResult DocumentSaveTimeline(int id)
        {
            CommentTimeline timeline = Db.CommentTimelines.Where(t => t.Id == id).FirstOrDefault();
            EventLog commentLog = OsbideDb.EventLogs.Include(u => u.Sender).Where(el => el.Id == timeline.EventLogId).FirstOrDefault();

            //get all posts in the conversation
            Post userPost = Db.Posts.Where(p => p.OsbideId == commentLog.Id).FirstOrDefault();
            List<Post> entireDiscussion = new List<Post>(); 
            if(userPost.ParentId > 0)
            {
                entireDiscussion = (from post in Db.Posts
                                    where (post.ParentId == userPost.ParentId || post.Id == userPost.ParentId)
                                    orderby post.OsbideId
                                    select post).ToList();
            }
            else
            {
                entireDiscussion = (from post in Db.Posts
                                    where (post.ParentId == userPost.Id || post.Id == userPost.Id)
                                    orderby post.OsbideId
                                    select post).ToList();
            }

            //for each post in the discussion, grab a snapshot of the user's code
            Dictionary<int, BuildEvent> beforeBuildEvents = new Dictionary<int, BuildEvent>();
            Dictionary<int, BuildEvent> afterBuildEvents = new Dictionary<int, BuildEvent>();
            Dictionary<int, TimelineState> statesBefore = new Dictionary<int, TimelineState>();
            Dictionary<int, TimelineState> statesAfter = new Dictionary<int, TimelineState>();
            foreach(Post post in entireDiscussion)
            {
                //get prior build event
                BuildEvent priorBuildEvent = (from el in OsbideDb.EventLogs
                                              join be in OsbideDb.BuildEvents 
                                              .Include(b => b.Documents.Select(d => d.Document))
                                              .Include(b => b.EventLog)
                                              on el.Id equals be.EventLogId
                                              where el.Id < post.OsbideId
                                              && el.SenderId == commentLog.SenderId
                                              orderby el.Id descending
                                              select be).Take(1).FirstOrDefault();
                //grab next build event
                BuildEvent nextBuildEvent = (from el in OsbideDb.EventLogs
                                             join be in OsbideDb.BuildEvents
                                             .Include(b => b.Documents.Select(d => d.Document))
                                             .Include(b => b.EventLog)
                                             on el.Id equals be.EventLogId
                                             where el.Id > post.OsbideId
                                             && el.SenderId == commentLog.SenderId
                                             orderby el.Id ascending
                                             select be).Take(1).FirstOrDefault();

                if (priorBuildEvent != null)
                {
                    //we want the NPSM state that resulted from this build
                    TimelineState priorBuildState = (from npsm in Db.TimelineStates
                                                     where npsm.StartTime >= priorBuildEvent.EventLog.DateReceived
                                                     && npsm.IsSocialEvent == false
                                                     && npsm.UserId == commentLog.SenderId
                                                     && npsm.State != "--"
                                                     orderby npsm.Id ascending
                                                     select npsm).Take(1).FirstOrDefault();
                    statesBefore.Add(post.Id, priorBuildState);
                    beforeBuildEvents.Add(post.Id, priorBuildEvent);
                }
                if(nextBuildEvent != null)
                {
                    //we want the NPSM state that resulted from this build
                    TimelineState afterBuildState = (from npsm in Db.TimelineStates
                                                     where npsm.StartTime >= nextBuildEvent.EventLog.DateReceived
                                                     && npsm.IsSocialEvent == false
                                                     && npsm.UserId == commentLog.SenderId
                                                     && npsm.State != "--"
                                                     orderby npsm.Id ascending
                                                     select npsm).Take(1).FirstOrDefault();
                    statesAfter.Add(post.Id, afterBuildState);
                    afterBuildEvents.Add(post.Id, nextBuildEvent);
                }
            }

            //construct final VM
            DocumentSaveTimelineViewModel viewModel = new DocumentSaveTimelineViewModel()
            {
                BuildsAfter = afterBuildEvents,
                BuildsBefore = beforeBuildEvents,
                Discussion = entireDiscussion,
                StatesAfter = statesAfter,
                StatesBefore = statesBefore,
                Timeline = timeline,
                TimelineLog = commentLog,
                User = commentLog.Sender
            };
            
            return View(viewModel);
        }
Beispiel #4
0
 public CommentTimelineViewModel(CommentTimeline timeline) : base()
 {
     Timeline = timeline;
 }