protected override void PrepareContainerForItemOverride(DependencyObject element, object item) { using (PerformanceBlock.Create(ComponentId.Money, CategoryId.View, MeasurementId.PrepareContainerForItemOverride)) { base.PrepareContainerForItemOverride(element, item); } }
public CategoryChart() { #if PerformanceBlocks using (PerformanceBlock.Create(ComponentId.Money, CategoryId.View, MeasurementId.CategoryChartInitialize)) { #endif InitializeComponent(); IsVisibleChanged += new DependencyPropertyChangedEventHandler(OnIsVisibleChanged); unassigned = new Category() { Name = "Unknown", Type = Data.CategoryType.None }; transferredIn = new Category() { Name = "Transferred In", Type = Data.CategoryType.Transfer }; transferredOut = new Category() { Name = "Transferred Out", Type = Data.CategoryType.Transfer }; PieChart.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(PieChart_MouseLeftButtonDown); #if PerformanceBlocks } #endif }
public CategoriesControl() { #if PerformanceBlocks using (PerformanceBlock.Create(ComponentId.Money, CategoryId.View, MeasurementId.CategoriesControlInitialize)) { #endif InitializeComponent(); this.treeView.SelectedItemChanged += new RoutedPropertyChangedEventHandler <object>(OnSelectedItemChanged); this.treeView.Loaded += new RoutedEventHandler(OnTreeViewLoaded); this.IsVisibleChanged += new DependencyPropertyChangedEventHandler(OnIsVisibleChanged); this.dragDropSupport = new DragAndDrop( this.treeView, this.dragDropformatNameForCategory, this.OnDragDropObjectSource, this.OnDragDropObjectTarget, this.OnDragDropSourceOnTarget ); #if PerformanceBlocks } #endif }
public AccountsControl() { #if PerformanceBlocks using (PerformanceBlock.Create(ComponentId.Money, CategoryId.View, MeasurementId.AccountsControlInitialize)) { #endif InitializeComponent(); this.listBox1.PreviewMouseDown += new MouseButtonEventHandler(listBox1_PreviewMouseDown); this.listBox1.SelectionChanged += new SelectionChangedEventHandler(OnListBoxSelectionChanged); this.listBox1.MouseDoubleClick += new MouseButtonEventHandler(OnListBoxMouseDoubleClick); foreach (object o in AccountsControlContextMenu.Items) { MenuItem m = o as MenuItem; if (m != null) { m.CommandTarget = this; } } #if PerformanceBlocks } #endif }
public CategoryChart() { #if PerformanceBlocks using (PerformanceBlock.Create(ComponentId.Money, CategoryId.View, MeasurementId.CategoryChartInitialize)) { #endif InitializeComponent(); IsVisibleChanged += new DependencyPropertyChangedEventHandler(OnIsVisibleChanged); unassigned = new Category() { Name = "Unknown", Type = Data.CategoryType.None }; transferredIn = new Category() { Name = "Transferred In", Type = Data.CategoryType.Transfer }; transferredOut = new Category() { Name = "Transferred Out", Type = Data.CategoryType.Transfer }; this.PieChart.PieSliceClicked += OnPieSliceClicked; this.PieChart.PieSliceHover += OnPieSliceHovered; this.PieChart.ToolTipGenerator = OnGenerateTip; this.Legend.Toggled += OnLegendToggled; #if PerformanceBlocks } #endif }
/// <summary> /// This runs on a background thread and finds all attachments and updates the HasAttachment /// flag on all transactions. /// </summary> /// <param name="state"></param> public void ScanDirectory() { // set of transactions that have attachments. Thread.Sleep(1000); // give app time to startup... #if PerformanceBlocks using (PerformanceBlock.Create(ComponentId.Money, CategoryId.Model, MeasurementId.ScanAttachments)) { #endif try { string path = this.AttachmentDirectory; if (!string.IsNullOrEmpty(path) && Directory.Exists(path) && this.money != null) { // process pending account checks Account a; while (accountQueue.TryDequeue(out a) && threadRunning) { FindAttachments(path, a); } // process pending individual transaction checks. List <Tuple <Transaction, bool> > toUpdate = new List <Tuple <Transaction, bool> >(); Transaction t; while (transactionQueue.TryDequeue(out t) && threadRunning) { bool yes = HasAttachments(path, t); if (t.HasAttachment != yes) { toUpdate.Add(new Tuple <Transaction, bool>(t, yes)); } } // Updating Money transactions has to happen on the UI thread. UiDispatcher.BeginInvoke(new Action(() => { BatchUpdate(toUpdate); })); } } catch { } #if PerformanceBlocks } #endif threadRunning = false; threadStopEvent.Set(); }
public SecuritiesControl() { #if PerformanceBlocks using (PerformanceBlock.Create(ComponentId.Money, CategoryId.View, MeasurementId.SecuritiesControlInitialize)) { #endif InitializeComponent(); this.MouseUp += new MouseButtonEventHandler(OnMouseUp); this.listbox1.SelectionChanged += new SelectionChangedEventHandler(OnSelectionChanged); this.dragDropSupport = new DragAndDrop(listbox1, this.dragDropformatNameForSecurity, OnDragSource, OnDropTarget, OnDropSourceOnTarget); this.IsVisibleChanged += new DependencyPropertyChangedEventHandler(OnIsVisibleChanged); #if PerformanceBlocks } #endif }
void MyApplicationStartup(object sender, StartupEventArgs e) { Settings settings = null; #if PerformanceBlocks using (PerformanceBlock.Create(ComponentId.Money, CategoryId.View, MeasurementId.AppInitialize)) { #endif HelpService.Initialize(); Process currentRunningInstanceOfMyMoney = null; if (SaveImportArgs()) { // Application is running Process command line args currentRunningInstanceOfMyMoney = BringToFrontApplicationIfAlreadyRunning(); } bool noSettings = false; foreach (string arg in e.Args) { if (string.Compare(arg, "/nosettings", StringComparison.OrdinalIgnoreCase) == 0) { noSettings = true; } } if (currentRunningInstanceOfMyMoney != null) { // Let the currently running application handle the IMPORT file // we can close this instance Shutdown(); return; } // Load the application settings settings = LoadSettings(noSettings); #if PerformanceBlocks } #endif // Lets run the application since there's no another instance running MainWindow mainWindow = new MainWindow(settings); mainWindow.Show(); }
public static DownloadLog Load(string logFolder) { DownloadLog log = new DownloadLog(); var filename = System.IO.Path.Combine(logFolder, "DownloadLog.xml"); if (System.IO.File.Exists(filename)) { #if PerformanceBlocks using (PerformanceBlock.Create(ComponentId.Money, CategoryId.View, MeasurementId.LoadStockDownloadLog)) { #endif try { XmlSerializer s = new XmlSerializer(typeof(DownloadLog)); using (XmlReader r = XmlReader.Create(filename)) { log = (DownloadLog)s.Deserialize(r); } } catch (Exception) { // got corrupted? no problem, just start over. log = new DownloadLog(); } log._logFolder = logFolder; // ensure unique list. foreach (var info in log.Downloaded.ToArray()) { log._downloaded[info.Symbol] = info; } if (log._downloaded.Count != log.Downloaded.Count) { log.Downloaded.Clear(); foreach (var info in log._downloaded.Values) { log.Downloaded.Add(info); } } #if PerformanceBlocks } #endif } return(log); }
/// <summary> /// This runs on a background thread and finds all attachments and updates the HasAttachment /// flag on all transactions. /// </summary> /// <param name="state"></param> public void ScanDirectory(object state) { // set of transactions that have attachments. Thread.Sleep(1000); // give app time to startup... #if PerformanceBlocks using (PerformanceBlock.Create(ComponentId.Money, CategoryId.Model, MeasurementId.ScanAttachments)) { #endif try { string path = this.AttachmentDirectory; HashSet <Transaction> changed = new HashSet <Transaction>(); if (!string.IsNullOrEmpty(path) && Directory.Exists(path) && this.money != null) { Account a; while (accountQueue.TryDequeue(out a) && threadRunning) { FindAttachments(path, a, changed); } this.money.BeginUpdate(); Transaction t; while (queue.TryDequeue(out t) && threadRunning) { bool yes = HasAttachments(path, t); if (t.HasAttachment != yes) { t.HasAttachment = yes; changed.Add(t); } } this.money.EndUpdate(); } } catch { } #if PerformanceBlocks } #endif threadRunning = false; threadStopEvent.Set(); }
protected override void OnInitialized(EventArgs e) { #if PerformanceBlocks using (PerformanceBlock.Create(ComponentId.Money, CategoryId.View, MeasurementId.AreaChartInitialize)) { #endif base.OnInitialized(e); nfi = new NumberFormatInfo(); nfi.CurrencyDecimalDigits = 0; nfi.CurrencySymbol = string.Empty; nfi.CurrencyNegativePattern = 0; this.Background = Brushes.Transparent; // so mouseclicks work. #if PerformanceBlocks } #endif }
public async void BeginFetchHistory(List <string> batch) { string singleton = null; bool busy = false; lock (_downloadSync) { busy = _downloadingHistory; if (busy) { if (batch.Count == 1) { // then we need this individual stock ASAP var item = batch[0]; if (_downloadBatch.Contains(item)) { _downloadBatch.Remove(item); } _downloadBatch.Insert(0, item); singleton = item; } else { // then merge the new batch with existing batch that we are downloading. foreach (var item in batch) { if (!_downloadBatch.Contains(item)) { _downloadBatch.Add(item); } } } } else { // starting a new download batch. _downloadBatch = new List <string>(batch); } } if (busy) { if (!string.IsNullOrEmpty(singleton)) { // in this case we want to load any cached history and make that available to unblock the UI thread ASAP // otherwise UI might be blocks on slow HTTP downloads. var history = await this._downloadLog.GetHistory(singleton); if (history != null && history.History != null && history.History.Count != 0) { // unblock the UI thread with the cached history for now. OnHistoryAvailable(history); } } // only allow one thread do all the downloading. return; } tokenSource = new CancellationTokenSource(); _downloadingHistory = true; while (_downloadingHistory) { string symbol = null; lock (_downloadSync) { if (_downloadBatch != null && _downloadBatch.Count > 0) { symbol = _downloadBatch.First(); _downloadBatch.Remove(symbol); } } if (symbol == null) { break; } else { #if PerformanceBlocks using (PerformanceBlock.Create(ComponentId.Money, CategoryId.View, MeasurementId.DownloadStockQuoteHistory)) { #endif StockQuoteHistory history = null; var info = this._downloadLog.GetInfo(symbol); history = await this._downloadLog.GetHistory(symbol); if (history == null) { history = new StockQuoteHistory() { Symbol = symbol }; } if (info != null && info.Downloaded.Date == DateTime.Today && history != null && history.Complete) { // already up to date } else { try { await _service.UpdateHistory(history); } catch (Exception ex) { OnError("Download history error: " + ex.Message); } } if (history != null && history.History != null && history.History.Count != 0) { OnHistoryAvailable(history); } #if PerformanceBlocks } #endif } } _downloadingHistory = false; while (_downloadingHistory && _downloadBatch.Count > 0) { Thread.Sleep(1000); // wait for download to finish. } _downloadingHistory = false; }
void MyApplicationStartup(object sender, StartupEventArgs e) { Settings settings = null; #if PerformanceBlocks using (PerformanceBlock.Create(ComponentId.Money, CategoryId.View, MeasurementId.AppInitialize)) { #endif HelpService.Initialize(); CleanUpOlderSpecialImportFile(); Process currentRunningInstanceOfMyMoney = null; if (IsCommandLineContainingValidImportFile()) { // Application is running Process command line args currentRunningInstanceOfMyMoney = BringToFrontApplicationIfAlreadyRunning(); } bool noSettings = false; foreach (string arg in e.Args) { if (string.Compare(arg, "/nosettings", StringComparison.OrdinalIgnoreCase) == 0) { noSettings = true; } } if (currentRunningInstanceOfMyMoney != null) { // Let the currently running application handle the IMPORT file // we can close this instance Shutdown(); return; } // this is a fallback theme for things not specified in more specific themes. ProcessHelper.SetTheme(0, "Themes/Generic.xaml"); if (Environment.OSVersion.Version >= new Version(6, 2)) { // windows 8 ProcessHelper.SetTheme(1, "Themes/GenericWindows8.xaml"); } else { // windows 7 ProcessHelper.SetTheme(1, "Themes/GenericWindows7.xaml"); } // Load the application settings settings = LoadSettings(noSettings); if (string.IsNullOrEmpty(settings.Theme)) { // this theme is the most tested right now... ProcessHelper.SetTheme(2, "Themes/Theme-VS2010.xaml"); } else { // set the user selected theme ProcessHelper.SetTheme(2, settings.Theme); } #if PerformanceBlocks } #endif // Lets run the application since there's no another instance running MainWindow mainWindow = new MainWindow(settings); mainWindow.Show(); }