private void textBox_TextChanged(object sender, TextChangedEventArgs e) { try { if (!String.IsNullOrEmpty(textBox.Text)) { if (!this.TimerDisabled) { _timer.Change(Delay, Delay); } } else { Trigger(); } if (TextChanged != null) { this.InvokeIfRequired(() => { TextChanged(sender, e); }); } } catch (Exception ex) { GlobalExceptionHandler.Handle(ex); } }
public static void QueueJob(Action job) { ThreadPool.QueueUserWorkItem((ignored) => { try { job(); } catch (Exception ex) { GlobalExceptionHandler.Handle(ex); } }); }
void txt_TextChanged(object sender, TextChangedEventArgs e) { if (!_ignoreTextChanged) { try { _timer.Change(_delay, _delay); } catch (Exception ex) { GlobalExceptionHandler.Handle(ex); } } }
/// <summary> /// Static initialiser /// </summary> static Config() { try { // config is stored on a per user basis in the local app data folder string path = String.Format("{0}\\BioLink", Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string configFile = string.Format("{0}\\BioLink.cfg", path); _instance = new ConfigurationStore(configFile); } catch (Exception ex) { GlobalExceptionHandler.Handle(ex); } }
void TextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) { try { if (!String.IsNullOrEmpty(Text)) { _timer.Change(_delay, _delay); } else { Trigger(); } } catch (Exception ex) { GlobalExceptionHandler.Handle(ex); } }
private void Trigger() { try { _timer.Change(Timeout.Infinite, Timeout.Infinite); if (TypingPaused != null) { string text = null; textBox.InvokeIfRequired(() => { text = textBox.Text; TypingPaused(text); }); } } catch (Exception ex) { GlobalExceptionHandler.Handle(ex); } }
private void Trigger() { try { _timer.Change(Timeout.Infinite, Timeout.Infinite); this.InvokeIfRequired(() => { BindingExpression expr = GetBindingExpression(TextBox.TextProperty); if (expr != null) { if (expr.Status == BindingStatus.Active) { expr.UpdateSource(); } } }); } catch (Exception ex) { GlobalExceptionHandler.Handle(ex); } }
private void SaveAll() { var dlg = new System.Windows.Forms.FolderBrowserDialog(); dlg.ShowNewFolderButton = true; var result = dlg.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { JobExecutor.QueueJob(() => { if (Progress != null) { Progress.ProgressStart("Exporting files..."); } int count = 0; foreach (MultimediaLinkViewModel vm in _model) { var destFile = string.Format("{0}\\{1}.{2}", dlg.SelectedPath, vm.Name, vm.Extension); var filename = _tempFileManager.GetContentFileName(vm.MultimediaID, vm.Extension); try { File.Copy(filename, destFile, true); count++; if (Progress != null) { double percent = (((double)count) / ((double)_model.Count)) * 100.0; Progress.ProgressMessage(string.Format("Exporting files ({0} of {1})", count, _model.Count), percent); } } catch (Exception ex) { GlobalExceptionHandler.Handle(ex); } } if (Progress != null) { Progress.ProgressEnd(string.Format("{0} files exported.", count)); } }); } }
private void Trigger() { try { _timer.Change(Timeout.Infinite, Timeout.Infinite); this.InvokeIfRequired(() => { var range = new TextRange(Document.ContentStart, Document.ContentEnd); string rtf; using (var stream = new MemoryStream()) { range.Save(stream, DataFormats.Rtf); stream.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(stream)) { rtf = reader.ReadToEnd(); } } _selfSetting = true; RTF = rtf; _selfSetting = false; }); } catch (Exception ex) { GlobalExceptionHandler.Handle(ex); } }
public UpdateCheckResults CheckForUpdates(IProgressObserver progress) { // Get the running apps version to compare... // We need to use the parent window because its the main application assembly version we want, not this plugin. var v = PluginManager.Instance.ParentWindow.GetType().Assembly.GetName().Version; var results = new UpdateCheckResults { CurrentMajor = v.Major, CurrentMinor = v.Minor, CurrentBuild = v.Revision, UpdateExists = false, UpdateLink = "" }; if (progress != null) { progress.ProgressStart("Checking for updates..."); } Config.SetGlobal("BioLink.UpdateURL", "http://downloads.ala.org.au/feed/p/biolink"); var updateURL = Config.GetGlobal("BioLink.UpdateURL", "http://downloads.ala.org.au/feed/p/biolink"); try { if (progress != null) { progress.ProgressMessage("Contacting update site..."); } var reader = XmlReader.Create(updateURL); var feed = SyndicationFeed.Load(reader); if (progress != null) { progress.ProgressMessage("Checking update site data..."); } var pattern = new Regex(@"BioLinkInstaller-(\d+)[.](\d+)[.](\d+)[.]exe"); foreach (SyndicationItem item in feed.Items) { foreach (var link in item.Links) { var m = pattern.Match(link.Uri.AbsoluteUri); if (m.Success) { bool updateExists = false; var major = Int32.Parse(m.Groups[1].Value); var minor = Int32.Parse(m.Groups[2].Value); var build = Int32.Parse(m.Groups[3].Value); if (major > results.CurrentMajor) { updateExists = true; } else if (major == results.CurrentMajor) { if (minor > results.CurrentMinor) { updateExists = true; } else if (minor == results.CurrentMinor) { updateExists = build > results.CurrentBuild; } } if (updateExists) { results.UpdateMajor = major; results.UpdateMinor = minor; results.UpdateBuild = build; results.UpdateExists = true; results.UpdateLink = link.Uri.AbsoluteUri; return(results); } } } } } catch (Exception ex) { GlobalExceptionHandler.Handle(ex); } finally { if (progress != null) { progress.ProgressEnd("Update check complete."); } } return(results); }
public static void GeoTag(GeoCodingAction geoCodeAction, double?startLat, double?startLon) { try { var ge = (dynamic)Interaction.CreateObject("GoogleEarth.ApplicationGE"); if (ge != null) { int gHandle = ge.GetMainHwnd(); SetForegroundWindow(gHandle); if (startLat.HasValue && startLon.HasValue) { try { var camera = ge.GetCamera(false); camera.FocusPointLatitude = startLat.Value; camera.FocusPointLongitude = startLon.Value; camera.FocusPointAltitude = 0; camera.Range = 5000; camera.Tilt = 0; ge.SetCamera(camera, 3); } catch (Exception) { } } // The KMZ file is a zip file containing a reticle png and kml file that will place the cross hairs on the google earth view (via temporary locations)... string kmzFile = PluginManager.Instance.ResourceTempFileManager.ProxyResource(new Uri("pack://application:,,,/BioLink.Client.Extensibility;component/Resources/Target.kmz")); ge.OpenKmlFile(kmzFile, true); var dlg = new GoogleEarthGeoTag(() => { var point = (dynamic)ge.GetPointOnTerrainFromScreenCoords(0, 0); double lat = point.Latitude; double lon = point.Longitude; double alt = point.Altitude; if (geoCodeAction != null) { geoCodeAction(lat, lon, (int)alt); } }); // Position the dialog in the lower left region of the GE window... RECT rect; GetWindowRect(gHandle, out rect); dlg.Top = rect.Bottom - (dlg.Height + 80); dlg.Left = rect.Right - (dlg.Width + 40); // This will suspend the thread until the dialog is closed... dlg.ShowDialog(); // Geocoded or not, if we get here we need to remove our cross hair... // Hokey way of removing the cross hair feature...but there does not seem to be a way to do it via the COM interface try { for (int i = 0; i < 5; i++) { var rmvFeature = ge.GetFeatureByName("BioLink Geo Coding"); if (rmvFeature == null) { break; } rmvFeature.Highlight(); SetForegroundWindow(gHandle); System.Windows.Forms.SendKeys.SendWait("{DELETE}"); System.Windows.Forms.SendKeys.SendWait("{ENTER}"); } } catch (Exception) { // ignore } } } catch (Exception ex) { GlobalExceptionHandler.Handle(ex); } }
public void CommitPendingChanges(Action successAction = null) { if (User == null) { throw new Exception("User object has not been set on the Control Host Window"); } #if DEBUG Logger.Debug("About to commit the following changes:"); foreach (DatabaseCommand command in _pendingChanges) { Logger.Debug("{0}", command); } #endif // First validate each command...Commands can produce messages if they are not valid. var errorMessages = new List <string>(); var warningMessages = new List <string>(); var messages = new ValidationMessages(); foreach (DatabaseCommand command in _pendingChanges) { command.Validate(messages); } if (messages != null && messages.Messages.Count > 0) { foreach (ValidationMessage message in messages.Messages) { switch (message.ValidationType) { case ValidationType.Error: errorMessages.Add(message.Message); break; case ValidationType.Warning: warningMessages.Add(message.Message); break; } } } if (errorMessages.Count > 0) { ErrorMessage.Show("One or more validation errors occured:\n\n{0}\n\nOperation aborted.", errorMessages.Join("\n\n")); return; } if (warningMessages.Count > 0) { if (!WarningMessage.Show("Please acknowledge the following warning(s) by clicking 'yes' to continue this operation, or 'no' to cancel this operation:\n\n{0}\n\nDo you wish to continue?", warningMessages.Join("\n\n"))) { return; } } // It may be that this control is aggregated as part of a larger control. This means that, come save time, there // may already be a transaction pending. If so, don't create a new one, just piggy back on the existing bool commitTrans = false; // flag to let us know if we are responsible for the transaction... if (!User.InTransaction) { User.BeginTransaction(); commitTrans = true; } try { foreach (DatabaseCommand command in _pendingChanges) { command.Process(User); } if (commitTrans) { User.CommitTransaction(); } if (successAction != null) { successAction(); } foreach (IChangeContainerObserver observer in _observers) { observer.OnChangesCommitted(); } if (ChangesCommitted != null) { ChangesCommitted(this); } _observers.Clear(); _pendingChanges.Clear(); // Reload the pinboard... JobExecutor.QueueJob(() => { PluginManager.Instance.RefreshPinBoard(); }); } catch (Exception ex) { if (commitTrans) { User.RollbackTransaction(); } GlobalExceptionHandler.Handle(ex); } }
private void LoadPlugins(PluginAction pluginAction, params string[] paths) { using (new CodeTimer("Plugin loader")) { FileSystemTraverser t = new FileSystemTraverser(); NotifyProgress("Searching for extensions...", -1, ProgressEventType.Start); List <Type> extensionTypes = new List <Type>(); foreach (string pathelement in paths) { string path = pathelement; string filterexpr = ".*[.]dll$"; if (path.Contains("|")) { path = pathelement.Substring(0, pathelement.IndexOf("|")); filterexpr = pathelement.Substring(pathelement.IndexOf("|") + 1); } Regex regex = new Regex(filterexpr, RegexOptions.IgnoreCase); FileSystemTraverser.Filter filter = (fileinfo) => { return(regex.IsMatch(fileinfo.Name)); }; Logger.Debug("LoadPlugins: Scanning: {0}", path); t.FilterFiles(path, filter, fileinfo => { ProcessAssembly(fileinfo, extensionTypes); }, false); } NotifyProgress("Loading plugins...", 0, ProgressEventType.Start); int i = 0; foreach (Type type in extensionTypes) { try { Logger.Debug("Instantiating type {0}", type.FullName); IBioLinkExtension extension = InstantiateExtension(type); if (extension != null) { if (extension is IBioLinkPlugin) { IBioLinkPlugin plugin = extension as IBioLinkPlugin; Logger.Debug("Initializing Plugin {0}...", plugin.Name); plugin.InitializePlugin(User, this, this.ParentWindow); Logger.Debug("Integrating Plugin...", plugin.Name); // Allow the consumer to process this plugin... if (pluginAction != null) { pluginAction(plugin); } } _extensions.Add(extension); double percentComplete = ((double)++i / (double)extensionTypes.Count) * 100.0; NotifyProgress(extension.Name, percentComplete, ProgressEventType.Update); } DoEvents(); } catch (Exception ex) { GlobalExceptionHandler.Handle(ex); } } // Fire an event signalling plugin loading is complete, and all plugins have been initialized if (this.PluginsLoaded != null) { PluginsLoaded(this); } NotifyProgress("Plugin loading complete", 100, ProgressEventType.End); } }