public RemoveQuotesForm(IQMDataCollection collection) { InitializeComponent(); mOrgCollection = collection; // fills the list view with all the data stored in the cache. foreach (IQMData data in collection) { ListViewItem item = listViewData.Items.Add(data.Instrument); item.SubItems.Add(data.Timeframe); item.SubItems.Add(data.Year.ToString()); item.SubItems.Add(data.Size.ToString()); } }
/// <summary> /// RemoveQuotes controller event: Cache content description is prepared /// </summary> /// <param name="collection"></param> private void RemoveQuotesController_Prepared(IQMDataCollection collection) { // In some cases the event might be received from the other thread if (this.InvokeRequired) { this.BeginInvoke(new RemoveQuotesController_Prepared(RemoveQuotesController_Prepared), collection); } else { // Show the form to choose the data to remove RemoveQuotesForm form = new RemoveQuotesForm(collection); if (form.ShowDialog(this) == DialogResult.OK && form.ToRemove.Count > 0) { // and if any data is chosen - remove then mRemoveController.RemoveData(form.ToRemove); } // ...the result will be passed to RemoveQuotesController_Removed event } }
/// <summary> /// Shows quotes that are available in local cache. /// </summary> /// <param name="quotesManager">QuotesManager instance</param> static void ShowLocalQuotes(QuotesManager quotesManager) { if (quotesManager == null) { Console.WriteLine("Failed to get local quotes"); return; } // if the instruments list is not updated, update it now if (!quotesManager.areInstrumentsUpdated()) { UpdateInstrumentsListener instrumentsCallback = new UpdateInstrumentsListener(); UpdateInstrumentsTask task = quotesManager.createUpdateInstrumentsTask(instrumentsCallback); quotesManager.executeTask(task); instrumentsCallback.WaitEvents(); } IQMDataCollection collection = PrepareListOfQMData(quotesManager); ShowPreparedQMDataList(collection); }
/// <summary> /// Show list of available quotes. /// </summary> /// <param name="collection">Collection of quotes manager storage data</param> static void ShowPreparedQMDataList(IQMDataCollection collection) { IDictionary <string, IDictionary <int, long> > instrumentsInfo = SummariseInstrumentDataSize(collection); if (instrumentsInfo == null || instrumentsInfo.Count == 0) { Console.WriteLine("There are no quotes in the local storage."); } else { Console.WriteLine("Quotes in the local storage"); foreach (string instrument in instrumentsInfo.Keys) { IDictionary <int, long> sizeByYear = instrumentsInfo[instrument]; foreach (int year in sizeByYear.Keys) { Console.WriteLine(" {0} {1} {2}", instrument, year, ReadableSize(sizeByYear[year])); } } } }
/// <summary> /// Get full size of available instrument's quotes. /// </summary> /// <param name="collection">Collection of quotes manager storage data</param> /// <returns>Collection of info about quotes in starage</returns> static IDictionary <string, IDictionary <int, long> > SummariseInstrumentDataSize(IQMDataCollection collection) { if (collection == null || collection.Count == 0) { return(null); } IDictionary <string, IDictionary <int, long> > instrumentsInfo = new Dictionary <string, IDictionary <int, long> >(); foreach (IQMData quote in collection) { string instrument = quote.Instrument; if (!instrumentsInfo.ContainsKey(instrument)) { instrumentsInfo[instrument] = new Dictionary <int, long>(); } int year = quote.Year; if (!instrumentsInfo[instrument].ContainsKey(year)) { instrumentsInfo[instrument][year] = 0; } instrumentsInfo[instrument][year] += quote.Size; } return(instrumentsInfo); }