Exemple #1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            if (e.Args.Length > 0 && e.Args[0] == "experiment")
            {
                SessionInfo.Get().ExperimentMode = true;
            }
            else if (e.Args.Length > 2)
            {
                int screentopicId;
                int screenDiscId;
                if (int.TryParse(e.Args[0], out screentopicId) &&
                    int.TryParse(e.Args[1], out screenDiscId))
                {
                    SessionInfo.Get().ScreenshotMode = true;
                    SessionInfo.Get().screenTopicId  = screentopicId;
                    SessionInfo.Get().screenDiscId   = screenDiscId;
                    SessionInfo.Get().screenMetaInfo = e.Args[2];
                }
            }

            //in screenshot mode, we may have temp images not yet built into report
            if (!SessionInfo.Get().ScreenshotMode)
            {
                try
                {
                    Directory.Delete(Utils.TempDir(), true);
                }
                catch (Exception)
                {
                }
            }
        }
Exemple #2
0
        public static bool HandleCommentCommit(string comment, ArgPoint ap)
        {
            if (string.IsNullOrWhiteSpace(comment) || NEW_COMMENT == comment)
            {
                return(false);
            }

            ap.ChangesPending = true;

            var c = new Comment {
                Text = comment
            };

            //inject author
            var commentAuthor = SessionInfo.Get().getPerson(ap);
            var res           = InjectAuthorOfComment(c, commentAuthor);

            ap.Comment.Add(c);

            if (c.Text != _recentStatsEventSubmittedComment)
            {
                UISharedRTClient.Instance.clienRt.SendStatsEvent(
                    StEvent.CommentAdded,
                    SessionInfo.Get().person.Id,
                    ap.Topic.Discussion.Id,
                    ap.Topic.Id,
                    DeviceType.Wpf);
                _recentStatsEventSubmittedComment = c.Text;
            }

            return(res);
        }
Exemple #3
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var attach = value as Attachment;

            if (attach == null)
            {
                return(Visibility.Hidden);
            }

            var currentPers = SessionInfo.Get().person;

            if (currentPers == null)
            {
                return(Visibility.Hidden);
            }

            if (attach.Person == null)
            {
                return(Visibility.Hidden);
            }

            if (attach.Person.Id == currentPers.Id)
            {
                return(Visibility.Visible);
            }

            return(Visibility.Hidden);
        }
Exemple #4
0
        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("");
        }
Exemple #5
0
        /// <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));
        }
Exemple #6
0
        public static ArgPoint NewPoint(Topic t, int orderNumber)
        {
            if (t == null)
            {
                return(null);
            }

            //create new point
            ArgPoint pt = new ArgPoint();

            pt.Point = "Your title here/タイトル";
            pt.RecentlyEnteredSource   = "Your web url link here/URLリンク";
            pt.RecentlyEnteredMediaUrl = "Your media link here/画像URLリンク";
            DaoUtils.EnsurePtDescriptionExists(pt);

            pt.Description.Text = NEW_DESCRIPTION;
            pt.Topic            = PrivateCenterCtx.Get().Topic.FirstOrDefault(t0 => t0.Id == t.Id);
            int selfId = SessionInfo.Get().person.Id;
            var pers   = PrivateCenterCtx.Get().Person.FirstOrDefault(p0 => p0.Id == selfId);

            pt.Person         = pers;
            pt.SharedToPublic = true;
            pt.SideCode       = DaoUtils.GetGeneralSide(SessionInfo.Get().person,
                                                        SessionInfo.Get().discussion);
            pt.OrderNumber = orderNumber;

            return(pt);
        }
Exemple #7
0
        public static void ReportMediaOpened(StEvent ev, ArgPoint ap)
        {
            if (ap == null)
            {
                return;
            }

            UISharedRTClient.Instance.clienRt.SendStatsEvent(ev,
                                                             SessionInfo.Get().person.Id,
                                                             ap.Topic.Discussion.Id,
                                                             ap.Topic.Id,
                                                             DeviceType.Wpf);
        }
