Esempio n. 1
0
 public MessageBoxConfirm(IMasterDisplayWindow ownerWindow) : this()
 {
     _ownerWindow = ownerWindow;
     if (null != ownerWindow)
     {
         this.Owner = ownerWindow.GetWindow();
     }
 }
Esempio n. 2
0
 public MessageBoxTip(IMasterDisplayWindow backgroundWindow) : this()
 {
     _backgroundWindow = backgroundWindow;
     if (null != backgroundWindow)
     {
         this.Owner = backgroundWindow.GetWindow();
     }
 }
        public void Diagnostic(IMasterDisplayWindow msgOwner)
        {
            WaitingCollectLogView waitingview = new WaitingCollectLogView();
            string           appDataFolder    = Utils.GetConfigDataPath();
            LogFileCollector collector        = new LogFileCollector(appDataFolder);

            Task.Run(() => {
                collector.Collect();
                _isLogUploadSuccess = collector.UploadToOss();
                CollectLogFinished(this, waitingview);
            });

            waitingview.Owner   = msgOwner.GetWindow();
            waitingview.Topmost = true;
            waitingview.ShowDialog();

            if (!_isLogUploadSuccess)
            {
                using (CommonOpenFileDialog dialog = new CommonOpenFileDialog())
                {
                    dialog.Title            = LanguageUtil.Instance.GetValueByKey("CHOOSE_LOG_FILE_PATH");
                    dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                    dialog.IsFolderPicker   = true;
                    if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
                    {
                        try
                        {
                            collector.SaveAsTo(dialog.FileName);
                        }
                        catch (Exception ex)
                        {
                            log.ErrorFormat("Error:\n {0}", ex.Message);
                            MessageBoxTip tip1 = new MessageBoxTip(msgOwner);
                            tip1.SetTitleAndMsg(LanguageUtil.Instance.GetValueByKey("PROMPT"), string.Format("Error:\n {0}", ex.Message),
                                                LanguageUtil.Instance.GetValueByKey("CONFIRM"));
                            tip1.ShowDialog();
                            return;
                        }
                    }
                    else
                    {
                        // no save file, just exit.
                        return;
                    }
                }
            }

            MessageBoxTip tip2 = new MessageBoxTip(msgOwner);
            string        msg  = LanguageUtil.Instance.GetValueByKey("SAVE_LOG_FILE_SUCCESS");

            if (_isLogUploadSuccess)
            {
                msg = LanguageUtil.Instance.GetValueByKey("UPLOAD_LOG_FILE_SUCCESS");
            }
            tip2.SetTitleAndMsg(LanguageUtil.Instance.GetValueByKey("PROMPT"), msg,
                                LanguageUtil.Instance.GetValueByKey("CONFIRM"));
            tip2.ShowDialog();
        }
Esempio n. 4
0
 public static void SetWindowCenterAndOwner(Window window, IMasterDisplayWindow masterWindow, Window owner = null)
 {
     if (null == masterWindow)
     {
         log.Info("Master window is null and can not center window");
         return;
     }
     System.Windows.Rect masterWindowRect = masterWindow.GetWindowRect();
     window.Left = masterWindowRect.Left + (masterWindowRect.Width - window.Width) / 2;
     window.Top  = masterWindowRect.Top + (masterWindowRect.Height - window.Height) / 2;
     window.WindowStartupLocation = WindowStartupLocation.Manual;
     window.Owner = null == owner?masterWindow.GetWindow() : owner;
 }
        public PopUpHeaderSelectWindow(IMasterDisplayWindow ownerWindow)
        {
            InitializeComponent();
            //disable move this window
            this.SourceInitialized += Window_SourceInitialized;
            GetDpi();

            _ownerWindow = ownerWindow;
            this.Owner   = ownerWindow.GetWindow();

            updateImg("pack://application:,,,/Resources/Icons/uploadHeaderBackGround.jpg");
            EVSdkManager.Instance.EventUploadUserImageComplete += EVSdkWrapper_EventUploadUserImageComplete;
            EVSdkManager.Instance.EventError += EVSdkWrapper_EventError;
        }
        public void sendEmail(string email)
        {
            log.Info("sendEmail");
            if (IsFoxmailAsDefaultMail())
            {
                System.Diagnostics.Process.Start("mailto:?");
                Application.Current.Dispatcher.InvokeAsync(() =>
                {
                    const string mailtoFlag  = "mailto:?";
                    const string subjectFlag = "subject=";
                    const string bodyFlag    = "body=";
                    if (0 != email.IndexOf(mailtoFlag))
                    {
                        log.Info("mailto flag is not correct.");
                        return;
                    }

                    string mailToData    = email.Substring(mailtoFlag.Length);
                    string subject       = "";
                    string body          = "";
                    string[] toDataItems = mailToData.Split('&');
                    for (int i = 0; i < toDataItems.Length; ++i)
                    {
                        if (0 == toDataItems[i].IndexOf(subjectFlag))
                        {
                            subject = toDataItems[i].Substring(subjectFlag.Length);
                        }
                        else if (0 == toDataItems[i].IndexOf(bodyFlag))
                        {
                            body = toDataItems[i].Substring(bodyFlag.Length);
                        }
                    }
                    body = body.Replace("%0A", Environment.NewLine).Replace("%26", "&");
                    EmailClientNotSupportPrompt prompt = new EmailClientNotSupportPrompt();
                    System.Windows.Rect mainWindowRect = _masterDisplayWindow.GetWindowRect();
                    prompt.Left = mainWindowRect.Left + (mainWindowRect.Width - prompt.Width) / 2;
                    prompt.Top  = mainWindowRect.Top + (mainWindowRect.Height - prompt.Height) / 2;
                    prompt.WindowStartupLocation = WindowStartupLocation.Manual;
                    prompt.Owner = _masterDisplayWindow.GetWindow();
                    prompt.SetSubjectAndBody(subject, body);
                    prompt.ShowDialog();
                });
            }
            else
            {
                System.Diagnostics.Process.Start(email);
            }
        }
