private CKSimNetCode() { ReInitPubSocket(); ReInitRepSocket(); repTimer.Start(); pubTimer.Start(); }
private void BtnInstall_OnClick(object sender, RoutedEventArgs e) { if (_installList.Count == 0) { MessageBox.Show(Localization.GetString("Global", 50), Localization.GetString("Global", 51)); return; } lblStatus.Text = Localization.GetString("Global", 48); pbProgress.Value = 0; pbProgress.Maximum = _installList.Count; lblProgress.Content = "0%"; dgUpdates.Disable(); rbnMain.IsEnabled = false; _tim = new ElapsedTimer(ref txtTime); _tim.Start(); var amountInstalled = 0; Task.Factory.StartNew(delegate { foreach (var currentFile in _installList) { currentFile.Status = currentFile.Install(); amountInstalled++; pbProgress.Dispatcher.BeginInvoke(new Action(() => { pbProgress.Value++; var progress = (pbProgress.Value / pbProgress.Maximum) * 100; lblStatus.Text = amountInstalled + " / " + _installList.Count + " " + Localization.GetString("Global", 62); lblProgress.Content = Math.Round(progress, 1) + "%"; dgUpdates.Items.Refresh(); })); } }).ContinueWith(continuation => { _tim.Stop(); lblStatus.Dispatcher.BeginInvoke(new Action(() => { lblStatus.Text = _installList.Count(c => c.Status == Status.Success) + " " + Localization.GetString("FrmLMM", 8); dgUpdates.Enable(); rbnMain.IsEnabled = true; })); }); }
public void ElapsedTimer_MultiRun() { ElapsedTimer timer; timer = new ElapsedTimer(true); Thread.Sleep(1000); timer.Stop(); Thread.Sleep(1000); timer.Start(); Thread.Sleep(1000); timer.Stop(); Assert.IsTrue(Compare(2000, timer.ElapsedTime)); }
private async void addUpdate(IEnumerable <string> files) { dgUpdates.Disable(); pbProgress.Value = 0; lblProgress.Content = "0%"; var source = files.ToArray(); pbProgress.Maximum = source.Count(); _tim = new ElapsedTimer(ref txtTime); _tim.Start(); await Task.Factory.StartNew(delegate { Parallel.ForEach(source, new ParallelOptions { MaxDegreeOfParallelism = Options.MaxThreads }, currentFile => { _Update newUpdate = null; if (currentFile.EndsWithIgnoreCase(".cab")) { newUpdate = new CabUpdate(currentFile); } else if (currentFile.EndsWithIgnoreCase(".msu")) { newUpdate = new MsuUpdate(currentFile); } pbProgress.Increment(lblProgress); if (newUpdate == null) { return; } _updates.Add(newUpdate); }); }); _tim.Stop(); dgUpdates.ItemsSource = _updates; dgUpdates.Update(); }
public void ElapsedTimer_Basic() { ElapsedTimer timer; // Timer not started #1 timer = new ElapsedTimer(); Thread.Sleep(200); Assert.AreEqual(TimeSpan.Zero, timer.ElapsedTime); Thread.Sleep(1000); timer.Stop(); Assert.AreEqual(TimeSpan.Zero, timer.ElapsedTime); // Timer not started #2 timer = new ElapsedTimer(false); Thread.Sleep(200); Assert.AreEqual(TimeSpan.Zero, timer.ElapsedTime); Thread.Sleep(1000); timer.Stop(); Assert.AreEqual(TimeSpan.Zero, timer.ElapsedTime); // Timer started manually timer = new ElapsedTimer(false); Thread.Sleep(200); Assert.AreEqual(TimeSpan.Zero, timer.ElapsedTime); timer.Start(); Thread.Sleep(1000); timer.Stop(); Assert.IsTrue(Compare(1000, timer.ElapsedTime)); // Timer started automatically timer = new ElapsedTimer(true); Assert.AreEqual(TimeSpan.Zero, timer.ElapsedTime); timer.Start(); Thread.Sleep(1000); timer.Stop(); Assert.IsTrue(Compare(1000, timer.ElapsedTime)); }
public void SwitchConnection_BlastBoth() { // Simulate the blasting of events from the switch to the remote connection // and commands from the remote machine to the switch. var handlerDone = false; var cCommandsReceived = 0; var cCommandsExecuted = 0; var cEventsReceived = 0; var connectHandler = new EventHandler <SwitchInboundConnectionArgs>( (s, a) => { a.StartConnectionThread = false; Helper.EnqueueAction(() => { SwitchConnection serverConnection = a.Connection; serverConnection.CommandReceived += (s1, a1) => { if (a1.CommandText == "sendevent HEARTBEAT" && Helper.ASCIIEncoding.GetString(a1.Content) == "Hello World!" && a1.Properties["Foo"] == "Bar") { Interlocked.Increment(ref cCommandsReceived); } }; AuthHandshake(serverConnection, false); serverConnection.StartThread(); Helper.EnqueueAction( () => { for (int i = 0; i < TransactionCount; i++) { SendEvent(serverConnection, SwitchEventCode.Heartbeat, "Hello World!", new NameValue("Foo", "Bar")); } }); Helper.WaitFor(() => cCommandsReceived == TransactionCount && cCommandsExecuted == TransactionCount && cEventsReceived == TransactionCount, Timeout); serverConnection.Close(); handlerDone = true; }); }); SwitchConnection.InboundConnection += connectHandler; try { SwitchConnection.SendBufferSize = SwitchConnection.ReceiveBufferSize = SocketBufferSize; SwitchConnection.StartListener(binding, 10); var connection = new SwitchConnection(binding, SwitchConnection.DefaultPassword); var elapsedTimer = new ElapsedTimer(); connection.EventReceived += (s, a) => { if (a.EventCode == SwitchEventCode.Heartbeat && a.ContentType == "text" && a.ContentText == "Hello World!") { Interlocked.Increment(ref cEventsReceived); } }; connection.Connect(); elapsedTimer.Start(); for (int i = 0; i < TransactionCount; i++) { var properties = new ArgCollection(ArgCollectionType.Unconstrained); properties["Foo"] = "Bar"; connection.SendEvent(SwitchEventCode.Heartbeat, properties, "Hello World!"); Interlocked.Increment(ref cCommandsExecuted); } Helper.WaitFor(() => handlerDone, Timeout); elapsedTimer.Stop(); var rate = (cCommandsReceived + cEventsReceived) / elapsedTimer.ElapsedTime.TotalSeconds; Debug.WriteLine(string.Format("Transaction Rate: {0}/sec", rate)); } finally { SwitchConnection.ResetGlobals(); SwitchConnection.InboundConnection -= connectHandler; SwitchConnection.StopListener(); } }
public void SwitchConnection_BlastEvents() { // Simulate the blasting of events from the switch to the remote connection. var handlerDone = false; var cEventsReceived = 0; var connectHandler = new EventHandler <SwitchInboundConnectionArgs>( (s, a) => { a.StartConnectionThread = false; Helper.EnqueueAction(() => { SwitchConnection serverConnection = a.Connection; AuthHandshake(serverConnection, false); serverConnection.StartThread(); Helper.EnqueueAction( () => { for (int i = 0; i < TransactionCount; i++) { SendEvent(serverConnection, SwitchEventCode.Heartbeat, "Hello World!", new NameValue("Foo", "Bar")); } }); Helper.WaitFor(() => cEventsReceived == TransactionCount, Timeout); serverConnection.Close(); handlerDone = true; }); }); SwitchConnection.InboundConnection += connectHandler; try { SwitchConnection.SendBufferSize = SwitchConnection.ReceiveBufferSize = SocketBufferSize; SwitchConnection.StartListener(binding, 10); var connection = new SwitchConnection(binding, SwitchConnection.DefaultPassword); var elapsedTimer = new ElapsedTimer(); connection.EventReceived += (s, a) => { if (a.EventCode == SwitchEventCode.Heartbeat && a.ContentType == "text" && a.ContentText == "Hello World!") { Interlocked.Increment(ref cEventsReceived); } }; connection.Connect(); elapsedTimer.Start(); Helper.WaitFor(() => handlerDone, Timeout); elapsedTimer.Stop(); var rate = cEventsReceived / elapsedTimer.ElapsedTime.TotalSeconds; Debug.WriteLine(string.Format("Transaction Rate: {0}/sec", rate)); } finally { SwitchConnection.ResetGlobals(); SwitchConnection.InboundConnection -= connectHandler; SwitchConnection.StopListener(); } }
private async void BtnPrepare_OnClick(object sender, RoutedEventArgs e) { if (dgUSB.SelectedItems.Count != 1) { MessageBox.Show(Localization.GetString("Global", 69), Localization.GetString("Global", 68)); return; } var usb = (USBDrive)dgUSB.SelectedItems[0]; if (usb.LargerThan32Gb) { MessageBox.Show(Localization.GetString("FrmUSBPrep", 23), Localization.GetString("FrmUSBPrep", 24)); return; } var MBR = MessageBoxResult.None; if (usb.BootRecord == BootRecord.MBR && rbUEFI.IsChecked == true) { MBR = MessageBox.Show( Localization.GetString("FrmUSBPrep", 35) + " " + Localization.GetString("Global", 55) + "\n\n[" + Localization.GetString("FrmUSBPrep", 34) + "]", Localization.GetString("FrmUSBPrep", 25), MessageBoxButton.YesNo); } if (usb.BootRecord == BootRecord.GPT && rbBIOS.IsChecked == true) { MBR = MessageBox.Show( Localization.GetString("FrmUSBPrep", 36) + " " + Localization.GetString("Global", 55) + "\n\n[" + Localization.GetString("FrmUSBPrep", 34) + "]", Localization.GetString("FrmUSBPrep", 25), MessageBoxButton.YesNo); } if (MBR != MessageBoxResult.None && MBR != MessageBoxResult.Yes) { return; } Enable(false); watcher.Stop(); var elapsedTimer = new ElapsedTimer(ref txtTime); elapsedTimer.Start(); pbProgress.Value = 0; lblStatus.Text = Localization.GetString("FrmISOMaker", 18); var quickFormat = cbQuickFormat.IsChecked == true; var UEFI = rbUEFI.IsChecked == true; var newFormat = DriveFormat.FAT32; if (rbNTFS.IsChecked == true) { newFormat = DriveFormat.NTFS; } var result = string.Empty; usb.PropertyChanged += delegate(object o, PropertyChangedEventArgs args) { lblStatus.UpdateText(args.PropertyName); }; watcher.Stop(); await Task.Factory.StartNew(() => { if (UEFI) { result = usb.PrepareUSB_GPT(quickFormat, pbProgress); } else { result = usb.PrepareUSB_MBR(quickFormat, newFormat, pbProgress); } }).ContinueWith(delegate { elapsedTimer.Stop(); pbProgress.Value = 100; lblStatus.Text = "Done"; }, TaskScheduler.FromCurrentSynchronizationContext()); Scan(); }
public void IPToGeocode_UpdateData_WithQueries() { // Blast 100,000 parallel async queries at the the service // in waves of a 1000 queries at a time and during the middle of // this activity, prod the server to download a new database file // as often as possible. try { TestInit(true, true); int cQueries = 100000; int cWave = 1000; int cCompleted = 0; bool fail = false; ElapsedTimer timer = new ElapsedTimer(); int lastUpdateCount = 0; double rate; for (int i = 0; i < cQueries / cWave; i++) { cCompleted = 0; timer.Start(); for (int j = 0; j < cWave; j++) { client.BeginIPToGeoFix(testIP, ar => { var c = Interlocked.Increment(ref cCompleted); try { VerifyTestFix(client.EndIPToGeoFix(ar)); } catch { fail = true; } if (cCompleted == cWave) { timer.Stop(); } }, null); } Helper.WaitFor(() => cCompleted == cWave, TimeSpan.FromSeconds(60)); // Prod the server the first time through and then after the server // has completed downloading the previous update. if (i == 0 || server.IPGeocoder.UpdateCount > lastUpdateCount) { var oldDate = new DateTime(2000, 1, 1); try { File.SetCreationTimeUtc(IPGeocoder.DataPath, oldDate); File.SetLastWriteTimeUtc(IPGeocoder.DataPath, oldDate); File.SetLastAccessTimeUtc(IPGeocoder.DataPath, oldDate); lastUpdateCount = server.IPGeocoder.UpdateCount; server.IPGeocoder.PollForUpdates(); } catch (IOException) { // I'm going to ignore I/O errors because there's a decent // chance that the data file may be open in the geocoder's // download thread. } } } rate = cQueries / timer.ElapsedTime.TotalSeconds; Debug.WriteLine("{0} seconds elapsed for {1} queries", timer.ElapsedTime, cQueries); Debug.WriteLine("Query Rate: {0}/sec", rate); if (fail) { Assert.Fail("One or more of the query operations failed."); } } finally { server.IPGeocoder.StopImmediately = true; TestCleanup(); } }
public void IPToGeocode_Query_AsyncBlast() { // Blast 100,000 parallel async queries at the the service // in waves of a 1000 queries at a time. try { TestInit(true, true); int cQueries = 100000; int cWave = 1000; int cCompleted = 0; bool fail = false; ElapsedTimer timer = new ElapsedTimer(); double rate; for (int i = 0; i < cQueries / cWave; i++) { cCompleted = 0; timer.Start(); for (int j = 0; j < cWave; j++) { client.BeginIPToGeoFix(testIP, ar => { var c = Interlocked.Increment(ref cCompleted); try { VerifyTestFix(client.EndIPToGeoFix(ar)); } catch { fail = true; } if (cCompleted == cWave) { timer.Stop(); } }, null); } Helper.WaitFor(() => cCompleted == cWave, TimeSpan.FromSeconds(60)); } rate = cQueries / timer.ElapsedTime.TotalSeconds; Debug.WriteLine("{0} seconds elapsed for {1} queries", timer.ElapsedTime, cQueries); Debug.WriteLine("Query Rate: {0}/sec", rate); if (fail) { Assert.Fail("One or more of the query operations failed."); } } finally { TestCleanup(); } }
private void BtnCreateISO_OnClick(object sender, RoutedEventArgs e) { if (btnCreateISO.Label == Localization.GetString("FrmISOMaker", 6)) { if (lblDirectory.Content.ToString().Equals(Localization.GetString("FrmISOMaker", 10))) { MessageBox.Show(Localization.GetString("FrmISOMaker", 10), ""); return; } if (lblISO.Content.ToString().Equals(Localization.GetString("FrmISOMaker", 9))) { MessageBox.Show(Localization.GetString("FrmISOMaker", 9), ""); return; } var directory = new DirectoryInfo(lblDirectory.Content.ToString()); var files = directory.GetFiles("*", SearchOption.AllDirectories); var filtered = files.Select(f => f) .Where(f => (f.Attributes & FileAttributes.Directory) != FileAttributes.Directory); if (!filtered.Any()) { MessageBox.Show(Localization.GetString("FrmISOMaker", 21), Localization.GetString("Global", 68)); return; } var timer = new ElapsedTimer(ref txtTime); timer.Start(); Enable(false); cancel = false; lblStatus.Text = Localization.GetString("FrmISOMaker", 18) + "..."; btnCreateISO.Label = Localization.GetString("Global", 66); var folder = lblDirectory.Content.ToString(); var isoPath = lblISO.Content.ToString(); iso = new ISO(folder, isoPath, txtLabel.Text); iso.ProgressChanged += iso_ProgressChanged; try { iso.CreateISO(); if (cancel) { pbProgress.Foreground = Brushes.Gold; DeleteISO(); lblStatus.Text = Localization.GetString("FrmISOMaker", 20); } else { lblStatus.Text = Localization.GetString("FrmISOMaker", 19); } } catch (Exception Ex) { DeleteISO(); lblStatus.Text = Localization.GetString("Global", 67) + ": " + Ex.Message; pbProgress.Foreground = Brushes.Red; } timer.Stop(); Enable(true); btnCreateISO.Label = Localization.GetString("FrmISOMaker", 6); btnCreateISO.IsEnabled = true; } else { cancel = true; pbProgress.Foreground = Brushes.Gold; btnCreateISO.IsEnabled = false; iso.Cancel(); } }
private void BtnConvert_OnClick(object sender, RoutedEventArgs e) { if (_conversionList.Count == 0) { MessageBox.Show(Localization.GetString("Global", 50), Localization.GetString("Global", 51)); return; } var output = lblOutput.Content.ToString(); if (!lblOutput.Content.ToString().ContainsIgnoreCase(":\\")) { MessageBox.Show(Localization.GetString("Global", 52), Localization.GetString("Global", 53)); return; } lblStatus.Text = Localization.GetString("Global", 48); pbProgress.Value = 0; pbProgress.Maximum = _conversionList.Count; lblProgress.Content = "0%"; dgUpdates.Disable(); rbnMain.IsEnabled = false; _tim = new ElapsedTimer(ref txtTime); _tim.Start(); var amountConverted = 0; Task.Factory.StartNew(delegate { Parallel.ForEach(_conversionList, new ParallelOptions { MaxDegreeOfParallelism = Options.MaxThreads }, currentFile => { currentFile.Status = currentFile.Convert(output); amountConverted++; pbProgress.Dispatcher.BeginInvoke(new Action(() => { pbProgress.Value++; var progress = (pbProgress.Value / pbProgress.Maximum) * 100; lblStatus.Text = amountConverted + " / " + _conversionList.Count + " " + Localization.GetString("Global", 49); lblProgress.Content = Math.Round(progress, 1) + "%"; dgUpdates.Items.Refresh(); })); }); }).ContinueWith(continuation => { IEnumerable <string> fileList = Directory.GetFiles(output, "*.xml", SearchOption.TopDirectoryOnly).ToArray(); if (!fileList.Any()) { return; } fileList = Directory.GetFiles(output, "*.msp", SearchOption.TopDirectoryOnly).ToArray(); if (!fileList.Any()) { return; } lblStatus.Dispatcher.BeginInvoke( new Action(() => { lblStatus.Text = Localization.GetString("Global", 47); })); Parallel.ForEach(fileList, new ParallelOptions { MaxDegreeOfParallelism = Options.MaxThreads }, xmlFile => { xmlFile = Path.GetDirectoryName(xmlFile) + "\\" + Path.GetFileNameWithoutExtension(xmlFile) + ".xml"; FileHandling.DeleteFile(xmlFile); }); }).ContinueWith(continuation => { _tim.Stop(); lblStatus.Dispatcher.BeginInvoke(new Action(() => { lblStatus.Text = _conversionList.Count(c => c.Status == Status.Success) + " " + Localization.GetString("FrmLMM", 8); dgUpdates.Enable(); rbnMain.IsEnabled = true; if (chkOpenExplorer.IsChecked == true) { Processes.OpenExplorer(output); } })); }); }