public Form1() { this.InitializeComponent(); this.updateContentTxbDelegate = this.AppendToContent; this.updateLogTxbDelegate = this.AppendToLog; }
/// <summary> /// Renders the base control. /// </summary> /// <param name="writer">The writer.</param> public void RenderBaseControl(HtmlTextWriter writer) { var renderInputGroup = PrependText.IsNotNullOrWhiteSpace() || AppendText.IsNotNullOrWhiteSpace(); string cssClass = this.CssClass; if (renderInputGroup) { writer.AddAttribute("class", "input-group " + cssClass); if (this.Style[HtmlTextWriterStyle.Display] == "none") { // render the display:none in the inputgroup div instead of the control itself writer.AddStyleAttribute(HtmlTextWriterStyle.Display, "none"); this.Style[HtmlTextWriterStyle.Display] = string.Empty; } writer.RenderBeginTag(HtmlTextWriterTag.Div); this.CssClass = string.Empty; } if (!string.IsNullOrWhiteSpace(PrependText)) { writer.AddAttribute("class", "input-group-addon"); writer.RenderBeginTag(HtmlTextWriterTag.Span); writer.Write(PrependText); writer.RenderEndTag(); } (( WebControl )this).AddCssClass("form-control"); if (EnhanceForLongLists) { (( WebControl )this).AddCssClass("chosen-select"); if (DisplayEnhancedAsAbsolute) { (( WebControl )this).AddCssClass("chosen-select-absolute"); } } base.RenderControl(writer); if (!string.IsNullOrWhiteSpace(AppendText)) { writer.AddAttribute("class", "input-group-addon"); writer.RenderBeginTag(HtmlTextWriterTag.Span); writer.Write(AppendText); writer.RenderEndTag(); } if (renderInputGroup) { writer.RenderEndTag(); // input-group this.CssClass = cssClass; } RenderDataValidator(writer); }
public void ShouldAppendSuffixToEndOfOrigin() { //Arrange AppendText subject = new AppendText(new TextOf("Any origin "), new TextOf("any suffix")); //Act string actual = subject; //Assert actual.Should().Be("Any origin any suffix"); }
private void WriteToConsole(string message) { AppendText action = AppendToConsole; var text = (txtOutput.Text.Length > 0 ? Environment.NewLine : "") + message; if (txtOutput.InvokeRequired) { txtOutput.Invoke(action, text); } else { action(text); } }
public ComPortsService(AppendText append_text) { appendText = append_text; message = ""; cont = true; // Создать объект класса SerialPort с настройками по умолчанию _serialPort = new SerialPort(); // Указать таймауты _serialPort.ReadTimeout = 1; _serialPort.WriteTimeout = 1; _readThread = new Thread(Read); _readThread.Start(); }
public MainForm() { InitializeComponent(); initConsoleStyles(); browserComboBox.SelectedIndex = 0; OSComboBox.SelectedIndex = 0; appendTextDelegate = new AppendText(AddTextMethod); addBrowsers(); threads = new List <Thread>(); template = "use.saucelabs=True\n" + "use.saucelabs.tunnel=True\n" + "saucelabs.username=${username}\n" + "saucelabs.access.key=${access.key}\n\n" + "send.saucelabs.okta.plugin=true\n" + "saucelabs.browser=${browser.name}\n" + "saucelabs.browser.version=${browser.version}\n" + "saucelabs.os=${os.version}\n\n" + "saucelabs.${plugin.browser}.plugin.url=sauce-storage:Okta${plugin.name}PluginSilentInstaller-early-access.exe\n" + "selenium.test.url=http://backdoorentry.okta1.com:1802\n" + "test.app.server=rain.okta1.com\n\n" + "junit.maxmem=1024m\n" + "junit.permgen=512m"; if (!Settings.Get().CheckConf()) { SettingsForm settingsForm = new SettingsForm(); settingsForm.ShowDialog(); } p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.FileName = "cmd"; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardInput = true; p.StartInfo.CreateNoWindow = true; p.Start(); injectEnvVars(); //p.StandardInput.WriteLine("D:"); //p.StandardInput.WriteLine("cd D:\\project"); }
private void CommitButton_Click(object sender, RoutedEventArgs e) { int i = 0; foreach (GameObject g in EngineManagerViewModel.instance.SelectedGameObjects) { ++i; //do replace pass first if (ReplaceText.Text.Count() != 0) { g.SetName(ReplaceText.Text); } //then do prefix and suffix if (AppendText.Text.Count() != 0) { g.SetName(g.GetName() + AppendText.Text); } if (PrefixText.Text.Count() != 0) { g.SetName(PrefixText.Text + g.GetName()); } //do append numbers pass last if (AppendNumbers.IsChecked.HasValue && AppendNumbers.IsChecked.Value) { g.SetName(g.GetName() + i.ToString()); } } ReplaceText.Clear(); AppendText.Clear(); PrefixText.Clear(); EngineManagerViewModel.instance.ForceRefreshGameObjects(); }
/// <summary> /// Verify worker thread. /// </summary> private void VerifyWorker2(VerifyMode mode) { // // delegates for messaging UI thread // AppendText appendText = new AppendText(this.txtOutput.AppendText); VoidMethod updateControls = new VoidMethod(this.UpdateControls); try { if ((mode & VerifyMode.VerifyProgram) == VerifyMode.VerifyProgram) { // // start stopwatch // this.stopwatch.Reset(); this.stopwatch.Start(); // // display verifying message // this.Invoke(appendText, Strings.VerifyingProgramMemory); // // verify program memory // this.programmer.Verify(0x000000, this.programMemory, this.selectedDevice.ProgramMemroySize, 0x000000, false, this.selectedDevice); // // stop the stopwatch // this.stopwatch.Stop(); // // display success message // this.Invoke(appendText, Strings.Success); this.Invoke(appendText, string.Format(" ({0})", this.stopwatch.Elapsed.ToString())); this.Invoke(appendText, Environment.NewLine); } if ((mode & VerifyMode.VerifyConfiguration) == VerifyMode.VerifyConfiguration) { // // restart the stopwatch // this.stopwatch.Reset(); this.stopwatch.Start(); // // display message // this.Invoke(appendText, "Verifying configuration bits..."); // // verify configuration memory // this.programmer.Verify(this.selectedDevice.ConfigAddress, this.configMemory, this.selectedDevice.ConfigBytes / 3, 0x000000, true, this.selectedDevice); // // stop the stopwatch // this.stopwatch.Stop(); // // display success mmessage // this.Invoke(appendText, Strings.Success); this.Invoke(appendText, string.Format(" ({0})", this.stopwatch.Elapsed.ToString())); this.Invoke(appendText, Environment.NewLine); } } catch (ThreadAbortException) { // // display abort message // //this.Invoke(appendText, Strings.Aborted); //this.Invoke(appendText, Environment.NewLine); } catch (AddressException) { // // display error // this.Invoke(appendText, Strings.Failed); this.Invoke(appendText, Environment.NewLine); this.Invoke(appendText, Strings.AddressError); this.Invoke(appendText, Environment.NewLine); } catch (VerifyException) { // // display error // this.Invoke(appendText, Strings.Failed); this.Invoke(appendText, Environment.NewLine); } catch (Exception ex) { // // display error // this.Invoke(appendText, Strings.Failed); this.Invoke(appendText, Environment.NewLine); this.Invoke(appendText, ex.Message); this.Invoke(appendText, Environment.NewLine); } finally { // // stop the stopwatch // if (this.stopwatch.IsRunning) { this.stopwatch.Stop(); } // // update controls // this.Invoke(updateControls); } }
/// <summary> /// Writes to program memory. /// </summary> private void WriteProgramMemoryWorker() { // // delegates for messaging UI thread // AppendText appendText = new AppendText(this.txtOutput.AppendText); //VoidMethod verify = new VoidMethod(this.Verify); VoidMethod updateControls = new VoidMethod(this.UpdateControls); // // start stopwatch // this.stopwatch.Reset(); this.stopwatch.Start(); try { // // program device // this.programmer.WriteProgramMemory(0x000000, this.programMemory, 0x000000); this.stopwatch.Stop(); // // show completed message // this.Invoke(appendText, Strings.Success); this.Invoke(appendText, string.Format(" ({0})", this.stopwatch.Elapsed.ToString())); this.Invoke(appendText, Environment.NewLine); // // verify program memory // //this.VerifyWorker2(VerifyMode.VerifyProgram); // // restart stopwatch // this.stopwatch.Reset(); this.stopwatch.Start(); // // write configuration bits programming message // this.Invoke(appendText, Strings.ProgrammingConfigBits); // // write configuration bits // this.programmer.WriteProgramMemory(this.selectedDevice.ConfigAddress, this.configMemory, 0x000000); // // stop the stopwatch // this.stopwatch.Stop(); // // display success message // this.Invoke(appendText, Strings.Success); this.Invoke(appendText, string.Format(" ({0})", this.stopwatch.Elapsed.ToString())); this.Invoke(appendText, Environment.NewLine); // // verify program memory // this.VerifyWorker2(VerifyMode.VerifyConfiguration); } catch (ThreadAbortException) { //this.Invoke(appendText, Strings.Aborted); //this.Invoke(appendText, Environment.NewLine); } catch (Exception ex) { // // display error message // this.Invoke(appendText, Strings.Failed); this.Invoke(appendText, Environment.NewLine); this.Invoke(appendText, ex.Message); this.Invoke(appendText, Environment.NewLine); } finally { this.Invoke(updateControls); } }
/// <summary> /// Reads program memory in a background thread. /// </summary> private void ReadMemoryWorker() { // // delegates for messaging UI thread // AppendText appendText = new AppendText(this.txtOutput.AppendText); VoidMethod populateListView = new VoidMethod(this.LoadProgramWords); VoidMethod updateControls = new VoidMethod(this.UpdateCOMPortList); // // start stopwatch // this.stopwatch.Reset(); this.stopwatch.Start(); try { // // download the program from the device's memory // if (rbPartialProgramming.Checked == true) { uint start = uint.Parse(this.txtPMStart.Text, NumberStyles.HexNumber); uint end = uint.Parse(this.txtPMEnd.Text, NumberStyles.HexNumber); // // read programm memory range // byte[] readBytes = this.programmer.ReadProgramMemory(start, (end - start) / 2); // // allocate program memory array // this.AllocateProgramArray(); // // copy read bytes to program memory array // Array.Copy(readBytes, 0, this.programMemory, (start / 2) * 3, (end - start) / 2); } else { // // read program memory // uint totalWords = this.selectedDevice.ProgramMemroySize + (this.selectedDevice.ConfigBytes / 3); this.programMemory = this.programmer.ReadProgramMemory(0x000000, totalWords); } // // stop timer // this.stopwatch.Stop(); // // display success message // this.Invoke(appendText, Strings.Success); this.Invoke(appendText, string.Format(" ({0})", this.stopwatch.Elapsed.ToString())); this.Invoke(appendText, Environment.NewLine); // // populate listview // this.Invoke(populateListView); } catch (ThreadAbortException) { //this.Invoke(appendText, Strings.Aborted); //this.Invoke(appendText, Environment.NewLine); } catch (Exception ex) { this.stopwatch.Stop(); // // display error message // this.Invoke(appendText, Strings.Failed); this.Invoke(appendText, Environment.NewLine); this.Invoke(appendText, ex.Message); this.Invoke(appendText, Environment.NewLine); MessageBox.Show(ex.Message, Strings.Error); } finally { this.Invoke(updateControls); } }
private void ProgramExecutive() { try { AppendText appendText = new AppendText(this.txtOutput.AppendText); string file = string.Empty; string executivePath = ConfigurationManager.AppSettings["ExecutivePath"]; this.Invoke(appendText, string.Format("Looking for executive in: {0}", executivePath)); this.Invoke(appendText, Environment.NewLine); // // // foreach (string f in Directory.GetFiles(executivePath)) { // // strip path from filename // file = Path.GetFileName(f); if (file.StartsWith(this.programmer.ExecutiveFile) && file.EndsWith(".hex")) { this.Invoke(appendText, string.Format("Found executive file: {0}", file)); this.Invoke(appendText, Environment.NewLine); file = f; break; } } // // // byte[] executiveMemory = new byte[2048 * 3]; for (int i = 0; i < executiveMemory.Length; i++) { executiveMemory[i] = 0xFF; } // // load the executive HEX file // HEXFile executive = new HEXFile(file); executive.ReadFile(new byte[] {}, executiveMemory, 0x800000); // // erase executive memory // this.Invoke(appendText, "Erasing program and executive memory..."); this.programmer.EraseProgramAndExecutiveMemory(); this.Invoke(appendText, Strings.Success); this.Invoke(appendText, Environment.NewLine); // // program the executive // this.Invoke(appendText, "Programming executive..."); this.programmer.WriteProgramMemory(0x800000, executiveMemory, 0x000000); this.Invoke(appendText, Strings.Success); this.Invoke(appendText, Environment.NewLine); } catch (DirectoryNotFoundException) { throw; } }
/// <summary> /// 比对函数,将每一帧抓拍的照片和身份证照片进行比对 /// </summary> /// <param name="bitmap"></param> /// <param name="e"></param> /// <returns></returns> private bool CompareImgWithIDImg(Bitmap bitmap, PaintEventArgs e) { recTimes--; if (bitmap == null) { return(false); } Graphics g = e.Graphics; float offsetX = videoSource.Width * 1f / bitmap.Width; float offsetY = videoSource.Height * 1f / bitmap.Height; //检测人脸,得到Rect框 ASF_MultiFaceInfo multiFaceInfo = FaceUtil.DetectFace(pVideoEngine, bitmap); //得到最大人脸 ASF_SingleFaceInfo maxFace = FaceUtil.GetMaxFace(multiFaceInfo); //得到Rect MRECT rect = maxFace.faceRect; float x = rect.left * offsetX; float width = rect.right * offsetX - x; float y = rect.top * offsetY; float height = rect.bottom * offsetY - y; //根据Rect进行画框 g.DrawRectangle(pen, x, y, width, height); //将上一帧检测结果显示到页面上 g.DrawString(trackUnit.message, font, brush, x, y + 5); //保证只检测一帧,防止页面卡顿以及出现其他内存被占用情况 if (isLock == false) { isLock = true; //异步处理提取特征值和比对,不然页面会比较卡 ThreadPool.QueueUserWorkItem(new WaitCallback(delegate { if (rect.left != 0 && rect.right != 0 && rect.top != 0 && rect.bottom != 0) { try { //提取人脸特征 IntPtr feature = FaceUtil.ExtractFeature(pVideoImageEngine, bitmap, maxFace); float similarity = CompareTwoFeatures(feature, idCardHelper.idInfo.imageFeature); this.similarity.Text = ("相似度为: " + similarity.ToString("P"));; //显示在界面上 this.similarity.ForeColor = similarity > threshold ? Color.Green : Color.Red; //得到比对结果 int result = (CompareTwoFeatures(feature, idCardHelper.idInfo.imageFeature) >= threshold) ? 1 : -1; if (result > -1) { bool isLiveness = false; ImageInfo imageInfo = ImageUtil.ReadBMP(bitmap); //调整图片数据 if (imageInfo == null) { return; } int retCode_Liveness = -1; //RGB活体检测 ASF_LivenessInfo liveInfo = FaceUtil.LivenessInfo_RGB(pVideoImageEngine, imageInfo, multiFaceInfo, out retCode_Liveness); //判断检测结果 if (retCode_Liveness == 0 && liveInfo.num > 0) { int isLive = MemoryUtil.PtrToStructure <int>(liveInfo.isLive); isLiveness = (isLive == 1) ? true : false; } if (isLiveness)//活体检测成功 { //存放当前人脸识别的相似度 idCardHelper.idInfo.similarity = similarity; //记录下当前的摄像头的人脸抓拍照 idCardHelper.idInfo.capImage = bitmap; //验证通过则不再是当前身份证,等待下一次身份证 idCardHelper.idInfo.isRight = false; //在子线程中输出信息到messageBox AppendText p = new AppendText(AddTextToMessBox); lbl_msg.Invoke(p, "人脸验证成功,请取卡...\n"); pass = 1; idCardHelper.idInfo.isPass = 1; //将比对结果放到显示消息中,用于最新显示 trackUnit.message = string.Format("通过验证,相似度为{0}", similarity); FileHelper.DeleteFile(m_strPath); //删除验证过的本地文件 Thread.Sleep(1000); //延时1秒 this.IDPbox.Image = defaultImage; //照片恢复默认照片 trackUnit.message = ""; //人脸识别框文字置空 setFormResultValue(true); } else { pass = 0;//标志未通过 trackUnit.message = "未通过,系统识别为照片"; AppendText p = new AppendText(AddTextToMessBox); lbl_msg.Invoke(p, "抱歉,您未通过人脸验证...\n"); FileHelper.DeleteFile(m_strPath);//删除验证过的本地文件 } } else { pass = 0;//标志未通过 trackUnit.message = "未通过人脸验证"; AppendText p = new AppendText(AddTextToMessBox); lbl_msg.Invoke(p, "抱歉,您未通过人脸验证...\n"); FileHelper.DeleteFile(m_strPath);//删除验证过的本地文件 } } catch (Exception ex) { Console.WriteLine(ex.Message); FileHelper.DeleteFile(m_strPath);//删除验证过的本地文件 } finally { isLock = false; } } isLock = false; })); } return(false); }
public virtual void AcceptGraphicalPrimitiveAppendText(AppendText appendText, T parameter) { // intentionally left blank }
public Form1() { this.InitializeComponent(); this.appendToContentDelegate = this.AppendToContent; this.loggingDelegate = this.Log; }
public void appendText(string msg) { AppendText aptxt = appentTextBox1; textBox1.BeginInvoke(aptxt, msg); }
public Form1() { InitializeComponent(); textbox3del = new AppendText(textBoxLog.AppendText); }
public void AcceptGraphicalPrimitiveAppendText(AppendText appendText, PrintContext parameter) { parameter.WriteLine("Append Text: '{0}'", appendText.Text); }
//比对函数 //将每一帧抓拍的照片和身份证照片进行比对 private bool CompareImgWithIDImg(Bitmap bitmap, PaintEventArgs e) { recTimes--; if (bitmap == null) { return(false); } Graphics g = e.Graphics; float offsetX = videoSource.Width * 1f / bitmap.Width; float offsetY = videoSource.Height * 1f / bitmap.Height; //检测人脸,得到Rect框 ASF_MultiFaceInfo multiFaceInfo = FaceUtil.DetectFace(pVideoEngine, bitmap); //得到最大人脸 ASF_SingleFaceInfo maxFace = FaceUtil.GetMaxFace(multiFaceInfo); //得到Rect MRECT rect = maxFace.faceRect; float x = rect.left * offsetX; float width = rect.right * offsetX - x; float y = rect.top * offsetY; float height = rect.bottom * offsetY - y; //根据Rect进行画框 g.DrawRectangle(pen, x, y, width, height); if (trackUnit.message != "" && x > 0 && y > 0) { //将上一帧检测结果显示到页面上 g.DrawString(trackUnit.message, font, brush, x, y + 5); } //保证只检测一帧,防止页面卡顿以及出现其他内存被占用情况 if (isLock == false) { isLock = true; //异步处理提取特征值和比对,不然页面会比较卡 ThreadPool.QueueUserWorkItem(new WaitCallback(delegate { if (rect.left != 0 && rect.right != 0 && rect.top != 0 && rect.bottom != 0) { try { //提取人脸特征 IntPtr feature = FaceUtil.ExtractFeature(pVideoImageEngine, bitmap, maxFace); float similarity = CompareTwoFeatures(feature, idInfo.imageFeature); messageBox.AppendText("相似度为: " + similarity); this.similarityText.Text = similarity.ToString(); //显示在界面上 //得到比对结果 int result = (CompareTwoFeatures(feature, idInfo.imageFeature) >= threshold) ? 1 : -1; if (result > -1) { //存放当前人脸识别的相似度 idInfo.similarity = similarity; //记录下当前的摄像头的人脸抓拍照 idInfo.capImage = bitmap; //标志人脸比对验证通过 faceState = true; //验证通过则不再是当前身份证,等待下一次身份证 idInfo.isRight = false; //在子线程中输出信息到messageBox AppendText p = new AppendText(AddTextToMessBox); messageBox.Invoke(p, "人脸验证成功,请通过闸机...\n"); //关闭读卡线程 //workThread.Suspend(); //最终通过闸机 pass = 1; //以人脸识别的方式通过闸机 idInfo.isPass = 1; /* *通信部分,将内存中的数据存放到数据库中 */ //将身份证数据传入到服务器上 sendMessageToServer(); //将比对结果放到显示消息中,用于最新显示 trackUnit.message = string.Format("通过验证,相似度为{0}", similarity); DeleteFile(); //删除验证过的本地文件 //延时3秒 Thread.Sleep(1000); //照片恢复默认照片 this.IDPbox.Image = defaultImage; } else { pass = 0; //重置显示消息 trackUnit.message = "未通过人脸验证"; AppendText p = new AppendText(AddTextToMessBox); messageBox.Invoke(p, "抱歉,您未通过人脸验证...\n"); DeleteFile(); //删除验证过的本地文件 } } catch (Exception ex) { Console.WriteLine(ex.Message); DeleteFile(); //删除验证过的本地文件 } finally { isLock = false; } } isLock = false; })); } return(false); }