/// <summary> /// Meldet, dass eine Quellgruppe (Transponder) vollständig untersucht wurde. /// </summary> /// <returns>Gesetzt, wenn der Suchlauf fortgesetzt werden soll.</returns> private bool OnUpdateScan() { // Attach to the scanner TransponderScanner scanner = m_Scanner; // Already done? if (null == scanner) { return(false); } // Total int total = 0; // Fill counters foreach (int sources in scanner.SourcesFound.Values) { total += sources; } // Remember m_ScanSources = total; // Try to get a new progress value decimal newProgress = 0; // See if we are already on if (scanner.TotalLocations > 0) { // Get the fraction per location decimal step = 1000m / scanner.TotalLocations; // Load the bias newProgress = (scanner.CurrentLocation - 1) * step; // Get the total number of groups int totalGroups = scanner.CurrentLocationGroup + scanner.CurrentLocationGroupsPending; // Be safe if (totalGroups > 0) { newProgress += step * scanner.CurrentLocationGroup / totalGroups; } } else { // Done when we started newProgress = 1000m; } // Store m_ScanProgress = (int)newProgress; // See if we are aborting return(null == m_ScanAbort); }
/// <summary> /// Beendet einen Sendersuchlauf auf dem aktuellen Geräteprofil. /// </summary> /// <param name="updateProfile">Gesetzt, wenn das Geräteprofil aktualisiert werden soll.</param> protected override void OnEndScan(bool?updateProfile) { // Process Start(device => { // Check mode if (m_ScanProgress < 0) { CardServerException.Throw(new SourceUpdateNotActiveFault()); } if (null != m_ScanAbort) { CardServerException.Throw(new SourceUpdateNotActiveFault()); } // Install action m_ScanAbort = () => { // With cleanup using (TransponderScanner scanner = m_Scanner) { // Mark as done m_ScanProgress = -1; m_Scanner = null; // Check mode if (updateProfile.HasValue) { // Do NOT merge if (!updateProfile.Value) { scanner.Profile.Locations.Clear(); } // Process scanner.UpdateProfile(); // Save it scanner.Profile.Save(); } } // Report ActionDone(null, null); }; // Done return(DelayedOperationTag); }); }
/// <summary> /// Beginnt mit der Ausführung dieser Aufgabe. /// </summary> /// <returns>Gesetzt, wenn die Aufgabe abgeschlossen werden konnte.</returns> bool IPlugInControl.Start() { // Create scanner m_Scanner = new TransponderScanner(m_PlugIn.Profile); // Connect all events m_Scanner.OnStartGroup += (l, g, s) => UpdateCounter(string.Format("{0} {1}", g, l)); m_Scanner.OnStartLocation += (l, s) => UpdateCounter(null); m_Scanner.OnDoneGroup += (l, g, s) => UpdateCounter(null); m_Scanner.OnDoneLocation += (l, s) => UpdateCounter(null); // Start with counter UpdateCounter(null); // Start the scan m_Scanner.Analyse(); // Start the timer ticker.Enabled = true; // Runs in background return(false); }
/// <summary> /// Beginnt einen Sendersuchlauf auf dem aktuellen Geräteprofil. /// </summary> protected override void OnStartScan() { // Process Start(device => { // Check mode if (EPGProgress.HasValue) { CardServerException.Throw(new EPGActiveFault()); } if (m_ScanProgress >= 0) { CardServerException.Throw(new SourceUpdateActiveFault()); } if (!string.IsNullOrEmpty(Profile.UseSourcesFrom)) { CardServerException.Throw(new NoSourceListFault(Profile.Name)); } // Stop all RemoveAll(); // Create scanner m_Scanner = new TransponderScanner(Profile); // Configure m_Scanner.OnDoneLocation += (l, s) => OnUpdateScan(); m_Scanner.OnDoneGroup += (l, g, s) => OnUpdateScan(); // Mark as started m_ScanProgress = 0; m_ScanSources = 0; // Start it m_Scanner.Scan(); }); }
/// <summary> /// Wird während der Ausführung periodisch aufgerufen. /// </summary> /// <param name="sender">Wird ignoriert.</param> /// <param name="e">Wird ignoriert.</param> private void ticker_Tick(object sender, EventArgs e) { // See if scanner is done if (!m_Scanner.Done) { return; } // Stop timer ticker.Enabled = false; // Final update UpdateCounter(null); // Prepare to terminate using (TransponderScanner scanner = m_Scanner) { // Forget m_Scanner = null; // Must finish try { // Process all scan locations found foreach (ScanLocation location in scanner.ScanLocations) { // Configure if (!string.IsNullOrEmpty(location.UniqueName)) { dlgSave.FileName = location.UniqueName + "." + dlgSave.DefaultExt; } // Ask user what to do if (DialogResult.OK != dlgSave.ShowDialog(this)) { continue; } // Update inner name if (string.IsNullOrEmpty(location.DisplayName)) { location.DisplayName = Path.GetFileNameWithoutExtension(dlgSave.FileName); } // Create wrapper ScanLocations save = new ScanLocations(); // Add this one save.Locations.Add(location); // Save to disk save.Save(dlgSave.FileName); } } finally { // Report to site m_Site.OperationDone(); } } }
/// <summary> /// Wird in einem festen Interval aufgerufen und prüft, ob die Operation bereits abgeschlossen ist /// oder abgebrochen werden soll. /// </summary> /// <param name="sender">Wird ignoriert.</param> /// <param name="e">Wird ignoriert.</param> private void tickEnd_Tick(object sender, EventArgs e) { // See if scanner is done if (!m_Scanner.Done) { return; } // Stop timer tickEnd.Enabled = false; // Final update UpdateCounter(null); // Prepare to terminate using (TransponderScanner scanner = m_Scanner) { // Forget m_Scanner = null; // Must finish try { // Check for error var error = scanner.Error; if (error != null) { MessageBox.Show(this, error.ToString(), Properties.Resources.Scanner_Error, MessageBoxButtons.OK, MessageBoxIcon.Warning); } // Create question string quest = string.Format(Properties.Resources.Save_Profile, scanner.Profile.Name); // Ask user DialogResult saveMode = MessageBox.Show(this, quest, Properties.Resources.Save_Profile_Titel, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); // Profile if (DialogResult.Cancel != saveMode) { // Check for reset if (!ckMerge.Checked) { scanner.Profile.Locations.Clear(); } // Update in memory scanner.UpdateProfile(); // Save to disk scanner.Profile.Save(); } // Protocol if (DialogResult.Yes == saveMode) { if (DialogResult.OK == saveProtocol.ShowDialog(this)) { using (StreamWriter protocol = new StreamWriter(saveProtocol.FileName, false, Encoding.Unicode)) { // Head line protocol.WriteLine(ProtocolRecord.LineFormat); // All lines foreach (ProtocolRecord record in scanner.Protocol) { protocol.WriteLine(record); } } } } } finally { // Report to site m_Site.OperationDone(); } } }