private void DecompileThread()
 {
     onStartTask?.BeginInvoke(null, null);
     TaskResult = GCompWrapper.Decompile(ref Params);
     if (frm.Visible)
     {
         frm.BeginInvoke(new MethodInvoker(delegate { frm.Hide(); }));
     }
     onFinishDecompile?.BeginInvoke(null, null);
 }
        public async Task <ConfigData?> LoadDatabaseAsync(Control window, string languageName, bool forceReload = false)
        {
            using var progressDlg = new ProgressForm();
            try
            {
                if (!forceReload && IsDatabaseAlreadyLoaded(languageName))
                {
                    return(_configDataLoader.BuildData(languageName));
                }
                progressDlg.BindAdapter(new CheckForUpdateDialogAdapter());
                progressDlg.Show(window);
                await _configDataLoader.LoadDatabaseAsync(progressDlg.CancelToken, forceReload);

                progressDlg.CurrentTaskProgress = 0.5f;
                if (_configDataLoader.DatabaseLoaded)
                {
                    await LoadDatabaseLanguageAsync(languageName, progressDlg.CancelToken, forceReload);

                    progressDlg.CurrentTaskProgress = 0.9f;
                    return(_configDataLoader.BuildData(languageName));
                }
                else
                {
                    _logger.Error("Failed parse settings database");
                    MessageBox.Show(window, Resources.GameSettings_FailedParseDb_Text,
                                    Resources.Localization_Error_Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception e)
            {
                if (!progressDlg.IsCanceledByUser)
                {
                    _logger.Error(e, "Error load settings database");
                    MessageBox.Show(window, Resources.GameSettings_FailedLoadDb_Text,
                                    Resources.Localization_Error_Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            finally
            {
                progressDlg.Hide();
            }
            if (forceReload && _configDataLoader.DatabaseLoaded)
            {
                try
                {
                    return(_configDataLoader.BuildData(languageName));
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Error build database data");
                }
            }
            return(null);
        }
Exemple #3
0
 static void _worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     if (!e.Cancelled)
     {
         ProcessResult = e.Result;
     }
     else
     {
         ProcessResult = null;
     }
     _progressForm.Hide();
 }
Exemple #4
0
 void agentServer_Disconnected(object sender, EventArgs e)
 {
     if (isInteractive)
     {
         recorder.Stop();
         toolWindow.Invoke((MethodInvoker) delegate
         {
             toolWindow.Hide();
         });
         tracker.Stop();
     }
     else
     {
         ProgressForm.Hide();
     }
 }
        public static void ReportFullPageScreenshot(RepoItemInfo repoItemInfo)
        {
            ProgressForm.Hide();

            try
            {
                Utils.CheckArgumentNotNull(repoItemInfo, "repoItemInfo");

                var webDocument = repoItemInfo.CreateAdapter <WebDocument>(false);

                if (webDocument == null)
                {
                    Report.Error("Repository item '" + repoItemInfo.FullName + "' is not a web document. " +
                                 "Screenshot can be taken only for web documents.");
                    return;
                }

                var screenshotFilePath = Path.GetTempFileName();

                var screenshot = webDocument.CaptureFullPageScreenshot();
                screenshot.Save(screenshotFilePath);

                Report.LogData(ReportLevel.Info, "Screenshot", screenshot);

                if (File.Exists(screenshotFilePath))
                {
                    try
                    {
                        File.Delete(screenshotFilePath);
                    }
                    catch
                    {
                        // No need to handle exception.
                        // Temp files are deleted only to prevent piling up of unnecessary files.
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.ReportException(ex, libraryName);
            }

            ProgressForm.Show();
        }
Exemple #6
0
        public async Task <bool> RefreshVersionsAsync(Control window)
        {
            _logger.Info($"Refresh localization versions: {CurrentRepository.RepositoryUrl}");
            bool status = false;

            using var progressDlg = new ProgressForm(30000);
            try
            {
                window.Enabled             = false;
                Cursor.Current             = Cursors.WaitCursor;
                progressDlg.Text           = Resources.Localization_RefreshAvailableVersion_Title;
                progressDlg.UserCancelText = Resources.Localization_Stop_Text;
                progressDlg.Show(window);
                await CurrentRepository.RefreshUpdatesAsync(progressDlg.CancelToken);

                progressDlg.CurrentTaskProgress = 1.0f;
                status = true;
            }
            catch (Exception e)
            {
                if (!progressDlg.IsCanceledByUser)
                {
                    _logger.Error(e, "Error during refresh localization versions");
                    if (e is HttpRequestException)
                    {
                        MessageBox.Show(window, Resources.Localization_Download_ErrorText + '\n' + e.Message,
                                        Resources.Localization_Download_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(window, Resources.Localization_Download_ErrorText,
                                        Resources.Localization_Download_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
                window.Enabled = true;
                progressDlg.Hide();
            }
            return(status);
        }
Exemple #7
0
        void DoReportProgress()
        {
            switch (FCaptureState)
            {
            case CaptureState.Idle:
                FProgressBar.Invoke((MethodInvoker) delegate { FProgressBar.Hide(); });
                return;

            case CaptureState.Capturing:
            {
                if (!FProgressBar.Visible)
                {
                    RECT windowRect;
                    User32.GetWindowRect(FHandle, out windowRect);
                    FProgressLabel.BackColor = Color.LightGreen;

                    FProgressBar.Show();

                    var subX = FSubrect.HasValue ? FSubrect.Value.X : 0;
                    var subY = FSubrect.HasValue ? FSubrect.Value.Y + FSubrect.Value.Height : 0;
                    FProgressBar.SetDesktopLocation(windowRect.Left + subX, windowRect.Top + subY + 30);
                }

                FProgressLabel.Text = "Frame Count: " + FFrames.Count.ToString();
                break;
            }

            case CaptureState.Writing:
            {
                FProgressBar.Invoke((MethodInvoker) delegate { FProgressBar.Show(); });
                FProgressLabel.Invoke((MethodInvoker) delegate
                    {
                        FProgressLabel.Text      = FFrames.Count.ToString() + " frames. Writing File: " + FSaveFilePath;
                        FProgressLabel.BackColor = Color.LightSalmon;
                    });

                break;
            }
            }

            FProgressBar.Invoke((MethodInvoker) delegate { FProgressBar.ClientSize = new Size(FProgressLabel.Size.Width, FProgressLabel.Size.Height); });
        }
Exemple #8
0
        public bool Uninstall(Control window)
        {
            if (CurrentInstallation.InstalledVersion != null)
            {
                if (!CurrentGame.IsAvailable())
                {
                    _logger.Error($"Uninstall localization mode path unavailable: {CurrentGame.RootFolderPath}");
                    MessageBox.Show(window, Resources.Localization_Uninstall_ErrorText,
                                    Resources.Localization_Uninstall_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
                var dialogResult = MessageBox.Show(window, Resources.Localization_Uninstall_QuestionText,
                                                   Resources.Localization_Uninstall_QuestionTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialogResult == DialogResult.No)
                {
                    return(false);
                }
                _logger.Info($"Uninstall localization: {CurrentGame.Mode}, {CurrentInstallation.Repository} {CurrentInstallation.InstalledVersion}");
                bool status = false;
                using var progressDlg = new ProgressForm();
                try
                {
                    progressDlg.BindAdapter(new UninstallProgressDialogAdapter());
                    progressDlg.Show(window);
                    using var gameMutex = new GameMutex();
                    if (!GameMutexController.AcquireWithRetryDialog(progressDlg, gameMutex))
                    {
                        _logger.Info($"Uninstall localization aborted by user because game running");
                        return(false);
                    }
                    switch (CurrentRepository.Installer.Uninstall(CurrentGame.RootFolderPath))
                    {
                    case UninstallStatus.Success:
                        GameSettings.RemoveCurrentLanguage();
                        GameSettings.Load();
                        gameMutex.Release();
                        progressDlg.CurrentTaskProgress = 1.0f;
                        RepositoryManager.RemoveInstalledRepository(CurrentRepository);
                        status = true;
                        break;

                    case UninstallStatus.Partial:
                        GameSettings.RemoveCurrentLanguage();
                        GameSettings.Load();
                        gameMutex.Release();
                        progressDlg.CurrentTaskProgress = 1.0f;
                        RepositoryManager.RemoveInstalledRepository(CurrentRepository);
                        status = true;
                        _logger.Warn($"Localization uninstalled partially: {CurrentGame.Mode}");
                        MessageBox.Show(progressDlg, Resources.Localization_Uninstall_WarningText,
                                        Resources.Localization_Uninstall_WarningTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        break;

                    default:
                        gameMutex.Release();
                        _logger.Error($"Failed uninstall localization: {CurrentGame.Mode}");
                        MessageBox.Show(progressDlg, Resources.Localization_Uninstall_ErrorText,
                                        Resources.Localization_Uninstall_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        break;
                    }
                }
                catch (Exception e)
                {
                    _logger.Error(e, $"Error during uninstall localization: {CurrentGame.Mode}");
                    MessageBox.Show(window, Resources.Localization_Uninstall_ErrorText,
                                    Resources.Localization_Uninstall_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    progressDlg.Hide();
                }
                return(status);
            }
            return(true);
        }
Exemple #9
0
        public async Task <bool> InstallVersionAsync(Control window, UpdateInfo selectedUpdateInfo)
        {
            if (!CurrentGame.IsAvailable())
            {
                _logger.Error($"Install localization mode path unavailable: {CurrentGame.RootFolderPath}");
                MessageBox.Show(window, Resources.Localization_File_ErrorText,
                                Resources.Localization_File_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (!Program.Settings.AcceptInstallWarning)
            {
                var dialogResult = MessageBox.Show(window, Resources.Localization_InstallWarning_Text,
                                                   Resources.Localization_InstallWarning_Title, MessageBoxButtons.YesNo,
                                                   MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                if (dialogResult != DialogResult.Yes)
                {
                    return(false);
                }
                Program.Settings.AcceptInstallWarning = true;
                Program.SaveAppSettings();
            }
            _logger.Info($"Install localization: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
            bool          status          = false;
            DirectoryInfo?downloadDirInfo = null;

            using var progressDlg = new ProgressForm();
            try
            {
                window.Enabled = false;
                Cursor.Current = Cursors.WaitCursor;
                var downloadDialogAdapter = new DownloadProgressDialogAdapter(selectedUpdateInfo.GetVersion());
                progressDlg.BindAdapter(downloadDialogAdapter);
                progressDlg.Show(window);
                downloadDirInfo = Directory.CreateDirectory(Path.Combine(CurrentGame.RootFolderPath, "download_" + Path.GetRandomFileName()));
                var packageIndex   = new LocalizationPackageIndex(CurrentGame.RootFolderPath);
                var downloadResult = await CurrentRepository.DownloadAsync(selectedUpdateInfo, downloadDirInfo.FullName, packageIndex,
                                                                           progressDlg.CancelToken, downloadDialogAdapter);

                progressDlg.BindAdapter(new InstallProgressDialogAdapter());
                using var gameMutex = new GameMutex();
                if (!GameMutexController.AcquireWithRetryDialog(progressDlg, gameMutex))
                {
                    _logger.Info($"Install localization aborted by user because game running");
                    return(false);
                }
                var installStatus = downloadResult switch
                {
                    FullDownoadResult fullResult => CurrentRepository.Installer.Install(fullResult.ArchiveFilePath, CurrentGame.RootFolderPath),
                    IncrementalDownloadResult incrementalResult => CurrentRepository.Installer.Install(incrementalResult.DownloadPath, CurrentGame.RootFolderPath, incrementalResult.DiffList),
                    _ => throw new InvalidOperationException("Download result is empty")
                };
                switch (installStatus)
                {
                case InstallStatus.Success:
                    if (selectedUpdateInfo is GitHubUpdateInfo githubUpateInfo)
                    {
                        CurrentRepository.Installer.WriteTimestamp(githubUpateInfo.Released, CurrentGame.RootFolderPath);
                    }
                    GameSettings.Load();
                    gameMutex.Release();
                    progressDlg.CurrentTaskProgress = 1.0f;
                    RepositoryManager.SetInstalledRepository(CurrentRepository, selectedUpdateInfo.GetVersion());
                    status = true;
                    break;

                case InstallStatus.PackageError:
                    gameMutex.Release();
                    _logger.Error($"Failed install localization due to package error: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    MessageBox.Show(progressDlg, Resources.Localization_Package_ErrorText,
                                    Resources.Localization_Package_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;

                case InstallStatus.VerifyError:
                    gameMutex.Release();
                    _logger.Error($"Failed install localization due to core verify error: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    MessageBox.Show(progressDlg, Resources.Localization_Verify_ErrorText,
                                    Resources.Localization_Verify_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;

                case InstallStatus.FileError:
                    gameMutex.Release();
                    _logger.Error($"Failed install localization due to file error: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    MessageBox.Show(progressDlg, Resources.Localization_File_ErrorText,
                                    Resources.Localization_File_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;

                default:
                    gameMutex.Release();
                    _logger.Error($"Failed install localization: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    MessageBox.Show(progressDlg, Resources.Localization_Install_ErrorText,
                                    Resources.Localization_Install_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }
            }
            catch (Exception e)
            {
                if (!progressDlg.IsCanceledByUser)
                {
                    _logger.Error(e, $"Error during install localization: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    if (e is HttpRequestException)
                    {
                        MessageBox.Show(window, Resources.Localization_Download_ErrorText + '\n' + e.Message,
                                        Resources.Localization_Download_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(window, Resources.Localization_Download_ErrorText,
                                        Resources.Localization_Download_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
                window.Enabled = true;
                progressDlg.Hide();
                if (downloadDirInfo != null && selectedUpdateInfo is GitHubUpdateInfo)
                {
                    if (downloadDirInfo.Exists && !FileUtils.DeleteDirectoryNoThrow(downloadDirInfo, true))
                    {
                        _logger.Warn($"Failed remove download directory: {downloadDirInfo.FullName}");
                    }
                }
            }
            return(status);
        }
Exemple #10
0
 /// <summary>
 /// 隐藏进度
 /// </summary>
 public void Hide()
 {
     progress.Hide();
 }
        public async Task <bool> InstallVersionAsync(Control window, UpdateInfo selectedUpdateInfo)
        {
            if (!CurrentGame.IsAvailable())
            {
                _logger.Error($"Install localization mode path unavailable: {CurrentGame.RootFolderPath}");
                MessageBox.Show(window, Resources.Localization_File_ErrorText,
                                Resources.Localization_File_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (!Program.Settings.AcceptInstallWarning)
            {
                var dialogResult = MessageBox.Show(window, Resources.Localization_InstallWarning_Text,
                                                   Resources.Localization_InstallWarning_Title, MessageBoxButtons.YesNo,
                                                   MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                if (dialogResult != DialogResult.Yes)
                {
                    return(false);
                }
                Program.Settings.AcceptInstallWarning = true;
                Program.SaveAppSettings();
            }
            _logger.Info($"Install localization: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
            bool status = false;

            using var progressDlg = new ProgressForm();
            try
            {
                window.Enabled = false;
                Cursor.Current = Cursors.WaitCursor;
                var downloadDialogAdapter = new DownloadProgressDialogAdapter(selectedUpdateInfo.GetVersion());
                progressDlg.BindAdapter(downloadDialogAdapter);
                progressDlg.Show(window);
                var filePath = await CurrentRepository.DownloadAsync(selectedUpdateInfo, Path.GetTempPath(),
                                                                     progressDlg.CancelToken, downloadDialogAdapter);

                progressDlg.BindAdapter(new InstallProgressDialogAdapter());
                var result = CurrentRepository.Installer.Install(filePath, CurrentGame.RootFolderPath);
                switch (result)
                {
                case InstallStatus.Success:
                    GameSettings.Load();
                    progressDlg.CurrentTaskProgress = 1.0f;
                    RepositoryManager.SetInstalledRepository(CurrentRepository, selectedUpdateInfo.GetVersion());
                    status = true;
                    break;

                case InstallStatus.PackageError:
                    _logger.Error($"Failed install localization due to package error: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    MessageBox.Show(progressDlg, Resources.Localization_Package_ErrorText,
                                    Resources.Localization_Package_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;

                case InstallStatus.VerifyError:
                    _logger.Error($"Failed install localization due to core verify error: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    MessageBox.Show(progressDlg, Resources.Localization_Verify_ErrorText,
                                    Resources.Localization_Verify_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;

                case InstallStatus.FileError:
                    _logger.Error($"Failed install localization due to file error: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    MessageBox.Show(progressDlg, Resources.Localization_File_ErrorText,
                                    Resources.Localization_File_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;

                default:
                    _logger.Error($"Failed install localization: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    MessageBox.Show(progressDlg, Resources.Localization_Install_ErrorText,
                                    Resources.Localization_Install_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }
            }
            catch (Exception e)
            {
                if (!progressDlg.IsCanceledByUser)
                {
                    _logger.Error(e, $"Error during install localization: {CurrentGame.Mode}, {selectedUpdateInfo.Dump()}");
                    if (e is HttpRequestException)
                    {
                        MessageBox.Show(window, Resources.Localization_Download_ErrorText + '\n' + e.Message,
                                        Resources.Localization_Download_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(window, Resources.Localization_Download_ErrorText,
                                        Resources.Localization_Download_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
                window.Enabled = true;
                progressDlg.Hide();
            }
            return(status);
        }
Exemple #12
0
		public void ConvertBitmapTo8Bpp(int correction)
		{
			//  this method is the only one that sometimes needs a long time;
			//  therefore Juergen Thomas added a progress form as standard,
			//  but shows it only for larger bitmaps
			using(ProgressForm progress = new ProgressForm(ctrl)) {
				if (bmp.Width * bmp.Height >= 40000)
					progress.Show();
				//  variables used instead of timer
				DateTime now;
				TimeSpan diff;

				Bitmap Result = new Bitmap( bmp.Width, bmp.Height,
					PixelFormat.Format8bppIndexed );

				BitmapData ResultData
					= Result.LockBits(
						new Rectangle(0, 0, bmp.Width, bmp.Height),
						ImageLockMode.ReadWrite,
						PixelFormat.Format8bppIndexed);

				int tmpStride = ResultData.Stride;
				IntPtr ptr = ResultData.Scan0;

				Hashtable ColorReduction = new Hashtable();
				byte offset = 39;
				for (int r = 0; r < 256; r += 51)
					for (int g = 0; g < 256; g += 51)
						for (int b = 0; b < 256; b += 51)
						{
							ColorReduction[Color.FromArgb(r, b, g)] = ++offset;
						}

				int tmpBytes = bmp.Height * tmpStride;
				byte[] tmpBitmapData = new byte[tmpBytes];

				now = DateTime.Now;
				for (int x = 0; x < bmp.Width; x++)
				{
					//  check if progress should be actualized (after 600 msec)
					diff = DateTime.Now - now;
					if (progress.Visible && (diff.Ticks > 6000000)) {
						progress.Progressing(x);
						now = DateTime.Now;
					}

					for (int y = 0; y < bmp.Height; y++)
					{
						int offset2 = (y * tmpStride) + x;
						//  get a suitable 8 bit color to the current 24 bit pixel
						Color col = ConvertColorTo8Bpp(bmp.GetPixel(x,y), correction);
						//  set this color as color resp. grayscale
						if (format8bitPixel == ColorDepthReduction.Colored8bpp)
							tmpBitmapData[offset2]
								= (byte)( col.R*0.3 + col.G*0.59 + col.B*0.11 );
						else
							tmpBitmapData[offset2]
								= (byte)ColorReduction[col];
					}
				}

				System.Runtime.InteropServices.Marshal.Copy(tmpBitmapData, 0, ptr, tmpBytes);

				Result.UnlockBits(ResultData);

				progress.Hide();

				//  change the formprint bitmap
				bmp.Dispose();
				bmp = Result;
			}
		}
Exemple #13
0
 private void HideProgressForm()
 {
     ProgressForm.Hide();
 }
Exemple #14
0
        void agentServer_OnCommand(Command command)
        {
            RanorexStepExecutionResponse stepResponse = null;

            if (command.command == "invoke")
            {
                if (!reportSetupDone)
                {
                    TestReport.Setup(Report.CurrentReportLevel, null, true, TestReport.EnableTracingScreenshots, 0, null);
                    reportSetupDone = true;
                }

                if (showExecutionUI)
                {
                    ProgressForm.Show();
                }
                else
                {
                    ProgressForm.Hide();
                }

                Dictionary <string, object> arguments = command.arguments;
                Hashtable props = (Hashtable)arguments["props"];

                if (sessionType == "Mobile")
                {
                    string target = (string)command.arguments["target"];
                    if (target.StartsWith("/mobileapp/"))
                    {
                        target.Replace("/mobileapp", "/mobileapp[@devicename'" + mobileDevice + "']");
                    }
                }

                foreach (DictionaryEntry entry in props)
                {
                    arguments.Add((string)entry.Key, entry.Value);
                }
                stepResponse = new RanorexHandlerFactory().GetHandler((string)command.arguments["itest-action"], repo).Execute(arguments);
                EXECUTION_INDEX++;
            }
            else if (command.command == "ping")
            {
                agentServer.Ping();
            }
            else if (command.command == "open")
            {
                try
                {
                    if ((bool)command.arguments["capture"] == true)
                    {
                        isInteractive = true;
                    }

                    OpenSession(command);

                    stepResponse         = new RanorexStepExecutionResponse();
                    stepResponse.success = true;
                }
                catch (Exception e)
                {
                    stepResponse         = new RanorexStepExecutionResponse();
                    stepResponse.success = false;
                    stepResponse.message = "Failed to open Ranorex session: " + e.Message;

                    agentServer.DropClient();
                }
            }
            else if (command.command == "close")
            {
                closeSession();
                agentServer.DropClient();
            }
            else if (command.command == "startcapture")
            {
            }
            else if (command.command == "stopcapture")
            {
                Thread startThread = new Thread(StopRecording);
                startThread.SetApartmentState(ApartmentState.STA);
                startThread.Start();
            }

            if (stepResponse != null)
            {
                AgentResponse agentResponse = new AgentResponse();
                agentResponse.messageType           = AgentResponse.MessageType.EXECUTION_STEP_RESPONSE;
                agentResponse.stepExecutionResponse = stepResponse;
                agentServer.SendMessage(agentResponse);
            }
        }
Exemple #15
0
 void HideProgress()
 {
     progressForm.Hide();          // or Close, it depends from app logic
 }
        public void ConvertBitmapTo8Bpp(int correction)
        {
            //  this method is the only one that sometimes needs a long time;
            //  therefore Juergen Thomas added a progress form as standard,
            //  but shows it only for larger bitmaps
            using (ProgressForm progress = new ProgressForm(ctrl)) {
                if (bmp.Width * bmp.Height >= 40000)
                {
                    progress.Show();
                }
                //  variables used instead of timer
                DateTime now;
                TimeSpan diff;

                Bitmap Result = new Bitmap(bmp.Width, bmp.Height,
                                           PixelFormat.Format8bppIndexed);

                BitmapData ResultData
                    = Result.LockBits(
                          new Rectangle(0, 0, bmp.Width, bmp.Height),
                          ImageLockMode.ReadWrite,
                          PixelFormat.Format8bppIndexed);

                int    tmpStride = ResultData.Stride;
                IntPtr ptr       = ResultData.Scan0;

                Hashtable ColorReduction = new Hashtable();
                byte      offset         = 39;
                for (int r = 0; r < 256; r += 51)
                {
                    for (int g = 0; g < 256; g += 51)
                    {
                        for (int b = 0; b < 256; b += 51)
                        {
                            ColorReduction[Color.FromArgb(r, b, g)] = ++offset;
                        }
                    }
                }

                int    tmpBytes      = bmp.Height * tmpStride;
                byte[] tmpBitmapData = new byte[tmpBytes];

                now = DateTime.Now;
                for (int x = 0; x < bmp.Width; x++)
                {
                    //  check if progress should be actualized (after 600 msec)
                    diff = DateTime.Now - now;
                    if (progress.Visible && (diff.Ticks > 6000000))
                    {
                        progress.Progressing(x);
                        now = DateTime.Now;
                    }

                    for (int y = 0; y < bmp.Height; y++)
                    {
                        int offset2 = (y * tmpStride) + x;
                        //  get a suitable 8 bit color to the current 24 bit pixel
                        Color col = ConvertColorTo8Bpp(bmp.GetPixel(x, y), correction);
                        //  set this color as color resp. grayscale
                        if (format8bitPixel == ColorDepthReduction.Colored8bpp)
                        {
                            tmpBitmapData[offset2]
                                = (byte)(col.R * 0.3 + col.G * 0.59 + col.B * 0.11);
                        }
                        else
                        {
                            tmpBitmapData[offset2]
                                = (byte)ColorReduction[col];
                        }
                    }
                }

                System.Runtime.InteropServices.Marshal.Copy(tmpBitmapData, 0, ptr, tmpBytes);

                Result.UnlockBits(ResultData);

                progress.Hide();

                //  change the formprint bitmap
                bmp.Dispose();
                bmp = Result;
            }
        }