示例#1
0
        private void OpenPage(string sitePostId, Action actionSuc, Action actionFail)
        {
            _state = WebBrowserState.Request;
            string url;

            if (string.IsNullOrEmpty(sitePostId))
            {
                _currentEditUrl      = null;
                _browser.CommandType = CommandType.OpenNew;
                url = _currentSiteInfo.PostNewUrl;
            }
            else
            {
                _currentEditUrl      = _currentSiteInfo.PostEditUrl.Replace("SitePostId", sitePostId);
                _browser.CommandType = CommandType.OpenEdit;
                url = _currentEditUrl;
            }

            NotifyStatus("正在打开页面:" + url);
            this.InvokeIfRequired(() => _browser.LoadPageAsync(url), true);
            //等待加载完成
            var resultLoad = SpinWait.SpinUntil(() => _state == WebBrowserState.LoadEnded, _timeOutTimeSpan);

            //超时未打开
            if (!resultLoad)
            {
                NotifyStatus("打开页面超时:" + url);
                actionFail();
            }
            else
            {
                _timerWait4OpenPageCompleted.Change(100, Timeout.Infinite);

                _browser.ExecuteScriptAsync("jQuery('#content-tmce').click();"); //确保为可视化界面
                _isWaiting4OpenAddOrEdit = true;
                //打开成功后执行
                _actionOpenCompleted = () =>
                {
                    NotifyStatus("打开页面成功");
                    _browser.CommandType =
                        string.IsNullOrEmpty(sitePostId) ? CommandType.Posting : CommandType.Updating;
                    actionSuc();
                };
            }
        }