Esempio n. 7
0
        public static System.Windows.Forms.Screen SetWndOnSuitableScreen(Window window, IMasterDisplayWindow masterWindow)
        {
            log.InfoFormat("set screen for window: {0}", window.Title);
            Screen screen = GetSuitableScreen(masterWindow);

            if (screen == null)
            {
                return(null);
            }
            log.InfoFormat("target screen is {0}", screen.DeviceName);
            //IntPtr handle = new WindowInteropHelper(window).Handle;

            Screen currentScreen = DpiUtil.GetScreenByPoint((int)window.Left, (int)window.Top);

            if (screen.Equals(currentScreen))
            {
                // already in the suitable screen, do nothing.
                screen = currentScreen;
            }
            log.DebugFormat("current screen is {0}", currentScreen.DeviceName);

            System.Windows.Forms.Screen masterWindowScreen = DpiUtil.GetScreenByHandle(masterWindow.GetHandle());
            double currentRatio      = 1;
            double primaryRatio      = 1;
            uint   currentScreenDpiX = 96;
            uint   currentScreenDpiY = 96;
            uint   primaryDpiX       = 96;
            uint   primaryDpiY       = 96;

            try
            {
                DpiUtil.GetDpiByScreen(screen, out currentScreenDpiX, out currentScreenDpiY);
                currentRatio = (double)currentScreenDpiX / 96;

                DpiUtil.GetDpiByScreen(System.Windows.Forms.Screen.PrimaryScreen, out primaryDpiX, out primaryDpiY);
                primaryRatio = (double)primaryDpiX / 96;
            }
            catch (DllNotFoundException e)
            {
                log.ErrorFormat("Can not load windows dll: {0}", e);
            }


            log.DebugFormat("```````1```{0}, {1}, {2}, {3}", window.Left, window.Top, window.Width, window.Height);


            if (masterWindow.GetWindow().WindowState == WindowState.Minimized)
            {
                masterWindow.GetWindow().WindowState = WindowState.Normal;
            }

            double tempWidth  = window.Width;
            double tempHeight = window.Height;

            if (currentScreen.DeviceName.Equals(System.Windows.Forms.Screen.PrimaryScreen.DeviceName))
            {
                log.DebugFormat("currentScreen in Primary");
                window.Left = (screen.Bounds.Left / primaryRatio + (screen.Bounds.Width / primaryRatio - tempWidth) / 2);
                window.Top  = (screen.Bounds.Top / primaryRatio + (screen.Bounds.Height / primaryRatio - tempHeight) / 2);
            }
            else
            {
                log.DebugFormat("currentScreen in extend");
                window.Left = (screen.Bounds.Left * currentRatio + (screen.Bounds.Width * currentRatio - tempWidth) / 2);
                window.Top  = (screen.Bounds.Top * currentRatio + (screen.Bounds.Height * currentRatio - tempHeight) / 2);
            }

            log.Info("Set window on suitable screen end.");
            return(screen);
        }
        public void CheckSoftwareUpdate(bool showPrompt)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(Properties.Settings.Default.SoftwareUpdateAddress)
            .Append("/")
            .Append(Properties.Settings.Default.SoftwareUpdateFlag)
            .Append("/")
            .Append(Properties.Settings.Default.SoftwareUpdateBundleId)
            .Append("/");
            if (!string.IsNullOrEmpty(Properties.Settings.Default.SoftwareUpdateAppInfoPrefix))
            {
                sb.Append(Properties.Settings.Default.SoftwareUpdateAppInfoPrefix).Append(".");
            }
            sb.Append(Properties.Settings.Default.SoftwareUpdateAppInfo);
            string swUpdateUrl = sb.ToString();

            log.InfoFormat("Software update url:{0}", swUpdateUrl);
            WaitingWindow waitingWindow = null;

            if (showPrompt)
            {
                Application.Current.Dispatcher.InvokeAsync(() => {
                    waitingWindow = new WaitingWindow(LanguageUtil.Instance.GetValueByKey("CHECKING_UPDATE"));
                    IMasterDisplayWindow masterWindow = ((MainWindow)Application.Current.MainWindow).GetCurrentMainDisplayWindow();
                    if (null != masterWindow)
                    {
                        waitingWindow.Owner = masterWindow.GetWindow();
                    }
                    waitingWindow.ShowDialog();
                });
            }
            Task.Run(() => {
                RestClient restClient = new RestClient();
                RestResponse response = null;
                try
                {
                    response = restClient.GetObject(swUpdateUrl);
                    if (response.StatusCode >= HttpStatusCode.BadRequest)
                    {
                        log.InfoFormat("Failed to get app info for software update, status code: {0}", response.StatusCode);
                        if (showPrompt)
                        {
                            Application.Current.Dispatcher.InvokeAsync(() => {
                                if (null != waitingWindow)
                                {
                                    waitingWindow.Close();
                                }
                                ShowNotFoundNewVersion();
                            });
                        }

                        return;
                    }

                    Rest.SoftwareUpdateRest.AppInfoRest appInfo = JsonConvert.DeserializeObject <Rest.SoftwareUpdateRest.AppInfoRest>(response.Content);
                    log.InfoFormat("Software update info, version:{0}, url:{1}", appInfo.VERSION, appInfo.DOWNLOAD_URL);
                    string currentVersion = Utils.GetEdition();
                    log.InfoFormat("Current app version: {0}", currentVersion);
                    string[] arrAppInfo        = appInfo.VERSION.Split('.');
                    string[] arrCurrentVersion = currentVersion.Split('.');
                    int len = arrAppInfo.Length > arrCurrentVersion.Length ? arrAppInfo.Length : arrCurrentVersion.Length;
                    bool newVersionFound = false;
                    for (int i = 0; i < len; ++i)
                    {
                        int newItem     = int.Parse(arrAppInfo[i]);
                        int currentItem = int.Parse(arrCurrentVersion[i]);
                        if (newItem > currentItem)
                        {
                            newVersionFound = true;
                            break;
                        }
                        else if (newItem < currentItem)
                        {
                            break;
                        }
                    }

                    if (!newVersionFound)
                    {
                        if (showPrompt)
                        {
                            Application.Current.Dispatcher.InvokeAsync(() => {
                                if (null != waitingWindow)
                                {
                                    waitingWindow.Close();
                                }
                                ShowNotFoundNewVersion();
                            });
                        }
                        return;
                    }

                    Application.Current.Dispatcher.InvokeAsync(() => {
                        if (null != waitingWindow)
                        {
                            waitingWindow.Close();
                        }
                        SoftwareUpdateWindow.Instance.Reset(appInfo.VERSION, appInfo.DOWNLOAD_URL);
                        IMasterDisplayWindow masterWindow = ((MainWindow)Application.Current.MainWindow).GetCurrentMainDisplayWindow();
                        DisplayUtil.SetWindowCenterAndOwner(SoftwareUpdateWindow.Instance, masterWindow);
                        if (null != masterWindow)
                        {
                            log.InfoFormat("Set soft update window owner to window:{0}", masterWindow.GetHashCode());
                        }

                        SoftwareUpdateWindow.Instance.Show();
                        if (null != SoftwareUpdateWindow.Instance.Owner)
                        {
                            // set the owner active or the owner will hide when cancel the software update window.
                            SoftwareUpdateWindow.Instance.Owner.Activate();
                        }
                    });
                }
                catch (Exception ex)
                {
                    log.ErrorFormat("Failed to get app info for software update, exception:{0}", ex);
                    if (showPrompt)
                    {
                        Application.Current.Dispatcher.InvokeAsync(() => {
                            if (null != waitingWindow)
                            {
                                waitingWindow.Close();
                            }
                            ShowNotFoundNewVersion();
                        });
                    }
                }
            });
        }