Beispiel #1
0
 public List<SNewCommentsFrom> NumCommentsUnreadBy(int pointId, int callerId)
 {
     using (var ctx = new DiscCtx(ConfigManager.ConnStr))
     {
         return DAL.Helper.NumCommentsUnreadBy(ctx, pointId, callerId);
     }                           
 }
Beispiel #2
0
 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 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());
        }
Beispiel #4
0
 public static void DropContext()
 {
     if (ctx != null)
     {
         ctx = null;
     }
 }
Beispiel #5
0
        public static bool PointHasUnreadComments(DiscCtx ctx, int argPointId, int callerId)
        {
            var caller = ctx.Person.FirstOrDefault(p => p.Id == callerId);
            if (caller == null)
                return false;

            var ap = ctx.ArgPoint.FirstOrDefault(ap0 => ap0.Id == argPointId);
            if (ap == null)
                return false;
            
            foreach (var c in ap.Comment)
            {
                if (c.Person == null)
                    continue;

                //skip own comment
                if (c.Person.Id == callerId)
                    continue;

                //if self is not in number of those who read the comment
                if (c.ReadEntry.All(re => re.Person.Id != callerId))
                    return true;
            }

            return false;
        }
Beispiel #6
0
        public static List<SNewCommentsFrom> NumCommentsUnreadBy(DiscCtx ctx, int argPointId, int callerId)
        {
            var res = new List<SNewCommentsFrom>();

            var ap = ctx.ArgPoint.FirstOrDefault(ap0 => ap0.Id == argPointId);
            if (ap == null)
                return res;

            foreach (var c in ap.Comment)
            {
                if (c.Person == null)
                    continue;

                //skip own comment
                if (c.Person.Id == callerId)
                    continue;

                //if self is not in number of those who read the comment
                if (!c.ReadEntry.Any(re => re.Person.Id == callerId))
                {
                    var bin = res.Find(ncf => ncf.PersonId == c.Person.Id);
                    if (bin == null)
                    {
                        bin = new SNewCommentsFrom {PersonId = c.Person.Id, PersonName = c.Person.Name};
                        res.Add(bin);
                    }
                    bin.NumNewComments++;
                }
            }

            return res;
        }
        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
            };
        }
Beispiel #8
0
 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();
     }
 }
Beispiel #9
0
 public static void Drop()
 {
     if (_cached != null)
     {
         _cached.Dispose();
         _cached = null;
     }
 }
Beispiel #10
0
        public static DiscCtx Get()
        {
            if (ctx == null)
            {
                ctx = new DiscCtx(Discussions.ConfigManager.ConnStr);
            }

            return ctx;
        }
        public CommentNotificationDeferral(Dispatcher disp, DiscCtx ctx, ItemsControl commentItems)
        {
            _disp = disp;
            _ctx = ctx;
            _commentItems = commentItems;

            _disp.BeginInvoke(new Action(InjectCommentNotifications),
                              System.Windows.Threading.DispatcherPriority.Background);
        }     
Beispiel #12
0
        protected override void Setup()
        {
            base.Setup();

            var ctx = new DiscCtx(Discussions.ConfigManager.ConnStr);
             
            foreach (var p in ctx.Person)
                p.Online = false;
            ctx.SaveChanges();
        }
Beispiel #13
0
        public SessionTopicDlg()
        {
            InitializeComponent();

            AddWindowAvailabilityHandlers();

            this.WindowState = WindowState.Normal;

            _ctx = new DiscCtx(Discussions.ConfigManager.ConnStr);
            lstSessions.ItemsSource = _ctx.Session;
        }
Beispiel #14
0
        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());
        }
Beispiel #15
0
        public static DiscCtx GetFresh()
        {
            if (_cached==null || !_dup.IsDuplicate())
            {
                _cached = new DiscCtx(ConfigManager.ConnStr);
            }

            _dup.RecordEvent();

            return _cached;
        }
Beispiel #16
0
        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            
            _ctx = new DiscCtx(ConfigManager.ConnStr);
            var reportParams = queryParams.Materialize(_ctx);
            if (reportParams == null)
            {
                context.Response.StatusCode = 400;
                return;
            }

            _screenshotClient = new ReportingPhotonClient();
            var reportingTasks = _screenshotClient.StartReportingActivities(
                reportParams.Topic,
                reportParams.Discussion,
                reportParams.Session,
                _ctx);

            //blocking wait
            //var r1 = reportingTasks.ScreenshotsTask.Result;  
            //var r2 = reportingTasks.ReportTask.Result;  

            //compute and set report parameters 
            _report = new Report
            {
                QueryParams = queryParams,
                ReportParams = reportParams,
                Participants = Helpers.ParticipantsTuples(reportParams.Topic, reportParams.Session),
                ComplexReport = reportingTasks.ReportTask.Result,
                ReportUrl = context.Request.Url.ToString(),
                BaseUrl = Helpers.BaseUrl(context.Request)
            };

            _report.ReceiveScreenshots(reportingTasks.ScreenshotsTask.Result, context);

            _cleanupTimer = new Timer(5 * 60 * 1000); //5 minutes
            _cleanupTimer.Elapsed += CleanupTimerOnElapsed;
            _cleanupTimer.Start();

            context.Response.Write(_report.TransformText());
        }