Exemple #8
0
        //we use separate context from one used by private board, not to interfere with it
        public static List <NewCommentsFrom> NumCommentsUnreadBy(DiscCtx ctx, int argPointId)
        {
            var res = new List <NewCommentsFrom>();

            //new point that hasn't been saved
            if (argPointId == 0)
            {
                return(res);
            }

            var selfId = SessionInfo.Get().person.Id;

            var ap = ctx.ArgPoint.FirstOrDefault(ap0 => ap0.Id == argPointId);

            if (ap == null)
            {
                return(new List <NewCommentsFrom>());
            }

            Comment[] comments = ap.Comment.ToArray();

            foreach (var c in comments)
            {
                if (c.Person == null)
                {
                    continue;
                }

                //skip own comment
                if (c.Person.Id == selfId)
                {
                    continue;
                }

                //if self is not in number of those who read the comment
                if (c.ReadEntry.All(re => re.Person.Id != selfId))
                {
                    var bin = res.Find(ncf => ncf.Person.Id == c.Person.Id);
                    if (bin == null)
                    {
                        bin = new NewCommentsFrom(c.Person);
                        res.Add(bin);
                    }
                    bin.NumNewComments++;
                }
            }

            return(res);
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (SessionInfo.Get().person == null)
            {
                return(Visibility.Collapsed);
            }

            if (SessionInfo.Get().person.Name.StartsWith(DaoUtils.MODER_SUBNAME))
            {
                return(Visibility.Visible);
            }
            else
            {
                return(Visibility.Collapsed);
            }
        }
        //all the changes will be cached locally without refreshing/redropping the context
        public static void pushDismissal(ArgPoint ap, DiscCtx ctx)
        {
            var persId = SessionInfo.Get().person.Id;

            var apId = ap.Id;

            ap = ctx.ArgPoint.Single(ap0 => ap0.Id == apId);

            foreach (var c in ap.Comment)
            {
                //skip "new comment"
                if (c.Person == null)
                {
                    continue;
                }

                var existing = c.ReadEntry.FirstOrDefault(re => re.Person.Id == persId);
                if (existing == null)
                {
                    var entry = new CommentPersonReadEntry
                    {
                        Comment = c,
                        Person  = ctx.Person.Single(p => p.Id == persId)
                    };
                    ctx.AddToCommentPersonReadEntry(entry);
                }
            }

            try
            {
                ctx.SaveChanges();
            }
            catch
            {
            }

            UISharedRTClient.Instance.clienRt.SendCommentsRead(SessionInfo.Get().person.Id,
                                                               ap.Topic.Id,
                                                               ap.Id, -1);
        }
        public static void startHtml5TopicReport(int topicId)
        {
            if (SessionInfo.Get().discussion == null)
            {
                MessageDlg.Show("No default discussion");
                return;
            }

            if (SessionInfo.Get().person.Session == null)
            {
                MessageDlg.Show(
                    string.Format(
                        "The function requires experimental mode (session)!",
                        SessionInfo.Get().person.Name));
                return;
            }

            var reportUrl = string.Format(
                "http://{0}/discsvc/report?discussionId={1}&topicId={2}&sessionId={3}",
                ConfigManager.ServiceServer,
                SessionInfo.Get().discussion.Id,
                topicId,
                SessionInfo.Get().person.Session.Id);

            try
            {
                System.Diagnostics.Process.Start("chrome", reportUrl);
            }
            catch
            {
                System.Diagnostics.Process.Start(reportUrl);
            }
            //var browser = WebkitBrowserWindow.Instance(reportUrl, topicId);
            //browser.Show();
            //browser.Activate();
        }
Exemple #12
0
        public static ArgPoint clonePoint(DiscCtx ctx, ArgPoint ap, Topic topic, Person owner, String name)
        {
            var top = ctx.Topic.FirstOrDefault(t0 => t0.Id == topic.Id);

            if (top == null)
            {
                return(null);
            }

            var ownPoints = top.ArgPoint.Where(p0 => p0.Person.Id == owner.Id);
            int orderNr   = 1;

            foreach (var pt in ownPoints)
            {
                if (pt.OrderNumber > orderNr)
                {
                    orderNr = pt.OrderNumber;
                }
            }

            var pointCopy = DaoUtils.NewPoint(top, orderNr + 1);

            pointCopy.Point            = name;
            pointCopy.Description.Text = ap.Description.Text;

            foreach (var src in ap.Description.Source)
            {
                var newSrc = new Source {
                    Text = src.Text
                };
                pointCopy.Description.Source.Add(newSrc);
            }

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

                var comment = new Comment();
                comment.Text = cmt.Text;
                var commentPersonId = cmt.Person.Id;
                comment.Person = ctx.Person.FirstOrDefault(p0 => p0.Id == commentPersonId);
                pointCopy.Comment.Add(comment);
            }

            var ownId = SessionInfo.Get().person.Id;
            var self  = ctx.Person.FirstOrDefault(p0 => p0.Id == ownId);

            foreach (var media in ap.Attachment)
            {
                var attach = new Attachment();
                attach.ArgPoint      = pointCopy;
                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 = self;
            }

            pointCopy.Person = self;

            pointCopy.Topic = top;

            return(pointCopy);
        }
        public static void startResultViewer()
        {
            if (SessionInfo.Get().discussion == null)
            {
                MessageDlg.Show("No default discussion");
            }
            else
            {
                if (SessionInfo.Get().person.Session == null)
                {
                    MessageDlg.Show(
                        string.Format(
                            "The function requires experimental mode (session)!",
                            SessionInfo.Get().person.Name));
                    return;
                }
                var tsd = new TopicSelectionDlg(SessionInfo.Get().discussion);
                tsd.ShowDialog();
                if (tsd.topic == null)
                {
                    return;
                }

                if (tsd.Html)
                {
                    var reportUrl = string.Format(
                        "http://{0}/discsvc/report?discussionId={1}&topicId={2}&sessionId={3}",
                        ConfigManager.ServiceServer,
                        SessionInfo.Get().discussion.Id,
                        tsd.topic.Id,
                        SessionInfo.Get().person.Session.Id);

                    try
                    {
                        System.Diagnostics.Process.Start("chrome", reportUrl);
                    }
                    catch
                    {
                        System.Diagnostics.Process.Start(reportUrl);
                    }
                    //var browser = WebkitBrowserWindow.Instance(reportUrl, tsd.topic.Id);
                    //browser.Show();
                    //browser.Activate();
                }
                else
                {
                    BusyWndSingleton.Show("Exporting, please wait...");
                    try
                    {
                        (new PdfReportDriver()).Run(SessionInfo.Get().person.Session,
                                                    tsd.topic,
                                                    SessionInfo.Get().discussion,
                                                    SessionInfo.Get().person);
                    }
                    finally
                    {
                        BusyWndSingleton.Hide();
                    }
                }
            }
        }