/// <summary> /// Delete an instrument and all locally stored data. /// </summary> public static void RemoveInstrument(Instrument instrument, IDataStorage localStorage) { using (var entityContext = new MyDBContext()) { //hacking around the circular reference issue if (instrument.IsContinuousFuture) { entityContext.Instruments.Attach(instrument); var tmpCF = instrument.ContinuousFuture; instrument.ContinuousFuture = null; instrument.ContinuousFutureID = null; entityContext.SaveChanges(); entityContext.ContinuousFutures.Attach(tmpCF); entityContext.ContinuousFutures.Remove(tmpCF); entityContext.SaveChanges(); } entityContext.Instruments.Attach(instrument); entityContext.Instruments.Remove(instrument); entityContext.SaveChanges(); } localStorage.Connect(); localStorage.DeleteAllInstrumentData(instrument); }
/// <summary> /// Delete an instrument and all locally stored data. /// </summary> public async Task RemoveInstrument(Instrument instrument, IDataStorage localStorage) { Context.Instruments.Attach(instrument); Context.Instruments.Remove(instrument); await Context.DbContext.SaveChangesAsync().ConfigureAwait(false); localStorage.Connect(); localStorage.DeleteAllInstrumentData(instrument); }
//delete data from selected instruments private void ClearDataBtn_ItemClick(object sender, RoutedEventArgs routedEventArgs) { IList selectedInstruments = InstrumentsGrid.SelectedItems; if (selectedInstruments.Count == 0) { return; } if (selectedInstruments.Count == 1) { var inst = (Instrument)selectedInstruments[0]; MessageBoxResult res = MessageBox.Show( string.Format("Are you sure you want to delete all data from {0} @ {1}?", inst.Symbol, inst.Datasource.Name), "Delete", MessageBoxButton.YesNo); if (res == MessageBoxResult.No) { return; } } else { MessageBoxResult res = MessageBox.Show( string.Format("Are you sure you want to delete all data from {0} instruments?", selectedInstruments.Count), "Delete", MessageBoxButton.YesNo); if (res == MessageBoxResult.No) { return; } } using (IDataStorage storage = DataStorageFactory.Get()) { //todo: remove dependency on local storage here, use client instead foreach (Instrument i in selectedInstruments) { try { storage.DeleteAllInstrumentData(i); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } StatusBarLabel.Content = "Instrument data deleted"; }
/// <summary> /// Delete an instrument and all locally stored data. /// </summary> public async Task RemoveInstrument(Instrument instrument, IDataStorage localStorage) { //hacking around the circular reference issue if (instrument.IsContinuousFuture) { Context.Instruments.Attach(instrument); var tmpCF = instrument.ContinuousFuture; instrument.ContinuousFuture = null; instrument.ContinuousFutureID = null; await Context.SaveChangesAsync().ConfigureAwait(false); Context.ContinuousFutures.Attach(tmpCF); Context.ContinuousFutures.Remove(tmpCF); await Context.SaveChangesAsync().ConfigureAwait(false); } Context.Instruments.Attach(instrument); Context.Instruments.Remove(instrument); await Context.SaveChangesAsync().ConfigureAwait(false); localStorage.Connect(); localStorage.DeleteAllInstrumentData(instrument); }
/// <summary> /// Delete an instrument and all locally stored data. /// </summary> public static void RemoveInstrument(Instrument instrument, IDataStorage localStorage) { using (var entityContext = new MyDBContext()) { //hacking around the circular reference issue if (instrument.IsContinuousFuture) { entityContext.Instruments.Attach(instrument); var tmpCF = instrument.ContinuousFuture; instrument.ContinuousFuture = null; instrument.ContinuousFutureID = null; entityContext.SaveChanges(); entityContext.ContinuousFutures.Attach(tmpCF); entityContext.ContinuousFutures.Remove(tmpCF); entityContext.SaveChanges(); } entityContext.Instruments.Attach(instrument); entityContext.Instruments.Remove(instrument); entityContext.SaveChanges(); } localStorage.Connect(); localStorage.DeleteAllInstrumentData(instrument); }