Beispiel #17
0
        private void RefreshUsersStatus()
        {
            UsersStatus.Clear();

            //fresh each time!
            var discCtx = new DiscCtx(Discussions.ConfigManager.ConnStr);
            foreach (var p in discCtx.Person)
                if (p.Online)
                    UsersStatus.Add(p);

            lblOnlinePlayers.Content = "Online now:" + UsersStatus.Count;
        }
Beispiel #18
0
        public void RemoveComment(int commentId)
        {
            using (var ctx = new DiscCtx(ConfigManager.ConnStr))
            {
                var dbComment = ctx.Comment.FirstOrDefault(c => c.Id == commentId);
                if (dbComment == null)
                    return;

                ctx.DeleteObject(dbComment);
                ctx.SaveChanges();
            }
        }
Beispiel #19
0
        public ReportParameters Materialize(DiscCtx ctx)
        {         
            var res = new ReportParameters
                {
                    Discussion = ctx.Discussion.FirstOrDefault(d0 => d0.Id == DiscussionId),
                    Topic = ctx.Topic.FirstOrDefault(t0 => t0.Id == TopicId),
                    Session = ctx.Session.FirstOrDefault(s0 => s0.Id == SessionId)
                };

            if (res.Discussion == null || res.Topic == null || res.Session==null)
                return null;

            return res;
        }
Beispiel #20
0
 public Attachment ToDbEntity(DiscCtx ctx)
 {
     return new Attachment 
     {
         Name = this.Name,
         Format = this.Format,
         VideoThumbURL = this.VideoThumbURL,
         VideoEmbedURL = this.VideoEmbedURL,
         VideoLinkURL = this.VideoLinkURL,
         Link = this.Link,
         Title = this.Title,
         Thumb = this.Thumb
     };
 }
Beispiel #21
0
        public void ChangeCommentText(int commentId, string newText)
        {
            using (var ctx = new DiscCtx(ConfigManager.ConnStr))
            {
                var dbComment = ctx.Comment.FirstOrDefault(c => c.Id == commentId);
                if (dbComment == null)
                    return;

                if (newText != dbComment.Text)
                {
                    dbComment.Text = newText;
                    ctx.SaveChanges();
                }
            }
        }
Beispiel #22
0
 public void ProcessRequest(HttpContext context)
 {
     context.Response.ContentType = "text/html";
     var discId = -1;
     if (int.TryParse(context.Request.QueryString["id"], out discId) || discId == -1)
     {
         DiscCtx ctx = new DiscCtx(ConfigManager.ConnStr);
         var disc = ctx.Discussion.FirstOrDefault(d0 => d0.Id == discId);
         if (disc != null)
             context.Response.Write(disc.HtmlBackground);
     }
     else
     {
         context.Response.Write("Cannot find background for this discussion");
     }
 }
Beispiel #23
0
        private static string Export(ExportEventSelectorVM eventsFilter, 
                                     List<ReportParameters> reportParams)
        {
            //write header
            var sb = new StringBuilder();
            sb.Append("Id;");
            sb.Append("Event;");
            sb.Append("EventName;");
            sb.Append("DiscussionId;");
            sb.Append("DiscussionName;");
            sb.Append("TopicId;");
            sb.Append("TopicName;");
            sb.Append("UserId;");
            sb.Append("UserName;");
            sb.Append("Time;");
            sb.Append("DeviceType;");
            sb.AppendLine("DeviceTypeName");

            var ctx = new DiscCtx(Discussions.ConfigManager.ConnStr);
            foreach (var ev in ctx.StatsEvent)
            {
                var addEvent = false;

                if (ev.Id == 2)
                {
                    int i = 0;
                }

                if(eventsFilter.EventExported((StEvent)ev.Event))
                {
                    if (ev.UserId == -1)
                    {
                        addEvent = true;
                    }
                    else if (EventPassesFilter(ev, reportParams))
                    {
                        addEvent = true;
                    }
                }

                if (addEvent)
                    AddEventRow(sb, ev);
            }

            return sb.ToString();
        }
        void GenerateReportTargets()
        {
            ReportTargets = new List<ReportParameters>();

            var ctx = new DiscCtx(Discussions.ConfigManager.ConnStr);

            var sessions = ctx.Session.ToList();

            var sessionIdToPersons = new Dictionary<int, List<Person>>();

            foreach (var session in sessions)
            {
                List<Person> sessionPersons = GetPersonsOfSession(session);
                sessionIdToPersons.Add(session.Id, sessionPersons);
            }

            var allTopics = new List<Topic>();

            var usersOfAllSessions = new List<Person>();
            foreach (var session in sessions)
            {
                //get users of current session             
                foreach (var person in session.Person)
                {
                    if (usersOfAllSessions.All(u => u.Id != person.Id))
                        usersOfAllSessions.Add(person);

                    foreach (var persTopic in person.Topic)
                    {
                        if (allTopics.All(t => t.Id != persTopic.Id))
                        {
                            allTopics.Add(persTopic);

                            var reportParams = new ReportParameters(
                                sessionIdToPersons[session.Id].Select(p => p.Id).ToList(),
                                session,
                                persTopic,
                                persTopic.Discussion
                                );

                            ReportTargets.Add(reportParams);
                        }
                    }
                }
            }
        }
