private void OnCommentRead(CommentsReadEvent ev) { var ap = DataContext as ArgPoint; if (ap == null) { return; } if (ev.ArgPointId != ap.Id) { return; } if (ev.PersonId == SessionInfo.Get().person.Id) { var ctx = new DiscCtx(ConfigManager.ConnStr); UpdateLocalReadCounts(ctx, ap); new CommentNotificationDeferral(Dispatcher, ctx, lstBxComments1); } else { UpdateRemoteReadCounts(new DiscCtx(ConfigManager.ConnStr), ap); } }
public static void DropContext() { if (ctx != null) { ctx = null; } }
public void AddComment(SComment comment) { using (var ctx = new DiscCtx(ConfigManager.ConnStr)) { var argPoint = ctx.ArgPoint.FirstOrDefault(ap => ap.Id == comment.ArgPointId); if (argPoint == null) { return; } var person = ctx.Person.FirstOrDefault(ap => ap.Id == comment.PersonId); if (person == null) { return; } var newComment = new Comment { ArgPoint = argPoint, Person = person, Text = comment.Text }; argPoint.Comment.Add(newComment); ctx.SaveChanges(); } }
public List <SComment> GetCommentsInArgPoint(int pointId) { using (var ctx = new DiscCtx(ConfigManager.ConnStr)) { return(ctx.Comment.Where(c => c.ArgPoint.Id == pointId).Select(c => new SComment(c)).ToList()); } }
public void AddSourceArgPoint(int pointId, string text, int callerId) { using (var ctx = new DiscCtx(ConfigManager.ConnStr)) { var point = ctx.ArgPoint.FirstOrDefault(ap => ap.Id == pointId); if (point == null) { return; } var lastSrc = point.Description.Source.OrderBy(s => s.OrderNumber).LastOrDefault(); int orderNumber = lastSrc != null ? lastSrc.OrderNumber + 1 : 1; var source = new Source { OrderNumber = orderNumber, RichText = null, Text = text }; point.Description.Source.Add(source); ctx.SaveChanges(); } }
public ReportingActivitiesTasks StartReportingActivities(Topic topic, Discussion disc, Session session, DiscCtx ctx) { _topic = topic; _disc = disc; _session = session; var moder = ctx.Person.Single(p => p.Name.StartsWith("moder")); _clienRt = new ClientRT(disc.Id, ConfigManager.ServiceServer, moder.Name, moder.Id, DeviceType.Wpf); _clienRt.onJoin += OnJoined; _hardReportTCS = new TaskCompletionSource <ReportCollector>(); _remoteScreenshotTCS = new TaskCompletionSource <Dictionary <int, byte[]> >(); Task.Factory.StartNew(async() => { while (_servicingPhotonClient) { _clienRt.Service(); await Utils.Delay(40); } }); return(new ReportingActivitiesTasks { ReportTask = _hardReportTCS.Task, ScreenshotsTask = _remoteScreenshotTCS.Task }); }
public List <SNewCommentsFrom> NumCommentsUnreadBy(int pointId, int callerId) { using (var ctx = new DiscCtx(ConfigManager.ConnStr)) { return(DAL.Helper.NumCommentsUnreadBy(ctx, pointId, callerId)); } }
public List <int> SubsetOfPersonsWithDots(List <int> personIds, int topicId, int callerId) { using (var ctx = new DiscCtx(ConfigManager.ConnStr)) { return(DAL.Helper.SubsetOfPersonsWithDots(ctx, personIds, topicId, callerId)); } }
public void Dispose() { if (_cachedEntity != null && _mediaStream != null) { // Get the new entity from the Entity Framework object state manager. ObjectStateEntry entry = this.context.ObjectStateManager.GetObjectStateEntry(_cachedEntity); if (entry.State == EntityState.Unchanged) { { var ctx = new DiscCtx(ConfigManager.ConnStr); ctx.Attach(_cachedEntity); _cachedEntity.MediaData.Data = _mediaStream.ToArray(); ctx.SaveChanges(); } } else { // A problem must have occurred when saving the entity to the database, // so we should delete the entity var mediaData = _cachedEntity.MediaData; _cachedEntity.MediaData = null; var ctx = new DiscCtx(ConfigManager.ConnStr); if (mediaData != null) { ctx.Attach(mediaData); ctx.DeleteObject(mediaData); } ctx.Attach(_cachedEntity); ctx.DeleteObject(_cachedEntity); throw new DataServiceException("An error occurred. The media resource could not be saved."); } } }
public static List <int> SubsetOfPersonsWithDots(DiscCtx ctx, List <int> personIds, int topicId, int callerId) { var topic = ctx.Topic.FirstOrDefault(t => t.Id == topicId); if (topic == null) { return(new List <int>()); } var res = new List <int>(); foreach (var ap in topic.ArgPoint) { if (!personIds.Contains(ap.Person.Id)) { continue; } if (NumCommentsUnreadBy(ctx, ap.Id, callerId).Total() > 0) { if (!res.Contains(ap.Person.Id)) { res.Add(ap.Person.Id); } } } return(res); }
public SCommentReadInfo GetCommentReadInfo(int commentId, int callerId) { using (var ctx = new DiscCtx(ConfigManager.ConnStr)) { var result = new SCommentReadInfo { PersonsWhoRead = new List <SPerson>() }; var comment = ctx.Comment.FirstOrDefault(c => c.Id == commentId); if (comment == null) { return(result); } result.PersonsWhoRead = comment.ReadEntry.Select(re => new SPerson(re.Person)).ToList(); var allUsersWhoCanRead = new List <int>(comment.ArgPoint.Topic.Person.Select(p => p.Id)); result.EveryoneInTopicRead = allUsersWhoCanRead.Except(result.PersonsWhoRead.Select(p => p.Id)).Count() == 0; return(result); } }
public static string GetBackground(QueryParams parameters, DiscCtx ctx) { var discId = parameters.DiscussionId; var disc = ctx.Discussion.Single(d0 => d0.Id == discId); return(disc.HtmlBackground); }
/// <summary> /// Own comment cannot be new. /// Placeholder cannot be new. /// Comment of other user is new if unread by us. /// </summary> public static bool IsCommentNewForUs(DiscCtx ctx, int commentId) { //new comment that hasn't been saved if (commentId == 0) { return(false); } if (SessionInfo.Get().person == null) { return(false); } var selfId = SessionInfo.Get().person.Id; var c = ctx.Comment.FirstOrDefault(c0 => c0.Id == commentId); if (c == null) { return(false); } if (c.Person == null) { return(false); } if (c.Person.Id == selfId) { return(false); } //if self is not in number of those who read the comment, the comment is new for us return(c.ReadEntry.All(re => re.Person.Id != selfId)); }
public static string RecentCommentReadBy(DiscCtx ctx, int argPointId) { if (argPointId == 0) { return(""); } var selfId = SessionInfo.Get().person.Id; var ap = ctx.ArgPoint.FirstOrDefault(ap0 => ap0.Id == argPointId); if (ap == null) { return(""); } //var recentComment = ap.Comment.LastOrDefault(c => c.Person != null && c.Person.Id == selfId); //use recent comment by anyone var recentComment = ap.Comment.LastOrDefault(c => c.Person != null); if (recentComment == null || recentComment.Person == null) { return(""); } var res = new StringBuilder(string.Format("\"{0}\" seen by ", SummaryTextConvertor.ShortenLine(recentComment.Text, 15) ) ); var atLeastOneReader = false; var unreadUsers = new List <int>(ap.Topic.Person.Where(p => p.Id != selfId).Select(p => p.Id)); foreach (var readEntry in recentComment.ReadEntry) { unreadUsers.Remove(readEntry.Person.Id); if (readEntry.Person.Id != selfId && recentComment.Person.Id != readEntry.Person.Id) { if (atLeastOneReader) { res.Append(", "); } atLeastOneReader = true; res.Append(readEntry.Person.Name); } } if (unreadUsers.Count == 0) { return(string.Format("\"{0}\" seen by all", SummaryTextConvertor.ShortenLine(recentComment.Text, 15))); } if (atLeastOneReader) { return(res.ToString()); } return(""); }
private void UpdateLocalUnreadCountsOfOtherUser(DiscCtx ctx) { foreach (var ap in ArgPointsOfOtherUser) { ap.NumUnreadComments = DaoUtils.NumCommentsUnreadBy(ctx, ap.Ap.Id).Total(); } }
private void lstBxPersons_SelectionChanged(object sender, SelectionChangedEventArgs e) { SelectedPerson = e.AddedItems[0] as Person; decoration.SetGreetingName(SelectedPerson.Name); //enum all discussions of the person if (SelectedPerson != null) { DiscCtx ctx = DbCtx.Get(); IQueryable <Discussion> myDiscussions = (from t in ctx.Topic where t.Person.Any(p0 => p0.Id == SelectedPerson.Id) select t.Discussion).Distinct(); _discussions.Clear(); foreach (var d in myDiscussions) { _discussions.Add(d); } //add dummy discussion for moderator if (SelectedPerson.Name.StartsWith("moder")) { _discussions.Add(DummyDiscussion); } lblSelDiscussion.Visibility = Visibility.Visible; } else { lblSelDiscussion.Visibility = Visibility.Hidden; } }
public void ProcessRequest(HttpContext context) { //validate query parameters QueryParams queryParams; try { queryParams = new QueryParams(context.Request); } catch { context.Response.StatusCode = 400; //bad request return; } //convert query parameters to entities var ctx = new DiscCtx(ConfigManager.ConnStr); var reportParams = queryParams.Materialize(ctx); if (reportParams == null) { context.Response.StatusCode = 400; return; } //compute and set report parameters var report = new SourcesReport { ReportParams = reportParams, }; context.Response.Write(report.TransformText()); }
//forces all badges to rebuild their views. but current instance of DB context is used (need to update it manually) public static void ToggleBadgeContexts(DiscCtx ctx, IEnumerable <IVdShape> badges) { foreach (var v in badges) { ((VdBadge)v).RecontextBadge(ctx); } }
public Discussion cloneDiscussion(DiscCtx ctx, Discussion original, Person moderator, int i) { var d = new Discussion(); d.Subject = injectNumber(original.Subject, i); //copy background d.Background = new RichText(); d.Background.Text = original.Background.Text; foreach (var src in original.Background.Source) { var s = new Source(); s.Text = src.Text; s.OrderNumber = src.OrderNumber; d.Background.Source.Add(s); } foreach (var media in original.Attachment) { var attach = new Attachment(); attach.Discussion = d; attach.Format = media.Format; attach.Link = media.Link; attach.Name = media.Name; attach.Title = media.Title; attach.VideoEmbedURL = media.VideoEmbedURL; attach.VideoLinkURL = media.VideoLinkURL; attach.VideoThumbURL = media.VideoThumbURL; attach.OrderNumber = media.OrderNumber; if (media.Thumb != null) { attach.Thumb = (byte[])media.Thumb.Clone(); } if (media.MediaData != null && media.MediaData.Data != null) { var mediaClone = new MediaData(); mediaClone.Data = (byte[])media.MediaData.Data.Clone(); attach.MediaData = mediaClone; } attach.Person = moderator; d.Attachment.Add(attach); } d.HtmlBackground = original.HtmlBackground; foreach (var topic in original.Topic) { var t = new Topic(); t.Name = injectNumber(topic.Name, i); t.Person.Add(moderator); d.Topic.Add(t); } return(d); }
private LoginResult testLoginStub(DiscCtx ctx) { var loginRes = new LoginResult(); loginRes.discussion = ctx.Discussion.First(); loginRes.person = ctx.Person.FirstOrDefault(p0 => p0.Name.StartsWith("moder")); return(loginRes); }
public static void Drop() { if (_cached != null) { _cached.Dispose(); _cached = null; } }
public List <SArgPoint> GetArgPointsInTopic(int topicId, int callerId) { using (var ctx = new DiscCtx(ConfigManager.ConnStr)) { var points = ctx.ArgPoint.Where(ap => ap.Topic.Id == topicId); return(points.Select(p => new SArgPoint(p, ctx, callerId)).ToList()); } }
public async void ProcessRequest(HttpContext context) { //validate query parameters QueryParams queryParams; try { queryParams = new QueryParams(context.Request); } catch { context.Response.StatusCode = 400; //bad request return; } //convert query parameters to entities var ctx = new DiscCtx(ConfigManager.ConnStr); var reportParams = queryParams.Materialize(ctx); if (reportParams == null) { context.Response.StatusCode = 400; return; } var screenshotClient = new ReportingPhotonClient(); var reportingTasks = screenshotClient.StartReportingActivities(reportParams.Topic, reportParams.Discussion, reportParams.Session); var complexReportTask = reportingTasks.Item2; //compute and set report parameters var report = new Report { QueryParams = queryParams, ReportParams = reportParams, Participants = Helpers.ParticipantsTuples(reportParams.Topic, reportParams.Session), ComplexReport = await complexReportTask, ReportUrl = context.Request.Url.ToString(), BaseUrl = Helpers.BaseUrl(context.Request) }; var screenshotTask = reportingTasks.Item1; report.ReceiveScreenshots(await screenshotTask, context); var cleanupTimer = new Timer(10 * 60 * 1000); //10 minutes cleanupTimer.Elapsed += (sender, args) => { cleanupTimer.Dispose(); report.Dispose(); screenshotClient.Dispose(); }; cleanupTimer.Start(); context.Response.Write(report.TransformText()); }
private void UpdateLocalReadCounts(DiscCtx ctx, ArgPoint ap) { if (ap == null) { return; } SetNumUnreadComments(DaoUtils.NumCommentsUnreadBy(ctx, ap.Id)); }
void UpdateRemoteReadCounts(DiscCtx ctx, ArgPoint ap) { if (ap == null) { return; } txtCommentSeenBy.Text = DaoUtils.RecentCommentReadBy(ctx, ap.Id); }
public CommentNotificationDeferral(Dispatcher disp, DiscCtx ctx, ItemsControl commentItems) { _disp = disp; _ctx = ctx; _commentItems = commentItems; _disp.BeginInvoke(new Action(InjectCommentNotifications), System.Windows.Threading.DispatcherPriority.Background); }
public bool MoveAttachmentDown(int attachmentId) { using (var ctx = new DiscCtx(ConfigManager.ConnStr)) { var res = DAL.Helper.SwapAttachmentWithNeib(ctx, false, attachmentId); ctx.SaveChanges(); return(res); } }
public bool MoveSourceDown(int sourceId) { using (var ctx = new DiscCtx(ConfigManager.ConnStr)) { var res = DAL.Helper.SwapSourceWithNeib(ctx, false, sourceId); ctx.SaveChanges(); return(res); } }
public static DiscCtx Get() { if (ctx == null) { ctx = new DiscCtx(Discussions.ConfigManager.ConnStr); } return(ctx); }
private void UpdateLocalReadCounts(DiscCtx ctx, ArgPoint ap) { if (ap == null) { return; } SetNumUnreadComments(DaoUtils.NumCommentsUnreadBy(ctx, ap.Id).Total()); new CommentNotificationDeferral(Dispatcher, ctx, lstBxComments); }