private static void DoInject(string injectJs, int chromeDevHwnd, ChatDesk desk, Func <bool> isConnectOk) { for (int i = 0; i < 4; i++) { WinApi.BringTopAndDoAction(chromeDevHwnd, () => { DispatcherEx.xInvoke(() => { WinApi.PressEsc(); }); }, 2); if (i == 0) { Thread.Sleep(4000); } else { Thread.Sleep(4000); } ExcuteJsInner(injectJs, chromeDevHwnd); Thread.Sleep(100); if (isConnectOk()) { break; } } if (desk.IsForeground) { desk.BringTop(); } }
private void Desk_EvClosed(object sender, ChatDeskEventArgs e) { DispatcherEx.xInvoke(() => { Close(); }); }
public void WakeUp() { //this.Wnd.Desk.EvChromeConnected -= Desk_EvChromeConnected; //this.Wnd.Desk.EvChromeDetached -= Desk_EvChromeDetached; //this.Wnd.Desk.ChatRecord.EvChatRecordChanged -= ChatRecord_EvChatRecordChanged; //this.Wnd.Desk.EvChromeConnected += Desk_EvChromeConnected; //this.Wnd.Desk.EvChromeDetached += Desk_EvChromeDetached; //this.Wnd.Desk.ChatRecord.EvChatRecordChanged += ChatRecord_EvChatRecordChanged; this.Wnd.Desk.EvBuyerChanged -= Desk_EvBuyerChanged; this.Wnd.Desk.EvBuyerChanged += Desk_EvBuyerChanged; if (this.Wnd.Desk.IsChatRecordChromeOk) { DispatcherEx.xInvoke(() => { this.ctlBuyer.ShowBuyer(this.Wnd.Desk.Buyer); }); } //if (this._chatRecordBeforeDetach != this.Wnd.Desk.ChatRecord.CachedHtml) //{ // this.OnChatRecordChanged(); //} if (this._buyerBeforeDetach != this.Wnd.Desk.Buyer) { DispatcherEx.xInvoke(() => { this.ctlBuyer.ShowBuyer(this.Wnd.Desk.Buyer); this.ctlMemo.LoadBuyerNote(this.Wnd.Desk.BuyerMainNick, this.Wnd.Desk.Seller); this._preBuyer = this.Wnd.Desk.Buyer; }); } }
private bool SendPlainImage(BitmapImage img) { bool isok = false; DispatcherEx.xInvoke(() => { HwndInfo hwndInfo = this.GetActivedEditorHwnd(); if (hwndInfo.Handle > 0) { this.FocusEditor(true); WinApi.Editor.MoveCaretToEnding(hwndInfo); var dict = ClipboardEx.Backup(); Clipboard.Clear(); Clipboard.SetImage(img); string text = this.GetPlainTextUnCached(); WinApi.PressCtrlV(); DateTime now = DateTime.Now; while ((DateTime.Now - now).TotalSeconds < 2.0) { string newText = this.GetPlainTextUnCached(); if (newText != text) { isok = true; } DispatcherEx.DoEvents(); } Util.WriteTimeElapsed(now, "等待时间"); ClipboardEx.Restore(dict); return; } }); return(isok); }
private void Desk_EvHide(object sender, ChatDeskEventArgs e) { DispatcherEx.xInvoke(() => { Hide(); Sleep(); }); }
public DelayCaller(Action act, int delayMs, bool useUIThread) { _act = (useUIThread ? new Action(() => { DispatcherEx.xInvoke(act); }) : act); _delayMs = delayMs; }
private static void ShowTip(string message, string title, Window owner, bool showCancelButton, Action <bool> callback, bool startUpCenterOwner = false) { DispatcherEx.xInvoke(() => { var wnd = new WndMsgBox(message, title, showCancelButton, callback); wnd.xSetOwner(owner); wnd.xSetStartUpLocation(startUpCenterOwner); wnd.xShowFirstTime(); }); }
void Desk_EvBuyerChanged(object sender, Automation.ChatDeskNs.BuyerChangedEventArgs e) { DispatcherEx.xInvoke(() => { this.ctlBuyer.ShowBuyer(this.Wnd.Desk.Buyer); this.ctlMemo.LoadBuyerNote(this.Wnd.Desk.BuyerMainNick, this.Wnd.Desk.Seller); this._preBuyer = this.Wnd.Desk.Buyer; }); }
private void Desk_EvShow(object sender, ChatDeskEventArgs e) { DispatcherEx.xInvoke(() => { if (!Desk.IsMinimized && Desk.IsVisible && base.Visibility > Visibility.Visible) { ShowAssist(); } }); }
private static void MaybeInUiThread(Action act, bool useUiThread) { if (useUiThread) { DispatcherEx.xInvoke(act); } else if (act != null) { act(); } }
private void WakeUpAssist() { if (!IsWakeUp) { IsWakeUp = true; DispatcherEx.xInvoke(() => { ctlRightPanel.WakeUp(); ctlBottomPanel.WakeUp(); }); } }
private void Sleep() { if (IsWakeUp) { IsWakeUp = false; DispatcherEx.xInvoke(() => { ctlRightPanel.Sleep(); ctlBottomPanel.Sleep(); }); } }
private void Desk_EvGetForeground(object sender, ChatDeskEventArgs e) { DispatcherEx.xInvoke(() => { ShowAssist(); DelayCaller foregroundTrackDelayCaller = _foregroundTrackDelayCaller; if (foregroundTrackDelayCaller != null) { foregroundTrackDelayCaller.CallAfterDelay(); } }); }
public void RemoveItem(string nick) { var idx = this.GetFirstLevelItemIndexByTagText(nick); if (idx >= 0) { DispatcherEx.xInvoke(() => { this.NotifyIconInner.ContextMenuStrip.Items.RemoveAt(idx); }); } }
private void DbSyner_EvSynFinished(object sender, DbSyner.SynFinishedEventArgs e) { DbSyner.EvSynFinished -= this.DbSyner_EvSynFinished; DispatcherEx.xInvoke(() => this.btnSyn.IsEnabled = true); if (e.IsOk) { MsgBox.ShowTip("数据同步完成", "提示"); } else { MsgBox.ShowErrDialog("数据同步失败,原因是:" + e.Error + "\r\n\r\n可试着再同步一次"); } }
public static void Reboot() { var fn = PathEx.ParentOfExePath + "Booter.exe"; Process.Start(fn, "reboot"); DispatcherEx.xInvoke(() => { if (Application.Current != null) { Application.Current.Shutdown(); } }); }
private void Desk_EvMaximize(object sender, ChatDeskEventArgs e) { Desk.ShowNormal(); DispatcherEx.xInvoke(() => { XYRatio toLogicalRatio = ToLogicalRatio; double maxW = SystemParameters.WorkArea.Width - (double)WaParams.GetRightPanelWidth(Desk.Seller) - (double)12f; int w = (int)(maxW / toLogicalRatio.XRatio); double maxH = SystemParameters.WorkArea.Height - (double)WaParams.GetBottomPanelHeight(Desk.Seller) - (double)12f; int h = (int)(maxH / toLogicalRatio.YRatio); Desk.SetRect(6, 6, w, h); }); Track(false, false); }
private void mImport_Click(object sender, RoutedEventArgs e) { WndShortcutImporter.MyShow(this._seller, this.xFindParentWindow(), () => { ShowTip("正在导入话术"); this.spTip.Visibility = Visibility.Visible; this.grdMain.IsEnabled = false; }, () => { DispatcherEx.xInvoke(() => { this.LoadDatas(null, null); this.HideTip(); }); }); }
private void Track(bool adjustDeskLocation = false, bool isLoopTrack = false) { if (!_isTracking && !IsClosed) { _isTracking = true; DispatcherEx.xInvoke(() => { try { if (!IsLoaded || IsHidden()) { Hide(); } else { if (!IsVisible && Desk.GetVisiblePercent(true) > 0.0) { Show(); } if (IsVisible) { SetPanelsSize(); if (_isFirstTrack | adjustDeskLocation) { _isFirstTrack = false; SetDeskLocation(); } SetRightPanelPosition(); SetBottomPanelPosition(); if (!isLoopTrack && Desk.IsMostlyVisible(true)) { BringTop(); } if (isLoopTrack) { BringWndAssitOfTopDeskTopMostIfNeed(); } } } } catch (Exception ex) { Log.Exception(ex); } }); _isTracking = false; } }
private void Desk_EvMinimize(object sender, ChatDeskEventArgs e) { DispatcherEx.xInvoke(() => { try { Hide(); Sleep(); } catch (Exception ex) { Log.Exception(ex); } }); }
public static bool RegisterHotKey(Window f, Keys key, int keyid) { var isok = false; DispatcherEx.xInvoke(() => { isok = RegisterHotKey(f.xHandle(), keyid, 0, (int)key); if (!isok) { var isInvalid = false; var lastErr = WinApi.GetLastError(out isInvalid); Log.Error(string.Format("RegisterHotKey失败,keyid={0},GetLastError={1},,isInvalid={2}", keyid, lastErr, isInvalid)); } }); return(isok); }
private static void ExcuteJsInner(string injectJs, int chromeDevHwnd) { ClipboardEx.UseClipboardWithAutoRestore(() => { DispatcherEx.xInvoke(() => { ClipboardEx.SetTextSafe(injectJs); WinApi.BringTopAndDoAction(chromeDevHwnd, () => { WinApi.PressCtrlV(); Thread.Sleep(500); WinApi.PressEnterKey(); }, 4); }); }); }
public static bool MyShowDialog(List <Inline> message, string title, string showkey, Window owner = null, bool startUpCenterOwner = true, string okButtonText = null) { var isok = true; DispatcherEx.xInvoke(() => { if (LocalParams.GetWndNotTipAgainNeedShow(showkey)) { var wnd = new WndNotTipAgain(message, title, showkey, okButtonText); wnd.xSetOwner(owner); wnd.xSetStartUpLocation(startUpCenterOwner); var dlgRlt = wnd.ShowDialog(); isok = dlgRlt.HasValue && dlgRlt.Value; } }); return(isok); }
public static void UpdateAllBuyerNote() { try { DispatcherEx.xInvoke(() => { foreach (var wndAssist in WndAssist.AssistBag) { wndAssist.ctlBottomPanel.ctlMemo.LoadBuyerNote(); } }); } catch (Exception e) { Log.Exception(e); } }
protected override void CleanUp_UnManaged_Resources() { try { DispatcherEx.xInvoke(() => { foreach (int int_ in this._instHookHandles) { WinApiLocal.UnhookWinEvent(int_); } this._instHookHandles.Clear(); }); } catch (Exception e) { Log.Exception(e); } }
public static string MyShowDialog(string tip, string title, string inputDef = null, string helpurl = null, Func <string, string> validator = null, Window owner = null, bool startUpCenterOwner = false) { var txt = string.Empty; DispatcherEx.xInvoke(() => { var editor = new WndInput(tip, title, inputDef, helpurl, validator); editor.Owner = owner; WindowEx.xSetStartUpLocation(editor, startUpCenterOwner); var dlgRlt = editor.ShowDialogEx(owner); if (dlgRlt.HasValue && dlgRlt.Value) { txt = editor.Result; } }); return(txt); }
public static void UseClipboardWithAutoRestoreInUiThread(Action act) { if (act != null) { lock (_synobj) { DispatcherEx.xInvoke(() => { var dict = Backup(false); if (act != null) { act(); } Restore(dict, false); }); } } }
public bool FocusEditor(bool focusEditor) { bool isok = false; DispatcherEx.xInvoke(() => { if (focusEditor) { this._desk.BringTop(); } HwndInfo hwndInfo = this.GetActivedEditorHwnd(); if (hwndInfo.Handle > 0) { isok = WinApi.SetFocus(hwndInfo); } }); return(isok); }
public static void UseClipboardWithAutoRestore(Action act) { if (act != null) { Dictionary <string, object> bp = null; DispatcherEx.xInvoke(() => { bp = Backup(false); }); if (act != null) { act(); } DispatcherEx.xInvoke(() => { Restore(bp, false); }); } }
public void UpdateShortcutUI() { DispatcherEx.xInvoke(() => { try { TabItem tabItem = GetTabItem(TabTypeEnum.ShortCut); CtlShortcut ctlShortcut = ((tabItem != null) ? tabItem.Content : null) as CtlShortcut; if (ctlShortcut != null) { ctlShortcut.SetTitleButtonsVisible(); ctlShortcut.SetContentVisible(); ctlShortcut.LoadDatas(null, null); } } catch (Exception e) { Log.Exception(e); } }); }