Beispiel #25
0
 public static ScreenshotResponse Read(Dictionary<byte, object> par)
 {
     var res = new ScreenshotResponse();
     res.screenshots = new Dictionary<int, byte[]>();
     using (var ctx = new DiscCtx(Discussions.ConfigManager.ConnStr))
     {
         var shapeIds = (int[]) par[(byte) DiscussionParamKey.ArrayOfInts];
         for (int i = 0; i < shapeIds.Length; i++)
         {
             int mediaId = (int) par[(byte) i];
             var mediaEntity = ctx.MediaDataSet.Single(m => m.Id == mediaId);
             res.screenshots.Add(shapeIds[i], mediaEntity.Data);
             ctx.DeleteObject(mediaEntity); 
         }
         ctx.SaveChanges(); //deleted entities 
         return res;
     }
 }
Beispiel #26
0
        public void CheckPersist()
        {
            if (!_pendingChanges)
                return;
            _pendingChanges = false;

            using (var dbCtx = new DiscCtx(Discussions.ConfigManager.ConnStr))
            {
                var topic = dbCtx.Topic.FirstOrDefault(t0 => t0.Id == _topicId);
                var str = new MemoryStream();
                var writer = new BinaryWriter(str);
                if (this.Write(writer))
                {
                    topic.Annotation = str.ToArray();
                    dbCtx.SaveChanges();
                }
            }
        }
Beispiel #27
0
        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();
            }
        }
Beispiel #28
0
        public static Dictionary<byte, object> Write(Dictionary<int, byte[]> screenshots)
        {
            using (var ctx = new DiscCtx(Discussions.ConfigManager.ConnStr))
            {
                var res = new Dictionary<byte, object>();

                //array of integers (shape Ids)          
                var shapeIds = screenshots.Keys.ToArray();
                res.Add((byte) DiscussionParamKey.ArrayOfInts, shapeIds);

                for (int i = 0; i < shapeIds.Length; i++)
                {
                    var md = new MediaData {Data = screenshots[shapeIds[i]]};
                    ctx.AddToMediaDataSet(md);
                    ctx.SaveChanges();//save here, need Id
                    res.Add((byte) i, md.Id);
                }                
                return res;
            }
        }
Beispiel #29
0
 public Attachment ToDbEntity(DiscCtx ctx)
 {
     return new Attachment 
     {
         Name = this.Name,
         Format = this.Format,
         VideoThumbURL = this.VideoThumbURL,
         VideoEmbedURL = this.VideoEmbedURL,
         VideoLinkURL = this.VideoLinkURL,
         Link = this.Link,
         Title = this.Title,
         Thumb = this.Thumb,
         OrderNumber = this.OrderNumber,
         ArgPoint = ArgPointId!=null ? ctx.ArgPoint.FirstOrDefault(ap => ap.Id == ArgPointId) : null,
         Person = ctx.Person.FirstOrDefault(p => p.Id == PersonId),
         Discussion = DiscussionId != null ? ctx.Discussion.FirstOrDefault(d => d.Id == DiscussionId) : null,
         PersonWithAvatar = PersonWithAvatarId != null ? ctx.Person.FirstOrDefault(p => p.Id == PersonWithAvatarId) : null,
         MediaData = ctx.MediaDataSet.FirstOrDefault(m=>m.Id==MediaDataId)
     };
 }
Beispiel #30
0
        public static bool Log(DiscCtx ctx, StEvent e, int userId, int discussionId, int topicId, DeviceType devType)
        {
            var pers = ctx.Person.FirstOrDefault(p0 => p0.Id == userId);
            if (pers == null && userId != -1)
                return false;

            var disc = ctx.Discussion.FirstOrDefault(d0 => d0.Id == discussionId);
            if (disc == null)
                return false;

            var topic = ctx.Topic.FirstOrDefault(t0 => t0.Id == topicId);
            if (topic == null)
                return false;

            if (!topic.Running && e != StEvent.RecordingStarted &&
                e != StEvent.RecordingStopped)
            {
                return false;
            }

            var s = new StatsEvent
            {
                DiscussionId = discussionId,
                DiscussionName = disc.Subject,
                TopicId = topicId,
                TopicName = topic.Name,
                UserId = userId
            };
            if (pers != null)
                s.UserName = pers.Name;
            else
                s.UserName = "******";
            s.Event = (int) e;
            s.Time = DateTime.Now;
            s.DeviceType = (int) devType;

            ctx.AddToStatsEvent(s);
            ctx.SaveChanges();

            return true;
        }