Exemple #1
0
        internal static bool OpenFeedItem(Commentable item)
        {
            string url = GetRantUrl(item.RantId);

            Process.Start(url);
            return(true);
        }
Exemple #2
0
        public void Question_CanBeCreated_Successfully()
        {
            // Arrange
            var    user        = new UserBuilder().BuildValidUser().Build();
            int    tagCount    = 3;
            string title       = "TitleNormal";
            string body        = "BodyNormal";
            var    tags        = new TagBuilder().Build(tagCount);
            var    limits      = new LimitsBuilder().Build();
            var    voteable    = new Voteable();
            var    commentable = new Commentable();

            // Act
            var result = Question.Create(user, title, body, tags, limits);

            // Assert
            Assert.NotEqual(default(Guid), result.Id);
            Assert.Equal(user, result.User);
            Assert.Equal(title, result.Title);
            Assert.Equal(body, result.Body);
            Assert.False(result.HasAcceptedAnswer);
            Assert.True(DateTime.UtcNow - result.CreatedOn < TimeSpan.FromSeconds(1));
            Assert.Empty(result.Answers);
            Assert.Empty(result.Comments);
            Assert.Equal(3, result.QuestionTags.Count());
        }
        private EditPostWindow(Type type, Draft existing = null, Commentable parent = null, FeedItem edit = null)
        {
            InitializeComponent();

            vm          = new EditPostWindowViewModel(this, type, existing, parent, edit);
            DataContext = vm;
        }
