public static T Load <T>(string _filePath, bool _showErrorMessage) { T loadedObject = default(T); FileStream fs = null; try { fs = new System.IO.FileStream(_filePath, FileMode.Open); } catch (FileNotFoundException ex) { return(default(T)); } BinaryFormatter formatter = new BinaryFormatter(); formatter.Binder = new MyBinaryFormatterBinder(); try { loadedObject = (T)formatter.Deserialize(fs); } catch (Exception ex) { if (_showErrorMessage) { UserMessages.ShowErrorMessage(ex, null); } return(default(T)); } finally { fs.Close(); } return(loadedObject); }
private void startTracking(string taskName) { try { this.TimeToShowForm = 2000; //use default value this.label.Text = taskName; this.label.Enabled = true; this.button_stop.Visible = false; this.bar.Visible = false; this.form.Height = this.formHeight2; this.watch_showStopButton.Reset(); //this.watch_showStopButton.Start(); this.watch_showForm.Reset(); this.watch_showForm.Start(); this.timer.Start(); this.StopTask = false; this.RunningTask = true; } catch (Exception ex) { stopTracking(); UserMessages.ShowErrorMessage(ex, this.form); } }
private void showForm_newThread() { try { if (this.watch_showForm.ElapsedMilliseconds > this.TimeToShowForm) { this.m_formShowing = true; var startProgressWindow = Task.Factory.StartNew(() => { try { this.form.ShowDialog(); } catch { this.m_formShowing = false; return; } }); MultiThreadMethods.WaitForFormToShowWithTimeOut(this.form, 100, 1000); } } catch (Exception ex) { UserMessages.ShowErrorMessage(ex, this.form); } }
private void trackProgress() { try { if (this.RunningTask == false || StopTask == true || this.Current < this.bar.Minimum || this.Current > this.bar.Maximum) { return; } this.bar.Value = this.Current; this.form.BringToFront(); //often form appears behind if (this.button_stop.Visible == false) { if (this.watch_showStopButton.ElapsedMilliseconds > this.TimeToShowStopButton) { this.button_stop.Visible = true; } } } catch (Exception ex) { stopTracking(); UserMessages.ShowErrorMessage(ex, this.form); } }
private void startTracking(string taskName, int min, int max, int timeToShowWindow, int timeToShowStopButton) { try { this.TimeToShowForm = timeToShowWindow; this.TimeToShowStopButton = timeToShowStopButton; this.label.Text = taskName; this.label.Enabled = true; this.button_stop.Enabled = true; this.form.Height = this.formHeight2; this.Current = min; this.bar.Minimum = min; this.bar.Value = min; this.bar.Maximum = max; this.bar.Enabled = true; this.bar.Visible = true; this.watch_showStopButton.Reset(); this.watch_showStopButton.Start(); this.watch_showForm.Reset(); this.watch_showForm.Start(); this.timer.Start(); this.RunningTask = true; } catch (Exception ex) { stopTracking(); UserMessages.ShowErrorMessage(ex, this.form); } }
private void stopTracking(string message, bool showMessageBox) { try { stopTracking(); this.label.Text = message; if (showMessageBox) { UserMessages.ShowMessage(message); } if (this.StopTask) { this.StopTask = false; } } catch (Exception ex) { UserMessages.ShowErrorMessage(ex, this.form); } }
private void stopTracking() { try { this.watch_showStopButton.Reset(); this.watch_showForm.Reset(); this.timer.Stop(); this.RunningTask = false; this.Current = 1; if (this.form.Visible) { this.form.Hide(); this.m_formShowing = false; } } catch (Exception ex) { UserMessages.ShowErrorMessage(ex, this.form); } }
public static bool Save(object _object, string _filePath, bool _showError) { System.IO.FileStream fs = new FileStream(_filePath, FileMode.Create); BinaryFormatter formatter = new BinaryFormatter(); try { formatter.Serialize(fs, _object); return(true); } catch (Exception ex) { if (_showError) { UserMessages.ShowErrorMessage(ex, null); } return(false); } finally { fs.Close(); } }
public static T Load <T>(string _filePath, bool _showErrorMessage) { T loadedObject = default(T); FileStream fs = null; try { fs = new System.IO.FileStream(_filePath, FileMode.Open); } catch (FileNotFoundException ex) { return(default(T)); } BinaryFormatter formatter = new BinaryFormatter(); formatter.Binder = new MyBinaryFormatterBinder(); try { loadedObject = (T)formatter.Deserialize(fs); //deserialize could throw "unable to find assembly" //exception when using addin manager. Goes away when //loaded in Revit. } catch (Exception ex) { if (_showErrorMessage) { UserMessages.ShowErrorMessage(ex, null); } return(default(T)); } finally { fs.Close(); } return(loadedObject); }