Example #1
0
        //public void OpenSendReplyPostPanel(string replyType, int postAuthorUserId, string postAuthorUsername, string quoteSimpleContent, string postTime, int floorNo, int postId, int threadId)
        //{
        //    FindName("UserDialog");

        //    Action<string> sendSuccess = (title) =>
        //    {
        //        // 开始倒计时
        //        SendMessageTimerSetup();

        //        // 回贴成功后,刷新回复页到底部
        //        if (AppFrame.Content.GetType().Equals(typeof(ThreadAndReplyPage)))
        //        {
        //            var page = (ThreadAndReplyPage)AppFrame.Content;
        //            var cmdBar = (CommandBar)page.FindName("RightCommandBar");
        //            if (cmdBar.DataContext.GetType().Equals(typeof(ReplyListViewForDefaultViewModel)))
        //            {
        //                var vm = (ReplyListViewForDefaultViewModel)cmdBar.DataContext;
        //                vm.LoadLastPageDataCommand.Execute(null);
        //            }
        //            else if (cmdBar.DataContext.GetType().Equals(typeof(ReplyListViewForSpecifiedPostViewModel)))
        //            {
        //                var vm = (ReplyListViewForSpecifiedPostViewModel)cmdBar.DataContext;
        //                vm.LoadLastPageDataCommand.Execute(null);
        //            }
        //        }
        //        else if (AppFrame.Content.GetType().Equals(typeof(ReplyListPage)))
        //        {
        //            var page = (ReplyListPage)AppFrame.Content;
        //            var cmdBar = (CommandBar)page.FindName("RightCommandBar");
        //            if (cmdBar.DataContext.GetType().Equals(typeof(ReplyListViewForDefaultViewModel)))
        //            {
        //                var vm = (ReplyListViewForDefaultViewModel)cmdBar.DataContext;
        //                vm.LoadLastPageDataCommand.Execute(null);
        //            }
        //            else if (cmdBar.DataContext.GetType().Equals(typeof(ReplyListViewForSpecifiedPostViewModel)))
        //            {
        //                var vm = (ReplyListViewForSpecifiedPostViewModel)cmdBar.DataContext;
        //                vm.LoadLastPageDataCommand.Execute(null);
        //            }
        //        }
        //    };

        //    var sendControl = new SendControl(replyType, postAuthorUserId, postAuthorUsername, quoteSimpleContent, postTime, floorNo, postId, threadId, sendSuccess);
        //    var binding = new Binding { Path = new PropertyPath("Countdown"), Source = this };
        //    sendControl.SetBinding(SendControl.CountdownProperty, binding);

        //    string titleParameter = string.Empty;
        //    if (replyType.Equals("r"))
        //    {
        //        titleParameter = "回复";
        //    }
        //    else if (replyType.Equals("q"))
        //    {
        //        titleParameter = "引用";
        //    }

        //    var titleBinding = new Binding { Path = new PropertyPath("Countdown"), Source = this, Converter = new CountdownToCountdownLabelConverter(), ConverterParameter = titleParameter };
        //    UserDialog.SetBinding(ContentDialog.TitleProperty, titleBinding);

        //    UserDialog.ContentTemplate = null;
        //    UserDialog.Content = sendControl;
        //}

        public void OpenSendEditPostPanel(PostEditDataModel editData)
        {
            OpenInputPanel(typeof(EditPostPage), editData);

            //FindName("UserDialog");

            //Action<string> sendSuccess = (t) =>
            //{
            //    // 开始倒计时
            //    SendMessageTimerSetup();

            //    // 回贴成功后,刷新回复页到底部
            //    if (AppFrame.Content.GetType().Equals(typeof(ThreadAndReplyPage)))
            //    {
            //        var page = (ThreadAndReplyPage)AppFrame.Content;
            //        var cmdBar = (CommandBar)page.FindName("RightCommandBar");
            //        if (cmdBar.DataContext.GetType().Equals(typeof(ReplyListViewForDefaultViewModel)))
            //        {
            //            var vm = (ReplyListViewForDefaultViewModel)cmdBar.DataContext;
            //            vm.RefreshReplyCommand.Execute(null);
            //        }
            //        else if (cmdBar.DataContext.GetType().Equals(typeof(ReplyListViewForSpecifiedPostViewModel)))
            //        {
            //            var vm = (ReplyListViewForSpecifiedPostViewModel)cmdBar.DataContext;
            //            vm.RefreshReplyCommand.Execute(null);
            //        }
            //    }
            //    else if (AppFrame.Content.GetType().Equals(typeof(ReplyListPage)))
            //    {
            //        var page = (ReplyListPage)AppFrame.Content;
            //        var cmdBar = (CommandBar)page.FindName("RightCommandBar");
            //        if (cmdBar.DataContext.GetType().Equals(typeof(ReplyListViewForDefaultViewModel)))
            //        {
            //            var vm = (ReplyListViewForDefaultViewModel)cmdBar.DataContext;
            //            vm.RefreshReplyCommand.Execute(null);
            //        }
            //        else if (cmdBar.DataContext.GetType().Equals(typeof(ReplyListViewForSpecifiedPostViewModel)))
            //        {
            //            var vm = (ReplyListViewForSpecifiedPostViewModel)cmdBar.DataContext;
            //            vm.RefreshReplyCommand.Execute(null);
            //        }
            //    }
            //};

            //var sendControl = new SendControl(title, content, postId, threadId, sendSuccess);
            //var binding = new Binding { Path = new PropertyPath("Countdown"), Source = this };
            //sendControl.SetBinding(SendControl.CountdownProperty, binding);

            //var titleBinding = new Binding { Path = new PropertyPath("Countdown"), Source = this, Converter = new CountdownToCountdownLabelConverter(), ConverterParameter = "编辑" };
            //UserDialog.SetBinding(ContentDialog.TitleProperty, titleBinding);

            //UserDialog.ContentTemplate = null;
            //UserDialog.Content = sendControl;
        }
        public SendEditPostPageViewModel(CancellationTokenSource cts, PostEditDataModel editData,
                                         Action <int, int, string> beforeUpload, Action <string> insertFileCodeIntoContentTextBox, Action <int> afterUpload, Action <string> sentFailded, Action <string> sentSuccess)
        {
            ShowUnusedImage(cts);

            Title          = editData.Title;
            Content        = editData.Content;
            AttachFileList = editData.AttachFileList;
            _postId        = editData.PostId;
            _threadId      = editData.ThreadId;
            _beforeUpload  = beforeUpload;
            _insertFileCodeIntoContentTextBox = insertFileCodeIntoContentTextBox;
            _afterUpload = afterUpload;
            _sentSuccess = sentSuccess;
            _sentFailded = sentFailded;

            //RemoveAttachFileCommand = new DelegateCommand();
            //RemoveAttachFileCommand.ExecuteAction = (p) =>
            //{
            //    int a = 1;
            //};

            //InsertAttachFileCommand = new DelegateCommand();
            //InsertAttachFileCommand.ExecuteAction = (p) =>
            //{
            //    int b = 1;
            //};

            AddAttachFilesCommand = new DelegateCommand();
            AddAttachFilesCommand.ExecuteAction = async(p) =>
            {
                var data = await SendService.UploadFileAsync(cts, _beforeUpload, _afterUpload);

                if (data[0] != null && data[0].Count > 0)
                {
                    _fileAddList.AddRange(data[0]);
                }
                if (data[1] != null && data[1].Count > 0)
                {
                    _fileCodeList.AddRange(data[1]);
                }

                if (_fileCodeList.Count > 0)
                {
                    string fileCodes = string.Join("\r\n", _fileCodeList).Trim();
                    _insertFileCodeIntoContentTextBox($"{fileCodes}\r\n");
                    _fileCodeList.Clear();

                    ShowUnusedImage(cts);
                }
            };

            SendCommand = new DelegateCommand();
            SendCommand.ExecuteAction = async(p) =>
            {
                if (string.IsNullOrEmpty(Content))
                {
                    _sentFailded?.Invoke("请填写内容!");
                    return;
                }

                await SendService.SendEditPostAsync(cts, Title, Content, _fileAddList, _fileRemoveList, _postId, _threadId);

                _fileAddList.Clear();
                _fileRemoveList.Clear();

                Title   = string.Empty;
                Content = string.Empty;

                // 提示发贴成功
                _sentSuccess?.Invoke(Title);
            };
        }