Exemple #4
0
        private void AddComment(Commentable post)
        {
            if (post == null)
            {
                if (SelectedPost == null)
                {
                    return;
                }
                else
                {
                    post = SelectedPost as Commentable;
                }
            }

            var dlg = EditPostWindow.CreateForComment(api, post);

            dlg.Owner = window;

            dlg.ShowDialog();

            if (!dlg.Cancelled)
            {
                post.IncrementComments();
            }
        }
    public void Update()
    {
        cursor.transform.position = Input.mousePosition;

        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit) && (DialogueRunner.instance != null && !DialogueRunner.instance.isDialogueRunning))
        {
            Debug.DrawLine(Camera.main.transform.position, hit.point);

            if (hit.transform.gameObject != lastHit)
            {
                lastHit = hit.transform.gameObject;

                if (lastHit.tag == "Interactable")
                {
                    animator.SetBool("Interacting", true);
                    Interactable i = lastHit.GetComponent <Interactable>();
                    text.text = i.interactionUIActionString + " " + i.interactionUIObjectString;
                }
                else if (lastHit.tag == "Viewable")
                {
                    animator.SetBool("Interacting", true);
                    Viewable i = lastHit.GetComponent <Viewable>();
                    text.text = i.viewUIActionString + " " + i.viewUIObjectString;
                }
                else if (lastHit.tag == "Pickupable")
                {
                    animator.SetBool("Interacting", true);
                    Pickupable i = lastHit.GetComponent <Pickupable>();
                    text.text = i.pickUpUIActionString + " " + i.pickUpUIObjectString;
                }
                else if (lastHit.tag == "NPC")
                {
                    animator.SetBool("Interacting", true);
                    Controller i = lastHit.GetComponentInParent <Controller>();
                    text.text = "Talk to " + i.name;
                }
                else if (lastHit.tag == "Commentable")
                {
                    animator.SetBool("Interacting", true);
                    Commentable i = lastHit.GetComponentInParent <Commentable>();
                    text.text = "Comment on " + i.commentableUIObjectString;
                }
                else
                {
                    animator.SetBool("Interacting", false);
                }
            }
        }
        else
        {
            animator.SetBool("Interacting", false);
        }
    }
        public EditPostWindowViewModel(Window window, EditPostWindow.Type type, Draft existing = null, Commentable parent = null, FeedItem edit = null)
        {
            this.window = window;
            this.api    = AppManager.Instance.API;
            this.db     = AppManager.Instance.DB;

            this.type     = type;
            this.existing = existing;
            this.parent   = parent;
            this.editing  = edit;

            Cancelled = true;

            if (parent != null)
            {
                mode = Mode.NewComment;

                ViewModels.Comment comment = parent as ViewModels.Comment;
                if (comment != null)
                {
                    if (AppManager.Instance.API.User.LoggedInUser != comment.Username)
                    {
                        Text = "@" + comment.Username + " ";
                    }
                }
            }
            else if (existing != null)
            {
                mode = Mode.EditDraft;

                Text       = existing.Text;
                TagsString = existing.Tags;
                ImagePath  = existing.ImagePath;
            }
            else if (edit != null)
            {
                mode = Mode.EditExisting;

                var r       = edit.AsRant();
                var comment = edit.AsComment();
                if (r != null)
                {
                    Text       = r.Text;
                    TagsString = r.TagsString;
                }
                else if (comment != null)
                {
                    Text = comment.Text;
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
        }
Exemple #7
0
        internal static async Task <bool> HandleButtons(Window window, ButtonClickedEventArgs args)
        {
            EditPostWindow editPost;

            switch (args.Type)
            {
            case ButtonType.Up:
            case ButtonType.Down:
                await Utilities.Vote(args);

                break;

            case ButtonType.Reply:
                if (args.SelectedItem is Commentable)
                {
                    Commentable ctbl = args.SelectedItem as Commentable;
                    editPost       = EditPostWindow.CreateForComment(AppManager.Instance.API, ctbl);
                    editPost.Owner = window;
                    editPost.ShowDialog();

                    if (!editPost.Cancelled)
                    {
                        ctbl.IncrementComments();
                    }
                }
                break;

            case ButtonType.Delete:
                switch (args.SelectedItem.Type)
                {
                case FeedItem.FeedItemType.Post:
                    AppManager.Instance.API.User.DeleteRant(args.SelectedItem.AsRant().ID);
                    break;

                case FeedItem.FeedItemType.Comment:
                    AppManager.Instance.API.User.DeleteComment(args.SelectedItem.AsComment().ID);
                    break;
                }
                break;

            case ButtonType.Edit:
                TimeSpan timespan = DateTime.Now.ToUniversalTime() - FromUnixTime(args.SelectedItem.RawCreateTime);
                if (timespan > MaxModifyMinutes)
                {
                    throw new Exception(args.SelectedItem.Type + " can no longer be edited.");
                }

                editPost       = EditPostWindow.CreateForEdit(AppManager.Instance.API, args.SelectedItem);
                editPost.Owner = window;
                editPost.ShowDialog();
                break;
            }

            return(true);
        }
    void Update()
    {
        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Input.GetButtonDown("Fire1"))
        {
            if (Physics.Raycast(ray, out hit))
            {
                if (hit.collider.CompareTag("Interactable"))
                {
                    Interactable objectHit = hit.transform.GetComponent <Interactable>();
                    if (objectHit != null && !DialogueRunner.instance.isDialogueRunning)
                    {
                        PlayerControllerMain.instance.InteractWith(objectHit);
                    }
                }
                else if (hit.collider.CompareTag("Viewable"))
                {
                    Viewable objectHit = hit.transform.GetComponent <Viewable>();
                    if (objectHit != null && !DialogueRunner.instance.isDialogueRunning)
                    {
                        PlayerControllerMain.instance.InteractWith(objectHit);
                    }
                }
                else if (hit.collider.CompareTag("Pickupable"))
                {
                    Pickupable objectHit = hit.transform.GetComponent <Pickupable>();
                    if (objectHit != null && !DialogueRunner.instance.isDialogueRunning)
                    {
                        PlayerControllerMain.instance.InteractWith(objectHit);
                    }
                }
                else if (hit.collider.tag == "NPC")
                {
                    if (PlayerControllerMain.instance.Control)
                    {
                        CheckForNearbyNPC(hit.collider.gameObject);
                    }
                }
                else if (hit.collider.tag == "Commentable")
                {
                    Commentable objectHit = hit.transform.GetComponent <Commentable>();
                    objectHit.Go();
                    if (objectHit != null && !DialogueRunner.instance.isDialogueRunning)
                    {
                        DialogueRunner.instance.StartDialogue(objectHit.startNode, playerText);
                    }
                }
            }
        }
    }
Exemple #9
0
        public QuestionBuilder SetupValidQuestion()
        {
            var    user        = new UserBuilder().BuildValidUser().Build();
            int    tagCount    = 3;
            string title       = "TitleNormal";
            string body        = "BodyNormal";
            var    tags        = new TagBuilder().Build(tagCount);
            var    voteable    = new Voteable();
            var    commentable = new Commentable();

            _target = Question.Create(user, title, body, tags, _limits);
            return(this);
        }
Exemple #10
0
        public void Answer_CreatingWithInvalidData_FailsValidation(string userId, string body)
        {
            // Arrange
            var question    = new QuestionBuilder().SetupValidQuestion().Build();
            var limits      = new LimitsBuilder().Build();
            var voteable    = new Voteable();
            var commentable = new Commentable();
            var user        = new UserBuilder().BuildUser(new Guid(userId)).Build();

            // Act, Assert
            Assert.Throws <BusinessException>(() =>
                                              Answer.Create(user, body, question, limits));
        }
Exemple #11
0
        public void Question_CreatingWithInvalidData_FailsValidation(string userId, int tagCount, string title, string body)
        {
            // Arrange
            var user        = new UserBuilder().BuildUser(new Guid(userId)).Build();
            var tags        = new TagBuilder().Build(tagCount);
            var limits      = new LimitsBuilder().Build();
            var voteable    = new Voteable();
            var commentable = new Commentable();

            // Act, Assert
            Assert.Throws <BusinessException>(() =>
                                              Question.Create(user, title, body, tags, limits));
        }
Exemple #12
0
        public void Commentable_CommentOutOfOrder_Throws()
        {
            // Arrange
            var target        = new Commentable();
            var firstComment  = new CommentBuilder().SetupValidComment(1).Build();
            var secondComment = new CommentBuilder().SetupValidComment(2).Build();
            var targetComment = new CommentBuilder().SetupValidComment(2).Build();  // Repeat the order number.

            target.Comment(firstComment);
            target.Comment(secondComment);

            // Act, Assert
            Assert.Throws <BusinessException>(() => target.Comment(targetComment));
        }
Exemple #13
0
        public void Question_CreatingWithWrongNumberOfTags_Fails(int tagCount)
        {
            // Arrange
            var user  = new UserBuilder().BuildValidUser().Build();
            var title = "TitleNormal";
            var body  = "BodyNormal";
            var tags  = Builder <Tag>
                        .CreateListOfSize(tagCount)
                        .Build()
                        .ToList();

            var limits      = new LimitsBuilder().Build();
            var voteable    = new Voteable();
            var commentable = new Commentable();

            // Act, Assert
            Assert.Throws <BusinessException>(() =>
                                              Question.Create(user, title, body, tags, limits));
        }
Exemple #14
0
        public void Commentable_CommentsAreAddedInIncreasingOrder_Successfully()
        {
            // Arrange
            var target        = new Commentable();
            var firstComment  = new CommentBuilder().SetupValidComment(1).Build();
            var secondComment = new CommentBuilder().SetupValidComment(2).Build();
            var thirdComment  = new CommentBuilder().SetupValidComment(7).Build(); // Not back-to-back.

            // Act
            target.Comment(firstComment);
            target.Comment(secondComment);
            target.Comment(thirdComment);

            // Assert
            Assert.Equal(3, target.Comments.Count());
            Assert.Contains(firstComment, target.Comments);
            Assert.Equal(1, firstComment.OrderNumber);
            Assert.Contains(secondComment, target.Comments);
            Assert.Equal(2, secondComment.OrderNumber);
            Assert.Contains(thirdComment, target.Comments);
            Assert.Equal(7, thirdComment.OrderNumber);
        }
Exemple #15
0
        public void Answer_CanBeCreated_Successfully()
        {
            // Arrange
            var    question    = new QuestionBuilder().SetupValidQuestion().Build();
            var    user        = new UserBuilder().BuildValidUser().Build();
            string body        = "BodyNormal";
            var    limits      = new LimitsBuilder().Build();
            var    voteable    = new Voteable();
            var    commentable = new Commentable();

            // Act
            var result = Answer.Create(user, body, question, limits);

            // Assert
            Assert.NotEqual(default(Guid), result.Id);
            Assert.Equal(user, result.User);
            Assert.Equal(body, result.Body);
            Assert.False(result.IsAcceptedAnswer);
            Assert.Null(result.AcceptedOn);
            Assert.True(DateTime.UtcNow - result.CreatedOn < TimeSpan.FromSeconds(1));
            Assert.Empty(result.Comments);
        }
        public static EditPostWindow CreateForComment(IDevRantClient api, Commentable parent)
        {
            var window = new EditPostWindow(Type.Comment, parent: parent);

            return(window);
        }
Exemple #17
0
        public bool HaveColumn(string columnName, string columnValue, out bool retValueMatched)
        {
            bool ret          = false;
            bool valueMatched = false;

            if (columnName == "InfoPageID")
            {
                ret = true;
                if (InfoPageID.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "InfoPageGUID")
            {
                ret = true;
                if (InfoPageGUID.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "RevisionNo")
            {
                ret = true;
                if (RevisionNo.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "UserID")
            {
                ret = true;
                if (UserID.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "UserGUID")
            {
                ret = true;
                if (UserGUID.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "CreatedDate")
            {
                ret = true;
                if (CreatedDate.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "LastUpdateDate")
            {
                ret = true;
                if (LastUpdateDate.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "CreatedUserID")
            {
                ret = true;
                if (CreatedUserID.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "CreatedUserGUID")
            {
                ret = true;
                if (CreatedUserGUID.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "InfoPageName")
            {
                ret = true;
                if (InfoPageName.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "InfoPageDescription")
            {
                ret = true;
                if (InfoPageDescription.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "InfoCategoryID")
            {
                ret = true;
                if (InfoCategoryID.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "InfoCategoryGUID")
            {
                ret = true;
                if (InfoCategoryGUID.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "AccessGroupID")
            {
                ret = true;
                if (AccessGroupID.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "AccessGroupGUID")
            {
                ret = true;
                if (AccessGroupGUID.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "AsyncLoading")
            {
                ret = true;
                if (AsyncLoading.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "Commentable")
            {
                ret = true;
                if (Commentable.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "CommentorRoleList")
            {
                ret = true;
                if (CommentorRoleList.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "CommentorGroupList")
            {
                ret = true;
                if (CommentorGroupList.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "CommentorHideRoleList")
            {
                ret = true;
                if (CommentorHideRoleList.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "CommentorHideGroupList")
            {
                ret = true;
                if (CommentorHideGroupList.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "IsActive")
            {
                ret = true;
                if (IsActive.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "ExpiryDate")
            {
                ret = true;
                if (ExpiryDate.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "IsCommon")
            {
                ret = true;
                if (IsCommon.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "IsPublic")
            {
                ret = true;
                if (IsPublic.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "Sequence")
            {
                ret = true;
                if (Sequence.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            if (columnName == "IsDeleted")
            {
                ret = true;
                if (IsDeleted.ToString() == columnValue)
                {
                    valueMatched = true;
                }
            }
            retValueMatched = valueMatched;
            return(ret);
        }