Ejemplo n.º 1
0
 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();
     }
 }
Ejemplo n.º 2
0
 private void Desk_EvClosed(object sender, ChatDeskEventArgs e)
 {
     DispatcherEx.xInvoke(() =>
     {
         Close();
     });
 }
Ejemplo n.º 3
0
        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;
                });
            }
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
 private void Desk_EvHide(object sender, ChatDeskEventArgs e)
 {
     DispatcherEx.xInvoke(() =>
     {
         Hide();
         Sleep();
     });
 }
Ejemplo n.º 6
0
 public DelayCaller(Action act, int delayMs, bool useUIThread)
 {
     _act = (useUIThread ? new Action(() =>
     {
         DispatcherEx.xInvoke(act);
     }) : act);
     _delayMs = delayMs;
 }
Ejemplo n.º 7
0
 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();
     });
 }
Ejemplo n.º 8
0
 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;
     });
 }
Ejemplo n.º 9
0
 private void Desk_EvShow(object sender, ChatDeskEventArgs e)
 {
     DispatcherEx.xInvoke(() =>
     {
         if (!Desk.IsMinimized && Desk.IsVisible && base.Visibility > Visibility.Visible)
         {
             ShowAssist();
         }
     });
 }
Ejemplo n.º 10
0
 private static void MaybeInUiThread(Action act, bool useUiThread)
 {
     if (useUiThread)
     {
         DispatcherEx.xInvoke(act);
     }
     else if (act != null)
     {
         act();
     }
 }
Ejemplo n.º 11
0
 private void WakeUpAssist()
 {
     if (!IsWakeUp)
     {
         IsWakeUp = true;
         DispatcherEx.xInvoke(() =>
         {
             ctlRightPanel.WakeUp();
             ctlBottomPanel.WakeUp();
         });
     }
 }
Ejemplo n.º 12
0
 private void Sleep()
 {
     if (IsWakeUp)
     {
         IsWakeUp = false;
         DispatcherEx.xInvoke(() =>
         {
             ctlRightPanel.Sleep();
             ctlBottomPanel.Sleep();
         });
     }
 }
Ejemplo n.º 13
0
 private void Desk_EvGetForeground(object sender, ChatDeskEventArgs e)
 {
     DispatcherEx.xInvoke(() =>
     {
         ShowAssist();
         DelayCaller foregroundTrackDelayCaller = _foregroundTrackDelayCaller;
         if (foregroundTrackDelayCaller != null)
         {
             foregroundTrackDelayCaller.CallAfterDelay();
         }
     });
 }
Ejemplo n.º 14
0
        public void RemoveItem(string nick)
        {
            var idx = this.GetFirstLevelItemIndexByTagText(nick);

            if (idx >= 0)
            {
                DispatcherEx.xInvoke(() =>
                {
                    this.NotifyIconInner.ContextMenuStrip.Items.RemoveAt(idx);
                });
            }
        }
Ejemplo n.º 15
0
 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可试着再同步一次");
     }
 }
Ejemplo n.º 16
0
        public static void Reboot()
        {
            var fn = PathEx.ParentOfExePath + "Booter.exe";

            Process.Start(fn, "reboot");
            DispatcherEx.xInvoke(() =>
            {
                if (Application.Current != null)
                {
                    Application.Current.Shutdown();
                }
            });
        }
Ejemplo n.º 17
0
 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);
 }
Ejemplo n.º 18
0
 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();
         });
     });
 }
Ejemplo n.º 19
0
        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;
            }
        }
Ejemplo n.º 20
0
 private void Desk_EvMinimize(object sender, ChatDeskEventArgs e)
 {
     DispatcherEx.xInvoke(() =>
     {
         try
         {
             Hide();
             Sleep();
         }
         catch (Exception ex)
         {
             Log.Exception(ex);
         }
     });
 }
Ejemplo n.º 21
0
            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);
            }
Ejemplo n.º 22
0
 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);
         });
     });
 }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
 public static void UpdateAllBuyerNote()
 {
     try
     {
         DispatcherEx.xInvoke(() =>
         {
             foreach (var wndAssist in WndAssist.AssistBag)
             {
                 wndAssist.ctlBottomPanel.ctlMemo.LoadBuyerNote();
             }
         });
     }
     catch (Exception e)
     {
         Log.Exception(e);
     }
 }
Ejemplo n.º 25
0
 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);
     }
 }
Ejemplo n.º 26
0
        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);
        }
Ejemplo n.º 27
0
 public static void UseClipboardWithAutoRestoreInUiThread(Action act)
 {
     if (act != null)
     {
         lock (_synobj)
         {
             DispatcherEx.xInvoke(() =>
             {
                 var dict = Backup(false);
                 if (act != null)
                 {
                     act();
                 }
                 Restore(dict, false);
             });
         }
     }
 }
Ejemplo n.º 28
0
        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);
        }
Ejemplo n.º 29
0
 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);
         });
     }
 }
Ejemplo n.º 30
0
 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);
         }
     });
 }